From b32074f4d1db87a5a014363d6d8fe7c2e5e7d8a8 Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 30 Jun 2021 22:54:33 +0300 Subject: [PATCH] support nested compilation --- src/core/stuff.h | 2 +- src/load.c | 29 +++++++++++++++++------------ src/vm.c | 2 +- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/core/stuff.h b/src/core/stuff.h index fa528b5a..68940cda 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -258,7 +258,7 @@ static inline void onFree(Value* x) { } -extern _Thread_local i64 comp_envPos; +extern _Thread_local i64 comp_currEnvPos; extern _Thread_local B comp_currPath; extern _Thread_local B comp_currArgs; extern _Thread_local B comp_currSrc; diff --git a/src/load.c b/src/load.c index 5253a442..fe626409 100644 --- a/src/load.c +++ b/src/load.c @@ -53,7 +53,7 @@ B r1Objs[rtLen]; B rtWrap_wrap(B x); // consumes -_Thread_local i64 comp_envPos; +_Thread_local i64 comp_currEnvPos; _Thread_local B comp_currPath; _Thread_local B comp_currArgs; _Thread_local B comp_currSrc; @@ -99,22 +99,24 @@ void load_gcFn() { mm_visit(comp_currArgs); mm_visit(comp_currSrc); } - NOINLINE Block* bqn_comp(B str, B path, B args) { // consumes all - comp_currPath = path; - comp_currArgs = args; - comp_currSrc = str; - comp_envPos = envCurr-envStart; + B prevPath = comp_currPath ; comp_currPath = path; + B prevArgs = comp_currArgs ; comp_currArgs = args; + B prevSrc = comp_currSrc ; comp_currSrc = str; + i64 prevEnvPos = comp_currEnvPos; comp_currEnvPos = envCurr-envStart; Block* r = load_compObj(c2(load_comp, inc(load_compArg), inc(str)), str, path, NULL); dec(path); dec(args); - comp_currPath = comp_currArgs = comp_currSrc = bi_N; + comp_currPath = prevPath; + comp_currArgs = prevArgs; + comp_currSrc = prevSrc; + comp_currEnvPos = prevEnvPos; return r; } NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // consumes str,path,args - comp_currPath = path; - comp_currArgs = args; - comp_currSrc = str; - comp_envPos = envCurr-envStart; + B prevPath = comp_currPath ; comp_currPath = path; + 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); if (repl && (!sc || sc->psc)) thrM("VM compiler: REPL mode must be used at top level scope"); @@ -136,7 +138,10 @@ NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // con } Block* r = load_compObj(c2(load_comp, m_v4(inc(load_rtObj), inc(bi_sys), vName, vDepth), inc(str)), str, path, sc); dec(path); dec(args); - comp_currPath = comp_currArgs = comp_currSrc = bi_N; + comp_currPath = prevPath; + comp_currArgs = prevArgs; + comp_currSrc = prevSrc; + comp_currEnvPos = prevEnvPos; return r; } diff --git a/src/vm.c b/src/vm.c index 0139d11b..24c8eccb 100644 --- a/src/vm.c +++ b/src/vm.c @@ -906,7 +906,7 @@ void unwindEnv(Env* envNew) { } void unwindCompiler() { #if UNWIND_COMPILER - unwindEnv(envStart+comp_envPos); + unwindEnv(envStart+comp_currEnvPos); #endif }