From 97d874f16b7fc915d4504ce219a2a41b87379264 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 15 Sep 2019 13:27:49 -0500 Subject: [PATCH] Fix small compiler bug (not freeing temp register). --- src/core/regalloc.c | 1 + src/core/specials.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/regalloc.c b/src/core/regalloc.c index 13898386..83cfbc7b 100644 --- a/src/core/regalloc.c +++ b/src/core/regalloc.c @@ -144,6 +144,7 @@ void janetc_regalloc_free(JanetcRegisterAllocator *ra, int32_t reg) { int32_t janetc_regalloc_temp(JanetcRegisterAllocator *ra, JanetcRegisterTemp nth) { int32_t oldmax = ra->max; if (ra->regtemps & (1 << nth)) { + printf("regtemp %d attempted\n", nth); janet_exit("regtemp already allocated"); } ra->regtemps |= 1 << nth; diff --git a/src/core/specials.c b/src/core/specials.c index 4a553412..8be85bdc 100644 --- a/src/core/specials.c +++ b/src/core/specials.c @@ -602,6 +602,7 @@ static JanetSlot janetc_while(JanetFopts opts, int32_t argn, const Janet *argv) int32_t tempself = janetc_regalloc_temp(&tempscope.ra, JANETC_REGTEMP_0); janetc_emit(c, JOP_LOAD_SELF | (tempself << 8)); janetc_emit(c, JOP_TAILCALL | (tempself << 8)); + janetc_regalloc_freetemp(&c->scope->ra, tempself, JANETC_REGTEMP_0); /* Compile function */ JanetFuncDef *def = janetc_pop_funcdef(c); def->name = janet_cstring("_while"); @@ -610,7 +611,7 @@ static JanetSlot janetc_while(JanetFopts opts, int32_t argn, const Janet *argv) int32_t cloreg = janetc_regalloc_temp(&c->scope->ra, JANETC_REGTEMP_0); janetc_emit(c, JOP_CLOSURE | (cloreg << 8) | (defindex << 16)); janetc_emit(c, JOP_CALL | (cloreg << 8) | (cloreg << 16)); - janetc_regalloc_free(&c->scope->ra, cloreg); + janetc_regalloc_freetemp(&c->scope->ra, cloreg, JANETC_REGTEMP_0); c->scope->flags |= JANET_SCOPE_CLOSURE; return janetc_cslot(janet_wrap_nil()); }