Skip to content

Commit

Permalink
🎨 rename Stmt->pos to loc
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Jan 30, 2024
1 parent 56d8b92 commit aa633ad
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 58 deletions.
6 changes: 3 additions & 3 deletions include/absyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ enum ae_pp_type {
};

#define MK_STMT_PP(_type, _pos, ...) (struct Stmt_){ .stmt_type = ae_stmt_pp, \
.d = { .stmt_pp = { __VA_ARGS__, .pp_type = ae_pp_##_type, }}, .pos = _pos }
.d = { .stmt_pp = { __VA_ARGS__, .pp_type = ae_pp_##_type, }}, .loc = _pos }
struct Stmt_PP_ {
m_str data;
Exp exp;
Expand Down Expand Up @@ -677,8 +677,8 @@ struct Stmt_ {
struct Stmt_Defer_ stmt_defer;
struct Spread_Def_ stmt_spread;
} d;
loc_t pos; ///< position
ae_stmt_t stmt_type;
loc_t loc; ///< position
ae_stmt_t stmt_type;
};

static inline Stmt stmt_self(const void *data) {
Expand Down
2 changes: 1 addition & 1 deletion src/ast_cpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ ANN static void cpy_stmt2(MemPool p, const Stmt a, const Stmt src) {
break;
}
a->stmt_type = src->stmt_type;
a->pos = src->pos;
a->loc = src->loc;
}

ANN Func_Def cpy_func_def(MemPool p, const Func_Def src) {
Expand Down
6 changes: 3 additions & 3 deletions 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, const 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, struct Stmt_, 1);
struct Stmt_ stmt = { .d = { .stmt_exp = { .val = exp }}, .stmt_type=ae_stmt_return, .pos = loc };
struct Stmt_ stmt = { .d = { .stmt_exp = { .val = exp }}, .stmt_type=ae_stmt_return, .loc = loc };
mp_vector_set(code, struct Stmt_, 0, stmt);
a->d.exp_lambda.def = new_func_def(p, base, code);
return a;
Expand Down Expand Up @@ -335,7 +335,7 @@ AST_NEW(Stmt, stmt_code, const Stmt_List list, const loc_t loc) {
AST_NEW(Stmt, stmt, const ae_stmt_t type, const loc_t loc) {
Stmt a = mp_calloc(p, Stmt);
a->stmt_type = type;
a->pos = loc;
a->loc = loc;
return a;
}

Expand Down Expand Up @@ -376,7 +376,7 @@ AST_NEW(Stmt, stmt_loop, const Exp cond, const Stmt body,
}

AST_NEW(Stmt, stmt_try, const restrict Stmt stmt, const Handler_List handler) {
Stmt a = new_stmt(p, ae_stmt_try, stmt->pos);
Stmt a = new_stmt(p, ae_stmt_try, stmt->loc);
a->d.stmt_try.stmt = cpy_stmt3(p, stmt);
a->d.stmt_try.handler = handler;
return a;
Expand Down
2 changes: 1 addition & 1 deletion src/defer.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static loc_t defer_func(void* arg NUSED) { return (loc_t){}; }
#define defer_stmt_exp defer_func

ANN static loc_t defer_stmt_return(const Stmt_Exp stmt) {
return stmt_self(stmt)->pos;
return stmt_self(stmt)->loc;
}

ANN static loc_t defer_stmt_defer(const Stmt_Defer stmt) {
Expand Down
50 changes: 25 additions & 25 deletions src/gwion.y
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ fptr_list: fptr_arg { YYLIST_INI(Arg, $$, $1); }

code_stmt
: "{" "}" {
$$ = (struct Stmt_) { .stmt_type = ae_stmt_code, .pos = @$}; }
$$ = (struct Stmt_) { .stmt_type = ae_stmt_code, .loc = @$}; }
| "{" stmt_list "}" {
$$ = (struct Stmt_) { .stmt_type = ae_stmt_code, .d = { .stmt_code = { .stmt_list = $2 }}, .pos = @$}; };
$$ = (struct Stmt_) { .stmt_type = ae_stmt_code, .d = { .stmt_code = { .stmt_list = $2 }}, .loc = @$}; };

code_list
: "{" "}" { $$ = new_mp_vector(mpool(arg), struct Stmt_, 0); }
Expand Down Expand Up @@ -435,13 +435,13 @@ spread_stmt: "..." ID ":" id_list "{" {lex_spread(((Scanner*)scan));} SPREAD {
.list = $4,
.data = $7,
};
$$ = (struct Stmt_) { .stmt_type = ae_stmt_spread, .d = { .stmt_spread = spread }, .pos = @2};
$$ = (struct Stmt_) { .stmt_type = ae_stmt_spread, .d = { .stmt_spread = spread }, .loc = @2};
}

retry_stmt: "retry" ";" {
if(!arg->handling)
{ parser_error(&@1, arg, "`retry` outside of `handle` block", 0); YYERROR; }
$$ = (struct Stmt_){ .stmt_type=ae_stmt_retry, .pos=@1};
$$ = (struct Stmt_){ .stmt_type=ae_stmt_retry, .loc=@1};
};
handler: "handle" { arg->handling = true; } opt_id stmt { $$ = (Handler){ .tag = MK_TAG($3, $3 ? @3 :@1), .stmt = cpy_stmt3(mpool(arg), &$4) }; arg->handling = false; };
handler_list: handler {
Expand All @@ -466,7 +466,7 @@ mp_vector_add(mpool(arg), &$1.handlers, Handler, $2);
}
try_stmt: "try" stmt handler_list { $$ = (struct Stmt_){ .stmt_type = ae_stmt_try,
.d = { .stmt_try = { .stmt = cpy_stmt3(mpool(arg), &$2), .handler = $3.handlers, }},
.pos = @1};
.loc = @1};
};

opt_id: ID | { $$ = NULL; };
Expand Down Expand Up @@ -501,7 +501,7 @@ match_case_stmt
.when = $3,
.list = $5
}},
.pos = @1
.loc = @1
};
};

