pass untagged pointer to get & getU
This commit is contained in:
parent
12d5a5a829
commit
a36ae1a716
@ -49,14 +49,14 @@ B ud_c1(B t, B x) {
|
||||
for (usz i = 0; i < xu; i++) rp[i] = i;
|
||||
return r;
|
||||
}
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
usz xia = a(x)->ia;
|
||||
if (rnk(x)!=1) thrF("↕: Argument must be either an integer or integer list (had rank %i)", rnk(x));
|
||||
if (xia>UR_MAX) thrF("↕: Result rank too large (%s≡≠𝕩)", xia);
|
||||
usz sh[xia];
|
||||
usz ria = 1;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
usz c = o2s(xgetU(x, i));
|
||||
usz c = o2s(GetU(x, i));
|
||||
if (c > I32_MAX) thrM("↕: Result too large");
|
||||
sh[i] = c;
|
||||
if (c*(u64)ria >= U32_MAX) thrM("↕: Result too large");
|
||||
@ -170,10 +170,10 @@ B indexOf_c1(B t, B x) {
|
||||
// wyhashmap_t idx[size];
|
||||
// i32 val[size];
|
||||
// for (i64 i = 0; i < size; i++) { idx[i] = 0; val[i] = -1; }
|
||||
// BS2B xget = TI(x,get);
|
||||
// SGet(x)
|
||||
// i32 ctr = 0;
|
||||
// for (usz i = 0; i < xia; i++) {
|
||||
// u64 hash = bqn_hash(xget(x,i), wy_secret);
|
||||
// u64 hash = bqn_hash(Get(x,i), wy_secret);
|
||||
// u64 p = wyhashmap(idx, size, &hash, 8, true, wy_secret);
|
||||
// if (val[p]==-1) val[p] = ctr++;
|
||||
// rp[i] = val[p];
|
||||
@ -186,10 +186,10 @@ B indexOf_c1(B t, B x) {
|
||||
// u64 s = nsTime();
|
||||
i32* rp; B r = m_i32arrv(&rp, xia);
|
||||
H_b2i* map = m_b2i(64);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
i32 ctr = 0;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
bool had; u64 p = mk_b2i(&map, xgetU(x,i), &had);
|
||||
bool had; u64 p = mk_b2i(&map, GetU(x,i), &had);
|
||||
if (had) rp[i] = map->a[p].val;
|
||||
else rp[i] = map->a[p].val = ctr++;
|
||||
}
|
||||
@ -204,7 +204,7 @@ B indexOf_c2(B t, B w, B x) {
|
||||
if (rnk(w)==1) {
|
||||
if (!isArr(x) || rnk(x)==0) {
|
||||
usz wia = a(w)->ia;
|
||||
B el = isArr(x)? TI(x,getU)(x,0) : x;
|
||||
B el = isArr(x)? IGetU(x,0) : x;
|
||||
i32 res = wia;
|
||||
if (TI(w,elType)==el_i32) {
|
||||
if (q_i32(el)) {
|
||||
@ -215,9 +215,9 @@ B indexOf_c2(B t, B w, B x) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BS2B wgetU = TI(w,getU);
|
||||
SGetU(w)
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
if (equal(wgetU(w,i), el)) { res = i; break; }
|
||||
if (equal(GetU(w,i), el)) { res = i; break; }
|
||||
}
|
||||
}
|
||||
dec(w); dec(x);
|
||||
@ -231,13 +231,13 @@ B indexOf_c2(B t, B w, B x) {
|
||||
// TODO O(wia×xia) for small wia
|
||||
i32* rp; B r = m_i32arrv(&rp, xia);
|
||||
H_b2i* map = m_b2i(64);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
BS2B wgetU = TI(w,getU);
|
||||
SGetU(x)
|
||||
SGetU(w)
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
bool had; u64 p = mk_b2i(&map, wgetU(w,i), &had);
|
||||
bool had; u64 p = mk_b2i(&map, GetU(w,i), &had);
|
||||
if (!had) map->a[p].val = i;
|
||||
}
|
||||
for (usz i = 0; i < xia; i++) rp[i] = getD_b2i(map, xgetU(x,i), wia);
|
||||
for (usz i = 0; i < xia; i++) rp[i] = getD_b2i(map, GetU(x,i), wia);
|
||||
free_b2i(map); dec(w); dec(x);
|
||||
return r;
|
||||
}
|
||||
@ -253,8 +253,8 @@ B memberOf_c1(B t, B x) {
|
||||
|
||||
i32* rp; B r = m_i32arrv(&rp, xia);
|
||||
H_Sb* set = m_Sb(64);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < xia; i++) rp[i] = !ins_Sb(&set, xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < xia; i++) rp[i] = !ins_Sb(&set, GetU(x,i));
|
||||
free_Sb(set); dec(x);
|
||||
return r;
|
||||
}
|
||||
@ -265,11 +265,11 @@ B memberOf_c2(B t, B w, B x) {
|
||||
// TODO O(wia×xia) for small wia
|
||||
H_Sb* set = m_Sb(64);
|
||||
bool had;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
BS2B wgetU = TI(w,getU);
|
||||
for (usz i = 0; i < xia; i++) mk_Sb(&set, xgetU(x,i), &had);
|
||||
SGetU(x)
|
||||
SGetU(w)
|
||||
for (usz i = 0; i < xia; i++) mk_Sb(&set, GetU(x,i), &had);
|
||||
i32* rp; B r = m_i32arrv(&rp, wia);
|
||||
for (usz i = 0; i < wia; i++) rp[i] = has_Sb(set, wgetU(w,i));
|
||||
for (usz i = 0; i < wia; i++) rp[i] = has_Sb(set, GetU(w,i));
|
||||
free_Sb(set); dec(w);dec(x);
|
||||
return r;
|
||||
}
|
||||
@ -283,9 +283,9 @@ B find_c1(B t, B x) {
|
||||
|
||||
B r = emptyHVec();
|
||||
H_Sb* set = m_Sb(64);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
B c = xgetU(x,i);
|
||||
B c = GetU(x,i);
|
||||
if (!ins_Sb(&set, c)) r = vec_add(r, inc(c));
|
||||
}
|
||||
free_Sb(set); dec(x);
|
||||
@ -302,9 +302,9 @@ B count_c1(B t, B x) {
|
||||
usz xia = a(x)->ia;
|
||||
i32* rp; B r = m_i32arrv(&rp, xia);
|
||||
H_b2i* map = m_b2i(64);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
bool had; u64 p = mk_b2i(&map, xgetU(x,i), &had);
|
||||
bool had; u64 p = mk_b2i(&map, GetU(x,i), &had);
|
||||
rp[i] = had? ++map->a[p].val : (map->a[p].val = 0);
|
||||
}
|
||||
dec(x); free_b2i(map);
|
||||
|
||||
@ -73,10 +73,10 @@ B GRADE_CAT(c1)(B t, B x) {
|
||||
}
|
||||
|
||||
TALLOC(BI32p, tmp, ia);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
tmp[i].v = i;
|
||||
tmp[i].k = xgetU(x,i);
|
||||
tmp[i].k = GetU(x,i);
|
||||
}
|
||||
CAT(GRADE_CAT(BP),tim_sort)(tmp, ia);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = tmp[i].v;
|
||||
@ -118,16 +118,16 @@ B GRADE_CAT(c2)(B t, B w, B x) {
|
||||
rp[i] = s;
|
||||
}
|
||||
} else {
|
||||
BS2B wgetU = TI(w,getU);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
if (CHECK_VALID) for (i64 i = 0; i < (i64)wia-1; i++) if (compare(wgetU(w,i), wgetU(w,i+1)) GRADE_UD(>,<) 0) thrM(GRADE_CHR": 𝕨 must be sorted"GRADE_UD(," in descending order"));
|
||||
SGetU(w)
|
||||
SGetU(x)
|
||||
if (CHECK_VALID) for (i64 i = 0; i < (i64)wia-1; i++) if (compare(GetU(w,i), GetU(w,i+1)) GRADE_UD(>,<) 0) thrM(GRADE_CHR": 𝕨 must be sorted"GRADE_UD(," in descending order"));
|
||||
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
B c = xgetU(x,i);
|
||||
B c = GetU(x,i);
|
||||
usz s = 0, e = wia+1;
|
||||
while (e-s > 1) {
|
||||
usz m = (s+e) / 2;
|
||||
if (compare(c, wgetU(w,m-1)) GRADE_UD(<,>) 0) e = m;
|
||||
if (compare(c, GetU(w,m-1)) GRADE_UD(<,>) 0) e = m;
|
||||
else s = m;
|
||||
}
|
||||
rp[i] = s;
|
||||
|
||||
@ -78,10 +78,10 @@ B listVariations_c2(B t, B w, B x) {
|
||||
|
||||
if (!isArr(w) || rnk(w)!=1) thrM("•internal.ListVariations: 𝕨 must be a list");
|
||||
usz wia = a(w)->ia;
|
||||
BS2B wgetU = TI(w,getU);
|
||||
SGetU(w)
|
||||
bool c_incr=false, c_rmFill=false;
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
u32 c = o2c(wgetU(w, i));
|
||||
u32 c = o2c(GetU(w, i));
|
||||
if (c=='i') c_incr=true;
|
||||
else if (c=='f') c_rmFill=true;
|
||||
else thrF("internal.ListVariations: Unknown option '%c' in 𝕨", c);
|
||||
@ -94,14 +94,14 @@ B listVariations_c2(B t, B w, B x) {
|
||||
bool ai8=false, ai16=false, ai32=false, af64=false,
|
||||
ac8=false, ac16=false, ac32=false;
|
||||
usz xia = a(x)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
if (isNum(xf)) {
|
||||
f64 min=0, max=0;
|
||||
if (xe==el_i8) { }
|
||||
else if (xe==el_i16) { i16* xp = i16any_ptr(x); for (usz i = 0; i < xia; i++) { if (xp[i]>max) max=xp[i]; if (xp[i]<min) min=xp[i]; } }
|
||||
else if (xe==el_i32) { i32* xp = i32any_ptr(x); for (usz i = 0; i < xia; i++) { if (xp[i]>max) max=xp[i]; if (xp[i]<min) min=xp[i]; } }
|
||||
else if (xe==el_f64) { f64* xp = f64any_ptr(x); for (usz i = 0; i < xia; i++) { if (xp[i]>max) max=xp[i]; if (xp[i]<min) min=xp[i]; if(xp[i]!=(i32)xp[i]) max=1e99; } }
|
||||
else for (usz i = 0; i < xia; i++) { B c = xgetU(x, i); if (!isF64(c)) goto noSpec; if (c.f>max) max=c.f; if (c.f<min) min=c.f; }
|
||||
else for (usz i = 0; i < xia; i++) { B c = GetU(x, i); if (!isF64(c)) goto noSpec; if (c.f>max) max=c.f; if (c.f<min) min=c.f; }
|
||||
ai8 = min==(i8 )min && max==(i8 )max;
|
||||
ai16 = min==(i16)min && max==(i16)max;
|
||||
ai32 = min==(i32)min && max==(i32)max;
|
||||
@ -109,7 +109,7 @@ B listVariations_c2(B t, B w, B x) {
|
||||
} else if (isC32(xf)) {
|
||||
u32 max = 0;
|
||||
if (xe!=el_c8) for (usz i = 0; i < xia; i++) {
|
||||
B c = xgetU(x, i);
|
||||
B c = GetU(x, i);
|
||||
if (!isC32(c)) goto noSpec;
|
||||
if (o2cu(c)>max) max = o2cu(c);
|
||||
}
|
||||
@ -161,8 +161,8 @@ B variation_c2(B t, B w, B x) {
|
||||
if (!isArr(x)) thrM("•internal.Variation: Non-array 𝕩");
|
||||
usz xia = a(x)->ia;
|
||||
u8 xe = TI(x,elType);
|
||||
BS2B xget = TI(x,get);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGet(x)
|
||||
SGetU(x)
|
||||
C8Arr* wc = toC8Arr(w);
|
||||
u8* wp = wc->a;
|
||||
u8* wpE = wp+wc->ia;
|
||||
@ -172,7 +172,7 @@ B variation_c2(B t, B w, B x) {
|
||||
bool slice = *wp == 'S';
|
||||
wp++;
|
||||
#define CPT(I) do { I; for (usz i = 0; i < xia; i++) tp[i] = xp[i]; } while(0)
|
||||
#define CPF(F) for (usz i = 0; i < xia; i++) tp[i] = F(xgetU(x,i))
|
||||
#define CPF(F) for (usz i = 0; i < xia; i++) tp[i] = F(GetU(x,i))
|
||||
if (u8_get(&wp, wpE, "i8" )) { i8* tp; res = m_i8arrc (&tp, x); if (xe==el_i8 ) CPT(i8* xp=i8any_ptr (x)); else CPF(o2i); }
|
||||
else if (u8_get(&wp, wpE, "i16")) { i16* tp; res = m_i16arrc(&tp, x); if (xe==el_i16) CPT(i16* xp=i16any_ptr(x)); else CPF(o2i); }
|
||||
else if (u8_get(&wp, wpE, "i32")) { i32* tp; res = m_i32arrc(&tp, x); if (xe==el_i32) CPT(i32* xp=i32any_ptr(x)); else CPF(o2i); }
|
||||
@ -183,12 +183,12 @@ B variation_c2(B t, B w, B x) {
|
||||
f64* tp; res = m_f64arrc(&tp, x);
|
||||
if (xe==el_i32) CPT(i32* xp=i32any_ptr(x));
|
||||
else if (xe==el_f64) CPT(f64* xp=f64any_ptr(x));
|
||||
else for (usz i = 0; i < xia; i++) tp[i] = o2f(xgetU(x,i));
|
||||
else for (usz i = 0; i < xia; i++) tp[i] = o2f(GetU(x,i));
|
||||
} else if (u8_get(&wp, wpE, "h")) {
|
||||
HArr_p t = m_harrUc(x);
|
||||
if (xe==el_i32) { i32* xp=i32any_ptr(x); for (usz i = 0; i < xia; i++) t.a[i] = m_f64(xp[i]); }
|
||||
else if (xe==el_f64) { f64* xp=f64any_ptr(x); for (usz i = 0; i < xia; i++) t.a[i] = m_f64(xp[i]); }
|
||||
else for (usz i = 0; i < xia; i++) t.a[i] = xget(x,i);
|
||||
else for (usz i = 0; i < xia; i++) t.a[i] = Get(x,i);
|
||||
res = t.b;
|
||||
} else if (u8_get(&wp, wpE, "f")) {
|
||||
Arr* t = m_fillarrp(xia);
|
||||
@ -198,7 +198,7 @@ B variation_c2(B t, B w, B x) {
|
||||
B* rp = fillarr_ptr(t);
|
||||
if (xe==el_i32) { i32* xp=i32any_ptr(x); for (usz i = 0; i < xia; i++) rp[i] = m_f64(xp[i]); }
|
||||
else if (xe==el_f64) { f64* xp=f64any_ptr(x); for (usz i = 0; i < xia; i++) rp[i] = m_f64(xp[i]); }
|
||||
else for (usz i = 0; i < xia; i++) rp[i] = xget(x,i);
|
||||
else for (usz i = 0; i < xia; i++) rp[i] = Get(x,i);
|
||||
} else thrF("•internal.Variation: Bad type \"%R\"", taga(wc));
|
||||
if (slice) {
|
||||
Arr* slice = TI(res,slice)(res, 0, a(res)->ia);
|
||||
|
||||
@ -51,16 +51,16 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
ur rr = wr+xr; usz ria = uszMulT(wia, xia);
|
||||
if (rr<xr) thrF("⌜: Result rank too large (%i≡=𝕨, %i≡=𝕩)", wr, xr);
|
||||
|
||||
BS2B wgetU = TI(w,getU);
|
||||
BS2B xget = TI(x,get);
|
||||
SGetU(w)
|
||||
SGet(x)
|
||||
BBB2B fc2 = c2fn(f);
|
||||
|
||||
usz ri = 0;
|
||||
HArr_p r = m_harrs(ria, &ri);
|
||||
for (usz wi = 0; wi < wia; wi++) {
|
||||
B cw = wgetU(w,wi);
|
||||
B cw = GetU(w,wi);
|
||||
for (usz xi = 0; xi < xia; xi++,ri++) {
|
||||
r.a[ri] = fc2(f, inc(cw), xget(x,xi));
|
||||
r.a[ri] = fc2(f, inc(cw), Get(x,xi));
|
||||
}
|
||||
}
|
||||
usz* rsh = harr_fa(r, rr);
|
||||
@ -128,16 +128,16 @@ B scan_c1(Md1D* d, B x) { B f = d->f;
|
||||
bool reuse = v(x)->type==t_harr && reusable(x);
|
||||
usz i = 0;
|
||||
HArr_p r = reuse? harr_parts(x) : m_harrs(a(x)->ia, &i);
|
||||
BS2B xget = reuse? TI(x,getU) : TI(x,get);
|
||||
AS2B xget = reuse? TI(x,getU) : TI(x,get); Arr* xa = a(x);
|
||||
BBB2B fc2 = c2fn(f);
|
||||
|
||||
if (xr==1) {
|
||||
r.a[i] = xget(x,0); i++;
|
||||
for (i = 1; i < ia; i++) r.a[i] = fc2(f, inc(r.a[i-1]), xget(x,i));
|
||||
r.a[i] = xget(xa,0); i++;
|
||||
for (i = 1; i < ia; i++) r.a[i] = fc2(f, inc(r.a[i-1]), xget(xa,i));
|
||||
} else {
|
||||
usz csz = arr_csz(x);
|
||||
for (; i < csz; i++) r.a[i] = xget(x,i);
|
||||
for (; i < ia; i++) r.a[i] = fc2(f, inc(r.a[i-csz]), xget(x,i));
|
||||
for (; i < csz; i++) r.a[i] = xget(xa,i);
|
||||
for (; i < ia; i++) r.a[i] = fc2(f, inc(r.a[i-csz]), xget(xa,i));
|
||||
}
|
||||
return withFill(reuse? x : harr_fcd(r, x), xf);
|
||||
}
|
||||
@ -182,22 +182,22 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
base:;
|
||||
|
||||
HArr_p r = reuse? harr_parts(x) : m_harrs(a(x)->ia, &i);
|
||||
BS2B xget = reuse? TI(x,getU) : TI(x,get);
|
||||
AS2B xget = reuse? TI(x,getU) : TI(x,get); Arr* xa = a(x);
|
||||
BBB2B fc2 = c2fn(f);
|
||||
|
||||
if (isArr(w)) {
|
||||
ur wr = rnk(w); usz* wsh = a(w)->sh; BS2B wget = TI(w,get);
|
||||
ur wr = rnk(w); usz* wsh = a(w)->sh; SGet(w)
|
||||
if (wr+1!=xr || !eqShPrefix(wsh, xsh+1, wr)) thrF("`: Shape of 𝕨 must match the cell of 𝕩 (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
|
||||
if (ia==0) return x;
|
||||
usz csz = arr_csz(x);
|
||||
for (; i < csz; i++) r.a[i] = fc2(f, wget(w,i), xget(x,i));
|
||||
for (; i < ia; i++) r.a[i] = fc2(f, inc(r.a[i-csz]), xget(x,i));
|
||||
for (; i < csz; i++) r.a[i] = fc2(f, Get(w,i), xget(xa,i));
|
||||
for (; i < ia; i++) r.a[i] = fc2(f, inc(r.a[i-csz]), xget(xa,i));
|
||||
dec(w);
|
||||
} else {
|
||||
if (xr!=1) thrF("`: Shape of 𝕨 must match the cell of 𝕩 (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
|
||||
if (ia==0) return x;
|
||||
B pr = r.a[0] = fc2(f, w, xget(x,0)); i++;
|
||||
for (; i < ia; i++) r.a[i] = pr = fc2(f, inc(pr), xget(x,i));
|
||||
B pr = r.a[0] = fc2(f, w, xget(xa,0)); i++;
|
||||
for (; i < ia; i++) r.a[i] = pr = fc2(f, inc(pr), xget(xa,i));
|
||||
}
|
||||
return withFill(reuse? x : harr_fcd(r, x), wf);
|
||||
}
|
||||
@ -254,7 +254,7 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
|
||||
}
|
||||
base:;
|
||||
|
||||
BS2B xget = TI(x,get);
|
||||
SGet(x)
|
||||
BBB2B fc2 = c2fn(f);
|
||||
B c;
|
||||
if (TI(x,elType)==el_i32) {
|
||||
@ -262,8 +262,8 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
|
||||
c = m_i32(xp[ia-1]);
|
||||
for (usz i = ia-1; i>0; i--) c = fc2(f, m_i32(xp[i-1]), c);
|
||||
} else {
|
||||
c = xget(x, ia-1);
|
||||
for (usz i = ia-1; i>0; i--) c = fc2(f, xget(x, i-1), c);
|
||||
c = Get(x, ia-1);
|
||||
for (usz i = ia-1; i>0; i--) c = fc2(f, Get(x, i-1), c);
|
||||
}
|
||||
dec(x);
|
||||
return c;
|
||||
@ -296,9 +296,9 @@ B fold_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
base:;
|
||||
|
||||
B c = w;
|
||||
BS2B xget = TI(x,get);
|
||||
SGet(x)
|
||||
BBB2B fc2 = c2fn(f);
|
||||
for (usz i = ia; i>0; i--) c = fc2(f, xget(x, i-1), c);
|
||||
for (usz i = ia; i>0; i--) c = fc2(f, Get(x, i-1), c);
|
||||
dec(x);
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -42,9 +42,9 @@ B catch_c2(Md2D* d, B w, B x) { return c2(d->f, w,x); }
|
||||
extern B rt_undo;
|
||||
void repeat_bounds(i64* bound, B g) { // doesn't consume
|
||||
if (isArr(g)) {
|
||||
BS2B xgetU = TI(g,getU);
|
||||
SGetU(g)
|
||||
usz ia = a(g)->ia;
|
||||
for (usz i = 0; i < ia; i++) repeat_bounds(bound, xgetU(g, i));
|
||||
for (usz i = 0; i < ia; i++) repeat_bounds(bound, GetU(g, i));
|
||||
} else if (isNum(g)) {
|
||||
i64 i = o2i64(g);
|
||||
if (i<bound[0]) bound[0] = i;
|
||||
@ -53,10 +53,10 @@ void repeat_bounds(i64* bound, B g) { // doesn't consume
|
||||
}
|
||||
B repeat_replace(B g, B* q) { // doesn't consume
|
||||
if (isArr(g)) {
|
||||
BS2B ggetU = TI(g,getU);
|
||||
SGetU(g)
|
||||
usz ia = a(g)->ia;
|
||||
HArr_p r = m_harrUc(g);
|
||||
for (usz i = 0; i < ia; i++) r.a[i] = repeat_replace(ggetU(g,i), q);
|
||||
for (usz i = 0; i < ia; i++) r.a[i] = repeat_replace(GetU(g,i), q);
|
||||
return r.b;
|
||||
} else {
|
||||
return inc(q[o2i64u(g)]);
|
||||
@ -111,12 +111,12 @@ B over_c2(Md2D* d, B w, B x) { B xr=c1(d->g, x); return c2(d->f, c1(d->g, w), xr
|
||||
B cond_c1(Md2D* d, B x) { B g=d->g;
|
||||
if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1");
|
||||
usz fr = WRAP(o2i64(c1iX(d->f, x)), a(g)->ia, thrM("◶: 𝔽 out of bounds of 𝕘"));
|
||||
return c1(TI(g,getU)(g, fr), x);
|
||||
return c1(IGetU(g, fr), x);
|
||||
}
|
||||
B cond_c2(Md2D* d, B w, B x) { B g=d->g;
|
||||
if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1");
|
||||
usz fr = WRAP(o2i64(c2iWX(d->f, w, x)), a(g)->ia, thrM("◶: 𝔽 out of bounds of 𝕘"));
|
||||
return c2(TI(g,getU)(g, fr), w, x);
|
||||
return c2(IGetU(g, fr), w, x);
|
||||
}
|
||||
|
||||
extern B rt_under, bi_before;
|
||||
|
||||
@ -45,7 +45,7 @@ B shape_c1(B t, B x) {
|
||||
} else {
|
||||
usz ia = a(x)->ia;
|
||||
if (ia==1 && TI(x,elType)<el_B) {
|
||||
B n = TI(x,get)(x,0);
|
||||
B n = IGet(x,0);
|
||||
dec(x);
|
||||
x = n;
|
||||
goto unit;
|
||||
@ -84,12 +84,12 @@ B shape_c2(B t, B w, B x) {
|
||||
}
|
||||
if (bad && !good) thrM("⥊: 𝕨 too large");
|
||||
} else {
|
||||
BS2B getU = TI(w,getU);
|
||||
SGetU(w)
|
||||
i32 unkPos = -1;
|
||||
i32 unkInd;
|
||||
bool bad=false, good=false;
|
||||
for (i32 i = 0; i < nr; i++) {
|
||||
B c = getU(w, i);
|
||||
B c = GetU(w, i);
|
||||
if (isF64(c)) {
|
||||
usz v = o2s(c);
|
||||
if (sh) sh->a[i] = v;
|
||||
@ -155,7 +155,7 @@ B shape_c2(B t, B w, B x) {
|
||||
// dec(x);
|
||||
// x = inc(xf);
|
||||
} else {
|
||||
B n = TI(x,get)(x,0);
|
||||
B n = IGet(x,0);
|
||||
dec(x);
|
||||
x = n;
|
||||
}
|
||||
@ -211,14 +211,14 @@ B pick_c1(B t, B x) {
|
||||
// dec(x);
|
||||
// return r;
|
||||
}
|
||||
B r = TI(x,get)(x, 0);
|
||||
B r = IGet(x, 0);
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
B pick_c2(B t, B w, B x) {
|
||||
if (isNum(w) && isArr(x) && rnk(x)==1) {
|
||||
usz p = WRAP(o2i64(w), a(x)->ia, thrF("⊑: indexing out-of-bounds (𝕨≡%R, %s≡≠𝕩)", w, iaW));
|
||||
B r = TI(x,get)(x, p);
|
||||
B r = IGet(x, p);
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
@ -254,7 +254,7 @@ B select_c2(B t, B w, B x) {
|
||||
return taga(r);
|
||||
}
|
||||
B xf = getFillQ(x);
|
||||
BS2B xget = TI(x,get);
|
||||
SGet(x)
|
||||
usz wia = a(w)->ia;
|
||||
|
||||
if (xr==1) {
|
||||
@ -303,7 +303,7 @@ B select_c2(B t, B w, B x) {
|
||||
HArr_p r = m_harrs(wia, &i);
|
||||
for (; i < wia; i++) {
|
||||
usz c = WRAP(wp[i], xia, thrF("⊏: Indexing out-of-bounds (%i∊𝕨, %s≡≠𝕩)", wp[i], xia));
|
||||
r.a[i] = xget(x, c);
|
||||
r.a[i] = Get(x, c);
|
||||
}
|
||||
dec(x);
|
||||
return withFill(harr_fcd(r,w),xf);
|
||||
@ -311,18 +311,18 @@ B select_c2(B t, B w, B x) {
|
||||
} else {
|
||||
usz i = 0;
|
||||
HArr_p r = m_harrs(wia, &i);
|
||||
BS2B wgetU = TI(w,getU);
|
||||
SGetU(w)
|
||||
for (; i < wia; i++) {
|
||||
B cw = wgetU(w, i);
|
||||
B cw = GetU(w, i);
|
||||
if (!isNum(cw)) { harr_abandon(r); goto base; }
|
||||
usz c = WRAP(o2i64(cw), xia, thrF("⊏: Indexing out-of-bounds (%R∊𝕨, %s≡≠𝕩)", cw, xia));
|
||||
r.a[i] = xget(x, c);
|
||||
r.a[i] = Get(x, c);
|
||||
}
|
||||
dec(x);
|
||||
return withFill(harr_fcd(r,w),xf);
|
||||
}
|
||||
} else {
|
||||
BS2B wgetU = TI(w,getU);
|
||||
SGetU(w)
|
||||
ur wr = rnk(w);
|
||||
i32 rr = wr+xr-1;
|
||||
if (xr==0) thrM("⊏: 𝕩 cannot be a unit");
|
||||
@ -331,7 +331,7 @@ B select_c2(B t, B w, B x) {
|
||||
usz cam = a(x)->sh[0];
|
||||
MAKE_MUT(r, wia*csz); mut_init(r, TI(x,elType));
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
B cw = wgetU(w, i);
|
||||
B cw = GetU(w, i);
|
||||
if (!isNum(cw)) { mut_pfree(r, i*csz); goto base; }
|
||||
f64 c = o2f(cw);
|
||||
if (c<0) c+= cam;
|
||||
@ -354,10 +354,10 @@ B select_c2(B t, B w, B x) {
|
||||
|
||||
static NOINLINE B slash_c1R(B x, u64 s) {
|
||||
usz xia = a(x)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
f64* rp; B r = m_f64arrv(&rp, s); usz ri = 0;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
usz c = o2s(xgetU(x, i));
|
||||
usz c = o2s(GetU(x, i));
|
||||
for (usz j = 0; j < c; j++) rp[ri++] = i;
|
||||
}
|
||||
dec(x);
|
||||
@ -385,9 +385,9 @@ B slash_c1(B t, B x) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (u64 i = 0; i < xia; i++) {
|
||||
usz c = o2s(xgetU(x, i));
|
||||
usz c = o2s(GetU(x, i));
|
||||
for (u64 j = 0; j < c; j++) *rp++ = i;
|
||||
}
|
||||
}
|
||||
@ -446,11 +446,11 @@ B slash_c2(B t, B w, B x) {
|
||||
return r;
|
||||
} else {
|
||||
HArr_p r = m_harrs(wsum, &ri);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
i32 cw = wp[i];
|
||||
if (cw==0) continue;
|
||||
B cx = incBy(xgetU(x, i), cw);
|
||||
B cx = incBy(GetU(x, i), cw);
|
||||
for (i64 j = 0; j < cw; j++) r.a[ri++] = cx;
|
||||
}
|
||||
dec(w); dec(x);
|
||||
@ -460,12 +460,12 @@ B slash_c2(B t, B w, B x) {
|
||||
i64 ria = isum(w);
|
||||
if (ria>USZ_MAX) thrOOM();
|
||||
HArr_p r = m_harrs(ria, &ri);
|
||||
BS2B wgetU = TI(w,getU);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(w)
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
usz c = o2s(wgetU(w, i));
|
||||
usz c = o2s(GetU(w, i));
|
||||
if (c) {
|
||||
B cx = incBy(xgetU(x, i), c);
|
||||
B cx = incBy(GetU(x, i), c);
|
||||
for (usz j = 0; RARE(j < c); j++) r.a[ri++] = cx;
|
||||
}
|
||||
}
|
||||
@ -492,9 +492,9 @@ B slash_c2(B t, B w, B x) {
|
||||
} else {
|
||||
B xf = getFillQ(x);
|
||||
HArr_p r = m_harrUv(xia*wv);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
B cx = incBy(xgetU(x, i), wv);
|
||||
B cx = incBy(GetU(x, i), wv);
|
||||
for (i64 j = 0; j < wv; j++) *r.a++ = cx;
|
||||
}
|
||||
dec(x);
|
||||
@ -590,9 +590,9 @@ B join_c1(B t, B x) {
|
||||
dec(xf);
|
||||
return withFill(r.b, xff);
|
||||
}
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
|
||||
B x0 = xgetU(x,0);
|
||||
B x0 = GetU(x,0);
|
||||
B rf; if(SFNS_FILLS) rf = getFillQ(x0);
|
||||
if (isAtm(x0)) thrM("∾: Rank of items must be equal or greater than rank of argument");
|
||||
usz ir = rnk(x0);
|
||||
@ -602,7 +602,7 @@ B join_c1(B t, B x) {
|
||||
usz csz = arr_csz(x0);
|
||||
usz cam = x0sh[0];
|
||||
for (usz i = 1; i < xia; i++) {
|
||||
B c = xgetU(x, i);
|
||||
B c = GetU(x, i);
|
||||
if (!isArr(c) || rnk(c)!=ir) thrF("∾: All items in argument should have same rank (contained items with ranks %i and %i)", ir, isArr(c)? rnk(c) : 0);
|
||||
usz* csh = a(c)->sh;
|
||||
if (ir>1) for (usz j = 1; j < ir; j++) if (csh[j]!=x0sh[j]) thrF("∾: Item trailing shapes must be equal (contained arrays with shapes %H and %H)", x0, c);
|
||||
@ -613,7 +613,7 @@ B join_c1(B t, B x) {
|
||||
MAKE_MUT(r, cam*csz);
|
||||
usz ri = 0;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
B c = xgetU(x, i);
|
||||
B c = GetU(x, i);
|
||||
usz cia = a(c)->ia;
|
||||
mut_copy(r, ri, c, 0, cia);
|
||||
ri+= cia;
|
||||
@ -643,8 +643,8 @@ B join_c2(B t, B w, B x) {
|
||||
ur c = wr>xr?wr:xr;
|
||||
if (c==0) {
|
||||
HArr_p r = m_harrUv(2);
|
||||
r.a[0] = TI(w,get)(w,0); dec(w);
|
||||
r.a[1] = TI(x,get)(x,0); dec(x);
|
||||
r.a[0] = IGet(w,0); dec(w);
|
||||
r.a[1] = IGet(x,0); dec(x);
|
||||
return qWithFill(r.b, f);
|
||||
}
|
||||
if (c-wr > 1 || c-xr > 1) thrF("∾: Argument ranks must differ by 1 or less (%i≡=𝕨, %i≡=𝕩)", wr, xr);
|
||||
@ -831,10 +831,10 @@ B group_c2(B t, B w, B x) {
|
||||
c->ia = 0;
|
||||
rp[i] = taga(c);
|
||||
}
|
||||
BS2B xget = TI(x,get);
|
||||
SGet(x)
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
i32 n = wp[i];
|
||||
if (n>=0) fillarr_ptr(a(rp[n]))[pos[n]++] = xget(x, i);
|
||||
if (n>=0) fillarr_ptr(a(rp[n]))[pos[n]++] = Get(x, i);
|
||||
}
|
||||
for (usz i = 0; i < ria; i++) { a(rp[i])->ia = len[i]; arr_shVec(a(rp[i])); }
|
||||
}
|
||||
@ -842,12 +842,12 @@ B group_c2(B t, B w, B x) {
|
||||
dec(w); dec(x); TFREE(lenO); TFREE(pos);
|
||||
return taga(r);
|
||||
} else {
|
||||
BS2B wgetU = TI(w,getU);
|
||||
i64 ria = wia==xia? 0 : o2i64(wgetU(w, xia));
|
||||
SGetU(w)
|
||||
i64 ria = wia==xia? 0 : o2i64(GetU(w, xia));
|
||||
if (ria<-1) thrM("⊔: 𝕨 can't contain elements less than ¯1");
|
||||
ria--;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
B cw = wgetU(w, i);
|
||||
B cw = GetU(w, i);
|
||||
if (!q_i64(cw)) goto base;
|
||||
i64 c = o2i64u(cw);
|
||||
if (c>ria) ria = c;
|
||||
@ -858,7 +858,7 @@ B group_c2(B t, B w, B x) {
|
||||
TALLOC(i32, lenO, ria+1); i32* len = lenO+1;
|
||||
TALLOC(i32, pos, ria);
|
||||
for (usz i = 0; i < ria; i++) len[i] = pos[i] = 0;
|
||||
for (usz i = 0; i < xia; i++) len[o2i64u(wgetU(w, i))]++;
|
||||
for (usz i = 0; i < xia; i++) len[o2i64u(GetU(w, i))]++;
|
||||
|
||||
Arr* r = m_fillarrp(ria); fillarr_setFill(r, m_f64(0)); arr_shVec(r);
|
||||
B* rp = fillarr_ptr(r);
|
||||
@ -874,10 +874,10 @@ B group_c2(B t, B w, B x) {
|
||||
Arr* rf = m_fillarrp(0); arr_shVec(rf);
|
||||
fillarr_setFill(rf, xf);
|
||||
fillarr_setFill(r, taga(rf));
|
||||
BS2B xget = TI(x,get);
|
||||
SGet(x)
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
i64 n = o2i64u(wgetU(w, i));
|
||||
if (n>=0) fillarr_ptr(a(rp[n]))[pos[n]++] = xget(x, i);
|
||||
i64 n = o2i64u(GetU(w, i));
|
||||
if (n>=0) fillarr_ptr(a(rp[n]))[pos[n]++] = Get(x, i);
|
||||
}
|
||||
for (usz i = 0; i < ria; i++) { a(rp[i])->ia = len[i]; arr_shVec(a(rp[i])); }
|
||||
dec(w); dec(x); TFREE(lenO); TFREE(pos);
|
||||
@ -940,7 +940,7 @@ B pick_uc1(B t, B o, B x) {
|
||||
if (isAtm(x) || a(x)->ia==0) return def_fn_uc1(t, o, x);
|
||||
B xf = getFillQ(x);
|
||||
usz ia = a(x)->ia;
|
||||
B arg = TI(x,get)(x, 0);
|
||||
B arg = IGet(x, 0);
|
||||
B rep = c1(o, arg);
|
||||
MAKE_MUT(r, ia); mut_init(r, el_or(TI(x,elType), selfElType(rep)));
|
||||
mut_setG(r, 0, rep);
|
||||
@ -953,7 +953,7 @@ B pick_ucw(B t, B o, B w, B x) {
|
||||
usz xia = a(x)->ia;
|
||||
usz wi = WRAP(o2i64(w), xia, thrF("𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡%R, %s≡≠𝕩)", w, xia));
|
||||
B xf = getFillQ(x);
|
||||
B arg = TI(x,get)(x, wi);
|
||||
B arg = IGet(x, wi);
|
||||
B rep = c1(o, arg);
|
||||
if (reusable(x) && TI(x,canStore)(rep)) {
|
||||
if (TI(x,elType)==el_i32) {
|
||||
@ -986,25 +986,25 @@ B pick_ucw(B t, B o, B w, B x) {
|
||||
B slash_ucw(B t, B o, B w, B x) {
|
||||
if (isAtm(w) || isAtm(x) || rnk(w)!=1 || rnk(x)!=1 || a(w)->ia!=a(x)->ia) return def_fn_ucw(t, o, w, x);
|
||||
usz ia = a(x)->ia;
|
||||
BS2B wgetU = TI(w,getU);
|
||||
if (TI(w,elType)!=el_i32) for (usz i = 0; i < ia; i++) if (!q_i32(wgetU(w,i))) return def_fn_ucw(t, o, w, x);
|
||||
SGetU(w)
|
||||
if (TI(w,elType)!=el_i32) for (usz i = 0; i < ia; i++) if (!q_i32(GetU(w,i))) return def_fn_ucw(t, o, w, x);
|
||||
B arg = slash_c2(t, inc(w), inc(x));
|
||||
usz argIA = a(arg)->ia;
|
||||
B rep = c1(o, arg);
|
||||
if (isAtm(rep) || rnk(rep)!=1 || a(rep)->ia != argIA) thrF("𝔽⌾(a⊸/)𝕩: Result of 𝔽 must have the same shape as a/𝕩 (expected ⟨%s⟩, got %H)", argIA, rep);
|
||||
MAKE_MUT(r, ia); mut_init(r, el_or(TI(x,elType), TI(rep,elType)));
|
||||
BS2B xget = TI(x,get);
|
||||
BS2B rgetU = TI(rep,getU);
|
||||
BS2B rget = TI(rep,get);
|
||||
SGet(x)
|
||||
SGetU(rep)
|
||||
SGet(rep)
|
||||
usz repI = 0;
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
i32 cw = o2iu(wgetU(w, i));
|
||||
i32 cw = o2iu(GetU(w, i));
|
||||
if (cw) {
|
||||
B cr = rget(rep,repI);
|
||||
if (CHECK_VALID) for (i32 j = 1; j < cw; j++) if (!equal(rgetU(rep,repI+j), cr)) { mut_pfree(r,i); thrM("𝔽⌾(a⊸/): Incompatible result elements"); }
|
||||
B cr = Get(rep,repI);
|
||||
if (CHECK_VALID) for (i32 j = 1; j < cw; j++) if (!equal(GetU(rep,repI+j), cr)) { mut_pfree(r,i); thrM("𝔽⌾(a⊸/): Incompatible result elements"); }
|
||||
mut_setG(r, i, cr);
|
||||
repI+= cw;
|
||||
} else mut_setG(r, i, xget(x,i));
|
||||
} else mut_setG(r, i, Get(x,i));
|
||||
}
|
||||
dec(w); dec(rep);
|
||||
return mut_fcd(r, x);
|
||||
@ -1014,8 +1014,8 @@ B select_ucw(B t, B o, B w, B x) {
|
||||
if (isAtm(x) || rnk(x)!=1 || isAtm(w) || rnk(w)!=1) return def_fn_ucw(t, o, w, x);
|
||||
usz xia = a(x)->ia;
|
||||
usz wia = a(w)->ia;
|
||||
BS2B wgetU = TI(w,getU);
|
||||
if (TI(w,elType)!=el_i32) for (usz i = 0; i < wia; i++) if (!q_i64(wgetU(w,i))) return def_fn_ucw(t, o, w, x);
|
||||
SGetU(w)
|
||||
if (TI(w,elType)!=el_i32) for (usz i = 0; i < wia; i++) if (!q_i64(GetU(w,i))) return def_fn_ucw(t, o, w, x);
|
||||
B arg = select_c2(t, inc(w), inc(x));
|
||||
B rep = c1(o, arg);
|
||||
if (isAtm(rep) || rnk(rep)!=1 || a(rep)->ia != wia) thrF("𝔽⌾(a⊸⊏)𝕩: Result of 𝔽 must have the same shape as a⊏𝕩 (expected ⟨%s⟩, got %H)", wia, rep);
|
||||
@ -1044,10 +1044,10 @@ B select_ucw(B t, B o, B w, B x) {
|
||||
return x;
|
||||
} else if (v(x)->type==t_harr) {
|
||||
B* xp = harr_ptr(x);
|
||||
BS2B rget = TI(rep,get);
|
||||
SGet(rep)
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
i64 cw = wp[i]; if (cw<0) cw+= (i64)xia;
|
||||
B cr = rget(rep, i);
|
||||
B cr = Get(rep, i);
|
||||
EQ(!equal(cr,xp[cw]));
|
||||
dec(xp[cw]);
|
||||
xp[cw] = cr;
|
||||
@ -1058,10 +1058,10 @@ B select_ucw(B t, B o, B w, B x) {
|
||||
}
|
||||
MAKE_MUT(r, xia); mut_init(r, el_or(TI(x,elType), TI(rep,elType)));
|
||||
mut_copyG(r, 0, x, 0, xia);
|
||||
BS2B rget = TI(rep,get);
|
||||
SGet(rep)
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
i64 cw = wp[i]; if (cw<0) cw+= (i64)xia;
|
||||
B cr = rget(rep, i);
|
||||
B cr = Get(rep, i);
|
||||
EQ(!equal(mut_getU(r, cw), cr));
|
||||
mut_rm(r, cw);
|
||||
mut_setG(r, cw, cr);
|
||||
@ -1071,10 +1071,10 @@ B select_ucw(B t, B o, B w, B x) {
|
||||
}
|
||||
MAKE_MUT(r, xia); mut_init(r, el_or(TI(x,elType), TI(rep,elType)));
|
||||
mut_copyG(r, 0, x, 0, xia);
|
||||
BS2B rget = TI(rep,get);
|
||||
SGet(rep)
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
i64 cw = o2i64u(wgetU(w, i)); if (cw<0) cw+= (i64)xia;
|
||||
B cr = rget(rep, i);
|
||||
i64 cw = o2i64u(GetU(w, i)); if (cw<0) cw+= (i64)xia;
|
||||
B cr = Get(rep, i);
|
||||
EQ(!equal(mut_getU(r, cw), cr));
|
||||
mut_rm(r, cw);
|
||||
mut_setG(r, cw, cr);
|
||||
|
||||
@ -41,8 +41,8 @@ B and_c1(B t, B x) {
|
||||
}
|
||||
B xf = getFillQ(x);
|
||||
HArr_p r = m_harrUv(xia);
|
||||
BS2B xget = TI(x,get);
|
||||
for (usz i = 0; i < xia; i++) r.a[i] = xget(x,i);
|
||||
SGet(x)
|
||||
for (usz i = 0; i < xia; i++) r.a[i] = Get(x,i);
|
||||
bA_tim_sort(r.a, xia);
|
||||
dec(x);
|
||||
return withFill(r.b,xf);
|
||||
@ -73,8 +73,8 @@ B or_c1(B t, B x) {
|
||||
}
|
||||
B xf = getFillQ(x);
|
||||
HArr_p r = m_harrUv(xia);
|
||||
BS2B xget = TI(x,get);
|
||||
for (usz i = 0; i < xia; i++) r.a[i] = xget(x,i);
|
||||
SGet(x)
|
||||
for (usz i = 0; i < xia; i++) r.a[i] = Get(x,i);
|
||||
bD_tim_sort(r.a, xia);
|
||||
dec(x);
|
||||
return withFill(r.b,xf);
|
||||
|
||||
@ -104,9 +104,9 @@ B fill_c2(B t, B w, B x) { // TODO not set fill for typed arrays
|
||||
|
||||
B grLen_both(i64 ria, B x) {
|
||||
usz ia = a(x)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
i64 c = o2i64u(xgetU(x, i));
|
||||
i64 c = o2i64u(GetU(x, i));
|
||||
if (c>ria) ria = c;
|
||||
}
|
||||
if (ria > (i64)(USZ_MAX-1)) thrOOM();
|
||||
@ -114,7 +114,7 @@ B grLen_both(i64 ria, B x) {
|
||||
i32* rp; B r = m_i32arrv(&rp, ria);
|
||||
for (usz i = 0; i < ria; i++) rp[i] = 0;
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
i64 n = o2i64u(xgetU(x, i));
|
||||
i64 n = o2i64u(GetU(x, i));
|
||||
if (n>=0) rp[n]++;
|
||||
assert(n>=-1);
|
||||
}
|
||||
@ -129,16 +129,16 @@ B grOrd_c2(B t, B w, B x) { // assumes valid arguments
|
||||
usz xia = a(x)->ia;
|
||||
if (wia==0) { dec(w); dec(x); return emptyIVec(); }
|
||||
if (xia==0) { dec(w); return x; }
|
||||
BS2B wgetU = TI(w,getU);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(w)
|
||||
SGetU(x)
|
||||
TALLOC(usz, tmp, wia);
|
||||
tmp[0] = 0;
|
||||
for (usz i = 1; i < wia; i++) tmp[i] = tmp[i-1]+o2su(wgetU(w,i-1));
|
||||
usz ria = tmp[wia-1]+o2su(wgetU(w,wia-1));
|
||||
for (usz i = 1; i < wia; i++) tmp[i] = tmp[i-1]+o2su(GetU(w,i-1));
|
||||
usz ria = tmp[wia-1]+o2su(GetU(w,wia-1));
|
||||
i32* rp; B r = m_i32arrv(&rp, ria);
|
||||
if (xia>=I32_MAX) thrM("⊔: Too large");
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
i64 c = o2i64(xgetU(x,i));
|
||||
i64 c = o2i64(GetU(x,i));
|
||||
if (c>=0) rp[tmp[c]++] = i;
|
||||
}
|
||||
dec(w); dec(x); TFREE(tmp);
|
||||
@ -160,12 +160,12 @@ B casrt_c2(B t, B w, B x) {
|
||||
unwindCompiler();
|
||||
dec(x);
|
||||
if (isArr(w) && a(w)->ia==2) {
|
||||
B w0 = TI(w,getU)(w,0);
|
||||
B w0 = IGetU(w,0);
|
||||
if (!isArr(w0) || a(w0)->ia<2) goto base;
|
||||
B s = TI(w,get)(w,1);
|
||||
BS2B w0getU = TI(w0,getU);
|
||||
B s = IGet(w,1);
|
||||
SGetU(w0)
|
||||
AFMT("\n");
|
||||
s = vm_fmtPoint(comp_currSrc, s, comp_currPath, o2s(w0getU(w0,0)), o2s(w0getU(w0,1))+1);
|
||||
s = vm_fmtPoint(comp_currSrc, s, comp_currPath, o2s(GetU(w0,0)), o2s(GetU(w0,1))+1);
|
||||
dec(w);
|
||||
thr(s);
|
||||
}
|
||||
@ -198,8 +198,8 @@ B bqn_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)!=1) thrM("•BQN: Argument must be a character vector");
|
||||
if (a(x)->type!=t_c32arr && a(x)->type!=t_c32slice) {
|
||||
usz ia = a(x)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) if (!isC32(xgetU(x,i))) thrM("•BQN: Argument must be a character vector");
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) if (!isC32(GetU(x,i))) thrM("•BQN: Argument must be a character vector");
|
||||
}
|
||||
return bqn_exec(x, bi_N, bi_N);
|
||||
}
|
||||
@ -459,10 +459,10 @@ B repl_c2(B t, B w, B x) {
|
||||
|
||||
if (!isArr(w) || rnk(w)!=1 || a(w)->ia>3) thrM("REPL: 𝕨 must be a vector with at most 3 items");
|
||||
usz ia = a(w)->ia;
|
||||
BS2B wget = TI(w,get);
|
||||
B path = ia>0? wget(w,0) : inc(replPath);
|
||||
B file = ia>1? wget(w,1) : emptyCVec();
|
||||
B args = ia>2? wget(w,2) : emptySVec();
|
||||
SGet(w)
|
||||
B path = ia>0? Get(w,0) : inc(replPath);
|
||||
B file = ia>1? Get(w,1) : emptyCVec();
|
||||
B args = ia>2? Get(w,2) : emptySVec();
|
||||
B fullpath = vec_join(vec_add(path, m_c32('/')), file);
|
||||
dec(w);
|
||||
|
||||
@ -522,8 +522,9 @@ B flines_c2(B d, B w, B x) {
|
||||
if (!isArr(x)) thrM("•FLines: Non-array 𝕩");
|
||||
B nl, s = emptyCVec();
|
||||
usz ia = a(x)->ia;
|
||||
SGet(x)
|
||||
for (u64 i = 0; i < ia; i++) {
|
||||
nl = TI(x,get)(x, i);
|
||||
nl = Get(x, i);
|
||||
if (!isArr(nl)) thrM("•FLines: Non-array element of 𝕩");
|
||||
s = vec_join(s, nl);
|
||||
//if (windows) s = vec_add(s, m_c32('\r')); TODO figure out whether or not this is a thing that should be done
|
||||
@ -586,9 +587,9 @@ B fromUtf8_c1(B t, B x) {
|
||||
if (!isArr(x)) thrM("•FromUTF8: Argument must be a character or number array");
|
||||
usz ia = a(x)->ia;
|
||||
TALLOC(char, chrs, ia);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (u64 i = 0; i < ia; i++) {
|
||||
B c = xgetU(x,i);
|
||||
B c = GetU(x,i);
|
||||
if (isC32(c)) {
|
||||
u32 v = o2cu(c);
|
||||
if (v>=256) thrF("•FromUTF8: Argument contained a character with codepoint %i", v);
|
||||
@ -612,9 +613,9 @@ B sh_c1(B t, B x) {
|
||||
usz xia = a(x)->ia;
|
||||
if (xia==0) thrM("•SH: 𝕩 must have at least one item");
|
||||
TALLOC(char*, argv, xia+1);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (u64 i = 0; i < xia; i++) {
|
||||
B c = xgetU(x, i);
|
||||
B c = GetU(x, i);
|
||||
if (isAtm(c) || rnk(c)!=1) thrM("•SH: 𝕩 must be a vector of strings");
|
||||
u64 len = utf8lenB(c);
|
||||
TALLOC(char, cstr, len+1);
|
||||
@ -668,12 +669,12 @@ B sys_c1(B t, B x) {
|
||||
assert(isArr(x));
|
||||
usz i = 0;
|
||||
HArr_p r = m_harrs(a(x)->ia, &i);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
B fileNS = m_f64(0);
|
||||
B path = m_f64(0);
|
||||
#define REQ_PATH ({ if(!path.u) path = path_abs(path_dir(inc(comp_currPath))); path; })
|
||||
for (; i < a(x)->ia; i++) {
|
||||
B c = xgetU(x,i);
|
||||
B c = GetU(x,i);
|
||||
if (eqStr(c, U"out")) r.a[i] = inc(bi_out);
|
||||
else if (eqStr(c, U"show")) r.a[i] = inc(bi_show);
|
||||
else if (eqStr(c, U"exit")) r.a[i] = inc(bi_exit);
|
||||
|
||||
@ -92,8 +92,8 @@ static i64 isum(B x) { // doesn't consume; may error; TODO error on overflow
|
||||
f64* p = f64any_ptr(x);
|
||||
for (usz i = 0; i < xia; i++) { if(p[i]!=(i64)p[i]) thrM("Expected integer"); r+= p[i]; }
|
||||
} else {
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < xia; i++) r+= o2i64(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < xia; i++) r+= o2i64(GetU(x,i));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -6,8 +6,8 @@ static C8Arr* toC8Arr(B x) {
|
||||
if (v(x)->type==t_c8arr) return c(C8Arr,x);
|
||||
u8* rp; B r = m_c8arrc(&rp, x);
|
||||
usz ia = a(r)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2cu(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2cu(GetU(x,i));
|
||||
dec(x);
|
||||
return c(C8Arr,r);
|
||||
}
|
||||
@ -15,8 +15,8 @@ static C16Arr* toC16Arr(B x) {
|
||||
if (v(x)->type==t_c16arr) return c(C16Arr,x);
|
||||
u16* rp; B r = m_c16arrc(&rp, x);
|
||||
usz ia = a(r)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2cu(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2cu(GetU(x,i));
|
||||
dec(x);
|
||||
return c(C16Arr,r);
|
||||
}
|
||||
@ -24,8 +24,8 @@ static C32Arr* toC32Arr(B x) {
|
||||
if (v(x)->type==t_c32arr) return c(C32Arr,x);
|
||||
u32* rp; B r = m_c32arrc(&rp, x);
|
||||
usz ia = a(r)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2cu(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2cu(GetU(x,i));
|
||||
dec(x);
|
||||
return c(C32Arr,r);
|
||||
}
|
||||
@ -33,10 +33,10 @@ static C32Arr* toC32Arr(B x) {
|
||||
|
||||
static bool eqStr(B w, u32* x) {
|
||||
if (isAtm(w) || rnk(w)!=1) return false;
|
||||
BS2B wgetU = TI(w,getU);
|
||||
SGetU(w)
|
||||
u64 i = 0;
|
||||
while (x[i]) {
|
||||
B c = wgetU(w, i);
|
||||
B c = GetU(w, i);
|
||||
if (!isC32(c) || x[i]!=(u32)c.u) return false;
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -4,8 +4,8 @@ static F64Arr* toF64Arr(B x) {
|
||||
if (v(x)->type==t_f64arr) return c(F64Arr,x);
|
||||
f64* rp; B r = m_f64arrc(&rp, x);
|
||||
usz ia = a(r)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2f(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2f(GetU(x,i));
|
||||
dec(x);
|
||||
return c(F64Arr,r);
|
||||
}
|
||||
|
||||
@ -17,9 +17,9 @@ B asFill(B x) { // consumes
|
||||
return r;
|
||||
}
|
||||
HArr_p r = m_harrUc(x);
|
||||
BS2B xget = TI(x,get);
|
||||
SGet(x)
|
||||
bool noFill = false;
|
||||
for (usz i = 0; i < ia; i++) if ((r.a[i]=asFill(xget(x,i))).u == bi_noFill.u) noFill = true;
|
||||
for (usz i = 0; i < ia; i++) if ((r.a[i]=asFill(Get(x,i))).u == bi_noFill.u) noFill = true;
|
||||
B xf = getFillQ(x);
|
||||
dec(x);
|
||||
if (noFill) { ptr_dec(r.c); return bi_noFill; }
|
||||
@ -40,10 +40,10 @@ static Arr* m_fillslice(Arr* p, B* ptr, usz ia) {
|
||||
static Arr* fillarr_slice (B x, usz s, usz ia) { return m_fillslice(a(x), c(FillArr,x)->a+s, ia); }
|
||||
static Arr* fillslice_slice(B x, usz s, usz ia) { Arr* p=c(Slice,x)->p; ptr_inc(p); Arr* r = m_fillslice(p, c(FillSlice,x)->a+s, ia); dec(x); return r; }
|
||||
|
||||
static B fillarr_get (B x, usz n) { VTY(x,t_fillarr ); return inc(c(FillArr ,x)->a[n]); }
|
||||
static B fillslice_get (B x, usz n) { VTY(x,t_fillslice); return inc(c(FillSlice,x)->a[n]); }
|
||||
static B fillarr_getU (B x, usz n) { VTY(x,t_fillarr ); return c(FillArr ,x)->a[n] ; }
|
||||
static B fillslice_getU(B x, usz n) { VTY(x,t_fillslice); return c(FillSlice,x)->a[n] ; }
|
||||
static B fillarr_get (Arr* x, usz n) { assert(x->type==t_fillarr ); return inc(((FillArr* )x)->a[n]); }
|
||||
static B fillslice_get (Arr* x, usz n) { assert(x->type==t_fillslice); return inc(((FillSlice*)x)->a[n]); }
|
||||
static B fillarr_getU (Arr* x, usz n) { assert(x->type==t_fillarr ); return ((FillArr* )x)->a[n] ; }
|
||||
static B fillslice_getU(Arr* x, usz n) { assert(x->type==t_fillslice); return ((FillSlice*)x)->a[n] ; }
|
||||
DEF_FREE(fillarr) {
|
||||
decSh(x);
|
||||
B* p = ((FillArr*)x)->a;
|
||||
@ -74,9 +74,9 @@ void fillarr_init() {
|
||||
|
||||
void validateFill(B x) {
|
||||
if (isArr(x)) {
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
usz ia = a(x)->ia;
|
||||
for (usz i = 0; i < ia; i++) validateFill(xgetU(x,i));
|
||||
for (usz i = 0; i < ia; i++) validateFill(GetU(x,i));
|
||||
} else if (isF64(x)) {
|
||||
assert(x.f==0);
|
||||
} else if (isC32(x)) {
|
||||
@ -94,9 +94,9 @@ NOINLINE bool fillEqualR(B w, B x) { // doesn't consume; both args must be array
|
||||
if (we!=el_B && xe!=el_B) {
|
||||
return elChr(we) == elChr(xe);
|
||||
}
|
||||
BS2B xgetU = TI(x,getU);
|
||||
BS2B wgetU = TI(w,getU);
|
||||
for (usz i = 0; i < ia; i++) if(!fillEqual(wgetU(w,i),xgetU(x,i))) return false;
|
||||
SGetU(x)
|
||||
SGetU(w)
|
||||
for (usz i = 0; i < ia; i++) if(!fillEqual(GetU(w,i),GetU(x,i))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -148,8 +148,8 @@ B withFill(B x, B fill) { // consumes both
|
||||
}
|
||||
} else {
|
||||
B* rp = r->a;
|
||||
BS2B xget = TI(x,get);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = xget(x,i);
|
||||
SGet(x)
|
||||
for (usz i = 0; i < ia; i++) rp[i] = Get(x,i);
|
||||
dec(x);
|
||||
}
|
||||
return taga(r);
|
||||
|
||||
@ -66,8 +66,8 @@ HArr* toHArr(B x) {
|
||||
if (v(x)->type==t_harr) return c(HArr,x);
|
||||
HArr_p r = m_harrUc(x);
|
||||
usz ia = r.c->ia;
|
||||
BS2B xget = TI(x,get);
|
||||
for (usz i = 0; i < ia; i++) r.a[i] = xget(x,i);
|
||||
SGet(x)
|
||||
for (usz i = 0; i < ia; i++) r.a[i] = Get(x,i);
|
||||
dec(x);
|
||||
return r.c;
|
||||
}
|
||||
@ -97,10 +97,10 @@ static Arr* m_hslice(Arr* p, B* ptr, usz ia) {
|
||||
static Arr* harr_slice (B x, usz s, usz ia) { return m_hslice(a(x), c(HArr,x)->a+s, ia); }
|
||||
static Arr* hslice_slice(B x, usz s, usz ia) { Arr* p=c(Slice,x)->p; ptr_inc(p); Arr* r = m_hslice(p, c(HSlice,x)->a+s, ia); dec(x); return r; }
|
||||
|
||||
static B harr_get (B x, usz n) { VTY(x,t_harr ); return inc(c(HArr ,x)->a[n]); }
|
||||
static B hslice_get (B x, usz n) { VTY(x,t_hslice); return inc(c(HSlice,x)->a[n]); }
|
||||
static B harr_getU (B x, usz n) { VTY(x,t_harr ); return c(HArr ,x)->a[n] ; }
|
||||
static B hslice_getU(B x, usz n) { VTY(x,t_hslice); return c(HSlice,x)->a[n] ; }
|
||||
static B harr_get (Arr* x, usz n) { assert(x->type==t_harr ); return inc(((HArr* )x)->a[n]); }
|
||||
static B hslice_get (Arr* x, usz n) { assert(x->type==t_hslice); return inc(((HSlice*)x)->a[n]); }
|
||||
static B harr_getU (Arr* x, usz n) { assert(x->type==t_harr ); return ((HArr* )x)->a[n] ; }
|
||||
static B hslice_getU(Arr* x, usz n) { assert(x->type==t_hslice); return ((HSlice*)x)->a[n] ; }
|
||||
DEF_FREE(harr) {
|
||||
decSh(x);
|
||||
B* p = ((HArr*)x)->a; // don't use harr_ptr so type isn't checked
|
||||
@ -128,7 +128,7 @@ static void harrP_visit(Value* x) { assert(x->type==t_harrPartial);
|
||||
usz am = *((HArr*)x)->sh;
|
||||
for (usz i = 0; i < am; i++) mm_visit(p[i]);
|
||||
}
|
||||
static B harrP_get(B x, usz n) { err("getting item from t_harrPartial"); }
|
||||
static B harrP_get(Arr* x, usz n) { err("getting item from t_harrPartial"); }
|
||||
static void harrP_print(B x) {
|
||||
B* p = c(HArr,x)->a;
|
||||
usz am = *c(HArr,x)->sh;
|
||||
|
||||
@ -8,8 +8,8 @@ static I8Arr* toI8Arr(B x) { // assumes it's possible
|
||||
i32* fp = i32any_ptr(x);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = (i8)fp[i];
|
||||
} else {
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2iu(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2iu(GetU(x,i));
|
||||
}
|
||||
dec(x);
|
||||
return c(I8Arr,r);
|
||||
@ -23,8 +23,8 @@ static I16Arr* toI16Arr(B x) { // assumes it's possible
|
||||
f64* fp = f64any_ptr(x);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = (i16)fp[i];
|
||||
} else {
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2iu(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2iu(GetU(x,i));
|
||||
}
|
||||
dec(x);
|
||||
return c(I16Arr,r);
|
||||
@ -38,8 +38,8 @@ static I32Arr* toI32Arr(B x) { // assumes it's possible
|
||||
f64* fp = f64any_ptr(x);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = (i32)fp[i];
|
||||
} else {
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2iu(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) rp[i] = o2iu(GetU(x,i));
|
||||
}
|
||||
dec(x);
|
||||
return c(I32Arr,r);
|
||||
|
||||
@ -46,7 +46,6 @@ static B rtUnder_cw(B f, B g, B w, B x) { // consumes w,x
|
||||
dec(fn);
|
||||
return r;
|
||||
}
|
||||
B def_getU(B x, usz n) { return x; }
|
||||
B def_fn_uc1(B t, B o, B x) { return rtUnder_c1(o, t, x); }
|
||||
B def_fn_ucw(B t, B o, B w, B x) { return rtUnder_cw(o, t, w, x); }
|
||||
B def_m1_uc1(B t, B o, B f, B x) { B t2 = m1_d(inc(t),inc(f) ); B r = rtUnder_c1(o, t2, x); dec(t2); return r; }
|
||||
@ -76,12 +75,12 @@ NOINLINE TStack* ts_e(TStack* o, u32 elsz, u64 am) { u64 size = o->size;
|
||||
|
||||
NOINLINE void arr_print(B x) { // should accept refc=0 arguments for debugging purposes
|
||||
ur r = rnk(x);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
usz ia = a(x)->ia;
|
||||
if (r!=1) {
|
||||
if (r==0) {
|
||||
printf("<");
|
||||
print(xgetU(x,0));
|
||||
print(GetU(x,0));
|
||||
return;
|
||||
}
|
||||
usz* sh = a(x)->sh;
|
||||
@ -92,11 +91,11 @@ NOINLINE void arr_print(B x) { // should accept refc=0 arguments for debugging p
|
||||
printf("⥊");
|
||||
} else if (ia>0) {
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
B c = xgetU(x,i);
|
||||
B c = GetU(x,i);
|
||||
if (!isC32(c) || (u32)c.u=='\n') goto reg;
|
||||
}
|
||||
printf("\"");
|
||||
for (usz i = 0; i < ia; i++) printUTF8((u32)xgetU(x,i).u); // c32, no need to decrement
|
||||
for (usz i = 0; i < ia; i++) printUTF8((u32)GetU(x,i).u); // c32, no need to decrement
|
||||
printf("\"");
|
||||
return;
|
||||
}
|
||||
@ -104,7 +103,7 @@ NOINLINE void arr_print(B x) { // should accept refc=0 arguments for debugging p
|
||||
printf("⟨");
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
if (i!=0) printf(", ");
|
||||
print(xgetU(x,i));
|
||||
print(GetU(x,i));
|
||||
}
|
||||
printf("⟩");
|
||||
}
|
||||
@ -147,9 +146,9 @@ NOINLINE void printRaw(B x) {
|
||||
else thrM("bad printRaw argument: atom arguments should be either numerical or characters");
|
||||
} else {
|
||||
usz ia = a(x)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
B c = xgetU(x,i);
|
||||
B c = GetU(x,i);
|
||||
#if !CATCH_ERRORS
|
||||
if (c.u==0 || noFill(c)) { printf(" "); continue; }
|
||||
#endif
|
||||
@ -304,15 +303,16 @@ NOINLINE void thrF(char* p, ...) {
|
||||
thr(r);
|
||||
}
|
||||
|
||||
|
||||
#define CMP(W,X) ({ AUTO wt = (W); AUTO xt = (X); (wt>xt?1:0)-(wt<xt?1:0); })
|
||||
NOINLINE i32 compareR(B w, B x) {
|
||||
if (isNum(w) & isC32(x)) return -1;
|
||||
if (isC32(w) & isNum(x)) return 1;
|
||||
if (isAtm(w) & isAtm(x)) thrM("Invalid comparison");
|
||||
bool wa=isAtm(w); usz wia; ur wr; usz* wsh; BS2B wgetU;
|
||||
bool xa=isAtm(x); usz xia; ur xr; usz* xsh; BS2B xgetU;
|
||||
if(wa) { wia=1; wr=0; wsh=NULL; wgetU=def_getU; } else { wia=a(w)->ia; wr=rnk(w); wsh=a(w)->sh; wgetU=TI(w,getU); }
|
||||
if(xa) { xia=1; xr=0; xsh=NULL; xgetU=def_getU; } else { xia=a(x)->ia; xr=rnk(x); xsh=a(x)->sh; xgetU=TI(x,getU); }
|
||||
bool wa=isAtm(w); usz wia; ur wr; usz* wsh; AS2B wgetU; Arr* wArr;
|
||||
bool xa=isAtm(x); usz xia; ur xr; usz* xsh; AS2B xgetU; Arr* xArr;
|
||||
if(wa) { wia=1; wr=0; wsh=NULL; } else { wia=a(w)->ia; wr=rnk(w); wsh=a(w)->sh; wgetU=TI(w,getU); wArr = a(w); }
|
||||
if(xa) { xia=1; xr=0; xsh=NULL; } else { xia=a(x)->ia; xr=rnk(x); xsh=a(x)->sh; xgetU=TI(x,getU); xArr = a(x); }
|
||||
if (wia==0 || xia==0) return CMP(wia, xia);
|
||||
|
||||
i32 rc = CMP(wr+(wa?0:1), xr+(xa?0:1));
|
||||
@ -330,7 +330,7 @@ NOINLINE i32 compareR(B w, B x) {
|
||||
rm*= wm<xm? wm : xm;
|
||||
}
|
||||
for (u64 i = 0; i < (u64)rm; i++) {
|
||||
int c = compare(wgetU(w,i), xgetU(x,i));
|
||||
int c = compare(wa? w : wgetU(wArr,i), xa? x : xgetU(xArr,i));
|
||||
if (c!=0) return c;
|
||||
}
|
||||
return rc;
|
||||
@ -375,9 +375,9 @@ NOINLINE bool equal(B w, B x) { // doesn't consume
|
||||
for (usz i = 0; i < ia; i++) if(wp[i]!=xp[i]) return false;
|
||||
return true;
|
||||
}
|
||||
BS2B xgetU = TI(x,getU);
|
||||
BS2B wgetU = TI(w,getU);
|
||||
for (usz i = 0; i < ia; i++) if(!equal(wgetU(w,i),xgetU(x,i))) return false;
|
||||
SGetU(x)
|
||||
SGetU(w)
|
||||
for (usz i = 0; i < ia; i++) if(!equal(GetU(w,i),GetU(x,i))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -410,9 +410,9 @@ bool eequal(B w, B x) { // doesn't consume
|
||||
// if (!feq) return false;
|
||||
if (!eqShape(w,x)) return false;
|
||||
usz ia = a(x)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
BS2B wgetU = TI(w,getU);
|
||||
for (usz i = 0; i < ia; i++) if(!eequal(wgetU(w,i),xgetU(x,i))) return false;
|
||||
SGetU(x)
|
||||
SGetU(w)
|
||||
for (usz i = 0; i < ia; i++) if(!eequal(GetU(w,i),GetU(x,i))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -421,9 +421,9 @@ u64 depth(B x) { // doesn't consume
|
||||
if (TI(x,arrD1)) return 1;
|
||||
u64 r = 0;
|
||||
usz ia = a(x)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
u64 n = depth(xgetU(x,i));
|
||||
u64 n = depth(GetU(x,i));
|
||||
if (n>r) r = n;
|
||||
}
|
||||
return r+1;
|
||||
@ -470,8 +470,8 @@ bool isPureFn(B x) { // doesn't consume
|
||||
dec(xd); return true;
|
||||
} else if (isArr(x)) {
|
||||
usz ia = a(x)->ia;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < ia; i++) if (!isPureFn(xgetU(x,i))) return false;
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < ia; i++) if (!isPureFn(GetU(x,i))) return false;
|
||||
return true;
|
||||
} else return isNum(x) || isC32(x);
|
||||
}
|
||||
@ -512,18 +512,18 @@ B num_squeeze(B x) {
|
||||
f64* rp; B r = m_f64arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2fu(xp[i]); dec(x); return r;
|
||||
}
|
||||
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (; i < ia; i++) {
|
||||
B cr = xgetU(x,i);
|
||||
B cr = GetU(x,i);
|
||||
if (!q_i32(cr)) goto n_i32_2;
|
||||
i32 c = o2iu(cr);
|
||||
or|= c<0?-c:c;
|
||||
}
|
||||
if (or<=I8_MAX ) { i8* rp; B r = m_i8arrc (&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2iu(xgetU(x,i)); dec(x); return r; }
|
||||
else if (or<=I16_MAX) { i16* rp; B r = m_i16arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2iu(xgetU(x,i)); dec(x); return r; }
|
||||
else { i32* rp; B r = m_i32arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2iu(xgetU(x,i)); dec(x); return r; }
|
||||
n_i32_2: while (i<ia) if (!isF64(xgetU(x,i++))) return x;
|
||||
f64* rp; B r = m_f64arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2fu(xgetU(x,i)); dec(x); return r;
|
||||
if (or<=I8_MAX ) { i8* rp; B r = m_i8arrc (&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2iu(GetU(x,i)); dec(x); return r; }
|
||||
else if (or<=I16_MAX) { i16* rp; B r = m_i16arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2iu(GetU(x,i)); dec(x); return r; }
|
||||
else { i32* rp; B r = m_i32arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2iu(GetU(x,i)); dec(x); return r; }
|
||||
n_i32_2: while (i<ia) if (!isF64(GetU(x,i++))) return x;
|
||||
f64* rp; B r = m_f64arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2fu(GetU(x,i)); dec(x); return r;
|
||||
}
|
||||
B chr_squeeze(B x) {
|
||||
usz ia = a(x)->ia;
|
||||
@ -543,15 +543,15 @@ B chr_squeeze(B x) {
|
||||
else if (or<=U16_MAX) { u16* rp; B r = m_c16arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2cu(xp[i]); dec(x); return r; }
|
||||
else { u32* rp; B r = m_c32arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2cu(xp[i]); dec(x); return r; }
|
||||
}
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
for (; i < ia; i++) {
|
||||
B cr = xgetU(x,i);
|
||||
B cr = GetU(x,i);
|
||||
if (!isC32(cr)) return x;
|
||||
or|= o2cu(cr);
|
||||
}
|
||||
if (or<=U8_MAX ) { u8* rp; B r = m_c8arrc (&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2cu(xgetU(x,i)); dec(x); return r; }
|
||||
else if (or<=U16_MAX) { u16* rp; B r = m_c16arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2cu(xgetU(x,i)); dec(x); return r; }
|
||||
else { u32* rp; B r = m_c32arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2cu(xgetU(x,i)); dec(x); return r; }
|
||||
if (or<=U8_MAX ) { u8* rp; B r = m_c8arrc (&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2cu(GetU(x,i)); dec(x); return r; }
|
||||
else if (or<=U16_MAX) { u16* rp; B r = m_c16arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2cu(GetU(x,i)); dec(x); return r; }
|
||||
else { u32* rp; B r = m_c32arrc(&rp, x); for (usz i=0;i<ia;i++) rp[i]=o2cu(GetU(x,i)); dec(x); return r; }
|
||||
}
|
||||
|
||||
B any_squeeze(B x) {
|
||||
@ -559,8 +559,8 @@ B any_squeeze(B x) {
|
||||
u8 xe = TI(x,elType);
|
||||
assert(xe!=el_bit);
|
||||
if (a(x)->ia==0) return x;
|
||||
BS2B xgetU = TI(x,getU);
|
||||
B x0 = xgetU(x, 0);
|
||||
SGetU(x)
|
||||
B x0 = GetU(x, 0);
|
||||
if (isNum(x0)) return num_squeeze(x);
|
||||
else if (isC32(x0)) return chr_squeeze(x);
|
||||
return x;
|
||||
@ -587,8 +587,8 @@ B bqn_merge(B x) {
|
||||
return taga(r);
|
||||
}
|
||||
|
||||
BS2B xgetU = TI(x,getU);
|
||||
B x0 = xgetU(x, 0);
|
||||
SGetU(x)
|
||||
B x0 = GetU(x, 0);
|
||||
usz* elSh = isArr(x0)? a(x0)->sh : NULL;
|
||||
ur elR = isArr(x0)? rnk(x0) : 0;
|
||||
usz elIA = isArr(x0)? a(x0)->ia : 1;
|
||||
@ -598,7 +598,7 @@ B bqn_merge(B x) {
|
||||
MAKE_MUT(r, xia*elIA);
|
||||
usz rp = 0;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
B c = xgetU(x, i);
|
||||
B c = GetU(x, i);
|
||||
if (isArr(c)? (elR!=rnk(c) || !eqShPrefix(elSh, a(c)->sh, elR)) : elR!=0) { mut_pfree(r, rp); thrF(">: Elements didn't have equal shapes (contained %H and %H)", x0, c); }
|
||||
if (isArr(c)) mut_copy(r, rp, c, 0, elIA);
|
||||
else mut_set(r, rp, c);
|
||||
|
||||
@ -140,7 +140,6 @@ B bqn_merge(B x); // consumes
|
||||
B any_squeeze(B x); // consumes; accepts any array, returns one with the smallest type (doesn't recurse!)
|
||||
B num_squeeze(B x); // consumes;
|
||||
B chr_squeeze(B x); // consumes
|
||||
B def_getU(B x, usz n);
|
||||
B def_fn_uc1(B t, B o, B x);
|
||||
B def_fn_ucw(B t, B o, B w, B x);
|
||||
B def_m1_uc1(B t, B o, B f, B x);
|
||||
|
||||
@ -13,8 +13,8 @@ static Arr* TP(m_,slice) (Arr* p, TEl* ptr, usz ia) {
|
||||
static Arr* TP(,arr_slice) (B x, usz s, usz ia) { return TP(m_,slice) (a(x), c(TArr,x)->a+s, ia); }
|
||||
static Arr* TP(,slice_slice) (B x, usz s, usz ia) { Arr* p=c(Slice,x)->p; ptr_inc(p); Arr* r = TP(m_,slice) (p, c(TSlice,x)->a+s, ia); dec(x); return r; }
|
||||
|
||||
static B TP(,arr_get) (B x, usz n) { VTY(x,T_ARR ); return TP(m_,) (c(TArr ,x)->a[n]); }
|
||||
static B TP(,slice_get) (B x, usz n) { VTY(x,T_SLICE); return TP(m_,) (c(TSlice,x)->a[n]); }
|
||||
static B TP(,arr_get) (Arr* x, usz n) { assert(x->type==T_ARR ); return TP(m_,) (((TArr* )x)->a[n]); }
|
||||
static B TP(,slice_get) (Arr* x, usz n) { assert(x->type==T_SLICE); return TP(m_,) (((TSlice*)x)->a[n]); }
|
||||
static bool TP(,arr_canStore) (B x) { return TP(q_,) (x); }
|
||||
|
||||
static void TP(,arr_init)() {
|
||||
|
||||
11
src/h.h
11
src/h.h
@ -381,6 +381,7 @@ void slice_print(B x);
|
||||
typedef bool (* B2b)(B);
|
||||
typedef void (* B2v)(B);
|
||||
typedef Arr* (*BSS2A)(B, usz, usz);
|
||||
typedef B (* AS2B)(Arr*, usz);
|
||||
typedef B (* BS2B)(B, usz);
|
||||
typedef B (* BSS2B)(B, usz, usz);
|
||||
typedef B (* B2B)(B);
|
||||
@ -398,8 +399,8 @@ typedef B (*M2C2)(Md2D*, B, B);
|
||||
|
||||
#define FOR_TI(F) \
|
||||
F(V2v, freeF) /* expects refc==0, includes mm_free */ \
|
||||
F(BS2B, get) /* increments result, doesn't consume arg; TODO figure out if this should never allocate, so GC wouldn't happen */ \
|
||||
F(BS2B, getU) /* like get, but doesn't increment result (mostly equivalent to `B t=get(…); dec(t); t`) */ \
|
||||
F(AS2B, get) /* increments result, doesn't consume arg; TODO figure out if this should never allocate, so GC wouldn't happen */ \
|
||||
F(AS2B, getU) /* like get, but doesn't increment result (mostly equivalent to `B t=get(…); dec(t); t`) */ \
|
||||
F(BB2B, m1_d) /* consume all args; (m, f) */ \
|
||||
F(BBB2B, m2_d) /* consume all args; (m, f, g) */ \
|
||||
F(BSS2A, slice) /* consumes; create slice from a starting position and length; add shape & rank yourself; may not actually be a Slice object; preserves fill */ \
|
||||
@ -429,6 +430,12 @@ typedef B (*M2C2)(Md2D*, B, B);
|
||||
#define TIv(X,V) (ti_##V[(X)->type])
|
||||
#define TI(X,V) (ti_##V[v(X)->type])
|
||||
|
||||
#define SGetU(X) Arr* X##_arrU = a(X); AS2B X##_getU = TIv(X##_arrU,getU);
|
||||
#define IGetU(X,N) ({ Arr* x_ = a(X); TIv(x_,getU)(x_,N); })
|
||||
#define GetU(X,N) X##_getU(X##_arrU,N)
|
||||
#define SGet(X) Arr* X##_arr = a(X); AS2B X##_get = TIv(X##_arr,get);
|
||||
#define IGet(X,N)({ Arr* x_ = a(X); TIv(x_,get)(x_,N); })
|
||||
#define Get(X,N) X##_get(X##_arr,N)
|
||||
|
||||
static bool q_N(B b) { return b.u==bi_N.u; }
|
||||
|
||||
|
||||
77
src/load.c
77
src/load.c
@ -103,11 +103,11 @@ _Thread_local B comp_currSrc;
|
||||
B rt_merge, rt_undo, rt_select, rt_slash, rt_join, rt_ud, rt_pick,rt_take, rt_drop,
|
||||
rt_group, rt_under, rt_reverse, rt_indexOf, rt_count, rt_memberOf, rt_find, rt_cell;
|
||||
Block* load_compObj(B x, B src, B path, Scope* sc) { // consumes x,src
|
||||
BS2B xget = TI(x,get);
|
||||
SGet(x)
|
||||
usz xia = a(x)->ia;
|
||||
if (xia!=6 & xia!=4) thrM("load_compObj: bad item count");
|
||||
Block* r = xia==6? compile(xget(x,0),xget(x,1),xget(x,2),xget(x,3),xget(x,4),xget(x,5), src, inc(path), sc)
|
||||
: compile(xget(x,0),xget(x,1),xget(x,2),xget(x,3),bi_N, bi_N, src, inc(path), sc);
|
||||
Block* r = xia==6? compile(Get(x,0),Get(x,1),Get(x,2),Get(x,3),Get(x,4),Get(x,5), src, inc(path), sc)
|
||||
: compile(Get(x,0),Get(x,1),Get(x,2),Get(x,3),bi_N, bi_N, src, inc(path), sc);
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
@ -168,7 +168,7 @@ NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // con
|
||||
for (u64 i = 0; i < csc->varAm; i++) {
|
||||
i32 nameID = csc->body->varIDs[i];
|
||||
B nl = csc->body->nsDesc->nameList;
|
||||
vName = vec_add(vName, TI(nl,get)(nl, nameID));
|
||||
vName = vec_add(vName, IGet(nl, nameID));
|
||||
vDepth = vec_add(vDepth, m_i32(depth));
|
||||
}
|
||||
if (csc->ext) for (u64 i = 0; i < csc->ext->varAm; i++) {
|
||||
@ -258,39 +258,39 @@ void load_init() { // very last init function
|
||||
#endif
|
||||
|
||||
B rtRes = m_funBlock(runtime_b, 0); ptr_dec(runtime_b);
|
||||
B rtObjRaw = TI(rtRes,get)(rtRes,0);
|
||||
B rtFinish = TI(rtRes,get)(rtRes,1);
|
||||
B rtObjRaw = IGet(rtRes,0);
|
||||
B rtFinish = IGet(rtRes,1);
|
||||
dec(rtRes);
|
||||
|
||||
if (c(Arr,rtObjRaw)->ia != rtLen) err("incorrectly defined rtLen!");
|
||||
HArr_p runtimeH = m_harrUc(rtObjRaw);
|
||||
BS2B rtObjGet = TI(rtObjRaw,get);
|
||||
SGet(rtObjRaw)
|
||||
|
||||
rt_undo = rtObjGet(rtObjRaw, 48); gc_add(rt_undo);
|
||||
rt_select = rtObjGet(rtObjRaw, 35); gc_add(rt_select);
|
||||
rt_slash = rtObjGet(rtObjRaw, 32); gc_add(rt_slash);
|
||||
rt_join = rtObjGet(rtObjRaw, 23); gc_add(rt_join);
|
||||
rt_ud = rtObjGet(rtObjRaw, 27); gc_add(rt_ud);
|
||||
rt_pick = rtObjGet(rtObjRaw, 36); gc_add(rt_pick);
|
||||
rt_take = rtObjGet(rtObjRaw, 25); gc_add(rt_take);
|
||||
rt_drop = rtObjGet(rtObjRaw, 26); gc_add(rt_drop);
|
||||
rt_group = rtObjGet(rtObjRaw, 41); gc_add(rt_group);
|
||||
rt_under = rtObjGet(rtObjRaw, 56); gc_add(rt_under);
|
||||
rt_reverse = rtObjGet(rtObjRaw, 30); gc_add(rt_reverse);
|
||||
rt_indexOf = rtObjGet(rtObjRaw, 37); gc_add(rt_indexOf);
|
||||
rt_count = rtObjGet(rtObjRaw, 38); gc_add(rt_count);
|
||||
rt_memberOf= rtObjGet(rtObjRaw, 39); gc_add(rt_memberOf);
|
||||
rt_find = rtObjGet(rtObjRaw, 40); gc_add(rt_find);
|
||||
rt_cell = rtObjGet(rtObjRaw, 45); gc_add(rt_cell);
|
||||
rt_undo = Get(rtObjRaw, 48); gc_add(rt_undo);
|
||||
rt_select = Get(rtObjRaw, 35); gc_add(rt_select);
|
||||
rt_slash = Get(rtObjRaw, 32); gc_add(rt_slash);
|
||||
rt_join = Get(rtObjRaw, 23); gc_add(rt_join);
|
||||
rt_ud = Get(rtObjRaw, 27); gc_add(rt_ud);
|
||||
rt_pick = Get(rtObjRaw, 36); gc_add(rt_pick);
|
||||
rt_take = Get(rtObjRaw, 25); gc_add(rt_take);
|
||||
rt_drop = Get(rtObjRaw, 26); gc_add(rt_drop);
|
||||
rt_group = Get(rtObjRaw, 41); gc_add(rt_group);
|
||||
rt_under = Get(rtObjRaw, 56); gc_add(rt_under);
|
||||
rt_reverse = Get(rtObjRaw, 30); gc_add(rt_reverse);
|
||||
rt_indexOf = Get(rtObjRaw, 37); gc_add(rt_indexOf);
|
||||
rt_count = Get(rtObjRaw, 38); gc_add(rt_count);
|
||||
rt_memberOf= Get(rtObjRaw, 39); gc_add(rt_memberOf);
|
||||
rt_find = Get(rtObjRaw, 40); gc_add(rt_find);
|
||||
rt_cell = Get(rtObjRaw, 45); gc_add(rt_cell);
|
||||
|
||||
for (usz i = 0; i < rtLen; i++) {
|
||||
#ifdef RT_WRAP
|
||||
r1Objs[i] = rtObjGet(rtObjRaw, i); gc_add(r1Objs[i]);
|
||||
r1Objs[i] = Get(rtObjRaw, i); gc_add(r1Objs[i]);
|
||||
#endif
|
||||
#ifdef ALL_R1
|
||||
B r = rtObjGet(rtObjRaw, i);
|
||||
B r = Get(rtObjRaw, i);
|
||||
#else
|
||||
B r = rtComplete[i]? inc(fruntime[i]) : rtObjGet(rtObjRaw, i);
|
||||
B r = rtComplete[i]? inc(fruntime[i]) : Get(rtObjRaw, i);
|
||||
#endif
|
||||
if (q_N(r)) err("· in runtime!\n");
|
||||
if (isVal(r)) v(r)->flags|= i+1;
|
||||
@ -347,9 +347,9 @@ void load_init() { // very last init function
|
||||
);
|
||||
B fmtM = m_funBlock(fmt_b, 0); ptr_dec(fmt_b);
|
||||
B fmtR = c1(fmtM, m_caB(4, (B[]){inc(bi_type), inc(bi_decp), inc(bi_glyph), inc(bi_repr)}));
|
||||
BS2B fget = TI(fmtR,get);
|
||||
load_fmt = fget(fmtR, 0); gc_add(load_fmt);
|
||||
load_repr = fget(fmtR, 1); gc_add(load_repr);
|
||||
SGet(fmtR)
|
||||
load_fmt = Get(fmtR, 0); gc_add(load_fmt);
|
||||
load_repr = Get(fmtR, 1); gc_add(load_repr);
|
||||
dec(fmtR);
|
||||
dec(fmtM);
|
||||
#endif
|
||||
@ -382,22 +382,23 @@ static void def_visit(Value* x) { printf("(no visit for %d=%s)\n", x->type, form
|
||||
static void def_print(B x) { printf("(%d=%s)", v(x)->type, format_type(v(x)->type)); }
|
||||
static bool def_canStore(B x) { return false; }
|
||||
static B def_identity(B f) { return bi_N; }
|
||||
static B def_get(B x, usz n) { return inc(x); }
|
||||
static B def_get(Arr* x, usz n) { err("def_get"); }
|
||||
static B def_getU(Arr* x, usz n) { err("def_getU"); }
|
||||
static B def_m1_d(B m, B f ) { thrM("cannot derive this"); }
|
||||
static B def_m2_d(B m, B f, B g) { thrM("cannot derive this"); }
|
||||
static Arr* def_slice(B x, usz s, usz ia) { thrM("cannot slice non-array!"); }
|
||||
|
||||
#ifdef DONT_FREE
|
||||
static B empty_get(B x, usz n) {
|
||||
v(x)->type = v(x)->flags;
|
||||
B r = TI(x,get)(x, n);
|
||||
v(x)->type = t_empty;
|
||||
static B empty_get(Arr* x, usz n) {
|
||||
x->type = x->flags;
|
||||
B r = TIv(x,get)(x, n);
|
||||
x->type = t_empty;
|
||||
return r;
|
||||
}
|
||||
static B empty_getU(B x, usz n) {
|
||||
v(x)->type = v(x)->flags;
|
||||
B r = TI(x,getU)(x, n);
|
||||
v(x)->type = t_empty;
|
||||
static B empty_getU(Arr* x, usz n) {
|
||||
x->type = x->flags;
|
||||
B r = TIv(x,getU)(x, n);
|
||||
x->type = t_empty;
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -117,9 +117,9 @@ int main(int argc, char* argv[]) {
|
||||
B path = fromUTF8l(argv[i++]);
|
||||
B lines = file_lines(path);
|
||||
usz ia = a(lines)->ia;
|
||||
BS2B lget = TI(lines,get);
|
||||
SGet(lines)
|
||||
for (u64 i = 0; i < ia; i++) {
|
||||
dec(gsc_exec_inline(lget(lines, i), inc(replPath), emptySVec()));
|
||||
dec(gsc_exec_inline(Get(lines, i), inc(replPath), emptySVec()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -32,12 +32,12 @@ B m_nfn(NFnDesc* desc, B obj) {
|
||||
return tag(r,FUN_TAG);
|
||||
}
|
||||
B nfn_name(B x) { VTY(x, t_nfn);
|
||||
return inc(c(NFnDesc,TI(nfn_list,getU)(nfn_list,c(NFn,x)->id))->name);
|
||||
return inc(c(NFnDesc,IGetU(nfn_list,c(NFn,x)->id))->name);
|
||||
}
|
||||
|
||||
DEF_FREE(nfn) { dec(((NFn*)x)->obj); }
|
||||
void nfn_visit(Value* x) { mm_visit(((NFn*)x)->obj); }
|
||||
void nfn_print(B x) { printRaw(c(NFnDesc,TI(nfn_list,getU)(nfn_list,c(NFn,x)->id))->name); }
|
||||
void nfn_print(B x) { printRaw(c(NFnDesc,IGetU(nfn_list,c(NFn,x)->id))->name); }
|
||||
DEF_FREE(nfnDesc) { err("nfnDesc shouldn't be freed!"); }
|
||||
void nfnDesc_visit(Value* x) { mm_visit(((NFnDesc*)x)->name); }
|
||||
void nfnDesc_print(B x) { printf("(native function description)"); }
|
||||
|
||||
40
src/ns.c
40
src/ns.c
@ -14,15 +14,15 @@ void m_nsDesc(Body* body, bool imm, u8 ty, B nameList, B varIDs, B exported) { /
|
||||
NSDesc* r = mm_alloc(fsizeof(NSDesc, expIDs, i32, vam), t_nsDesc);
|
||||
r->nameList = nameList;
|
||||
r->varAm = vam;
|
||||
BS2B getIDU = TI(varIDs,getU);
|
||||
BS2B getOnU = TI(exported,getU);
|
||||
SGetU(varIDs)
|
||||
SGetU(exported)
|
||||
for (i32 i = 0; i < off; i++) {
|
||||
body->varIDs[i] = -1;
|
||||
r ->expIDs[i] = -1;
|
||||
}
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
i32 cid = o2i(getIDU(varIDs, i));
|
||||
bool cexp = o2b(getOnU(exported, i));
|
||||
i32 cid = o2i(GetU(varIDs, i));
|
||||
bool cexp = o2b(GetU(exported, i));
|
||||
body->varIDs[i+off] = cid;
|
||||
r->expIDs[i+off] = cexp? cid : -1;
|
||||
}
|
||||
@ -45,11 +45,11 @@ B ns_getU(B ns, B cNL, i32 nameID) { VTY(ns, t_ns);
|
||||
assert((u64)nameID < a(cNL)->ia && nameID>=0);
|
||||
B dNL = d->nameList;
|
||||
if (cNL.u != dNL.u) {
|
||||
B cName = TI(cNL,getU)(cNL, nameID);
|
||||
BS2B dNLgetU = TI(dNL,getU);
|
||||
B cName = IGetU(cNL, nameID);
|
||||
SGetU(dNL)
|
||||
for (i32 i = 0; i < dVarAm; i++) {
|
||||
i32 dID = d->expIDs[i];
|
||||
if (dID>=0 && equal(dNLgetU(dNL, dID), cName)) return n->sc->vars[i];
|
||||
if (dID>=0 && equal(GetU(dNL, dID), cName)) return n->sc->vars[i];
|
||||
}
|
||||
} else {
|
||||
for (i32 i = 0; i < dVarAm; i++) {
|
||||
@ -65,11 +65,11 @@ B ns_qgetU(B ns, B cNL, i32 nameID) { VTY(ns, t_ns); // TODO somehow merge impl
|
||||
assert((u64)nameID < a(cNL)->ia && nameID>=0);
|
||||
B dNL = d->nameList;
|
||||
if (cNL.u != dNL.u) {
|
||||
B cName = TI(cNL,getU)(cNL, nameID);
|
||||
BS2B dNLgetU = TI(dNL,getU);
|
||||
B cName = IGetU(cNL, nameID);
|
||||
SGetU(dNL)
|
||||
for (i32 i = 0; i < dVarAm; i++) {
|
||||
i32 dID = d->expIDs[i];
|
||||
if (dID>=0 && equal(dNLgetU(dNL, dID), cName)) return n->sc->vars[i];
|
||||
if (dID>=0 && equal(GetU(dNL, dID), cName)) return n->sc->vars[i];
|
||||
}
|
||||
} else {
|
||||
for (i32 i = 0; i < dVarAm; i++) {
|
||||
@ -83,10 +83,10 @@ B ns_getNU(B ns, B name, bool thrEmpty) { VTY(ns, t_ns);
|
||||
NSDesc* d = n->desc;
|
||||
i32 dVarAm = d->varAm;
|
||||
B dNL = d->nameList;
|
||||
BS2B dNLgetU = TI(dNL,getU);
|
||||
SGetU(dNL)
|
||||
for (i32 i = 0; i < dVarAm; i++) {
|
||||
i32 dID = d->expIDs[i];
|
||||
if (dID>=0 && equal(dNLgetU(dNL, dID), name)) return n->sc->vars[i];
|
||||
if (dID>=0 && equal(GetU(dNL, dID), name)) return n->sc->vars[i];
|
||||
}
|
||||
if (thrEmpty) thrM("No key found");
|
||||
return bi_N;
|
||||
@ -96,10 +96,10 @@ void ns_set(B ns, B name, B val) { VTY(ns, t_ns);
|
||||
NSDesc* d = n->desc;
|
||||
i32 dVarAm = d->varAm;
|
||||
B dNL = d->nameList;
|
||||
BS2B dNLgetU = TI(dNL,getU);
|
||||
SGetU(dNL)
|
||||
for (i32 i = 0; i < dVarAm; i++) {
|
||||
i32 dID = d->expIDs[i];
|
||||
if (dID>=0 && equal(dNLgetU(dNL, dID), name)) {
|
||||
if (dID>=0 && equal(GetU(dNL, dID), name)) {
|
||||
dec(n->sc->vars[i]);
|
||||
n->sc->vars[i] = val;
|
||||
return;
|
||||
@ -112,10 +112,10 @@ i32 ns_pos(B ns, B name) { VTY(ns, t_ns);
|
||||
Body* b = c(NS, ns)->sc->body;
|
||||
B nameList = c(NS, ns)->desc->nameList;
|
||||
i32 bVarAm = b->varAm;
|
||||
BS2B nlGetU = TI(nameList,getU);
|
||||
SGetU(nameList)
|
||||
for (i32 i = 0; i < bVarAm; i++) {
|
||||
i32 id = b->varIDs[i];
|
||||
if (id>=0) if (equal(nlGetU(nameList, id), name)) { dec(name); return i; }
|
||||
if (id>=0) if (equal(GetU(nameList, id), name)) { dec(name); return i; }
|
||||
}
|
||||
thrM("No key found");
|
||||
}
|
||||
@ -141,14 +141,14 @@ static void ns_print(B x) {
|
||||
NSDesc* desc = c(NS,x)->desc;
|
||||
Scope* sc = c(NS,x)->sc;
|
||||
i32 am = desc->varAm;
|
||||
BS2B getNameU = TI(desc->nameList,getU);
|
||||
B nl = desc->nameList; SGetU(nl)
|
||||
bool first = true;
|
||||
for (i32 i = 0; i < am; i++) {
|
||||
i32 id = desc->expIDs[i];
|
||||
if (id>=0) {
|
||||
if (first) first=false;
|
||||
else printf(" ⋄ ");
|
||||
printRaw(getNameU(desc->nameList, id));
|
||||
printRaw(GetU(nl, id));
|
||||
printf("⇐");
|
||||
print(sc->vars[i]);
|
||||
}
|
||||
@ -160,14 +160,14 @@ B nsFmt(B x) { // consumes
|
||||
ACHR('{');
|
||||
NSDesc* desc = c(NS,x)->desc;
|
||||
i32 am = desc->varAm;
|
||||
BS2B getNameU = TI(desc->nameList,getU);
|
||||
B nl = desc->nameList; SGetU(nl)
|
||||
bool first = true;
|
||||
for (i32 i = 0; i < am; i++) {
|
||||
i32 id = desc->expIDs[i];
|
||||
if (id>=0) {
|
||||
if (first) first=false;
|
||||
else ACHR(U'‿');
|
||||
AFMT("%R", getNameU(desc->nameList, id));
|
||||
AFMT("%R", GetU(nl, id));
|
||||
}
|
||||
}
|
||||
AU("⇐}");
|
||||
|
||||
@ -86,7 +86,7 @@ struct WMd2 {
|
||||
WMd2* lastWM2;
|
||||
void wm2_visit(Value* x) { mm_visit(((WMd2*)x)->v); }
|
||||
|
||||
B wm1_c1(B d, B x) { B f = c(Md1D,d)->f; B t = c(Md1D,d)->m1;
|
||||
B wm1_c1(Md1D* d, B x) { B f = d->f; B t = d->m1;
|
||||
u64 pfwt=fwTotal; fwTotal = 0;
|
||||
WMd1* c = c(WMd1,t);
|
||||
B om = c->v;
|
||||
@ -100,7 +100,7 @@ B wm1_c1(B d, B x) { B f = c(Md1D,d)->f; B t = c(Md1D,d)->m1;
|
||||
fwTotal = pfwt + e-s + 30;
|
||||
return r;
|
||||
}
|
||||
B wm1_c2(B d, B w, B x) { B f = c(Md1D,d)->f; B t = c(Md1D,d)->m1;
|
||||
B wm1_c2(Md1D* d, B w, B x) { B f = d->f; B t = d->m1;
|
||||
u64 pfwt=fwTotal; fwTotal = 0;
|
||||
WMd1* c = c(WMd1,t);
|
||||
B om = c->v;
|
||||
@ -115,7 +115,7 @@ B wm1_c2(B d, B w, B x) { B f = c(Md1D,d)->f; B t = c(Md1D,d)->m1;
|
||||
return r;
|
||||
}
|
||||
|
||||
B wm2_c1(B d, B x) { B f = c(Md2D,d)->f; B g = c(Md2D,d)->g; B t = c(Md2D,d)->m2;
|
||||
B wm2_c1(Md2D* d, B x) { B f = d->f; B g = d->g; B t = d->m2;
|
||||
u64 pfwt=fwTotal; fwTotal = 0;
|
||||
WMd1* c = c(WMd1,t);
|
||||
B om = c->v;
|
||||
@ -129,7 +129,7 @@ B wm2_c1(B d, B x) { B f = c(Md2D,d)->f; B g = c(Md2D,d)->g; B t = c(Md2D,d)->m2
|
||||
fwTotal = pfwt + e-s + 30;
|
||||
return r;
|
||||
}
|
||||
B wm2_c2(B d, B w, B x) { B f = c(Md2D,d)->f; B g = c(Md2D,d)->g; B t = c(Md2D,d)->m2;
|
||||
B wm2_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g; B t = d->m2;
|
||||
u64 pfwt=fwTotal; fwTotal = 0;
|
||||
WMd1* c = c(WMd1,t);
|
||||
B om = c->v;
|
||||
|
||||
@ -7,13 +7,13 @@ static inline B hmv(HArr_p p, usz n) { B r = p.a[n]; p.a[n] = m_f64(0); return r
|
||||
static B eachd_fn(BBB2B f, B fo, B w, B x) { // consumes w,x; assumes at least one is array
|
||||
if (isAtm(w)) w = m_atomUnit(w);
|
||||
if (isAtm(x)) x = m_atomUnit(x);
|
||||
ur wr = rnk(w); BS2B wget = TI(w,get);
|
||||
ur xr = rnk(x); BS2B xget = TI(x,get);
|
||||
ur wr = rnk(w); SGet(w);
|
||||
ur xr = rnk(x); SGet(x);
|
||||
bool wg = wr>xr;
|
||||
ur rM = wg? wr : xr;
|
||||
ur rm = wg? xr : wr;
|
||||
if (rM==0) {
|
||||
B r = f(fo, wget(w,0), xget(x,0));
|
||||
B r = f(fo, Get(w,0), Get(x,0));
|
||||
dec(w); dec(x);
|
||||
return m_hunit(r);
|
||||
}
|
||||
@ -23,12 +23,12 @@ static B eachd_fn(BBB2B f, B fo, B w, B x) { // consumes w,x; assumes at least o
|
||||
if (rw|rx && (wr==xr | rm==0)) {
|
||||
HArr_p r = harr_parts(rw? w : x);
|
||||
usz ria = r.c->ia;
|
||||
if (wr==0) { B c=wget(w, 0); for(usz i = 0; i < ria; i++) r.a[i] = f(fo, inc(c), hmv(r,i)); dec(c); }
|
||||
else if (xr==0) { B c=xget(x, 0); for(usz i = 0; i < ria; i++) r.a[i] = f(fo, hmv(r,i), inc(c) ); dec(c); }
|
||||
if (wr==0) { B c=Get(w, 0); for(usz i = 0; i < ria; i++) r.a[i] = f(fo, inc(c), hmv(r,i)); dec(c); }
|
||||
else if (xr==0) { B c=Get(x, 0); for(usz i = 0; i < ria; i++) r.a[i] = f(fo, hmv(r,i), inc(c) ); dec(c); }
|
||||
else {
|
||||
assert(wr==xr);
|
||||
if (rw) for (usz i = 0; i < ria; i++) r.a[i] = f(fo, hmv(r,i), xget(x,i));
|
||||
else for (usz i = 0; i < ria; i++) r.a[i] = f(fo, wget(w,i), hmv(r,i));
|
||||
if (rw) for (usz i = 0; i < ria; i++) r.a[i] = f(fo, hmv(r,i), Get(x,i));
|
||||
else for (usz i = 0; i < ria; i++) r.a[i] = f(fo, Get(w,i), hmv(r,i));
|
||||
}
|
||||
dec(rw? x : w);
|
||||
return r.b;
|
||||
@ -38,14 +38,14 @@ static B eachd_fn(BBB2B f, B fo, B w, B x) { // consumes w,x; assumes at least o
|
||||
usz ria = a(bo)->ia;
|
||||
usz ri = 0;
|
||||
HArr_p r = m_harrs(ria, &ri);
|
||||
if (wr==xr) for(; ri < ria; ri++) r.a[ri] = f(fo, wget(w,ri), xget(x,ri));
|
||||
else if (wr==0) { B c=wget(w, 0); for(; ri < ria; ri++) r.a[ri] = f(fo, inc(c) , xget(x,ri)); dec(c); }
|
||||
else if (xr==0) { B c=xget(x, 0); for(; ri < ria; ri++) r.a[ri] = f(fo, wget(w,ri), inc(c) ); dec(c); }
|
||||
if (wr==xr) for(; ri < ria; ri++) r.a[ri] = f(fo, Get(w,ri), Get(x,ri));
|
||||
else if (wr==0) { B c=Get(w, 0); for(; ri < ria; ri++) r.a[ri] = f(fo, inc(c) , Get(x,ri)); dec(c); }
|
||||
else if (xr==0) { B c=Get(x, 0); for(; ri < ria; ri++) r.a[ri] = f(fo, Get(w,ri), inc(c) ); dec(c); }
|
||||
else if (ria>0) {
|
||||
usz min = wg? a(x)->ia : a(w)->ia;
|
||||
usz ext = ria / min;
|
||||
if (wg) for (usz i = 0; i < min; i++) { B c=xget(x,i); for (usz j = 0; j < ext; j++,ri++) r.a[ri] = f(fo, wget(w,ri), inc(c)); }
|
||||
else for (usz i = 0; i < min; i++) { B c=wget(w,i); for (usz j = 0; j < ext; j++,ri++) r.a[ri] = f(fo, inc(c), xget(x,ri)); }
|
||||
if (wg) for (usz i = 0; i < min; i++) { B c=Get(x,i); for (usz j = 0; j < ext; j++,ri++) r.a[ri] = f(fo, Get(w,ri), inc(c)); }
|
||||
else for (usz i = 0; i < min; i++) { B c=Get(w,i); for (usz j = 0; j < ext; j++,ri++) r.a[ri] = f(fo, inc(c), Get(x,ri)); }
|
||||
}
|
||||
B rb = harr_fc(r, bo);
|
||||
dec(w); dec(x);
|
||||
@ -55,9 +55,9 @@ static B eachd_fn(BBB2B f, B fo, B w, B x) { // consumes w,x; assumes at least o
|
||||
static B eachm_fn(BB2B f, B fo, B x) { // consumes x; x must be array
|
||||
usz ia = a(x)->ia;
|
||||
if (ia==0) return x;
|
||||
BS2B xget = TI(x,get);
|
||||
SGet(x);
|
||||
usz i = 0;
|
||||
B cr = f(fo, xget(x,0));
|
||||
B cr = f(fo, Get(x,0));
|
||||
HArr_p rH;
|
||||
if (TI(x,canStore)(cr)) {
|
||||
bool reuse = reusable(x);
|
||||
@ -129,7 +129,7 @@ static B eachm_fn(BB2B f, B fo, B x) { // consumes x; x must be array
|
||||
rH = m_harrs(ia, &i);
|
||||
fallback:
|
||||
rH.a[i++] = cr;
|
||||
for (; i < ia; i++) rH.a[i] = f(fo, xget(x,i));
|
||||
for (; i < ia; i++) rH.a[i] = f(fo, Get(x,i));
|
||||
return harr_fcd(rH, x);
|
||||
}
|
||||
|
||||
|
||||
@ -73,21 +73,21 @@ B file_lines(B path) { // consumes
|
||||
B path_resolve(B base, B rel) { // consumes rel; assumes base is a char vector or bi_N
|
||||
assert((isArr(base) || q_N(base)));
|
||||
if (!isArr(rel) || rnk(rel)!=1) thrM("Paths must be character vectors");
|
||||
BS2B rgetU = TI(rel,getU);
|
||||
SGetU(rel)
|
||||
usz ria = a(rel)->ia;
|
||||
if (rnk(rel)!=1) thrM("Paths must be character vectors");
|
||||
for (usz i = 0; i < ria; i++) if (!isC32(rgetU(rel, i))) thrM("Paths must be character vectors");
|
||||
if (ria>0 && o2cu(rgetU(rel, 0))=='/') return rel;
|
||||
for (usz i = 0; i < ria; i++) if (!isC32(GetU(rel, i))) thrM("Paths must be character vectors");
|
||||
if (ria>0 && o2cu(GetU(rel, 0))=='/') return rel;
|
||||
if (q_N(base)) thrM("Using relative path with no absolute base path known");
|
||||
if (ria==0) { dec(rel); return inc(base); }
|
||||
BS2B bgetU = TI(base,getU);
|
||||
SGetU(base)
|
||||
usz bia = a(base)->ia;
|
||||
bool has = bia && o2cu(bgetU(base, bia-1))=='/';
|
||||
bool has = bia && o2cu(GetU(base, bia-1))=='/';
|
||||
u32* rp; B r = m_c32arrv(&rp, bia+ria+(has?0:1));
|
||||
usz ri = 0;
|
||||
for (usz i = 0; i < bia-(has?1:0); i++) rp[ri++] = o2cu(bgetU(base, i));
|
||||
for (usz i = 0; i < bia-(has?1:0); i++) rp[ri++] = o2cu(GetU(base, i));
|
||||
rp[ri++] = '/';
|
||||
for (usz i = 0; i < ria; i++) rp[ri++] = o2cu(rgetU(rel, i));
|
||||
for (usz i = 0; i < ria; i++) rp[ri++] = o2cu(GetU(rel, i));
|
||||
dec(rel);
|
||||
return r;
|
||||
}
|
||||
@ -95,12 +95,12 @@ B path_resolve(B base, B rel) { // consumes rel; assumes base is a char vector o
|
||||
B path_dir(B path) { // consumes; returns directory part of file path with trailing slash, or ·
|
||||
assert(isArr(path) || q_N(path));
|
||||
if (q_N(path)) return path;
|
||||
BS2B pgetU = TI(path,getU);
|
||||
SGetU(path)
|
||||
usz pia = a(path)->ia;
|
||||
if (pia==0) thrM("Empty file path");
|
||||
for (usz i = 0; i < pia; i++) if (!isC32(pgetU(path, i))) thrM("Paths must be character vectors");
|
||||
for (usz i = 0; i < pia; i++) if (!isC32(GetU(path, i))) thrM("Paths must be character vectors");
|
||||
for (i64 i = (i64)pia-1; i >= 0; i--) {
|
||||
if (o2cu(pgetU(path, i))=='/') {
|
||||
if (o2cu(GetU(path, i))=='/') {
|
||||
Arr* r = TI(path,slice)(path, 0, i+1); arr_shVec(r);
|
||||
return taga(r);
|
||||
}
|
||||
@ -143,8 +143,8 @@ void file_wBytes(B path, B x) { // consumes path
|
||||
|
||||
u64 len = a(x)->ia;
|
||||
TALLOC(char, val, len);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (u64 i = 0; i < len; i++) val[i] = o2i(xgetU(x,i));
|
||||
SGetU(x)
|
||||
for (u64 i = 0; i < len; i++) val[i] = o2i(GetU(x,i));
|
||||
|
||||
if (fwrite(val, 1, len, f) != len) thrF("Error writing to file \"%R\"", path);
|
||||
TFREE(val);
|
||||
|
||||
@ -27,8 +27,8 @@ static u64 bqn_hash(B x, const u64 secret[4]) { // doesn't consume
|
||||
else {
|
||||
assert(xe==el_B);
|
||||
TALLOC(u64, data, xia);
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (usz i = 0; i < xia; i++) data[i] = bqn_hash(xgetU(x, i), secret);
|
||||
SGetU(x)
|
||||
for (usz i = 0; i < xia; i++) data[i] = bqn_hash(GetU(x, i), secret);
|
||||
r = wyhash(data, xia*8, shHash, secret);
|
||||
TFREE(data);
|
||||
}
|
||||
|
||||
@ -210,8 +210,8 @@ static void mut_copyG(Mut* m, usz ms, B x, usz xs, usz l) { assert(isArr(x));
|
||||
for (usz i = 0; i < l; i++) inc(mpo[i]);
|
||||
return;
|
||||
}
|
||||
BS2B xget = TIi(xt,get);
|
||||
for (usz i = 0; i < l; i++) mpo[i] = xget(x,i+xs);
|
||||
SGet(x)
|
||||
for (usz i = 0; i < l; i++) mpo[i] = Get(x,i+xs);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -259,8 +259,8 @@ static B vec_join(B w, B x) { // consumes both
|
||||
else if (xe==el_c32) { u32* xp=c32any_ptr(x); for (usz i=0; i<xia; i++) rp[i] = m_c32(xp[i]); }
|
||||
else if (xe==el_f64) { f64* xp=f64any_ptr(x); for (usz i=0; i<xia; i++) rp[i] = m_f64(xp[i]); }
|
||||
else {
|
||||
BS2B xget = TI(x,get);
|
||||
for (usz i = 0; i < xia; i++) rp[i] = xget(x, i);
|
||||
SGet(x)
|
||||
for (usz i = 0; i < xia; i++) rp[i] = Get(x, i);
|
||||
}
|
||||
dec(x);
|
||||
return w;
|
||||
|
||||
@ -53,20 +53,20 @@ void printUTF8(u32 c) {
|
||||
|
||||
u64 utf8lenB(B x) { // doesn't consume; may error as it verifies whether is all chars
|
||||
assert(isArr(x));
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
usz ia = a(x)->ia;
|
||||
u64 res = 0;
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
u32 c = o2c(xgetU(x,i));
|
||||
u32 c = o2c(GetU(x,i));
|
||||
res+= c<128? 1 : c<0x07FF? 2 : c<0xFFFF? 3 : 4;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
void toUTF8(B x, char* p) {
|
||||
BS2B xgetU = TI(x,getU);
|
||||
SGetU(x)
|
||||
usz ia = a(x)->ia;
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
u32 c = o2cu(xgetU(x,i));
|
||||
u32 c = o2cu(GetU(x,i));
|
||||
if (c<128) { *p++ = c; }
|
||||
else if (c<=0x07FF) { *p++ = 0xC0|c>>6 ; *p++ = 0x80|(c &0x3F); }
|
||||
else if (c<=0xFFFF) { *p++ = 0xE0|c>>12; *p++ = 0x80|(c>>6 &0x3F);*p++ = 0x80|(c &0x3F); }
|
||||
|
||||
88
src/vm.c
88
src/vm.c
@ -153,25 +153,25 @@ typedef struct SETHRequest {
|
||||
Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBlocks, B allBodies, B nameList, Scope* sc, i32 depth) {
|
||||
usz blIA = a(block)->ia;
|
||||
if (blIA!=3) thrM("VM compiler: Bad block info size");
|
||||
BS2B blGetU = TI(block,getU);
|
||||
usz ty = o2s(blGetU(block,0)); if (ty>2) thrM("VM compiler: Bad type");
|
||||
bool imm = o2b(blGetU(block,1));
|
||||
B bodyObj = blGetU(block,2);
|
||||
SGetU(block)
|
||||
usz ty = o2s(GetU(block,0)); if (ty>2) thrM("VM compiler: Bad type");
|
||||
bool imm = o2b(GetU(block,1));
|
||||
B bodyObj = GetU(block,2);
|
||||
i32* bodyI;
|
||||
i32 bodyAm1, bodyAm2, bodyILen;
|
||||
if (isArr(bodyObj)) {
|
||||
if (a(bodyObj)->ia!=2) thrM("VM compiler: Unexpected body list length");
|
||||
// print(bodyObj); putchar('\n');
|
||||
BS2B boGetU = TI(bodyObj,getU);
|
||||
B b1 = boGetU(bodyObj,0);
|
||||
B b2 = boGetU(bodyObj,1);
|
||||
SGetU(bodyObj)
|
||||
B b1 = GetU(bodyObj,0);
|
||||
B b2 = GetU(bodyObj,1);
|
||||
if (!isArr(b1) || !isArr(b2)) thrM("VM compiler: Body list contained non-arrays");
|
||||
bodyAm1 = a(b1)->ia; BS2B b1GetU = TI(b1,getU);
|
||||
bodyAm2 = a(b2)->ia; BS2B b2GetU = TI(b2,getU);
|
||||
bodyAm1 = a(b1)->ia; SGetU(b1)
|
||||
bodyAm2 = a(b2)->ia; SGetU(b2)
|
||||
bodyILen = bodyAm1+bodyAm2;
|
||||
TALLOC(i32, bodyInds_, bodyILen+2); bodyI = bodyInds_; i32* bodyI2 = bodyInds_+bodyAm1+1;
|
||||
for (i32 i = 0; i < bodyAm1; i++) bodyI [i] = o2i(b1GetU(b1, i));
|
||||
for (i32 i = 0; i < bodyAm2; i++) bodyI2[i] = o2i(b2GetU(b2, i));
|
||||
for (i32 i = 0; i < bodyAm1; i++) bodyI [i] = o2i(GetU(b1, i));
|
||||
for (i32 i = 0; i < bodyAm2; i++) bodyI2[i] = o2i(GetU(b2, i));
|
||||
for (i32 i = 1; i < bodyAm1; i++) if (bodyI [i]<=bodyI [i-1]) thrM("VM compiler: Expected body indices to be sorted");
|
||||
for (i32 i = 1; i < bodyAm2; i++) if (bodyI2[i]<=bodyI2[i-1]) thrM("VM compiler: Expected body indices to be sorted");
|
||||
bodyI[bodyAm1] = bodyI[bodyILen+1] = I32_MAX;
|
||||
@ -221,11 +221,11 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
|
||||
// printf("idxs: %d %d\n", index1, index2);
|
||||
|
||||
|
||||
B bodyRepr = TI(allBodies,getU)(allBodies, currBody); if (!isArr(bodyRepr)) thrM("VM compiler: Body array contained non-array");
|
||||
B bodyRepr = IGetU(allBodies, currBody); if (!isArr(bodyRepr)) thrM("VM compiler: Body array contained non-array");
|
||||
usz boIA = a(bodyRepr)->ia; if (boIA!=2 && boIA!=4) thrM("VM compiler: Body array had invalid length");
|
||||
BS2B biGetU = TI(bodyRepr,getU);
|
||||
usz idx = o2s(biGetU(bodyRepr,0)); if (idx>=bcIA) thrM("VM compiler: Bytecode index out of bounds");
|
||||
usz vam = o2s(biGetU(bodyRepr,1)); if (vam!=(u16)vam) thrM("VM compiler: >2⋆16 variables not supported"); // TODO any reason for this? 2⋆32 vars should just work, no? // oh, some size fields are u16s. but i doubt those change much, or even make things worse
|
||||
SGetU(bodyRepr)
|
||||
usz idx = o2s(GetU(bodyRepr,0)); if (idx>=bcIA) thrM("VM compiler: Bytecode index out of bounds");
|
||||
usz vam = o2s(GetU(bodyRepr,1)); if (vam!=(u16)vam) thrM("VM compiler: >2⋆16 variables not supported"); // TODO any reason for this? 2⋆32 vars should just work, no? // oh, some size fields are u16s. but i doubt those change much, or even make things worse
|
||||
|
||||
i32 h = 0; // stack height
|
||||
i32 hM = 0; // max stack height
|
||||
@ -245,10 +245,10 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
|
||||
memcpy(nE->vars+nSZ, oE->vars+oSZ, oSZ*sizeof(B));
|
||||
mm_free((Value*)oE);
|
||||
}
|
||||
B varIDs = biGetU(bodyRepr,2);
|
||||
B varIDs = GetU(bodyRepr,2);
|
||||
for (i32 i = oSZ; i < nSZ; i++) {
|
||||
nE->vars[i] = bi_noVar;
|
||||
nE->vars[i+nSZ] = TI(nameList,get)(nameList, o2s(TI(varIDs,getU)(varIDs, regAm+i)));
|
||||
nE->vars[i+nSZ] = IGet(nameList, o2s(IGetU(varIDs, regAm+i)));
|
||||
}
|
||||
sc->ext = nE;
|
||||
}
|
||||
@ -280,7 +280,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
|
||||
if ((u32)id >= a(allBlocks)->ia) thrM("VM compiler: DFND index out-of-bounds");
|
||||
if (bDone[id]) thrM("VM compiler: DFND of the same block in multiple places");
|
||||
bDone[id] = true;
|
||||
Block* bl = compileBlock(TI(allBlocks,getU)(allBlocks,id), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, depth+1);
|
||||
Block* bl = compileBlock(IGetU(allBlocks,id), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, depth+1);
|
||||
TSADD(newBC, bl->ty==0? DFND0 : bl->ty==1? DFND1 : DFND2);
|
||||
A64((u64)bl);
|
||||
TSADD(usedBlocks, bl);
|
||||
@ -329,7 +329,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
|
||||
|
||||
Body* body = m_body(vam, bcStart, hM, mpsc);
|
||||
if (boIA>2) {
|
||||
m_nsDesc(body, imm, ty, inc(nameList), biGetU(bodyRepr,2), biGetU(bodyRepr,3));
|
||||
m_nsDesc(body, imm, ty, inc(nameList), GetU(bodyRepr,2), GetU(bodyRepr,3));
|
||||
} else {
|
||||
body->nsDesc = NULL;
|
||||
for (u64 i = 0; i < vam; i++) body->varIDs[i] = -1;
|
||||
@ -408,21 +408,21 @@ NOINLINE Block* compile(B bcq, B objs, B allBlocks, B allBodies, B indices, B to
|
||||
if (q_N(tokenInfo)) {
|
||||
nameList = bi_emptyHVec;
|
||||
} else {
|
||||
B t = TI(tokenInfo,getU)(tokenInfo,2);
|
||||
nameList = TI(t,getU)(t,0);
|
||||
B t = IGetU(tokenInfo,2);
|
||||
nameList = IGetU(t,0);
|
||||
}
|
||||
if (!q_N(src) && !q_N(indices)) {
|
||||
if (isAtm(indices) || rnk(indices)!=1 || a(indices)->ia!=2) thrM("VM compiler: Bad indices");
|
||||
for (i32 i = 0; i < 2; i++) {
|
||||
B ind = TI(indices,getU)(indices,i);
|
||||
B ind = IGetU(indices,i);
|
||||
if (isAtm(ind) || rnk(ind)!=1 || a(ind)->ia!=bcIA) thrM("VM compiler: Bad indices");
|
||||
BS2B indGetU = TI(ind,getU);
|
||||
for (usz j = 0; j < bcIA; j++) o2i(indGetU(ind,j));
|
||||
SGetU(ind)
|
||||
for (usz j = 0; j < bcIA; j++) o2i(GetU(ind,j));
|
||||
}
|
||||
}
|
||||
TALLOC(bool,bDone,bIA);
|
||||
for (usz i = 0; i < bIA; i++) bDone[i] = false;
|
||||
Block* ret = compileBlock(TI(allBlocks,getU)(allBlocks, 0), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, 0);
|
||||
Block* ret = compileBlock(IGetU(allBlocks, 0), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, 0);
|
||||
TFREE(bDone);
|
||||
ptr_dec(comp); dec(allBlocks); dec(allBodies); dec(tokenInfo);
|
||||
return ret;
|
||||
@ -464,8 +464,8 @@ NOINLINE void v_setR(Scope* pscs[], B s, B x, bool upd) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (u64 i = 0; i < ia; i++) v_set(pscs, sp[i], xgetU(x,i), upd);
|
||||
SGetU(x)
|
||||
for (u64 i = 0; i < ia; i++) v_set(pscs, sp[i], GetU(x,i), upd);
|
||||
}
|
||||
}
|
||||
NOINLINE bool v_sethR(Scope* pscs[], B s, B x) {
|
||||
@ -493,8 +493,8 @@ NOINLINE bool v_sethR(Scope* pscs[], B s, B x) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
BS2B xgetU = TI(x,getU);
|
||||
for (u64 i = 0; i < ia; i++) if (!v_seth(pscs, sp[i], xgetU(x,i))) return false;
|
||||
SGetU(x)
|
||||
for (u64 i = 0; i < ia; i++) if (!v_seth(pscs, sp[i], GetU(x,i))) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -990,23 +990,23 @@ void popCatch() {
|
||||
}
|
||||
|
||||
NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes prepend
|
||||
BS2B srcGetU = TI(src,getU);
|
||||
SGetU(src)
|
||||
usz srcL = a(src)->ia;
|
||||
usz srcS = cs;
|
||||
while (srcS>0 && o2cu(srcGetU(src,srcS-1))!='\n') srcS--;
|
||||
while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--;
|
||||
usz srcE = srcS;
|
||||
while (srcE<srcL) { if(o2cu(srcGetU(src, srcE))=='\n') break; srcE++; }
|
||||
while (srcE<srcL) { if(o2cu(GetU(src, srcE))=='\n') break; srcE++; }
|
||||
if (ce>srcE) ce = srcE;
|
||||
|
||||
i64 ln = 1;
|
||||
for (usz i = 0; i < srcS; i++) if(o2cu(srcGetU(src, i))=='\n') ln++;
|
||||
for (usz i = 0; i < srcS; i++) if(o2cu(GetU(src, i))=='\n') ln++;
|
||||
B s = prepend;
|
||||
if (isArr(path) && (a(path)->ia>1 || (a(path)->ia==1 && TI(path,getU)(path,0).u!=m_c32('.').u))) AFMT("%R:%l:\n ", path, ln);
|
||||
if (isArr(path) && (a(path)->ia>1 || (a(path)->ia==1 && IGetU(path,0).u!=m_c32('.').u))) AFMT("%R:%l:\n ", path, ln);
|
||||
else AFMT("at ");
|
||||
i64 padEnd = (i64)a(s)->ia;
|
||||
i64 padStart = padEnd;
|
||||
BS2B sGetU = TI(s,getU);
|
||||
while (padStart>0 && o2cu(sGetU(s,padStart-1))!='\n') padStart--;
|
||||
SGetU(s)
|
||||
while (padStart>0 && o2cu(GetU(s,padStart-1))!='\n') padStart--;
|
||||
|
||||
Arr* slice = TI(src,slice)(inc(src),srcS, srcE-srcS); arr_shVec(slice);
|
||||
AJOIN(taga(slice));
|
||||
@ -1014,7 +1014,7 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p
|
||||
ce-= srcS;
|
||||
ACHR('\n');
|
||||
for (i64 i = padStart; i < padEnd; i++) ACHR(' ');
|
||||
for (u64 i = 0; i < cs; i++) ACHR(o2cu(srcGetU(src, srcS+i))=='\t'? '\t' : ' '); // ugh tabs
|
||||
for (u64 i = 0; i < cs; i++) ACHR(o2cu(GetU(src, srcS+i))=='\t'? '\t' : ' '); // ugh tabs
|
||||
for (u64 i = cs; i < ce; i++) ACHR('^');
|
||||
return s;
|
||||
}
|
||||
@ -1022,15 +1022,15 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p
|
||||
NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) {
|
||||
B src = comp->src;
|
||||
if (!q_N(src) && !q_N(comp->indices)) {
|
||||
B inds = TI(comp->indices,getU)(comp->indices, 0); usz cs = o2s(TI(inds,getU)(inds,bcPos));
|
||||
B inde = TI(comp->indices,getU)(comp->indices, 1); usz ce = o2s(TI(inde,getU)(inde,bcPos))+1;
|
||||
B inds = IGetU(comp->indices, 0); usz cs = o2s(IGetU(inds,bcPos));
|
||||
B inde = IGetU(comp->indices, 1); usz ce = o2s(IGetU(inde,bcPos))+1;
|
||||
// printf(" bcPos=%d\n", bcPos); // in case the pretty error generator is broken
|
||||
// printf(" inds:%d…%d\n", cs, ce);
|
||||
// int start = pos==-1? 0 : printf(N64d": ", pos);
|
||||
// usz srcL = a(src)->ia;
|
||||
// BS2B srcGetU = TI(src,getU);
|
||||
// usz srcS = cs; while (srcS>0 && o2cu(srcGetU(src,srcS-1))!='\n') srcS--;
|
||||
// usz srcE = srcS; while (srcE<srcL) { u32 chr = o2cu(srcGetU(src, srcE)); if(chr=='\n')break; printUTF8(chr); srcE++; }
|
||||
// SGetU(src)
|
||||
// usz srcS = cs; while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--;
|
||||
// usz srcE = srcS; while (srcE<srcL) { u32 chr = o2cu(GetU(src, srcE)); if(chr=='\n')break; printUTF8(chr); srcE++; }
|
||||
// if (ce>srcE) ce = srcE;
|
||||
// cs-= srcS; ce-= srcS;
|
||||
// putchar('\n');
|
||||
@ -1081,9 +1081,9 @@ void unwindCompiler() {
|
||||
|
||||
NOINLINE void printErrMsg(B msg) {
|
||||
if (isArr(msg)) {
|
||||
BS2B msgGetU = TI(msg,getU);
|
||||
SGetU(msg)
|
||||
usz msgLen = a(msg)->ia;
|
||||
for (usz i = 0; i < msgLen; i++) if (!isC32(msgGetU(msg,i))) goto base;
|
||||
for (usz i = 0; i < msgLen; i++) if (!isC32(GetU(msg,i))) goto base;
|
||||
printRaw(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user