x->ia → IA(x) / PIA(x)

This commit is contained in:
dzaima 2022-08-19 22:46:24 +03:00
parent 558c14cccd
commit e6b4f85662
38 changed files with 267 additions and 265 deletions

View File

@ -181,7 +181,7 @@ c(BMd2,bi_some2mod)->im = some2mod_im; // you get the idea
## Arrays ## 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. 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.

View File

@ -23,7 +23,7 @@
if (isArr(w)|isArr(x)) { B ow=w; B ox=x; \ if (isArr(w)|isArr(x)) { B ow=w; B ox=x; \
if (isArr(w)&isArr(x) && rnk(w)==rnk(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(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 we = TI(w,elType); \
u8 xe = TI(x,elType); \ u8 xe = TI(x,elType); \
if ((we==el_i32|we==el_f64)&(xe==el_i32|xe==el_f64)) { \ 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); \ 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; \ u8 xe = TI(x,elType); f64*rp; \
if (xe==el_i32) { B r=m_f64arrc(&rp, x); i32*xp=i32any_ptr(x); \ 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;} \ 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;} \ for (usz i = 0; i < ia; i++) {B x/*shadow*/;x.f=xp[i];rp[i]=EXPR;} \
decG(x); return num_squeeze(r); \ 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; \ u8 we = TI(w,elType); f64*rp; \
if (we==el_i32) { B r=m_f64arrc(&rp, w); i32*wp=i32any_ptr(w); \ 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;} \ 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 static NOINLINE B bit_sel1Fn(BBB2B f, B w, B x, bool bitX) { // consumes both
B b = bitX? x : w; B b = bitX? x : w;
u64* bp = bitarr_ptr(b); u64* bp = bitarr_ptr(b);
usz ia = a(b)->ia; usz ia = IA(b);
bool b0 = ia? bp[0]&1 : 0; bool b0 = ia? bp[0]&1 : 0;
bool both = false; bool both = false;
@ -160,7 +160,7 @@
if (isArr(w)|isArr(x)) { \ if (isArr(w)|isArr(x)) { \
if (isArr(w)&isArr(x) && rnk(w)==rnk(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(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 we = TI(w,elType); \
u8 xe = TI(x,elType); \ u8 xe = TI(x,elType); \
if ((we==el_bit | xe==el_bit) && (we|xe)<=el_f64) { \ 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_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) } \ 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(w)&isArr(x)) { usz ia=IA(x); 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(x)&isArr(w)) { usz ia=IA(w); u8 we=TI(w,elType); DO_AS(NAME,EXPR) } \
base: P2(NAME) \ base: P2(NAME) \
} \ } \
thrM(SYMB ": Unexpected argument types"); \ 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 (isArr(w)&isC32(x) || isC32(w)&isArr(x)) { if (isArr(w)) { B t=w;w=x;x=t; }
if (TI(x,elType) == el_i32) { if (TI(x,elType) == el_i32) {
u32 wv = o2cu(w); 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); u32* rp; B r = m_c32arrc(&rp, x);
for (usz i = 0; i < xia; i++) { for (usz i = 0; i < xia; i++) {
rp[i] = (u32)(xp[i]+(i32)wv); rp[i] = (u32)(xp[i]+(i32)wv);
@ -286,14 +286,14 @@ GC2i("-", sub, wv-xv, {
if (isArr(w) && TI(w,elType)==el_c32) { if (isArr(w) && TI(w,elType)==el_c32) {
if (isC32(x)) { if (isC32(x)) {
i32 xv = (i32)o2cu(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); i32* rp; B r = m_i32arrc(&rp, w);
for (usz i = 0; i < wia; i++) rp[i] = (i32)wp[i] - xv; for (usz i = 0; i < wia; i++) rp[i] = (i32)wp[i] - xv;
decG(w); decG(w);
return r; return r;
} }
if (isArr(x) && eqShape(w, x)) { 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) { if (TI(x,elType)==el_i32) {
u32* rp; B r = m_c32arrc(&rp, w); u32* rp; B r = m_c32arrc(&rp, w);
i32* xp = i32any_ptr(x); i32* xp = i32any_ptr(x);

View File

@ -14,7 +14,7 @@ static inline B arith_recm(BB2B f, B x) {
B bit_negate(B x) { // consumes B bit_negate(B x) { // consumes
u64* xp = bitarr_ptr(x); u64* xp = bitarr_ptr(x);
u64* rp; B r = m_bitarrc(&rp, 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]; for (usz i = 0; i < ia; i++) rp[i] = ~xp[i];
decG(x); decG(x);
return r; return r;
@ -24,7 +24,7 @@ B bit_negate(B x) { // consumes
if (isF64(x)) { f64 v = x.f; return m_f64(FEXPR); } \ if (isF64(x)) { f64 v = x.f; return m_f64(FEXPR); } \
if (RARE(!isArr(x))) thrM(SYMB ": Expected argument to be a number"); \ if (RARE(!isArr(x))) thrM(SYMB ": Expected argument to be a number"); \
u8 xe = TI(x,elType); \ 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); \ 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; } \ 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; \ decG(x); (void)MIN;(void)MAX; return r; \

View File

@ -9,7 +9,7 @@
#if SINGELI #if SINGELI
#include "../singeli/c/cmp.c" #include "../singeli/c/cmp.c"
#else #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) \ #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 (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); \ if (isC32(w)&isC32(x)) return m_i32(w.u OP x.u); \

View File

@ -43,7 +43,7 @@ B ud_c1(B t, B x) {
return r; return r;
} }
SGetU(x) 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 (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); if (xia>UR_MAX) thrF("↕: Result rank too large (%s≡≠𝕩)", xia);
usz sh[xia]; usz sh[xia];
@ -124,7 +124,7 @@ B fne_c2(B t, B w, B x) {
extern B rt_indexOf; extern B rt_indexOf;
B indexOf_c1(B t, B x) { B indexOf_c1(B t, B x) {
if (isAtm(x)) thrM("⊐: 𝕩 cannot have rank 0"); 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 (xia==0) { decG(x); return emptyIVec(); }
if (rnk(x)==1 && TI(x,elType)==el_i32) { if (rnk(x)==1 && TI(x,elType)==el_i32) {
i32* xp = i32any_ptr(x); 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 (!isArr(w) || rnk(w)==0) thrM("⊐: 𝕨 must have rank at least 1");
if (rnk(w)==1) { if (rnk(w)==1) {
if (!isArr(x) || rnk(x)==0) { if (!isArr(x) || rnk(x)==0) {
usz wia = a(w)->ia; usz wia = IA(w);
B el = isArr(x)? IGetU(x,0) : x; B el = isArr(x)? IGetU(x,0) : x;
i32 res = wia; i32 res = wia;
if (TI(w,elType)==el_i32) { if (TI(w,elType)==el_i32) {
@ -213,8 +213,8 @@ B indexOf_c2(B t, B w, B x) {
rp[0] = res; rp[0] = res;
return taga(r); return taga(r);
} else { } else {
usz wia = a(w)->ia; usz wia = IA(w);
usz xia = a(x)->ia; usz xia = IA(x);
// TODO O(wia×xia) for small wia or xia // TODO O(wia×xia) for small wia or xia
i32* rp; B r = m_i32arrc(&rp, x); i32* rp; B r = m_i32arrc(&rp, x);
H_b2i* map = m_b2i(64); H_b2i* map = m_b2i(64);
@ -238,7 +238,7 @@ extern B rt_memberOf;
B memberOf_c1(B t, B x) { B memberOf_c1(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM("∊: Argument cannot have rank 0"); if (isAtm(x) || rnk(x)==0) thrM("∊: Argument cannot have rank 0");
if (rnk(x)!=1) x = toCells(x); if (rnk(x)!=1) x = toCells(x);
usz xia = a(x)->ia; usz xia = IA(x);
u64* rp; B r = m_bitarrv(&rp, xia); u64* rp; B r = m_bitarrv(&rp, xia);
H_Sb* set = m_Sb(64); H_Sb* set = m_Sb(64);
@ -264,7 +264,7 @@ B memberOf_c2(B t, B w, B x) {
B r; B r;
single: { single: {
usz xia = a(x)->ia; usz xia = IA(x);
SGetU(x) SGetU(x)
for (usz i = 0; i < xia; i++) if (equal(GetU(x, i), w)) { r = inc(enclosed_1); goto dec_wx; } for (usz i = 0; i < xia; i++) if (equal(GetU(x, i), w)) { r = inc(enclosed_1); goto dec_wx; }
r = inc(enclosed_0); r = inc(enclosed_0);
@ -274,8 +274,8 @@ B memberOf_c2(B t, B w, B x) {
many: { many: {
usz xia = a(x)->ia; usz xia = IA(x);
usz wia = a(w)->ia; usz wia = IA(w);
// TODO O(wia×xia) for small wia or xia // TODO O(wia×xia) for small wia or xia
H_Sb* set = m_Sb(64); H_Sb* set = m_Sb(64);
SGetU(x) SGetU(w) SGetU(x) SGetU(w)
@ -295,7 +295,7 @@ B memberOf_c2(B t, B w, B x) {
extern B rt_find; extern B rt_find;
B find_c1(B t, B x) { B find_c1(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM("⍷: Argument cannot have rank 0"); 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); B xf = getFillQ(x);
if (rnk(x)!=1) return c1(rt_find, 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) { B count_c1(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM("⊒: Argument cannot have rank 0"); if (isAtm(x) || rnk(x)==0) thrM("⊒: Argument cannot have rank 0");
if (rnk(x)>1) x = toCells(x); if (rnk(x)>1) x = toCells(x);
usz xia = a(x)->ia; usz xia = IA(x);
i32* rp; B r = m_i32arrv(&rp, xia); i32* rp; B r = m_i32arrv(&rp, xia);
H_b2i* map = m_b2i(64); H_b2i* map = m_b2i(64);
SGetU(x) SGetU(x)
@ -359,10 +359,10 @@ i32 str2gid(B s) {
} }
bool had; bool had;
u64 p = mk_b2i(&globalNames, s, &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; if(had) return globalNames->a[p].val;
i32 r = a(globalNameList)->ia; i32 r = IA(globalNameList);
globalNameList = vec_addN(globalNameList, inc(s)); globalNameList = vec_addN(globalNameList, inc(s));
globalNames->a[p].val = r; globalNames->a[p].val = r;
return r; return r;

View File

@ -13,7 +13,7 @@
B GRADE_CAT(c1)(B t, B x) { B GRADE_CAT(c1)(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM(GRADE_CHR": Argument cannot be a unit"); if (isAtm(x) || rnk(x)==0) thrM(GRADE_CHR": Argument cannot be a unit");
if (rnk(x)>1) x = toCells(x); 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>I32_MAX) thrM(GRADE_CHR": Argument too large");
if (ia==0) { decG(x); return emptyIVec(); } 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; w = toCells(w); xr = 1;
} }
u8 we = TI(w,elType); usz wia = a(w)->ia; u8 we = TI(w,elType); usz wia = IA(w);
u8 xe = TI(x,elType); usz xia = a(x)->ia; u8 xe = TI(x,elType); usz xia = IA(x);
if (wia>I32_MAX-10) thrM(GRADE_CHR": 𝕨 too big"); if (wia>I32_MAX-10) thrM(GRADE_CHR": 𝕨 too big");
i32* rp; B r = m_i32arrc(&rp, x); i32* rp; B r = m_i32arrc(&rp, x);

View File

@ -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(x)) thrM("•internal.ListVariations: 𝕩 must be an array");
if (!isArr(w) || rnk(w)!=1) thrM("•internal.ListVariations: 𝕨 must be a list"); if (!isArr(w) || rnk(w)!=1) thrM("•internal.ListVariations: 𝕨 must be a list");
usz wia = a(w)->ia; usz wia = IA(w);
SGetU(w) SGetU(w)
bool c_incr=false, c_rmFill=false; bool c_incr=false, c_rmFill=false;
for (usz i = 0; i < wia; i++) { 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 ah = c_rmFill || noFill(xf);
bool ai8=false, ai16=false, ai32=false, af64=false, bool ai8=false, ai16=false, ai32=false, af64=false,
ac8=false, ac16=false, ac32=false, abit=false; ac8=false, ac16=false, ac32=false, abit=false;
usz xia = a(x)->ia; usz xia = IA(x);
SGetU(x) SGetU(x)
if (isNum(xf)) { if (isNum(xf)) {
i32 min=I32_MAX, max=I32_MIN; i32 min=I32_MAX, max=I32_MIN;
@ -174,11 +174,11 @@ static void variation_gcRoot() {
B variation_c2(B t, B w, B x) { B variation_c2(B t, B w, B x) {
if (!isArr(w)) thrM("•internal.Variation: Non-array 𝕨"); if (!isArr(w)) thrM("•internal.Variation: Non-array 𝕨");
if (!isArr(x)) 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); C8Arr* wc = toC8Arr(w);
u8* wp = c8arrv_ptr(wc); u8* wp = c8arrv_ptr(wc);
u8* wpE = wp+wc->ia; u8* wpE = wp+PIA(wc);
if (wc->ia==0) thrM("•internal.Variation: Zero-length 𝕨"); if (PIA(wc)==0) thrM("•internal.Variation: Zero-length 𝕨");
B res; B res;
if (*wp == 'A' || *wp == 'S') { if (*wp == 'A' || *wp == 'S') {
bool slice = *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)); } else thrF("•internal.Variation: Bad type \"%R\"", taga(wc));
if (slice) { 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); arr_shCopy(slice, res);
dec(res); dec(res);
res = taga(slice); res = taga(slice);
@ -234,7 +234,7 @@ B variation_c2(B t, B w, B x) {
B clearRefs_c1(B t, B x) { B clearRefs_c1(B t, B x) {
dec(x); dec(x);
if (!isArr(variation_refs)) return m_f64(0); if (!isArr(variation_refs)) return m_f64(0);
usz res = a(variation_refs)->ia; usz res = IA(variation_refs);
dec(variation_refs); dec(variation_refs);
variation_refs = m_f64(0); variation_refs = m_f64(0);
return m_f64(res); return m_f64(res);
@ -242,7 +242,7 @@ B clearRefs_c1(B t, B x) {
static B unshare(B x) { static B unshare(B x) {
if (!isArr(x)) return x; if (!isArr(x)) return x;
usz xia = a(x)->ia; usz xia = IA(x);
switch (v(x)->type) { switch (v(x)->type) {
case t_bitarr: return taga(cpyBitArr(inc(x))); case t_bitarr: return taga(cpyBitArr(inc(x)));
case t_i8arr: return taga(cpyI8Arr (inc(x))); case t_i8arr: return taga(cpyI8Arr (inc(x)));

View File

@ -51,8 +51,8 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
if (EACH_FILLS) xf = getFillQ(x); if (EACH_FILLS) xf = getFillQ(x);
if (isAtm(w)) w = m_atomUnit(w); if (isAtm(w)) w = m_atomUnit(w);
if (isAtm(x)) x = m_atomUnit(x); if (isAtm(x)) x = m_atomUnit(x);
ur wr = rnk(w); usz wia = a(w)->ia; ur wr = rnk(w); usz wia = IA(w);
ur xr = rnk(x); usz xia = a(x)->ia; ur xr = rnk(x); usz xia = IA(x);
ur rr = wr+xr; usz ria = uszMul(wia, xia); ur rr = wr+xr; usz ria = uszMul(wia, xia);
if (rr<xr) thrF("⌜: Result rank too large (%i≡=𝕨, %i≡=𝕩)", wr, xr); if (rr<xr) thrF("⌜: Result rank too large (%i≡=𝕨, %i≡=𝕩)", wr, xr);
@ -150,7 +150,7 @@ static u64 vg_rand(u64 x) { return x; }
B scan_c1(Md1D* d, B x) { B f = d->f; B scan_c1(Md1D* d, B x) { B f = d->f;
if (isAtm(x) || rnk(x)==0) thrM("`: Argument cannot have rank 0"); if (isAtm(x) || rnk(x)==0) thrM("`: Argument cannot have rank 0");
ur xr = rnk(x); ur xr = rnk(x);
usz ia = a(x)->ia; usz ia = IA(x);
if (ia==0) return x; if (ia==0) return x;
B xf = getFillQ(x); B xf = getFillQ(x);
u8 xe = TI(x,elType); 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; B scan_c2(Md1D* d, B w, B x) { B f = d->f;
if (isAtm(x) || rnk(x)==0) thrM("`: 𝕩 cannot have rank 0"); 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); B wf = getFillQ(w);
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (xr==1 && q_i32(w) && xe<el_f64 && isFun(f) && v(f)->flags) { if (xr==1 && q_i32(w) && xe<el_f64 && isFun(f) && v(f)->flags) {
@ -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; 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); 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) { if (ia==0) {
decG(x); decG(x);
if (isFun(f)) { 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; 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); 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); u8 xe = TI(x,elType);
if (q_i32(w) && isFun(f) && v(f)->flags && xe<el_f64) { if (q_i32(w) && isFun(f) && v(f)->flags && xe<el_f64) {
i32 wi = o2iu(w); i32 wi = o2iu(w);
@ -511,7 +511,7 @@ B cell_c1(Md1D* d, B x) { B f = d->f;
return isAtm(r)? m_atomUnit(r) : r; 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]; usz cam = a(x)->sh[0];
if (cam==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; extern B rt_insert;
B insert_c1(Md1D* d, B x) { B f = d->f; B insert_c1(Md1D* d, B x) { B f = d->f;
if (isAtm(x) || rnk(x)==0) thrM("˝: 𝕩 must have rank at least 1"); 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 (xia==0) return m1c1(rt_insert, f, x);
if (rnk(x)==1 && isFun(f) && isPervasiveDy(f)) { if (rnk(x)==1 && isFun(f) && isPervasiveDy(f)) {
return m_atomUnit(fold_c1(d, x)); 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; 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"); 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; B r = w;
if (xia!=0) { if (xia!=0) {
S_SLICES(x) S_SLICES(x)

View File

@ -61,7 +61,7 @@ extern B rt_undo;
void repeat_bounds(i64* bound, B g) { // doesn't consume void repeat_bounds(i64* bound, B g) { // doesn't consume
if (isArr(g)) { if (isArr(g)) {
SGetU(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)); for (usz i = 0; i < ia; i++) repeat_bounds(bound, GetU(g, i));
} else if (isNum(g)) { } else if (isNum(g)) {
i64 i = o2i64(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 B repeat_replace(B g, B* q) { // doesn't consume
if (isArr(g)) { if (isArr(g)) {
SGetU(g) SGetU(g)
usz ia = a(g)->ia; usz ia = IA(g);
M_HARR(r, ia); M_HARR(r, ia);
for (usz i = 0; i < ia; i++) HARR_ADD(r, i, repeat_replace(GetU(g,i), q)); for (usz i = 0; i < ia; i++) HARR_ADD(r, i, repeat_replace(GetU(g,i), q));
return HARR_FC(r, g); 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); B fr = c1iX(f, x);
if (isNum(fr)) { if (isNum(fr)) {
if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1"); 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); return c1(IGetU(g, fri), x);
} else { } else {
B fn = pick_c2(m_f64(0), fr, inc(g)); 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); B fr = c2iWX(d->f, w, x);
if (isNum(fr)) { if (isNum(fr)) {
if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1"); 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); return c2(IGetU(g, fri), w, x);
} else { } else {
B fn = pick_c2(m_f64(0), fr, inc(g)); 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) { static usz check_rank_vec(B g) {
if (!isArr(g)) thrM("⎉: Invalid 𝔾 result"); 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"); if (!(gia>=1 && gia<=3)) thrM("⎉: 𝔾 result must have 1 to 3 elements");
SGetU(g) SGetU(g)
if (TI(g,elType)>=el_f64) for (i32 i = 0; i < gia; i++) req_whole(o2f(GetU(g,i))); 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); i32 xr = rnk(x);
ur cr = cell_rank(xr, kf); ur cr = cell_rank(xr, kf);
i32 k = xr - cr; 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* xsh = a(x)->sh;
usz cam = shProd(xsh, 0, k); usz cam = shProd(xsh, 0, k);

View File

@ -39,7 +39,7 @@ B select_c2(B t, B w, B x) {
} }
B xf = getFillQ(x); B xf = getFillQ(x);
SGet(x) SGet(x)
usz wia = a(w)->ia; usz wia = IA(w);
B r; B r;
if (xr==1) { if (xr==1) {
@ -62,7 +62,7 @@ B select_c2(B t, B w, B x) {
decG(w); decG(w);
return r; return r;
} }
usz xia = a(x)->ia; usz xia = IA(x);
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
u8 we = TI(w,elType); u8 we = TI(w,elType);
#if SINGELI #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) { 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); if (isAtm(x) || rnk(x)!=1 || isAtm(w)) return def_fn_ucw(t, o, w, x);
usz xia = a(x)->ia; usz xia = IA(x);
usz wia = a(w)->ia; usz wia = IA(w);
SGetU(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); if (TI(w,elType)!=el_i32) for (usz i = 0; i < wia; i++) if (!q_i64(GetU(w,i))) return def_fn_ucw(t, o, w, x);
B arg = select_c2(t, inc(w), inc(x)); B arg = select_c2(t, inc(w), inc(x));

View File

@ -5,7 +5,7 @@
#include "../builtins.h" #include "../builtins.h"
static Arr* take_impl(usz ria, B x) { // consumes x; returns v↑⥊𝕩 without set shape; v is non-negative 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) { if (ria>xia) {
B xf = getFillE(x); B xf = getFillE(x);
MAKE_MUT(r, ria); mut_init(r, el_or(TI(x,elType), selfElType(xf))); 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) { B shape_c1(B t, B x) {
if (isAtm(x)) return m_vec1(x); if (isAtm(x)) return m_vec1(x);
if (rnk(x)==1) return x; if (rnk(x)==1) return x;
usz ia = a(x)->ia; usz ia = IA(x);
if (ia==1 && TI(x,elType)<el_B) { if (ia==1 && TI(x,elType)<el_B) {
B n = IGet(x,0); B n = IGet(x,0);
decG(x); decG(x);
@ -105,7 +105,7 @@ static B truncReshape(B x, usz xia, usz nia, ur nr, ShArr* sh) { // consumes all
return r; return r;
} }
B shape_c2(B t, B w, B x) { B shape_c2(B t, B w, B x) {
usz xia = isArr(x)? a(x)->ia : 1; usz xia = isArr(x)? IA(x) : 1;
usz nia = 1; usz nia = 1;
ur nr; ur nr;
ShArr* sh; ShArr* sh;
@ -116,8 +116,8 @@ B shape_c2(B t, B w, B x) {
} else { } else {
if (isAtm(w)) w = m_atomUnit(w); if (isAtm(w)) w = m_atomUnit(w);
if (rnk(w)>1) thrM("⥊: 𝕨 must have rank at most 1"); if (rnk(w)>1) thrM("⥊: 𝕨 must have rank at most 1");
if (a(w)->ia>UR_MAX) thrM("⥊: Result rank too large"); if (IA(w)>UR_MAX) thrM("⥊: Result rank too large");
nr = a(w)->ia; nr = IA(w);
sh = nr<=1? NULL : m_shArr(nr); sh = nr<=1? NULL : m_shArr(nr);
if (TI(w,elType)==el_i32) { if (TI(w,elType)==el_i32) {
i32* wi = i32any_ptr(w); i32* wi = i32any_ptr(w);
@ -243,7 +243,7 @@ B shape_c2(B t, B w, B x) {
extern B rt_pick; extern B rt_pick;
B pick_c1(B t, B x) { B pick_c1(B t, B x) {
if (isAtm(x)) return x; if (isAtm(x)) return x;
if (RARE(a(x)->ia==0)) { if (RARE(IA(x)==0)) {
thrM("⊑: Argument cannot be empty"); thrM("⊑: Argument cannot be empty");
// B r = getFillE(x); // B r = getFillE(x);
// dec(x); // dec(x);
@ -256,12 +256,12 @@ B pick_c1(B t, B x) {
static NOINLINE void checkNumeric(B w) { static NOINLINE void checkNumeric(B w) {
SGetU(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"); 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 static B recPick(B w, B x) { // doesn't consume
assert(isArr(w) && isArr(x)); assert(isArr(w) && isArr(x));
usz ia = a(w)->ia; usz ia = IA(w);
ur xr = rnk(x); ur xr = rnk(x);
usz* xsh = a(x)->sh; usz* xsh = a(x)->sh;
switch(TI(w,elType)) { default: UD; 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) { B pick_c2(B t, B w, B x) {
if (RARE(isAtm(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); dec(w);
return x; return x;
} }
if (isNum(w)) { if (isNum(w)) {
if (rnk(x)!=1) thrF("⊑: 𝕩 must be a list when 𝕨 is a number (%H ≡ ≢𝕩)", x); 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); B r = IGet(x, p);
decG(x); decG(x);
return r; 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); if (RARE(isAtm(x)) || RARE(rnk(x)!=1)) thrF("/: Argument must have rank 1 (%H ≡ ≢𝕩)", x);
u64 s = usum(x); u64 s = usum(x);
if (s>=USZ_MAX) thrOOM(); if (s>=USZ_MAX) thrOOM();
usz xia = a(x)->ia; usz xia = IA(x);
if (RARE(xia>=I32_MAX)) { if (RARE(xia>=I32_MAX)) {
usz xia = a(x)->ia; usz xia = IA(x);
SGetU(x) SGetU(x)
f64* rp; B r = m_f64arrv(&rp, s); usz ri = 0; f64* rp; B r = m_f64arrv(&rp, s); usz ri = 0;
for (usz i = 0; i < xia; i++) { 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) { B slash_c2(B t, B w, B x) {
if (isArr(x) && rnk(x)==1 && isArr(w) && rnk(w)==1 && depth(w)==1) { if (isArr(x) && rnk(x)==1 && isArr(w) && rnk(w)==1 && depth(w)==1) {
usz wia = a(w)->ia; usz wia = IA(w);
usz xia = a(x)->ia; usz xia = IA(x);
if (RARE(wia!=xia)) { if (RARE(wia!=xia)) {
if (wia==0) { decG(w); return x; } if (wia==0) { decG(w); return x; }
thrF("/: Lengths of components of 𝕨 must match 𝕩 (%s ≠ %s)", wia, xia); 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); return withFill(HARR_FV(r), xf);
} }
if (isArr(x) && rnk(x)==1 && q_i32(w)) { if (isArr(x) && rnk(x)==1 && q_i32(w)) {
usz xia = a(x)->ia; usz xia = IA(x);
i32 wv = o2i(w); i32 wv = o2i(w);
if (wv<=0) { if (wv<=0) {
if (wv<0) thrM("/: 𝕨 cannot be negative"); 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) { B slash_im(B t, B x) {
if (!isArr(x) || rnk(x)!=1) thrM("/⁼: Argument must be an array"); if (!isArr(x) || rnk(x)!=1) thrM("/⁼: Argument must be an array");
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
usz xia = a(x)->ia; usz xia = IA(x);
if (xia==0) { decG(x); return emptyIVec(); } if (xia==0) { decG(x); return emptyIVec(); }
switch(xe) { default: UD; switch(xe) { default: UD;
case el_i8: { case el_i8: {
@ -762,7 +762,7 @@ B slash_im(B t, B x) {
} }
static B slicev(B x, usz s, usz ia) { 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))); 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); a = take_impl(t, x);
} else { } else {
t = -t; t = -t;
usz xia = a(x)->ia; usz xia = IA(x);
if (t>xia) { if (t>xia) {
B xf = getFillE(x); B xf = getFillE(x);
MAKE_MUT(r, t); mut_init(r, el_or(TI(x,elType), selfElType(xf))); 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) { B drop_c2(B t, B w, B x) {
if (isNum(w) && isArr(x) && rnk(x)==1) { if (isNum(w) && isArr(x) && rnk(x)==1) {
i64 v = o2i64(w); 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); 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); 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"); if (isAtm(x)) thrM("∾: Argument must be an array");
ur xr = rnk(x); ur xr = rnk(x);
usz xia = a(x)->ia; usz xia = IA(x);
if (xia==0) { if (xia==0) {
B xf = getFillE(x); B xf = getFillE(x);
if (isAtm(xf)) { if (isAtm(xf)) {
@ -930,7 +930,7 @@ B join_c1(B t, B x) {
for (usz i = 0; i < xia; i++) { for (usz i = 0; i < xia; i++) {
B c = GetU(x, i); B c = GetU(x, i);
if (isArr(c)) { if (isArr(c)) {
usz cia = a(c)->ia; usz cia = IA(c);
mut_copy(r, ri, c, 0, cia); mut_copy(r, ri, c, 0, cia);
ri+= cia; ri+= cia;
} else { } else {
@ -955,7 +955,7 @@ B join_c1(B t, B x) {
B rf; if(SFNS_FILLS) rf = getFillQ(x0); B rf; if(SFNS_FILLS) rf = getFillQ(x0);
ur r0 = isAtm(x0) ? 0 : rnk(x0); ur r0 = isAtm(x0) ? 0 : rnk(x0);
usz xia = a(x)->ia; usz xia = IA(x);
usz* xsh = a(x)->sh; usz* xsh = a(x)->sh;
usz tlen = 4*xr+2*r0; for (usz a=0; a<xr; a++) tlen+=xsh[a]; usz tlen = 4*xr+2*r0; for (usz a=0; a<xr; a++) tlen+=xsh[a];
TALLOC(usz, st, tlen); // Temp buffer TALLOC(usz, st, tlen); // Temp buffer
@ -1046,7 +1046,7 @@ B join_c1(B t, B x) {
assert(l==1); assert(l==1);
mut_set(r, ri, inc(e)); mut_set(r, ri, inc(e));
} else { } else {
usz eia = a(e)->ia; usz eia = IA(e);
if (eia) { if (eia) {
usz rj = ri; usz rj = ri;
usz *ii=tsh0; for (usz k=0; k<xr-1; k++) ii[k]=0; usz *ii=tsh0; for (usz k=0; k<xr-1; k++) ii[k]=0;
@ -1114,7 +1114,7 @@ B join_c2(B t, B w, B x) {
usz wia; usz wia;
usz* wsh; usz* wsh;
if (wr==1 && reusedW) { if (wr==1 && reusedW) {
wia = a(w)->ia-a(x)->ia; wia = IA(w)-IA(x);
wsh = &wia; wsh = &wia;
} else { } else {
wsh = a(w)->sh; // when wr>1, shape object won't be disturbed by arr_join_inline 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) { B couple_c1(B t, B x) {
if (isAtm(x)) return m_vec1(x); if (isAtm(x)) return m_vec1(x);
usz rr = rnk(x); usz rr = rnk(x);
usz ia = a(x)->ia; usz ia = IA(x);
Arr* r = TI(x,slice)(incG(x),0, ia); Arr* r = TI(x,slice)(incG(x),0, ia);
usz* sh = arr_shAlloc(r, rr+1); 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, 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(w)) w = m_atomUnit(w);
if (isAtm(x)) x = m_atomUnit(x); if (isAtm(x)) x = m_atomUnit(x);
if (!eqShape(w, x)) thrF("≍: 𝕨 and 𝕩 must have equal shapes (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, 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); ur wr = rnk(w);
MAKE_MUT(r, ia*2); mut_init(r, el_or(TI(w,elType), TI(x,elType))); MAKE_MUT(r, ia*2); mut_init(r, el_or(TI(w,elType), TI(x,elType)));
MUTG_INIT(r); MUTG_INIT(r);
@ -1186,7 +1186,7 @@ static inline void shift_check(B w, B x) {
B shiftb_c1(B t, B x) { B shiftb_c1(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM("»: Argument cannot be a scalar"); 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; if (ia==0) return x;
B xf = getFillE(x); B xf = getFillE(x);
usz csz = arr_csz(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); if (isAtm(w)) w = m_atomUnit(w);
shift_check(w, x); shift_check(w, x);
B f = fill_both(w, x); B f = fill_both(w, x);
usz wia = a(w)->ia; usz wia = IA(w);
usz xia = a(x)->ia; usz xia = IA(x);
MAKE_MUT(r, xia); mut_init(r, el_or(TI(w,elType), TI(x,elType))); MAKE_MUT(r, xia); mut_init(r, el_or(TI(w,elType), TI(x,elType)));
MUTG_INIT(r); MUTG_INIT(r);
int mid = wia<xia? wia : xia; int mid = wia<xia? wia : xia;
@ -1215,7 +1215,7 @@ B shiftb_c2(B t, B w, B x) {
B shifta_c1(B t, B x) { B shifta_c1(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM("«: Argument cannot be a scalar"); 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; if (ia==0) return x;
B xf = getFillE(x); B xf = getFillE(x);
usz csz = arr_csz(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); if (isAtm(w)) w = m_atomUnit(w);
shift_check(w, x); shift_check(w, x);
B f = fill_both(w, x); B f = fill_both(w, x);
usz wia = a(w)->ia; usz wia = IA(w);
usz xia = a(x)->ia; usz xia = IA(x);
MAKE_MUT(r, xia); mut_init(r, el_or(TI(w,elType), TI(x,elType))); MAKE_MUT(r, xia); mut_init(r, el_or(TI(w,elType), TI(x,elType)));
MUTG_INIT(r); MUTG_INIT(r);
if (wia < xia) { if (wia < xia) {
@ -1251,8 +1251,8 @@ B group_c1(B t, B x) {
} }
B group_c2(B t, B w, 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) { if (isArr(w)&isArr(x) && rnk(w)==1 && rnk(x)==1 && depth(w)==1) {
usz wia = a(w)->ia; usz wia = IA(w);
usz xia = a(x)->ia; usz xia = IA(x);
if (wia-xia > 1) thrF("⊔: ≠𝕨 must be either ≠𝕩 or one bigger (%s≡≠𝕨, %s≡≠𝕩)", wia, xia); if (wia-xia > 1) thrF("⊔: ≠𝕨 must be either ≠𝕩 or one bigger (%s≡≠𝕨, %s≡≠𝕩)", wia, xia);
u8 we = TI(w,elType); u8 we = TI(w,elType);
if (we<=el_i32) { if (we<=el_i32) {
@ -1370,7 +1370,7 @@ B group_c2(B t, B w, B x) {
extern B rt_reverse; extern B rt_reverse;
B reverse_c1(B t, B x) { B reverse_c1(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM("⌽: Argument cannot be a unit"); 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; if (xia==0) return x;
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (rnk(x)==1) { if (rnk(x)==1) {
@ -1413,7 +1413,7 @@ B reverse_c1(B t, B x) {
B reverse_c2(B t, B w, B x) { B reverse_c2(B t, B w, B x) {
if (isArr(w)) return c2(rt_reverse, w, 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 𝕨"); 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; if (xia==0) return x;
B xf = getFillQ(x); B xf = getFillQ(x);
usz cam = a(x)->sh[0]; usz cam = a(x)->sh[0];
@ -1435,7 +1435,7 @@ B transp_c1(B t, B x) {
ur xr = rnk(x); ur xr = rnk(x);
if (xr<=1) return x; if (xr<=1) return x;
usz ia = a(x)->ia; usz ia = IA(x);
usz* xsh = a(x)->sh; usz* xsh = a(x)->sh;
usz h = xsh[0]; usz h = xsh[0];
usz w = xsh[1] * shProd(xsh, 2, xr); 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? 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); B xf = getFillQ(x);
usz ia = a(x)->ia; usz ia = IA(x);
B arg = IGet(x, 0); B arg = IGet(x, 0);
B rep = c1(o, arg); B rep = c1(o, arg);
MAKE_MUT(r, ia); mut_init(r, el_or(TI(x,elType), selfElType(rep))); 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) { 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); 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)); usz wi = WRAP(o2i64(w), xia, thrF("𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡%R, %s≡≠𝕩)", w, xia));
B arg = IGet(x, wi); B arg = IGet(x, wi);
B rep = c1(o, arg); 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) { 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); 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 = a(x)->ia; usz ia = IA(x);
SGetU(w) 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); 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)); B arg = slash_c2(t, inc(w), inc(x));
usz argIA = a(arg)->ia; usz argIA = IA(arg);
B rep = c1(o, 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))); MAKE_MUT(r, ia); mut_init(r, el_or(TI(x,elType), TI(rep,elType)));
SGet(x) SGet(x)
SGet(rep) 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) { 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 csz = arr_csz(x);
usz tk = csz*am; // taken element count usz tk = csz*am; // taken element count
usz lv = xia-tk; // elements left alone 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) { 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; return r;
} }
B shape_uc1(B t, B o, B x) { B shape_uc1(B t, B o, B x) {
if (!isArr(x) || rnk(x)==0) { 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)); 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); if (rnk(x)==1) return shape_uc1_t(c1(o, x), xia);
ur xr = rnk(x); ur xr = rnk(x);
ShArr* sh = ptr_inc(shObj(x)); ShArr* sh = ptr_inc(shObj(x));

View File

@ -30,7 +30,7 @@ typedef struct I32I32p { i32 k; i32 v; } I32I32p;
B and_c1(B t, B x) { B and_c1(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM("∧: Argument cannot have rank 0"); if (isAtm(x) || rnk(x)==0) thrM("∧: Argument cannot have rank 0");
if (rnk(x)!=1) return bqn_merge(and_c1(t, toCells(x))); 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); u8 xe = TI(x,elType);
if (xe<=el_i32) { if (xe<=el_i32) {
if (xe!=el_i32) x = taga(cpyI32Arr(x)); 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) { B or_c1(B t, B x) {
if (isAtm(x) || rnk(x)==0) thrM(": Argument cannot have rank 0"); if (isAtm(x) || rnk(x)==0) thrM(": Argument cannot have rank 0");
if (rnk(x)!=1) return bqn_merge(or_c1(t, toCells(x))); 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); u8 xe = TI(x,elType);
if (xe<=el_i32) { if (xe<=el_i32) {
if (xe!=el_i32) x = taga(cpyI32Arr(x)); if (xe!=el_i32) x = taga(cpyI32Arr(x));

View File

@ -33,7 +33,7 @@ NOINLINE B num_squeezeF(B x, usz ia) {
return taga(a); return taga(a);
} }
B num_squeeze(B x) { B num_squeeze(B x) {
usz ia = a(x)->ia; usz ia = IA(x);
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
#if !SINGELI #if !SINGELI
@ -107,7 +107,7 @@ B num_squeeze(B x) {
return rb; return rb;
} }
B chr_squeeze(B x) { B chr_squeeze(B x) {
usz ia = a(x)->ia; usz ia = IA(x);
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
usz i = 0; usz i = 0;
i32 or = 0; i32 or = 0;
@ -168,7 +168,7 @@ B chr_squeeze(B x) {
B any_squeeze(B x) { B any_squeeze(B x) {
assert(isArr(x)); assert(isArr(x));
if (FL_HAS(x,fl_squoze)) return 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); B x0 = IGetU(x, 0);
if (isNum(x0)) return num_squeeze(x); if (isNum(x0)) return num_squeeze(x);
else if (isC32(x0)) return chr_squeeze(x); else if (isC32(x0)) return chr_squeeze(x);
@ -179,7 +179,7 @@ B squeeze_deep(B x) {
if (!isArr(x)) return x; if (!isArr(x)) return x;
x = any_squeeze(x); x = any_squeeze(x);
if (TI(x,elType)!=el_B) return x; if (TI(x,elType)!=el_B) return x;
usz ia = a(x)->ia; usz ia = IA(x);
M_HARR(r, ia) M_HARR(r, ia)
B* xp = arr_bptr(x); B* xp = arr_bptr(x);
B xf = getFillQ(x); B xf = getFillQ(x);

View File

@ -23,7 +23,7 @@ static bool eqStr(B w, u32* x) {
if (!isC32(c) || x[i]!=(u32)c.u) return false; if (!isC32(c) || x[i]!=(u32)c.u) return false;
i++; 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) { B grLen_both(i64 ria, B x) {
usz ia = a(x)->ia; usz ia = IA(x);
SGetU(x) SGetU(x)
for (usz i = 0; i < ia; i++) { for (usz i = 0; i < ia; i++) {
i64 c = o2i64u(GetU(x, 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 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 B grOrd_c2(B t, B w, B x) { // assumes valid arguments
usz wia = a(w)->ia; usz wia = IA(w);
usz xia = a(x)->ia; usz xia = IA(x);
if (wia==0) { decG(w); decG(x); return emptyIVec(); } if (wia==0) { decG(w); decG(x); return emptyIVec(); }
if (xia==0) { decG(w); return x; } if (xia==0) { decG(w); return x; }
SGetU(w) 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; } if (LIKELY(isF64(x) && o2fu(x)==1)) { dec(w); return x; }
unwindCompiler(); unwindCompiler();
dec(x); dec(x);
if (isArr(w) && a(w)->ia==2) { if (isArr(w) && IA(w)==2) {
B w0 = IGetU(w,0); B w0 = IGetU(w,0);
if (isNum(w0)) { if (isNum(w0)) {
B s = IGet(w,1); B s = IGet(w,1);
@ -198,14 +198,14 @@ B casrt_c2(B t, B w, B x) {
dec(w); dec(w);
thr(s); 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"); B s = IGet(w,1); AFMT("\n");
usz pos = o2s(IGetU(w0,0)); usz pos = o2s(IGetU(w0,0));
s = vm_fmtPoint(comp_currSrc, s, comp_currPath, pos, pos+1); s = vm_fmtPoint(comp_currSrc, s, comp_currPath, pos, pos+1);
dec(w); dec(w);
thr(s); 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"); B s = IGet(w,1); AFMT("\n");
SGetU(w0) SGetU(w0)
s = vm_fmtPoint(comp_currSrc, s, comp_currPath, o2s(GetU(w0,0)), o2s(GetU(w0,1))+1); 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) { 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 (isAtm(x) || rnk(x)!=1) thrF("%U: %U must be a character vector", name, arg);
if (!elChr(TI(x,elType))) { if (!elChr(TI(x,elType))) {
usz ia = a(x)->ia; usz ia = IA(x);
SGetU(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); 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; B cdPath;
static B args_path(B* fullpath, B w, char* name) { // consumes w, returns args, writes to fullpath 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); 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 = a(w)->ia; usz ia = IA(w);
SGet(w) SGet(w)
B path = ia>0? vfyStr(Get(w,0),name,"path" ) : inc(cdPath); B path = ia>0? vfyStr(Get(w,0),name,"path" ) : inc(cdPath);
B file = ia>1? vfyStr(Get(w,1),name,"filename") : emptyCVec(); 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 (isArr(w)) {
if (rnk(w) > 1) thrM("(rand).Range: 𝕨 must be a valid shape"); if (rnk(w) > 1) thrM("(rand).Range: 𝕨 must be a valid shape");
SGetU(w); SGetU(w);
usz wia = a(w)->ia; usz wia = IA(w);
for (u64 i = 0; i < wia; i++) mulOn(am, o2s(GetU(w, i))); for (u64 i = 0; i < wia; i++) mulOn(am, o2s(GetU(w, i)));
} else { } else {
am = o2s(w); am = o2s(w);
@ -370,7 +370,7 @@ B rand_range_c2(B t, B w, B x) {
RAND_END; RAND_END;
if (isArr(w)) { if (isArr(w)) {
usz wia = a(w)->ia; usz wia = IA(w);
switch (wia) { switch (wia) {
case 0: { arr_shAlloc(r, 0); break; } case 0: { arr_shAlloc(r, 0); break; }
case 1: { arr_shVec(r); break; } case 1: { arr_shVec(r); break; }
@ -627,7 +627,7 @@ B fchars_c2(B d, B w, B x) {
static NFnDesc* fBytesDesc; static NFnDesc* fBytesDesc;
B fbytes_c1(B d, B x) { B fbytes_c1(B d, B x) {
I8Arr* tf = path_bytes(path_rel(nfn_objU(d), 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); u8* rp; B r = m_c8arrv(&rp, ia);
for (i64 i = 0; i < ia; i++) rp[i] = p[i]; for (i64 i = 0; i < ia; i++) rp[i] = p[i];
ptr_dec(tf); ptr_dec(tf);
@ -647,7 +647,7 @@ B flines_c1(B d, B x) {
B flines_c2(B d, B w, B x) { B flines_c2(B d, B w, B x) {
if (!isArr(x)) thrM("•FLines: Non-array 𝕩"); if (!isArr(x)) thrM("•FLines: Non-array 𝕩");
B nl, s = emptyCVec(); B nl, s = emptyCVec();
usz ia = a(x)->ia; usz ia = IA(x);
SGet(x) SGet(x)
for (u64 i = 0; i < ia; i++) { for (u64 i = 0; i < ia; i++) {
nl = Get(x, i); nl = Get(x, i);
@ -686,7 +686,7 @@ B import_c1(B d, B x) {
i32 prevIdx = getPrevImport(path); i32 prevIdx = getPrevImport(path);
if (prevIdx>=0) { 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); dec(path);
return IGet(importValList, prevIdx); return IGet(importValList, prevIdx);
} }
@ -696,7 +696,7 @@ B import_c1(B d, B x) {
rethrow(); rethrow();
} }
i32 prevLen = a(importValList)->ia; i32 prevLen = IA(importValList);
importKeyList = vec_addN(importKeyList, path); importKeyList = vec_addN(importKeyList, path);
importValList = vec_addN(importValList, bi_N); importValList = vec_addN(importValList, bi_N);
@ -817,7 +817,7 @@ B getLine_c1(B t, B x) {
B fromUtf8_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"); 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); TALLOC(char, chrs, ia);
SGetU(x) SGetU(x)
for (u64 i = 0; i < ia; i++) { for (u64 i = 0; i < ia; i++) {
@ -863,7 +863,7 @@ B sh_c2(B t, B w, B x) {
// allocate args // allocate args
if (isAtm(x) || rnk(x)>1) thrM("•SH: 𝕩 must be a vector of strings"); 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"); if (xia==0) thrM("•SH: 𝕩 must have at least one item");
TALLOC(char*, argv, xia+1); TALLOC(char*, argv, xia+1);
SGetU(x) SGetU(x)
@ -966,8 +966,8 @@ B sh_c2(B t, B w, B x) {
dec(w); dec(x); dec(w); dec(x);
B s_outRaw = toC8Any(s_out); B s_outRaw = toC8Any(s_out);
B s_errRaw = toC8Any(s_err); B s_errRaw = toC8Any(s_err);
B s_outObj = utf8Decode((char*)c8any_ptr(s_outRaw), a(s_outRaw)->ia); dec(s_outRaw); B s_outObj = utf8Decode((char*)c8any_ptr(s_outRaw), IA(s_outRaw)); dec(s_outRaw);
B s_errObj = utf8Decode((char*)c8any_ptr(s_errRaw), a(s_errRaw)->ia); dec(s_errRaw); 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); return m_hVec3(m_i32(WEXITSTATUS(status)), s_outObj, s_errObj);
} }
#else #else
@ -1046,7 +1046,7 @@ static CastType getCastType(B e, B v) {
s = o2s(e); s = o2s(e);
c = q_N(v) ? 0 : isCharType(v(v)->type); c = q_N(v) ? 0 : isCharType(v(v)->type);
} else { } 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) SGetU(e)
s = o2s(GetU(e,0)); s = o2s(GetU(e,0));
u32 t = o2c(GetU(e,1)); u32 t = o2c(GetU(e,1));
@ -1107,7 +1107,7 @@ B bitcast_impl(B el0, B el1, B x) {
r = taga(copy(xt, r)); r = taga(copy(xt, r));
} else if (v(r)->refc!=1) { } else if (v(r)->refc!=1) {
B pr = r; 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 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 // 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; 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) SGetU(f)
return bitcast_impl(GetU(f,0), GetU(f,1), x); return bitcast_impl(GetU(f,0), GetU(f,1), x);
} }
B bitcast_im(Md1D* d, B x) { B f = d->f; 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) SGetU(f)
return bitcast_impl(GetU(f,1), GetU(f,0), x); 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) { B sys_c1(B t, B x) {
assert(isArr(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 fileNS = m_f64(0);
B path = m_f64(0); B path = m_f64(0);
B name = m_f64(0); B name = m_f64(0);
B wdpath = 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_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; }) #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 c = GetU(x,i);
B cr; B cr;
if (eqStr(c, U"out")) cr = incG(bi_out); if (eqStr(c, U"out")) cr = incG(bi_out);

View File

@ -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_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_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_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_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 = 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 = IA(x);)
// width in log2(bytes) // width in log2(bytes)
static void* m_tyarrlp(Arr** rp, usz w, usz ia, u8 type) M_TYARR(1, , , r, ) 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_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) // width in log2(bits)
static void* m_tyarrlbp(Arr** rp, usz w, usz ia, u8 type) M_TYARR(2, , , r, ) 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_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[]; extern u8 elType2type[];
#define el2t(X) elType2type[X] // TODO maybe reorganize array types such that this can just be addition? #define el2t(X) elType2type[X] // TODO maybe reorganize array types such that this can just be addition?

View File

@ -3,7 +3,7 @@
B asFill(B x) { // consumes B asFill(B x) { // consumes
if (isArr(x)) { if (isArr(x)) {
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
usz ia = a(x)->ia; usz ia = IA(x);
if (elNum(xe)) { if (elNum(xe)) {
Arr* r = allZeroes(ia); Arr* r = allZeroes(ia);
arr_shCopy(r, x); arr_shCopy(r, x);
@ -16,7 +16,7 @@ B asFill(B x) { // consumes
decG(x); decG(x);
return r; return r;
} }
M_HARR(r, a(x)->ia) M_HARR(r, IA(x))
SGet(x) SGet(x)
for (usz i = 0; i < ia; i++) { 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; } 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); decSh(x);
B* p = ((FillArr*)x)->a; B* p = ((FillArr*)x)->a;
dec(((FillArr*)x)->fill); dec(((FillArr*)x)->fill);
usz ia = ((Arr*)x)->ia; usz ia = PIA((Arr*)x);
for (usz i = 0; i < ia; i++) dec(p[i]); for (usz i = 0; i < ia; i++) dec(p[i]);
} }
static void fillarr_visit(Value* x) { assert(x->type == t_fillarr); 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); mm_visit(((FillArr*)x)->fill);
for (usz i = 0; i < ia; i++) mm_visit(p[i]); for (usz i = 0; i < ia; i++) mm_visit(p[i]);
} }
@ -82,7 +82,7 @@ void fillarr_init() {
void validateFill(B x) { void validateFill(B x) {
if (isArr(x)) { if (isArr(x)) {
SGetU(x) SGetU(x)
usz ia = a(x)->ia; usz ia = IA(x);
for (usz i = 0; i < ia; i++) validateFill(GetU(x,i)); for (usz i = 0; i < ia; i++) validateFill(GetU(x,i));
} else if (isF64(x)) { } else if (isF64(x)) {
assert(x.f==0); 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 NOINLINE bool fillEqualF(B w, B x) { // doesn't consume; both args must be arrays
if (!eqShape(w, x)) return false; if (!eqShape(w, x)) return false;
usz ia = a(w)->ia; usz ia = IA(w);
if (ia==0) return true; if (ia==0) return true;
u8 we = TI(w,elType); u8 we = TI(w,elType);
@ -129,7 +129,7 @@ B withFill(B x, B fill) { // consumes both
} }
break; break;
} }
usz ia = a(x)->ia; usz ia = IA(x);
if (!FL_HAS(x,fl_squoze)) { if (!FL_HAS(x,fl_squoze)) {
if (isNum(fill)) { if (isNum(fill)) {
x = num_squeeze(x); x = num_squeeze(x);

View File

@ -90,11 +90,11 @@ static B hslice_getU(Arr* x, usz n) { assert(x->type==t_hslice); return ((HS
DEF_FREE(harr) { DEF_FREE(harr) {
decSh(x); decSh(x);
B* p = ((HArr*)x)->a; // don't use harr_ptr so type isn't checked 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]); for (usz i = 0; i < ia; i++) dec(p[i]);
} }
static void harr_visit(Value* x) { 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]); for (usz i = 0; i < ia; i++) mm_visit(p[i]);
} }
static bool harr_canStore(B x) { return true; } 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); DEF_FREE(harrP) { assert(x->type==t_harrPartial|x->type==t_freed);
B* p = ((HArr*)x)->a; 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]); for (usz i = 0; i < am; i++) dec(p[i]);
} }
void harr_abandon_impl(HArr* p) { assert(p->type == t_harrPartial); 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); static void harrP_visit(Value* x) { assert(x->type == t_harrPartial);
B* p = ((HArr*)x)->a; 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]); 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 B harrP_get(Arr* x, usz n) { err("getting item from t_harrPartial"); }
static void harrP_print(FILE* f, B x) { static void harrP_print(FILE* f, B x) {
B* p = c(HArr,x)->a; B* p = c(HArr,x)->a;
usz am = *c(HArr,x)->sh; 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); fprintf(f, "(partial HArr "N64d"/"N64d": ⟨", (u64)am, (u64)ia);
for (usz i = 0; i < ia; i++) { for (usz i = 0; i < ia; i++) {
if (i) fprintf(f, ", "); if (i) fprintf(f, ", ");
@ -133,7 +133,7 @@ static void harrP_print(FILE* f, B x) {
#if DEBUG #if DEBUG
static void harr_freeT(Value* x) { static void harr_freeT(Value* x) {
B* p = ((HArr*)x)->a; 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])); for (usz i = 0; i < ia; i++) assert(!isVal(p[i]));
tyarr_freeF(x); tyarr_freeF(x);
} }

View File

@ -73,7 +73,7 @@ void harr_abandon_impl(HArr* p);
// unsafe-ish things - don't allocate/GC anything before having written to all items // 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;i<n_;i++)r_.a[i]=m_f64(0); r_; }) #define m_harr0v(N) ({ usz n_ = (N); HArr_p r_ = m_harrUv(n_); for(usz i=0;i<n_;i++)r_.a[i]=m_f64(0); r_; })
#define m_harr0c(X) ({ B x_ = (X); usz n_ = a(x_)->ia; HArr_p r_ = m_harrUc(x_); for(usz i=0;i<n_;i++)r_.a[i]=m_f64(0); r_; }) #define m_harr0c(X) ({ B x_ = (X); usz n_ = IA(x_); HArr_p r_ = m_harrUc(x_); for(usz i=0;i<n_;i++)r_.a[i]=m_f64(0); r_; })
#define m_harr0p(N) ({ usz n_ = (N); HArr_p r_ = m_harrUp(n_); for(usz i=0;i<n_;i++)r_.a[i]=m_f64(0); r_; }) #define m_harr0p(N) ({ usz n_ = (N); HArr_p r_ = m_harrUp(n_); for(usz i=0;i<n_;i++)r_.a[i]=m_f64(0); r_; })
static HArr_p m_harrUv(usz ia) { static HArr_p m_harrUv(usz ia) {
CHECK_IA(ia, sizeof(B)); CHECK_IA(ia, sizeof(B));
@ -82,7 +82,7 @@ static HArr_p m_harrUv(usz ia) {
return harrP_parts(r); return harrP_parts(r);
} }
static HArr_p m_harrUc(B x) { assert(isArr(x)); static HArr_p m_harrUc(B x) { assert(isArr(x));
usz ia = a(x)->ia; usz ia = IA(x);
CHECK_IA(ia, sizeof(B)); CHECK_IA(ia, sizeof(B));
HArr* r = m_arr(fsizeof(HArr,a,B,ia), t_harr, ia); HArr* r = m_arr(fsizeof(HArr,a,B,ia), t_harr, ia);
arr_shCopy((Arr*)r, x); arr_shCopy((Arr*)r, x);

View File

@ -52,7 +52,7 @@ static B m_bitarrv(u64** p, usz ia) {
return taga(r); return taga(r);
} }
static B m_bitarrc(u64** p, B x) { assert(isArr(x)); 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; *p = (u64*)r->a;
arr_shCopy((Arr*)r, x); arr_shCopy((Arr*)r, x);
return taga(r); 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 static u64 usum(B x) { // doesn't consume; may error
assert(isArr(x)); assert(isArr(x));
u64 r = 0; u64 r = 0;
usz xia = a(x)->ia; usz xia = IA(x);
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (xe==el_bit) return bit_sum(bitarr_ptr(x), xia); 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]; } } 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]; } }

View File

@ -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 void farr_print(FILE* f, B x) { // should accept refc=0 arguments for debugging purposes
ur r = rnk(x); ur r = rnk(x);
SGetU(x) SGetU(x)
usz ia = a(x)->ia; usz ia = IA(x);
if (r!=1) { if (r!=1) {
if (r==0) { if (r==0) {
fprintf(f, "<"); fprintf(f, "<");
@ -164,7 +164,7 @@ NOINLINE void fprintRaw(FILE* f, B x) {
else if (isC32(x)) fprintUTF8(f, (u32)x.u); else if (isC32(x)) fprintUTF8(f, (u32)x.u);
else thrM("•Out: Unexpected argument type"); else thrM("•Out: Unexpected argument type");
} else { } else {
usz ia = a(x)->ia; usz ia = IA(x);
SGetU(x) SGetU(x)
for (usz i = 0; i < ia; i++) { for (usz i = 0; i < ia; i++) {
B c = GetU(x,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"); if (isAtm(w) & isAtm(x)) thrM("Invalid comparison");
bool wa=isAtm(w); usz wia; ur wr; usz* wsh; AS2B wgetU; Arr* wArr; 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; 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(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=a(x)->ia; xr=rnk(x); xsh=a(x)->sh; xgetU=TI(x,getU); xArr = a(x); } 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); if (wia==0 || xia==0) return CMP(wia, xia);
i32 rc = CMP(wr+(wa?0:1), xr+(xa?0:1)); 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 wd=dcf(inc(w)); B* wdp = harr_ptr(wd);
B xd=dcf(inc(x)); B* xdp = harr_ptr(xd); B xd=dcf(inc(x)); B* xdp = harr_ptr(xd);
if (o2i(wdp[0])<=1) { decG(wd);decG(xd); return false; } if (o2i(wdp[0])<=1) { decG(wd);decG(xd); return false; }
usz wia = a(wd)->ia; usz wia = IA(wd);
if (wia!=a(xd)->ia) { decG(wd);decG(xd); return false; } if (wia!=IA(xd)) { decG(wd);decG(xd); return false; }
for (u64 i = 0; i<wia; i++) if(!equal(wdp[i], xdp[i])) for (u64 i = 0; i<wia; i++) if(!equal(wdp[i], xdp[i]))
{ decG(wd);decG(xd); return false; } { decG(wd);decG(xd); return false; }
decG(wd);decG(xd); return true; decG(wd);decG(xd); return true;
@ -455,9 +455,9 @@ NOINLINE bool equal(B w, B x) { // doesn't consume
ur wr = rnk(w); ur wr = rnk(w);
ur xr = rnk(x); ur xr = rnk(x);
if (wr!=xr) return false; if (wr!=xr) return false;
usz ia = a(x)->ia; usz ia = IA(x);
if (LIKELY(wr==1)) { if (LIKELY(wr==1)) {
if (ia != a(w)->ia) return false; if (ia != IA(w)) return false;
} else { } else {
usz* wsh = a(w)->sh; usz* wsh = a(w)->sh;
usz* xsh = a(x)->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 wd=dcf(inc(w)); B* wdp = harr_ptr(wd);
B xd=dcf(inc(x)); B* xdp = harr_ptr(xd); B xd=dcf(inc(x)); B* xdp = harr_ptr(xd);
if (o2i(wdp[0])<=1) { decG(wd);decG(xd); return false; } if (o2i(wdp[0])<=1) { decG(wd);decG(xd); return false; }
usz wia = a(wd)->ia; usz wia = IA(wd);
if (wia!=a(xd)->ia) { decG(wd);decG(xd); return false; } if (wia!=IA(xd)) { decG(wd);decG(xd); return false; }
for (u64 i = 0; i<wia; i++) if(!eequal(wdp[i], xdp[i])) for (u64 i = 0; i<wia; i++) if(!eequal(wdp[i], xdp[i]))
{ decG(wd);decG(xd); return false; } { decG(wd);decG(xd); return false; }
decG(wd);dec(xd); return true; decG(wd);dec(xd); return true;
@ -536,7 +536,7 @@ bool eequal(B w, B x) { // doesn't consume
u8 we = TI(w,elType); u8 we = TI(w,elType);
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (we==el_f64 && xe==el_f64) { if (we==el_f64 && xe==el_f64) {
usz ia = a(x)->ia; usz ia = IA(x);
f64* wp = f64any_ptr(w); f64* wp = f64any_ptr(w);
f64* xp = f64any_ptr(x); f64* xp = f64any_ptr(x);
u64 r = 1; u64 r = 1;
@ -550,7 +550,7 @@ bool eequal(B w, B x) { // doesn't consume
return r; return r;
} }
if (we!=el_B && xe!=el_B) return equal(w, x); if (we!=el_B && xe!=el_B) return equal(w, x);
usz ia = a(x)->ia; usz ia = IA(x);
SGetU(x) SGetU(x)
SGetU(w) SGetU(w)
for (usz i = 0; i < ia; i++) if(!eequal(GetU(w,i),GetU(x,i))) return false; 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 (isAtm(x)) return 0;
if (TI(x,arrD1)) return 1; if (TI(x,arrD1)) return 1;
u64 r = 0; u64 r = 0;
usz ia = a(x)->ia; usz ia = IA(x);
SGetU(x) SGetU(x)
for (usz i = 0; i < ia; i++) { for (usz i = 0; i < ia; i++) {
u64 n = depth(GetU(x,i)); u64 n = depth(GetU(x,i));
@ -599,11 +599,11 @@ bool isPureFn(B x) { // doesn't consume
B* xdp = harr_ptr(xd); B* xdp = harr_ptr(xd);
i32 t = o2iu(xdp[0]); i32 t = o2iu(xdp[0]);
if (t<2) { decG(xd); return t==0; } if (t<2) { decG(xd); return t==0; }
usz xdia = a(xd)->ia; usz xdia = IA(xd);
for (u64 i = 1; i<xdia; i++) if(!isPureFn(xdp[i])) { decG(xd); return false; } for (u64 i = 1; i<xdia; i++) if(!isPureFn(xdp[i])) { decG(xd); return false; }
decG(xd); return true; decG(xd); return true;
} else if (isArr(x)) { } else if (isArr(x)) {
usz ia = a(x)->ia; usz ia = IA(x);
SGetU(x) SGetU(x)
for (usz i = 0; i < ia; i++) if (!isPureFn(GetU(x,i))) return false; for (usz i = 0; i < ia; i++) if (!isPureFn(GetU(x,i))) return false;
return true; return true;
@ -612,7 +612,7 @@ bool isPureFn(B x) { // doesn't consume
B bqn_merge(B x) { B bqn_merge(B x) {
assert(isArr(x)); assert(isArr(x));
usz xia = a(x)->ia; usz xia = IA(x);
ur xr = rnk(x); ur xr = rnk(x);
if (xia==0) { if (xia==0) {
B xf = getFillE(x); B xf = getFillE(x);
@ -635,7 +635,7 @@ B bqn_merge(B x) {
B x0 = GetU(x, 0); B x0 = GetU(x, 0);
usz* elSh = isArr(x0)? a(x0)->sh : NULL; usz* elSh = isArr(x0)? a(x0)->sh : NULL;
ur elR = isArr(x0)? rnk(x0) : 0; 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); B fill = getFillQ(x0);
if (xr+elR > UR_MAX) thrM(">: Result rank too large"); if (xr+elR > UR_MAX) thrM(">: Result rank too large");
@ -739,7 +739,7 @@ NOINLINE void print_allocStats() {
void* data; void* data;
u64 len; u64 len;
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
u64 ia = a(x)->ia; u64 ia = IA(x);
if (xe!=el_B) { if (xe!=el_B) {
data = tyany_ptr(x); data = tyany_ptr(x);
if (xe==el_bit) { if (xe==el_bit) {
@ -831,7 +831,7 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); }
#endif #endif
#if WARN_SLOW==1 #if WARN_SLOW==1
static void warn_ln(B x) { 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 { else {
fprintf(stderr, "atom: "); fprintf(stderr, "atom: ");
fprintRaw(stderr, x = bqn_fmt(inc(x))); dec(x); 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) { 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); fprintf(stderr, "slow %s: ", s); warn_ln(x);
fflush(stderr); fflush(stderr);
} }
void warn_slow2(char* s, B w, B x) { 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, "slow %s:\n 𝕨: ", s); warn_ln(w);
fprintf(stderr, " 𝕩: "); warn_ln(x); fprintf(stderr, " 𝕩: "); warn_ln(x);
fflush(stderr); fflush(stderr);
} }
void warn_slow3(char* s, B w, B x, B y) { 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, "slow %s:\n 𝕨: ", s); warn_ln(w);
fprintf(stderr, " 𝕩: "); warn_ln(x); fprintf(stderr, " 𝕩: "); warn_ln(x);
fprintf(stderr, " f: "); warn_ln(y); fprintf(stderr, " f: "); warn_ln(y);

View File

@ -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 static void arr_shCopy(Arr* n, B o) { // copy shape & rank from o to n
assert(isArr(o)); assert(isArr(o));
assert(a(o)->ia==n->ia); assert(IA(o)==n->ia);
ur r = sprnk(n,rnk(o)); ur r = sprnk(n,rnk(o));
if (r<=1) { if (r<=1) {
n->sh = &n->ia; n->sh = &n->ia;

View File

@ -12,9 +12,9 @@ static B TP(m_,arrv) (TEl** p, usz ia) {
return taga(r); return taga(r);
} }
static B TP(m_,arrc) (TEl** p, B x) { assert(isArr(x)); 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)); 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; *p = (TEl*)r->a;
arr_shCopy((Arr*)r, x); arr_shCopy((Arr*)r, x);
return taga(r); return taga(r);

View File

@ -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)); } size_t bqn_rank(BQNV a) { return rnk(getB(a)); }
void bqn_shape(BQNV a, size_t* buf) { B b = getB(a); void bqn_shape(BQNV a, size_t* buf) { B b = getB(a);
ur r = rnk(b); ur r = rnk(b);
@ -76,15 +76,15 @@ BQNV bqn_pick(BQNV a, size_t pos) {
} }
// TODO copy directly with some mut.h thing // 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_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), a(c)->ia * 2); 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), a(c)->ia * 4); 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), a(c)->ia * 8); 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), a(c)->ia * 1); 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), a(c)->ia * 2); 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), a(c)->ia * 4); 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); 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); B* p = arr_bptr(b);
if (p!=NULL) { if (p!=NULL) {
for (usz i = 0; i < ia; i++) buf[i] = makeX(inc(p[i])); 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 BQNFFIEnt ffi_parseType(B arg, bool forRes) { // doesn't consume; parse argument side & other global decorators
vfyStr(arg, "FFI", "type"); vfyStr(arg, "FFI", "type");
usz ia = a(arg)->ia; usz ia = IA(arg);
if (ia==0) { if (ia==0) {
if (!forRes) thrM("FFI: Argument type empty"); if (!forRes) thrM("FFI: Argument type empty");
return (BQNFFIEnt){.t = ffi_type_void, .o=m_c32(sty_void), .resSingle=false}; 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); inc(c);
B cG; B cG;
if (!isArr(c)) thrF("FFI: Expected array corresponding to \"*%S\"", sty_names[o2cu(e)]); 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; bool mut = t->a[0].mutPtr;
switch(o2cu(e)) { default: thrF("FFI: \"*%S\" argument type NYI", sty_names[o2cu(e)]); 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; 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 et = o2cu(o2);
u8 etw = sty_w[et]*8; u8 etw = sty_w[et]*8;
if (!isArr(c)) thrF("FFI: Expected array corresponding to \"%S:%c%i\"", sty_names[et], reT, 1<<reW); if (!isArr(c)) thrF("FFI: Expected array corresponding to \"%S:%c%i\"", sty_names[et], reT, 1<<reW);
if (a(c)->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)); B cG = toW(reT, reW, inc(c));
memcpy(ffiTmpS+pos, tyany_ptr(cG), 8); // may over-read, ¯\_(ツ)_/¯ memcpy(ffiTmpS+pos, tyany_ptr(cG), 8); // may over-read, ¯\_(ツ)_/¯
dec(cG); dec(cG);
@ -531,7 +531,7 @@ B buildObj(BQNFFIEnt ent, bool anyMut, B* objs, usz* objPos) {
B f = objs[(*objPos)++]; B f = objs[(*objPos)++];
bool mut = t->a[0].mutPtr; bool mut = t->a[0].mutPtr;
if (mut) { if (mut) {
usz ia = a(f)->ia; usz ia = IA(f);
switch(o2cu(e)) { default: UD; switch(o2cu(e)) { default: UD;
case sty_i8: case sty_i16: case sty_i32: case sty_f64: return inc(f); 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; i<ia; i++) rp[i]=tp[i]; return r; } case sty_u8: { u8* tp=tyarr_ptr(f); i16* rp; B r=m_i16arrv(&rp, ia); for (usz i=0; i<ia; i++) rp[i]=tp[i]; return r; }
@ -664,7 +664,7 @@ B libffiFn_c1(B t, B x) { return libffiFn_c2(t, bi_N, x); }
#else #else
BQNFFIEnt ffi_parseType(B arg, bool forRes) { BQNFFIEnt ffi_parseType(B arg, bool forRes) {
if (!isArr(arg) || a(arg)->ia!=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){}; return (BQNFFIEnt){};
} }
#endif #endif
@ -673,7 +673,7 @@ BQNFFIEnt ffi_parseType(B arg, bool forRes) {
B ffiload_c2(B t, B w, B x) { 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"); if (xia<2) thrM("FFI: Function specification must have at least two items");
usz argn = xia-2; usz argn = xia-2;
SGetU(x) SGetU(x)
@ -740,17 +740,17 @@ B ffiload_c2(B t, B w, B x) {
} }
DEF_FREE(ffiType) { 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); for (usz i = 0; i < ia; i++) dec(((BQNFFIType*)x)->a[i].o);
} }
void ffiType_visit(Value* x) { 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); for (usz i = 0; i < ia; i++) mm_visit(((BQNFFIType*)x)->a[i].o);
} }
void ffiType_print(FILE* f, B x) { void ffiType_print(FILE* f, B x) {
BQNFFIType* t = c(BQNFFIType,x); BQNFFIType* t = c(BQNFFIType,x);
fprintf(f, "cty_%d⟨", t->ty); fprintf(f, "cty_%d⟨", t->ty);
for (usz i=0, ia=t->ia; i<ia; i++) { for (usz i=0, ia=PIA(t); i<ia; i++) {
if (i) fprintf(f, ", "); if (i) fprintf(f, ", ");
printFFIType(f, t->a[i].o); printFFIType(f, t->a[i].o);
} }

View File

@ -375,6 +375,8 @@ void freeThrown(void);
#define sprnk(X,R) (X->extra=(R)) #define sprnk(X,R) (X->extra=(R))
#define rnk(X ) prnk(v(X)) #define rnk(X ) prnk(v(X))
#define srnk(X,R) sprnk(v(X),R) #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)) #define VTY(X,T) assert(isVal(X) && v(X)->type==(T))
void print_vmStack(void); void print_vmStack(void);

View File

@ -465,7 +465,7 @@ static OptRes opt(u32* bc0) {
bc = bc0; pos = 0; bc = bc0; pos = 0;
TSFREE(data); TSFREE(data);
TSFREE(actions); 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}; return (OptRes){.bc = rbc, .offset = roff, .refs = refs};
} }
#undef SREF #undef SREF

View File

@ -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; 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 Block* load_compObj(B x, B src, B path, Scope* sc) { // consumes x,src
SGet(x) SGet(x)
usz xia = a(x)->ia; usz xia = IA(x);
if (xia!=6 & xia!=4) thrM("load_compObj: bad item count"); 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) 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); : 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; Scope* csc = sc;
while (csc) { while (csc) {
B vars = listVars(csc); B vars = listVars(csc);
usz am = a(vars)->ia; usz am = IA(vars);
vName = vec_join(vName, vars); vName = vec_join(vName, vars);
for (usz i = 0; i < am; i++) vDepth = vec_addN(vDepth, m_i32(depth)); for (usz i = 0; i < am; i++) vDepth = vec_addN(vDepth, m_i32(depth));
csc = csc->psc; csc = csc->psc;
@ -219,12 +219,12 @@ void init_comp(B* set, B prim) {
set[2] = inc(load_glyphs); set[2] = inc(load_glyphs);
} else { } else {
if (!isArr(prim) || rnk(prim)!=1) thrM("•ReBQN: 𝕩.primitives must be a list"); 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 usz np[3] = {0}; // number of functions, 1-modifiers, and 2-modifiers
SGetU(prim); SGetU(prim);
for (usz i = 0; i < pia; i++) { // check and count for (usz i = 0; i < pia; i++) { // check and count
B p = GetU(prim, i); 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"); if (!isC32(IGet(p, 0))) thrM("•ReBQN 𝕩.primitives: Glyphs must be characters");
B v = IGetU(p, 1); B v = IGetU(p, 1);
i32 t = isFun(v)? 0 : isMd1(v)? 1 : isMd2(v)? 2 : 3; i32 t = isFun(v)? 0 : isMd1(v)? 1 : isMd2(v)? 2 : 3;
@ -266,9 +266,9 @@ B getPrimitives() {
} }
B* pr = harr_ptr(r); B* pr = harr_ptr(r);
B* gg = harr_ptr(g); B* gg = harr_ptr(g);
M_HARR(ph, a(r)->ia); M_HARR(ph, IA(r));
for (usz gi = 0; gi < 3; gi++) { for (usz gi = 0; gi < 3; gi++) {
usz l = a(gg[gi])->ia; usz l = IA(gg[gi]);
u32* gp = c32arr_ptr(gg[gi]); u32* gp = c32arr_ptr(gg[gi]);
for (usz i = 0; i < l; i++) { for (usz i = 0; i < l; i++) {
HARR_ADDA(ph, m_hVec2(m_c32(gp[i]), inc(pr[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); HArr_p runtimeH = m_harrUc(rtObjRaw);
SGet(rtObjRaw) SGet(rtObjRaw)

View File

@ -132,7 +132,7 @@ void cbqn_runLine0(char* ln, i64 read) {
i32 am = e->varAm; i32 am = e->varAm;
for (i32 i = 0; i < am; i++) { for (i32 i = 0; i < am; i++) {
B c = e->vars[i+am]; B c = e->vars[i+am];
if (a(c)->ia != len) continue; if (IA(c) != len) continue;
SGetU(c) SGetU(c)
bool ok = true; bool ok = true;
for (i32 j = 0; j < len; j++) ok&= o2cu(GetU(c, j))==name[j]; 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)) { if (q_N(r)) {
printf("Couldn't list variables\n"); printf("Couldn't list variables\n");
} else { } else {
usz ia = a(r)->ia; usz ia = IA(r);
B* rp = harr_ptr(r); B* rp = harr_ptr(r);
for (usz i = 0; i < ia; i++) { for (usz i = 0; i < ia; i++) {
if (i!=0) printf(", "); 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 ")) { } else if (isCmd(cmdS, &cmdE, "e ") || isCmd(cmdS, &cmdE, "explain ")) {
B expl = bqn_explain(utf8Decode0(cmdE), replPath); B expl = bqn_explain(utf8Decode0(cmdE), replPath);
HArr* expla = toHArr(expl); HArr* expla = toHArr(expl);
usz ia=expla->ia; usz ia=PIA(expla);
for(usz i=0; i<ia; i++) { for(usz i=0; i<ia; i++) {
printRaw(expla->a[i]); printRaw(expla->a[i]);
putchar('\n'); putchar('\n');
@ -373,7 +373,7 @@ int main(int argc, char* argv[]) {
case 'R': { repl_init(); REQARG(R); case 'R': { repl_init(); REQARG(R);
B path = utf8Decode0(argv[i++]); B path = utf8Decode0(argv[i++]);
B lines = path_lines(path); B lines = path_lines(path);
usz ia = a(lines)->ia; usz ia = IA(lines);
SGet(lines) SGet(lines)
for (u64 i = 0; i < ia; i++) { for (u64 i = 0; i < ia; i++) {
dec(gsc_exec_inline(Get(lines, i), incG(replPath), emptySVec())); dec(gsc_exec_inline(Get(lines, i), incG(replPath), emptySVec()));

View File

@ -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 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"); if (!isArr(varIDs) || !isArr(exported)) thrM("Bad namespace description information");
usz ia = a(varIDs)->ia; usz ia = IA(varIDs);
if (ia!=a(exported)->ia) thrM("Bad namespace description information"); if (ia!=IA(exported)) thrM("Bad namespace description information");
i32 off = (ty==0?0:ty==1?2:3) + (imm?0:3); i32 off = (ty==0?0:ty==1?2:3) + (imm?0:3);
i32 vam = ia+off; i32 vam = ia+off;

View File

@ -36,7 +36,7 @@ FN_LUT(avx2, ge, AS); FN_LUT(avx2, ge, AA);
FN_LUT(avx2, lt, AS); FN_LUT(avx2, lt, AS);
FN_LUT(avx2, le, 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) \ #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 (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); \ if (isC32(w)&isC32(x)) return m_i32(w.u OP x.u); \

View File

@ -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 (!h0) t0=t1; // TODO just do separate impls for !h0 and !h1
if (!h1) t1=t0; if (!h1) t1=t0;
u64* bp = bitarr_ptr(b); u64* bp = bitarr_ptr(b);
usz ia = a(b)->ia; usz ia = IA(b);
if (elNum(t0) && elNum(t1)) { B r; if (elNum(t0) && elNum(t1)) { B r;
f64 f0 = o2fu(e0); i32 i0 = f0; f64 f0 = o2fu(e0); i32 i0 = f0;
f64 f1 = o2fu(e1); i32 i1 = f1; f64 f1 = o2fu(e1); i32 i1 = f1;

View File

@ -35,13 +35,13 @@ B eachd_fn(B fo, B w, B x, BBB2B f) {
} }
B bo = wg? w : x; B bo = wg? w : x;
usz ria = a(bo)->ia; usz ria = IA(bo);
M_HARR(r, ria) M_HARR(r, ria)
if (wr==xr) for(usz ri=0; ri<ria; ri++) HARR_ADD(r, ri, f(fo, Get(w,ri), Get(x,ri))); if (wr==xr) for(usz ri=0; ri<ria; ri++) HARR_ADD(r, ri, f(fo, Get(w,ri), Get(x,ri)));
else if (wr==0) { B c=Get(w, 0); for(usz ri=0; ri<ria; ri++) HARR_ADD(r, ri, f(fo, inc(c) , Get(x,ri))); dec(c); } else if (wr==0) { B c=Get(w, 0); for(usz ri=0; ri<ria; ri++) HARR_ADD(r, ri, f(fo, inc(c) , Get(x,ri))); dec(c); }
else if (xr==0) { B c=Get(x, 0); for(usz ri=0; ri<ria; ri++) HARR_ADD(r, ri, f(fo, Get(w,ri), inc(c) )); dec(c); } else if (xr==0) { B c=Get(x, 0); for(usz ri=0; ri<ria; ri++) HARR_ADD(r, ri, f(fo, Get(w,ri), inc(c) )); dec(c); }
else if (ria>0) { else if (ria>0) {
usz min = wg? a(x)->ia : a(w)->ia; usz min = wg? IA(x) : IA(w);
usz ext = ria / min; 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))); } 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)))); } 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 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; if (ia==0) return x;
SGet(x); SGet(x);
usz i = 0; usz i = 0;

View File

@ -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 static B eachm(B f, B x) { // complete F¨ x without fills; consumes x
if (isAtm(x)) return m_hunit(c1(f, x)); if (isAtm(x)) return m_hunit(c1(f, x));
if (isFun(f)) return eachm_fn(f, x, c(Fun,f)->c1); 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); MAKE_MUT(r, ia);
mut_fill(r, 0, f, ia); mut_fill(r, 0, f, ia);
return mut_fcd(r, x); return mut_fcd(r, x);

View File

@ -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 static NOINLINE void guaranteeStr(B x) { // assumes x is an array
if (elChr(TI(x,elType))) return; if (elChr(TI(x,elType))) return;
usz xia = a(x)->ia; usz xia = IA(x);
SGetU(x) SGetU(x)
for (usz i = 0; i < xia; i++) if (!isC32(GetU(x, i))) thrM("Paths must be character vectors"); 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)); assert(isArr(base) || q_N(base));
if (!isArr(rel) || rnk(rel)!=1) thrM("Paths must be character vectors"); if (!isArr(rel) || rnk(rel)!=1) thrM("Paths must be character vectors");
SGetU(rel) SGetU(rel)
usz ria = a(rel)->ia; usz ria = IA(rel);
if (rnk(rel)!=1) thrM("Paths must be character vectors"); if (rnk(rel)!=1) thrM("Paths must be character vectors");
guaranteeStr(rel); guaranteeStr(rel);
if (ria>0 && o2cu(GetU(rel, 0))=='/') return 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 (q_N(base)) thrM("Using relative path with no absolute base path known");
if (ria==0) { dec(rel); return incG(base); } if (ria==0) { dec(rel); return incG(base); }
usz bia = a(base)->ia; usz bia = IA(base);
if (bia==0) return rel; if (bia==0) return rel;
SGetU(base) SGetU(base)
bool has = o2cu(GetU(base, bia-1))=='/'; 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) { B path_dir(B path) {
assert(isArr(path)); assert(isArr(path));
SGetU(path) SGetU(path)
usz pia = a(path)->ia; usz pia = IA(path);
if (pia==0) thrM("Empty file path"); if (pia==0) thrM("Empty file path");
guaranteeStr(path); guaranteeStr(path);
for (i64 i = (i64)pia-1; i >= 0; i--) { for (i64 i = (i64)pia-1; i >= 0; i--) {
@ -133,7 +133,7 @@ B path_dir(B path) {
B path_name(B path) { B path_name(B path) {
assert(isArr(path)); assert(isArr(path));
SGetU(path) SGetU(path)
usz pia = a(path)->ia; usz pia = IA(path);
if (pia==0) thrM("Empty file path"); if (pia==0) thrM("Empty file path");
guaranteeStr(path); guaranteeStr(path);
for (i64 i = (i64)pia-1; i >= 0; i--) { for (i64 i = (i64)pia-1; i >= 0; i--) {
@ -178,7 +178,7 @@ void path_wChars(B path, B x) { // consumes path
fclose(f); fclose(f);
} }
void file_wBytes(FILE* f, B name, B x) { void file_wBytes(FILE* f, B name, B x) {
u64 len = a(x)->ia; u64 len = IA(x);
bool newBuf = false; bool newBuf = false;
char* buf; char* buf;

View File

@ -3,7 +3,7 @@
#include "time.h" #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 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 if (xia==0) return ~secret[3]; // otherwise squeeze will care about fills
x = any_squeeze(incG(x)); x = any_squeeze(incG(x));
u8 xr = rnk(x); u8 xr = rnk(x);

View File

@ -35,7 +35,7 @@ NOINLINE void mut_to(Mut* m, u8 n) {
} }
NOINLINE B vec_addF(B w, B x) { 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))); MAKE_MUT(r, wia+1); mut_init(r, el_or(TI(w,elType), selfElType(x)));
MUTG_INIT(r); MUTG_INIT(r);
mut_copyG(r, 0, w, 0, wia); 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__; \ static copy_fn copy##T##Fns[] = __VA_ARGS__; \
T##Arr* cpy##T##Arr(B x) { \ T##Arr* cpy##T##Arr(B x) { \
usz ia = a(x)->ia; \ usz ia = IA(x); \
MAKE; arr_shCopy(r, x); \ MAKE; arr_shCopy(r, x); \
if (ia>0) { \ if (ia>0) { \
copy##T##Fns[TI(x,elType)](tyany_ptr(x), (u8*)(XRP), ia, (u8*)a(x)); \ 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 #else
#define MAKE_ICPY(T,E) T##Arr* cpy##T##Arr(B x) { \ #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); \ E* rp; Arr* r = m_##E##arrp(&rp, ia); \
arr_shCopy(r, x); \ arr_shCopy(r, x); \
u8 xe = TI(x,elType); \ 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) \ #define MAKE_CCPY(T,E) \
T##Arr* cpy##T##Arr(B x) { \ 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); \ T##Atom* rp; Arr* r = m_##E##arrp(&rp, ia); \
arr_shCopy(r, x); \ arr_shCopy(r, x); \
u8 xe = TI(x,elType); \ 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) { HArr* cpyHArr(B x) {
usz ia = a(x)->ia; usz ia = IA(x);
HArr_p r = m_harrUc(x); HArr_p r = m_harrUc(x);
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (xe==el_bit) { u64* xp = bitarr_ptr(x); for(usz i=0; i<ia; i++) r.a[i]=m_f64(bitp_get(xp, i)); } if (xe==el_bit) { u64* xp = bitarr_ptr(x); for(usz i=0; i<ia; i++) r.a[i]=m_f64(bitp_get(xp, i)); }
@ -345,7 +345,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x
return r.c; return r.c;
} }
BitArr* cpyBitArr(B x) { BitArr* cpyBitArr(B x) {
usz ia = a(x)->ia; usz ia = IA(x);
u64* rp; Arr* r = m_bitarrp(&rp, ia); u64* rp; Arr* r = m_bitarrp(&rp, ia);
arr_shCopy(r, x); arr_shCopy(r, x);
u8 xe = TI(x,elType); u8 xe = TI(x,elType);

View File

@ -43,7 +43,7 @@ struct Mut {
static void mut_init(Mut* m, u8 n) { static void mut_init(Mut* m, u8 n) {
m->fns = &mutFns[n]; m->fns = &mutFns[n];
usz ia = m->ia; usz ia = PIA(m);
usz sz; usz sz;
// hack around inlining of the allocator too many times // hack around inlining of the allocator too many times
switch(n) { default: UD; 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 // 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) // 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) { FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* reusedW) {
usz wia = a(w)->ia; usz wia = IA(w);
usz xia = a(x)->ia; usz xia = IA(x);
usz ria = wia+xia; usz ria = wia+xia;
if (reusable(w)) { if (reusable(w)) {
u64 wsz = mm_size(v(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 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; usz ria = wia+1;
if (reusable(w)) { if (reusable(w)) {
u64 wsz = mm_size(v(w)); u64 wsz = mm_size(v(w));

View File

@ -50,7 +50,7 @@ B utf8Decode0(const char* s) {
} }
B utf8DecodeA(I8Arr* a) { // consumes a 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); ptr_dec(a);
return r; 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 u64 utf8lenB(B x) { // doesn't consume; may error as it verifies whether is all chars
assert(isArr(x)); assert(isArr(x));
SGetU(x) SGetU(x)
usz ia = a(x)->ia; usz ia = IA(x);
u64 res = 0; u64 res = 0;
for (usz i = 0; i < ia; i++) { for (usz i = 0; i < ia; i++) {
u32 c = o2c(GetU(x,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) { void toUTF8(B x, char* p) {
SGetU(x) SGetU(x)
usz ia = a(x)->ia; usz ia = IA(x);
for (usz i = 0; i < ia; i++) { for (usz i = 0; i < ia; i++) {
u32 c = o2cu(GetU(x,i)); u32 c = o2cu(GetU(x,i));
if (c<128) { *p++ = c; } if (c<128) { *p++ = c; }

View File

@ -135,7 +135,7 @@ typedef struct NextRequest {
static B emptyARMM; 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) { 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"); if (blIA!=3) thrM("VM compiler: Bad block info size");
SGetU(block) SGetU(block)
usz ty = o2s(GetU(block,0)); if (ty>2) thrM("VM compiler: Bad type"); 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}; Body* startBodies[6] = {failBody,failBody,failBody,failBody,failBody,failBody};
bool boArr = isArr(bodyObj); 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 (boCount<1 || boCount>5) thrM("VM compiler: Unexpected body list length");
// if (boArr) { print(bodyObj); putchar('\n'); } // if (boArr) { print(bodyObj); putchar('\n'); }
i32 firstMPos = failBodyI; i32 firstMPos = failBodyI;
@ -180,8 +180,8 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
b2 = i+1<boCount? GetU(bodyObj, i+1) : bi_emptyHVec; b2 = i+1<boCount? GetU(bodyObj, i+1) : bi_emptyHVec;
} }
if (!isArr(b1) || !isArr(b2)) thrM("VM compiler: Body list contained non-arrays"); if (!isArr(b1) || !isArr(b2)) thrM("VM compiler: Body list contained non-arrays");
mCount = a(b1)->ia; SGetU(b1) mCount = IA(b1); SGetU(b1)
dCount = a(b2)->ia; SGetU(b2) dCount = IA(b2); SGetU(b2)
mapLen = mCount+dCount; mapLen = mCount+dCount;
TALLOC(i32, bodyPs_, mapLen+2); bodyPs = bodyPs_; TALLOC(i32, bodyPs_, mapLen+2); bodyPs = bodyPs_;
i32* bodyM = 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"); 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) SGetU(bodyRepr)
usz idx = o2s(GetU(bodyRepr,0)); if (idx>=bcIA) thrM("VM compiler: Bytecode index out of bounds"); 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 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; break;
case DFND: { case DFND: {
u32 id = c[1]; 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"); if (bDone[id]) thrM("VM compiler: DFND of the same block in multiple places");
bDone[id] = true; bDone[id] = true;
Block* bl = compileBlock(IGetU(allBlocks,id), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, depth+1, c-bc); 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) // 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 // 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) { 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); I32Arr* bca = toI32Arr(bcq);
u32* bc = (u32*)bca->a; u32* bc = (u32*)bca->a;
usz bcIA = bca->ia; usz bcIA = PIA(bca);
Comp* comp = mm_alloc(sizeof(Comp), t_comp); Comp* comp = mm_alloc(sizeof(Comp), t_comp);
comp->bc = taga(bca); comp->bc = taga(bca);
comp->indices = indices; 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 // and now finally it's safe to allocate stuff
HArr* objArr = cpyHArr(objs); HArr* objArr = cpyHArr(objs);
comp->objs = objArr; 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]); for (usz i = 0; i < objAm; i++) objArr->a[i] = squeeze_deep(objArr->a[i]);
if (!q_N(src) && !q_N(indices)) { 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++) { for (i32 i = 0; i < 2; i++) {
B ind = IGetU(indices,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) SGetU(ind)
for (usz j = 0; j < bcIA; j++) o2i(GetU(ind,j)); 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? "" : ""); if (!isArr(x) || rnk(x)==0) thrF("[…]%U𝕩: 𝕩 cannot have rank 0", upd? "" : "");
B* op = harr_ptr(o); B* op = harr_ptr(o);
usz oia = a(o)->ia; usz oia = IA(o);
if (a(x)->sh[0] != oia) { if (a(x)->sh[0] != oia) {
if (hdr) return false; 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) { NOINLINE void v_setF(Scope* pscs[], B s, B x, bool upd) {
if (isArr(s)) { VTY(s, t_harr); if (isArr(s)) { VTY(s, t_harr);
B* sp = harr_ptr(s); B* sp = harr_ptr(s);
usz ia = a(s)->ia; usz ia = IA(s);
if (isAtm(x) || !eqShape(s, x)) { if (isAtm(x) || !eqShape(s, x)) {
if (!isNsp(x)) thrM("Assignment: Mismatched shape for spread assignment"); if (!isNsp(x)) thrM("Assignment: Mismatched shape for spread assignment");
for (u64 i = 0; i < ia; i++) { for (u64 i = 0; i < ia; i++) {
@ -558,7 +558,7 @@ NOINLINE bool v_sethF(Scope* pscs[], B s, B x) {
if (isArr(s)) { if (isArr(s)) {
VTY(s, t_harr); VTY(s, t_harr);
B* sp = harr_ptr(s); B* sp = harr_ptr(s);
usz ia = a(s)->ia; usz ia = IA(s);
if (isAtm(x) || !eqShape(s, x)) { if (isAtm(x) || !eqShape(s, x)) {
if (!isNsp(x)) return false; if (!isNsp(x)) return false;
for (u64 i = 0; i < ia; i++) { 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) { NOINLINE B v_getF(Scope* pscs[], B s) {
if (isArr(s)) { if (isArr(s)) {
VTY(s, t_harr); VTY(s, t_harr);
usz ia = a(s)->ia; usz ia = IA(s);
B* sp = harr_ptr(s); B* sp = harr_ptr(s);
HArr_p r = m_harrUv(ia); HArr_p r = m_harrUv(ia);
for (u64 i = 0; i < ia; i++) r.a[i] = v_get(pscs, sp[i], true); 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 NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes prepend
SGetU(src) SGetU(src)
usz srcL = a(src)->ia; usz srcL = IA(src);
usz srcS = cs; usz srcS = cs;
while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--; while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--;
usz srcE = 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; i64 ln = 1;
for (usz i = 0; i < srcS; i++) if(o2cu(GetU(src, i))=='\n') ln++; for (usz i = 0; i < srcS; i++) if(o2cu(GetU(src, i))=='\n') ln++;
B s = prepend; 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 "); else AFMT("at ");
i64 padEnd = (i64)a(s)->ia; i64 padEnd = (i64)IA(s);
i64 padStart = padEnd; i64 padStart = padEnd;
SGetU(s) SGetU(s)
while (padStart>0 && o2cu(GetU(s,padStart-1))!='\n') padStart--; 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: native_print:
freeThrown(); freeThrown();
int start = fprintf(stderr, "at "); int start = fprintf(stderr, "at ");
usz srcL = a(src)->ia; usz srcL = IA(src);
SGetU(src) SGetU(src)
usz srcS = cs; while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--; usz srcS = cs; while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--;
usz srcE = srcS; while (srcE<srcL) { u32 chr = o2cu(GetU(src, srcE)); if(chr=='\n')break; fprintUTF8(stderr, chr); srcE++; } usz srcE = srcS; while (srcE<srcL) { u32 chr = o2cu(GetU(src, srcE)); if(chr=='\n')break; fprintUTF8(stderr, chr); srcE++; }
@ -1482,7 +1482,7 @@ usz profiler_getResults(B* compListRes, B* mapListRes, bool keyPath) {
if (idx == compCount) { if (idx == compCount) {
compList = vec_addN(compList, tag(comp, OBJ_TAG)); compList = vec_addN(compList, tag(comp, OBJ_TAG));
i32* rp; i32* rp;
usz ia = q_N(comp->src)? 1 : a(comp->src)->ia; usz ia = q_N(comp->src)? 1 : IA(comp->src);
mapList = vec_addN(mapList, m_i32arrv(&rp, ia)); mapList = vec_addN(mapList, m_i32arrv(&rp, ia));
for (i32 i = 0; i < ia; i++) rp[i] = 0; for (i32 i = 0; i < ia; i++) rp[i] = 0;
compCount++; compCount++;
@ -1518,7 +1518,7 @@ void profiler_displayResults() {
i32* m = i32arr_ptr(mapObj); i32* m = i32arr_ptr(mapObj);
u64 sum = 0; u64 sum = 0;
usz ia = a(mapObj)->ia; usz ia = IA(mapObj);
for (usz i = 0; i < ia; i++) sum+= m[i]; for (usz i = 0; i < ia; i++) sum+= m[i];
if (q_N(c->src)) { if (q_N(c->src)) {
@ -1531,7 +1531,7 @@ void profiler_displayResults() {
printf(": "N64d" samples:\n", sum); printf(": "N64d" samples:\n", sum);
B src = c->src; B src = c->src;
SGetU(src) SGetU(src)
usz sia = a(src)->ia; usz sia = IA(src);
usz pi = 0; usz pi = 0;
i32 curr = 0; i32 curr = 0;
for (usz i = 0; i < sia; i++) { for (usz i = 0; i < sia; i++) {
@ -1583,7 +1583,7 @@ void unwindCompiler() {
NOINLINE void printErrMsg(B msg) { NOINLINE void printErrMsg(B msg) {
if (isArr(msg)) { if (isArr(msg)) {
SGetU(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; for (usz i = 0; i < msgLen; i++) if (!isC32(GetU(msg,i))) goto base;
fprintRaw(stderr,msg); fprintRaw(stderr,msg);
return; return;