From 86c773dfe744b66661b63f9c414d4ccee797c70a Mon Sep 17 00:00:00 2001 From: Gavan Fantom Date: Mon, 31 Dec 2007 00:51:40 +0000 Subject: [PATCH] Don't trash the number of arguments in the current function when making a function call. --- src/lsc/codegen.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lsc/codegen.c b/src/lsc/codegen.c index 2ceba10..463039d 100644 --- a/src/lsc/codegen.c +++ b/src/lsc/codegen.c @@ -549,6 +549,7 @@ void codegen(ast *node) int hasdefault; int i; int savedlineno; + int ncallargs; union { int i; @@ -616,9 +617,11 @@ void codegen(ast *node) * Arguments on the stack directly above * local variables, and then return address */ + printf("(argument)\n"); emit_instr_imm_const(OP_LOAD, sp + 1 + nargs - var.addr, fnconst); } else { + printf("(non-argument)\n"); emit_instr_imm_const(OP_LOAD, sp - var.addr - 1, fnconst); } sp++; @@ -777,14 +780,14 @@ void codegen(ast *node) // printf("savedsp = %d\n", savedsp); - nargs = 0; + ncallargs = 0; /* Evaluate the arguments first */ for (ptr = node->info.node.head->next->elem->info.node.head; ptr; ptr = ptr->next) { codegen(ptr->elem); - nargs++; + ncallargs++; } // printf("sp = %d\n", sp); @@ -800,7 +803,7 @@ void codegen(ast *node) * This is something only supported for * builtin functions at present. */ - emit_instr_immediate(OP_PUSH, nargs); + emit_instr_immediate(OP_PUSH, ncallargs); sp++; }