From 521abe669dda298eeabdf819531d2ef68519eed9 Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 16 Aug 2021 00:48:15 +0300 Subject: [PATCH] hopefully fix SETH refcounts --- makefile | 6 +++--- src/builtins/sfns.c | 7 +------ src/core/stuff.c | 3 +++ src/h.h | 7 +++++-- src/opt/mm_buddyTemplate.h | 8 +++++++- src/vm.c | 2 +- src/vm.h | 10 +++------- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/makefile b/makefile index 9146c82e..a5f3d758 100644 --- a/makefile +++ b/makefile @@ -23,11 +23,11 @@ c: # custom b: gen single-o3: - $(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions $(CCFLAGS) -no-pie -O3 -o BQN src/opt/single.c -lm + $(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions $(CCFLAGS) -no-pie $(f) -O3 -o BQN src/opt/single.c -lm single-o3g: - $(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions $(CCFLAGS) -no-pie -O3 -g -o BQN src/opt/single.c -lm + $(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions $(CCFLAGS) -no-pie $(f) -O3 -g -o BQN src/opt/single.c -lm single-debug: - $(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions $(CCFLAGS) -no-pie -DDEBUG -g -o BQN src/opt/single.c -lm + $(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions $(CCFLAGS) -no-pie $(f) -DDEBUG -g -o BQN src/opt/single.c -lm single-c: $(CC) -std=gnu11 -Wall -Wno-unused-function -fms-extensions $(CCFLAGS) -no-pie $(f) -o BQN src/opt/single.c -lm diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 7e38a23c..61999968 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -531,13 +531,8 @@ B join_c1(B t, B x) { B xf = getFillE(x); if (isAtm(xf)) { decA(xf); - if (!PROPER_FILLS) { - B xfq = getFillR(x); - bool no = noFill(xfq); - decR(xfq); - if (no) return x; - } dec(x); + if (!PROPER_FILLS) return emptyHVec(); thrM("∾: Empty vector 𝕩 cannot have an atom fill element"); } dec(x); diff --git a/src/core/stuff.c b/src/core/stuff.c index 89f2af55..a2cecb24 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -567,6 +567,9 @@ NOINLINE void printAllocStats() { #ifdef DEBUG NOINLINE Value* VALIDATEP(Value* x) { if (x->refc<=0 || (x->refc>>28) == 'a' || x->type==t_empty) { + #ifdef OBJ_COUNTER + printf("Object ID: "N64u"\n", x->uid); + #endif printf("bad refcount for type %d: %d\nattempting to print: ", x->type, x->refc); fflush(stdout); print(tag(x,OBJ_TAG)); putchar('\n'); fflush(stdout); err(""); diff --git a/src/h.h b/src/h.h index 0ee360f8..d4f78cc7 100644 --- a/src/h.h +++ b/src/h.h @@ -76,8 +76,8 @@ #define PROPER_FILLS (EACH_FILLS&SFNS_FILLS) #else #undef EACH_FILLS - #define EACH_FILLS false - #define PROPER_FILLS false + #define EACH_FILLS 0 + #define PROPER_FILLS 0 #endif #if defined(RT_PERF) || defined(RT_VERIFY) #define RT_WRAP @@ -85,6 +85,9 @@ #error "can't have both RT_PERF and RT_VERIFY" #endif #endif +#if defined(OBJ_TRACK) + #define OBJ_COUNTER 1 +#endif #define i8 int8_t #define u8 uint8_t diff --git a/src/opt/mm_buddyTemplate.h b/src/opt/mm_buddyTemplate.h index 0e1c9987..ca20f931 100644 --- a/src/opt/mm_buddyTemplate.h +++ b/src/opt/mm_buddyTemplate.h @@ -38,7 +38,13 @@ static void* BN(allocL)(i64 bucket, u8 type) { while(suid = currObjCounter++; + x->uid = currObjCounter++; + #ifdef OBJ_TRACK + if (x->uid == OBJ_TRACK) { + printf("Tracked object "N64u" created at:\n", (u64)OBJ_TRACK); + vm_pstLive(); + } + #endif #endif return x; } diff --git a/src/vm.c b/src/vm.c index a0596703..ba96d134 100644 --- a/src/vm.c +++ b/src/vm.c @@ -662,7 +662,7 @@ B evalBC(Block* bl, Body* b, Scope* sc) { // doesn't consume break; } case SETH: { P(s) P(x) GS_UPD; POS_UPD; - bool ok = v_seth(pscs, s, x); + bool ok = v_seth(pscs, s, x); dec(x); dec(s); if (!ok) thrM("VM: Header fallback NYI"); break; } diff --git a/src/vm.h b/src/vm.h index 7f77312b..3a4c260f 100644 --- a/src/vm.h +++ b/src/vm.h @@ -209,12 +209,8 @@ static inline void v_set(Scope* pscs[], B s, B x, bool upd) { // doesn't consume else v_setI(pscs[(u16)(s.u>>32)], (u32)s.u, inc(x), upd); } -static inline bool v_seth(Scope* pscs[], B s, B x) { // consumes both; s cannot contain extended variables - if (RARE(!isVar(s))) { - bool r = v_sethR(pscs, s, x); - dec(s); dec(x); - return r; - } - v_setI(pscs[(u16)(s.u>>32)], (u32)s.u, x, false); +static inline bool v_seth(Scope* pscs[], B s, B x) { // doesn't consume; s cannot contain extended variables + if (RARE(!isVar(s))) return v_sethR(pscs, s, x); + v_setI(pscs[(u16)(s.u>>32)], (u32)s.u, inc(x), false); return true; }