access function/modifier runtime ID through macro
This commit is contained in:
parent
d4b36b3017
commit
3d4a31ae6f
@ -82,15 +82,15 @@ static inline bool isImpureBuiltin(B x) {
|
||||
}
|
||||
|
||||
// these assume x is a function
|
||||
static inline bool isPervasiveDy (B x) { return (u8)(v(x)->flags-1) <= n_ge; }
|
||||
static inline bool isPervasiveMon(B x) { return (u8)(v(x)->flags-1) <= n_stile; }
|
||||
static inline bool isPervasiveDy (B x) { return (u8)RTID(x) <= n_ge; }
|
||||
static inline bool isPervasiveMon(B x) { return (u8)RTID(x) <= n_stile; }
|
||||
|
||||
static bool isPervasiveDyExt(B x) {
|
||||
assert(isFun(x));
|
||||
if (isPervasiveDy(x)) return true;
|
||||
if (TY(x)==t_md1D) {
|
||||
Md1D* d = c(Md1D, x);
|
||||
if (d->m1->flags-1 == n_swap && isFun(d->f)) return isPervasiveDy(d->f);
|
||||
if (PRTID(d->m1) == n_swap && isFun(d->f)) return isPervasiveDy(d->f);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -100,7 +100,7 @@ static bool toConstant(B x, B* out) { // doesn't consume x; if possible, writes
|
||||
if (TY(x) == t_md1D) {
|
||||
Md1D* d = c(Md1D,x);
|
||||
Md1* m1 = d->m1;
|
||||
if (PTY(m1)==t_md1BI && m1->flags-1 == n_const) { *out = inc(d->f); return true; }
|
||||
if (PTY(m1)==t_md1BI && PRTID(m1) == n_const) { *out = inc(d->f); return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -459,7 +459,7 @@ B for_cells_c1(B f, u32 xr, u32 cr, u32 k, B x, u32 chr) { // F⎉cr x; array x,
|
||||
usz* xsh = SH(x);
|
||||
usz cam = shProd(xsh, 0, k); // from k>0 this will always include at least one item of shape; therefore, cam≡0 → IA(x)≡0 and IA(x)≢0 → cam≢0
|
||||
if (isFun(f)) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
u8 rtid = RTID(f);
|
||||
switch(rtid) {
|
||||
case n_ltack: case n_rtack:
|
||||
return x;
|
||||
@ -541,13 +541,13 @@ B for_cells_c1(B f, u32 xr, u32 cr, u32 k, B x, u32 chr) { // F⎉cr x; array x,
|
||||
|
||||
if (TY(f) == t_md1D) {
|
||||
Md1D* fd = c(Md1D,f);
|
||||
u8 rtid = fd->m1->flags-1;
|
||||
u8 rtid = PRTID(fd->m1);
|
||||
switch(rtid) {
|
||||
case n_const: f=fd->f; goto const_f;
|
||||
case n_cell: cr-= cr>0; return for_cells_c1(fd->f, xr, cr, xr-cr, x, U'˘');
|
||||
case n_fold: if (cr != 1) break; // else fall through
|
||||
case n_insert: if (cr>0 && isFun(fd->f)) {
|
||||
u8 frtid = v(fd->f)->flags-1;
|
||||
u8 frtid = RTID(fd->f);
|
||||
if (frtid==n_join && rtid==n_insert) return insert_cells_join(x, xsh, cr, k);
|
||||
usz m = xsh[k];
|
||||
if (m==0) return insert_cells_identity(x, fd->f, xsh, xr, k, rtid);
|
||||
@ -581,7 +581,7 @@ B for_cells_c1(B f, u32 xr, u32 cr, u32 k, B x, u32 chr) { // F⎉cr x; array x,
|
||||
usz m = xsh[k];
|
||||
if (m<=1 || IA(x)==0) return x;
|
||||
if (!isFun(fd->f)) break;
|
||||
u8 frtid = v(fd->f)->flags-1;
|
||||
u8 frtid = RTID(fd->f);
|
||||
if (frtid==n_rtack) return x;
|
||||
if (TI(x,elType)==el_bit && (isPervasiveDyExt(fd->f)||frtid==n_ltack)
|
||||
&& 1==shProd(xsh, k+1, xr)) {
|
||||
@ -590,7 +590,7 @@ B for_cells_c1(B f, u32 xr, u32 cr, u32 k, B x, u32 chr) { // F⎉cr x; array x,
|
||||
break;
|
||||
}
|
||||
case n_undo: if (isFun(fd->f)) {
|
||||
u8 frtid = v(fd->f)->flags-1;
|
||||
u8 frtid = RTID(fd->f);
|
||||
if (frtid==n_couple && cr!=0 && xsh[k]==1) {
|
||||
assert(xr>=2);
|
||||
if (xr==2) return C1(shape, x);
|
||||
@ -604,7 +604,7 @@ B for_cells_c1(B f, u32 xr, u32 cr, u32 k, B x, u32 chr) { // F⎉cr x; array x,
|
||||
}
|
||||
} else if (TY(f) == t_md2D) {
|
||||
Md2D* fd = c(Md2D,f);
|
||||
u8 rtid = fd->m2->flags-1;
|
||||
u8 rtid = PRTID(fd->m2);
|
||||
if (rtid==n_before && !isCallable(fd->f)) return for_cells_SA(fd->g, inc(fd->f), x, cr, xr, chr);
|
||||
if (rtid==n_after && !isCallable(fd->g)) return for_cells_AS(fd->f, x, inc(fd->g), cr, xr, chr);
|
||||
}
|
||||
@ -707,7 +707,7 @@ NOINLINE B for_cells_AS(B f, B w, B x, ur wcr, ur wr, u32 chr) { // F⟜x⎉wcr
|
||||
usz* wsh=SH(w); usz cam=shProd(wsh,0,wk);
|
||||
if (cam==0) return rank2_empty(f, w, wk, x, 0, chr);
|
||||
if (isFun(f)) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
u8 rtid = RTID(f);
|
||||
switch (rtid) {
|
||||
case n_ltack: dec(x); return w;
|
||||
case n_rtack: return const_cells(w, wk, wsh, x, chr);
|
||||
@ -739,7 +739,7 @@ NOINLINE B for_cells_SA(B f, B w, B x, ur xcr, ur xr, u32 chr) { // w⊸F⎉xcr
|
||||
usz* xsh=SH(x); usz cam=shProd(xsh,0,xk);
|
||||
if (cam==0) return rank2_empty(f, w, 0, x, xk, chr);
|
||||
if (isFun(f)) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
u8 rtid = RTID(f);
|
||||
switch(rtid) {
|
||||
case n_rtack: dec(w); return x;
|
||||
case n_ltack: return const_cells(x, xk, xsh, w, chr);
|
||||
@ -859,7 +859,7 @@ NOINLINE B for_cells_AA(B f, B w, B x, ur wcr, ur xcr, u32 chr) { // w F⎉wcr
|
||||
|
||||
if (isFun(f)) {
|
||||
if (wk==xk) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
u8 rtid = RTID(f);
|
||||
if (rtid==n_rtack) { decG(w); return x; }
|
||||
if (rtid==n_ltack) { decG(x); return w; }
|
||||
if (rtid==n_feq || rtid==n_fne) {
|
||||
|
||||
@ -202,8 +202,8 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
|
||||
}
|
||||
if (RARE(!isFun(f))) { decG(x); if (isMd(f)) thrM("Calling a modifier"); return inc(f); }
|
||||
u8 xe = TI(x,elType);
|
||||
if (v(f)->flags) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
if (RTID(f) != RTID_NONE) {
|
||||
u8 rtid = RTID(f);
|
||||
if (rtid==n_ltack) return TO_GET(x, 0);
|
||||
if (rtid==n_rtack) return TO_GET(x, ia-1);
|
||||
if (xe>el_f64) goto base;
|
||||
@ -274,8 +274,8 @@ B fold_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
if (RARE(!isFun(f))) { dec(w); decG(x); if (isMd(f)) thrM("Calling a modifier"); return inc(f); }
|
||||
|
||||
u8 xe = TI(x,elType);
|
||||
if (v(f)->flags) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
if (RTID(f) != RTID_NONE) {
|
||||
u8 rtid = RTID(f);
|
||||
if (rtid==n_ltack) {
|
||||
dec(w);
|
||||
return TO_GET(x, 0);
|
||||
@ -399,7 +399,7 @@ B insert_c1(Md1D* d, B x) { B f = d->f;
|
||||
shcpy(rsh, xsh+1, xr-1);
|
||||
}
|
||||
decG(x); return taga(r);
|
||||
} else if (v(f)->flags == n_join+1) {
|
||||
} else if (RTID(f) == n_join) {
|
||||
if (xr <= 1) thrM("˝: Identity does not exist");
|
||||
goto join;
|
||||
}
|
||||
@ -421,8 +421,8 @@ B insert_c1(Md1D* d, B x) { B f = d->f;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
if (v(f)->flags) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
if (RTID(f) != RTID_NONE) {
|
||||
u8 rtid = RTID(f);
|
||||
if (rtid==n_ltack) return C1(select, x);
|
||||
if (rtid==n_rtack) return C2(select, m_f64(-1), x);
|
||||
if (rtid==n_join) { join:;
|
||||
@ -470,8 +470,8 @@ B insert_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
return r;
|
||||
skip:;
|
||||
}
|
||||
if (v(f)->flags) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
if (RTID(f) != RTID_NONE) {
|
||||
u8 rtid = RTID(f);
|
||||
if (rtid==n_ltack) { dec(w); return C1(select, x); }
|
||||
if (rtid==n_rtack) { decG(x); return w; }
|
||||
}
|
||||
@ -619,8 +619,8 @@ B sum_rows_bit(B x, usz n, usz m) {
|
||||
// Return a vector regardless of argument shape, or bi_N if not handled
|
||||
B fold_rows_bit(Md1D* fd, B x, usz n, usz m) {
|
||||
assert(isArr(x) && TI(x,elType)==el_bit && IA(x)==n*m);
|
||||
if (!v(fd->f)->flags) return bi_N;
|
||||
u8 rtid = v(fd->f)->flags-1;
|
||||
if (RTID(fd->f) == RTID_NONE) return bi_N;
|
||||
u8 rtid = RTID(fd->f);
|
||||
if (rtid==n_add) return sum_rows_bit(x, n, m);
|
||||
#if SINGELI
|
||||
bool is_or = rtid==n_or |rtid==n_ceil;
|
||||
|
||||
@ -42,7 +42,7 @@ B each_c1(Md1D* d, B x) { B f = d->f;
|
||||
|
||||
if (isAtm(x)) r = m_hunit(c1(f, x));
|
||||
else if (isFun(f)) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
u8 rtid = RTID(f);
|
||||
if (rtid==n_ltack || rtid==n_rtack) {
|
||||
if (EACH_FILLS) dec(xf);
|
||||
return TI(x,arrD1) || IA(x)==0? x : any_squeeze(EACH_FILLS? x : withFill(x, bi_noFill));
|
||||
@ -83,11 +83,11 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
Arr* ra = mut_fp(rm);
|
||||
rsh = arr_shAlloc(ra, rr);
|
||||
r = taga(ra);
|
||||
} else if (v(f)->flags-1 == n_ltack) {
|
||||
} else if (RTID(f) == n_ltack) {
|
||||
Arr* wd = arr_shVec(TI(w,slice)(incG(w), 0, wia));
|
||||
r = C2(slash, m_i32(xia), taga(wd));
|
||||
goto arith_finish;
|
||||
} else if (v(f)->flags-1 == n_rtack) {
|
||||
} else if (RTID(f) == n_rtack) {
|
||||
r = C2(shape, m_f64(ria), incG(x));
|
||||
goto arith_finish;
|
||||
} else if (TI(w,arrD1) && isPervasiveDyExt(f)) {
|
||||
|
||||
@ -243,8 +243,8 @@ B scan_c1(Md1D* d, B x) { B f = d->f;
|
||||
return withFill(mut_fcd(rm, x), xf);
|
||||
}
|
||||
u8 xe = TI(x,elType);
|
||||
if (v(f)->flags) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
if (RTID(f) != RTID_NONE) {
|
||||
u8 rtid = RTID(f);
|
||||
if (rtid==n_rtack) return x;
|
||||
if (rtid==n_ltack) {
|
||||
usz csz = arr_csz(x);
|
||||
@ -318,8 +318,8 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
return withFill(mut_fcd(rm, x), xf);
|
||||
}
|
||||
u8 xe = TI(x,elType);
|
||||
if (v(f)->flags) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
if (RTID(f) != RTID_NONE) {
|
||||
u8 rtid = RTID(f);
|
||||
if (rtid==n_rtack) { dec(w); return x; }
|
||||
if (rtid==n_ltack) return C2(shape, C1(fne, x), w);
|
||||
if (!(xr==1 && elNum(xe) && xe<=el_f64)) goto base;
|
||||
|
||||
@ -228,7 +228,7 @@ B shape_c2(B t, B w, B x) {
|
||||
if (unkPos!=-1) thrM("⥊: 𝕨 contained multiple computed axes");
|
||||
unkPos = i;
|
||||
if (!isPrim(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
||||
unkInd = ((i32)v(c)->flags) - 1;
|
||||
unkInd = RTID(c);
|
||||
good|= xia==0 | unkInd==n_floor;
|
||||
}
|
||||
}
|
||||
|
||||
@ -986,7 +986,7 @@ B slash_ucw(B t, B o, B w, B x) {
|
||||
if (xe==el_B) goto notConstEach;
|
||||
|
||||
Md1D* od = c(Md1D,o);
|
||||
if (od->m1->flags-1 != n_each) goto notConstEach;
|
||||
if (PRTID(od->m1) != n_each) goto notConstEach;
|
||||
B f = od->f;
|
||||
B c;
|
||||
if (!toConstant(f, &c)) goto notConstEach;
|
||||
|
||||
@ -53,7 +53,7 @@ B decp_c1(B t, B x) {
|
||||
|
||||
B primInd_c1(B t, B x) {
|
||||
if (!isVal(x)) return m_i32(RT_LEN);
|
||||
if (isPrim(x)) { B r = m_i32(v(x)->flags-1); dec(x); return r; }
|
||||
if (isPrim(x)) { B r = m_i32(RTID(x)); dec(x); return r; }
|
||||
dec(x);
|
||||
return m_i32(RT_LEN);
|
||||
}
|
||||
@ -68,7 +68,7 @@ B glyph_c1(B t, B x) {
|
||||
x = rtWrap_unwrap(x);
|
||||
#endif
|
||||
if (isPrim(x)) {
|
||||
B r = m_c32(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!˙˜˘¨⌜⁼´˝`∘○⊸⟜⌾⊘◶⎉⚇⍟⎊"[v(x)->flags-1]);
|
||||
B r = m_c32(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!˙˜˘¨⌜⁼´˝`∘○⊸⟜⌾⊘◶⎉⚇⍟⎊"[RTID(x)]);
|
||||
decG(x);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ static B m2BI_d(B t, B f, B g) { return m_md2D(c(Md2,t), f, g); }
|
||||
|
||||
static B md1D_identity(B t) {
|
||||
Md1D* d = c(Md1D, t);
|
||||
if (d->m1->flags-1 == n_tbl) {
|
||||
if (PRTID(d->m1) == n_tbl) {
|
||||
B i = TI(d->f,identity)(d->f);
|
||||
return q_N(i)? i : m_unit(i);
|
||||
}
|
||||
|
||||
5
src/h.h
5
src/h.h
@ -424,6 +424,9 @@ void freeThrown(void);
|
||||
#define TY(X) PTY(v(X))
|
||||
#define RNK(X) PRNK(v(X))
|
||||
|
||||
#define RTID_NONE -1
|
||||
#define PRTID(X) ((X)->flags-1)
|
||||
#define RTID(X) PRTID(v(X))
|
||||
#define NID(X) ((X)->extra)
|
||||
|
||||
#define VTY(X,T) assert(isVal(X) && TY(X)==(T))
|
||||
@ -454,7 +457,7 @@ FORCE_INLINE bool isNum(B x) { return isF64(x); }
|
||||
|
||||
FORCE_INLINE bool isAtm(B x) { return !isArr(x); }
|
||||
FORCE_INLINE bool isCallable(B x) { return isMd(x) | isFun(x); }
|
||||
FORCE_INLINE bool isPrim(B x) { return isCallable(x) && v(x)->flags; }
|
||||
FORCE_INLINE bool isPrim(B x) { return isCallable(x) && RTID(x)!=RTID_NONE; }
|
||||
|
||||
|
||||
// make objects
|
||||
|
||||
@ -209,7 +209,7 @@ B rtWrap_wrap(B t, bool nnbi) {
|
||||
#endif
|
||||
if (isFun(t)) {
|
||||
#if RT_VERIFY
|
||||
if(v(t)->flags==0) return t;
|
||||
if(RTID(t) == RTID_NONE) return t;
|
||||
#endif
|
||||
WFun* r = mm_alloc(sizeof(WFun), t_funWrap);
|
||||
r->extra = v(t)->extra;
|
||||
@ -220,7 +220,7 @@ B rtWrap_wrap(B t, bool nnbi) {
|
||||
r->prev = lastWF;
|
||||
lastWF = r;
|
||||
#if RT_VERIFY
|
||||
r->r1 = r1Objs[v(t)->flags-1];
|
||||
r->r1 = r1Objs[RTID(t)];
|
||||
#elif RT_PERF
|
||||
r->c1t = 0; r->c1a = 0;
|
||||
r->c2t = 0; r->c2a = 0;
|
||||
@ -242,12 +242,11 @@ B rtWrap_wrap(B t, bool nnbi) {
|
||||
return tag(r,MD1_TAG);
|
||||
}
|
||||
if (isMd2(t)) {
|
||||
Md2* fc = c(Md2,t);
|
||||
WMd2* r = mm_alloc(sizeof(WMd2), t_md2Wrap);
|
||||
r->extra = v(t)->extra;
|
||||
r->flags = v(t)->flags;
|
||||
r->c1 = wm2_c1;
|
||||
r->c2 = wm2_c2;
|
||||
r->extra = fc->extra;
|
||||
r->flags = fc->flags;
|
||||
r->v = t;
|
||||
r->prev = lastWM2;
|
||||
lastWM2 = r;
|
||||
|
||||
@ -308,7 +308,7 @@ extern void (*const orAAu_bit_bit_bit)(void*,void*,void*,u64); // used in bits.c
|
||||
|
||||
DyTableAA* dyTableAAFor(B f) {
|
||||
assert(isFun(f));
|
||||
switch(v(f)->flags-1) { default: return NULL;
|
||||
switch(RTID(f)) { default: return NULL;
|
||||
case n_add: return &addDyTableAA;
|
||||
case n_sub: return &subDyTableAA;
|
||||
case n_mul: return &mulDyTableAA;
|
||||
@ -321,7 +321,7 @@ DyTableAA* dyTableAAFor(B f) {
|
||||
|
||||
DyTableSA* dyTableSAFor(B f, bool atomChar) {
|
||||
assert(isFun(f));
|
||||
switch(v(f)->flags-1) { default: return NULL;
|
||||
switch(RTID(f)) { default: return NULL;
|
||||
case n_add: return atomChar? &addDyTableCA : &addDyTableNA;
|
||||
case n_sub: return atomChar? &subDyTableCA : &subDyTableNA;
|
||||
case n_mul: return atomChar? NULL : &mulDyTableNA;
|
||||
@ -332,7 +332,7 @@ DyTableSA* dyTableSAFor(B f, bool atomChar) {
|
||||
}
|
||||
DyTableSA* dyTableASFor(B f, bool atomChar) {
|
||||
assert(isFun(f));
|
||||
switch(v(f)->flags-1) { default: return NULL;
|
||||
switch(RTID(f)) { default: return NULL;
|
||||
case n_add: return atomChar? &addDyTableCA : &addDyTableNA;
|
||||
case n_sub: return atomChar? &subDyTableAC : &subDyTableAN;
|
||||
case n_mul: return atomChar? NULL : &mulDyTableNA;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user