diff options
author | Teddy <ted.sybil@gmail.com> | 2013-08-11 22:25:22 +0800 |
---|---|---|
committer | Teddy <ted.sybil@gmail.com> | 2013-08-11 22:25:22 +0800 |
commit | 76977635e28e06192a486a9452e03bc7b8f612dc (patch) | |
tree | c8eaf0c22f1516bb88c2a21661a3bc2b8eadd2c6 /eval.cpp | |
parent | ab3a756ccb788487136d6982a7ddf6d4053ec133 (diff) |
fixed severe bug in many special opts
Diffstat (limited to 'eval.cpp')
-rw-r--r-- | eval.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -82,6 +82,11 @@ void Evaluator::add_builtin_routines() { ADD_BUILTIN_PROC("string>?", string_gt); ADD_BUILTIN_PROC("string<=?", string_ge); ADD_BUILTIN_PROC("string=?", string_eq); + + ADD_BUILTIN_PROC("make-vector", make_vector); + ADD_BUILTIN_PROC("vector-set!", vector_set); + ADD_BUILTIN_PROC("vector-ref", vector_ref); + ADD_BUILTIN_PROC("vector-length", vector_length); } Evaluator::Evaluator() { @@ -104,18 +109,22 @@ inline bool make_exec(Pair *ptr) { } inline void push(Pair * &pc, FrameObj ** &top_ptr, Environment *envt) { +// if (pc->car == NULL) + // puts("oops"); if (pc->car->is_simple_obj()) // Not an opt invocation { *top_ptr = envt->get_obj(pc->car); // Objectify the symbol top_ptr++; pc = pc->next; // Move to the next instruction +// if (pc == empty_list) +// puts("oops"); } else // Operational Invocation { if (pc->car == empty_list) throw NormalError(SYN_ERR_EMPTY_COMB); - *top_ptr++ = new RetAddr(pc); // Push the return address + *top_ptr++ = new RetAddr(pc, NULL); // Push the return address 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 @@ -124,6 +133,17 @@ inline void push(Pair * &pc, FrameObj ** &top_ptr, Environment *envt) { } } +void print_stack(FrameObj **top) { + for (FrameObj **i = eval_stack; i < top; i++) + { + if ((*i)->is_ret_addr()) + puts("<return addr>"); + else + printf("%s\n", static_cast<EvalObj*>(*i)->ext_repr().c_str()); + } + puts(""); +} + EvalObj *Evaluator::run_expr(Pair *prog) { FrameObj **top_ptr = eval_stack; Pair *pc = prog; |