From b6a279fafe43f502ab5647a705b8880f8961b404 Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 7 Aug 2013 16:37:43 +0800 Subject: fixed a severe bug in `define` --- builtin.cpp | 4 ++-- main.cpp | 4 ++-- model.cpp | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/builtin.cpp b/builtin.cpp index 0228b45..e435c8c 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -701,9 +701,9 @@ void SpecialOptDefine::prepare(Cons *pc) { if (!pc->cdr->is_cons_obj()) throw TokenError(name, RUN_ERR_WRONG_NUM_OF_ARGS); - pc = TO_CONS(pc->cdr); - if (pc->car->is_simple_obj()) // Simple value assignment + if (TO_CONS(pc->cdr)->car->is_simple_obj()) // Simple value assignment { + pc = TO_CONS(pc->cdr); if (!pc->cdr->is_cons_obj()) throw TokenError(name, RUN_ERR_WRONG_NUM_OF_ARGS); pc->skip = true; // Skip the identifier diff --git a/main.cpp b/main.cpp index 2e4d294..c07b873 100644 --- a/main.cpp +++ b/main.cpp @@ -17,7 +17,7 @@ void tree_print(Cons *ptr) { #endif int main() { -// freopen("in.scm", "r", stdin); + //freopen("in.scm", "r", stdin); Tokenizor *tk = new Tokenizor(); ASTGenerator *ast = new ASTGenerator(); Evaluator *eval = new Evaluator(); @@ -25,7 +25,7 @@ int main() { int rcnt = 0; while (1) { - printf("Sonsi> "); + fprintf(stderr, "Sonsi> "); try { Cons *tree = ast->absorb(tk); diff --git a/model.cpp b/model.cpp index 67db5fe..89849ca 100644 --- a/model.cpp +++ b/model.cpp @@ -145,19 +145,19 @@ Cons *ProcObj::call(ArgList *args, Environment * &genvt, // Create local env and recall the closure Environment *_envt = new Environment(envt); // static_cast because the para_list is already checked - Cons *ptr, *ppar; + Cons *ppar; EvalObj *nptr; - for (ptr = TO_CONS(args->cdr), ppar = para_list; + for (ppar = para_list; ppar != empty_list; ppar = TO_CONS(ppar->cdr)) { - _envt->add_binding(static_cast(ppar->car), ptr->car); - if ((nptr = ptr->cdr)->is_cons_obj()) - ptr = TO_CONS(nptr); + if ((nptr = args->cdr)->is_cons_obj()) + args = TO_CONS(nptr); else break; + _envt->add_binding(static_cast(ppar->car), args->car); } - if (ptr->cdr != empty_list || ppar->cdr != empty_list) + if (args->cdr != empty_list || ppar != empty_list) throw TokenError("", RUN_ERR_WRONG_NUM_OF_ARGS); genvt = _envt; -- cgit v1.2.3-70-g09d2