From a54570352a6f81923ab0b0edbbef0f10e1c94eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Fri, 6 Jun 2025 15:15:48 +0200 Subject: [PATCH] [maybe] bytevm: open-code lexical environment allocation To avoid dependency on vector.o we opencode allocating the vector. Note that we can't use ecl_make_stack, because mallocated memory must be reegistered as a root. [todo] move finalizers to memory and fix t_bclosure [note] ecl_stack_pshu never resizes the stack (realloc vs manual resize) --- src/c/interpreter.d | 14 ++++++++++---- src/c/mem_bdwgc.d | 8 ++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/c/interpreter.d b/src/c/interpreter.d index 45cd19252..0ab1ad46b 100644 --- a/src/c/interpreter.d +++ b/src/c/interpreter.d @@ -175,16 +175,22 @@ ecl_lex_env_get_record(cl_object env, int s) /* -- Lexical and local env operators ------------------------------------------ */ static cl_object -make_lex(cl_index n) +make_lex(cl_index size) { - return si_make_vector(ECL_T, ecl_make_fixnum(n), ECL_NIL, - ecl_make_fixnum(0), ECL_NIL, ECL_NIL); + cl_object x = ecl_alloc_object(t_vector); + x->vector.elttype = ecl_aet_object; + x->vector.displaced = ECL_NIL; + x->vector.dim = size; + x->vector.fillp = 0; + x->vector.flags = ECL_FLAG_ADJUSTABLE | ECL_FLAG_HAS_FILL_POINTER; + x->vector.self.t = (cl_object *)ecl_alloc(size * sizeof(cl_object)); + return x; } static void push_lex(cl_object stack, cl_object new) { - cl_vector_push(new, stack); + ecl_stack_pshu(stack, new); } /* -------------------- AIDS TO THE INTERPRETER -------------------- */ diff --git a/src/c/mem_bdwgc.d b/src/c/mem_bdwgc.d index 298973e22..d6a1e3e14 100644 --- a/src/c/mem_bdwgc.d +++ b/src/c/mem_bdwgc.d @@ -340,6 +340,13 @@ standard_finalizer(cl_object o) case t_weak_pointer: GC_unregister_disappearing_link((void**)&(o->weak.value)); break; +#if 0 + case t_bclosure: { + ecl_free_stack(o->bclosure.lex); + o->bclosure.lex = ECL_NIL; + break; + } +#endif #ifdef ECL_THREADS case t_lock: { const cl_env_ptr the_env = ecl_process_env(); @@ -400,6 +407,7 @@ standard_finalizer(cl_object o) ecl_atomic_push(&ecl_core.reused_indices, ecl_make_fixnum(o->symbol.binding)); o->symbol.binding = ECL_MISSING_SPECIAL_BINDING; } + break; } #endif /* ECL_THREADS */ default:;