diff options
-rw-r--r-- | eval.c | 6 | ||||
-rw-r--r-- | test.toc | 29 | ||||
-rw-r--r-- | types.c | 4 |
3 files changed, 29 insertions, 10 deletions
@@ -1084,9 +1084,7 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) { switch (e->kind) { case EXPR_UNARY_OP: { Value of; - if (e->unary.op != UNARY_ADDRESS) { - if (!eval_expr(ev, e->unary.of, &of)) return false; - } + if (!eval_expr(ev, e->unary.of, &of)) return false; Type *of_type = &e->unary.of->type; switch (e->unary.op) { case UNARY_ADDRESS: { @@ -1095,7 +1093,7 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) { if (!eval_expr(ev, e->unary.of, &of)) return false; /* "address" of type (pointer to type) */ v->type = evalr_malloc(ev, sizeof *v->type); - v->type->flags = 0; + v->type->flags = TYPE_IS_RESOLVED; v->type->kind = TYPE_PTR; v->type->ptr = of.type; break; @@ -1,11 +1,30 @@ +#include "std/io.toc"; +/* -Point ::= struct { - a ::= 3; +sum ::= fn(n::=, t::=, a: [n]t) t { + total : t = 0; + for x := a { + total += x; + } + total } - main ::= fn() { - use p: Point; - a; + t ::= int; + numbers : [1000]t; + for x, i : (&t, t) = &numbers { + *x = i; + } + puti(sum(numbers) as int); + +} +*/ +ll ::= struct (t::Type) { + head: t; + next: &ll(t); +} + +main ::= fn() { + x: ll(int); } @@ -887,7 +887,7 @@ static Status type_resolve(Typer *tr, Type *t, Location where) { } } if (!(t->flags & TYPE_IS_RESOLVED)) { - /* this can happen with functions returning parameterized structs */ + /* this can happen with functions returning parameterized structs or pointers */ if (!type_resolve(tr, t, where)) return false; } @@ -1646,6 +1646,8 @@ static Status types_expr(Typer *tr, Expression *e) { fo_type_tuple = header_type->tuple; val_type = &fo_type_tuple[0]; index_type = &fo_type_tuple[1]; + assert(val_type->flags & TYPE_IS_RESOLVED); + assert(index_type->flags & TYPE_IS_RESOLVED); if (!type_is_int(index_type)) { char *s = type_to_str(index_type); err_print(header->where, "Expected index type of for loop to be a builtin integer type, but it's %s.", s); |