diff options
-rw-r--r-- | eval.cpp | 3 | ||||
-rw-r--r-- | model.cpp | 26 | ||||
-rw-r--r-- | model.h | 2 | ||||
-rw-r--r-- | robust_test.scm | 2 |
4 files changed, 24 insertions, 9 deletions
@@ -102,7 +102,7 @@ void push(Pair * &pc, FrameObj ** &top_ptr, Environment *envt) { throw NormalError(SYN_ERR_EMPTY_COMB); *top_ptr++ = new RetAddr(pc); // Push the return address - if (!is_list(TO_PAIR(pc->car))) + if (!make_exec(TO_PAIR(pc->car))) throw TokenError(pc->car->ext_repr(), RUN_ERR_WRONG_NUM_OF_ARGS); // static_cast because of is_simple_obj() is false pc = static_cast<Pair*>(pc->car); // Go deeper to enter the call @@ -121,7 +121,6 @@ EvalObj *Evaluator::run_expr(Pair *prog) { { if (top_ptr == eval_stack + EVAL_STACK_SIZE) throw TokenError("Evaluation", RUN_ERR_STACK_OVERFLOW); -// for (; pc && pc->skip; pc = pc->next); if (pc) push(pc, top_ptr, envt); else @@ -84,8 +84,13 @@ string EvalObj::ext_repr() { if (obj) { *(++top_ptr) = obj->get_repr_cons(); - if (hash.count((*top_ptr)->ori)) - *top_ptr = new ReprStr("#inf#"); + EvalObj *ptr = (*top_ptr)->ori; + if (ptr) + { + if (hash.count(ptr)) + *top_ptr = new ReprStr("#inf#"); + else hash.insert(ptr); + } } else { @@ -100,8 +105,13 @@ string EvalObj::ext_repr() { if (obj) { *(++top_ptr) = obj->get_repr_cons(); - if (hash.count((*top_ptr)->ori)) - *top_ptr = new ReprStr("#inf#"); + EvalObj *ptr = (*top_ptr)->ori; + if (ptr) + { + if (hash.count(ptr)) + *top_ptr = new ReprStr("#inf#"); + else hash.insert(ptr); + } } else *top_ptr = new ReprStr((*top_ptr)->repr); } @@ -401,13 +411,17 @@ EvalObj *PromObj::get_mem() { return mem; } void PromObj::feed_mem(EvalObj *res) { mem = res; } -bool is_list(Pair *ptr) { +bool make_exec(Pair *ptr) { if (ptr == empty_list) return true; EvalObj *nptr; for (;;) if ((nptr = ptr->cdr)->is_pair_obj()) - ptr = TO_PAIR(nptr); + { + ptr->next = TO_PAIR(nptr); + ptr = ptr->next; + } else break; + ptr->next = NULL; return ptr->cdr == empty_list; } @@ -464,6 +464,6 @@ class Continuation { Pair *proc_body); }; -bool is_list(Pair *ptr); +bool make_exec(Pair *ptr); #endif diff --git a/robust_test.scm b/robust_test.scm index 152e380..bc327ea 100644 --- a/robust_test.scm +++ b/robust_test.scm @@ -172,6 +172,8 @@ t src (eval src) (eval '(g 0)) +(eval (list * 2 3)) +(eval '(* 2 3)) (define f (lambda (x) (+ x x))) ;; test comments ((lambda (x y) (f 3)) 1 2) ;; first-class procedure |