support nested compilation

This commit is contained in:
dzaima 2021-06-30 22:54:33 +03:00
parent 383d649480
commit b32074f4d1
3 changed files with 19 additions and 14 deletions

View File

@ -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_currPath;
extern _Thread_local B comp_currArgs; extern _Thread_local B comp_currArgs;
extern _Thread_local B comp_currSrc; extern _Thread_local B comp_currSrc;

View File

@ -53,7 +53,7 @@ B r1Objs[rtLen];
B rtWrap_wrap(B x); // consumes 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_currPath;
_Thread_local B comp_currArgs; _Thread_local B comp_currArgs;
_Thread_local B comp_currSrc; _Thread_local B comp_currSrc;
@ -99,22 +99,24 @@ void load_gcFn() {
mm_visit(comp_currArgs); mm_visit(comp_currArgs);
mm_visit(comp_currSrc); mm_visit(comp_currSrc);
} }
NOINLINE Block* bqn_comp(B str, B path, B args) { // consumes all NOINLINE Block* bqn_comp(B str, B path, B args) { // consumes all
comp_currPath = path; B prevPath = comp_currPath ; comp_currPath = path;
comp_currArgs = args; B prevArgs = comp_currArgs ; comp_currArgs = args;
comp_currSrc = str; B prevSrc = comp_currSrc ; comp_currSrc = str;
comp_envPos = envCurr-envStart; i64 prevEnvPos = comp_currEnvPos; comp_currEnvPos = envCurr-envStart;
Block* r = load_compObj(c2(load_comp, inc(load_compArg), inc(str)), str, path, NULL); Block* r = load_compObj(c2(load_comp, inc(load_compArg), inc(str)), str, path, NULL);
dec(path); dec(args); 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; return r;
} }
NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // consumes str,path,args NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // consumes str,path,args
comp_currPath = path; B prevPath = comp_currPath ; comp_currPath = path;
comp_currArgs = args; B prevArgs = comp_currArgs ; comp_currArgs = args;
comp_currSrc = str; B prevSrc = comp_currSrc ; comp_currSrc = str;
comp_envPos = envCurr-envStart; i64 prevEnvPos = comp_currEnvPos; comp_currEnvPos = envCurr-envStart;
B vName = inc(bi_emptyHVec); B vName = inc(bi_emptyHVec);
B vDepth = inc(bi_emptyIVec); B vDepth = inc(bi_emptyIVec);
if (repl && (!sc || sc->psc)) thrM("VM compiler: REPL mode must be used at top level scope"); 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); 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); 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; return r;
} }

View File

@ -906,7 +906,7 @@ void unwindEnv(Env* envNew) {
} }
void unwindCompiler() { void unwindCompiler() {
#if UNWIND_COMPILER #if UNWIND_COMPILER
unwindEnv(envStart+comp_envPos); unwindEnv(envStart+comp_currEnvPos);
#endif #endif
} }