diff options
-rw-r--r-- | cgen.c | 4 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | std/io.toc | 4 | ||||
-rw-r--r-- | test.toc | 13 | ||||
-rw-r--r-- | types.c | 22 |
5 files changed, 28 insertions, 17 deletions
@@ -1803,7 +1803,7 @@ static void cgen_block(CGenerator *g, Block *b, const char *ret_name, U16 flags) } ++g->indent_lvl; - + arr_foreach(b->stmts, Statement, s) cgen_stmt(g, s); if (b->ret_expr && ret_name) { @@ -1957,6 +1957,8 @@ static void cgen_decl(CGenerator *g, Declaration *d) { if (has_expr) { cgen_val_pre(g, val, type); } + if (d->flags & DECL_IS_CONST) + cgen_write(g, "static "); cgen_type_pre(g, type); cgen_write(g, " "); cgen_ident(g, i); @@ -8,8 +8,6 @@ /* @TODO: -does our use before declare thing work with #include? -allow using constant before declaring it, and do DECL_FINDING_TYPE, for circular dependencies #no_warn start making a standard library... (printf; stringbuilder would be nice to have) if we do #include "foo.toc", bar; and foo.toc fails, bar should be declared as TYPE_UNKNOWN (right now it's undeclared) @@ -13,7 +13,6 @@ unfortunately, we can't use fwrite because MSVC doesn't like it when you use a file handle that's not from the DLL. (i.e. you can't pass your stdout to the imported version of fwrite) */ -/* writes ::= fn(x: []char) { for c := x { toc_putchar(c); @@ -51,9 +50,7 @@ puti ::= fn(x: int) { writei(x); toc_putchar('\n'); } -*/ -/* writef ::= fn(x: float) { fmt := "%f\0"; printf(&fmt[0], x); @@ -62,4 +59,3 @@ putf ::= fn(x: float) { writef(x); toc_putchar('\n'); } -*/ @@ -1 +1,14 @@ #include "std/io.toc", io; + +foo ::= fn() { + x := bar(12); + io.puti(x); +} + +bar ::= fn(x: int) int { + y := x; + io.puti(y); + y +} + +foo(); @@ -845,20 +845,22 @@ top:; t->flags |= TYPE_IS_RESOLVED; /* for function templates */ return true; } else { - if (where.start <= d->where.end) { + if (d->flags & DECL_INFER) { char *s = ident_to_str(i); - err_print(where, "Use of identifier %s before its declaration.", s); - info_print(d->where, "%s will be declared here.", s); + err_print(where, "Use of identifier %s before it has been inferred. You are trying to do stuff with inference which toc doesn't support.", s); free(s); return false; - } else { - if (d->flags & DECL_INFER) { - err_print(where, "Use of identifier before it has been inferred. You are trying to do stuff with inference which toc doesn't support."); - return false; - } - /* let's type the declaration, and redo this (for evaling future functions) */ + } + if ((d->flags & DECL_IS_CONST) && (tr->block == NULL)) { + /* let's type the declaration, and redo this (for evaling future constants) */ if (!types_decl(tr, d)) return false; goto top; + } else { + char *s = ident_to_str(i); + err_print(where, "Use of %s before its declaration.", s); + info_print(d->where, "%s will be declared here.", s); + free(s); + return false; } } } @@ -2074,7 +2076,7 @@ static Status types_expr(Typer *tr, Expression *e) { } if (undeclared) { char *s = cstr(e->ident_str.str, e->ident_str.len); - err_print(e->where, "Undeclared identifier \"%s\".", s); + err_print(e->where, "Undeclared identifier '%s'.", s); free(s); return false; } |