summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--identifiers.c14
-rw-r--r--test.toc14
-rw-r--r--toc.c2
-rw-r--r--types.c4
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;
}