skip value checking for builtin loading
perf is reporting an 0.15% increase in instruction count (what?), but that's not gonna stop me
This commit is contained in:
parent
f75efbcc26
commit
7999683edf
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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++) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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));
|
||||
|
||||
6
src/h.h
6
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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
12
src/main.c
12
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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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));
|
||||
|
||||
4
src/vm.c
4
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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user