From ebed63c4771e83d640ffef3bbcec980f98212365 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Thu, 31 Oct 2019 18:06:06 -0400 Subject: almost fixed the bug --- eval.c | 2 ++ test.toc | 2 ++ types.c | 3 +++ types.h | 4 ++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/eval.c b/eval.c index 86fdc61..b4b747e 100644 --- a/eval.c +++ b/eval.c @@ -1,4 +1,5 @@ static bool types_block(Typer *tr, Block *b); +static bool types_decl(Typer *tr, Declaration *d); static size_t compiler_sizeof(Type *t); static bool eval_block(Evaluator *ev, Block *b, Type *t, Value *v); static bool eval_expr(Evaluator *ev, Expression *e, Value *v); @@ -1010,6 +1011,7 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) { case EXPR_IDENT: { IdentDecl *idecl = ident_decl(e->ident); Declaration *d = idecl->decl; + if (!types_decl(ev->typer, d)) return false; if (idecl->flags & IDECL_FLAG_HAS_VAL) { *v = idecl->val; } else if (d->flags & DECL_FLAG_CONST) { diff --git a/test.toc b/test.toc index 3a17585..c7e4997 100644 --- a/test.toc +++ b/test.toc @@ -7,6 +7,8 @@ Point @= struct { x, y : int; }; + + sum @= fn(p: &Point) int { p.x + p.y }; diff --git a/types.c b/types.c index cdc762b..641b922 100644 --- a/types.c +++ b/types.c @@ -1164,6 +1164,8 @@ static bool types_expr(Typer *tr, Expression *e) { } static bool types_block(Typer *tr, Block *b) { + if (b->flags & BLOCK_FLAG_FOUND_TYPES) + return true; bool success = true; Block *prev_block = tr->block; tr->block = b; @@ -1182,6 +1184,7 @@ static bool types_block(Typer *tr, Block *b) { } block_exit(b, b->stmts); tr->block = prev_block; + b->flags |= BLOCK_FLAG_FOUND_TYPES; return success; } diff --git a/types.h b/types.h index 523f882..2e9383f 100644 --- a/types.h +++ b/types.h @@ -310,9 +310,9 @@ typedef struct Type { } Type; #define BLOCK_FLAG_FN 0x01 - +#define BLOCK_FLAG_FOUND_TYPES 0x02 typedef struct Block { - uint16_t flags; + U16 flags; Location start; Location end; struct Statement *stmts; -- cgit v1.2.3