From e6b4f85662bac0a83d8cd586abb420a7483db270 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 19 Aug 2022 22:46:24 +0300 Subject: [PATCH] =?UTF-8?q?x->ia=20=E2=86=92=20IA(x)=20/=20PIA(x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/README.md | 2 +- src/builtins/arithd.c | 20 ++++----- src/builtins/arithm.c | 4 +- src/builtins/cmp.c | 2 +- src/builtins/fns.c | 26 +++++------ src/builtins/grade.h | 6 +-- src/builtins/internal.c | 16 +++---- src/builtins/md1.c | 18 ++++---- src/builtins/md2.c | 12 ++--- src/builtins/select.c | 8 ++-- src/builtins/sfns.c | 96 ++++++++++++++++++++-------------------- src/builtins/sort.c | 4 +- src/builtins/squeeze.c | 8 ++-- src/builtins/sysfn.c | 52 +++++++++++----------- src/core/arrFns.h | 8 ++-- src/core/fillarr.c | 14 +++--- src/core/harr.c | 12 ++--- src/core/harr.h | 4 +- src/core/numarr.h | 4 +- src/core/stuff.c | 44 +++++++++--------- src/core/stuff.h | 2 +- src/core/tyarrTemplate.h | 4 +- src/ffi.c | 36 +++++++-------- src/h.h | 2 + src/jit/nvm_x86_64.c | 2 +- src/load.c | 14 +++--- src/main.c | 8 ++-- src/ns.c | 4 +- src/singeli/c/cmp.c | 2 +- src/utils/bits.c | 2 +- src/utils/each.c | 6 +-- src/utils/each.h | 4 +- src/utils/file.c | 12 ++--- src/utils/hash.c | 2 +- src/utils/mut.c | 12 ++--- src/utils/mut.h | 8 ++-- src/utils/utf.c | 6 +-- src/vm.c | 46 +++++++++---------- 38 files changed, 267 insertions(+), 265 deletions(-) diff --git a/src/README.md b/src/README.md index abdf7e20..b7314628 100644 --- a/src/README.md +++ b/src/README.md @@ -181,7 +181,7 @@ c(BMd2,bi_some2mod)->im = some2mod_im; // you get the idea ## Arrays -If you know that `x` is an array (e.g. by testing `isArr(x)` beforehand), `a(x)->ia` will give you the product of the shape (aka total element count), `rnk(x)` will give you the rank (use `prnk(x)` for an untagged pointer object), and `a(x)->sh` will give you a `usz*` to the full shape. +If you know that `x` is an array (e.g. by testing `isArr(x)` beforehand), `IA(x)` will give you the product of the shape (aka total element count), `rnk(x)` will give you the rank (use `prnk(x)` for an untagged pointer object), and `a(x)->sh` will give you a `usz*` to the full shape. The shape pointer of a rank 0 or 1 array will point to the object's own `ia` field. Otherwise, it'll point inside a `t_shape` object. diff --git a/src/builtins/arithd.c b/src/builtins/arithd.c index e37ffc6d..f7daf6cb 100644 --- a/src/builtins/arithd.c +++ b/src/builtins/arithd.c @@ -23,7 +23,7 @@ if (isArr(w)|isArr(x)) { B ow=w; B ox=x; \ if (isArr(w)&isArr(x) && rnk(w)==rnk(x)) { \ if (!eqShPart(a(w)->sh, a(x)->sh, rnk(w))) thrF(SYMB ": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \ - usz ia = a(x)->ia; \ + usz ia = IA(x); \ u8 we = TI(w,elType); \ u8 xe = TI(x,elType); \ if ((we==el_i32|we==el_f64)&(xe==el_i32|xe==el_f64)) { \ @@ -37,7 +37,7 @@ } \ decG(w); decG(x); return num_squeeze(r); \ } \ - } else if (isF64(w)&isArr(x)) { usz ia = a(x)->ia; \ + } else if (isF64(w)&isArr(x)) { usz ia = IA(x); \ u8 xe = TI(x,elType); f64*rp; \ if (xe==el_i32) { B r=m_f64arrc(&rp, x); i32*xp=i32any_ptr(x); \ for (usz i = 0; i < ia; i++) {B x/*shadow*/;x.f=xp[i];rp[i]=EXPR;} \ @@ -47,7 +47,7 @@ for (usz i = 0; i < ia; i++) {B x/*shadow*/;x.f=xp[i];rp[i]=EXPR;} \ decG(x); return num_squeeze(r); \ } \ - } else if (isF64(x)&isArr(w)) { usz ia = a(w)->ia; \ + } else if (isF64(x)&isArr(w)) { usz ia = IA(w); \ u8 we = TI(w,elType); f64*rp; \ if (we==el_i32) { B r=m_f64arrc(&rp, w); i32*wp=i32any_ptr(w); \ for (usz i = 0; i < ia; i++) {B w/*shadow*/;w.f=wp[i];rp[i]=EXPR;} \ @@ -89,7 +89,7 @@ static NOINLINE B bit_sel1Fn(BBB2B f, B w, B x, bool bitX) { // consumes both B b = bitX? x : w; u64* bp = bitarr_ptr(b); - usz ia = a(b)->ia; + usz ia = IA(b); bool b0 = ia? bp[0]&1 : 0; bool both = false; @@ -160,7 +160,7 @@ if (isArr(w)|isArr(x)) { \ if (isArr(w)&isArr(x) && rnk(w)==rnk(x)) { \ if (!eqShPart(a(w)->sh, a(x)->sh, rnk(w))) thrF(SYMB ": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \ - usz ia = a(x)->ia; \ + usz ia = IA(x); \ u8 we = TI(w,elType); \ u8 xe = TI(x,elType); \ if ((we==el_bit | xe==el_bit) && (we|xe)<=el_f64) { \ @@ -189,8 +189,8 @@ if(we==el_i16 & xe==el_i8 ) { PI16(w) PI8 (x) DOI16(EXPR,w,wp[i],xp[i],base) } \ if(we==el_i8 & xe==el_i16) { PI8 (w) PI16(x) DOI16(EXPR,w,wp[i],xp[i],base) } \ } \ - else if (isF64(w)&isArr(x)) { usz ia=a(x)->ia; u8 xe=TI(x,elType); DO_SA(NAME,EXPR) } \ - else if (isF64(x)&isArr(w)) { usz ia=a(w)->ia; u8 we=TI(w,elType); DO_AS(NAME,EXPR) } \ + else if (isF64(w)&isArr(x)) { usz ia=IA(x); u8 xe=TI(x,elType); DO_SA(NAME,EXPR) } \ + else if (isF64(x)&isArr(w)) { usz ia=IA(w); u8 we=TI(w,elType); DO_AS(NAME,EXPR) } \ base: P2(NAME) \ } \ thrM(SYMB ": Unexpected argument types"); \ @@ -267,7 +267,7 @@ GC2i("+", add, wv+xv, { if (isArr(w)&isC32(x) || isC32(w)&isArr(x)) { if (isArr(w)) { B t=w;w=x;x=t; } if (TI(x,elType) == el_i32) { u32 wv = o2cu(w); - i32* xp = i32any_ptr(x); usz xia = a(x)->ia; + i32* xp = i32any_ptr(x); usz xia = IA(x); u32* rp; B r = m_c32arrc(&rp, x); for (usz i = 0; i < xia; i++) { rp[i] = (u32)(xp[i]+(i32)wv); @@ -286,14 +286,14 @@ GC2i("-", sub, wv-xv, { if (isArr(w) && TI(w,elType)==el_c32) { if (isC32(x)) { i32 xv = (i32)o2cu(x); - u32* wp = c32any_ptr(w); usz wia = a(w)->ia; + u32* wp = c32any_ptr(w); usz wia = IA(w); i32* rp; B r = m_i32arrc(&rp, w); for (usz i = 0; i < wia; i++) rp[i] = (i32)wp[i] - xv; decG(w); return r; } if (isArr(x) && eqShape(w, x)) { - u32* wp = c32any_ptr(w); usz wia = a(w)->ia; + u32* wp = c32any_ptr(w); usz wia = IA(w); if (TI(x,elType)==el_i32) { u32* rp; B r = m_c32arrc(&rp, w); i32* xp = i32any_ptr(x); diff --git a/src/builtins/arithm.c b/src/builtins/arithm.c index d456f798..d01e3f60 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -14,7 +14,7 @@ static inline B arith_recm(BB2B f, B x) { B bit_negate(B x) { // consumes u64* xp = bitarr_ptr(x); u64* rp; B r = m_bitarrc(&rp, x); - usz ia = BIT_N(a(x)->ia); + usz ia = BIT_N(IA(x)); for (usz i = 0; i < ia; i++) rp[i] = ~xp[i]; decG(x); return r; @@ -24,7 +24,7 @@ B bit_negate(B x) { // consumes if (isF64(x)) { f64 v = x.f; return m_f64(FEXPR); } \ if (RARE(!isArr(x))) thrM(SYMB ": Expected argument to be a number"); \ u8 xe = TI(x,elType); \ - i64 sz = a(x)->ia; BX \ + i64 sz = IA(x); BX \ if (xe==el_i8) { i8 MAX=I8_MAX; i8 MIN=I8_MIN; i8* xp=i8any_ptr(x); i8* rp; B r=m_i8arrc(&rp,x); \ for (i64 i = 0; i < sz; i++) { i8 v = xp[i]; if (RARE(IBAD)) { decG(r); goto base; } rp[i] = IEXPR; } \ decG(x); (void)MIN;(void)MAX; return r; \ diff --git a/src/builtins/cmp.c b/src/builtins/cmp.c index 9f594f74..708033d8 100644 --- a/src/builtins/cmp.c +++ b/src/builtins/cmp.c @@ -9,7 +9,7 @@ #if SINGELI #include "../singeli/c/cmp.c" #else -#define AL(X) u64* rp; B r = m_bitarrc(&rp, X); usz ria=a(r)->ia; usz bia = BIT_N(ria); +#define AL(X) u64* rp; B r = m_bitarrc(&rp, X); usz ria=IA(r); usz bia = BIT_N(ria); #define CMP_IMPL(CHR, NAME, RNAME, PNAME, L, R, OP, FC, CF, BX) \ if (isF64(w)&isF64(x)) return m_i32(w.f OP x.f); \ if (isC32(w)&isC32(x)) return m_i32(w.u OP x.u); \ diff --git a/src/builtins/fns.c b/src/builtins/fns.c index bc899815..3814b537 100644 --- a/src/builtins/fns.c +++ b/src/builtins/fns.c @@ -43,7 +43,7 @@ B ud_c1(B t, B x) { return r; } SGetU(x) - usz xia = a(x)->ia; + usz xia = IA(x); 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]; @@ -124,7 +124,7 @@ B fne_c2(B t, B w, B x) { extern B rt_indexOf; B indexOf_c1(B t, B x) { if (isAtm(x)) thrM("⊐: 𝕩 cannot have rank 0"); - usz xia = a(x)->ia; + usz xia = IA(x); if (xia==0) { decG(x); return emptyIVec(); } if (rnk(x)==1 && TI(x,elType)==el_i32) { i32* xp = i32any_ptr(x); @@ -190,7 +190,7 @@ B indexOf_c2(B t, B w, B x) { if (!isArr(w) || rnk(w)==0) thrM("⊐: 𝕨 must have rank at least 1"); if (rnk(w)==1) { if (!isArr(x) || rnk(x)==0) { - usz wia = a(w)->ia; + usz wia = IA(w); B el = isArr(x)? IGetU(x,0) : x; i32 res = wia; if (TI(w,elType)==el_i32) { @@ -213,8 +213,8 @@ B indexOf_c2(B t, B w, B x) { rp[0] = res; return taga(r); } else { - usz wia = a(w)->ia; - usz xia = a(x)->ia; + usz wia = IA(w); + usz xia = IA(x); // TODO O(wia×xia) for small wia or xia i32* rp; B r = m_i32arrc(&rp, x); H_b2i* map = m_b2i(64); @@ -238,7 +238,7 @@ extern B rt_memberOf; B memberOf_c1(B t, B x) { if (isAtm(x) || rnk(x)==0) thrM("∊: Argument cannot have rank 0"); if (rnk(x)!=1) x = toCells(x); - usz xia = a(x)->ia; + usz xia = IA(x); u64* rp; B r = m_bitarrv(&rp, xia); H_Sb* set = m_Sb(64); @@ -264,7 +264,7 @@ B memberOf_c2(B t, B w, B x) { B r; single: { - usz xia = a(x)->ia; + usz xia = IA(x); SGetU(x) for (usz i = 0; i < xia; i++) if (equal(GetU(x, i), w)) { r = inc(enclosed_1); goto dec_wx; } r = inc(enclosed_0); @@ -274,8 +274,8 @@ B memberOf_c2(B t, B w, B x) { many: { - usz xia = a(x)->ia; - usz wia = a(w)->ia; + usz xia = IA(x); + usz wia = IA(w); // TODO O(wia×xia) for small wia or xia H_Sb* set = m_Sb(64); SGetU(x) SGetU(w) @@ -295,7 +295,7 @@ B memberOf_c2(B t, B w, B x) { extern B rt_find; B find_c1(B t, B x) { if (isAtm(x) || rnk(x)==0) thrM("⍷: Argument cannot have rank 0"); - usz xia = a(x)->ia; + usz xia = IA(x); B xf = getFillQ(x); if (rnk(x)!=1) return c1(rt_find, x); @@ -317,7 +317,7 @@ extern B rt_count; B count_c1(B t, B x) { if (isAtm(x) || rnk(x)==0) thrM("⊒: Argument cannot have rank 0"); if (rnk(x)>1) x = toCells(x); - usz xia = a(x)->ia; + usz xia = IA(x); i32* rp; B r = m_i32arrv(&rp, xia); H_b2i* map = m_b2i(64); SGetU(x) @@ -359,10 +359,10 @@ i32 str2gid(B s) { } bool had; u64 p = mk_b2i(&globalNames, s, &had); - // if(had) print_fmt("str2gid %R → %i\n", s, globalNames->a[p].val); else print_fmt("str2gid %R → %i!!\n", s, a(globalNameList)->ia); + // if(had) print_fmt("str2gid %R → %i\n", s, globalNames->a[p].val); else print_fmt("str2gid %R → %i!!\n", s, IA(globalNameList)); if(had) return globalNames->a[p].val; - i32 r = a(globalNameList)->ia; + i32 r = IA(globalNameList); globalNameList = vec_addN(globalNameList, inc(s)); globalNames->a[p].val = r; return r; diff --git a/src/builtins/grade.h b/src/builtins/grade.h index 628c51ac..c5b5b0fb 100644 --- a/src/builtins/grade.h +++ b/src/builtins/grade.h @@ -13,7 +13,7 @@ B GRADE_CAT(c1)(B t, B x) { if (isAtm(x) || rnk(x)==0) thrM(GRADE_CHR": Argument cannot be a unit"); if (rnk(x)>1) x = toCells(x); - usz ia = a(x)->ia; + usz ia = IA(x); if (ia>I32_MAX) thrM(GRADE_CHR": Argument too large"); if (ia==0) { decG(x); return emptyIVec(); } @@ -107,8 +107,8 @@ B GRADE_CAT(c2)(B t, B w, B x) { w = toCells(w); xr = 1; } - u8 we = TI(w,elType); usz wia = a(w)->ia; - u8 xe = TI(x,elType); usz xia = a(x)->ia; + u8 we = TI(w,elType); usz wia = IA(w); + u8 xe = TI(x,elType); usz xia = IA(x); if (wia>I32_MAX-10) thrM(GRADE_CHR": 𝕨 too big"); i32* rp; B r = m_i32arrc(&rp, x); diff --git a/src/builtins/internal.c b/src/builtins/internal.c index 2bd41a34..6cea9802 100644 --- a/src/builtins/internal.c +++ b/src/builtins/internal.c @@ -88,7 +88,7 @@ B listVariations_c2(B t, B w, B x) { if (!isArr(x)) thrM("•internal.ListVariations: 𝕩 must be an array"); if (!isArr(w) || rnk(w)!=1) thrM("•internal.ListVariations: 𝕨 must be a list"); - usz wia = a(w)->ia; + usz wia = IA(w); SGetU(w) bool c_incr=false, c_rmFill=false; for (usz i = 0; i < wia; i++) { @@ -104,7 +104,7 @@ B listVariations_c2(B t, B w, B x) { bool ah = c_rmFill || noFill(xf); bool ai8=false, ai16=false, ai32=false, af64=false, ac8=false, ac16=false, ac32=false, abit=false; - usz xia = a(x)->ia; + usz xia = IA(x); SGetU(x) if (isNum(xf)) { i32 min=I32_MAX, max=I32_MIN; @@ -174,11 +174,11 @@ static void variation_gcRoot() { B variation_c2(B t, B w, B x) { if (!isArr(w)) thrM("•internal.Variation: Non-array 𝕨"); if (!isArr(x)) thrM("•internal.Variation: Non-array 𝕩"); - usz xia = a(x)->ia; + usz xia = IA(x); C8Arr* wc = toC8Arr(w); u8* wp = c8arrv_ptr(wc); - u8* wpE = wp+wc->ia; - if (wc->ia==0) thrM("•internal.Variation: Zero-length 𝕨"); + u8* wpE = wp+PIA(wc); + if (PIA(wc)==0) thrM("•internal.Variation: Zero-length 𝕨"); B res; if (*wp == 'A' || *wp == 'S') { bool slice = *wp == 'S'; @@ -212,7 +212,7 @@ B variation_c2(B t, B w, B x) { } else thrF("•internal.Variation: Bad type \"%R\"", taga(wc)); if (slice) { - Arr* slice = TI(res,slice)(inc(res), 0, a(res)->ia); + Arr* slice = TI(res,slice)(inc(res), 0, IA(res)); arr_shCopy(slice, res); dec(res); res = taga(slice); @@ -234,7 +234,7 @@ B variation_c2(B t, B w, B x) { B clearRefs_c1(B t, B x) { dec(x); if (!isArr(variation_refs)) return m_f64(0); - usz res = a(variation_refs)->ia; + usz res = IA(variation_refs); dec(variation_refs); variation_refs = m_f64(0); return m_f64(res); @@ -242,7 +242,7 @@ B clearRefs_c1(B t, B x) { static B unshare(B x) { if (!isArr(x)) return x; - usz xia = a(x)->ia; + usz xia = IA(x); switch (v(x)->type) { case t_bitarr: return taga(cpyBitArr(inc(x))); case t_i8arr: return taga(cpyI8Arr (inc(x))); diff --git a/src/builtins/md1.c b/src/builtins/md1.c index b1a2e8a7..f57f3e66 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -51,8 +51,8 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f; if (EACH_FILLS) xf = getFillQ(x); if (isAtm(w)) w = m_atomUnit(w); if (isAtm(x)) x = m_atomUnit(x); - ur wr = rnk(w); usz wia = a(w)->ia; - ur xr = rnk(x); usz xia = a(x)->ia; + ur wr = rnk(w); usz wia = IA(w); + ur xr = rnk(x); usz xia = IA(x); ur rr = wr+xr; usz ria = uszMul(wia, xia); if (rrf; if (isAtm(x) || rnk(x)==0) thrM("`: Argument cannot have rank 0"); ur xr = rnk(x); - usz ia = a(x)->ia; + usz ia = IA(x); if (ia==0) return x; B xf = getFillQ(x); u8 xe = TI(x,elType); @@ -231,7 +231,7 @@ B scan_c1(Md1D* d, B x) { B f = d->f; } B scan_c2(Md1D* d, B w, B x) { B f = d->f; if (isAtm(x) || rnk(x)==0) thrM("`: 𝕩 cannot have rank 0"); - ur xr = rnk(x); usz* xsh = a(x)->sh; usz ia = a(x)->ia; + ur xr = rnk(x); usz* xsh = a(x)->sh; usz ia = IA(x); B wf = getFillQ(w); u8 xe = TI(x,elType); if (xr==1 && q_i32(w) && xeflags) { @@ -294,7 +294,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f; B fold_c1(Md1D* d, B x) { B f = d->f; if (isAtm(x) || rnk(x)!=1) thrF("´: Argument must be a list (%H ≡ ≢𝕩)", x); - usz ia = a(x)->ia; + usz ia = IA(x); if (ia==0) { decG(x); if (isFun(f)) { @@ -363,7 +363,7 @@ B fold_c1(Md1D* d, B x) { B f = d->f; } B fold_c2(Md1D* d, B w, B x) { B f = d->f; if (isAtm(x) || rnk(x)!=1) thrF("´: 𝕩 must be a list (%H ≡ ≢𝕩)", x); - usz ia = a(x)->ia; + usz ia = IA(x); u8 xe = TI(x,elType); if (q_i32(w) && isFun(f) && v(f)->flags && xef; return isAtm(r)? m_atomUnit(r) : r; } - if (Q_BI(f,lt) && a(x)->ia!=0 && rnk(x)>1) return toCells(x); + if (Q_BI(f,lt) && IA(x)!=0 && rnk(x)>1) return toCells(x); usz cam = a(x)->sh[0]; if (cam==0) { @@ -567,7 +567,7 @@ B cell_c2(Md1D* d, B w, B x) { B f = d->f; extern B rt_insert; B insert_c1(Md1D* d, B x) { B f = d->f; if (isAtm(x) || rnk(x)==0) thrM("˝: 𝕩 must have rank at least 1"); - usz xia = a(x)->ia; + usz xia = IA(x); if (xia==0) return m1c1(rt_insert, f, x); if (rnk(x)==1 && isFun(f) && isPervasiveDy(f)) { return m_atomUnit(fold_c1(d, x)); @@ -585,7 +585,7 @@ B insert_c1(Md1D* d, B x) { B f = d->f; } B insert_c2(Md1D* d, B w, B x) { B f = d->f; if (isAtm(x) || rnk(x)==0) thrM("˝: 𝕩 must have rank at least 1"); - usz xia = a(x)->ia; + usz xia = IA(x); B r = w; if (xia!=0) { S_SLICES(x) diff --git a/src/builtins/md2.c b/src/builtins/md2.c index a5cd4218..056667e8 100644 --- a/src/builtins/md2.c +++ b/src/builtins/md2.c @@ -61,7 +61,7 @@ extern B rt_undo; void repeat_bounds(i64* bound, B g) { // doesn't consume if (isArr(g)) { SGetU(g) - usz ia = a(g)->ia; + usz ia = IA(g); for (usz i = 0; i < ia; i++) repeat_bounds(bound, GetU(g, i)); } else if (isNum(g)) { i64 i = o2i64(g); @@ -72,7 +72,7 @@ void repeat_bounds(i64* bound, B g) { // doesn't consume B repeat_replace(B g, B* q) { // doesn't consume if (isArr(g)) { SGetU(g) - usz ia = a(g)->ia; + usz ia = IA(g); M_HARR(r, ia); for (usz i = 0; i < ia; i++) HARR_ADD(r, i, repeat_replace(GetU(g,i), q)); return HARR_FC(r, g); @@ -134,7 +134,7 @@ B cond_c1(Md2D* d, B x) { B f=d->f; B g=d->g; B fr = c1iX(f, x); if (isNum(fr)) { if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1"); - usz fri = WRAP(o2i64(fr), a(g)->ia, thrM("◶: 𝔽 out of bounds of 𝕘")); + usz fri = WRAP(o2i64(fr), IA(g), thrM("◶: 𝔽 out of bounds of 𝕘")); return c1(IGetU(g, fri), x); } else { B fn = pick_c2(m_f64(0), fr, inc(g)); @@ -147,7 +147,7 @@ B cond_c2(Md2D* d, B w, B x) { B g=d->g; B fr = c2iWX(d->f, w, x); if (isNum(fr)) { if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1"); - usz fri = WRAP(o2i64(fr), a(g)->ia, thrM("◶: 𝔽 out of bounds of 𝕘")); + usz fri = WRAP(o2i64(fr), IA(g), thrM("◶: 𝔽 out of bounds of 𝕘")); return c2(IGetU(g, fri), w, x); } else { B fn = pick_c2(m_f64(0), fr, inc(g)); @@ -207,7 +207,7 @@ static f64 req_whole(f64 f) { } static usz check_rank_vec(B g) { if (!isArr(g)) thrM("⎉: Invalid 𝔾 result"); - usz gia = a(g)->ia; + usz gia = IA(g); if (!(gia>=1 && gia<=3)) thrM("⎉: 𝔾 result must have 1 to 3 elements"); SGetU(g) if (TI(g,elType)>=el_f64) for (i32 i = 0; i < gia; i++) req_whole(o2f(GetU(g,i))); @@ -295,7 +295,7 @@ B rank_c1(Md2D* d, B x) { B f = d->f; B g = d->g; i32 xr = rnk(x); ur cr = cell_rank(xr, kf); i32 k = xr - cr; - if (Q_BI(f,lt) && a(x)->ia!=0 && rnk(x)>1) return toKCells(x, k); + if (Q_BI(f,lt) && IA(x)!=0 && rnk(x)>1) return toKCells(x, k); usz* xsh = a(x)->sh; usz cam = shProd(xsh, 0, k); diff --git a/src/builtins/select.c b/src/builtins/select.c index 85781311..e0769cea 100644 --- a/src/builtins/select.c +++ b/src/builtins/select.c @@ -39,7 +39,7 @@ B select_c2(B t, B w, B x) { } B xf = getFillQ(x); SGet(x) - usz wia = a(w)->ia; + usz wia = IA(w); B r; if (xr==1) { @@ -62,7 +62,7 @@ B select_c2(B t, B w, B x) { decG(w); return r; } - usz xia = a(x)->ia; + usz xia = IA(x); u8 xe = TI(x,elType); u8 we = TI(w,elType); #if SINGELI @@ -164,8 +164,8 @@ B select_c2(B t, B w, B x) { B select_ucw(B t, B o, B w, B x) { if (isAtm(x) || rnk(x)!=1 || isAtm(w)) return def_fn_ucw(t, o, w, x); - usz xia = a(x)->ia; - usz wia = a(w)->ia; + usz xia = IA(x); + usz wia = IA(w); 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)); diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 74d19ab4..371a3872 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -5,7 +5,7 @@ #include "../builtins.h" static Arr* take_impl(usz ria, B x) { // consumes x; returns v↑⥊𝕩 without set shape; v is non-negative - usz xia = a(x)->ia; + usz xia = IA(x); if (ria>xia) { B xf = getFillE(x); MAKE_MUT(r, ria); mut_init(r, el_or(TI(x,elType), selfElType(xf))); @@ -85,7 +85,7 @@ B pair_c2(B t, B w, B x) { return m_vec2Base(w, x, true); } B shape_c1(B t, B x) { if (isAtm(x)) return m_vec1(x); if (rnk(x)==1) return x; - usz ia = a(x)->ia; + usz ia = IA(x); if (ia==1 && TI(x,elType)ia : 1; + usz xia = isArr(x)? IA(x) : 1; usz nia = 1; ur nr; ShArr* sh; @@ -116,8 +116,8 @@ B shape_c2(B t, B w, B x) { } else { if (isAtm(w)) w = m_atomUnit(w); if (rnk(w)>1) thrM("⥊: 𝕨 must have rank at most 1"); - if (a(w)->ia>UR_MAX) thrM("⥊: Result rank too large"); - nr = a(w)->ia; + if (IA(w)>UR_MAX) thrM("⥊: Result rank too large"); + nr = IA(w); sh = nr<=1? NULL : m_shArr(nr); if (TI(w,elType)==el_i32) { i32* wi = i32any_ptr(w); @@ -243,7 +243,7 @@ B shape_c2(B t, B w, B x) { extern B rt_pick; B pick_c1(B t, B x) { if (isAtm(x)) return x; - if (RARE(a(x)->ia==0)) { + if (RARE(IA(x)==0)) { thrM("⊑: Argument cannot be empty"); // B r = getFillE(x); // dec(x); @@ -256,12 +256,12 @@ B pick_c1(B t, B x) { static NOINLINE void checkNumeric(B w) { SGetU(w) - usz ia = a(w)->ia; + usz ia = IA(w); for (usz i = 0; i < ia; i++) if (!isNum(GetU(w,i))) thrM("⊑: 𝕨 contained list with mixed-type elements"); } static B recPick(B w, B x) { // doesn't consume assert(isArr(w) && isArr(x)); - usz ia = a(w)->ia; + usz ia = IA(w); ur xr = rnk(x); usz* xsh = a(x)->sh; switch(TI(w,elType)) { default: UD; @@ -307,13 +307,13 @@ static B recPick(B w, B x) { // doesn't consume B pick_c2(B t, B w, B x) { if (RARE(isAtm(x))) { - if (isAtm(w) || rnk(w)!=1 || a(w)->ia!=0) return c2(rt_pick, w, x); // ugh this is such a lame case that'd need a whole another recursive fn to implement + if (isAtm(w) || rnk(w)!=1 || IA(w)!=0) return c2(rt_pick, w, x); // ugh this is such a lame case that'd need a whole another recursive fn to implement dec(w); return x; } if (isNum(w)) { if (rnk(x)!=1) thrF("⊑: 𝕩 must be a list when 𝕨 is a number (%H ≡ ≢𝕩)", x); - usz p = WRAP(o2i64(w), a(x)->ia, thrF("⊑: indexing out-of-bounds (𝕨≡%R, %s≡≠𝕩)", w, iaW)); + usz p = WRAP(o2i64(w), IA(x), thrF("⊑: indexing out-of-bounds (𝕨≡%R, %s≡≠𝕩)", w, iaW)); B r = IGet(x, p); decG(x); return r; @@ -430,9 +430,9 @@ B slash_c1(B t, B x) { if (RARE(isAtm(x)) || RARE(rnk(x)!=1)) thrF("/: Argument must have rank 1 (%H ≡ ≢𝕩)", x); u64 s = usum(x); if (s>=USZ_MAX) thrOOM(); - usz xia = a(x)->ia; + usz xia = IA(x); if (RARE(xia>=I32_MAX)) { - usz xia = a(x)->ia; + usz xia = IA(x); SGetU(x) f64* rp; B r = m_f64arrv(&rp, s); usz ri = 0; for (usz i = 0; i < xia; i++) { @@ -499,8 +499,8 @@ B slash_c1(B t, B x) { B slash_c2(B t, B w, B x) { if (isArr(x) && rnk(x)==1 && isArr(w) && rnk(w)==1 && depth(w)==1) { - usz wia = a(w)->ia; - usz xia = a(x)->ia; + usz wia = IA(w); + usz xia = IA(x); if (RARE(wia!=xia)) { if (wia==0) { decG(w); return x; } thrF("/: Lengths of components of 𝕨 must match 𝕩 (%s ≠ %s)", wia, xia); @@ -643,7 +643,7 @@ B slash_c2(B t, B w, B x) { return withFill(HARR_FV(r), xf); } if (isArr(x) && rnk(x)==1 && q_i32(w)) { - usz xia = a(x)->ia; + usz xia = IA(x); i32 wv = o2i(w); if (wv<=0) { if (wv<0) thrM("/: 𝕨 cannot be negative"); @@ -677,7 +677,7 @@ B slash_c2(B t, B w, B x) { B slash_im(B t, B x) { if (!isArr(x) || rnk(x)!=1) thrM("/⁼: Argument must be an array"); u8 xe = TI(x,elType); - usz xia = a(x)->ia; + usz xia = IA(x); if (xia==0) { decG(x); return emptyIVec(); } switch(xe) { default: UD; case el_i8: { @@ -762,7 +762,7 @@ B slash_im(B t, B x) { } static B slicev(B x, usz s, usz ia) { - usz xia = a(x)->ia; assert(s+ia <= xia); + usz xia = IA(x); assert(s+ia <= xia); return taga(arr_shVec(TI(x,slice)(x, s, ia))); } @@ -818,7 +818,7 @@ B take_c2(B t, B w, B x) { a = take_impl(t, x); } else { t = -t; - usz xia = a(x)->ia; + usz xia = IA(x); if (t>xia) { B xf = getFillE(x); MAKE_MUT(r, t); mut_init(r, el_or(TI(x,elType), selfElType(xf))); @@ -846,7 +846,7 @@ B take_c2(B t, B w, B x) { B drop_c2(B t, B w, B x) { if (isNum(w) && isArr(x) && rnk(x)==1) { i64 v = o2i64(w); - usz ia = a(x)->ia; + usz ia = IA(x); if (v<0) return -v>ia? slicev(x, 0, 0) : slicev(x, 0, v+ia); else return v>ia? slicev(x, 0, 0) : slicev(x, v, ia-v); } @@ -857,7 +857,7 @@ B join_c1(B t, B x) { if (isAtm(x)) thrM("∾: Argument must be an array"); ur xr = rnk(x); - usz xia = a(x)->ia; + usz xia = IA(x); if (xia==0) { B xf = getFillE(x); if (isAtm(xf)) { @@ -930,7 +930,7 @@ B join_c1(B t, B x) { for (usz i = 0; i < xia; i++) { B c = GetU(x, i); if (isArr(c)) { - usz cia = a(c)->ia; + usz cia = IA(c); mut_copy(r, ri, c, 0, cia); ri+= cia; } else { @@ -955,7 +955,7 @@ B join_c1(B t, B x) { B rf; if(SFNS_FILLS) rf = getFillQ(x0); ur r0 = isAtm(x0) ? 0 : rnk(x0); - usz xia = a(x)->ia; + usz xia = IA(x); usz* xsh = a(x)->sh; usz tlen = 4*xr+2*r0; for (usz a=0; aia; + usz eia = IA(e); if (eia) { usz rj = ri; usz *ii=tsh0; for (usz k=0; kia-a(x)->ia; + wia = IA(w)-IA(x); wsh = &wia; } else { wsh = a(w)->sh; // when wr>1, shape object won't be disturbed by arr_join_inline @@ -1149,7 +1149,7 @@ B join_c2(B t, B w, B x) { B couple_c1(B t, B x) { if (isAtm(x)) return m_vec1(x); usz rr = rnk(x); - usz ia = a(x)->ia; + usz ia = IA(x); Arr* r = TI(x,slice)(incG(x),0, ia); usz* sh = arr_shAlloc(r, rr+1); if (sh) { sh[0] = 1; shcpy(sh+1, a(x)->sh, rr); } @@ -1161,7 +1161,7 @@ B couple_c2(B t, B w, B x) { if (isAtm(w)) w = m_atomUnit(w); if (isAtm(x)) x = m_atomUnit(x); if (!eqShape(w, x)) thrF("≍: 𝕨 and 𝕩 must have equal shapes (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); - usz ia = a(w)->ia; + usz ia = IA(w); ur wr = rnk(w); MAKE_MUT(r, ia*2); mut_init(r, el_or(TI(w,elType), TI(x,elType))); MUTG_INIT(r); @@ -1186,7 +1186,7 @@ static inline void shift_check(B w, B x) { B shiftb_c1(B t, B x) { if (isAtm(x) || rnk(x)==0) thrM("»: Argument cannot be a scalar"); - usz ia = a(x)->ia; + usz ia = IA(x); if (ia==0) return x; B xf = getFillE(x); usz csz = arr_csz(x); @@ -1202,8 +1202,8 @@ B shiftb_c2(B t, B w, B x) { if (isAtm(w)) w = m_atomUnit(w); shift_check(w, x); B f = fill_both(w, x); - usz wia = a(w)->ia; - usz xia = a(x)->ia; + usz wia = IA(w); + usz xia = IA(x); MAKE_MUT(r, xia); mut_init(r, el_or(TI(w,elType), TI(x,elType))); MUTG_INIT(r); int mid = wiaia; + usz ia = IA(x); if (ia==0) return x; B xf = getFillE(x); usz csz = arr_csz(x); @@ -1230,8 +1230,8 @@ B shifta_c2(B t, B w, B x) { if (isAtm(w)) w = m_atomUnit(w); shift_check(w, x); B f = fill_both(w, x); - usz wia = a(w)->ia; - usz xia = a(x)->ia; + usz wia = IA(w); + usz xia = IA(x); MAKE_MUT(r, xia); mut_init(r, el_or(TI(w,elType), TI(x,elType))); MUTG_INIT(r); if (wia < xia) { @@ -1251,8 +1251,8 @@ B group_c1(B t, B x) { } B group_c2(B t, B w, B x) { if (isArr(w)&isArr(x) && rnk(w)==1 && rnk(x)==1 && depth(w)==1) { - usz wia = a(w)->ia; - usz xia = a(x)->ia; + usz wia = IA(w); + usz xia = IA(x); if (wia-xia > 1) thrF("⊔: ≠𝕨 must be either ≠𝕩 or one bigger (%s≡≠𝕨, %s≡≠𝕩)", wia, xia); u8 we = TI(w,elType); if (we<=el_i32) { @@ -1370,7 +1370,7 @@ B group_c2(B t, B w, B x) { extern B rt_reverse; B reverse_c1(B t, B x) { if (isAtm(x) || rnk(x)==0) thrM("⌽: Argument cannot be a unit"); - usz xia = a(x)->ia; + usz xia = IA(x); if (xia==0) return x; u8 xe = TI(x,elType); if (rnk(x)==1) { @@ -1413,7 +1413,7 @@ B reverse_c1(B t, B x) { B reverse_c2(B t, B w, B x) { if (isArr(w)) return c2(rt_reverse, w, x); if (isAtm(x) || rnk(x)==0) thrM("⌽: 𝕩 must have rank at least 1 for atom 𝕨"); - usz xia = a(x)->ia; + usz xia = IA(x); if (xia==0) return x; B xf = getFillQ(x); usz cam = a(x)->sh[0]; @@ -1435,7 +1435,7 @@ B transp_c1(B t, B x) { ur xr = rnk(x); if (xr<=1) return x; - usz ia = a(x)->ia; + usz ia = IA(x); usz* xsh = a(x)->sh; usz h = xsh[0]; usz w = xsh[1] * shProd(xsh, 2, xr); @@ -1481,9 +1481,9 @@ B transp_c2(B t, B w, B x) { return c2(rt_transp, w, x); } B pick_uc1(B t, B o, B x) { // TODO do in-place like pick_ucw; maybe just call it? - if (isAtm(x) || a(x)->ia==0) return def_fn_uc1(t, o, x); + if (isAtm(x) || IA(x)==0) return def_fn_uc1(t, o, x); B xf = getFillQ(x); - usz ia = a(x)->ia; + usz ia = IA(x); B arg = IGet(x, 0); B rep = c1(o, arg); MAKE_MUT(r, ia); mut_init(r, el_or(TI(x,elType), selfElType(rep))); @@ -1495,7 +1495,7 @@ B pick_uc1(B t, B o, B x) { // TODO do in-place like pick_ucw; maybe just call i B pick_ucw(B t, B o, B w, B x) { if (isArr(w) || isAtm(x) || rnk(x)!=1) return def_fn_ucw(t, o, w, x); - usz xia = a(x)->ia; + usz xia = IA(x); usz wi = WRAP(o2i64(w), xia, thrF("𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡%R, %s≡≠𝕩)", w, xia)); B arg = IGet(x, wi); B rep = c1(o, arg); @@ -1526,14 +1526,14 @@ 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; + if (isAtm(w) || isAtm(x) || rnk(w)!=1 || rnk(x)!=1 || IA(w)!=IA(x)) return def_fn_ucw(t, o, w, x); + usz ia = IA(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; + usz argIA = IA(arg); 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); + if (isAtm(rep) || rnk(rep)!=1 || IA(rep) != 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))); SGet(x) SGet(rep) @@ -1574,7 +1574,7 @@ B slash_ucw(B t, B o, B w, B x) { } static B takedrop_ucw(i64 wi, B o, u64 am, B x, size_t xr) { - usz xia = a(x)->ia; + usz xia = IA(x); usz csz = arr_csz(x); usz tk = csz*am; // taken element count usz lv = xia-tk; // elements left alone @@ -1624,15 +1624,15 @@ B drop_ucw(B t, B o, B w, B x) { } static B shape_uc1_t(B r, usz ia) { - if (!isArr(r) || rnk(r)!=1 || a(r)->ia!=ia) thrM("𝔽⌾⥊: 𝔽 changed the shape of the argument"); + if (!isArr(r) || rnk(r)!=1 || IA(r)!=ia) thrM("𝔽⌾⥊: 𝔽 changed the shape of the argument"); return r; } B shape_uc1(B t, B o, B x) { if (!isArr(x) || rnk(x)==0) { - usz xia = isArr(x)? a(x)->ia : 1; + usz xia = isArr(x)? IA(x) : 1; return shape_c2(t, emptyIVec(), shape_uc1_t(c1(o, shape_c1(t, x)), xia)); } - usz xia = a(x)->ia; + usz xia = IA(x); if (rnk(x)==1) return shape_uc1_t(c1(o, x), xia); ur xr = rnk(x); ShArr* sh = ptr_inc(shObj(x)); diff --git a/src/builtins/sort.c b/src/builtins/sort.c index e4a2d70d..159f6bad 100644 --- a/src/builtins/sort.c +++ b/src/builtins/sort.c @@ -30,7 +30,7 @@ typedef struct I32I32p { i32 k; i32 v; } I32I32p; B and_c1(B t, B x) { if (isAtm(x) || rnk(x)==0) thrM("∧: Argument cannot have rank 0"); if (rnk(x)!=1) return bqn_merge(and_c1(t, toCells(x))); - usz xia = a(x)->ia; + usz xia = IA(x); u8 xe = TI(x,elType); if (xe<=el_i32) { if (xe!=el_i32) x = taga(cpyI32Arr(x)); @@ -64,7 +64,7 @@ B and_c1(B t, B x) { B or_c1(B t, B x) { if (isAtm(x) || rnk(x)==0) thrM("∨: Argument cannot have rank 0"); if (rnk(x)!=1) return bqn_merge(or_c1(t, toCells(x))); - usz xia = a(x)->ia; + usz xia = IA(x); u8 xe = TI(x,elType); if (xe<=el_i32) { if (xe!=el_i32) x = taga(cpyI32Arr(x)); diff --git a/src/builtins/squeeze.c b/src/builtins/squeeze.c index c3fd4c16..b6ab2081 100644 --- a/src/builtins/squeeze.c +++ b/src/builtins/squeeze.c @@ -33,7 +33,7 @@ NOINLINE B num_squeezeF(B x, usz ia) { return taga(a); } B num_squeeze(B x) { - usz ia = a(x)->ia; + usz ia = IA(x); u8 xe = TI(x,elType); #if !SINGELI @@ -107,7 +107,7 @@ B num_squeeze(B x) { return rb; } B chr_squeeze(B x) { - usz ia = a(x)->ia; + usz ia = IA(x); u8 xe = TI(x,elType); usz i = 0; i32 or = 0; @@ -168,7 +168,7 @@ B chr_squeeze(B x) { B any_squeeze(B x) { assert(isArr(x)); if (FL_HAS(x,fl_squoze)) return x; - if (a(x)->ia==0) return FL_SET(x, fl_squoze); // TODO return a version of the smallest type + if (IA(x)==0) return FL_SET(x, fl_squoze); // TODO return a version of the smallest type B x0 = IGetU(x, 0); if (isNum(x0)) return num_squeeze(x); else if (isC32(x0)) return chr_squeeze(x); @@ -179,7 +179,7 @@ B squeeze_deep(B x) { if (!isArr(x)) return x; x = any_squeeze(x); if (TI(x,elType)!=el_B) return x; - usz ia = a(x)->ia; + usz ia = IA(x); M_HARR(r, ia) B* xp = arr_bptr(x); B xf = getFillQ(x); diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 38a7ec01..997c9f4c 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -23,7 +23,7 @@ static bool eqStr(B w, u32* x) { if (!isC32(c) || x[i]!=(u32)c.u) return false; i++; } - return i==a(w)->ia; + return i==IA(w); } @@ -120,7 +120,7 @@ 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; + usz ia = IA(x); SGetU(x) for (usz i = 0; i < ia; i++) { i64 c = o2i64u(GetU(x, i)); @@ -154,8 +154,8 @@ B grLen_c1(B t, B x) { return grLen_both( -1, x); } // assumes vali B grLen_c2(B t, B w, B x) { return grLen_both(o2i64u(w)-1, x); } // assumes valid arguments B grOrd_c2(B t, B w, B x) { // assumes valid arguments - usz wia = a(w)->ia; - usz xia = a(x)->ia; + usz wia = IA(w); + usz xia = IA(x); if (wia==0) { decG(w); decG(x); return emptyIVec(); } if (xia==0) { decG(w); return x; } SGetU(w) @@ -188,7 +188,7 @@ B casrt_c2(B t, B w, B x) { if (LIKELY(isF64(x) && o2fu(x)==1)) { dec(w); return x; } unwindCompiler(); dec(x); - if (isArr(w) && a(w)->ia==2) { + if (isArr(w) && IA(w)==2) { B w0 = IGetU(w,0); if (isNum(w0)) { B s = IGet(w,1); @@ -198,14 +198,14 @@ B casrt_c2(B t, B w, B x) { dec(w); thr(s); } - if (isArr(w0) && rnk(w0)==1 && a(w0)->ia>=1) { + if (isArr(w0) && rnk(w0)==1 && IA(w0)>=1) { B s = IGet(w,1); AFMT("\n"); usz pos = o2s(IGetU(w0,0)); s = vm_fmtPoint(comp_currSrc, s, comp_currPath, pos, pos+1); dec(w); thr(s); } - if (isArr(w0) && rnk(w0)==2 && a(w0)->ia>=2) { + if (isArr(w0) && rnk(w0)==2 && IA(w0)>=2) { B s = IGet(w,1); AFMT("\n"); SGetU(w0) s = vm_fmtPoint(comp_currSrc, s, comp_currPath, o2s(GetU(w0,0)), o2s(GetU(w0,1))+1); @@ -242,7 +242,7 @@ B show_c1(B t, B x) { B vfyStr(B x, char* name, char* arg) { if (isAtm(x) || rnk(x)!=1) thrF("%U: %U must be a character vector", name, arg); if (!elChr(TI(x,elType))) { - usz ia = a(x)->ia; + usz ia = IA(x); SGetU(x) for (usz i = 0; i < ia; i++) if (!isC32(GetU(x,i))) thrF("%U: %U must be a character vector", name, arg); } @@ -251,8 +251,8 @@ B vfyStr(B x, char* name, char* arg) { B cdPath; static B args_path(B* fullpath, B w, char* name) { // consumes w, returns args, writes to fullpath - if (!isArr(w) || rnk(w)!=1 || a(w)->ia>3) thrF("%U: 𝕨 must be a vector with at most 3 items, but had shape %H", name, w); - usz ia = a(w)->ia; + if (!isArr(w) || rnk(w)!=1 || IA(w)>3) thrF("%U: 𝕨 must be a vector with at most 3 items, but had shape %H", name, w); + usz ia = IA(w); SGet(w) B path = ia>0? vfyStr(Get(w,0),name,"path" ) : inc(cdPath); B file = ia>1? vfyStr(Get(w,1),name,"filename") : emptyCVec(); @@ -322,7 +322,7 @@ B rand_range_c2(B t, B w, B x) { if (isArr(w)) { if (rnk(w) > 1) thrM("(rand).Range: 𝕨 must be a valid shape"); SGetU(w); - usz wia = a(w)->ia; + usz wia = IA(w); for (u64 i = 0; i < wia; i++) mulOn(am, o2s(GetU(w, i))); } else { am = o2s(w); @@ -370,7 +370,7 @@ B rand_range_c2(B t, B w, B x) { RAND_END; if (isArr(w)) { - usz wia = a(w)->ia; + usz wia = IA(w); switch (wia) { case 0: { arr_shAlloc(r, 0); break; } case 1: { arr_shVec(r); break; } @@ -627,7 +627,7 @@ B fchars_c2(B d, B w, B x) { static NFnDesc* fBytesDesc; B fbytes_c1(B d, B x) { I8Arr* tf = path_bytes(path_rel(nfn_objU(d), x)); - usz ia = tf->ia; u8* p = (u8*)tf->a; + usz ia = PIA(tf); u8* p = (u8*)tf->a; u8* rp; B r = m_c8arrv(&rp, ia); for (i64 i = 0; i < ia; i++) rp[i] = p[i]; ptr_dec(tf); @@ -647,7 +647,7 @@ B flines_c1(B d, B x) { 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; + usz ia = IA(x); SGet(x) for (u64 i = 0; i < ia; i++) { nl = Get(x, i); @@ -686,7 +686,7 @@ B import_c1(B d, B x) { i32 prevIdx = getPrevImport(path); if (prevIdx>=0) { - // print_fmt("cached: %R @ %i/%i\n", path, prevIdx, a(importKeyList)->ia); + // print_fmt("cached: %R @ %i/%i\n", path, prevIdx, IA(importKeyList)); dec(path); return IGet(importValList, prevIdx); } @@ -696,7 +696,7 @@ B import_c1(B d, B x) { rethrow(); } - i32 prevLen = a(importValList)->ia; + i32 prevLen = IA(importValList); importKeyList = vec_addN(importKeyList, path); importValList = vec_addN(importValList, bi_N); @@ -817,7 +817,7 @@ B getLine_c1(B t, B x) { 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; + usz ia = IA(x); TALLOC(char, chrs, ia); SGetU(x) for (u64 i = 0; i < ia; i++) { @@ -863,7 +863,7 @@ B sh_c2(B t, B w, B x) { // allocate args if (isAtm(x) || rnk(x)>1) thrM("•SH: 𝕩 must be a vector of strings"); - usz xia = a(x)->ia; + usz xia = IA(x); if (xia==0) thrM("•SH: 𝕩 must have at least one item"); TALLOC(char*, argv, xia+1); SGetU(x) @@ -966,8 +966,8 @@ B sh_c2(B t, B w, B x) { dec(w); dec(x); B s_outRaw = toC8Any(s_out); B s_errRaw = toC8Any(s_err); - B s_outObj = utf8Decode((char*)c8any_ptr(s_outRaw), a(s_outRaw)->ia); dec(s_outRaw); - B s_errObj = utf8Decode((char*)c8any_ptr(s_errRaw), a(s_errRaw)->ia); dec(s_errRaw); + B s_outObj = utf8Decode((char*)c8any_ptr(s_outRaw), IA(s_outRaw)); dec(s_outRaw); + B s_errObj = utf8Decode((char*)c8any_ptr(s_errRaw), IA(s_errRaw)); dec(s_errRaw); return m_hVec3(m_i32(WEXITSTATUS(status)), s_outObj, s_errObj); } #else @@ -1046,7 +1046,7 @@ static CastType getCastType(B e, B v) { s = o2s(e); c = q_N(v) ? 0 : isCharType(v(v)->type); } else { - if (!isArr(e) || rnk(e)!=1 || a(e)->ia!=2) thrM("•bit._cast: 𝕗 elements must be numbers or two-element lists"); + if (!isArr(e) || rnk(e)!=1 || IA(e)!=2) thrM("•bit._cast: 𝕗 elements must be numbers or two-element lists"); SGetU(e) s = o2s(GetU(e,0)); u32 t = o2c(GetU(e,1)); @@ -1107,7 +1107,7 @@ B bitcast_impl(B el0, B el1, B x) { r = taga(copy(xt, r)); } else if (v(r)->refc!=1) { B pr = r; - r = taga(TI(r,slice)(r, 0, a(r)->ia)); + r = taga(TI(r,slice)(r, 0, IA(r))); arr_shSetI(a(r), xr, shObj(pr)); // safe to use pr because r has refcount>1 and slice only consumes one, leaving some behind } // Cast to output type @@ -1131,13 +1131,13 @@ B bitcast_impl(B el0, B el1, B x) { } B bitcast_c1(Md1D* d, B x) { B f = d->f; - if (!isArr(f) || rnk(f)!=1 || a(f)->ia!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)"); + if (!isArr(f) || rnk(f)!=1 || IA(f)!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)"); SGetU(f) return bitcast_impl(GetU(f,0), GetU(f,1), x); } B bitcast_im(Md1D* d, B x) { B f = d->f; - if (!isArr(f) || rnk(f)!=1 || a(f)->ia!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)"); + if (!isArr(f) || rnk(f)!=1 || IA(f)!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)"); SGetU(f) return bitcast_impl(GetU(f,1), GetU(f,0), x); } @@ -1164,14 +1164,14 @@ B ffiload_c2(B t, B w, B x); B sys_c1(B t, B x) { assert(isArr(x)); - M_HARR(r, a(x)->ia) SGetU(x) + M_HARR(r, IA(x)) SGetU(x) B fileNS = m_f64(0); B path = m_f64(0); B name = m_f64(0); B wdpath = m_f64(0); #define REQ_PATH ({ if(!path.u) path = q_N(comp_currPath)? bi_N : path_abs(path_dir(inc(comp_currPath))); path; }) #define REQ_NAME ({ if(!name.u) name = path_name(inc(comp_currPath)); name; }) - for (usz i = 0; i < a(x)->ia; i++) { + for (usz i = 0; i < IA(x); i++) { B c = GetU(x,i); B cr; if (eqStr(c, U"out")) cr = incG(bi_out); diff --git a/src/core/arrFns.h b/src/core/arrFns.h index c1379437..62a3211e 100644 --- a/src/core/arrFns.h +++ b/src/core/arrFns.h @@ -36,18 +36,18 @@ static void* m_tyarrp (Arr** rp, usz w, usz ia, u8 type ) M_TYARR(0, static void* m_tyarrpO(Arr** rp, usz w, usz ia, u8 type, usz over) M_TYARR(0,+over, , r, ) static void* m_tyarrv (B* rp, usz w, usz ia, u8 type ) M_TYARR(0, , arr_shVec((Arr*)r);, taga(r), ) static void* m_tyarrvO(B* rp, usz w, usz ia, u8 type, usz over) M_TYARR(0,+over, arr_shVec((Arr*)r);, taga(r), ) -static void* m_tyarrc (B* rp, usz w, B x, u8 type ) M_TYARR(0, , arr_shCopy((Arr*)r,x);, taga(r), usz ia = a(x)->ia;) -static void* m_tyarrcO(B* rp, usz w, B x, u8 type, usz over) M_TYARR(0,+over, arr_shCopy((Arr*)r,x);, taga(r), usz ia = a(x)->ia;) +static void* m_tyarrc (B* rp, usz w, B x, u8 type ) M_TYARR(0, , arr_shCopy((Arr*)r,x);, taga(r), usz ia = IA(x);) +static void* m_tyarrcO(B* rp, usz w, B x, u8 type, usz over) M_TYARR(0,+over, arr_shCopy((Arr*)r,x);, taga(r), usz ia = IA(x);) // width in log2(bytes) static void* m_tyarrlp(Arr** rp, usz w, usz ia, u8 type) M_TYARR(1, , , r, ) static void* m_tyarrlv(B* rp, usz w, usz ia, u8 type) M_TYARR(1, , arr_shVec((Arr*)r);, taga(r), ) -static void* m_tyarrlc(B* rp, usz w, B x, u8 type) M_TYARR(1, , arr_shCopy((Arr*)r,x);, taga(r), usz ia = a(x)->ia;) +static void* m_tyarrlc(B* rp, usz w, B x, u8 type) M_TYARR(1, , arr_shCopy((Arr*)r,x);, taga(r), usz ia = IA(x);) // width in log2(bits) static void* m_tyarrlbp(Arr** rp, usz w, usz ia, u8 type) M_TYARR(2, , , r, ) static void* m_tyarrlbv(B* rp, usz w, usz ia, u8 type) M_TYARR(2, , arr_shVec((Arr*)r);, taga(r), ) -static void* m_tyarrlbc(B* rp, usz w, B x, u8 type) M_TYARR(2, , arr_shCopy((Arr*)r,x);, taga(r), usz ia = a(x)->ia;) +static void* m_tyarrlbc(B* rp, usz w, B x, u8 type) M_TYARR(2, , arr_shCopy((Arr*)r,x);, taga(r), usz ia = IA(x);) extern u8 elType2type[]; #define el2t(X) elType2type[X] // TODO maybe reorganize array types such that this can just be addition? diff --git a/src/core/fillarr.c b/src/core/fillarr.c index 5a7befab..a16c7e36 100644 --- a/src/core/fillarr.c +++ b/src/core/fillarr.c @@ -3,7 +3,7 @@ B asFill(B x) { // consumes if (isArr(x)) { u8 xe = TI(x,elType); - usz ia = a(x)->ia; + usz ia = IA(x); if (elNum(xe)) { Arr* r = allZeroes(ia); arr_shCopy(r, x); @@ -16,7 +16,7 @@ B asFill(B x) { // consumes decG(x); return r; } - M_HARR(r, a(x)->ia) + M_HARR(r, IA(x)) SGet(x) for (usz i = 0; i < ia; i++) { if (noFill(HARR_ADD(r, i, asFill(Get(x,i))))) { HARR_ABANDON(r); decG(x); return bi_noFill; } @@ -48,11 +48,11 @@ DEF_FREE(fillarr) { decSh(x); B* p = ((FillArr*)x)->a; dec(((FillArr*)x)->fill); - usz ia = ((Arr*)x)->ia; + usz ia = PIA((Arr*)x); for (usz i = 0; i < ia; i++) dec(p[i]); } static void fillarr_visit(Value* x) { assert(x->type == t_fillarr); - usz ia = ((Arr*)x)->ia; B* p = ((FillArr*)x)->a; + usz ia = PIA((Arr*)x); B* p = ((FillArr*)x)->a; mm_visit(((FillArr*)x)->fill); for (usz i = 0; i < ia; i++) mm_visit(p[i]); } @@ -82,7 +82,7 @@ void fillarr_init() { void validateFill(B x) { if (isArr(x)) { SGetU(x) - usz ia = a(x)->ia; + usz ia = IA(x); for (usz i = 0; i < ia; i++) validateFill(GetU(x,i)); } else if (isF64(x)) { assert(x.f==0); @@ -93,7 +93,7 @@ void validateFill(B x) { NOINLINE bool fillEqualF(B w, B x) { // doesn't consume; both args must be arrays if (!eqShape(w, x)) return false; - usz ia = a(w)->ia; + usz ia = IA(w); if (ia==0) return true; u8 we = TI(w,elType); @@ -129,7 +129,7 @@ B withFill(B x, B fill) { // consumes both } break; } - usz ia = a(x)->ia; + usz ia = IA(x); if (!FL_HAS(x,fl_squoze)) { if (isNum(fill)) { x = num_squeeze(x); diff --git a/src/core/harr.c b/src/core/harr.c index 10809c61..c17a841d 100644 --- a/src/core/harr.c +++ b/src/core/harr.c @@ -90,11 +90,11 @@ static B hslice_getU(Arr* x, usz n) { assert(x->type==t_hslice); return ((HS DEF_FREE(harr) { decSh(x); B* p = ((HArr*)x)->a; // don't use harr_ptr so type isn't checked - usz ia = ((Arr*)x)->ia; + usz ia = PIA((Arr*)x); for (usz i = 0; i < ia; i++) dec(p[i]); } static void harr_visit(Value* x) { - usz ia = ((Arr*)x)->ia; B* p = ((HArr*)x)->a; + usz ia = PIA((Arr*)x); B* p = ((HArr*)x)->a; for (usz i = 0; i < ia; i++) mm_visit(p[i]); } static bool harr_canStore(B x) { return true; } @@ -103,7 +103,7 @@ static bool harr_canStore(B x) { return true; } DEF_FREE(harrP) { assert(x->type==t_harrPartial|x->type==t_freed); B* p = ((HArr*)x)->a; - usz am = ((HArr*)x)->ia; + usz am = PIA((HArr*)x); for (usz i = 0; i < am; i++) dec(p[i]); } void harr_abandon_impl(HArr* p) { assert(p->type == t_harrPartial); @@ -113,14 +113,14 @@ void harr_abandon_impl(HArr* p) { assert(p->type == t_harrPartial); } static void harrP_visit(Value* x) { assert(x->type == t_harrPartial); B* p = ((HArr*)x)->a; - usz am = ((HArr*)x)->ia; + usz am = PIA((HArr*)x); for (usz i = 0; i < am; i++) mm_visit(p[i]); } static B harrP_get(Arr* x, usz n) { err("getting item from t_harrPartial"); } static void harrP_print(FILE* f, B x) { B* p = c(HArr,x)->a; usz am = *c(HArr,x)->sh; - usz ia = a(x)->ia; + usz ia = IA(x); fprintf(f, "(partial HArr "N64d"/"N64d": ⟨", (u64)am, (u64)ia); for (usz i = 0; i < ia; i++) { if (i) fprintf(f, ", "); @@ -133,7 +133,7 @@ static void harrP_print(FILE* f, B x) { #if DEBUG static void harr_freeT(Value* x) { B* p = ((HArr*)x)->a; - usz ia = ((Arr*)x)->ia; + usz ia = PIA((Arr*)x); for (usz i = 0; i < ia; i++) assert(!isVal(p[i])); tyarr_freeF(x); } diff --git a/src/core/harr.h b/src/core/harr.h index 0d54ebf3..94c6a4ef 100644 --- a/src/core/harr.h +++ b/src/core/harr.h @@ -73,7 +73,7 @@ void harr_abandon_impl(HArr* p); // unsafe-ish things - don't allocate/GC anything before having written to all items #define m_harr0v(N) ({ usz n_ = (N); HArr_p r_ = m_harrUv(n_); for(usz i=0;iia; HArr_p r_ = m_harrUc(x_); for(usz i=0;iia; + usz ia = IA(x); CHECK_IA(ia, sizeof(B)); HArr* r = m_arr(fsizeof(HArr,a,B,ia), t_harr, ia); arr_shCopy((Arr*)r, x); diff --git a/src/core/numarr.h b/src/core/numarr.h index 3709a21b..7ee0598e 100644 --- a/src/core/numarr.h +++ b/src/core/numarr.h @@ -52,7 +52,7 @@ static B m_bitarrv(u64** p, usz ia) { return taga(r); } static B m_bitarrc(u64** p, B x) { assert(isArr(x)); - BitArr* r = m_arr(BITARR_SZ(a(x)->ia), t_bitarr, a(x)->ia); + BitArr* r = m_arr(BITARR_SZ(IA(x)), t_bitarr, IA(x)); *p = (u64*)r->a; arr_shCopy((Arr*)r, x); return taga(r); @@ -98,7 +98,7 @@ static i64 bit_sum(u64* x, u64 am) { static u64 usum(B x) { // doesn't consume; may error assert(isArr(x)); u64 r = 0; - usz xia = a(x)->ia; + usz xia = IA(x); u8 xe = TI(x,elType); if (xe==el_bit) return bit_sum(bitarr_ptr(x), xia); else if (xe==el_i8 ) { i8* p = i8any_ptr (x); for (usz i = 0; i < xia; i++) { if (RARE(p[i]<0)) goto neg; r+= p[i]; } } diff --git a/src/core/stuff.c b/src/core/stuff.c index 1a545bf9..1ba2c99a 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -95,7 +95,7 @@ void fprint(FILE* f, B x); void farr_print(FILE* f, B x) { // should accept refc=0 arguments for debugging purposes ur r = rnk(x); SGetU(x) - usz ia = a(x)->ia; + usz ia = IA(x); if (r!=1) { if (r==0) { fprintf(f, "<"); @@ -164,7 +164,7 @@ NOINLINE void fprintRaw(FILE* f, B x) { else if (isC32(x)) fprintUTF8(f, (u32)x.u); else thrM("•Out: Unexpected argument type"); } else { - usz ia = a(x)->ia; + usz ia = IA(x); SGetU(x) for (usz i = 0; i < ia; i++) { B c = GetU(x,i); @@ -372,8 +372,8 @@ NOINLINE i32 compareF(B w, B x) { if (isAtm(w) & isAtm(x)) thrM("Invalid comparison"); 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(wa) { wia=1; wr=0; wsh=NULL; } else { wia=IA(w); wr=rnk(w); wsh=a(w)->sh; wgetU=TI(w,getU); wArr = a(w); } + if(xa) { xia=1; xr=0; xsh=NULL; } else { xia=IA(x); 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)); @@ -405,8 +405,8 @@ NOINLINE bool atomEqualF(B w, B x) { B wd=dcf(inc(w)); B* wdp = harr_ptr(wd); B xd=dcf(inc(x)); B* xdp = harr_ptr(xd); if (o2i(wdp[0])<=1) { decG(wd);decG(xd); return false; } - usz wia = a(wd)->ia; - if (wia!=a(xd)->ia) { decG(wd);decG(xd); return false; } + usz wia = IA(wd); + if (wia!=IA(xd)) { decG(wd);decG(xd); return false; } for (u64 i = 0; iia; + usz ia = IA(x); if (LIKELY(wr==1)) { - if (ia != a(w)->ia) return false; + if (ia != IA(w)) return false; } else { usz* wsh = a(w)->sh; usz* xsh = a(x)->sh; @@ -515,8 +515,8 @@ bool atomEEqual(B w, B x) { // doesn't consume (not that that matters really cur B wd=dcf(inc(w)); B* wdp = harr_ptr(wd); B xd=dcf(inc(x)); B* xdp = harr_ptr(xd); if (o2i(wdp[0])<=1) { decG(wd);decG(xd); return false; } - usz wia = a(wd)->ia; - if (wia!=a(xd)->ia) { decG(wd);decG(xd); return false; } + usz wia = IA(wd); + if (wia!=IA(xd)) { decG(wd);decG(xd); return false; } for (u64 i = 0; iia; + usz ia = IA(x); f64* wp = f64any_ptr(w); f64* xp = f64any_ptr(x); u64 r = 1; @@ -550,7 +550,7 @@ bool eequal(B w, B x) { // doesn't consume return r; } if (we!=el_B && xe!=el_B) return equal(w, x); - usz ia = a(x)->ia; + usz ia = IA(x); SGetU(x) SGetU(w) for (usz i = 0; i < ia; i++) if(!eequal(GetU(w,i),GetU(x,i))) return false; @@ -561,7 +561,7 @@ u64 depth(B x) { // doesn't consume if (isAtm(x)) return 0; if (TI(x,arrD1)) return 1; u64 r = 0; - usz ia = a(x)->ia; + usz ia = IA(x); SGetU(x) for (usz i = 0; i < ia; i++) { u64 n = depth(GetU(x,i)); @@ -599,11 +599,11 @@ bool isPureFn(B x) { // doesn't consume B* xdp = harr_ptr(xd); i32 t = o2iu(xdp[0]); if (t<2) { decG(xd); return t==0; } - usz xdia = a(xd)->ia; + usz xdia = IA(xd); for (u64 i = 1; iia; + usz ia = IA(x); SGetU(x) for (usz i = 0; i < ia; i++) if (!isPureFn(GetU(x,i))) return false; return true; @@ -612,7 +612,7 @@ bool isPureFn(B x) { // doesn't consume B bqn_merge(B x) { assert(isArr(x)); - usz xia = a(x)->ia; + usz xia = IA(x); ur xr = rnk(x); if (xia==0) { B xf = getFillE(x); @@ -635,7 +635,7 @@ B bqn_merge(B 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; + usz elIA = isArr(x0)? IA(x0) : 1; B fill = getFillQ(x0); if (xr+elR > UR_MAX) thrM(">: Result rank too large"); @@ -739,7 +739,7 @@ NOINLINE void print_allocStats() { void* data; u64 len; u8 xe = TI(x,elType); - u64 ia = a(x)->ia; + u64 ia = IA(x); if (xe!=el_B) { data = tyany_ptr(x); if (xe==el_bit) { @@ -831,7 +831,7 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); } #endif #if WARN_SLOW==1 static void warn_ln(B x) { - if (isArr(x)) print_fmt("%s items, %S, shape=%H\n", a(x)->ia, eltype_repr(TI(x,elType)), x); + if (isArr(x)) print_fmt("%s items, %S, shape=%H\n", IA(x), eltype_repr(TI(x,elType)), x); else { fprintf(stderr, "atom: "); fprintRaw(stderr, x = bqn_fmt(inc(x))); dec(x); @@ -839,18 +839,18 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); } } } void warn_slow1(char* s, B x) { - if (isArr(x) && a(x)->ia<100) return; + if (isArr(x) && IA(x)<100) return; fprintf(stderr, "slow %s: ", s); warn_ln(x); fflush(stderr); } void warn_slow2(char* s, B w, B x) { - if ((isArr(w)||isArr(x)) && (!isArr(w) || a(w)->ia<50) && (!isArr(x) || a(x)->ia<50)) return; + if ((isArr(w)||isArr(x)) && (!isArr(w) || IA(w)<50) && (!isArr(x) || IA(x)<50)) return; fprintf(stderr, "slow %s:\n 𝕨: ", s); warn_ln(w); fprintf(stderr, " 𝕩: "); warn_ln(x); fflush(stderr); } void warn_slow3(char* s, B w, B x, B y) { - if ((isArr(w)||isArr(x)) && (!isArr(w) || a(w)->ia<50) && (!isArr(x) || a(x)->ia<50)) return; + if ((isArr(w)||isArr(x)) && (!isArr(w) || IA(w)<50) && (!isArr(x) || IA(x)<50)) return; fprintf(stderr, "slow %s:\n 𝕨: ", s); warn_ln(w); fprintf(stderr, " 𝕩: "); warn_ln(x); fprintf(stderr, " f: "); warn_ln(y); diff --git a/src/core/stuff.h b/src/core/stuff.h index 5c1ead1f..d18a2956 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -75,7 +75,7 @@ static void arr_shSetU(Arr* x, ur r, ShArr* sh) { // set rank and assign shape } static void arr_shCopy(Arr* n, B o) { // copy shape & rank from o to n assert(isArr(o)); - assert(a(o)->ia==n->ia); + assert(IA(o)==n->ia); ur r = sprnk(n,rnk(o)); if (r<=1) { n->sh = &n->ia; diff --git a/src/core/tyarrTemplate.h b/src/core/tyarrTemplate.h index fedc3225..02aa32e0 100644 --- a/src/core/tyarrTemplate.h +++ b/src/core/tyarrTemplate.h @@ -12,9 +12,9 @@ static B TP(m_,arrv) (TEl** p, usz ia) { return taga(r); } static B TP(m_,arrc) (TEl** p, B x) { assert(isArr(x)); - usz ia = a(x)->ia; + usz ia = IA(x); CHECK_IA(ia, sizeof(TEl)); - TyArr* r = m_arr(TYARR_SZ2(TU,ia), T_ARR, a(x)->ia); + TyArr* r = m_arr(TYARR_SZ2(TU,ia), T_ARR, IA(x)); *p = (TEl*)r->a; arr_shCopy((Arr*)r, x); return taga(r); diff --git a/src/ffi.c b/src/ffi.c index 11dfea31..4635af75 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -64,7 +64,7 @@ BQNV bqn_evalCStr(const char* str) { } -size_t bqn_bound(BQNV a) { return a(getB(a))->ia; } +size_t bqn_bound(BQNV a) { return IA(getB(a)); } size_t bqn_rank(BQNV a) { return rnk(getB(a)); } void bqn_shape(BQNV a, size_t* buf) { B b = getB(a); ur r = rnk(b); @@ -76,15 +76,15 @@ BQNV bqn_pick(BQNV a, size_t pos) { } // TODO copy directly with some mut.h thing -void bqn_readI8Arr (BQNV a, i8* buf) { B c = toI8Any (incG(getB(a))); memcpy(buf, i8any_ptr (c), a(c)->ia * 1); dec(c); } -void bqn_readI16Arr(BQNV a, i16* buf) { B c = toI16Any(incG(getB(a))); memcpy(buf, i16any_ptr(c), a(c)->ia * 2); dec(c); } -void bqn_readI32Arr(BQNV a, i32* buf) { B c = toI32Any(incG(getB(a))); memcpy(buf, i32any_ptr(c), a(c)->ia * 4); dec(c); } -void bqn_readF64Arr(BQNV a, f64* buf) { B c = toF64Any(incG(getB(a))); memcpy(buf, f64any_ptr(c), a(c)->ia * 8); dec(c); } -void bqn_readC8Arr (BQNV a, u8* buf) { B c = toC8Any (incG(getB(a))); memcpy(buf, c8any_ptr (c), a(c)->ia * 1); dec(c); } -void bqn_readC16Arr(BQNV a, u16* buf) { B c = toC16Any(incG(getB(a))); memcpy(buf, c16any_ptr(c), a(c)->ia * 2); dec(c); } -void bqn_readC32Arr(BQNV a, u32* buf) { B c = toC32Any(incG(getB(a))); memcpy(buf, c32any_ptr(c), a(c)->ia * 4); dec(c); } +void bqn_readI8Arr (BQNV a, i8* buf) { B c = toI8Any (incG(getB(a))); memcpy(buf, i8any_ptr (c), IA(c) * 1); dec(c); } +void bqn_readI16Arr(BQNV a, i16* buf) { B c = toI16Any(incG(getB(a))); memcpy(buf, i16any_ptr(c), IA(c) * 2); dec(c); } +void bqn_readI32Arr(BQNV a, i32* buf) { B c = toI32Any(incG(getB(a))); memcpy(buf, i32any_ptr(c), IA(c) * 4); dec(c); } +void bqn_readF64Arr(BQNV a, f64* buf) { B c = toF64Any(incG(getB(a))); memcpy(buf, f64any_ptr(c), IA(c) * 8); dec(c); } +void bqn_readC8Arr (BQNV a, u8* buf) { B c = toC8Any (incG(getB(a))); memcpy(buf, c8any_ptr (c), IA(c) * 1); dec(c); } +void bqn_readC16Arr(BQNV a, u16* buf) { B c = toC16Any(incG(getB(a))); memcpy(buf, c16any_ptr(c), IA(c) * 2); dec(c); } +void bqn_readC32Arr(BQNV a, u32* buf) { B c = toC32Any(incG(getB(a))); memcpy(buf, c32any_ptr(c), IA(c) * 4); dec(c); } void bqn_readObjArr(BQNV a, BQNV* buf) { B b = getB(a); - usz ia = a(b)->ia; + usz ia = IA(b); B* p = arr_bptr(b); if (p!=NULL) { for (usz i = 0; i < ia; i++) buf[i] = makeX(inc(p[i])); @@ -346,7 +346,7 @@ BQNFFIEnt ffi_parseTypeStr(u32** src, bool inPtr) { // parse actual type BQNFFIEnt ffi_parseType(B arg, bool forRes) { // doesn't consume; parse argument side & other global decorators vfyStr(arg, "FFI", "type"); - usz ia = a(arg)->ia; + usz ia = IA(arg); if (ia==0) { if (!forRes) thrM("FFI: Argument type empty"); return (BQNFFIEnt){.t = ffi_type_void, .o=m_c32(sty_void), .resSingle=false}; @@ -467,7 +467,7 @@ usz genObj(BQNFFIEnt ent, B c, bool anyMut) { inc(c); B cG; if (!isArr(c)) thrF("FFI: Expected array corresponding to \"*%S\"", sty_names[o2cu(e)]); - usz ia = a(c)->ia; + usz ia = IA(c); bool mut = t->a[0].mutPtr; switch(o2cu(e)) { default: thrF("FFI: \"*%S\" argument type NYI", sty_names[o2cu(e)]); case sty_i8: cG = mut? taga(cpyI8Arr (c)) : toI8Any (c); break; @@ -491,7 +491,7 @@ usz genObj(BQNFFIEnt ent, B c, bool anyMut) { u8 et = o2cu(o2); u8 etw = sty_w[et]*8; if (!isArr(c)) thrF("FFI: Expected array corresponding to \"%S:%c%i\"", sty_names[et], reT, 1<ia != etw>>reW) thrM("FFI: Bad input array length"); + if (IA(c) != etw>>reW) thrM("FFI: Bad input array length"); B cG = toW(reT, reW, inc(c)); memcpy(ffiTmpS+pos, tyany_ptr(cG), 8); // may over-read, ¯\_(ツ)_/¯ dec(cG); @@ -531,7 +531,7 @@ B buildObj(BQNFFIEnt ent, bool anyMut, B* objs, usz* objPos) { B f = objs[(*objPos)++]; bool mut = t->a[0].mutPtr; if (mut) { - usz ia = a(f)->ia; + usz ia = IA(f); switch(o2cu(e)) { default: UD; case sty_i8: case sty_i16: case sty_i32: case sty_f64: return inc(f); case sty_u8: { u8* tp=tyarr_ptr(f); i16* rp; B r=m_i16arrv(&rp, ia); for (usz i=0; iia!=1 || IGetU(arg,0).u!=m_c32('a').u) thrM("FFI: Only \"a\" arguments & return value supported with compile flag FFI=1"); + if (!isArr(arg) || IA(arg)!=1 || IGetU(arg,0).u!=m_c32('a').u) thrM("FFI: Only \"a\" arguments & return value supported with compile flag FFI=1"); return (BQNFFIEnt){}; } #endif @@ -673,7 +673,7 @@ BQNFFIEnt ffi_parseType(B arg, bool forRes) { B ffiload_c2(B t, B w, B x) { - usz xia = a(x)->ia; + usz xia = IA(x); if (xia<2) thrM("FFI: Function specification must have at least two items"); usz argn = xia-2; SGetU(x) @@ -740,17 +740,17 @@ B ffiload_c2(B t, B w, B x) { } DEF_FREE(ffiType) { - usz ia = ((BQNFFIType*)x)->ia; + usz ia = PIA((BQNFFIType*)x); for (usz i = 0; i < ia; i++) dec(((BQNFFIType*)x)->a[i].o); } void ffiType_visit(Value* x) { - usz ia = ((BQNFFIType*)x)->ia; + usz ia = PIA((BQNFFIType*)x); for (usz i = 0; i < ia; i++) mm_visit(((BQNFFIType*)x)->a[i].o); } void ffiType_print(FILE* f, B x) { BQNFFIType* t = c(BQNFFIType,x); fprintf(f, "cty_%d⟨", t->ty); - for (usz i=0, ia=t->ia; ia[i].o); } diff --git a/src/h.h b/src/h.h index 3426c4ef..311ba84a 100644 --- a/src/h.h +++ b/src/h.h @@ -375,6 +375,8 @@ void freeThrown(void); #define sprnk(X,R) (X->extra=(R)) #define rnk(X ) prnk(v(X)) #define srnk(X,R) sprnk(v(X),R) +#define IA(X) (a(X)->ia) +#define PIA(X) ((X)->ia) #define VTY(X,T) assert(isVal(X) && v(X)->type==(T)) void print_vmStack(void); diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index 9359f131..d3d80cfe 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -465,7 +465,7 @@ static OptRes opt(u32* bc0) { bc = bc0; pos = 0; TSFREE(data); TSFREE(actions); - if (a(refs)->ia==0) { dec(refs); refs=m_f64(0); } + if (IA(refs)==0) { dec(refs); refs=m_f64(0); } return (OptRes){.bc = rbc, .offset = roff, .refs = refs}; } #undef SREF diff --git a/src/load.c b/src/load.c index c25bfb58..7194b554 100644 --- a/src/load.c +++ b/src/load.c @@ -107,7 +107,7 @@ B rt_undo, rt_select, rt_slash, rt_join, rt_ud, rt_pick, rt_take, rt_drop, rt_in rt_group, rt_under, rt_reverse, rt_indexOf, rt_count, rt_memberOf, rt_find, rt_transp; Block* load_compObj(B x, B src, B path, Scope* sc) { // consumes x,src SGet(x) - usz xia = a(x)->ia; + usz xia = IA(x); if (xia!=6 & xia!=4) thrM("load_compObj: bad item count"); 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); @@ -190,7 +190,7 @@ Block* bqn_compScc(B str, B path, B args, Scope* sc, B comp, B rt, bool repl) { Scope* csc = sc; while (csc) { B vars = listVars(csc); - usz am = a(vars)->ia; + usz am = IA(vars); vName = vec_join(vName, vars); for (usz i = 0; i < am; i++) vDepth = vec_addN(vDepth, m_i32(depth)); csc = csc->psc; @@ -219,12 +219,12 @@ void init_comp(B* set, B prim) { set[2] = inc(load_glyphs); } else { if (!isArr(prim) || rnk(prim)!=1) thrM("•ReBQN: 𝕩.primitives must be a list"); - usz pia = a(prim)->ia; + usz pia = IA(prim); usz np[3] = {0}; // number of functions, 1-modifiers, and 2-modifiers SGetU(prim); for (usz i = 0; i < pia; i++) { // check and count B p = GetU(prim, i); - if (!isArr(p) || rnk(p)!=1 || a(p)->ia!=2) thrM("•ReBQN: 𝕩.primitives must consist of glyph-primitive pairs"); + if (!isArr(p) || rnk(p)!=1 || IA(p)!=2) thrM("•ReBQN: 𝕩.primitives must consist of glyph-primitive pairs"); if (!isC32(IGet(p, 0))) thrM("•ReBQN 𝕩.primitives: Glyphs must be characters"); B v = IGetU(p, 1); i32 t = isFun(v)? 0 : isMd1(v)? 1 : isMd2(v)? 2 : 3; @@ -266,9 +266,9 @@ B getPrimitives() { } B* pr = harr_ptr(r); B* gg = harr_ptr(g); - M_HARR(ph, a(r)->ia); + M_HARR(ph, IA(r)); for (usz gi = 0; gi < 3; gi++) { - usz l = a(gg[gi])->ia; + usz l = IA(gg[gi]); u32* gp = c32arr_ptr(gg[gi]); for (usz i = 0; i < l; i++) { HARR_ADDA(ph, m_hVec2(m_c32(gp[i]), inc(pr[i]))); @@ -379,7 +379,7 @@ void load_init() { // very last init function - if (c(Arr,rtObjRaw)->ia != rtLen) err("incorrectly defined rtLen!"); + if (IA(rtObjRaw) != rtLen) err("incorrectly defined rtLen!"); HArr_p runtimeH = m_harrUc(rtObjRaw); SGet(rtObjRaw) diff --git a/src/main.c b/src/main.c index 9be7bfeb..335a914f 100644 --- a/src/main.c +++ b/src/main.c @@ -132,7 +132,7 @@ void cbqn_runLine0(char* ln, i64 read) { i32 am = e->varAm; for (i32 i = 0; i < am; i++) { B c = e->vars[i+am]; - if (a(c)->ia != len) continue; + if (IA(c) != len) continue; SGetU(c) bool ok = true; for (i32 j = 0; j < len; j++) ok&= o2cu(GetU(c, j))==name[j]; @@ -157,7 +157,7 @@ void cbqn_runLine0(char* ln, i64 read) { if (q_N(r)) { printf("Couldn't list variables\n"); } else { - usz ia = a(r)->ia; + usz ia = IA(r); B* rp = harr_ptr(r); for (usz i = 0; i < ia; i++) { if (i!=0) printf(", "); @@ -201,7 +201,7 @@ void cbqn_runLine0(char* ln, i64 read) { } else if (isCmd(cmdS, &cmdE, "e ") || isCmd(cmdS, &cmdE, "explain ")) { B expl = bqn_explain(utf8Decode0(cmdE), replPath); HArr* expla = toHArr(expl); - usz ia=expla->ia; + usz ia=PIA(expla); for(usz i=0; ia[i]); putchar('\n'); @@ -373,7 +373,7 @@ int main(int argc, char* argv[]) { case 'R': { repl_init(); REQARG(R); B path = utf8Decode0(argv[i++]); B lines = path_lines(path); - usz ia = a(lines)->ia; + usz ia = IA(lines); SGet(lines) for (u64 i = 0; i < ia; i++) { dec(gsc_exec_inline(Get(lines, i), incG(replPath), emptySVec())); diff --git a/src/ns.c b/src/ns.c index dbc8e929..9a458c93 100644 --- a/src/ns.c +++ b/src/ns.c @@ -6,8 +6,8 @@ void m_nsDesc(Body* body, bool imm, u8 ty, i32 actualVam, B nameList, B varIDs, B exported) { // doesn't consume nameList if (!isArr(varIDs) || !isArr(exported)) thrM("Bad namespace description information"); - usz ia = a(varIDs)->ia; - if (ia!=a(exported)->ia) thrM("Bad namespace description information"); + usz ia = IA(varIDs); + if (ia!=IA(exported)) thrM("Bad namespace description information"); i32 off = (ty==0?0:ty==1?2:3) + (imm?0:3); i32 vam = ia+off; diff --git a/src/singeli/c/cmp.c b/src/singeli/c/cmp.c index 1c796c7b..036f58da 100644 --- a/src/singeli/c/cmp.c +++ b/src/singeli/c/cmp.c @@ -36,7 +36,7 @@ FN_LUT(avx2, ge, AS); FN_LUT(avx2, ge, AA); FN_LUT(avx2, lt, AS); FN_LUT(avx2, le, AS); -#define AL(X) u64* rp; B r = m_bitarrc(&rp, X); usz ria=a(r)->ia +#define AL(X) u64* rp; B r = m_bitarrc(&rp, X); usz ria=IA(r) #define CMP_IMPL(CHR, NAME, RNAME, PNAME, L, R, OP, FC, CF, BX) \ if (isF64(w)&isF64(x)) return m_i32(w.f OP x.f); \ if (isC32(w)&isC32(x)) return m_i32(w.u OP x.u); \ diff --git a/src/utils/bits.c b/src/utils/bits.c index cf48b722..2ecf10bd 100644 --- a/src/utils/bits.c +++ b/src/utils/bits.c @@ -9,7 +9,7 @@ NOINLINE B bit_sel(B b, B e0, bool h0, B e1, bool h1) { if (!h0) t0=t1; // TODO just do separate impls for !h0 and !h1 if (!h1) t1=t0; u64* bp = bitarr_ptr(b); - usz ia = a(b)->ia; + usz ia = IA(b); if (elNum(t0) && elNum(t1)) { B r; f64 f0 = o2fu(e0); i32 i0 = f0; f64 f1 = o2fu(e1); i32 i1 = f1; diff --git a/src/utils/each.c b/src/utils/each.c index 67091511..ef8336b0 100644 --- a/src/utils/each.c +++ b/src/utils/each.c @@ -35,13 +35,13 @@ B eachd_fn(B fo, B w, B x, BBB2B f) { } B bo = wg? w : x; - usz ria = a(bo)->ia; + usz ria = IA(bo); M_HARR(r, ria) if (wr==xr) for(usz ri=0; ri0) { - usz min = wg? a(x)->ia : a(w)->ia; + usz min = wg? IA(x) : IA(w); usz ext = ria / min; if (wg) for (usz i = 0; i < min; i++) { B c=Get(x,i); for (usz j = 0; j < ext; j++) HARR_ADDA(r, f(fo, Get(w,HARR_I(r)), inc(c))); } else for (usz i = 0; i < min; i++) { B c=Get(w,i); for (usz j = 0; j < ext; j++) HARR_ADDA(r, f(fo, inc(c), Get(x,HARR_I(r)))); } @@ -52,7 +52,7 @@ B eachd_fn(B fo, B w, B x, BBB2B f) { } B eachm_fn(B fo, B x, BB2B f) { // TODO definitely rewrite this. Probably still has refcounting errors - usz ia = a(x)->ia; + usz ia = IA(x); if (ia==0) return x; SGet(x); usz i = 0; diff --git a/src/utils/each.h b/src/utils/each.h index 3c78b2d8..a4910158 100644 --- a/src/utils/each.h +++ b/src/utils/each.h @@ -7,9 +7,9 @@ B eachm_fn(B fo, B x, BB2B f); // consumes x; x must be array static B eachm(B f, B x) { // complete F¨ x without fills; consumes x if (isAtm(x)) return m_hunit(c1(f, x)); if (isFun(f)) return eachm_fn(f, x, c(Fun,f)->c1); - if (isMd(f)) if (isAtm(x) || a(x)->ia) { decR(x); thrM("Calling a modifier"); } + if (isMd(f)) if (isAtm(x) || IA(x)) { decR(x); thrM("Calling a modifier"); } - usz ia = a(x)->ia; + usz ia = IA(x); MAKE_MUT(r, ia); mut_fill(r, 0, f, ia); return mut_fcd(r, x); diff --git a/src/utils/file.c b/src/utils/file.c index 7dba4fb6..57c04c54 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -88,7 +88,7 @@ B path_lines(B path) { // consumes; TODO rewrite this, it's horrible static NOINLINE void guaranteeStr(B x) { // assumes x is an array if (elChr(TI(x,elType))) return; - usz xia = a(x)->ia; + usz xia = IA(x); SGetU(x) for (usz i = 0; i < xia; i++) if (!isC32(GetU(x, i))) thrM("Paths must be character vectors"); } @@ -98,13 +98,13 @@ B path_rel(B base, B rel) { // consumes rel; assumes base is a char vector or bi assert(isArr(base) || q_N(base)); if (!isArr(rel) || rnk(rel)!=1) thrM("Paths must be character vectors"); SGetU(rel) - usz ria = a(rel)->ia; + usz ria = IA(rel); if (rnk(rel)!=1) thrM("Paths must be character vectors"); guaranteeStr(rel); 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 incG(base); } - usz bia = a(base)->ia; + usz bia = IA(base); if (bia==0) return rel; SGetU(base) bool has = o2cu(GetU(base, bia-1))=='/'; @@ -120,7 +120,7 @@ B path_rel(B base, B rel) { // consumes rel; assumes base is a char vector or bi B path_dir(B path) { assert(isArr(path)); SGetU(path) - usz pia = a(path)->ia; + usz pia = IA(path); if (pia==0) thrM("Empty file path"); guaranteeStr(path); for (i64 i = (i64)pia-1; i >= 0; i--) { @@ -133,7 +133,7 @@ B path_dir(B path) { B path_name(B path) { assert(isArr(path)); SGetU(path) - usz pia = a(path)->ia; + usz pia = IA(path); if (pia==0) thrM("Empty file path"); guaranteeStr(path); for (i64 i = (i64)pia-1; i >= 0; i--) { @@ -178,7 +178,7 @@ void path_wChars(B path, B x) { // consumes path fclose(f); } void file_wBytes(FILE* f, B name, B x) { - u64 len = a(x)->ia; + u64 len = IA(x); bool newBuf = false; char* buf; diff --git a/src/utils/hash.c b/src/utils/hash.c index 438f7319..47f2bd4d 100644 --- a/src/utils/hash.c +++ b/src/utils/hash.c @@ -3,7 +3,7 @@ #include "time.h" NOINLINE u64 bqn_hashArr(B x, const u64 secret[4]) { // TODO manual separation of atom & arr probably won't be worth it when there are actually sane typed array hashing things - usz xia = a(x)->ia; + usz xia = IA(x); if (xia==0) return ~secret[3]; // otherwise squeeze will care about fills x = any_squeeze(incG(x)); u8 xr = rnk(x); diff --git a/src/utils/mut.c b/src/utils/mut.c index 425d6445..f6f3d732 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -35,7 +35,7 @@ NOINLINE void mut_to(Mut* m, u8 n) { } NOINLINE B vec_addF(B w, B x) { - usz wia = a(w)->ia; + usz wia = IA(w); MAKE_MUT(r, wia+1); mut_init(r, el_or(TI(w,elType), selfElType(x))); MUTG_INIT(r); mut_copyG(r, 0, w, 0, wia); @@ -237,7 +237,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x } \ static copy_fn copy##T##Fns[] = __VA_ARGS__; \ T##Arr* cpy##T##Arr(B x) { \ - usz ia = a(x)->ia; \ + usz ia = IA(x); \ MAKE; arr_shCopy(r, x); \ if (ia>0) { \ copy##T##Fns[TI(x,elType)](tyany_ptr(x), (u8*)(XRP), ia, (u8*)a(x)); \ @@ -288,7 +288,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x } #else #define MAKE_ICPY(T,E) T##Arr* cpy##T##Arr(B x) { \ - usz ia = a(x)->ia; \ + usz ia = IA(x); \ E* rp; Arr* r = m_##E##arrp(&rp, ia); \ arr_shCopy(r, x); \ u8 xe = TI(x,elType); \ @@ -308,7 +308,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x #define MAKE_CCPY(T,E) \ T##Arr* cpy##T##Arr(B x) { \ - usz ia = a(x)->ia; \ + usz ia = IA(x); \ T##Atom* rp; Arr* r = m_##E##arrp(&rp, ia); \ arr_shCopy(r, x); \ u8 xe = TI(x,elType); \ @@ -325,7 +325,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x } HArr* cpyHArr(B x) { - usz ia = a(x)->ia; + usz ia = IA(x); HArr_p r = m_harrUc(x); u8 xe = TI(x,elType); if (xe==el_bit) { u64* xp = bitarr_ptr(x); for(usz i=0; iia; + usz ia = IA(x); u64* rp; Arr* r = m_bitarrp(&rp, ia); arr_shCopy(r, x); u8 xe = TI(x,elType); diff --git a/src/utils/mut.h b/src/utils/mut.h index 73a7d9f5..4a51f833 100644 --- a/src/utils/mut.h +++ b/src/utils/mut.h @@ -43,7 +43,7 @@ struct Mut { static void mut_init(Mut* m, u8 n) { m->fns = &mutFns[n]; - usz ia = m->ia; + usz ia = PIA(m); usz sz; // hack around inlining of the allocator too many times switch(n) { default: UD; @@ -161,8 +161,8 @@ B vec_join(B w, B x); // consumes both // if `consume==true`, consumes w,x and expects both args to be vectors // else, doesn't consume x, and decrements refcount of w iif *reusedW (won't free because the result will be w) FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* reusedW) { - usz wia = a(w)->ia; - usz xia = a(x)->ia; + usz wia = IA(w); + usz xia = IA(x); usz ria = wia+xia; if (reusable(w)) { u64 wsz = mm_size(v(w)); @@ -216,7 +216,7 @@ FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* reusedW) { } static inline bool inplace_add(B w, B x) { // consumes x if returns true; fails if fills wouldn't be correct - usz wia = a(w)->ia; + usz wia = IA(w); usz ria = wia+1; if (reusable(w)) { u64 wsz = mm_size(v(w)); diff --git a/src/utils/utf.c b/src/utils/utf.c index 4c790da4..1382209d 100644 --- a/src/utils/utf.c +++ b/src/utils/utf.c @@ -50,7 +50,7 @@ B utf8Decode0(const char* s) { } B utf8DecodeA(I8Arr* a) { // consumes a - B r = utf8Decode((char*)a->a, a->ia); + B r = utf8Decode((char*)a->a, PIA(a)); ptr_dec(a); return r; } @@ -72,7 +72,7 @@ void fprintUTF8(FILE* f, u32 c) { u64 utf8lenB(B x) { // doesn't consume; may error as it verifies whether is all chars assert(isArr(x)); SGetU(x) - usz ia = a(x)->ia; + usz ia = IA(x); u64 res = 0; for (usz i = 0; i < ia; i++) { u32 c = o2c(GetU(x,i)); @@ -82,7 +82,7 @@ u64 utf8lenB(B x) { // doesn't consume; may error as it verifies whether is all } void toUTF8(B x, char* p) { SGetU(x) - usz ia = a(x)->ia; + usz ia = IA(x); for (usz i = 0; i < ia; i++) { u32 c = o2cu(GetU(x,i)); if (c<128) { *p++ = c; } diff --git a/src/vm.c b/src/vm.c index b010b7b3..50a0f344 100644 --- a/src/vm.c +++ b/src/vm.c @@ -135,7 +135,7 @@ typedef struct NextRequest { static B emptyARMM; Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBlocks, B allBodies, B nameList, Scope* sc, i32 depth, i32 myPos) { - usz blIA = a(block)->ia; + usz blIA = IA(block); if (blIA!=3) thrM("VM compiler: Bad block info size"); SGetU(block) usz ty = o2s(GetU(block,0)); if (ty>2) thrM("VM compiler: Bad type"); @@ -159,7 +159,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl Body* startBodies[6] = {failBody,failBody,failBody,failBody,failBody,failBody}; bool boArr = isArr(bodyObj); - i32 boCount = boArr? a(bodyObj)->ia : 1; + i32 boCount = boArr? IA(bodyObj) : 1; if (boCount<1 || boCount>5) thrM("VM compiler: Unexpected body list length"); // if (boArr) { print(bodyObj); putchar('\n'); } i32 firstMPos = failBodyI; @@ -180,8 +180,8 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl b2 = i+1ia; SGetU(b1) - dCount = a(b2)->ia; SGetU(b2) + mCount = IA(b1); SGetU(b1) + dCount = IA(b2); SGetU(b2) mapLen = mCount+dCount; TALLOC(i32, bodyPs_, mapLen+2); bodyPs = bodyPs_; i32* bodyM = bodyPs; @@ -221,7 +221,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl 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"); + usz boIA = IA(bodyRepr); if (boIA!=2 && boIA!=4) thrM("VM compiler: Body array had invalid length"); 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 @@ -312,7 +312,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl break; case DFND: { u32 id = c[1]; - if ((u32)id >= a(allBlocks)->ia) thrM("VM compiler: DFND index out-of-bounds"); + if ((u32)id >= IA(allBlocks)) 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(IGetU(allBlocks,id), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, depth+1, c-bc); @@ -437,10 +437,10 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl // consumes all; assumes arguments are valid (verifies some stuff, but definitely not everything) // if sc isn't NULL, this block must only be evaluated directly in that scope precisely once NOINLINE Block* compile(B bcq, B objs, B allBlocks, B allBodies, B indices, B tokenInfo, B src, B path, Scope* sc) { - usz bIA = a(allBlocks)->ia; + usz bIA = IA(allBlocks); I32Arr* bca = toI32Arr(bcq); u32* bc = (u32*)bca->a; - usz bcIA = bca->ia; + usz bcIA = PIA(bca); Comp* comp = mm_alloc(sizeof(Comp), t_comp); comp->bc = taga(bca); comp->indices = indices; @@ -459,14 +459,14 @@ NOINLINE Block* compile(B bcq, B objs, B allBlocks, B allBodies, B indices, B to // and now finally it's safe to allocate stuff HArr* objArr = cpyHArr(objs); comp->objs = objArr; - usz objAm = objArr->ia; + usz objAm = PIA(objArr); for (usz i = 0; i < objAm; i++) objArr->a[i] = squeeze_deep(objArr->a[i]); if (!q_N(src) && !q_N(indices)) { - if (isAtm(indices) || rnk(indices)!=1 || a(indices)->ia!=2) thrM("VM compiler: Bad indices"); + if (isAtm(indices) || rnk(indices)!=1 || IA(indices)!=2) thrM("VM compiler: Bad indices"); for (i32 i = 0; i < 2; i++) { B ind = IGetU(indices,i); - if (isAtm(ind) || rnk(ind)!=1 || a(ind)->ia!=bcIA) thrM("VM compiler: Bad indices"); + if (isAtm(ind) || rnk(ind)!=1 || IA(ind)!=bcIA) thrM("VM compiler: Bad indices"); SGetU(ind) for (usz j = 0; j < bcIA; j++) o2i(GetU(ind,j)); } @@ -487,7 +487,7 @@ FORCE_INLINE bool v_merge(Scope* pscs[], B s, B x, bool upd, bool hdr) { if (!isArr(x) || rnk(x)==0) thrF("[…]%U𝕩: 𝕩 cannot have rank 0", upd? "↩" : "←"); B* op = harr_ptr(o); - usz oia = a(o)->ia; + usz oia = IA(o); if (a(x)->sh[0] != oia) { if (hdr) return false; @@ -517,7 +517,7 @@ FORCE_INLINE bool v_merge(Scope* pscs[], B s, B x, bool upd, bool hdr) { NOINLINE void v_setF(Scope* pscs[], B s, B x, bool upd) { if (isArr(s)) { VTY(s, t_harr); B* sp = harr_ptr(s); - usz ia = a(s)->ia; + usz ia = IA(s); if (isAtm(x) || !eqShape(s, x)) { if (!isNsp(x)) thrM("Assignment: Mismatched shape for spread assignment"); for (u64 i = 0; i < ia; i++) { @@ -558,7 +558,7 @@ NOINLINE bool v_sethF(Scope* pscs[], B s, B x) { if (isArr(s)) { VTY(s, t_harr); B* sp = harr_ptr(s); - usz ia = a(s)->ia; + usz ia = IA(s); if (isAtm(x) || !eqShape(s, x)) { if (!isNsp(x)) return false; for (u64 i = 0; i < ia; i++) { @@ -591,7 +591,7 @@ NOINLINE bool v_sethF(Scope* pscs[], B s, B x) { NOINLINE B v_getF(Scope* pscs[], B s) { if (isArr(s)) { VTY(s, t_harr); - usz ia = a(s)->ia; + usz ia = IA(s); B* sp = harr_ptr(s); HArr_p r = m_harrUv(ia); for (u64 i = 0; i < ia; i++) r.a[i] = v_get(pscs, sp[i], true); @@ -1288,7 +1288,7 @@ void popCatch() { NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes prepend SGetU(src) - usz srcL = a(src)->ia; + usz srcL = IA(src); usz srcS = cs; while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--; usz srcE = srcS; @@ -1298,9 +1298,9 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p i64 ln = 1; 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 && IGetU(path,0).u!=m_c32('.').u))) AFMT("%R:%l:\n ", path, ln); + if (isArr(path) && (IA(path)>1 || (IA(path)==1 && IGetU(path,0).u!=m_c32('.').u))) AFMT("%R:%l:\n ", path, ln); else AFMT("at "); - i64 padEnd = (i64)a(s)->ia; + i64 padEnd = (i64)IA(s); i64 padStart = padEnd; SGetU(s) while (padStart>0 && o2cu(GetU(s,padStart-1))!='\n') padStart--; @@ -1340,7 +1340,7 @@ NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) { native_print: freeThrown(); int start = fprintf(stderr, "at "); - usz srcL = a(src)->ia; + usz srcL = IA(src); SGetU(src) usz srcS = cs; while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--; usz srcE = srcS; while (srcEsrc)? 1 : a(comp->src)->ia; + usz ia = q_N(comp->src)? 1 : IA(comp->src); mapList = vec_addN(mapList, m_i32arrv(&rp, ia)); for (i32 i = 0; i < ia; i++) rp[i] = 0; compCount++; @@ -1518,7 +1518,7 @@ void profiler_displayResults() { i32* m = i32arr_ptr(mapObj); u64 sum = 0; - usz ia = a(mapObj)->ia; + usz ia = IA(mapObj); for (usz i = 0; i < ia; i++) sum+= m[i]; if (q_N(c->src)) { @@ -1531,7 +1531,7 @@ void profiler_displayResults() { printf(": "N64d" samples:\n", sum); B src = c->src; SGetU(src) - usz sia = a(src)->ia; + usz sia = IA(src); usz pi = 0; i32 curr = 0; for (usz i = 0; i < sia; i++) { @@ -1583,7 +1583,7 @@ void unwindCompiler() { NOINLINE void printErrMsg(B msg) { if (isArr(msg)) { SGetU(msg) - usz msgLen = a(msg)->ia; + usz msgLen = IA(msg); for (usz i = 0; i < msgLen; i++) if (!isC32(GetU(msg,i))) goto base; fprintRaw(stderr,msg); return;