Expand All @@ -515,7 +515,7 @@ match_stmt: "match" exp "{" match_list "}" "where" stmt {
.list = $4,
.where = cpy_stmt3(mpool(arg), &$7)
}},
.pos = @1
.loc = @1
};
}
|
Expand All @@ -525,7 +525,7 @@ match_stmt: "match" exp "{" match_list "}" "where" stmt {
.cond = $2,
.list = $4,
}},
.pos = @1
.loc = @1
};
};

Expand All @@ -541,7 +541,7 @@ loop_stmt
.cond = $3,
.body = cpy_stmt3(mpool(arg), &$5)
}},
.pos = @1
.loc = @1
};
}
| "do" stmt flow exp ";"
Expand All @@ -551,7 +551,7 @@ loop_stmt
.body = cpy_stmt3(mpool(arg), &$2),
.is_do = true
}},
.pos = @1
.loc = @1
};
}
| "for" "(" exp_stmt exp_stmt ")" stmt
Expand All @@ -561,7 +561,7 @@ loop_stmt
.c2 = cpy_stmt3(mpool(arg), &$4),
.body = cpy_stmt3(mpool(arg), &$6),
}},
.pos = @1
.loc = @1
};
}
| "for" "(" exp_stmt exp_stmt exp ")" stmt
Expand All @@ -572,7 +572,7 @@ loop_stmt
.c3 = $5,
.body = cpy_stmt3(mpool(arg), &$7),
}},
.pos = @1
.loc = @1
};
}
| "foreach" "(" ID ":" opt_var binary_exp ")" stmt
Expand All @@ -582,7 +582,7 @@ loop_stmt
.exp = $6,
.body = cpy_stmt3(mpool(arg), &$8),
}},
.pos = @1
.loc = @1
};
// what to do with opt_var?
// list rem?
Expand All @@ -594,7 +594,7 @@ loop_stmt
.exp = $8,
.body = cpy_stmt3(mpool(arg), &$10),
}},
.pos = @1
.loc = @1
};
$$.d.stmt_each.idx = mp_malloc(mpool(arg), EachIdx);
$$.d.stmt_each.idx->var = (Var_Decl){.tag=MK_TAG($3, @3)};
Expand All @@ -608,7 +608,7 @@ loop_stmt
.cond = $3,
.body = cpy_stmt3(mpool(arg), &$5)
}},
.pos = @1
.loc = @1
};
}
| "repeat" "(" ID "," binary_exp ")" stmt
Expand All @@ -617,7 +617,7 @@ loop_stmt
.cond = $5,
.body = cpy_stmt3(mpool(arg), &$7)
}},
.pos = @1
.loc = @1
};
$$.d.stmt_loop.idx = mp_malloc(mpool(arg), EachIdx);
$$.d.stmt_loop.idx->var = (Var_Decl){ .tag = MK_TAG($3, @3) };
Expand All @@ -632,7 +632,7 @@ defer_stmt: "defer" stmt {
}
$$ = (struct Stmt_) { .stmt_type = ae_stmt_defer,
.d = { .stmt_defer = { .stmt = cpy_stmt3(mpool(arg), &$2) }},
.pos = @1
.loc = @1
};
};

Expand All @@ -643,7 +643,7 @@ selection_stmt
.cond = $3,
.if_body = cpy_stmt3(mpool(arg), &$5)
}},
.pos = @1
.loc = @1
};
}
| "if" "(" exp ")" stmt "else" stmt
Expand All @@ -653,39 +653,39 @@ selection_stmt
.if_body = cpy_stmt3(mpool(arg), &$5),
.else_body = cpy_stmt3(mpool(arg), &$7)
}},
.pos = @1
.loc = @1
};
};

breaks: "break" { $$ = ae_stmt_break; } | CONTINUE { $$ = ae_stmt_continue; };
jump_stmt
: "return" exp ";" { $$ = (struct Stmt_) { .stmt_type = ae_stmt_return,
.d = { .stmt_exp = { .val = $2 }},
.pos = @1
.loc = @1
};
}
| "return" ";" { $$ = (struct Stmt_) { .stmt_type = ae_stmt_return,
.pos = @1
.loc = @1
};
}
| breaks decimal ";" { $$ = (struct Stmt_) { .stmt_type = $1,
.d = { .stmt_index = { .idx = $2.num }},
.pos = @1
.loc = @1
};
}
| breaks ";" { $$ = (struct Stmt_) { .stmt_type = $1,
.d = { .stmt_index = { .idx = -1 }},
.pos = @1 };
.loc = @1 };
};

exp_stmt
: exp ";" { $$ = (struct Stmt_) { .stmt_type = ae_stmt_exp,
.d = { .stmt_exp = { .val = $1 }},
.pos = @1
.loc = @1
};
}
| ";" { $$ = (struct Stmt_) { .stmt_type = ae_stmt_exp,
.pos = @1
.loc = @1
};
};

Expand Down
Loading

0 comments on commit aa633ad

Please sign in to comment.