summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.c8
-rw-r--r--test.toc31
-rw-r--r--types.c33
3 files changed, 38 insertions, 34 deletions
diff --git a/parse.c b/parse.c
index 3e5b363..2527b0f 100644
--- a/parse.c
+++ b/parse.c
@@ -608,12 +608,18 @@ static bool parse_type(Parser *p, Type *type) {
/* help cgen out */
struc->c.id = 0;
struc->fields = NULL;
+ struc->params = NULL;
struc->where = parser_mk_loc(p);
struc->where.start = t->token;
++t->token;
+ if (token_is_kw(t->token, KW_LPAREN)) {
+ ++t->token;
+ if (!parse_decl_list(p, &struc->params, DECL_END_RPAREN_COMMA))
+ return false;
+ }
if (!token_is_kw(t->token, KW_LBRACE)) {
- tokr_err(t, "Expected { or ( to follow struct.");
+ tokr_err(t, "Expected { to follow struct.");
return false;
}
++t->token;
diff --git a/test.toc b/test.toc
index 75bdad5..ba3ef1b 100644
--- a/test.toc
+++ b/test.toc
@@ -1,28 +1,11 @@
-io ::= nms {
- #include "std/io.toc";
-};
-
-ll ::= struct {
- head : int;
- tail : ≪
-};
+// io ::= nms {
+ // #include "std/io.toc";
+// };
-slice_to_ll ::= fn(x: []int) l: ll {
- if x.len == 1 {
- l.head = x[0];
- l.tail = 0 as ≪
- return;
- }
- l.head = x[0];
- l.tail = new(ll);
- *l.tail = slice_to_ll(x[1:]);
+foo ::= struct(t::Type) {
+ x: t;
};
main ::= fn() {
- a : []int = new(int,3);
- a[0] = 1;
- a[1] = 2;
- a[2] = 3;
- l : ll = slice_to_ll(a);
- io.puti(l.tail.tail.head);
-};
+
+}; \ No newline at end of file
diff --git a/types.c b/types.c
index 56411b6..0f89af7 100644
--- a/types.c
+++ b/types.c
@@ -572,7 +572,11 @@ static bool type_resolve_(Typer *tr, Type *t, Location where, bool is_reference)
return false;
break;
case TYPE_STRUCT:
- /* TODO: lookup args! */
+ if (t->struc.def->params) {
+ err_print(where, "Expected arguments to structure.");
+ info_print(t->struc.def->where, "Structure was declared here.");
+ return false;
+ }
arr_foreach(t->struc.def->fields, Field, f) {
if (!type_resolve_(tr, &f->type, where, is_reference))
return false;
@@ -2186,12 +2190,19 @@ static bool types_expr(Typer *tr, Expression *e) {
}
break;
}
- case EXPR_TYPE:
- if (!type_resolve(tr, &e->typeval, e->where))
+ case EXPR_TYPE: {
+ Type *tval = &e->typeval;
+ if (tval->kind == TYPE_STRUCT && tval->struc.def->params) {
+ /* don't try to resolve this */
+ t->kind = TYPE_BUILTIN;
+ t->builtin = BUILTIN_TYPE;
+ break;
+ }
+ if (!type_resolve(tr, tval, e->where))
return false;
t->kind = TYPE_BUILTIN;
t->builtin = BUILTIN_TYPE;
- break;
+ } break;
case EXPR_NMS: {
e->nms.body.flags |= BLOCK_IS_NMS;
if (!types_block(tr, &e->nms.body))
@@ -2368,11 +2379,15 @@ static bool types_decl(Typer *tr, Declaration *d) {
if (type_is_builtin(t, BUILTIN_TYPE)) {
if (d->flags & DECL_HAS_EXPR) {
Value *val = d->type.kind == TYPE_TUPLE ? &d->val.tuple[i] : &d->val;
- if (!type_resolve(tr, val->type, d->where)) return false;
- if (val->type->kind == TYPE_TUPLE) {
- err_print(d->where, "You can't declare a new type to be a tuple.");
- success = false;
- goto ret;
+ if (val->type->kind == TYPE_STRUCT && val->type->struc.def->params) {
+ /* don't resolve it because it's not really complete */
+ } else {
+ if (!type_resolve(tr, val->type, d->where)) return false;
+ if (val->type->kind == TYPE_TUPLE) {
+ err_print(d->where, "You can't declare a new type to be a tuple.");
+ success = false;
+ goto ret;
+ }
}
}
} else if (!(d->flags & DECL_IS_CONST) && t->kind == TYPE_FN && t->fn.constness) {