From 7999683edfc8e4faf592258ce9ef6f8ed4591874 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 3 Jul 2021 02:38:00 +0300 Subject: [PATCH] skip value checking for builtin loading perf is reporting an 0.15% increase in instruction count (what?), but that's not gonna stop me --- src/builtins/arithd.c | 2 +- src/builtins/arithm.c | 2 +- src/builtins/fns.c | 8 ++++---- src/builtins/grade.h | 2 +- src/builtins/internal.c | 8 ++++---- src/builtins/sysfn.c | 8 ++++---- src/core/c32arr.c | 4 +++- src/core/harr.c | 3 +-- src/core/i32arr.c | 3 +-- src/core/stuff.c | 2 +- src/h.h | 6 +++++- src/jit/nvm_x86_64.c | 6 +++--- src/load.c | 4 ++-- src/main.c | 12 ++++++------ src/nfns.c | 2 +- src/utils/file.c | 2 +- src/vm.c | 4 ++-- 17 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/builtins/arithd.c b/src/builtins/arithd.c index 437ff80d..1a4d0361 100644 --- a/src/builtins/arithd.c +++ b/src/builtins/arithd.c @@ -9,7 +9,7 @@ usz ia = a(x)->ia; if (ia==0) { if (rnk(x)>1) return x; - dec(x); return inc(bi_emptyIVec); + dec(x); return emptyIVec(); } if (xp[0] != (i32)xp[0]) return x; i32* rp; B r = m_i32arrc(&rp, x); diff --git a/src/builtins/arithm.c b/src/builtins/arithm.c index 39bd8f07..9d5275df 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -39,7 +39,7 @@ static B mathNS; B getMathNS() { if (mathNS.u == 0) { #define F(X,N) m_nfn(registerNFn(m_str32(U"•math." N), X##_c1, c2_invalid),m_f64(0)), - B fn = bqn_exec(m_str32(U"{⟨ Sin, Cos, Tan, Asin, Acos, Atan ⟩⇐𝕩}"), inc(bi_emptyCVec), inc(bi_emptySVec)); + B fn = bqn_exec(m_str32(U"{⟨ Sin, Cos, Tan, Asin, Acos, Atan ⟩⇐𝕩}"), emptyCVec(), emptySVec()); B arg = m_caB(6, (B[]){F(sin,U"Sin")F(cos,U"Cos")F(tan,U"Tan")F(asin,U"Asin")F(acos,U"Acos")F(atan,U"Atan")}); #undef F mathNS = c1(fn,arg); diff --git a/src/builtins/fns.c b/src/builtins/fns.c index 1f5baa60..c34152bb 100644 --- a/src/builtins/fns.c +++ b/src/builtins/fns.c @@ -34,7 +34,7 @@ B ud_c1(B t, B x) { for (usz i = 0; i < xu; i++) rp[i] = i; return r; } - if (xu==0) { B r = bi_emptyIVec; ptr_inc(v(r)); return r; } + if (xu==0) return emptyIVec(); i32* rp; B r = m_i32arrv(&rp, xu); for (usz i = 0; i < xu; i++) rp[i] = i; return r; @@ -124,7 +124,7 @@ B fne_c1(B t, B x) { return r; } else { dec(x); - return inc(bi_emptyIVec); + return emptyIVec(); } } B feq_c1(B t, B x) { @@ -150,7 +150,7 @@ extern B rt_indexOf; B indexOf_c1(B t, B x) { if (isAtm(x)) thrM("⊐: 𝕩 cannot have rank 0"); usz xia = a(x)->ia; - if (xia==0) { dec(x); return inc(bi_emptyIVec); } + if (xia==0) { dec(x); return emptyIVec(); } if (rnk(x)==1 && TI(x).elType==el_i32) { i32* xp = i32any_ptr(x); i32 min=I32_MAX, max=I32_MIN; @@ -293,7 +293,7 @@ B find_c1(B t, B x) { B xf = getFillQ(x); if (rnk(x)!=1) return c1(rt_find, x); - B r = inc(bi_emptyHVec); + B r = emptyHVec(); H_Sb* set = m_Sb(64); BS2B xgetU = TI(x).getU; for (usz i = 0; i < xia; i++) { diff --git a/src/builtins/grade.h b/src/builtins/grade.h index 6416bb1e..4cd7d572 100644 --- a/src/builtins/grade.h +++ b/src/builtins/grade.h @@ -15,7 +15,7 @@ B GRADE_CAT(c1)(B t, B x) { if (rnk(x)>1) x = toCells(x); usz ia = a(x)->ia; if (ia>I32_MAX) thrM(GRADE_CHR": Argument too large"); - if (ia==0) { dec(x); return inc(bi_emptyIVec); } + if (ia==0) { dec(x); return emptyIVec(); } i32* rp; B r = m_i32arrv(&rp, ia); if (TI(x).elType==el_i32) { diff --git a/src/builtins/internal.c b/src/builtins/internal.c index 5a1f3187..d4a79f19 100644 --- a/src/builtins/internal.c +++ b/src/builtins/internal.c @@ -34,7 +34,7 @@ B isPure_c1(B t, B x) { } B info_c2(B t, B w, B x) { - B s = inc(bi_emptyCVec); + B s = emptyCVec(); i32 m = o2i(w); if (isVal(x)) { if (m) AFMT("%xl: ", x.u); @@ -113,7 +113,7 @@ B listVariations_c2(B t, B w, B x) { } } } else ai32=af64=false; - B r = inc(bi_emptyHVec); + B r = emptyHVec(); if(ai32) { r=vec_add(r,inc(v_Ai32)); r=vec_add(r,inc(v_Si32)); if(c_incr) {r=vec_add(r,inc(v_Ai32Inc)); r=vec_add(r,inc(v_Si32Inc)); } } if(af64) { r=vec_add(r,inc(v_Af64)); r=vec_add(r,inc(v_Sf64)); if(c_incr) {r=vec_add(r,inc(v_Af64Inc)); r=vec_add(r,inc(v_Sf64Inc)); } } if(ac32) { r=vec_add(r,inc(v_Ac32)); r=vec_add(r,inc(v_Sc32)); if(c_incr) {r=vec_add(r,inc(v_Ac32Inc)); r=vec_add(r,inc(v_Sc32Inc)); } } @@ -198,7 +198,7 @@ B variation_c2(B t, B w, B x) { } if (u32_get(&wp, wpE, U"Inc")) { if (!variation_refs.u) { - variation_refs = inc(bi_emptyHVec); + variation_refs = emptyHVec(); } variation_refs = vec_add(variation_refs, inc(res)); } @@ -269,7 +269,7 @@ B getInternalNS() { listVariations_def = m_str32(U"if"); gc_addFn(variation_root); #define F(X) inc(bi_##X), - B fn = bqn_exec(m_str32(U"{⟨ Type, Refc, Squeeze, IsPure, Info, ListVariations, Variation, ClearRefs, Unshare⟩⇐𝕩}"), inc(bi_emptyCVec), inc(bi_emptySVec)); + B fn = bqn_exec(m_str32(U"{⟨ Type, Refc, Squeeze, IsPure, Info, ListVariations, Variation, ClearRefs, Unshare⟩⇐𝕩}"), emptyCVec(), emptySVec()); B arg = m_caB(9, (B[]){F(itype)F(refc)F(squeeze)F(isPure)F(info)F(listVariations)F(variation)F(clearRefs)F(unshare)}); #undef F internalNS = c1(fn,arg); diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 543daff5..b935ad0c 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -93,7 +93,7 @@ B grLen_c2(B t, B w, B x) { return grLen_both(o2i64u(w)-1, x); } // assumes vali B grOrd_c2(B t, B w, B x) { // assumes valid arguments usz wia = a(w)->ia; usz xia = a(x)->ia; - if (wia==0) { dec(w); dec(x); return inc(bi_emptyIVec); } + if (wia==0) { dec(w); dec(x); return emptyIVec(); } if (xia==0) { dec(w); return x; } BS2B wgetU = TI(w).getU; BS2B xgetU = TI(x).getU; @@ -236,7 +236,7 @@ B rand_range_c2(B t, B w, B x) { } static NOINLINE void rand_init() { - rand_ns = bqn_exec(m_str32(U"{a←𝕨⋄b←𝕩⋄range⇐0}"), inc(bi_emptyCVec), inc(bi_emptySVec)); gc_add(rand_ns); + rand_ns = bqn_exec(m_str32(U"{a←𝕨⋄b←𝕩⋄range⇐0}"), emptyCVec(), emptySVec()); gc_add(rand_ns); rand_rangeName = m_str32(U"range"); gc_add(rand_rangeName); rand_rangeDesc = registerNFn(m_str32(U"(rand).Range"), rand_range_c1, rand_range_c2); B tmp = c2(rand_ns, m_f64(0), m_f64(0)); @@ -296,7 +296,7 @@ B flines_c1(B d, B x) { return harr_fv(r); } static NFnDesc* importDesc; -B import_c1(B d, B x) { return bqn_execFile(path_resolve(nfn_objU(d), x), inc(bi_emptySVec)); } +B import_c1(B d, B x) { return bqn_execFile(path_resolve(nfn_objU(d), x), emptySVec()); } B import_c2(B d, B w, B x) { return bqn_execFile(path_resolve(nfn_objU(d), x), w); } static NFnDesc* listDesc; B list_c1(B d, B x) { @@ -374,5 +374,5 @@ void sysfn_init() { listDesc = registerNFn(m_str32(U"•file.List"), list_c1, c2_invalid); } void sysfnPost_init() { - file_nsGen = bqn_exec(m_str32(U"{⟨List, Bytes, Chars, Lines⟩⇐𝕩}"), inc(bi_emptyCVec), inc(bi_emptySVec)); gc_add(file_nsGen); + file_nsGen = bqn_exec(m_str32(U"{⟨List, Bytes, Chars, Lines⟩⇐𝕩}"), emptyCVec(), emptySVec()); gc_add(file_nsGen); } diff --git a/src/core/c32arr.c b/src/core/c32arr.c index e09977c7..c3b7e787 100644 --- a/src/core/c32arr.c +++ b/src/core/c32arr.c @@ -44,9 +44,11 @@ void c32arr_init() { ti[t_i32arr].arrD1 = true; ti[t_i32slice].arrD1 = true; ti[t_c32arr].elType = el_c32; ti[t_c32slice].elType = el_c32; ti[t_c32arr].canStore = c32arr_canStore; + u32* tmp; bi_emptyCVec = m_c32arrv(&tmp, 0); gc_add(bi_emptyCVec); + Arr* emptySVec = m_fillarrp(0); arr_shVec(emptySVec, 0); - fillarr_setFill(emptySVec, inc(bi_emptyCVec)); + fillarr_setFill(emptySVec, emptyCVec()); bi_emptySVec = taga(emptySVec); gc_add(bi_emptySVec); } diff --git a/src/core/harr.c b/src/core/harr.c index c18ca4b9..b0a918ba 100644 --- a/src/core/harr.c +++ b/src/core/harr.c @@ -154,6 +154,5 @@ void harr_init() { ti[t_harr].print = arr_print; ti[t_hslice].print = arr_print; ti[t_harrPartial].print = harrP_print; ti[t_harr].isArr = true; ti[t_hslice].isArr = true; ti[t_harr].canStore = harr_canStore; - bi_emptyHVec = m_harrUv(0).b; - gc_add(bi_emptyHVec); + bi_emptyHVec = m_harrUv(0).b; gc_add(bi_emptyHVec); } diff --git a/src/core/i32arr.c b/src/core/i32arr.c index b7ec2611..5bba6323 100644 --- a/src/core/i32arr.c +++ b/src/core/i32arr.c @@ -31,6 +31,5 @@ void i32arr_init() { ti[t_i32arr].arrD1 = true; ti[t_i32slice].arrD1 = true; ti[t_i32arr].elType = el_i32; ti[t_i32slice].elType = el_i32; ti[t_i32arr].canStore = i32arr_canStore; - i32* tmp; bi_emptyIVec = m_i32arrv(&tmp, 0); - gc_add(bi_emptyIVec); + i32* tmp; bi_emptyIVec = m_i32arrv(&tmp, 0); gc_add(bi_emptyIVec); } diff --git a/src/core/stuff.c b/src/core/stuff.c index daeb79ec..aa56d331 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -11,7 +11,7 @@ NORETURN NOINLINE void err(char* s) { exit(1); } -B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; // TODO add some way to get inc(these) without going through the tagging mess +B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; NOINLINE TStack* ts_e(TStack* o, u32 elsz, u64 am) { u64 size = o->size; u64 alsz = mm_round(fsizeof(TStack, data, u8, (size+am)*elsz)); diff --git a/src/h.h b/src/h.h index 4a313276..ad190855 100644 --- a/src/h.h +++ b/src/h.h @@ -231,6 +231,10 @@ static const B bi_badHdr = b((u64)0x7FF2000000000002ull); // tag(2, TAG_TAG); static const B bi_optOut = b((u64)0x7FF2000000000003ull); // tag(3, TAG_TAG); static const B bi_noFill = b((u64)0x7FF2000000000005ull); // tag(5, TAG_TAG); extern B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; +#define emptyHVec() ({ B t = bi_emptyHVec; ptr_inc(v(t)); t; }) +#define emptyIVec() ({ B t = bi_emptyIVec; ptr_inc(v(t)); t; }) +#define emptyCVec() ({ B t = bi_emptyCVec; ptr_inc(v(t)); t; }) +#define emptySVec() ({ B t = bi_emptySVec; ptr_inc(v(t)); t; }) static void dec(B x); static B inc(B x); static void ptr_dec(void* x); @@ -256,7 +260,7 @@ B bqn_repr(B x); // consumes NOINLINE NORETURN void thr(B b); NOINLINE NORETURN void thrM(char* s); -#define thrF(...) thr(append_fmt(inc(bi_emptyCVec), __VA_ARGS__)) +#define thrF(...) thr(append_fmt(emptyCVec(), __VA_ARGS__)) NOINLINE NORETURN void thrOOM(); jmp_buf* prepareCatch(); #if CATCH_ERRORS diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index f4032319..6fea660c 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -77,7 +77,7 @@ INS B i_FN2Oi(B w, B x, BB2B fm, BBB2B fd, u32* bc) { POS_UPD; else return isNothing(w)? fm(b((u64)0), x) : fd(b((u64)0), w, x); } INS B i_ARR_0() { // TODO combine with ADDI - return inc(bi_emptyHVec); + return emptyHVec(); } INS B i_ARR_p(B el0, i64 sz, B* cStack) { assert(sz>0); HArr_p r = m_harrUv(sz); // can't use harrs as gStack isn't updated @@ -314,7 +314,7 @@ static OptRes opt(u32* bc0) { TSALLOC(u32, rbc, TSSIZE(actions)); TSALLOC(u32, roff, TSSIZE(actions)); - B refs = inc(bi_emptyHVec); + B refs = emptyHVec(); bc = bc0; u64 tpos = 0, dpos = 0; while (true) { @@ -403,7 +403,7 @@ static u32 readBytes4(u8* d) { char off[20]; snprintf(off, 20, "%p", p); B o = m_str8l(off); file_wChars(m_str32(U"asm_off"), o); dec(o); - B s = inc(bi_emptyCVec); + B s = emptyCVec(); #define F(X) AFMT("s/%p$/%p # i_" #X "/;", i_##X, i_##X); F(POPS) F(INC) F(FN1C) F(FN1O) F(FN2C) F(FN2O) F(FN1Oi) F(FN2Oi) F(ARR_0) F(ARR_p) F(DFND_0) F(DFND_1) F(DFND_2) F(OP1D) F(OP2D) F(OP2H) F(TR2D) F(TR3D) F(TR3O) F(LOCU) F(EXTO) F(EXTU) F(SETN) F(SETU) F(SETM) F(FLDO) F(NSPM) F(RETD) F(SETNi) F(SETUi) F(SETMi) #undef F diff --git a/src/load.c b/src/load.c index 91a06c8b..7bac826c 100644 --- a/src/load.c +++ b/src/load.c @@ -117,8 +117,8 @@ NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // con B prevArgs = comp_currArgs ; comp_currArgs = args; B prevSrc = comp_currSrc ; comp_currSrc = str; i64 prevEnvPos = comp_currEnvPos; comp_currEnvPos = envCurr-envStart; - B vName = inc(bi_emptyHVec); - B vDepth = inc(bi_emptyIVec); + B vName = emptyHVec(); + B vDepth = emptyIVec(); if (repl && (!sc || sc->psc)) thrM("VM compiler: REPL mode must be used at top level scope"); i32 depth = repl? -1 : 0; Scope* csc = sc; diff --git a/src/main.c b/src/main.c index fef254ba..c7e70e9f 100644 --- a/src/main.c +++ b/src/main.c @@ -9,7 +9,7 @@ static bool init = false; static void repl_init() { if (init) return; cbqn_init(); - replPath = inc(bi_emptyCVec); gc_add(replPath); + replPath = emptyCVec(); gc_add(replPath); Block* initBlock = bqn_comp(m_str32(U"\"(REPL initializer)\""), inc(replPath), m_f64(0)); gsc = m_scope(initBlock->body, NULL, 0, 0, NULL); gc_add(tag(gsc,OBJ_TAG)); ptr_dec(initBlock); @@ -87,17 +87,17 @@ int main(int argc, char* argv[]) { #define REQARG(X) if(*carg) { fprintf(stderr, "%s: -%s must end the option\n", argv[0], #X); exit(1); } if (i==argc) { fprintf(stderr, "%s: -%s requires an argument\n", argv[0], #X); exit(1); } case 'f': repl_init(); REQARG(f); goto execFile; case 'e': { repl_init(); REQARG(e); - dec(gsc_exec_inline(fromUTF8l(argv[i++]), m_str32(U"(-e)"), inc(bi_emptySVec))); + dec(gsc_exec_inline(fromUTF8l(argv[i++]), m_str32(U"(-e)"), emptySVec())); break; } case 'p': { repl_init(); REQARG(p); - B r = gsc_exec_inline(fromUTF8l(argv[i++]), m_str32(U"(-p)"), inc(bi_emptySVec)); + B r = gsc_exec_inline(fromUTF8l(argv[i++]), m_str32(U"(-p)"), emptySVec()); print(r); dec(r); printf("\n"); break; } case 'o': { repl_init(); REQARG(o); - B r = gsc_exec_inline(fromUTF8l(argv[i++]), m_str32(U"(-o)"), inc(bi_emptySVec)); + B r = gsc_exec_inline(fromUTF8l(argv[i++]), m_str32(U"(-o)"), emptySVec()); printRaw(r); dec(r); printf("\n"); break; @@ -126,7 +126,7 @@ int main(int argc, char* argv[]) { B src = fromUTF8l(argv[i++]); B args; if (i==argc) { - args = inc(bi_emptySVec); + args = emptySVec(); } else { HArr_p ap = m_harrUv(argc-i); // eh whatever, erroring will exit anyways for (usz j = 0; j < argc-i; j++) { @@ -155,7 +155,7 @@ int main(int argc, char* argv[]) { if (!silentREPL) printf(" "); i64 read = getline(&ln, &gl, stdin); if (read<=0 || ln[0]==0 || ln[0]==10) { if(!silentREPL) putchar('\n'); break; } - Block* block = bqn_compSc(fromUTF8(ln, strlen(ln)), inc(replPath), inc(bi_emptySVec), gsc, true); + Block* block = bqn_compSc(fromUTF8(ln, strlen(ln)), inc(replPath), emptySVec(), gsc, true); free(ln); ptr_dec(gsc->body); ptr_inc(block->body); diff --git a/src/nfns.c b/src/nfns.c index 5c2c7df1..8090f293 100644 --- a/src/nfns.c +++ b/src/nfns.c @@ -46,7 +46,7 @@ void nfn_gcFn() { mm_visit(nfn_list); } void nfn_init() { - nfn_list = inc(bi_emptyHVec); + nfn_list = emptyHVec(); ti[t_nfn].free = nfn_free; ti[t_nfnDesc].free = nfnDesc_free; ti[t_nfn].visit = nfn_visit; ti[t_nfnDesc].visit = nfnDesc_visit; ti[t_nfn].print = nfn_print; ti[t_nfnDesc].print = nfnDesc_print; diff --git a/src/utils/file.c b/src/utils/file.c index e97ec584..fbef5c9d 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -114,7 +114,7 @@ void file_wBytes(B path, B x) { // consumes path B file_list(B path) { DIR* d = dir_open(path); struct dirent *c; - B res = inc(bi_emptySVec); + B res = emptySVec(); while ((c = readdir(d)) != NULL) { char* name = c->d_name; if (name[0]=='.'? !(name[1]==0 || (name[1]=='.'&&name[2]==0)) : true) res = vec_add(res, m_str8l(name)); diff --git a/src/vm.c b/src/vm.c index e3654941..acaef818 100644 --- a/src/vm.c +++ b/src/vm.c @@ -453,7 +453,7 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume case ARRO: case ARRM: { u32 sz = *bc++; if (sz==0) { - ADD(inc(bi_emptyHVec)); + ADD(emptyHVec()); } else { HArr_p r = m_harrUv(sz); bool allNum = true; @@ -871,7 +871,7 @@ NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) { // for (i32 i = 0; i < cs+start; i++) putchar(' '); // for (i32 i = cs; i < ce; i++) putchar('^'); // putchar('\n'); - B s = inc(bi_emptyCVec); + B s = emptyCVec(); printRaw(vm_fmtPoint(src, s, comp->path, cs, ce)); putchar('\n'); } else {