split apart def_decompose

This commit is contained in:
dzaima 2024-10-10 02:33:24 +03:00
parent c46182d070
commit 6bd47b067e
7 changed files with 14 additions and 15 deletions

View File

@ -74,13 +74,6 @@ static const i32 firstImpurePFN = pf_type;
static const i32 firstImpurePM1 = pm1_timed;
static const i32 firstImpurePM2 = pm2_while;
static inline bool isImpureBuiltin(B x) {
if (isFun(x)) { u8 nid = NID(v(x)); return nid==0 || nid>=firstImpurePFN; }
if (isMd1(x)) { u8 nid = NID(v(x)); return nid==0 || nid>=firstImpurePM1; }
if (isMd2(x)) { u8 nid = NID(v(x)); return nid==0 || nid>=firstImpurePM2; }
return false;
}
// these assume x is a function
static inline bool isPervasiveDy (B x) { return (u8)RTID(x) <= n_ge; }
static inline bool isPervasiveMon(B x) { return (u8)RTID(x) <= n_stile; }

View File

@ -56,7 +56,6 @@ NOINLINE i32 compareF(B w, B x) {
NOINLINE bool atomEqualF(B w, B x) {
if (TY(w)!=TY(x)) return false;
B2B dcf = TI(w,decompose);
if (dcf == def_decompose) return false;
B wd=dcf(incG(w)); B* wdp = harr_ptr(wd);
B xd=dcf(incG(x)); B* xdp = harr_ptr(xd);
if (o2i(wdp[0])<=1) { decG(wd);decG(xd); return false; }
@ -75,7 +74,6 @@ bool atomEEqual(B w, B x) { // doesn't consume
if (!isVal(w) | !isVal(x)) return false;
if (TY(w)!=TY(x)) return false;
B2B dcf = TI(w,decompose);
if (dcf == def_decompose) return false;
B wd=dcf(incG(w)); B* wdp = harr_ptr(wd);
B xd=dcf(incG(x)); B* xdp = harr_ptr(xd);
if (o2i(wdp[0])<=1) { decG(wd);decG(xd); return false; }

View File

@ -87,9 +87,6 @@ B def_m1_uc1(Md1* t, B o, B f, B x) { B t2 = m1_d(tag(ptr_inc(t),MD1_T
B def_m1_ucw(Md1* t, B o, B f, B w, B x) { B t2 = m1_d(tag(ptr_inc(t),MD1_TAG),inc(f) ); B r = rtUnder_cw(o, t2, w, x); decG(t2); return r; }
B def_m2_uc1(Md2* t, B o, B f, B g, B x) { B t2 = m2_d(tag(ptr_inc(t),MD2_TAG),inc(f),inc(g)); B r = rtUnder_c1(o, t2, x); decG(t2); return r; }
B def_m2_ucw(Md2* t, B o, B f, B g, B w, B x) { B t2 = m2_d(tag(ptr_inc(t),MD2_TAG),inc(f),inc(g)); B r = rtUnder_cw(o, t2, w, x); decG(t2); return r; }
B def_decompose(B x) {
return m_hvec2(m_i32(isCallable(x)? (isImpureBuiltin(x)? 1 : 0) : -1),x);
}
GLOBAL B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec;

View File

@ -288,7 +288,6 @@ B def_fn_is(B t, B x);
B def_fn_im(B t, B x); B def_m1_im(Md1D* d, B x); B def_m2_im(Md2D* d, B x);
B def_fn_iw(B t, B w, B x); B def_m1_iw(Md1D* d, B w, B x); B def_m2_iw(Md2D* d, B w, B x);
B def_fn_ix(B t, B w, B x); B def_m1_ix(Md1D* d, B w, B x); B def_m2_ix(Md2D* d, B w, B x);
B def_decompose(B x);
void noop_visit(Value* x);
#if HEAP_VERIFY

View File

@ -686,6 +686,12 @@ static void def_visit(Value* x) { fatal("undefined visit for object\n"); }
static void def_print(FILE* f, B x) { fprintf(f, "(%d=%s)", v(x)->type, type_repr(v(x)->type)); }
static bool def_canStore(B x) { return false; }
static B def_identity(B f) { return bi_N; }
static NOINLINE B makeDecompose(i32 i, B x) { return m_hvec2(m_i32(i), x); }
static B def_decompose(B x) { assert(!isCallable(x)); return makeDecompose(-1, x); }
static B funBI_decompose(B x) { return makeDecompose(NID(c(BFn, x))>=firstImpurePFN? 1 : 0, x); }
static B md1BI_decompose(B x) { return makeDecompose(NID(c(BMd1,x))>=firstImpurePM1? 1 : 0, x); }
static B md2BI_decompose(B x) { return makeDecompose(NID(c(BMd2,x))>=firstImpurePM2? 1 : 0, x); }
B block_decompose(B x) { return makeDecompose(1, x); }
static B def_get(Arr* x, usz n) { fatal("def_get"); }
static B def_getU(Arr* x, usz n) { fatal("def_getU"); }
static B def_m1_d(B m, B f ) { thrM("cannot derive this"); }
@ -834,10 +840,15 @@ void base_init() { // very first init function
TIi(t_shape,visit) = noop_visit;
TIi(t_temp,visit) = noop_visit;
TIi(t_talloc,visit) = noop_visit;
TIi(t_md1BI,visit) = TIi(t_md2BI,visit) = noop_visit;
TIi(t_md1BI,freeO) = TIi(t_md2BI,freeO) = TIi(t_funBI,freeO) = builtin_free;
TIi(t_md1BI,freeF) = TIi(t_md2BI,freeF) = TIi(t_funBI,freeF) = builtin_free;
TIi(t_funBI,visit) = funBI_visit;
TIi(t_funBI,decompose) = funBI_decompose;
TIi(t_md1BI,decompose) = md1BI_decompose;
TIi(t_md2BI,decompose) = md2BI_decompose;
TIi(t_hashmap,visit) = noop_visit;
TIi(t_customObj,freeO) = customObj_freeO;
TIi(t_customObj,freeF) = customObj_freeF;

View File

@ -34,11 +34,13 @@ DEF_FREE(nfnDesc) { fatal("nfnDesc shouldn't be freed!"); }
void nfnDesc_visit(Value* x) { mm_visit(((NFnDesc*)x)->name); }
void nfnDesc_print(FILE* f, B x) { fprintf(f, "(native function description)"); }
B block_decompose(B x);
void nfn_init(void) {
nfn_list = emptyHVec();
TIi(t_nfn,freeO) = nfn_freeO; TIi(t_nfnDesc,freeO) = nfnDesc_freeO;
TIi(t_nfn,freeF) = nfn_freeF; TIi(t_nfnDesc,freeF) = nfnDesc_freeF;
TIi(t_nfn,visit) = nfn_visit; TIi(t_nfnDesc,visit) = nfnDesc_visit;
TIi(t_nfn,print) = nfn_print; TIi(t_nfnDesc,print) = nfnDesc_print;
TIi(t_nfn,decompose) = block_decompose;
gc_add_ref(&nfn_list);
}

View File

@ -1159,8 +1159,7 @@ void scExt_print(FILE* f, B x) { fprintf(f,"(scope extension with %d vars)", c(S
void funBl_print(FILE* f, B x) { fprintf(f,"{function"" block}"); }
void md1Bl_print(FILE* f, B x) { fprintf(f,"{1-modifier block}"); }
void md2Bl_print(FILE* f, B x) { fprintf(f,"{2-modifier block}"); }
B block_decompose(B x) { return m_hvec2(m_i32(1), x); }
B block_decompose(B x);
#if !defined(_WIN32) && !defined(_WIN64)
STATIC_GLOBAL usz pageSizeV;