From cc33de45174358c13eea4fecaa5f10b094048020 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Thu, 31 Oct 2019 22:42:31 -0400 Subject: fixed some bugs involving trying to call future functions at compile time; not done yet --- identifiers.c | 14 ++++++-------- test.toc | 14 +++++++++----- toc.c | 2 +- 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; } diff --git a/test.toc b/test.toc index 7991086..2aaca38 100644 --- a/test.toc +++ b/test.toc @@ -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); -}; + diff --git a/toc.c b/toc.c index 243baaa..85c0404 100644 --- a/toc.c +++ b/toc.c @@ -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; } diff --git a/types.c b/types.c index ba82ed0..b64fb36 100644 --- a/types.c +++ b/types.c @@ -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; } -- cgit v1.2.3