diff --git a/src/ast.c b/src/ast.c index 3e2ae8c..aae73ac 100644 --- a/src/ast.c +++ b/src/ast.c @@ -208,14 +208,17 @@ expr_set_unexpr(M1_compiler *comp, m1_expression *node, m1_expression *exp, m1_u } m1_expression * -funcall(M1_compiler *comp, char *name, m1_expression *args) { +funcall(M1_compiler *comp, m1_object *fun, m1_expression *args) { m1_expression *expr = expression(comp, EXPR_FUNCALL); expr->expr.f = (m1_funcall *)m1_malloc(sizeof(m1_funcall)); - expr->expr.f->name = name; + + + expr->expr.f->name = fun->obj.name; +// expr->expr.f->name = name; expr->expr.f->arguments = args; /* enter name of function to invoke into constant table. */ - sym_enter_chunk(comp, &comp->currentchunk->constants, name); + sym_enter_chunk(comp, &comp->currentchunk->constants, fun->obj.name); return expr; } diff --git a/src/ast.h b/src/ast.h index 865746d..f5fb53c 100644 --- a/src/ast.h +++ b/src/ast.h @@ -321,7 +321,7 @@ extern int yyget_lineno(yyscan_t yyscanner); extern m1_chunk *chunk(M1_compiler *comp, char *rettype, char *name); extern m1_expression *expression(M1_compiler *comp, m1_expr_type type); -extern m1_expression *funcall(M1_compiler *comp, char *name, m1_expression *args); +extern m1_expression *funcall(M1_compiler *comp, m1_object *fun, m1_expression *args); extern m1_object *object(M1_compiler *comp, m1_object_type type); extern void obj_set_ident(m1_object *node, char *ident); diff --git a/src/gencode.c b/src/gencode.c index e28945d..c290c5c 100644 --- a/src/gencode.c +++ b/src/gencode.c @@ -81,8 +81,8 @@ use_reg(M1_compiler *comp, m1_valuetype type) { i++; } - if (i >= REG_NUM) fprintf(stderr, "Out of registers!\n"); - else fprintf(stderr, "Allocating register %d\n", i); + //if (i >= REG_NUM) fprintf(stderr, "Out of registers!\n"); + //else fprintf(stderr, "Allocating register %d\n", i); /* set the register to "used". */ registers[type][i] = REG_USED; @@ -113,10 +113,11 @@ static void unuse_reg(M1_compiler *comp, m1_reg r) { if (registers[r.type][r.no] != REG_SYMBOL) { - fprintf(stderr, "Unusing %d for good\n", r.no); + //fprintf(stderr, "Unusing %d for good\n", r.no); registers[r.type][r.no] = REG_UNUSED; } /* XXX this is for debugging. */ + /* int i; for (i = 0; i < 40; i++) fprintf(stderr, "%2d ", i); @@ -126,6 +127,7 @@ unuse_reg(M1_compiler *comp, m1_reg r) { fprintf(stderr, "%2d ", registers[r.type][i]); } fprintf(stderr, "\n\n"); + */ } /* @@ -1404,14 +1406,16 @@ gencode_break(M1_compiler *comp) { static void gencode_funcall(M1_compiler *comp, m1_funcall *f) { - m1_symbol *fun = sym_find_chunk(&comp->currentchunk->constants, f->name); + m1_symbol *fun; + fun = sym_find_chunk(&comp->currentchunk->constants, f->name); m1_reg pc_reg, cont_offset, return_reg; - if (fun == NULL) { /* XXX need to check in semcheck */ + if (fun == NULL) { // XXX need to check in semcheck fprintf(stderr, "Cant find function '%s'\n", f->name); ++comp->errors; return; } + m1_reg cf_reg = use_reg(comp, VAL_CHUNK); diff --git a/src/m1.y b/src/m1.y index fde8197..f76d153 100644 --- a/src/m1.y +++ b/src/m1.y @@ -719,10 +719,9 @@ default_case: /* empty */ | "default" ':' statements { $$ = $3; } ; - -/* TODO: at some point we want x.y(); replace TK_IDENT with "lhs". Get this working first though*/ -function_call_expr : TK_IDENT '(' arguments ')' - { $$ = funcall((M1_compiler *)yyget_extra(yyscanner), $1, $3); } + +function_call_expr : lhs '(' arguments ')' + { $$ = funcall((M1_compiler *)yyget_extra(yyscanner), $1->expr.t, $3); } ; function_call_stat : function_call_expr ';' diff --git a/src/semcheck.c b/src/semcheck.c index 39e48c2..473cef5 100644 --- a/src/semcheck.c +++ b/src/semcheck.c @@ -52,7 +52,8 @@ type_error_extra(M1_compiler *comp, unsigned line, char *msg, ...) { for (p = msg; *p != '\0'; p++) { if (*p != '%') { - putchar(*p); + putc(*p, stderr); + continue; } switch (*++p) { @@ -76,6 +77,7 @@ type_error_extra(M1_compiler *comp, unsigned line, char *msg, ...) { } } + fprintf(stderr, "\n"); va_end(argp); } @@ -409,7 +411,7 @@ check_switch(M1_compiler *comp, m1_switch *s, unsigned line) { (void)pop(comp->breakstack); } -static void +static m1_decl * check_newexpr(M1_compiler *comp, m1_newexpr *n, unsigned line) { assert(comp != NULL); assert(n != NULL); @@ -419,7 +421,7 @@ check_newexpr(M1_compiler *comp, m1_newexpr *n, unsigned line) { if (n->typedecl == NULL) { type_error_extra(comp, line, "Cannot find type '%s' requested for in new-statement\n", n->type); } - + return n->typedecl; } static void @@ -551,7 +553,7 @@ check_expr(M1_compiler *comp, m1_expression *e) { break; case EXPR_NEW: - check_newexpr(comp, e->expr.n, e->line); + return check_newexpr(comp, e->expr.n, e->line); break; case EXPR_PRINT: check_expr(comp, e->expr.e); diff --git a/t/pmc.m1 b/t/pmc.m1 index d3b994e..4b5b970 100644 --- a/t/pmc.m1 +++ b/t/pmc.m1 @@ -11,6 +11,9 @@ int main() { print("1..1\n"); print("ok 1 - PMC parsed correctly\n"); + integer i; + i = new integer(); +// i.init(); }