From ed46ec7a446aca00254c60271bb7de818b47a0f2 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 28 May 2021 01:19:22 +0300 Subject: [PATCH] fix REPL top-level errors --- src/main.c | 5 ++++- src/vm.h | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 84e8a79f..252c2e07 100644 --- a/src/main.c +++ b/src/main.c @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) { if (startREPL) { INIT; B replPath = m_str32(U"REPL"); gc_add(replPath); - Block* gscInit = bqn_comp(m_str32(U"1"), inc(replPath), m_f64(0)); + Block* gscInit = bqn_comp(m_str32(U"\"(REPL initializer)\""), inc(replPath), m_f64(0)); Scope* gsc = m_scope(gscInit->body, NULL, 0); gc_add(tag(gsc,OBJ_TAG)); ptr_dec(gscInit); while (CATCH) { @@ -147,6 +147,9 @@ int main(int argc, char* argv[]) { Block* block = bqn_compSc(fromUTF8(ln, strlen(ln)), inc(replPath), inc(bi_emptyHVec), gsc, true); free(ln); + ptr_dec(gsc->body); ptr_inc(block->body); // redirect new errors to the newly executed code; initial scope had 0 vars, so this is safe + gsc->body = block->body; + #ifdef TIME u64 sns = nsTime(); B res = evalBC(block->body, gsc); diff --git a/src/vm.h b/src/vm.h index 7f7f3a6e..bf4d4ba8 100644 --- a/src/vm.h +++ b/src/vm.h @@ -52,9 +52,9 @@ struct ScopeExt { struct Scope { struct Value; Scope* psc; - Body* body; + Body* body; // last place where code was executed in this scope; also used for variable name resolution, so can only safely be replaced if varAm==0 u16 varAm; - ScopeExt* ext; + ScopeExt* ext; // will probably be NULL B vars[]; };