From c4cc861054bc4f4a3a6749d60344e3e91bed8662 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 1 Oct 2021 19:59:55 +0300 Subject: [PATCH] fix namespace assignment to special name list --- src/ns.c | 6 ++++-- src/vm.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ns.c b/src/ns.c index cb922c05..dbe7b993 100644 --- a/src/ns.c +++ b/src/ns.c @@ -9,14 +9,15 @@ void m_nsDesc(Body* body, bool imm, u8 ty, B nameList, B varIDs, B exported) { / if (ia!=a(exported)->ia) thrM("Bad namespace description information"); i32 off = (ty==0?0:ty==1?2:3) + (imm?0:3); i32 vam = ia+off; + i32 actualVam = body->varAm; // if (vam != body->varAm) thrM("Bad namespace description information"); // arg remapping makes body->varAm unrelated to named variable count - NSDesc* r = mm_alloc(fsizeof(NSDesc, expIDs, i32, vam), t_nsDesc); + NSDesc* r = mm_alloc(fsizeof(NSDesc, expIDs, i32, actualVam), t_nsDesc); r->nameList = nameList; r->varAm = vam; SGetU(varIDs) SGetU(exported) - for (i32 i = 0; i < off; i++) { + for (i32 i = 0; i < actualVam; i++) { body->varIDs[i] = -1; r ->expIDs[i] = -1; } @@ -42,6 +43,7 @@ B ns_getU(B ns, B cNL, i32 nameID) { VTY(ns, t_ns); NS* n = c(NS, ns); NSDesc* d = n->desc; i32 dVarAm = d->varAm; + if (nameID<0) thrM("Cannot read key with special name"); assert((u64)nameID < a(cNL)->ia && nameID>=0); B dNL = d->nameList; if (cNL.u != dNL.u) { diff --git a/src/vm.c b/src/vm.c index 6aae419c..7105bbc0 100644 --- a/src/vm.c +++ b/src/vm.c @@ -276,10 +276,11 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl c = nextBC(c); } if (remapArgs) { + if (sc && depth==0) thrM("Predicates cannot be used directly in a REPL"); c = bc+idx; bool argUsed[6] = {0,0,0,0,0,0}; while (*c!=RETN & *c!=RETD) { - if (*c==VARO | *c==VARM | *c==VARU) if (c[1]==0 && c[2]