From 1103b2dc782c5fc787a51ac53ae81f11fa50cc58 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Fri, 22 Dec 2023 16:40:38 +0100 Subject: [PATCH] Squashed 'lispBM/lispBM/' changes from acf53419..928f96dc 928f96dc bugfix related to environment creation for comparators in merge and sort git-subtree-dir: lispBM/lispBM git-subtree-split: 928f96dc047aa9927081a3892f78226c8fef321c --- experiment_repl/repl.c | 2 +- src/env.c | 1 - src/eval_cps.c | 36 ++++++++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/experiment_repl/repl.c b/experiment_repl/repl.c index d43f6ec2..78ed0c68 100644 --- a/experiment_repl/repl.c +++ b/experiment_repl/repl.c @@ -609,7 +609,7 @@ int main(int argc, char **argv) { pthread_t lispbm_thd; lbm_heap_state_t heap_state; - unsigned int heap_size = 2048; + unsigned int heap_size = 8192;//2048; lbm_cons_t *heap_storage = NULL; lbm_const_heap_t const_heap; diff --git a/src/env.c b/src/env.c index f272c1be..42bab3bc 100644 --- a/src/env.c +++ b/src/env.c @@ -116,7 +116,6 @@ lbm_value lbm_env_set(lbm_value env, lbm_value key, lbm_value val) { } new_env = lbm_cons(keyval, env); - return new_env; } diff --git a/src/eval_cps.c b/src/eval_cps.c index 05cf2a77..76ac8f37 100644 --- a/src/eval_cps.c +++ b/src/eval_cps.c @@ -2527,8 +2527,11 @@ static void apply_merge(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) { if (len == 2) { par1 = get_car(cl[CLO_PARAMS]); par2 = get_car(get_cdr(cl[CLO_PARAMS])); - WITH_GC(cmp_env, lbm_env_set(cmp_env, par1, lbm_car(a_1))); - WITH_GC(cmp_env, lbm_env_set(cmp_env, par2, lbm_car(b_1))); + lbm_value new_env0; + lbm_value new_env; + WITH_GC(new_env0, lbm_env_set(cmp_env, par1, lbm_car(a_1))); + WITH_GC_RMBR_1(new_env, lbm_env_set(new_env0, par2, lbm_car(b_1)),new_env0); + cmp_env = new_env; } else { error_at_ctx(ENC_SYM_TERROR, args[0]); } @@ -2587,8 +2590,11 @@ static void apply_sort(lbm_value *args, lbm_uint nargs, eval_context_t *ctx) { if (cl_len == 2) { par1 = get_car(cl[CLO_PARAMS]); par2 = get_car(get_cdr(cl[CLO_PARAMS])); - WITH_GC(cmp_env, lbm_env_set(cmp_env, par1, lbm_car(a))); - WITH_GC(cmp_env, lbm_env_set(cmp_env, par2, lbm_car(b))); + lbm_value new_env0; + lbm_value new_env; + WITH_GC(new_env0, lbm_env_set(cmp_env, par1, lbm_car(a))); + WITH_GC_RMBR_1(new_env, lbm_env_set(new_env0, par2, lbm_car(b)), new_env0); + cmp_env = new_env; } else { error_at_ctx(ENC_SYM_TERROR, args[0]); } @@ -3077,8 +3083,15 @@ static void cont_merge_rest(eval_context_t *ctx) { lbm_value par2 = sptr[8]; lbm_value cmp_body = sptr[5]; lbm_value cmp_env = sptr[6]; - WITH_GC(cmp_env, lbm_env_set(cmp_env, par1, lbm_car(a))); - WITH_GC(cmp_env, lbm_env_set(cmp_env, par2, lbm_car(b))); + // Environment should be preallocated already at this point + // and the operations below should never need GC. + // maybe rewrite this as a more efficient update and + // a fatal error if that is not possible. + lbm_value new_env0; + lbm_value new_env; + WITH_GC(new_env0, lbm_env_set(cmp_env, par1, lbm_car(a))); + WITH_GC_RMBR_1(new_env, lbm_env_set(new_env0, par2, lbm_car(b)), new_env0); + cmp_env = new_env; stack_push(&ctx->K, MERGE_REST); ctx->curr_exp = cmp_body; @@ -3182,8 +3195,15 @@ static void cont_merge_layer(eval_context_t *ctx) { lbm_value cmp_env = sptr[1]; lbm_value par1 = sptr[2]; lbm_value par2 = sptr[3]; - WITH_GC(cmp_env, lbm_env_set(cmp_env, par1, lbm_car(a))); - WITH_GC(cmp_env, lbm_env_set(cmp_env, par2, lbm_car(b))); + // Environment should be preallocated already at this point + // and the operations below should never need GC. + // maybe rewrite this as a more efficient update and + // a fatal error if that is not possible. + lbm_value new_env0; + lbm_value new_env; + WITH_GC(new_env0, lbm_env_set(cmp_env, par1, lbm_car(a))); + WITH_GC_RMBR_1(new_env, lbm_env_set(new_env0, par2, lbm_car(b)), new_env0); + cmp_env = new_env; lbm_uint *merge_cont = stack_reserve(ctx, 11); merge_cont[0] = MERGE_LAYER;