diff --git a/src/h.h b/src/h.h index 5e6d294d..d0396744 100644 --- a/src/h.h +++ b/src/h.h @@ -392,12 +392,8 @@ TypeInfo ti[t_COUNT]; B bi_N, bi_noVar, bi_badHdr, bi_optOut, bi_noFill; void do_nothing(B x) { } -B def_decompose(B x) { return m_v2(m_i32((isFun(x)|isMd(x))? 0 : -1),x); } - - bool isNothing(B b) { return b.u==bi_N.u; } - // refcount bool reusable(B x) { return v(x)->refc==1; } static inline void value_free(B x, Value* vx) { diff --git a/src/main.c b/src/main.c index 267fe1e1..345a8692 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,7 @@ // #define OBJ_COUNTER // store a unique allocation number with each object for easier analysis // #define ALL_R0 // use all of r0.bqn for runtime_0 // #define ALL_R1 // use all of r1.bqn for runtime +#define EACH_FILLS false // whether to try to squeeze out fills for ¨ and ⌜ #define FAKE_RUNTIME false // whether to disable the self-hosted runtime // #define LOG_GC // log GC stats @@ -19,6 +20,12 @@ // #define TIME // output runtime of every expression // #define RT_PERF // time runtime primitives + +#ifndef CATCH_ERRORS + #undef EACH_FILLS + #define EACH_FILLS false +#endif + #define rtLen 63 #include "h.h" #include "stuff.c" @@ -101,7 +108,7 @@ int main() { comp_init(); rtPerf_init(); - // fake runtime + B fruntime[] = { /* +-×÷⋆√⌊⌈|¬ */ bi_add , bi_sub , bi_mul , bi_div , bi_pow , bi_N , bi_floor, bi_ceil, bi_stile , bi_not, /* ∧∨<>≠=≤≥≡≢ */ bi_and , bi_or , bi_lt , bi_gt , bi_ne , bi_eq , bi_le , bi_ge , bi_feq , bi_fne, @@ -114,7 +121,7 @@ int main() { bool rtComplete[] = { /* +-×÷⋆√⌊⌈|¬ */ 1,1,1,1,1,0,1,1,1,1, /* ∧∨<>≠=≤≥≡≢ */ 1,1,1,1,1,1,1,1,1,1, - /* ⊣⊢⥊∾≍↑↓↕«» */ 1,1,0,1,0,0,0,0,0,1, + /* ⊣⊢⥊∾≍↑↓↕«» */ 1,1,0,1,0,0,0,0,0,0, /* ⌽⍉/⍋⍒⊏⊑⊐⊒∊ */ 0,0,1,0,0,1,0,0,0,0, /* ⍷⊔!˙˜˘¨⌜⁼´ */ 0,0,1,1,1,0,1,1,0,1, /* ˝`∘○⊸⟜⌾⊘◶⎉ */ 0,1,1,1,1,1,0,1,0,0, diff --git a/src/md1.c b/src/md1.c index ca54c4a0..ac6fda24 100644 --- a/src/md1.c +++ b/src/md1.c @@ -1,10 +1,58 @@ #include "h.h" + +bool isPureFn(B x) { // doesn't consume + if (!isFun(x) && !isMd(x)) return true; + if (v(x)->flags) return true; + B2B dcf = TI(x).decompose; + B xd = dcf(inc(x)); + B* xdp = harr_ptr(xd); + i32 t = o2iu(xdp[0]); + if (t<2) { dec(xd); return t==0; } + usz xdia = a(xd)->ia; + for (i32 i = 1; if; - // return eachm(f, x); - return withFill(eachm(f, x), m_f64(0)); + if (!EACH_FILLS) return eachm(f, x); + B xf = getFill(inc(x)); + return homFil1(f, eachm(f, x), xf); } B tbl_c2(B d, B w, B x) { B f = c(Md1D,d)->f; + B wf, xf; + if (EACH_FILLS) wf = getFill(inc(w)); + if (EACH_FILLS) xf = getFill(inc(x)); if (isAtm(w)) w = m_hunit(w); if (isAtm(x)) x = m_hunit(x); usz wia = a(w)->ia; ur wr = rnk(w); @@ -28,17 +76,20 @@ B tbl_c2(B d, B w, B x) { B f = c(Md1D,d)->f; memcpy(rsh+wr, a(x)->sh, xr*sizeof(usz)); } dec(w); dec(x); - // return r.b; - return withFill(r.b, m_f64(0)); + if (EACH_FILLS) return homFil2(f, r.b, wf, xf); + return r.b; } B each_c1(B d, B x) { B f = c(Md1D,d)->f; - // return eachm(f, x); - return withFill(eachm(f, x), m_f64(0)); + if (!EACH_FILLS) return eachm(f, x); + B xf = getFill(inc(x)); + return homFil1(f, eachm(f, x), xf); } B each_c2(B d, B w, B x) { B f = c(Md1D,d)->f; - // return eachd(f, w, x); - return withFill(eachd(f, w, x), m_f64(0)); + if (!EACH_FILLS) return eachd(f, w, x); + B wf = getFill(inc(w)); + B xf = getFill(inc(x)); + return homFil2(f, eachd(f, w, x), wf, xf); } diff --git a/src/stuff.c b/src/stuff.c index ec63a732..50273e58 100644 --- a/src/stuff.c +++ b/src/stuff.c @@ -176,6 +176,7 @@ B def_m1_d(B m, B f ) { thrM("cannot derive this"); } B def_m2_d(B m, B f, B g) { thrM("cannot derive this"); } B def_slice(B x, usz s) { thrM("cannot slice non-array!"); } bool def_canStore(B x) { return false; } +B def_decompose(B x) { return m_v2(m_i32((isFun(x)|isMd(x))? 0 : -1),x); } static inline void hdr_init() { for (i32 i = 0; i < t_COUNT; i++) { diff --git a/src/sysfn.c b/src/sysfn.c index caffa54e..6b46825c 100644 --- a/src/sysfn.c +++ b/src/sysfn.c @@ -9,7 +9,7 @@ B type_c1(B t, B x) { else if (isFun(x)) r = 3; else if (isMd1(x)) r = 4; else if (isMd2(x)) r = 5; - if (r==-1) return err("getting type"); + if (r==-1) { print(x); err(": getting type"); } decR(x); return m_i32(r); } @@ -34,7 +34,12 @@ B glyph_c1(B t, B x) { B fill_c1(B t, B x) { B f = getFill(x); - if (noFill(f)) thrM("No fill found"); + if (noFill(f)) { + #if !defined(CATCH_ERRORS) || !EACH_FILLS + return m_f64(0); + #endif + thrM("No fill found"); + } return f; } B fill_c2(B t, B w, B x) { // TODO not set fill for typed arrays @@ -121,6 +126,7 @@ B asrt_c2(B t, B w, B x) { thr(w); } +bool isPureFn(B x); B internal_c2(B t, B w, B x) { B r; u64 id = o2s(w); @@ -137,6 +143,7 @@ B internal_c2(B t, B w, B x) { } else if(id==1) { r = isVal(x)? m_i32(v(x)->mmInfo & 0x7f) : m_str32(U"(not heap-allocated)"); } else if(id==2) { r = isVal(x)? m_i32(v(x)->refc) : m_str32(U"(not heap-allocated)"); } else if(id==3) { printf("%p\n", (void*)x.u); r = inc(x); } + else if(id==4) { r = m_f64(isPureFn(x)); } else { dec(x); thrM("Bad 𝕨 argument for •Internal"); } dec(x); return r;