Skip to content

Commit 033f856

Browse files
committed
work on parameter passing.
1 parent 52eb261 commit 033f856

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

src/ast.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,11 @@ expr_set_unexpr(M1_compiler *comp, m1_expression *node, m1_expression *exp, m1_u
187187

188188
m1_expression *
189189
funcall(M1_compiler *comp, char *name, m1_expression *args) {
190-
m1_expression *expr = expression(comp, EXPR_FUNCALL);
191-
expr->expr.f = (m1_funcall *)m1_malloc(sizeof(m1_funcall));
192-
expr->expr.f->name = name;
193-
190+
m1_expression *expr = expression(comp, EXPR_FUNCALL);
191+
expr->expr.f = (m1_funcall *)m1_malloc(sizeof(m1_funcall));
192+
expr->expr.f->name = name;
193+
expr->expr.f->arguments = args;
194+
194195
/* enter name of function to invoke into constant table. */
195196
sym_enter_chunk(&comp->currentchunk->constants, name);
196197
return expr;

src/ast.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ typedef struct m1_assignment {
4949
} m1_assignment;
5050

5151
typedef struct m1_funcall {
52-
char *name;
53-
/* TODO: add args */
52+
char *name;
53+
struct m1_expression *arguments;
5454

5555
} m1_funcall;
5656

src/gencode.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,22 @@ gencode_funcall(M1_compiler *comp, m1_funcall *f) {
10951095
fprintf(OUT, "\tset_imm I%d, 0, 0\n", flagsreg.no);
10961096
fprintf(OUT, "\tgc_alloc P%d, I%d, I%d\n", cf_reg.no, sizereg.no, flagsreg.no);
10971097

1098+
/* store arguments in registers of new callframe.
1099+
XXX this still needs to be specced for M0's calling conventions. */
1100+
1101+
m1_expression *argiter = f->arguments;
1102+
int regindex = 12; /* points to I0. XXX */
1103+
while (argiter != NULL) {
1104+
m1_reg argreg;
1105+
m1_reg indexreg = gen_reg(comp, VAL_INT);
1106+
gencode_expr(comp, argiter);
1107+
argreg = popreg(comp->regstack);
1108+
fprintf(OUT, "\tset_imm I%d, 0, %d\n", indexreg.no, regindex);
1109+
fprintf(OUT, "\tset_ref P%d, I%d, I%d\n", cf_reg.no, indexreg.no, argreg.no);
1110+
regindex++;
1111+
argiter = argiter->next;
1112+
}
1113+
10981114
/* init_cf_copy: */
10991115
m1_reg temp = gen_reg(comp, VAL_INT);
11001116
fprintf(OUT, "\tset_imm I%d, 0, INTERP\n", temp.no);

src/m1.y

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ function_init : return_type TK_IDENT
454454
}
455455
;
456456

457-
/* TODO: parameter handling. */
458457
parameters : /* empty */
459458
{ $$ = NULL; }
460459
| param_list

0 commit comments

Comments
 (0)