fix REPL top-level errors

This commit is contained in:
dzaima 2021-05-28 01:19:22 +03:00
parent 345a0bfc8b
commit ed46ec7a44
2 changed files with 6 additions and 3 deletions

View File

@ -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);

View File

@ -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[];
};