From d2a4efe4b5c9bdd9b7d5415d2327c1b320bb7112 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 19 Aug 2022 22:56:29 +0300 Subject: [PATCH] =?UTF-8?q?x->sh=20=E2=86=92=20SH(x)=20/=20PSH(x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/arithd.c | 4 ++-- src/builtins/arithm.c | 2 +- src/builtins/fns.c | 2 +- src/builtins/md1.c | 24 +++++++++---------- src/builtins/md2.c | 16 ++++++------- src/builtins/select.c | 16 ++++++------- src/builtins/sfns.c | 54 +++++++++++++++++++++---------------------- src/builtins/sysfn.c | 2 +- src/core/harr.c | 8 +++---- src/core/stuff.c | 24 +++++++++---------- src/core/stuff.h | 12 +++++----- src/ffi.c | 2 +- src/h.h | 3 +++ src/utils/each.c | 2 +- src/utils/hash.c | 2 +- src/vm.c | 2 +- 16 files changed, 89 insertions(+), 86 deletions(-) diff --git a/src/builtins/arithd.c b/src/builtins/arithd.c index f7daf6cb..6ab0561e 100644 --- a/src/builtins/arithd.c +++ b/src/builtins/arithd.c @@ -22,7 +22,7 @@ EXTRA \ 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); \ + if (!eqShPart(SH(w), SH(x), rnk(w))) thrF(SYMB ": Expected equal shape prefix (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); \ usz ia = IA(x); \ u8 we = TI(w,elType); \ u8 xe = TI(x,elType); \ @@ -159,7 +159,7 @@ EXTRA2 \ 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); \ + if (!eqShPart(SH(w), SH(x), rnk(w))) thrF(SYMB ": Expected equal shape prefix (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); \ usz ia = IA(x); \ u8 we = TI(w,elType); \ u8 xe = TI(x,elType); \ diff --git a/src/builtins/arithm.c b/src/builtins/arithm.c index d01e3f60..5d74b01d 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -72,7 +72,7 @@ B atan_c1(B t, B x) { if (isF64(x)) return m_f64( atan(x.f)); P1( atan); thrM(" B lt_c1(B t, B x) { return m_atomUnit(x); } B eq_c1(B t, B x) { if (isAtm(x)) { decA(x); return m_i32(0); } B r = m_i32(rnk(x) ); decG(x); return r; } -B ne_c1(B t, B x) { if (isAtm(x)) { decA(x); return m_i32(1); } B r = m_f64(*a(x)->sh); decG(x); return r; } +B ne_c1(B t, B x) { if (isAtm(x)) { decA(x); return m_i32(1); } B r = m_f64(*SH(x)); decG(x); return r; } static B mathNS; diff --git a/src/builtins/fns.c b/src/builtins/fns.c index 3814b537..98dbcef4 100644 --- a/src/builtins/fns.c +++ b/src/builtins/fns.c @@ -92,7 +92,7 @@ B fne_c1(B t, B x) { return emptyIVec(); } ur xr = rnk(x); - usz* sh = a(x)->sh; + usz* sh = SH(x); usz or = 0; for (i32 i = 0; i < xr; i++) or|= sh[i]; B r; diff --git a/src/builtins/md1.c b/src/builtins/md1.c index f57f3e66..c029efbc 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -88,8 +88,8 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f; r = HARR_O(r).b; } if (rsh) { - shcpy(rsh , a(w)->sh, wr); - shcpy(rsh+wr, a(x)->sh, xr); + shcpy(rsh , SH(w), wr); + shcpy(rsh+wr, SH(x), xr); } decG(w); decG(x); if (EACH_FILLS) return homFil2(f, r, wf, xf); @@ -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 = IA(x); + ur xr = rnk(x); usz* xsh = SH(x); usz ia = IA(x); B wf = getFillQ(w); u8 xe = TI(x,elType); if (xr==1 && q_i32(w) && xeflags) { @@ -275,7 +275,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f; BBB2B fc2 = c2fn(f); if (isArr(w)) { - ur wr = rnk(w); usz* wsh = a(w)->sh; SGet(w) + ur wr = rnk(w); usz* wsh = SH(w); SGet(w) if (wr+1!=xr || !eqShPart(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); @@ -461,11 +461,11 @@ static B m1c2(B t, B f, B w, B x) { // consumes w,x if (X##_cr>1) { \ X##_csh = m_shArr(X##_cr); \ NOUNROLL for (usz i = 0; i < X##_cr; i++) { \ - usz v = a(X)->sh[i+1]; \ + usz v = SH(X)[i+1]; \ X##_csz*= v; \ X##_csh->a[i] = v; \ } \ - } else if (X##_cr!=0) X##_csz*= a(X)->sh[1]; + } else if (X##_cr!=0) X##_csz*= SH(X)[1]; #define SLICE(X, S) ({ Arr* r_ = X##_slc(incG(X), S, X##_csz); arr_shSetI(r_, X##_cr, X##_csh); taga(r_); }) @@ -490,7 +490,7 @@ static B merge_fill_result_1(B rc) { usz* rsh = arr_shAlloc(r, rr); if (rr>1) { rsh[0] = 0; - shcpy(rsh+1, a(rc)->sh, rr-1); + shcpy(rsh+1, SH(rc), rr-1); } dec(rc); return taga(r); @@ -513,7 +513,7 @@ B cell_c1(Md1D* d, B x) { B f = d->f; if (Q_BI(f,lt) && IA(x)!=0 && rnk(x)>1) return toCells(x); - usz cam = a(x)->sh[0]; + usz cam = SH(x)[0]; if (cam==0) { if (!isPureFn(f) || !CATCH_ERRORS) { decG(x); return emptyHVec(); } B cf = to_fill_cell_1(x); @@ -536,7 +536,7 @@ B cell_c2(Md1D* d, B w, B x) { B f = d->f; B r; if (wr==0 && xr==0) return isAtm(r = c2(f, w, x))? m_atomUnit(r) : r; if (wr==0) { - usz cam = a(x)->sh[0]; + usz cam = SH(x)[0]; if (cam==0) return cell2_empty(f, w, x, wr, xr); S_SLICES(x) M_HARR(r, cam); @@ -544,7 +544,7 @@ B cell_c2(Md1D* d, B w, B x) { B f = d->f; E_SLICES(x) dec(w); r = HARR_FV(r); } else if (xr==0) { - usz cam = a(w)->sh[0]; + usz cam = SH(w)[0]; if (cam==0) return cell2_empty(f, w, x, wr, xr); S_SLICES(w) M_HARR(r, cam); @@ -552,9 +552,9 @@ B cell_c2(Md1D* d, B w, B x) { B f = d->f; E_SLICES(w) dec(x); r = HARR_FV(r); } else { - usz cam = a(w)->sh[0]; + usz cam = SH(w)[0]; if (cam==0) return cell2_empty(f, w, x, wr, xr); - if (cam != a(x)->sh[0]) thrF("˘: Leading axis of arguments not equal (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); + if (cam != SH(x)[0]) thrF("˘: Leading axis of arguments not equal (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); S_SLICES(w) S_SLICES(x) M_HARR(r, cam); for (usz i=0,wp=0,xp=0; ish+k; + usz* sh = SH(x)+k; usz csz = 1; for (usz i=0; i1) { shcpy(rsh, sh, k); - shcpy(rsh+k, a(rc)->sh, rr-k); + shcpy(rsh+k, SH(rc), rr-k); } dec(rc); return taga(r); @@ -258,7 +258,7 @@ static B empty_frame(usz* xsh, ur k) { static B rank2_empty(B f, B w, ur wk, B x, ur xk) { B fa = wk>xk?w:x; ur k = wk>xk?wk:xk; - usz* sh = a(fa)->sh; + usz* sh = SH(fa); usz s0=0; ShArr* s=NULL; ur sho=rnk(fa)>1; if (!sho) { s0=sh[0]; sh=&s0; } else { s=ptr_inc(shObj(fa)); } if (!isPureFn(f) || !CATCH_ERRORS) { dec(w); dec(x); goto empty; } @@ -297,7 +297,7 @@ B rank_c1(Md2D* d, B x) { B f = d->f; B g = d->g; i32 k = xr - cr; if (Q_BI(f,lt) && IA(x)!=0 && rnk(x)>1) return toKCells(x, k); - usz* xsh = a(x)->sh; + usz* xsh = SH(x); usz cam = shProd(xsh, 0, k); if (cam == 0) { usz s0=0; ShArr* s=NULL; @@ -363,7 +363,7 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g; return isAtm(r)? m_atomUnit(r) : r; } else { i32 k = xr - xc; - usz* xsh = a(x)->sh; + usz* xsh = SH(x); usz cam = shProd(xsh, 0, k); if (cam == 0) return rank2_empty(f, w, 0, x, k); usz csz = shProd(xsh, k, xr); @@ -387,7 +387,7 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g; } } else if (xr == xc) { i32 k = wr - wc; - usz* wsh = a(w)->sh; + usz* wsh = SH(w); usz cam = shProd(wsh, 0, k); if (cam == 0) return rank2_empty(f, w, k, x, 0); usz csz = shProd(wsh, k, wr); @@ -409,8 +409,8 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g; decG(w); dec(x); r = HARR_O(r).b; } else { - i32 wk = wr - wc; usz* wsh = a(w)->sh; - i32 xk = xr - xc; usz* xsh = a(x)->sh; + i32 wk = wr - wc; usz* wsh = SH(w); + i32 xk = xr - xc; usz* xsh = SH(x); i32 k=wk, zk=xk; if (k>zk) { i32 t=k; k=zk; zk=t; } usz* zsh = wk>xk? wsh : xsh; diff --git a/src/builtins/select.c b/src/builtins/select.c index e0769cea..f90fedc6 100644 --- a/src/builtins/select.c +++ b/src/builtins/select.c @@ -15,11 +15,11 @@ B select_c1(B t, B x) { if (isAtm(x)) thrM("⊏: Argument cannot be an atom"); ur xr = rnk(x); if (xr==0) thrM("⊏: Argument cannot be rank 0"); - if (a(x)->sh[0]==0) thrF("⊏: Argument shape cannot start with 0 (%H ≑ ≒𝕩)", x); - usz ia = shProd(a(x)->sh, 1, xr); + if (SH(x)[0]==0) thrF("⊏: Argument shape cannot start with 0 (%H ≑ ≒𝕩)", x); + usz ia = shProd(SH(x), 1, xr); Arr* r = TI(x,slice)(incG(x), 0, ia); usz* sh = arr_shAlloc(r, xr-1); - if (sh) shcpy(sh, a(x)->sh+1, xr-1); + if (sh) shcpy(sh, SH(x)+1, xr-1); decG(x); return taga(r); } @@ -29,11 +29,11 @@ B select_c2(B t, B w, B x) { if (isAtm(w)) { if (xr==0) thrM("⊏: 𝕩 cannot be a unit"); usz csz = arr_csz(x); - usz cam = a(x)->sh[0]; + usz cam = SH(x)[0]; usz wi = WRAP(o2i64(w), cam, thrF("⊏: Indexing out-of-bounds (𝕨≑%R, %s≑≠𝕩)", w, cam)); Arr* r = TI(x,slice)(incG(x), wi*csz, csz); usz* sh = arr_shAlloc(r, xr-1); - if (sh) shcpy(sh, a(x)->sh+1, xr-1); + if (sh) shcpy(sh, SH(x)+1, xr-1); decG(x); return taga(r); } @@ -131,7 +131,7 @@ B select_c2(B t, B w, B x) { if (xr==0) thrM("⊏: 𝕩 cannot be a unit"); if (rr>UR_MAX) thrF("⊏: Result rank too large (%i≑=𝕨, %i≑=𝕩)", wr, xr); usz csz = arr_csz(x); - usz cam = a(x)->sh[0]; + usz cam = SH(x)[0]; MAKE_MUT(r, wia*csz); mut_init(r, TI(x,elType)); MUTG_INIT(r); for (usz i = 0; i < wia; i++) { @@ -145,8 +145,8 @@ B select_c2(B t, B w, B x) { Arr* ra = mut_fp(r); usz* rsh = arr_shAlloc(ra, rr); if (rsh) { - shcpy(rsh , a(w)->sh , wr ); - shcpy(rsh+wr, a(x)->sh+1, xr-1); + shcpy(rsh , SH(w) , wr ); + shcpy(rsh+wr, SH(x)+1, xr-1); } decG(w); decG(x); return withFill(taga(ra),xf); diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 371a3872..4dde93ce 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -263,7 +263,7 @@ static B recPick(B w, B x) { // doesn't consume assert(isArr(w) && isArr(x)); usz ia = IA(w); ur xr = rnk(x); - usz* xsh = a(x)->sh; + usz* xsh = SH(x); switch(TI(w,elType)) { default: UD; case el_i8: { i8* wp = i8any_ptr (w); if(rnk(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { c = c*xsh[i] + WRAP(wp[i], xsh[i], goto oob); }; return IGet(x,c); } case el_i16: { i16* wp = i16any_ptr(w); if(rnk(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { c = c*xsh[i] + WRAP(wp[i], xsh[i], goto oob); }; return IGet(x,c); } @@ -769,7 +769,7 @@ static B slicev(B x, usz s, usz ia) { FORCE_INLINE B affixes(B x, i32 post) { if (!isArr(x) || rnk(x)==0) thrM(post? "↓: Argument must have rank at least 1" : "↑: Argument must have rank at least 1"); ur xr = rnk(x); - usz* xsh = a(x)->sh; + usz* xsh = SH(x); u64 cam = *xsh; u64 ria = cam+1; M_HARR(r, ria); @@ -809,7 +809,7 @@ B take_c2(B t, B w, B x) { usz* xsh; if (xr>1) { csz = arr_csz(x); - xsh = a(x)->sh; + xsh = SH(x); ptr_inc(shObjS(xsh)); // we'll look at it at the end and dec there } i64 t = wv*csz; // TODO error on overflow somehow @@ -872,9 +872,9 @@ B join_c1(B t, B x) { usz* sh = arr_shAlloc((Arr*)r.c, ir); if (sh) { sh[0] = 0; - usz* fsh = a(xf)->sh; + usz* fsh = SH(xf); if (xr>1) { - usz* xsh = a(x)->sh; + usz* xsh = SH(x); for (usz i = 0; i < xr; i++) sh[i] = xsh[i]*fsh[i]; } shcpy(sh+xr, fsh+xr, ir-xr); @@ -892,7 +892,7 @@ B join_c1(B t, B x) { usz* esh = NULL; usz cam = 1; // Result length if (rm) { - esh = a(x0)->sh; + esh = SH(x0); cam = *esh++; } else { rr++; @@ -905,7 +905,7 @@ B join_c1(B t, B x) { if (rm > 1) thrF("∾: Item ranks in a list can differ by at most one (contained ranks %i and %i)", 0, rm); rd=rm; cam++; } else { - usz* csh = a(c)->sh; + usz* csh = SH(c); ur cd = rm - cr; if (RARE(cd > rd)) { if ((ur)(cd+1-rd) > 2-rd) thrF("∾: Item ranks in a list can differ by at most one (contained ranks %i and %i)", rm-rd*(cr==rm), cr); @@ -956,7 +956,7 @@ B join_c1(B t, B x) { ur r0 = isAtm(x0) ? 0 : rnk(x0); usz xia = IA(x); - usz* xsh = a(x)->sh; + usz* xsh = SH(x); usz tlen = 4*xr+2*r0; for (usz a=0; a1; ) st[a-1] = st[a]*xsh[a]; // Stride @@ -974,7 +974,7 @@ B join_c1(B t, B x) { usz *ll = lp+lp[a]; if (n == 1) { if (!tr) thrM("∾: Ranks of argument items too small"); - st[a] = ll[0] = a(x0)->sh[r0-tr]; + st[a] = ll[0] = SH(x0)[r0-tr]; tr--; continue; } usz step = st[a]; @@ -994,7 +994,7 @@ B join_c1(B t, B x) { ll[i] = -1; } else { B c = GetU(x, i*step); - ll[i] = a(c)->sh[r0-tr]; + ll[i] = SH(c)[r0-tr]; } } @@ -1005,7 +1005,7 @@ B join_c1(B t, B x) { ur r1 = r+1-a0; ur lr = 0; if (r) { - usz* sh=a(base)->sh; + usz* sh=SH(base); lr = r - tr; shcpy(tsh,sh,r); shcpy(tsh0,sh,r); if (!a0) shcpy(tsh +lr+1, tsh +lr , tr ); @@ -1015,7 +1015,7 @@ B join_c1(B t, B x) { B c = GetU(x, j+i*step); bool rd = ll[i]==-1; tsh[lr] = ll[i]; - ur cr=0; usz* sh=NULL; if (!isAtm(c)) { cr=rnk(c); sh=a(c)->sh; } + ur cr=0; usz* sh=NULL; if (!isAtm(c)) { cr=rnk(c); sh=SH(c); } if (cr != r1-rd) thrF("∾: Incompatible item ranks", base, c); if (!eqShPart(rd?tsh0:tsh, sh, cr)) thrF("∾: Incompatible item shapes (contained arrays with shapes %H and %H along axis %i)", base, c, a); if (SFNS_FILLS && !noFill(rf)) rf = fill_or(rf, getFillQ(c)); @@ -1032,7 +1032,7 @@ B join_c1(B t, B x) { } // Move the data - usz* csh = tr ? a(x0)->sh + r0-tr : NULL; // Trailing shape + usz* csh = tr ? SH(x0) + r0-tr : NULL; // Trailing shape usz csz = shProd(csh, 0, tr); MAKE_MUT(r, shProd(st, 0, xr)*csz); // Element index and effective shape, updated progressively @@ -1117,9 +1117,9 @@ B join_c2(B t, B w, B x) { 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 + wsh = SH(w); // when wr>1, shape object won't be disturbed by arr_join_inline } - usz* xsh = a(x)->sh; + usz* xsh = SH(x); srnk(r, 0); // otherwise shape allocation failing may break things usz* rsh = arr_shAlloc(a(r), c); #if PRINT_JOIN_REUSE @@ -1152,7 +1152,7 @@ B couple_c1(B t, B x) { 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); } + if (sh) { sh[0] = 1; shcpy(sh+1, SH(x), rr); } decG(x); return taga(r); } @@ -1169,7 +1169,7 @@ B couple_c2(B t, B w, B x) { mut_copyG(r, ia, x, 0, ia); Arr* ra = mut_fp(r); usz* sh = arr_shAlloc(ra, wr+1); - if (sh) { sh[0]=2; shcpy(sh+1, a(w)->sh, wr); } + if (sh) { sh[0]=2; shcpy(sh+1, SH(w), wr); } if (!SFNS_FILLS) { decG(w); decG(x); return taga(ra); } B rf = fill_both(w, x); decG(w); decG(x); @@ -1178,8 +1178,8 @@ B couple_c2(B t, B w, B x) { static inline void shift_check(B w, B x) { - ur wr = rnk(w); usz* wsh = a(w)->sh; - ur xr = rnk(x); usz* xsh = a(x)->sh; + ur wr = rnk(w); usz* wsh = SH(w); + ur xr = rnk(x); usz* xsh = SH(x); if (wr+1!=xr & wr!=xr) thrF("shift: =𝕨 must be =𝕩 or Β―1+=𝕩 (%i≑=𝕨, %i≑=𝕩)", wr, xr); for (i32 i = 1; i < xr; i++) if (wsh[i+wr-xr] != xsh[i]) thrF("shift: Lengths not matchable (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); } @@ -1398,7 +1398,7 @@ B reverse_c1(B t, B x) { B xf = getFillQ(x); SLOW1("βŒ½π•©", x); usz csz = arr_csz(x); - usz cam = a(x)->sh[0]; + usz cam = SH(x)[0]; usz rp = 0; usz ip = xia; MAKE_MUT(r, xia); mut_init(r, xe); @@ -1416,7 +1416,7 @@ B reverse_c2(B t, B w, B x) { usz xia = IA(x); if (xia==0) return x; B xf = getFillQ(x); - usz cam = a(x)->sh[0]; + usz cam = SH(x)[0]; usz csz = arr_csz(x); i64 am = o2i64(w); if ((u64)am >= (u64)cam) { am%= (i64)cam; if(am<0) am+= cam; } @@ -1436,7 +1436,7 @@ B transp_c1(B t, B x) { if (xr<=1) return x; usz ia = IA(x); - usz* xsh = a(x)->sh; + usz* xsh = SH(x); usz h = xsh[0]; usz w = xsh[1] * shProd(xsh, 2, xr); @@ -1581,12 +1581,12 @@ static B takedrop_ucw(i64 wi, B o, u64 am, B x, size_t xr) { Arr* arg = TI(x,slice)(incG(x), wi<0? lv : 0, tk); usz* ash = arr_shAlloc(arg, xr); - if (ash) { ash[0] = am; shcpy(ash+1, a(x)->sh+1, xr-1); } + if (ash) { ash[0] = am; shcpy(ash+1, SH(x)+1, xr-1); } B rep = c1(o, taga(arg)); if (isAtm(rep)) thrM("π”½βŒΎ(nβŠΈβ†‘): 𝔽 returned an atom"); - usz* repsh = a(rep)->sh; - if (rnk(rep)==0 || !eqShPart(repsh+1, a(x)->sh+1, xr-1) || repsh[0]!=am) thrM("π”½βŒΎ(nβŠΈβ†‘)𝕩: 𝔽 returned an array with a different shape than n↑𝕩"); + usz* repsh = SH(rep); + if (rnk(rep)==0 || !eqShPart(repsh+1, SH(x)+1, xr-1) || repsh[0]!=am) thrM("π”½βŒΎ(nβŠΈβ†‘)𝕩: 𝔽 returned an array with a different shape than n↑𝕩"); MAKE_MUT(r, xia); mut_init(r, el_or(TI(x,elType), TI(rep,elType))); MUTG_INIT(r); @@ -1608,7 +1608,7 @@ B take_ucw(B t, B o, B w, B x) { u64 am = wi<0? -wi : wi; if (isAtm(x)) x = m_vec1(x); ur xr = rnk(x); if (xr==0) xr = 1; - if (am>a(x)->sh[0]) thrF("π”½βŒΎ(nβŠΈβ†‘)𝕩: Cannot modify fill with Under (%l ≑ 𝕨, %H ≑ ≒𝕩)", wi, x); + if (am>SH(x)[0]) thrF("π”½βŒΎ(nβŠΈβ†‘)𝕩: Cannot modify fill with Under (%l ≑ 𝕨, %H ≑ ≒𝕩)", wi, x); return takedrop_ucw(wi, o, am, x, xr); } @@ -1618,7 +1618,7 @@ B drop_ucw(B t, B o, B w, B x) { u64 am = wi<0? -wi : wi; if (isAtm(x)) x = m_vec1(x); ur xr = rnk(x); if (xr==0) xr = 1; - usz cam = a(x)->sh[0]; + usz cam = SH(x)[0]; if (am>cam) am = cam; return takedrop_ucw(-wi, o, cam-am, x, xr); } diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 997c9f4c..4e9b8c3b 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -1096,7 +1096,7 @@ B bitcast_impl(B el0, B el1, B x) { CastType xt = getCastType(el0, x); CastType zt = getCastType(el1, bi_N); - usz* sh = a(x)->sh; + usz* sh = SH(x); u64 s=xt.s*(u64)sh[xr-1], zl=s/zt.s; if (zl*zt.s != s) thrM("β€’bit._cast: incompatible lengths"); if (zl>=USZ_MAX) thrM("β€’bit._cast: output too large"); diff --git a/src/core/harr.c b/src/core/harr.c index c17a841d..d846e110 100644 --- a/src/core/harr.c +++ b/src/core/harr.c @@ -5,7 +5,7 @@ B toCells(B x) { assert(isArr(x) && rnk(x)>1); - usz cam = a(x)->sh[0]; + usz cam = SH(x)[0]; usz csz = arr_csz(x); BSS2A slice = TI(x,slice); M_HARR(r, cam) @@ -18,7 +18,7 @@ B toCells(B x) { } else { usz cr = rnk(x)-1; ShArr* csh = m_shArr(cr); - usz* xsh = a(x)->sh; + usz* xsh = SH(x); shcpy(csh->a, xsh+1, cr); for (usz i = 0; i < cam; i++) { Arr* s = slice(incG(x), p, csz); arr_shSetI(s, cr, csh); @@ -32,7 +32,7 @@ B toCells(B x) { } B toKCells(B x, ur k) { assert(isArr(x) && k<=rnk(x) && k>=0); - ur xr = rnk(x); usz* xsh = a(x)->sh; + ur xr = rnk(x); usz* xsh = SH(x); ur cr = xr-k; usz cam = shProd(xsh, 0, k); usz csz = shProd(xsh, k, xr); @@ -119,7 +119,7 @@ static void harrP_visit(Value* x) { assert(x->type == t_harrPartial); 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 am = *SH(x); usz ia = IA(x); fprintf(f, "(partial HArr "N64d"/"N64d": ⟨", (u64)am, (u64)ia); for (usz i = 0; i < ia; i++) { diff --git a/src/core/stuff.c b/src/core/stuff.c index 1ba2c99a..2e3e0aca 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -102,7 +102,7 @@ void farr_print(FILE* f, B x) { // should accept refc=0 arguments for debugging fprint(f, GetU(x,0)); return; } - usz* sh = a(x)->sh; + usz* sh = SH(x); for (i32 i = 0; i < r; i++) { if(i==0)fprintf(f, N64d,(u64)sh[i]); else fprintf(f, "β€Ώ"N64d,(u64)sh[i]); @@ -259,7 +259,7 @@ NOINLINE B do_fmt(B s, char* p, va_list a) { } else { B o = va_arg(a, B); r = isArr(o)? rnk(o) : 0; - sh = isArr(o)? a(o)->sh : NULL; + sh = isArr(o)? SH(o) : NULL; } if (r==0) AU("⟨⟩"); else if (r==1) AFMT("⟨%s⟩", sh[0]); @@ -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=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(wa) { wia=1; wr=0; wsh=NULL; } else { wia=IA(w); wr=rnk(w); wsh=SH(w); wgetU=TI(w,getU); wArr = a(w); } + if(xa) { xia=1; xr=0; xsh=NULL; } else { xia=IA(x); xr=rnk(x); xsh=SH(x); 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)); @@ -459,8 +459,8 @@ NOINLINE bool equal(B w, B x) { // doesn't consume if (LIKELY(wr==1)) { if (ia != IA(w)) return false; } else { - usz* wsh = a(w)->sh; - usz* xsh = a(x)->sh; + usz* wsh = SH(w); + usz* xsh = SH(x); if (wsh!=xsh) for (usz i = 0; i < wr; i++) if (wsh[i]!=xsh[i]) return false; } if (ia==0) return true; @@ -624,8 +624,8 @@ B bqn_merge(B x) { if (xr+xfr > UR_MAX) thrM(">: Result rank too large"); usz* rsh = arr_shAlloc(r, xr+xfr); if (rsh) { - shcpy (rsh , a(x )->sh, xr); - if(xfr)shcpy(rsh+xr, a(xf)->sh, xfr); + shcpy (rsh , SH(x), xr); + if(xfr)shcpy(rsh+xr, SH(xf), xfr); } decG(x); dec(xf); return taga(r); @@ -633,7 +633,7 @@ B bqn_merge(B x) { SGetU(x) B x0 = GetU(x, 0); - usz* elSh = isArr(x0)? a(x0)->sh : NULL; + usz* elSh = isArr(x0)? SH(x0) : NULL; ur elR = isArr(x0)? rnk(x0) : 0; usz elIA = isArr(x0)? IA(x0) : 1; B fill = getFillQ(x0); @@ -643,7 +643,7 @@ B bqn_merge(B x) { usz rp = 0; for (usz i = 0; i < xia; i++) { B c = GetU(x, i); - if (isArr(c)? (elR!=rnk(c) || !eqShPart(elSh, a(c)->sh, elR)) : elR!=0) { mut_pfree(r, rp); thrF(">: Elements didn't have equal shapes (contained shapes %H and %H)", x0, c); } + if (isArr(c)? (elR!=rnk(c) || !eqShPart(elSh, SH(c), elR)) : elR!=0) { mut_pfree(r, rp); thrF(">: Elements didn't have equal shapes (contained shapes %H and %H)", x0, c); } if (isArr(c)) mut_copy(r, rp, c, 0, elIA); else mut_set(r, rp, inc(c)); if (!noFill(fill)) fill = fill_or(fill, getFillQ(c)); @@ -652,7 +652,7 @@ B bqn_merge(B x) { Arr* ra = mut_fp(r); usz* rsh = arr_shAlloc(ra, xr+elR); if (rsh) { - shcpy (rsh , a(x)->sh, xr); + shcpy (rsh , SH(x), xr); if (elSh)shcpy(rsh+xr, elSh, elR); } decG(x); @@ -807,7 +807,7 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); } Arr* a = (Arr*)x; if (prnk(x)<=1) assert(a->sh == &a->ia); else { - assert(shProd(a->sh, 0, prnk(x)) == a->ia); + assert(shProd(PSH(a), 0, prnk(x)) == a->ia); VALIDATE(tag(shObjP(x),OBJ_TAG)); } } diff --git a/src/core/stuff.h b/src/core/stuff.h index d18a2956..2f99b95b 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -24,8 +24,8 @@ typedef struct ShArr { usz a[]; } ShArr; static ShArr* shObjS(usz* x) { return RFLD(x, ShArr, a); } -static ShArr* shObj (B x) { return RFLD(a(x)->sh, ShArr, a); } -static ShArr* shObjP(Value* x) { return RFLD(((Arr*)x)->sh, ShArr, a); } +static ShArr* shObj (B x) { return RFLD(SH(x), ShArr, a); } +static ShArr* shObjP(Value* x) { return RFLD(PSH((Arr*)x), ShArr, a); } static void decShObj(ShArr* x) { tptr_dec(x, mm_free); } static void decSh(Value* x) { if (RARE(prnk(x)>1)) decShObj(shObjP(x)); } @@ -81,7 +81,7 @@ static void arr_shCopy(Arr* n, B o) { // copy shape & rank from o to n n->sh = &n->ia; } else { ptr_inc(shObj(o)); - n->sh = a(o)->sh; + n->sh = SH(o); } } static void shcpy(usz* dst, usz* src, size_t len) { @@ -97,7 +97,7 @@ static usz shProd(usz* sh, usz s, usz e) { static usz arr_csz(B x) { ur xr = rnk(x); if (xr<=1) return 1; - return shProd(a(x)->sh, 1, xr); + return shProd(SH(x), 1, xr); } static bool eqShPart(usz* w, usz* x, usz len) { // return memcmp(w, x, len*sizeof(usz))==0; @@ -105,8 +105,8 @@ static bool eqShPart(usz* w, usz* x, usz len) { return true; } static bool eqShape(B w, B x) { assert(isArr(w)); assert(isArr(x)); - ur wr = rnk(w); usz* wsh = a(w)->sh; - ur xr = rnk(x); usz* xsh = a(x)->sh; + ur wr = rnk(w); usz* wsh = SH(w); + ur xr = rnk(x); usz* xsh = SH(x); if (wr!=xr) return false; if (wsh==xsh) return true; return eqShPart(wsh, xsh, wr); diff --git a/src/ffi.c b/src/ffi.c index 4635af75..1c99c75b 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -68,7 +68,7 @@ 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); - usz* sh = a(b)->sh; + usz* sh = SH(b); for (usz i = 0; i < r; i++) buf[i] = sh[i]; } BQNV bqn_pick(BQNV a, size_t pos) { diff --git a/src/h.h b/src/h.h index 311ba84a..203d1485 100644 --- a/src/h.h +++ b/src/h.h @@ -377,6 +377,9 @@ void freeThrown(void); #define srnk(X,R) sprnk(v(X),R) #define IA(X) (a(X)->ia) #define PIA(X) ((X)->ia) +#define SH(X) (a(X)->sh) +#define PSH(X) ((X)->sh) + #define VTY(X,T) assert(isVal(X) && v(X)->type==(T)) void print_vmStack(void); diff --git a/src/utils/each.c b/src/utils/each.c index ef8336b0..826b73b6 100644 --- a/src/utils/each.c +++ b/src/utils/each.c @@ -17,7 +17,7 @@ B eachd_fn(B fo, B w, B x, BBB2B f) { decG(w); decG(x); return m_unit(r); } - if (rm && !eqShPart(a(w)->sh, a(x)->sh, rm)) thrF("Mapping: Expected equal shape prefix (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); + if (rm && !eqShPart(SH(w), SH(x), rm)) thrF("Mapping: Expected equal shape prefix (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); bool rw = rM==wr && ((v(w)->type==t_harr) & reusable(w)); // v(…) is safe as rank>0 bool rx = rM==xr && ((v(x)->type==t_harr) & reusable(x)); if (rw|rx && (wr==xr | rm==0)) { diff --git a/src/utils/hash.c b/src/utils/hash.c index 47f2bd4d..d736fbd5 100644 --- a/src/utils/hash.c +++ b/src/utils/hash.c @@ -10,7 +10,7 @@ NOINLINE u64 bqn_hashArr(B x, const u64 secret[4]) { // TODO manual separation o u8 xe = TI(x,elType); u64 shHash; if (xr<=1) shHash = wyhash64(xia, xe); - else shHash = wyhash(a(x)->sh, xr*sizeof(usz), xe, secret); + else shHash = wyhash(SH(x), xr*sizeof(usz), xe, secret); bool isTemp = false; void* data; u64 bytes; diff --git a/src/vm.c b/src/vm.c index 50a0f344..c7e1825d 100644 --- a/src/vm.c +++ b/src/vm.c @@ -489,7 +489,7 @@ FORCE_INLINE bool v_merge(Scope* pscs[], B s, B x, bool upd, bool hdr) { B* op = harr_ptr(o); usz oia = IA(o); - if (a(x)->sh[0] != oia) { + if (SH(x)[0] != oia) { if (hdr) return false; else thrF("[…]%U𝕩: Target length & leading axis of 𝕩 didn't match", upd? "↩" : "←"); }