diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-11-30 18:02:53 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-11-30 18:02:53 -0500 |
commit | 469ed2a877aeadc5286e08fcaee77ce31268495c (patch) | |
tree | c8f777a196f5cca614bba41b073f75b7fbd52a88 | |
parent | 8f996b4ac75c7c62f04f09fffa81a686c1f74ab6 (diff) |
fixed bug
-rw-r--r-- | decls_cgen.c | 1 | ||||
-rw-r--r-- | parse.c | 11 | ||||
-rw-r--r-- | test.toc | 6 | ||||
-rw-r--r-- | types.c | 2 |
4 files changed, 15 insertions, 5 deletions
diff --git a/decls_cgen.c b/decls_cgen.c index 7fcb106..35ef2b5 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -73,6 +73,7 @@ static bool cgen_decls_decl(CGenerator *g, Declaration *d) { if (!cgen_fn_header(g, &d->expr.fn, d->where, 0, 0)) return false; cgen_write(g, ";"); + cgen_nl(g); fn_exit(&d->expr.fn); } cgen_recurse_subexprs(g, (&d->expr), cgen_decls_expr, cgen_decls_block, cgen_decls_decl); @@ -290,7 +290,9 @@ typedef enum { EXPR_CAN_END_WITH_COMMA = 0x01, /* a comma could end the expression */ EXPR_CAN_END_WITH_LBRACE = 0x02, EXPR_CAN_END_WITH_COLON = 0x04, - EXPR_CAN_END_WITH_DOTDOT = 0x08 + EXPR_CAN_END_WITH_DOTDOT = 0x08, + EXPR_CAN_END_WITH_EQ = 0x10, + /* note that parse_type uses -1 for this */ } ExprEndFlags; /* is_vbs can be NULL */ static Token *expr_find_end(Parser *p, ExprEndFlags flags, bool *is_vbs) { @@ -351,6 +353,10 @@ static Token *expr_find_end(Parser *p, ExprEndFlags flags, bool *is_vbs) { if (brace_level == 0 && square_level == 0 && paren_level == 0 && (flags & EXPR_CAN_END_WITH_DOTDOT)) return token; break; + case KW_EQ: + if (brace_level == 0 && square_level == 0 && paren_level == 0 && (flags & EXPR_CAN_END_WITH_EQ)) + return token; + break; case KW_COLON: if ((flags & EXPR_CAN_END_WITH_COLON) && brace_level == 0 && square_level == 0 && paren_level == 0) @@ -599,7 +605,8 @@ static bool parse_type(Parser *p, Type *type) { break; default: /* TYPE_EXPR */ - if (parse_expr(p, type->expr = parser_new_expr(p), expr_find_end(p, 0, NULL))) { + if (parse_expr(p, type->expr = parser_new_expr(p), + expr_find_end(p, -1 /* end as soon as possible */, NULL))) { type->kind = TYPE_EXPR; } else { tokr_err(t, "Unrecognized type."); @@ -15,12 +15,14 @@ -main @= fn() { - t @= struct { A: int; b: int; }; + +f @= fn() {}; +main @= fn() { + u @= t; x : t; y : u = x; @@ -53,7 +53,7 @@ static bool type_eq(Type *a, Type *b) { case TYPE_TYPE: return true; case TYPE_BUILTIN: return a->builtin == b->builtin; - case TYPE_STRUCT: return false; + case TYPE_STRUCT: return a->struc == b->struc; case TYPE_FN: { if (arr_len(a->fn.types) != arr_len(b->fn.types)) return false; Type *a_types = a->fn.types, *b_types = b->fn.types; |