From 0b32ef96ce7b8a023e8bcd9729551042bf660d5d Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 19 Mar 2023 22:47:00 +0200 Subject: [PATCH] =?UTF-8?q?inline=20=E2=86=92=20inplace=20in=20existing-sc?= =?UTF-8?q?ope-mutating=20function=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jit/nvm_x86_64.c | 2 +- src/load.c | 2 +- src/main.c | 22 +++++++++++----------- src/vm.c | 8 ++++---- src/vm.h | 12 ++++++------ 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index 424e44e6..363f392a 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -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); diff --git a/src/load.c b/src/load.c index d3bc1cdc..d569dc90 100644 --- a/src/load.c +++ b/src/load.c @@ -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); diff --git a/src/main.c b/src/main.c index 50e0121d..2b572203 100644 --- a/src/main.c +++ b/src/main.c @@ -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); } diff --git a/src/vm.c b/src/vm.c index 3668c52d..2fcdcb66 100644 --- a/src/vm.c +++ b/src/vm.c @@ -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; } diff --git a/src/vm.h b/src/vm.h index 4615375d..959ea475 100644 --- a/src/vm.h +++ b/src/vm.h @@ -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); }