diff --git a/src/language/ctu/include/ctu/ast.h b/src/language/ctu/include/ctu/ast.h index 64922aad..e596ad7c 100644 --- a/src/language/ctu/include/ctu/ast.h +++ b/src/language/ctu/include/ctu/ast.h @@ -124,7 +124,7 @@ typedef struct ctu_t { /* eCtuDeclVariant */ struct { ctu_t *underlying; - vector_t *cases; + const vector_t *cases; }; /* eCtuVariantCase */ @@ -308,7 +308,7 @@ ctu_t *ctu_decl_typealias(scan_t *scan, where_t where, bool exported, char *name ctu_t *ctu_decl_union(scan_t *scan, where_t where, bool exported, char *name, vector_t *fields); ctu_t *ctu_decl_struct(scan_t *scan, where_t where, bool exported, char *name, vector_t *fields); -ctu_t *ctu_decl_variant(scan_t *scan, where_t where, bool exported, char *name, ctu_t *underlying, vector_t *cases); +ctu_t *ctu_decl_variant(scan_t *scan, where_t where, bool exported, char *name, ctu_t *underlying, const vector_t *cases); /// /// internal components diff --git a/src/language/ctu/src/ast.c b/src/language/ctu/src/ast.c index 19eed2bc..308c357b 100644 --- a/src/language/ctu/src/ast.c +++ b/src/language/ctu/src/ast.c @@ -322,7 +322,7 @@ ctu_t *ctu_decl_struct(scan_t *scan, where_t where, bool exported, char *name, v return ast; } -ctu_t *ctu_decl_variant(scan_t *scan, where_t where, bool exported, char *name, ctu_t *underlying, vector_t *cases) +ctu_t *ctu_decl_variant(scan_t *scan, where_t where, bool exported, char *name, ctu_t *underlying, const vector_t *cases) { ctu_t *ast = ctu_decl(scan, where, eCtuDeclVariant, name, exported); ast->underlying = underlying; diff --git a/src/language/ctu/src/ctu.y b/src/language/ctu/src/ctu.y index e2c94aba..73943a24 100644 --- a/src/language/ctu/src/ctu.y +++ b/src/language/ctu/src/ctu.y @@ -136,12 +136,12 @@ void ctuerror(where_t *where, void *state, scan_t *scan, const char *msg); attrib_args expr_list type_list - variant_field_list opt_variant_field_list + variant_field_list initList attribs attrib attrib_body attrib_list %type - modspec imports opt_type_list opt_expr_list decls + modspec imports opt_type_list opt_expr_list decls opt_variant_field_list /** * order of operations, tightest first @@ -268,7 +268,7 @@ underlying: %empty { $$ = NULL; } | COLON type { $$ = $2; } ; -opt_variant_field_list: %empty { $$ = &gEmptyVector; } +opt_variant_field_list: %empty { $$ = &kEmptyVector; } | variant_field_list { $$ = $1; } ; diff --git a/src/language/ctu/src/sema/expr.c b/src/language/ctu/src/sema/expr.c index 5ffca2b3..c2dc90e0 100644 --- a/src/language/ctu/src/sema/expr.c +++ b/src/language/ctu/src/sema/expr.c @@ -643,7 +643,8 @@ static tree_t *sema_local(ctu_sema_t *sema, const ctu_t *stmt) return tree_stmt_assign(stmt->node, self, value); } - return tree_stmt_block(stmt->node, &gEmptyVector); // TODO: good enough + // TODO: maybe a nop node would be better + return tree_stmt_block(stmt->node, &kEmptyVector); } static tree_t *sema_stmts(ctu_sema_t *sema, const ctu_t *stmt) @@ -685,7 +686,7 @@ static tree_t *sema_while(ctu_sema_t *sema, const ctu_t *stmt) tree_t *save = ctu_current_loop(sema); tree_t *cond = ctu_sema_rvalue(sema, stmt->cond, ctu_get_bool_type()); - tree_t *loop = tree_stmt_loop(stmt->node, cond, tree_stmt_block(stmt->node, &gEmptyVector), + tree_t *loop = tree_stmt_loop(stmt->node, cond, tree_stmt_block(stmt->node, &kEmptyVector), NULL); if (stmt->name != NULL) diff --git a/src/language/pl0/src/sema.c b/src/language/pl0/src/sema.c index 632b9ce9..6a3a8698 100644 --- a/src/language/pl0/src/sema.c +++ b/src/language/pl0/src/sema.c @@ -415,11 +415,10 @@ static void sema_proc(tree_t *sema, tree_t *tree, pl0_t *node) tree_add_local(tree, it); } - tree_t *ret = tree_stmt_return(node->node, tree_expr_unit(node->node, gVoidType)); - vector_t *inner = sema_stmt_vector(nest, node->body); - vector_push(&inner, inner); + // make sure we always have a return statement + tree_t *ret = tree_stmt_return(node->node, tree_expr_unit(node->node, gVoidType)); vector_push(&inner, ret); // make sure we have a return statement