diff --git a/include/absyn.h b/include/absyn.h index 4aa2275d..1467f097 100644 --- a/include/absyn.h +++ b/include/absyn.h @@ -682,6 +682,7 @@ struct Stmt { .d = { __VA_ARGS__ }, .loc = _loc } #define MK_STMT_PP(_type, _pos, ...) MK_STMT(ae_stmt_pp, _pos, .stmt_pp = { .pp_type = ae_pp_##_type, __VA_ARGS__ }) #define MK_STMT_EXP(_pos, _exp) MK_STMT(ae_stmt_exp, _pos, .stmt_exp = { .val = _exp }) +#define MK_STMT_RETURN(_pos, _exp) MK_STMT(ae_stmt_return, _pos, .stmt_exp = { .val = _exp }) static inline Stmt* stmt_self(const void *data) { return container_of((char *)data, Stmt, d); diff --git a/main.c b/main.c index af773c16..b0e3cbc7 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,7 @@ #include "gwion_ast.h" #include "parser.h" int main(int argc, char **argv) { -// MemPool p = mempool_ini(sizeof(struct Exp_)); +// MemPool p = mempool_ini(sizeof(Exp)); MemPool p = mempool_ini(1024); SymTable *st = new_symbol_table(p, 65536); struct PPArg_ ppa; diff --git a/src/ast_new.c b/src/ast_new.c index 8dd86ffd..f6483b65 100644 --- a/src/ast_new.c +++ b/src/ast_new.c @@ -52,7 +52,7 @@ AST_NEW(Exp*, exp_lambda2, const Symbol xid, const Arg_List args, Exp* exp, Func_Base *base = new_func_base(p, NULL, xid, args, ae_flag_none, loc); base->fbflag |= fbflag_lambda; Stmt_List code = new_mp_vector(p, Stmt, 1); - Stmt stmt = { .d = { .stmt_exp = { .val = exp }}, .stmt_type=ae_stmt_return, .loc = loc }; + Stmt stmt = MK_STMT_RETURN(loc, exp); mp_vector_set(code, Stmt, 0, stmt); a->d.exp_lambda.def = new_func_def(p, base, code); return a; diff --git a/src/gwion.y b/src/gwion.y index 652e94e4..cf21cd35 100644 --- a/src/gwion.y +++ b/src/gwion.y @@ -628,8 +628,8 @@ selection_stmt breaks: "break" { $$ = ae_stmt_break; } | CONTINUE { $$ = ae_stmt_continue; }; jump_stmt - : "return" exp ";" { $$ = MK_STMT(ae_stmt_return, @1, .stmt_exp = { .val = $2}); } - | "return" ";" { $$ = MK_STMT(ae_stmt_return, @1); } + : "return" exp ";" { $$ = MK_STMT_RETURN(@1, $2); } + | "return" ";" { $$ = MK_STMT_RETURN(@1, NULL); } | breaks decimal ";" { $$ = MK_STMT($1, @1, .stmt_index = { .idx = $2.num });} | breaks ";" { $$ = MK_STMT($1, @1, .stmt_index = { .idx = -1 });} diff --git a/src/parser.c b/src/parser.c index 38ea652a..f6080923 100644 --- a/src/parser.c +++ b/src/parser.c @@ -3487,13 +3487,13 @@ mp_vector_add(mpool(arg), &(yyvsp[-1].handler_list).handlers, Handler, (yyvsp[0] case 132: /* jump_stmt: "return" exp ";" */ #line 631 "src/gwion.y" - { (yyval.stmt) = MK_STMT(ae_stmt_return, (yylsp[-2]), .stmt_exp = { .val = (yyvsp[-1].exp)}); } + { (yyval.stmt) = MK_STMT_RETURN((yylsp[-2]), (yyvsp[-1].exp)); } #line 3492 "src/parser.c" break; case 133: /* jump_stmt: "return" ";" */ #line 632 "src/gwion.y" - { (yyval.stmt) = MK_STMT(ae_stmt_return, (yylsp[-1])); } + { (yyval.stmt) = MK_STMT_RETURN((yylsp[-1]), NULL); } #line 3498 "src/parser.c" break;