crappy fills

This commit is contained in:
dzaima 2021-05-01 22:26:18 +03:00
parent 2828a05dfc
commit 76c3466c96
5 changed files with 78 additions and 16 deletions

View File

@ -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) {

View File

@ -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,

View File

@ -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; i<xdia; i++) if(!isPureFn(xdp[i])) { dec(xd); return false; }
dec(xd); return true;
}
B homFil1(B f, B r, B xf) {
assert(EACH_FILLS);
if (isPureFn(f)) {
if (f.u==bi_eq.u || f.u==bi_ne.u || f.u==bi_feq.u) { dec(xf); return tag(toI32Arr(r), ARR_TAG); } // ≠ may return ≥2⋆31, but whatever, this thing is stupid anyway
if (f.u==bi_fne.u) { dec(xf); return withFill(r, m_harrUv(0).b); }
if (!noFill(xf)) {
if (CATCH) { dec(catchMessage); return r; }
B rf = asFill(c1(f, xf));
popCatch();
return withFill(r, rf);
}
}
dec(xf);
return r;
}
B homFil2(B f, B r, B wf, B xf) {
assert(EACH_FILLS);
if (isPureFn(f)) {
if (f.u==bi_feq.u || f.u==bi_fne.u) { dec(wf); dec(xf); return tag(toI32Arr(r), ARR_TAG); }
if (!noFill(wf) && !noFill(xf)) {
if (CATCH) { dec(catchMessage); return r; }
B rf = asFill(c2(f, wf, xf));
popCatch();
return withFill(r, rf);
}
}
dec(wf); dec(xf);
return r;
}
B tbl_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 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);
}

View File

@ -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++) {

View File

@ -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;