Skip to content

Commit

Permalink
🔥 more convenience macros
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Jan 31, 2024
1 parent 1c3afd6 commit 0fc5575
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/absyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ast_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/gwion.y
Original file line number Diff line number Diff line change
Expand Up @@ -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 });}

Expand Down
4 changes: 2 additions & 2 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 0fc5575

Please sign in to comment.