aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <ted.sybil@gmail.com>2013-08-07 16:37:43 +0800
committerTeddy <ted.sybil@gmail.com>2013-08-07 16:37:43 +0800
commitb6a279fafe43f502ab5647a705b8880f8961b404 (patch)
tree3f9a0ae3b3a988c1b6e270652c4859cb2f89681c
parentc5f2c8fa951100d6c3ee13e551c4ec78b7a4a616 (diff)
fixed a severe bug in `define`
-rw-r--r--builtin.cpp4
-rw-r--r--main.cpp4
-rw-r--r--model.cpp12
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<SymObj*> 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<SymObj*>(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<SymObj*>(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;