summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--decls_cgen.c1
-rw-r--r--parse.c11
-rw-r--r--test.toc6
-rw-r--r--types.c2
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);
diff --git a/parse.c b/parse.c
index 68e1652..cc198cc 100644
--- a/parse.c
+++ b/parse.c
@@ -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.");
diff --git a/test.toc b/test.toc
index 5fc72d4..91c14b9 100644
--- a/test.toc
+++ b/test.toc
@@ -15,12 +15,14 @@
-main @= fn() {
-
t @= struct {
A: int;
b: int;
};
+
+f @= fn() {};
+main @= fn() {
+
u @= t;
x : t;
y : u = x;
diff --git a/types.c b/types.c
index 5dac5e7..2384f32 100644
--- a/types.c
+++ b/types.c
@@ -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;