diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-10-31 22:42:31 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-10-31 22:42:31 -0400 |
commit | cc33de45174358c13eea4fecaa5f10b094048020 (patch) | |
tree | 0d6767ac52a492f9afd093bf72ace8601370e1ac | |
parent | 21b42cd9099d25b89f20789bf75f0833f2a5a980 (diff) |
fixed some bugs involving trying to call future functions at compile time; not done yet
-rw-r--r-- | identifiers.c | 14 | ||||
-rw-r--r-- | test.toc | 14 | ||||
-rw-r--r-- | toc.c | 2 | ||||
-rw-r--r-- | types.c | 4 |
4 files changed, 19 insertions, 15 deletions
diff --git a/identifiers.c b/identifiers.c index 0465e12..d86dba1 100644 --- a/identifiers.c +++ b/identifiers.c @@ -177,13 +177,15 @@ static void idents_test(void) { idents_free(&ids); } -/* if i has a non-constant declaration, returns NULL. */ -static Value *ident_decl_val(Identifier i) { + +static inline Type *ident_typeval(Identifier i) { + Value *val; IdentDecl *idecl = ident_decl(i); if (!idecl) return NULL; Declaration *d = idecl->decl; if (!(d->flags & DECL_FLAG_CONST)) return NULL; + assert(d->flags & DECL_FLAG_FOUND_TYPE); if (d->type.kind == TYPE_TUPLE) { size_t idx; for (idx = 0; idx < arr_len(d->idents); idx++) { @@ -191,13 +193,9 @@ static Value *ident_decl_val(Identifier i) { break; } assert(idx < arr_len(d->idents)); - return &d->val.tuple[idx]; - } else return &d->val; -} + val = &d->val.tuple[idx]; + } else val = &d->val; -static inline Type *ident_typeval(Identifier i) { - Value *val = ident_decl_val(i); - if (!val) return NULL; return val->type; } @@ -1,8 +1,16 @@ + + + puti @= fn(x: int) { #C("printf(\"%ld\\n\", (long)x); "); }; +main @= fn() { +// puti(somesum()); +foo @= somesum(); +// puti(foo); +}; Point @= struct { x, y : int; }; @@ -16,8 +24,4 @@ somesum @= fn() int { total := sum(&p); total }; -main @= fn() { -// puti(somesum()); -foo @= somesum(); -// puti(foo); -}; + @@ -25,7 +25,7 @@ static Type *type_inner(Type *t) { - while (t->kind == TYPE_USER) + while (t && t->kind == TYPE_USER) t = ident_typeval(t->user.name); return t; } @@ -294,7 +294,9 @@ static bool type_of_ident(Typer *tr, Location where, Identifier i, Type *t) { info_print(d->where, "%s will be declared here.", s); free(s); } else { - err_print(d->where, "Declaration type not found yet, even though it has passed.\nThis should not happen."); + /* let's type the declaration, and redo this (for evaling future functions) */ + if (!types_decl(tr, d)) return false; + return type_of_ident(tr, where, i, t); } return false; } |