Browse Source

Don't trash the number of arguments in the current function when making a

function call.
master
Gavan Fantom 17 years ago
parent
commit
86c773dfe7
  1. 9
      src/lsc/codegen.c

9
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++;
}

Loading…
Cancel
Save