Skip to content

Commit

Permalink
add a bit more space to annotations. Still experimenting with this. A…
Browse files Browse the repository at this point in the history
…lso, fix a bug: don't forget to typecheck arguments to a funcall, as this sets pointers to the symbols in the symtab, which is essential. Add a test for this.
  • Loading branch information
kjs committed Jun 13, 2012
1 parent 1fdc321 commit a7e7d51
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/ast.c
Expand Up @@ -35,7 +35,8 @@ m1_malloc(size_t size) {


m1_chunk *
chunk(ARGIN_NOTNULL(M1_compiler *comp), ARGIN(char *rettype), ARGIN_NOTNULL(char *name)) {
chunk( ARGIN_NOTNULL( M1_compiler * const comp ), ARGIN( char *rettype ), ARGIN_NOTNULL( char *name ) )
{
m1_chunk *c = (m1_chunk *)m1_malloc(sizeof(m1_chunk));
c->rettype = rettype;
c->name = name;
Expand All @@ -53,9 +54,11 @@ chunk(ARGIN_NOTNULL(M1_compiler *comp), ARGIN(char *rettype), ARGIN_NOTNULL(char
}

m1_expression *
block(ARGIN_NOTNULL(M1_compiler *comp)) {
block( ARGIN_NOTNULL( M1_compiler *comp ) )
{
m1_expression *expr = expression(comp, EXPR_BLOCK);
expr->expr.blck = (m1_block *)m1_malloc(sizeof(m1_block));
expr->expr.blck = (m1_block *)m1_malloc(sizeof(m1_block));

init_symtab(&expr->expr.blck->locals);
return expr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast.h
Expand Up @@ -323,7 +323,7 @@ typedef struct m1_expression {
extern int yyget_lineno(yyscan_t yyscanner);

//extern m1_chunk *chunk(M1_compiler *comp, char *rettype, char *name);
extern m1_chunk *chunk(ARGIN_NOTNULL(M1_compiler *comp), ARGIN(char *rettype), ARGIN_NOTNULL(char *name));
extern m1_chunk *chunk(ARGIN_NOTNULL(M1_compiler * const comp), ARGIN(char *rettype), ARGIN_NOTNULL(char *name));

//extern m1_expression *block(M1_compiler *comp);
extern m1_expression *block(ARGIN_NOTNULL(M1_compiler *comp));
Expand Down
1 change: 1 addition & 0 deletions src/gencode.c
Expand Up @@ -409,6 +409,7 @@ OBJECT_LINK-----> L1
{
m1_reg reg;

fprintf(stderr, "[object_main] handling '%s'\n", obj->obj.name);
assert(obj->obj.field != NULL);
assert(obj->sym != NULL);
assert(obj->sym->typedecl != NULL);
Expand Down
5 changes: 5 additions & 0 deletions src/semcheck.c
Expand Up @@ -145,8 +145,11 @@ check_obj(M1_compiler *comp, m1_object *obj, unsigned line) {
type_error_extra(comp, line, "Undeclared variable '%s'\n", obj->obj.name);
}
else { /* found symbol, now link it to the object node. */
fprintf(stderr, "[semcheck] found var '%s'\n", obj->obj.name);
assert(sym != NULL);
obj->sym = sym;
t = sym->typedecl;
assert(t != NULL);
}
break;
}
Expand Down Expand Up @@ -383,6 +386,8 @@ check_funcall(M1_compiler *comp, m1_funcall *f, unsigned line) {
assert(comp != NULL);
assert(f != NULL);
assert(line != 0);
/* check arguments of the function call; this is a list of m1_expressions. */
check_exprlist(comp, f->arguments);

/* find declaration of function, check arguments against function signature. */
/* TODO */
Expand Down
17 changes: 17 additions & 0 deletions t/stringparam.m1
@@ -0,0 +1,17 @@
int main() {
print("1..2\n");
string s = "ok 1\n";
foo(s);
}

int foo(string s) {

print(s);
string t;
t = "ok 2\n";
bar(t);
}

int bar(string s) {
print(s);
}

0 comments on commit a7e7d51

Please sign in to comment.