From 72ab4af20e4bc1baf1b0e58b08a01b21b7a60a36 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Mon, 31 Dec 2018 14:43:47 +0000 Subject: [PATCH] Seem to have fixed the 'oblist getting lost' problem. --- lisp/fact.lisp | 1 + src/ops/lispops.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lisp/fact.lisp b/lisp/fact.lisp index de1f12b..968ea73 100644 --- a/lisp/fact.lisp +++ b/lisp/fact.lisp @@ -1,5 +1,6 @@ (set! fact (lambda (n) + "Compute the factorial of `n`, expected to be an integer." (cond ((= n 1) 1) (t (* n (fact (- n 1))))))) diff --git a/src/ops/lispops.c b/src/ops/lispops.c index 476cf46..d20dbf9 100644 --- a/src/ops/lispops.c +++ b/src/ops/lispops.c @@ -1015,11 +1015,11 @@ struct cons_pointer lisp_repl( struct stack_frame *frame, struct cons_pointer prompt_name = c_string_to_lisp_symbol( L"*prompt*" ); struct cons_pointer old_oblist = oblist; struct cons_pointer new_env = env; + inc_ref(env); inc_ref( input ); inc_ref( output ); inc_ref( prompt_name ); - inc_ref( new_env ); /* TODO: this is subtly wrong. If we were evaluating * (print (eval (read))) @@ -1039,6 +1039,7 @@ struct cons_pointer lisp_repl( struct stack_frame *frame, struct cons_pointer cursor = oblist; while ( !nilp( cursor ) && !eq( cursor, old_oblist ) ) { + struct cons_pointer old_new_env = new_env; debug_print ( L"lisp_repl: copying new oblist binding into REPL environment:\n", DEBUG_REPL ); @@ -1046,6 +1047,8 @@ struct cons_pointer lisp_repl( struct stack_frame *frame, debug_println( DEBUG_REPL ); new_env = make_cons( c_car( cursor ), new_env ); + inc_ref( new_env); + dec_ref( old_new_env); cursor = c_cdr( cursor ); } old_oblist = oblist; @@ -1078,7 +1081,7 @@ struct cons_pointer lisp_repl( struct stack_frame *frame, dec_ref( input ); dec_ref( output ); dec_ref( prompt_name ); - dec_ref( new_env ); + dec_ref( env ); return expr; }