Move optimiize out of pop_funcdef.

This commit is contained in:
Calvin Rose committed 2026-09-19 16:28:41 -05:00
1 parent f442b310ef
commit d763d0d51a
4 files changed
+22 -10

No files matched your search

+4 -4
View File
@@ -4,10 +4,10 @@
#define JANETCONF_H
#define JANET_VERSION_MAJOR 1
#define JANET_VERSION_MINOR 42
#define JANET_VERSION_PATCH 1
#define JANET_VERSION_EXTRA ""
#define JANET_VERSION "1.42.1"
#define JANET_VERSION_MINOR 43
#define JANET_VERSION_PATCH 0
#define JANET_VERSION_EXTRA "-dev"
#define JANET_VERSION "1.43.0-dev"
/* #define JANET_BUILD "local" */
+10
View File
@@ -971,6 +971,16 @@ void janet_bytecode_remove_unused_constants(JanetFuncDef *def) {
janet_assert(words > 0, "bad length");
uint32_t *bitset = array_allocate(sizeof(uint32_t), words);
memset(bitset, 0, words * sizeof(uint32_t));
/* Quirk: We rely on the first N constants being the named arguments of a function for warnings
* while making function calls. Preserve these in the case we have named arguments so we don't get
* spurious warnings for unused named arguments (or miss warnings!) */
if (def->flags & JANET_FUNCDEF_FLAG_NAMEDARGS) {
for (int32_t index = 0; index < def->named_args_count; index++) {
bs_set_bit(bitset, index);
}
}
for (int32_t pc = 0; pc < def->bytecode_length; pc++) {
uint32_t E = code[pc] >> 16;
switch (code[pc] & 0x7F) {
+1 -6
View File
@@ -1012,9 +1012,6 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c, JanetString name) {
JanetFuncDef *def = janet_funcdef_alloc();
def->slotcount = scope->ra.max + 1;
/* TODO - turn this on even for unused code for verification purposes */
int optimize = (scope->flags & JANET_SCOPE_UNUSED) ? 0 : c->optimize;
janet_assert(scope->flags & JANET_SCOPE_FUNCTION, "expected function scope");
/* Copy envs */
@@ -1141,9 +1138,6 @@ JanetFuncDef *janetc_pop_funcdef(JanetCompiler *c, JanetString name) {
/* Add a name _before_ optimization for debugging */
def->name = name;
/* Do basic optimization */
janet_bytecode_optimize(def, optimize);
#ifdef JANET_DEBUG
janet_verify(def);
#endif
@@ -1209,6 +1203,7 @@ JanetCompileResult janet_compile_lint(Janet source,
if (c.result.status == JANET_COMPILE_OK) {
JanetFuncDef *def = janetc_pop_funcdef(&c, janet_cstring("thunk"));
janet_def_addflags(def);
janet_bytecode_optimize(def, c.optimize);
c.result.funcdef = def;
} else {
c.result.error_mapping = c.current_mapping;
+7
View File
@@ -963,6 +963,9 @@ static JanetSlot janetc_while(JanetFopts opts, int32_t argn, const Janet *argv)
JanetFuncDef *def = janetc_pop_funcdef(c, janet_cstring("while"));
janet_def_addflags(def);
int32_t defindex = janetc_addfuncdef(c, def);
/* Do basic optimization */
int32_t optimize = (c->scope->flags & JANET_SCOPE_UNUSED) ? -1 : c->optimize;
janet_bytecode_optimize(def, optimize);
/* And then load the closure and call it. */
int32_t cloreg = janetc_regalloc_temp(&c->scope->ra, JANETC_REGTEMP_0);
janetc_emit(c, JOP_CLOSURE | ((uint32_t) cloreg << 8) | ((uint32_t) defindex << 16));
@@ -1023,6 +1026,7 @@ static JanetSlot janetc_fn(JanetFopts opts, int32_t argn, const Janet *argv) {
/* Begin function */
c->scope->flags |= JANET_SCOPE_CLOSURE;
int32_t optimize = (c->scope->flags & JANET_SCOPE_UNUSED) ? -1 : c->optimize;
janetc_scope(&fnscope, c, JANET_SCOPE_FUNCTION, "function");
if (argn == 0) {
@@ -1212,6 +1216,9 @@ static JanetSlot janetc_fn(JanetFopts opts, int32_t argn, const Janet *argv) {
/* Ensure enough slots for vararg function. */
if (arity + vararg > def->slotcount) def->slotcount = arity + vararg;
/* Do basic optimization */
janet_bytecode_optimize(def, optimize);
/* Instantiate closure */
ret = janetc_gettarget(opts);
janetc_emit_su(c, JOP_CLOSURE, ret, defindex, 1);