From 898e4df5036f0337607bdf3548d15f5457221533 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Tue, 11 Oct 2022 19:12:37 +0200 Subject: [PATCH] Squashed 'lispBM/lispBM/' changes from ca26715a..e76a3deb e76a3deb removed GC from finish_ctx. Can be taken care of from the C interface 91924e68 clean up heap after an error. Most important after an out_of_memory a bit dependent on how one interacts with the RTS ba1c57ad new test on setvar together with let - passes. df38cde4 small cleaning around bug fix area git-subtree-dir: lispBM/lispBM git-subtree-split: e76a3debc2abfd8528becb4295eb6f22492b3826 --- repl/repl.c | 8 ++++---- src/eval_cps.c | 4 +--- tests/test_setvar_let_2.lisp | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 tests/test_setvar_let_2.lisp diff --git a/repl/repl.c b/repl/repl.c index 416653b9..be5cb939 100644 --- a/repl/repl.c +++ b/repl/repl.c @@ -661,7 +661,7 @@ int main(int argc, char **argv) { file_str); /* Get exclusive access to the heap */ - lbm_pause_eval(); + lbm_pause_eval_with_gc(50); while(lbm_get_eval_state() != EVAL_CPS_STATE_PAUSED) { sleep_callback(10); } @@ -809,7 +809,7 @@ int main(int argc, char **argv) { int i_val; if (sscanf(str + 5, "%d%d", &id, &i_val) == 2) { - lbm_pause_eval(); + lbm_pause_eval_with_gc(50); while(lbm_get_eval_state() != EVAL_CPS_STATE_PAUSED) { sleep_callback(10); } @@ -849,7 +849,7 @@ int main(int argc, char **argv) { printf("symbol does not exist\n"); } } else if (strncmp(str, ":undef", 6) == 0) { - lbm_pause_eval(); + lbm_pause_eval_with_gc(50); while(lbm_get_eval_state() != EVAL_CPS_STATE_PAUSED) { sleep_callback(10); } @@ -861,7 +861,7 @@ int main(int argc, char **argv) { } else { /* Get exclusive access to the heap */ read_t *r = malloc(sizeof(read_t)); - lbm_pause_eval(); + lbm_pause_eval_with_gc(50); while(lbm_get_eval_state() != EVAL_CPS_STATE_PAUSED) { sleep_callback(10); } diff --git a/src/eval_cps.c b/src/eval_cps.c index d21c472f..af40b223 100644 --- a/src/eval_cps.c +++ b/src/eval_cps.c @@ -1997,19 +1997,17 @@ static void cont_application_args(eval_context_t *ctx) { lbm_value rest = sptr[2]; lbm_value arg = ctx->r; + ctx->curr_env = env; sptr[0] = arg; if (lbm_is_symbol_nil(rest)) { // no arguments - sptr[1] = count; lbm_stack_drop(&ctx->K, 1); - ctx->curr_env = env; cont_application(ctx); } else if (lbm_is_cons(rest)) { sptr[1] = env; sptr[2] = lbm_enc_u(lbm_dec_u(count) + 1); CHECK_STACK(lbm_push_2(&ctx->K,lbm_cdr(rest), APPLICATION_ARGS)); ctx->curr_exp = lbm_car(rest); - ctx->curr_env = env; } else { error_ctx(ENC_SYM_EERROR); } diff --git a/tests/test_setvar_let_2.lisp b/tests/test_setvar_let_2.lisp new file mode 100644 index 00000000..a2777100 --- /dev/null +++ b/tests/test_setvar_let_2.lisp @@ -0,0 +1,21 @@ +(define a 12) +(defun b () 18) + +(define res + (let ((a 9)) + (+ (b) (let ((b 6)) + (progn + (setvar 'b 7) + (setvar 'a (+ b 2)) + a)) + a) +)) + +; Expected: +; res = 36 +; a = 12 +; (b) = 18 + +(and (= res 36) + (= a 12) + (= (b) 18))