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 hasdefault;
int i; int i;
int savedlineno; int savedlineno;
int ncallargs;
union { union {
int i; int i;
@ -616,9 +617,11 @@ void codegen(ast *node)
* Arguments on the stack directly above * Arguments on the stack directly above
* local variables, and then return address * local variables, and then return address
*/ */
printf("(argument)\n");
emit_instr_imm_const(OP_LOAD, emit_instr_imm_const(OP_LOAD,
sp + 1 + nargs - var.addr, fnconst); sp + 1 + nargs - var.addr, fnconst);
} else { } else {
printf("(non-argument)\n");
emit_instr_imm_const(OP_LOAD, sp - var.addr - 1, fnconst); emit_instr_imm_const(OP_LOAD, sp - var.addr - 1, fnconst);
} }
sp++; sp++;
@ -777,14 +780,14 @@ void codegen(ast *node)
// printf("savedsp = %d\n", savedsp); // printf("savedsp = %d\n", savedsp);
nargs = 0; ncallargs = 0;
/* Evaluate the arguments first */ /* Evaluate the arguments first */
for (ptr = for (ptr =
node->info.node.head->next->elem->info.node.head; node->info.node.head->next->elem->info.node.head;
ptr; ptr = ptr->next) { ptr; ptr = ptr->next) {
codegen(ptr->elem); codegen(ptr->elem);
nargs++; ncallargs++;
} }
// printf("sp = %d\n", sp); // printf("sp = %d\n", sp);
@ -800,7 +803,7 @@ void codegen(ast *node)
* This is something only supported for * This is something only supported for
* builtin functions at present. * builtin functions at present.
*/ */
emit_instr_immediate(OP_PUSH, nargs); emit_instr_immediate(OP_PUSH, ncallargs);
sp++; sp++;
} }

Loading…
Cancel
Save