From d984e1585b749f184d2014ffff498ce5f36bcf5a Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sat, 30 Nov 2019 21:11:29 -0500 Subject: fixed was_expr bug --- main.c | 2 +- parse.c | 1 + test.toc | 31 +++++++++++++++++-------------- types.c | 2 ++ 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index 9e388a3..17f0bd1 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,6 @@ /* TODO: -functions returning Types +fix VBS with structs test ArrInt @= Arr(int); packages diff --git a/parse.c b/parse.c index cc198cc..26381ac 100644 --- a/parse.c +++ b/parse.c @@ -945,6 +945,7 @@ static int op_precedence(Keyword op) { static bool parse_expr(Parser *p, Expression *e, Token *end) { Tokenizer *t = p->tokr; e->flags = 0; + e->type.flags = 0; if (end == NULL) return false; e->where = t->token->where; if (end <= t->token) { diff --git a/test.toc b/test.toc index 473e442..ec20c2f 100644 --- a/test.toc +++ b/test.toc @@ -1,11 +1,11 @@ -// puti @= fn(x: int) { -// #C("printf(\"%ld\\n\", (long)x); -// "); -// }; -// putf @= fn(x: float) { -// #C("printf(\"%f\\n\", (double)x); -// "); -// }; +puti @= fn(x: int) { + #C("printf(\"%ld\\n\", (long)x); +"); +}; +putf @= fn(x: float) { + #C("printf(\"%f\\n\", (double)x); +"); +}; // f @= fn(x @ int) Type { // struct { @@ -15,13 +15,16 @@ -f @= fn(s @ Type) Type { -t @= int; -t +pair @= fn(s @ Type) Type { + [2]s }; main @= fn() { -x : f(int); -y : f(int); -z : f(float); +x : pair(int); +y : pair(int); +z : pair(float); +x[0] = 7; +puti(x[0]); +z[0] = 3.3; +putf(z[0]); }; \ No newline at end of file diff --git a/types.c b/types.c index e7bd2ec..282c930 100644 --- a/types.c +++ b/types.c @@ -495,6 +495,7 @@ static bool type_resolve(Typer *tr, Type *t, Location where) { if (!eval_expr(tr->evalr, t->expr, &typeval)) return false; *t = *typeval.type; + assert(t->flags & TYPE_IS_RESOLVED); } break; case TYPE_UNKNOWN: case TYPE_VOID: @@ -726,6 +727,7 @@ static bool types_expr(Typer *tr, Expression *e) { t->kind = TYPE_SLICE; t->slice = typer_malloc(tr, sizeof *t->slice); t->slice->flags = TYPE_IS_RESOLVED; + t->slice->was_expr = NULL; t->slice->kind = TYPE_BUILTIN; t->slice->builtin = BUILTIN_CHAR; t->flags |= TYPE_IS_RESOLVED; -- cgit v1.2.3