From c79e260e34e585a27cacdd2783dbb6dc6b005cbb Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 20 Nov 2021 01:05:14 +0200 Subject: [PATCH] =?UTF-8?q?m=5Fv[1234]=20=E2=86=92=20m=5FhVec[1234]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/README.md | 12 ++++++------ src/builtins/sfns.c | 2 +- src/builtins/sysfn.c | 8 ++++---- src/core/derv.c | 10 +++++----- src/core/harr.h | 8 ++++---- src/core/stuff.c | 2 +- src/core/stuff.h | 8 ++++---- src/load.c | 14 +++++++------- src/vm.c | 2 +- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/README.md b/src/README.md index 1791ccc6..c9395a8b 100644 --- a/src/README.md +++ b/src/README.md @@ -92,9 +92,9 @@ An object can be allocated with `mm_alloc(sizeInBytes, t_something)`. The return A heap-allocated object can be cast to a `Value*` with `v(x)`, to an `Arr*` with `a(x)`, or to any pointer type with `c(Type,x)`. `v(x)->type` stores the type of an object (see `enum Type` in `src/h.h`), which is used by runtime functions to decide how to interpret an object. -Reference count of any `B` object can be incremented/decremented with `inc(x)`/`dec(x)` (`inc(x)` also returns `x`, so you can use it inline in the consumer). A pointer type has `ptr_inc(x)`/`ptr_dec(x)`. `dec`/`ptr_dec` will return the object to the memory manager if the refcount goes to zero. +Reference count of any `B` object can be incremented/decremented with `inc(x)`/`dec(x)`, and any subtype of `Value*` has `ptr_inc(x)`/`ptr_dec(x)`. `inc(x)`/`ptr_inc(x)` will return the argument, so you can use it inline, and `dec`/`ptr_dec` will return the object to the memory manager if the refcount goes to zero. -Since reference counting is hard, there's `make heapverify` that verifies that code executed does it right (and screams unreadable messages when it doesn't). After any changes, I'd suggest running: +Since reference counting is hard, there's `make heapverify` that verifies that any code executed does it right (and screams unreadable messages when it doesn't). After any changes, I'd suggest running: ```bash #!/usr/bin/env bash make rtverify && echo 'rtverify:' && ./BQN -M 1000 path/to/mlochbaum/BQN/test/this.bqn @@ -200,10 +200,10 @@ u64 sz = utf8lenB(x); TALLOC(char, buf, sz+1); toUTF8(x, buf); buf[sz]=0; /*use B r = m_unit(x); // equivalent to <𝕩 B r = m_hunit(x); // like the above, except no fill is set B r = m_atomUnit(x); // if x is likely to be an atom, this is a better alternative to m_unit -B r = m_v1(a); // ⟨a⟩ -B r = m_v2(a,b); // ⟨a,b⟩ -B r = m_v3(a,b,c); // ⟨a,b,c⟩ -B r = m_v4(a,b,c,d); // ⟨a,b,c,d⟩ +B r = m_hVec1(a); // ⟨a⟩ +B r = m_hVec2(a,b); // ⟨a,b⟩ +B r = m_hVec3(a,b,c); // ⟨a,b,c⟩ +B r = m_hVec4(a,b,c,d); // ⟨a,b,c,d⟩ B r = emptyHVec(); // an empty vector with no fill B r = emptyIVec(); // an empty integer vector B r = emptyCVec(); // an empty character vector diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 0e42e1da..89ad1658 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -72,7 +72,7 @@ FORCE_INLINE B m_vec2Base(B a, B b, bool fills) { return taga(ra); } noFills: - return m_v2(a,b); + return m_hVec2(a,b); } B m_vec2(B a, B b) { return m_vec2Base(a, b, false); } diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 9ab4e909..d241a4ea 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -41,8 +41,8 @@ B type_c1(B t, B x) { } B decp_c1(B t, B x) { - if (!isVal(x)) return m_v2(m_i32(-1), x); - if (isPrim(x)) return m_v2(m_i32(0), x); + if (!isVal(x)) return m_hVec2(m_i32(-1), x); + if (isPrim(x)) return m_hVec2(m_i32(0), x); return TI(x,decompose)(x); } @@ -537,7 +537,7 @@ B reBQN_c1(B t, B x) { scVal = tag(sc,OBJ_TAG); } ptr_dec(initBlock); - return m_nfn(reBQNDesc, m_v2(m_f64(replVal), scVal)); + return m_nfn(reBQNDesc, m_hVec2(m_f64(replVal), scVal)); } B repl_c2(B t, B w, B x) { vfyStr(x, "REPL", "𝕩"); @@ -753,7 +753,7 @@ B sh_c1(B t, B x) { posix_spawn_file_actions_destroy(&a); dec(x); - return m_v3(m_i32(WEXITSTATUS(status)), s_out, s_err); + return m_hVec3(m_i32(WEXITSTATUS(status)), s_out, s_err); } #else B sh_c1(B t, B x) { diff --git a/src/core/derv.c b/src/core/derv.c index e660c3e8..fd7bb59c 100644 --- a/src/core/derv.c +++ b/src/core/derv.c @@ -49,11 +49,11 @@ B fork_c2(B t, B w, B x) { B md2H_c1(Md1D* m, B x) { Md2H* t=c(Md2H,m->m1); return md2D_c1(m_md2D(t->m2, m->f, t->g), x); } B md2H_c2(Md1D* m, B w, B x) { Md2H* t=c(Md2H,m->m1); return md2D_c2(m_md2D(t->m2, m->f, t->g), w, x); } -static B md1D_decompose(B x) { B r=m_v3(m_i32(4),inc(c(Md1D,x)->f),inc(c(Md1D,x)->m1) ); decR(x); return r; } -static B md2D_decompose(B x) { B r=m_v4(m_i32(5),inc(c(Md2D,x)->f),inc(c(Md2D,x)->m2), inc(c(Md2D,x)->g)); decR(x); return r; } -static B md2H_decompose(B x) { B r=m_v3(m_i32(6), inc(c(Md2H,x)->m2), inc(c(Md2H,x)->g)); decR(x); return r; } -static B fork_decompose(B x) { B r=m_v4(m_i32(3),inc(c(Fork,x)->f),inc(c(Fork,x)->g ), inc(c(Fork,x)->h)); decR(x); return r; } -static B atop_decompose(B x) { B r=m_v3(m_i32(2), inc(c(Atop,x)->g ), inc(c(Atop,x)->h)); decR(x); return r; } +static B md1D_decompose(B x) { B r=m_hVec3(m_i32(4),inc(c(Md1D,x)->f),inc(c(Md1D,x)->m1) ); decR(x); return r; } +static B md2D_decompose(B x) { B r=m_hVec4(m_i32(5),inc(c(Md2D,x)->f),inc(c(Md2D,x)->m2), inc(c(Md2D,x)->g)); decR(x); return r; } +static B md2H_decompose(B x) { B r=m_hVec3(m_i32(6), inc(c(Md2H,x)->m2), inc(c(Md2H,x)->g)); decR(x); return r; } +static B fork_decompose(B x) { B r=m_hVec4(m_i32(3),inc(c(Fork,x)->f),inc(c(Fork,x)->g ), inc(c(Fork,x)->h)); decR(x); return r; } +static B atop_decompose(B x) { B r=m_hVec3(m_i32(2), inc(c(Atop,x)->g ), inc(c(Atop,x)->h)); decR(x); return r; } static B md2D_uc1(B t, B o, B x) { B m = c(Md2D, t)->m2; diff --git a/src/core/harr.h b/src/core/harr.h index 6c7f448a..d8c885e1 100644 --- a/src/core/harr.h +++ b/src/core/harr.h @@ -93,8 +93,8 @@ static HArr* toHArr(B x) { return v(x)->type==t_harr? c(HArr,x) : cpyHArr(x); } B m_caB(usz ia, B* a); // consumes all -static B m_v1(B a ) { HArr_p r = m_harrUv(1); r.a[0] = a; return r.b; } -static B m_v2(B a, B b ) { HArr_p r = m_harrUv(2); r.a[0] = a; r.a[1] = b; return r.b; } -static B m_v3(B a, B b, B c ) { HArr_p r = m_harrUv(3); r.a[0] = a; r.a[1] = b; r.a[2] = c; return r.b; } -static B m_v4(B a, B b, B c, B d) { HArr_p r = m_harrUv(4); r.a[0] = a; r.a[1] = b; r.a[2] = c; r.a[3] = d; return r.b; } +static B m_hVec1(B a ) { HArr_p r = m_harrUv(1); r.a[0] = a; return r.b; } +static B m_hVec2(B a, B b ) { HArr_p r = m_harrUv(2); r.a[0] = a; r.a[1] = b; return r.b; } +static B m_hVec3(B a, B b, B c ) { HArr_p r = m_harrUv(3); r.a[0] = a; r.a[1] = b; r.a[2] = c; return r.b; } +static B m_hVec4(B a, B b, B c, B d) { HArr_p r = m_harrUv(4); r.a[0] = a; r.a[1] = b; r.a[2] = c; r.a[3] = d; return r.b; } diff --git a/src/core/stuff.c b/src/core/stuff.c index c6ec72d7..84eb2540 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -62,7 +62,7 @@ B def_m1_ucw(B t, B o, B f, B w, B x) { B t2 = m1_d(inc(t),inc(f) ); B def_m2_uc1(B t, B o, B f, B g, B x) { B t2 = m2_d(inc(t),inc(f),inc(g)); B r = rtUnder_c1(o, t2, x); dec(t2); return r; } B def_m2_ucw(B t, B o, B f, B g, B w, B x) { B t2 = m2_d(inc(t),inc(f),inc(g)); B r = rtUnder_cw(o, t2, w, x); dec(t2); return r; } B def_decompose(B x) { - return m_v2(m_i32(isCallable(x)? (isImpureBuiltin(x)? 1 : 0) : -1),x); + return m_hVec2(m_i32(isCallable(x)? (isImpureBuiltin(x)? 1 : 0) : -1),x); } B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; diff --git a/src/core/stuff.h b/src/core/stuff.h index 4f2efe87..ef6bc73f 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -92,10 +92,10 @@ static bool eqShape(B w, B x) { assert(isArr(w)); assert(isArr(x)); B bit_sel(B b, B e0, bool h0, B e1, bool h1); // consumes b; h0/h1 can be true if unknown -static B m_v1(B a ); // consumes all -static B m_v2(B a, B b ); // consumes all -static B m_v3(B a, B b, B c ); // consumes all -static B m_v4(B a, B b, B c, B d); // consumes all +static B m_hVec1(B a ); // consumes all +static B m_hVec2(B a, B b ); // consumes all +static B m_hVec3(B a, B b, B c ); // consumes all +static B m_hVec4(B a, B b, B c, B d); // consumes all B m_vec1(B a); // complete fills B m_vec2(B a, B b); // incomplete fills diff --git a/src/load.c b/src/load.c index 80916bae..5860e98d 100644 --- a/src/load.c +++ b/src/load.c @@ -186,7 +186,7 @@ NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // con csc = csc->psc; depth++; } - Block* r = load_compObj(c2(load_comp, m_v4(incG(load_rtObj), incG(bi_sys), vName, vDepth), inc(str)), str, path, sc); + Block* r = load_compObj(c2(load_comp, m_hVec4(incG(load_rtObj), incG(bi_sys), vName, vDepth), inc(str)), str, path, sc); dec(path); dec(args); comp_currPath = prevPath; comp_currArgs = prevArgs; @@ -208,10 +208,10 @@ void bqn_setComp(B comp) { // consumes; doesn't unload old comp, but whatever static NOINLINE B m_lvB_0( ) { return emptyHVec(); } -static NOINLINE B m_lvB_1(B a ) { return m_v1(a); } -static NOINLINE B m_lvB_2(B a, B b ) { return m_v2(a,b); } -static NOINLINE B m_lvB_3(B a, B b, B c ) { return m_v3(a,b,c); } -static NOINLINE B m_lvB_4(B a, B b, B c, B d) { return m_v4(a,b,c,d); } +static NOINLINE B m_lvB_1(B a ) { return m_hVec1(a); } +static NOINLINE B m_lvB_2(B a, B b ) { return m_hVec2(a,b); } +static NOINLINE B m_lvB_3(B a, B b, B c ) { return m_hVec3(a,b,c); } +static NOINLINE B m_lvB_4(B a, B b, B c, B d) { return m_hVec4(a,b,c,d); } static NOINLINE B m_lvi32_0( ) { return emptyIVec(); } static NOINLINE B m_lvi32_1(i32 a ) { i32* rp; B r = m_i32arrv(&rp,1); rp[0]=a; return r; } static NOINLINE B m_lvi32_2(i32 a, i32 b ) { i32* rp; B r = m_i32arrv(&rp,2); rp[0]=a; rp[1]=b; return r; } @@ -312,9 +312,9 @@ void load_init() { // very last init function dec(rtObjRaw); B* runtime = runtimeH.a; B rtObj = runtimeH.b; - dec(c1(rtFinish, m_v2(incG(bi_decp), incG(bi_primInd)))); dec(rtFinish); + dec(c1(rtFinish, m_hVec2(incG(bi_decp), incG(bi_primInd)))); dec(rtFinish); load_rtObj = FAKE_RUNTIME? frtObj : rtObj; - load_compArg = m_v2(load_rtObj, incG(bi_sys)); gc_add(FAKE_RUNTIME? rtObj : frtObj); + load_compArg = m_hVec2(load_rtObj, incG(bi_sys)); gc_add(FAKE_RUNTIME? rtObj : frtObj); gc_add(load_compArg); #else B* runtime = fruntime; diff --git a/src/vm.c b/src/vm.c index 2a38e503..13d23fab 100644 --- a/src/vm.c +++ b/src/vm.c @@ -913,7 +913,7 @@ void funBl_print(B x) { printf("{function"" block}"); } void md1Bl_print(B x) { printf("{1-modifier block}"); } void md2Bl_print(B x) { printf("{2-modifier block}"); } -B block_decompose(B x) { return m_v2(m_i32(1), x); } +B block_decompose(B x) { return m_hVec2(m_i32(1), x); } static usz pageSizeV; usz getPageSize() {