From bebf1e4255b2d2ac2e9eecd11a38774f40e1ebe9 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 25 Dec 2021 17:58:25 +0200 Subject: [PATCH] error location for autogenerated FAIL bodies and also more )gc things --- src/main.c | 25 +++++++++++++++++++++++-- src/vm.c | 16 ++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index 1a07e3b3..6bb30e91 100644 --- a/src/main.c +++ b/src/main.c @@ -218,8 +218,29 @@ int main(int argc, char* argv[]) { goto cont; } else if (isCmd(cmdS, &cmdE, "gc ")) { #if ENABLE_GC - if (gc_depth!=0) printf("Cannot GC currently\n"); - else gc_forceGC(); + if (0==*cmdE) { + if (gc_depth!=0) { + printf("GC is disabled, but forcibly GCing anyway\n"); + gc_enable(); + gc_forceGC(); + gc_disable(); + } else { + gc_forceGC(); + } + } else if (strcmp(cmdE,"on")==0) { + if (gc_depth==0) printf("GC already on\n"); + else if (gc_depth>1) printf("GC cannot be enabled\n"); + else { + gc_enable(); + printf("GC enabled\n"); + } + } else if (strcmp(cmdE,"off")==0) { + if (gc_depth>0) printf("GC already off\n"); + else { + gc_disable(); + printf("GC disabled\n"); + } + } else printf("Unknown GC command\n"); #else printf("Macro ENABLE_GC was false at compile-time, cannot GC\n"); #endif diff --git a/src/vm.c b/src/vm.c index bf59b3b6..a29411c2 100644 --- a/src/vm.c +++ b/src/vm.c @@ -133,7 +133,7 @@ typedef struct NextRequest { u32 pos2; // ↑ for dyadic; U32_MAX if not wanted } NextRequest; -Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBlocks, B allBodies, B nameList, Scope* sc, i32 depth) { +Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBlocks, B allBodies, B nameList, Scope* sc, i32 depth, i32 myPos) { usz blIA = a(block)->ia; if (blIA!=3) thrM("VM compiler: Bad block info size"); SGetU(block) @@ -149,7 +149,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl // failed match body TSADD(newBC, FAIL); - TSADD(mapBC, 0); + TSADD(mapBC, myPos); Body* failBody = m_body(6, 0, 1, 0); failBody->nsDesc = NULL; TSADD(bodies, failBody); @@ -303,7 +303,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl if ((u32)id >= a(allBlocks)->ia) thrM("VM compiler: DFND index out-of-bounds"); if (bDone[id]) thrM("VM compiler: DFND of the same block in multiple places"); bDone[id] = true; - Block* bl = compileBlock(IGetU(allBlocks,id), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, depth+1); + Block* bl = compileBlock(IGetU(allBlocks,id), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, depth+1, c-bc); TSADD(newBC, bl->ty==0? DFND0 : bl->ty==1? DFND1 : DFND2); A64((u64)bl); TSADD(usedBlocks, bl); @@ -459,7 +459,7 @@ NOINLINE Block* compile(B bcq, B objs, B allBlocks, B allBodies, B indices, B to } TALLOC(bool,bDone,bIA); for (usz i = 0; i < bIA; i++) bDone[i] = false; - Block* ret = compileBlock(IGetU(allBlocks, 0), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, 0); + Block* ret = compileBlock(IGetU(allBlocks, 0), comp, bDone, bc, bcIA, allBlocks, allBodies, nameList, sc, 0, 0); TFREE(bDone); ptr_dec(comp); dec(allBlocks); dec(allBodies); dec(tokenInfo); return ret; @@ -738,20 +738,20 @@ B evalBC(Block* bl, Body* b, Scope* sc) { // doesn't consume case SETH1:{ P(s) P(x) GS_UPD; POS_UPD; u64 v1 = L64; bool ok = v_seth(pscs, s, x); dec(x); dec(s); - if (!ok) { GS_UPD; return gotoNextBody(bl, sc, (Body*)v1); } + if (!ok) { return gotoNextBody(bl, sc, (Body*)v1); } break; } case SETH2:{ P(s) P(x) GS_UPD; POS_UPD; u64 v1 = L64; u64 v2 = L64; bool ok = v_seth(pscs, s, x); dec(x); dec(s); - if (!ok) { GS_UPD; return gotoNextBody(bl, sc, (Body*)(q_N(sc->vars[2])? v1 : v2)); } + if (!ok) { return gotoNextBody(bl, sc, (Body*)(q_N(sc->vars[2])? v1 : v2)); } break; } case PRED1:{ P(x) GS_UPD; POS_UPD; u64 v1 = L64; - if (!o2b(x)) { GS_UPD; return gotoNextBody(bl, sc, (Body*)v1); } + if (!o2b(x)) { return gotoNextBody(bl, sc, (Body*)v1); } break; } case PRED2:{ P(x) GS_UPD; POS_UPD; u64 v1 = L64; u64 v2 = L64; - if (!o2b(x)) { GS_UPD; return gotoNextBody(bl, sc, (Body*)(q_N(sc->vars[2])? v1 : v2)); } + if (!o2b(x)) { return gotoNextBody(bl, sc, (Body*)(q_N(sc->vars[2])? v1 : v2)); } break; }