x->type → TY(x) / PTY(x)

This commit is contained in:
dzaima 2022-08-19 23:00:57 +03:00
parent d2a4efe4b5
commit e10f13d6ea
6 changed files with 26 additions and 25 deletions

View File

@ -7,7 +7,7 @@
B itype_c1(B t, B x) {
B r;
if(isVal(x)) {
r = m_c8vec_0(type_repr(v(x)->type));
r = m_c8vec_0(type_repr(TY(x)));
} else {
if (isF64(x)) r = m_c8vec_0("tagged f64");
else if (isC32(x)) r = m_c8vec_0("tagged c32");
@ -55,7 +55,7 @@ B info_c2(B t, B w, B x) {
AFMT("flags:%i ", xv->flags);
AFMT("extra:%i ", xv->extra);
}
AFMT("type:%i=%S ", xv->type, type_repr(xv->type));
AFMT("type:%i=%S ", PTY(xv), type_repr(PTY(xv)));
AFMT("alloc:%l", mm_size(xv));
decG(x);
} else {
@ -243,7 +243,7 @@ B clearRefs_c1(B t, B x) {
static B unshare(B x) {
if (!isArr(x)) return x;
usz xia = IA(x);
switch (v(x)->type) {
switch (TY(x)) {
case t_bitarr: return taga(cpyBitArr(inc(x)));
case t_i8arr: return taga(cpyI8Arr (inc(x)));
case t_i16arr: return taga(cpyI16Arr(inc(x)));
@ -265,7 +265,7 @@ static B unshare(B x) {
for (usz i = 0; i < xia; i++) rp[i] = unshare(xp[i]);
return taga(r);
}
default: thrF("•internal.Unshare: Cannot unshare array with type %i=%S", v(x)->type, type_repr((v(x)->type)));
default: thrF("•internal.Unshare: Cannot unshare array with type %i=%S", TY(x), type_repr(TY(x)));
}
}

View File

@ -212,7 +212,7 @@ B scan_c1(Md1D* d, B x) { B f = d->f;
base:;
SLOW2("𝕎` 𝕩", f, x);
bool reuse = v(x)->type==t_harr && reusable(x);
bool reuse = TY(x)==t_harr && reusable(x);
HArr_p r = reuse? harr_parts(REUSE(x)) : m_harr0c(x);
AS2B xget = reuse? TI(x,getU) : TI(x,get); Arr* xa = a(x);
BBB2B fc2 = c2fn(f);
@ -268,7 +268,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f;
base:;
SLOW3("𝕨 F` 𝕩", w, x, f);
bool reuse = (v(x)->type==t_harr && reusable(x)) | !ia;
bool reuse = (TY(x)==t_harr && reusable(x)) | !ia;
usz i = 0;
HArr_p r = reuse? harr_parts(REUSE(x)) : m_harr0c(x);
AS2B xget = reuse? TI(x,getU) : TI(x,get); Arr* xa = a(x);

View File

@ -379,8 +379,10 @@ void freeThrown(void);
#define PIA(X) ((X)->ia)
#define SH(X) (a(X)->sh)
#define PSH(X) ((X)->sh)
#define TY(X) (v(X)->type)
#define PTY(X) ((X)->type)
#define VTY(X,T) assert(isVal(X) && v(X)->type==(T))
#define VTY(X,T) assert(isVal(X) && TY(X)==(T))
void print_vmStack(void);
#ifdef DEBUG
@ -525,8 +527,8 @@ typedef B (*D2C2)(Md2D*, B, B);
FOR_TI(F)
#undef F
#define TIi(X,V) (ti_##V[X])
#define TIv(X,V) (ti_##V[(X)->type])
#define TI(X,V) (ti_##V[v(X)->type])
#define TIv(X,V) (ti_##V[PTY(X)])
#define TI(X,V) (ti_##V[ TY(X)])
#define SGetU(X) Arr* X##_arrU = a(X); AS2B X##_getU = TIv(X##_arrU,getU);
#define IGetU(X,N) ({ Arr* x_ = a(X); TIv(x_,getU)(x_,N); })

View File

@ -24,11 +24,11 @@ static void nfn_lateInit(NFn* fn, NFnDesc* desc) {
fn->id = desc->id;
}
static B nfn_objU(B t) {
assert(isVal(t) && v(t)->type == t_nfn);
assert(isVal(t) && TY(t) == t_nfn);
return c(NFn,t)->obj;
}
static i32 nfn_data(B t) {
assert(isVal(t) && v(t)->type == t_nfn);
assert(isVal(t) && TY(t) == t_nfn);
return c(NFn,t)->data;
}
static B nfn_swapObj(B t, B n) { // consumes n, returns old value

View File

@ -260,9 +260,9 @@ B rtWrap_wrap(B t, bool nnbi) {
}
B rtWrap_unwrap(B x) {
if (!isVal(x)) return x;
if (v(x)->type==t_funWrap) { B r = c(WFun,x)->v; dec(x); return r; }
if (v(x)->type==t_md1Wrap) { B r = c(WMd1,x)->v; dec(x); return r; }
if (v(x)->type==t_md2Wrap) { B r = c(WMd2,x)->v; dec(x); return r; }
if (TY(x)==t_funWrap) { B r = c(WFun,x)->v; dec(x); return r; }
if (TY(x)==t_md1Wrap) { B r = c(WMd1,x)->v; dec(x); return r; }
if (TY(x)==t_md2Wrap) { B r = c(WMd2,x)->v; dec(x); return r; }
return x;
}

View File

@ -482,7 +482,7 @@ NOINLINE Block* compile(B bcq, B objs, B allBlocks, B allBodies, B indices, B to
FORCE_INLINE bool v_merge(Scope* pscs[], B s, B x, bool upd, bool hdr) {
assert(v(s)->type == t_arrMerge);
assert(TY(s) == t_arrMerge);
B o = c(WrappedObj,s)->obj;
if (!isArr(x) || rnk(x)==0) thrF("[…]%U𝕩: 𝕩 cannot have rank 0", upd? "" : "");
@ -529,7 +529,7 @@ NOINLINE void v_setF(Scope* pscs[], B s, B x, bool upd) {
ScopeExt* ext = pscs[(u16)(c.u>>32)]->ext;
v_set(pscs, c, ns_getNU(x, ext->vars[(u32)c.u + ext->varAm], true), upd, true);
} else if (isObj(c)) {
assert(v(c)->type == t_fldAlias);
assert(TY(c) == t_fldAlias);
FldAlias* cf = c(FldAlias,c);
v_set(pscs, cf->obj, ns_getU(x, cf->p), upd, true);
} else thrM("Assignment: extracting non-name from namespace");
@ -541,8 +541,8 @@ NOINLINE void v_setF(Scope* pscs[], B s, B x, bool upd) {
} else if (s.u == bi_N.u) {
return;
} else if (isObj(s)) {
if (v(s)->type == t_arrMerge) v_merge(pscs, s, x, upd, false);
else if (v(s)->type == t_fldAlias) thrF("Assignment: Cannot assign non-namespace to a list containing aliases"); // v_set(pscs, c(FldAlias, s)->obj, x, upd, true);
if (TY(s) == t_arrMerge) v_merge(pscs, s, x, upd, false);
else if (TY(s) == t_fldAlias) thrF("Assignment: Cannot assign non-namespace to a list containing aliases"); // v_set(pscs, c(FldAlias, s)->obj, x, upd, true);
else UD;
} else if (isExt(s)) {
Scope* sc = pscs[(u16)(s.u>>32)];
@ -567,8 +567,7 @@ NOINLINE bool v_sethF(Scope* pscs[], B s, B x) {
Scope* sc = pscs[(u16)(c.u>>32)];
B g = ns_qgetU(x, pos2gid(sc->body, (u32)c.u));
if (q_N(g) || !v_seth(pscs, c, g)) return false;
} else if (isObj(c) && v(c)->type==t_fldAlias) {
assert(v(c)->type == t_fldAlias);
} else if (isObj(c) && TY(c)==t_fldAlias) {
FldAlias* cf = c(FldAlias,c);
B g = ns_qgetU(x, cf->p);
if (q_N(g) || !v_seth(pscs, cf->obj, g)) return false;
@ -580,9 +579,9 @@ NOINLINE bool v_sethF(Scope* pscs[], B s, B x) {
for (u64 i = 0; i < ia; i++) if (!v_seth(pscs, sp[i], GetU(x,i))) return false;
return true;
}
if (v(s)->type==t_vfyObj) return equal(c(WrappedObj,s)->obj,x);
if (v(s)->type==t_arrMerge) return v_merge(pscs, s, x, false, true);
if (v(s)->type==t_fldAlias) return false; // return v_seth(pscs, c(FldAlias, s)->obj, x);
if (TY(s)==t_vfyObj) return equal(c(WrappedObj,s)->obj,x);
if (TY(s)==t_arrMerge) return v_merge(pscs, s, x, false, true);
if (TY(s)==t_fldAlias) return false; // return v_seth(pscs, c(FldAlias, s)->obj, x);
UD;
}
@ -603,7 +602,7 @@ NOINLINE B v_getF(Scope* pscs[], B s) {
sc->ext->vars[(u32)s.u] = bi_optOut;
return r;
} else {
assert(isObj(s) && v(s)->type==t_arrMerge);
assert(isObj(s) && TY(s)==t_arrMerge);
return bqn_merge(v_getF(pscs, c(WrappedObj,s)->obj));
}
}
@ -648,7 +647,7 @@ NOINLINE void scope_decF(Scope* sc) {
for (i32 i = 0; i < varAm; i++) {
B c = sc->vars[i];
if (isVal(c) && v(c)->refc==1) {
u8 t = v(c)->type;
u8 t = TY(c);
if (t==t_funBl && c(FunBlock,c)->sc==sc) innerRef++;
else if (t==t_md1Bl && c(Md1Block,c)->sc==sc) innerRef++;
else if (t==t_md2Bl && c(Md2Block,c)->sc==sc) innerRef++;