summaryrefslogtreecommitdiff
path: root/src/lisp/ao_lisp_eval.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2016-11-10 23:29:21 -0800
committerKeith Packard <keithp@keithp.com>2016-11-17 22:18:39 -0800
commit654a34e72e28bfa52f26ed0be3bef63dfb50bba6 (patch)
tree0a2198463ee176e29a20a55413eac561e35b4c0a /src/lisp/ao_lisp_eval.c
parentcc50f9628431c13c556de8e54788264a5f653f54 (diff)
altos/lisp: Deal with memory compation in the middle of operations
Handle memory compaction in places where we've got pointers into the heap across an allocation operation. Either re-compute the values from managed global references or add new roots across the allocation. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lisp/ao_lisp_eval.c')
-rw-r--r--src/lisp/ao_lisp_eval.c59
1 files changed, 16 insertions, 43 deletions
diff --git a/src/lisp/ao_lisp_eval.c b/src/lisp/ao_lisp_eval.c
index c5addcb0..ae2436b8 100644
--- a/src/lisp/ao_lisp_eval.c
+++ b/src/lisp/ao_lisp_eval.c
@@ -12,7 +12,7 @@
* General Public License for more details.
*/
-#define DBG_EVAL 1
+#define DBG_EVAL 0
#include "ao_lisp.h"
#include <assert.h>
@@ -46,19 +46,20 @@ stack_move(void *addr)
struct ao_lisp_stack *stack = addr;
while (stack) {
- void *prev;
+ struct ao_lisp_stack *prev;
int ret;
(void) ao_lisp_poly_move(&stack->sexprs, 0);
(void) ao_lisp_poly_move(&stack->values, 0);
(void) ao_lisp_poly_move(&stack->values_tail, 0);
(void) ao_lisp_poly_move(&stack->frame, 0);
prev = ao_lisp_poly_stack(stack->prev);
- ret = ao_lisp_move(&ao_lisp_stack_type, &prev);
+ ret = ao_lisp_move_memory((void **) &prev,
+ sizeof (struct ao_lisp_stack));
if (prev != ao_lisp_poly_stack(stack->prev))
stack->prev = ao_lisp_stack_poly(prev);
if (ret)
break;
- stack = ao_lisp_poly_stack(stack->prev);
+ stack = prev;
}
}
@@ -101,8 +102,8 @@ ao_lisp_stack_push(void)
ao_lisp_stack = stack;
ao_lisp_stack_reset(stack);
DBGI("stack push\n");
- DBG_IN();
DBG_FRAMES();
+ DBG_IN();
return 1;
}
@@ -236,37 +237,11 @@ static int
ao_lisp_eval_val(void)
{
DBGI("val: "); DBG_POLY(ao_lisp_v); DBG("\n");
-#if 0
- if (ao_lisp_stack->macro) {
- DBGI(".. end macro %d\n", ao_lisp_stack->macro);
- DBGI(".. sexprs "); DBG_POLY(ao_lisp_stack->sexprs); DBG("\n");
- DBGI(".. values "); DBG_POLY(ao_lisp_stack->values); DBG("\n");
- ao_lisp_frames_dump();
-
- ao_lisp_stack_pop();
-#if 0
- /*
- * Re-use the current stack to evaluate
- * the value from the macro
- */
- ao_lisp_stack->state = eval_sexpr;
- ao_lisp_frame_current = ao_lisp_poly_frame(ao_lisp_stack->macro_frame);
- ao_lisp_stack->frame = ao_lisp_stack->macro_frame;
- ao_lisp_stack->macro = 0;
- ao_lisp_stack->macro_frame = AO_LISP_NIL;
- ao_lisp_stack->sexprs = AO_LISP_NIL;
- ao_lisp_stack->values = AO_LISP_NIL;
- ao_lisp_stack->values_tail = AO_LISP_NIL;
-#endif
- } else
-#endif
- {
- /*
- * Value computed, pop the stack
- * to figure out what to do with the value
- */
- ao_lisp_stack_pop();
- }
+ /*
+ * Value computed, pop the stack
+ * to figure out what to do with the value
+ */
+ ao_lisp_stack_pop();
DBGI("..state %d\n", ao_lisp_stack ? ao_lisp_stack->state : -1);
return 1;
}
@@ -305,7 +280,6 @@ ao_lisp_eval_formal(void)
break;
case AO_LISP_FUNC_MACRO:
/* Evaluate the result once more */
- prev = ao_lisp_stack;
ao_lisp_stack->state = eval_sexpr;
if (!ao_lisp_stack_push())
return 0;
@@ -313,6 +287,7 @@ ao_lisp_eval_formal(void)
/* After the function returns, take that
* value and re-evaluate it
*/
+ prev = ao_lisp_poly_stack(ao_lisp_stack->prev);
ao_lisp_stack->state = eval_sexpr;
ao_lisp_stack->sexprs = prev->sexprs;
prev->sexprs = AO_LISP_NIL;
@@ -400,8 +375,7 @@ ao_lisp_eval_exec(void)
case AO_LISP_LAMBDA:
ao_lisp_stack->state = eval_sexpr;
DBGI(".. frame "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");
- ao_lisp_v = ao_lisp_lambda_eval(ao_lisp_poly_lambda(ao_lisp_v),
- ao_lisp_poly_cons(ao_lisp_stack->values));
+ ao_lisp_v = ao_lisp_lambda_eval();
DBGI(".. sexpr "); DBG_POLY(ao_lisp_v); DBG("\n");
DBGI(".. frame "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");
break;
@@ -464,12 +438,11 @@ ao_lisp_eval_cond_test(void)
struct ao_lisp_cons *car = ao_lisp_poly_cons(ao_lisp_poly_cons(ao_lisp_stack->sexprs)->car);
struct ao_lisp_cons *c = ao_lisp_poly_cons(car->cdr);
- ao_lisp_stack->state = eval_val;
if (c) {
+ ao_lisp_stack->state = eval_sexpr;
ao_lisp_v = c->car;
- if (!ao_lisp_stack_push())
- return 0;
- }
+ } else
+ ao_lisp_stack->state = eval_val;
} else {
ao_lisp_stack->sexprs = ao_lisp_poly_cons(ao_lisp_stack->sexprs)->cdr;
DBGI("next cond: "); DBG_POLY(ao_lisp_stack->sexprs); DBG("\n");