inline → inplace in existing-scope-mutating function names

This commit is contained in:
dzaima 2023-03-19 22:47:00 +02:00
parent d157fac17f
commit 0b32ef96ce
5 changed files with 23 additions and 23 deletions

View File

@ -196,7 +196,7 @@ FORCE_INLINE B gotoNextBodyJIT(Scope* sc, Body* body) {
u64 ga = blockGivenVars(bl);
for (u64 i = 0; i < ga; i++) inc(sc->vars[i]);
Scope* nsc = m_scope(body, sc->psc, body->varAm, ga, sc->vars);
return execBodyInlineI(body, nsc, bl);
return execBodyInplaceI(body, nsc, bl);
}
INS B i_SETH1(B s, B x, Scope** pscs, u32* bc, Body* v1) { POS_UPD;
bool ok = v_seth(pscs, s, x); dec(x); dec(s);

View File

@ -340,7 +340,7 @@ B rebqn_exec(B str, B path, B args, B o) {
comp_currRe = prevRe;
ptr_dec(sc->body);
sc->body = ptr_inc(block->bodies[0]);
res = execBlockInline(block, sc);
res = execBlockInplace(block, sc);
} else {
B rtsys = m_hVec2(inc(op[3]), incG(bi_sys));
block = bqn_compc(str, path, args, op[2], rtsys);

View File

@ -548,11 +548,11 @@ static NOINLINE i64 readInt(char** p) {
#endif
static NOINLINE B gsc_exec_inline(B src, B path, B args) {
static NOINLINE B gsc_exec_inplace(B src, B path, B args) {
Block* block = bqn_compSc(src, path, args, gsc, true);
ptr_dec(gsc->body); // redirect new errors to the newly executed code; initial scope had 0 vars, so this is safe
gsc->body = ptr_inc(block->bodies[0]);
B r = execBlockInline(block, gsc);
B r = execBlockInplace(block, gsc);
ptr_dec(block);
return r;
}
@ -780,12 +780,12 @@ void cbqn_runLine0(char* ln, i64 read) {
f64 t;
if (time==-1) {
u64 sns = nsTime();
res = execBlockInline(block, gsc);
res = execBlockInplace(block, gsc);
u64 ens = nsTime();
t = ens-sns;
} else {
u64 sns = nsTime();
for (i64 i = 0; i < time; i++) dec(execBlockInline(block, gsc));
for (i64 i = 0; i < time; i++) dec(execBlockInplace(block, gsc));
u64 ens = nsTime();
t = (ens-sns)*1.0 / time;
res = m_c32(0);
@ -797,13 +797,13 @@ void cbqn_runLine0(char* ln, i64 read) {
} else if (profile>0) {
if (CATCH) { profiler_stop(); profiler_free(); rethrow(); }
if (profiler_alloc() && profiler_start(profile)) {
res = execBlockInline(block, gsc);
res = execBlockInplace(block, gsc);
profiler_stop();
profiler_displayResults();
profiler_free();
}
popCatch();
} else res = execBlockInline(block, gsc);
} else res = execBlockInplace(block, gsc);
ptr_dec(block);
if (output) {
@ -913,12 +913,12 @@ 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(utf8Decode0(argv[i++]), m_c8vec_0("(-e)"), emptySVec()));
dec(gsc_exec_inplace(utf8Decode0(argv[i++]), m_c8vec_0("(-e)"), emptySVec()));
break;
}
case 'L': { repl_init(); break; } // just initialize. mostly for perf testing
case 'p': { repl_init(); REQARG(p);
B r = gsc_exec_inline(utf8Decode0(argv[i++]), m_c8vec_0("(-p)"), emptySVec());
B r = gsc_exec_inplace(utf8Decode0(argv[i++]), m_c8vec_0("(-p)"), emptySVec());
if (FORMATTER) { r = bqn_fmt(r); printsB(r); }
else { printI(r); }
dec(r);
@ -926,7 +926,7 @@ int main(int argc, char* argv[]) {
break;
}
case 'o': { repl_init(); REQARG(o);
B r = gsc_exec_inline(utf8Decode0(argv[i++]), m_c8vec_0("(-o)"), emptySVec());
B r = gsc_exec_inplace(utf8Decode0(argv[i++]), m_c8vec_0("(-o)"), emptySVec());
printsB(r); dec(r);
printf("\n");
break;
@ -950,7 +950,7 @@ int main(int argc, char* argv[]) {
usz ia = IA(lines);
SGet(lines)
for (u64 i = 0; i < ia; i++) {
dec(gsc_exec_inline(Get(lines, i), incG(replPath), emptySVec()));
dec(gsc_exec_inplace(Get(lines, i), incG(replPath), emptySVec()));
}
break;
}
@ -978,7 +978,7 @@ int main(int argc, char* argv[]) {
B execRes;
if (execStdin) {
execRes = gsc_exec_inline(utf8DecodeA(stream_bytes(stdin)), m_c8vec_0("(-)"), args);
execRes = gsc_exec_inplace(utf8DecodeA(stream_bytes(stdin)), m_c8vec_0("(-)"), args);
} else {
execRes = bqn_execFile(src, args);
}

View File

@ -676,7 +676,7 @@ FORCE_INLINE B gotoNextBody(Block* bl, Scope* sc, Body* body) {
assert(sc->psc!=NULL);
Scope* nsc = m_scopeI(body, sc->psc, body->varAm, ga, sc->vars, true);
scope_dec(sc);
return execBodyInlineI(body, nsc, bl);
return execBodyInplaceI(body, nsc, bl);
}
#ifdef DEBUG_VM
@ -957,10 +957,10 @@ NOINLINE Scope* m_scope(Body* body, Scope* psc, u16 varAm, i32 initVarAm, B* ini
return m_scopeI(body, psc, varAm, initVarAm, initVars, false);
}
B execBlockInlineImpl(Body* body, Scope* sc, Block* block) { return execBodyInlineI(block->bodies[0], sc, block); }
B execBlockInplaceImpl(Body* body, Scope* sc, Block* block) { return execBodyInplaceI(block->bodies[0], sc, block); }
#if JIT_START != -1
B mnvmExecBodyInline(Body* body, Scope* sc) {
B mnvmExecBodyInplace(Body* body, Scope* sc) {
Nvm_res r = m_nvm(body);
body->nvm = r.p;
body->nvmRefs = r.refs;
@ -1000,7 +1000,7 @@ FORCE_INLINE B execBlock(Block* block, Body* body, Scope* psc, i32 ga, B* svar)
assert(varAm>=ga);
assert(ga == blockGivenVars(block));
Scope* sc = m_scopeI(body, psc, varAm, ga, svar, true);
B r = execBodyInlineI(body, sc, block);
B r = execBodyInplaceI(body, sc, block);
return r;
}

View File

@ -167,15 +167,15 @@ void nvm_free(u8* ptr);
B evalJIT(Body* b, Scope* sc, u8* ptr);
B evalBC(Body* b, Scope* sc, Block* bl);
B execBlockInlineImpl(Body* body, Scope* sc, Block* block);
static B execBlockInline(Block* block, Scope* sc) { // doesn't consume; executes bytecode of the monadic body directly in the scope
return execBlockInlineImpl(block->bodies[0], ptr_inc(sc), block);
B execBlockInplaceImpl(Body* body, Scope* sc, Block* block);
static B execBlockInplace(Block* block, Scope* sc) { // doesn't consume; executes bytecode of the monadic body directly in the scope
return execBlockInplaceImpl(block->bodies[0], ptr_inc(sc), block);
}
#if JIT_START != -1
NOINLINE B mnvmExecBodyInline(Body* body, Scope* sc);
NOINLINE B mnvmExecBodyInplace(Body* body, Scope* sc);
#endif
FORCE_INLINE B execBodyInlineI(Body* body, Scope* sc, Block* block) { // consumes sc, unlike execBlockInline
FORCE_INLINE B execBodyInplaceI(Body* body, Scope* sc, Block* block) { // consumes sc, unlike execBlockInplace
#if JIT_START != -1
if (LIKELY(body->nvm != NULL)) return evalJIT(body, sc, body->nvm);
bool jit = true;
@ -183,7 +183,7 @@ FORCE_INLINE B execBodyInlineI(Body* body, Scope* sc, Block* block) { // consume
jit = body->callCount++ >= JIT_START;
#endif
// jit = body->bc[2]==m_f64(123456).u>>32; // enable JIT for blocks starting with `123456⋄`
if (jit) return mnvmExecBodyInline(body, sc);
if (jit) return mnvmExecBodyInplace(body, sc);
#endif
return evalBC(body, sc, block);
}