Use getRange_fns for repeat_bounds
This commit is contained in:
parent
dc80bc6809
commit
9cb0ab2fbb
@ -1,6 +1,7 @@
|
|||||||
#include "../core.h"
|
#include "../core.h"
|
||||||
#include "../utils/each.h"
|
#include "../utils/each.h"
|
||||||
#include "../utils/talloc.h"
|
#include "../utils/talloc.h"
|
||||||
|
#include "../utils/calls.h"
|
||||||
#include "../nfns.h"
|
#include "../nfns.h"
|
||||||
#include "../builtins.h"
|
#include "../builtins.h"
|
||||||
|
|
||||||
@ -55,23 +56,25 @@ B catch_c2(Md2D* d, B w, B x) { return c2(d->f, w,x); }
|
|||||||
|
|
||||||
extern GLOBAL B rt_undo;
|
extern GLOBAL B rt_undo;
|
||||||
void repeat_bounds(i64* bound, B g) { // doesn't consume
|
void repeat_bounds(i64* bound, B g) { // doesn't consume
|
||||||
#define UPD_BOUNDS(I) ({ i64 i_ = (I); if (i_<bound[0]) bound[0] = i_; if (i_>bound[1]) bound[1] = i_; })
|
#define UPD_BOUNDS(B,I) ({ i64 i_ = (I); if (i_<bound[0]) bound[0] = i_; if (i_>bound[1]) bound[1] = i_; })
|
||||||
if (isArr(g)) {
|
if (isArr(g)) {
|
||||||
usz ia = IA(g);
|
usz ia = IA(g);
|
||||||
u8 xe = TI(g,elType);
|
u8 ge = TI(g,elType);
|
||||||
if (elNum(xe)) {
|
if (elNum(ge)) {
|
||||||
incG(g);
|
i64 bres[2];
|
||||||
if (xe<el_i32) g = taga(cpyI32Arr(g));
|
if (!getRange_fns[ge](tyany_ptr(g), bres, ia)) thrM("⍟: 𝔾 contained non-integer (or integer was out of range)");
|
||||||
if (xe==el_f64) { f64* gp = f64any_ptr(g); NOUNROLL for (usz i=0; i<ia; i++) UPD_BOUNDS(o2i64(b(gp[i]))); }
|
if (bres[0]<bound[0]) bound[0] = bres[0];
|
||||||
else { i32* gp = i32any_ptr(g); NOUNROLL for (usz i=0; i<ia; i++) UPD_BOUNDS( gp[i] ); }
|
if (bres[1]>bound[1]) bound[1] = bres[1];
|
||||||
decG(g);
|
|
||||||
} else {
|
} else {
|
||||||
SGetU(g)
|
SGetU(g)
|
||||||
for (usz i = 0; i < ia; i++) repeat_bounds(bound, GetU(g, i));
|
for (usz i = 0; i < ia; i++) repeat_bounds(bound, GetU(g, i));
|
||||||
}
|
}
|
||||||
} else if (isNum(g)) {
|
} else if (isNum(g)) {
|
||||||
UPD_BOUNDS(o2i64(g));
|
if (!q_i64(g)) thrM("⍟: 𝔾 contained non-integer (or integer was out of range)");
|
||||||
} else thrM("⍟: 𝔾 contained a non-number atom");
|
i64 c = o2i64G(g);
|
||||||
|
if (c<bound[0]) bound[0] = c;
|
||||||
|
if (c>bound[1]) bound[1] = c;
|
||||||
|
} else thrM("⍟: 𝔾 contained non-number");
|
||||||
}
|
}
|
||||||
B repeat_replaceR(B g, B* q);
|
B repeat_replaceR(B g, B* q);
|
||||||
FORCE_INLINE B repeat_replace(B g, B* q) { // doesn't consume
|
FORCE_INLINE B repeat_replace(B g, B* q) { // doesn't consume
|
||||||
|
|||||||
@ -323,6 +323,12 @@ w←1‿1⥊1 ⋄ x←2⥊1 ⋄ w‿x <¨↩ ⋄ {! (∾⟨•Repr𝕩,": Expe
|
|||||||
%USE eqvar ⋄ a←¯5+↕10 ⋄ {1⊸+⍟𝕩 ⋈10}_eqvar a %% ⋈¨ 5+↕10
|
%USE eqvar ⋄ a←¯5+↕10 ⋄ {1⊸+⍟𝕩 ⋈10}_eqvar a %% ⋈¨ 5+↕10
|
||||||
%USE eqvar ⋄ a←¯5+↕10 ⋄ {1+⍟𝕩 ⋈10}_eqvar a %% ⋈¨ 5+↕10
|
%USE eqvar ⋄ a←¯5+↕10 ⋄ {1+⍟𝕩 ⋈10}_eqvar a %% ⋈¨ 5+↕10
|
||||||
%USE eqvar ⋄ a←¯5+↕10 ⋄ {1+⍟(𝕩{!𝕩≡⋈10 ⋄ 𝕗}) ⋈10}_eqvar a %% ⋈¨ 5+↕10
|
%USE eqvar ⋄ a←¯5+↕10 ⋄ {1+⍟(𝕩{!𝕩≡⋈10 ⋄ 𝕗}) ⋈10}_eqvar a %% ⋈¨ 5+↕10
|
||||||
|
!"Calling a modifier" % 1⊸+⍟{∘} 0
|
||||||
|
!"⍟: 𝔾 contained non-number" % 1⊸+⍟⟨1,∘,3⟩ 0
|
||||||
|
!"Expected integer, got 1.5" % 1⊸+⍟1.5 0
|
||||||
|
!"Integer out of range: 1e20" % 1⊸+⍟1e20 0
|
||||||
|
!"⍟: 𝔾 contained non-integer (or integer was out of range)" % %USE evar ⋄ {1⊸+⍟𝕩 0}_evar ⟨1.5⟩
|
||||||
|
!"⍟: 𝔾 contained non-integer (or integer was out of range)" % %USE evar ⋄ {1⊸+⍟𝕩 0}_evar ⟨1e20⟩
|
||||||
|
|
||||||
# ◶
|
# ◶
|
||||||
!"◶: 𝕘 must have rank 1 when index is a number" % 1◶[1‿2,3‿4] 3
|
!"◶: 𝕘 must have rank 1 when index is a number" % 1◶[1‿2,3‿4] 3
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user