From 1bd0e2f2e84be1ca0fa8265ccdc1566b73b59aab Mon Sep 17 00:00:00 2001 From: cassowarii <2374677+cassowarii@users.noreply.github.com> Date: Thu, 9 Jul 2026 23:51:36 -0700 Subject: [PATCH] retain/release for integers; don't retain on stack push --- Makefile | 5 ++++- src/compile/ir.c | 4 ---- src/data/integer.c | 14 ++++++++++++++ src/data/integer.h | 4 ++++ src/data/value.c | 23 +++++++++++++++++++---- src/vm/exec.c | 6 ------ 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index e40a60d..5159e2d 100644 --- a/Makefile +++ b/Makefile @@ -14,13 +14,16 @@ build/a.out: $(OBJECTS) @mkdir -p $(dir $@) $(CC) $(CFLAGS) -I$(SRC) $(OBJECTS) $(LIBS) -o $@ -.PHONY: parsedebug optimized dev +.PHONY: parsedebug optimized dev profile parsedebug: CFLAGS += -DPARSEDEBUG parsedebug: clean build/a.out optimized: CFLAGS=-Wall -O3 -flto optimized: clean build/a.out +profile: CFLAGS=-Wall -O3 -flto -pg +profile: clean build/a.out + dev: clean build/a.out $(OBJ)/%.o: $(SRC)/%.c diff --git a/src/compile/ir.c b/src/compile/ir.c index bca110b..4503cd3 100644 --- a/src/compile/ir.c +++ b/src/compile/ir.c @@ -8,10 +8,6 @@ #include -#define BY_LET 1 -#define BY_DEF 2 -#define BY_PARAM 3 - typedef struct varmapentry { const char *name; usize name_len; diff --git a/src/data/integer.c b/src/data/integer.c index 5d75198..db70adb 100644 --- a/src/data/integer.c +++ b/src/data/integer.c @@ -73,6 +73,20 @@ hInteger sbInteger_new(i64 value) { } } +void sbInteger_retain(hInteger a) { + if (is_bigint(a)) { + bigint *big = find_bigint_for_handle(a); + big->gcinfo.refcount ++; + } +} + +void sbInteger_release(hInteger a) { + if (is_bigint(a)) { + bigint *big = find_bigint_for_handle(a); + big->gcinfo.refcount --; + } +} + hInteger sbInteger_sum(hInteger a, hInteger b) { if (!is_bigint(a) && !is_bigint(b)) { return sbInteger_new(a + b); diff --git a/src/data/integer.h b/src/data/integer.h index 84c4075..238d132 100644 --- a/src/data/integer.h +++ b/src/data/integer.h @@ -11,6 +11,10 @@ void sbInteger_sys_deinit(); hInteger sbInteger_new(i64 value); +void sbInteger_retain(hInteger a); + +void sbInteger_release(hInteger a); + hInteger sbInteger_sum(hInteger a, hInteger b); hInteger sbInteger_diff(hInteger a, hInteger b); diff --git a/src/data/value.c b/src/data/value.c index 41c8402..4d77ddb 100644 --- a/src/data/value.c +++ b/src/data/value.c @@ -3,6 +3,7 @@ #include "data/string.h" #include "data/list.h" #include "data/hashtable.h" +#include "data/integer.h" #define FLAG_NONINTRINSIC (1ULL << 63) @@ -111,14 +112,28 @@ void sbV_retain(const hV *a) { * because they are trivially copiable. some classes (integer, string) need * to sometimes be retained but sometimes not, so we delegate to them to * figure out if they need to or not. */ - if (a->type == IT_STRING) { - sbString_clone(a->string); + switch (a->type) { + case IT_STRING: + sbString_clone(a->string); + break; + case IT_INTEGER: + sbInteger_retain(a->string); + break; + default: + /* nothing */ } } void sbV_release(const hV *a) { - if (a->type == IT_STRING) { - sbString_release(a->string); + switch (a->type) { + case IT_STRING: + sbString_release(a->string); + break; + case IT_INTEGER: + sbInteger_release(a->string); + break; + default: + /* nothing */ } } diff --git a/src/vm/exec.c b/src/vm/exec.c index 3989faa..c18800b 100644 --- a/src/vm/exec.c +++ b/src/vm/exec.c @@ -182,7 +182,6 @@ void store_local(hVm vm, usize local_index, const hV *value) { } void push_stack(hVm vm, hV *value) { - sbV_retain(value); *(hV**)vm->vsp = value; vm->vsp += sizeof(hV*); vm->xsp += sizeof(hV); @@ -190,7 +189,6 @@ void push_stack(hVm vm, hV *value) { void push_stack_immediate(hVm vm, const hV *value) { /* save it on our own stack */ - sbV_retain(value); *(hV*)vm->xsp = *value; *(hV**)vm->vsp = (hV*)vm->xsp; vm->vsp += sizeof(hV*); @@ -200,16 +198,12 @@ void push_stack_immediate(hVm vm, const hV *value) { hV *pop_stack(hVm vm) { vm->vsp -= sizeof(hV*); vm->xsp -= sizeof(hV); - sbV_release(*(hV**)vm->vsp); return *(hV**)vm->vsp; } hV *npop_stack(hVm vm, usize count) { vm->vsp -= count * sizeof(hV*); vm->xsp -= count * sizeof(hV); - for (usize i = 0; i < count; i++) { - sbV_release(((hV**)vm->vsp)[i]); - } return *(hV**)vm->vsp; } -- 1.8.3.1