From 582b17bf533b14f60a97f60baecd80826ec99fb1 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sat, 23 Nov 2019 18:37:05 +0100 Subject: [PATCH] :art: Use prefix in pass macros --- ast | 2 +- include/parse.h | 14 +++++++------- include/traverse.h | 8 ++++---- src/emit/emit.c | 6 +++--- src/import/item.c | 2 +- src/lib/tuple.c | 2 +- src/parse/check.c | 15 +++++++-------- src/parse/scan1.c | 2 +- src/parse/scan2.c | 2 +- src/parse/traverse.c | 8 ++++---- 10 files changed, 30 insertions(+), 31 deletions(-) diff --git a/ast b/ast index 2ed49910..820ad7c1 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 2ed499104f6366ec0fbdb460e91cf31e8c5bb13e +Subproject commit 820ad7c108f5dbd692cb39fec04e69dc90a986c1 diff --git a/include/parse.h b/include/parse.h index d03d98bb..c9f62808 100644 --- a/include/parse.h +++ b/include/parse.h @@ -28,15 +28,15 @@ else if(GET_FLAG(a, protect)) \ DECL_SECTION_FUNC(prefix, type, Arg) \ ANN static inline type prefix##_section(const Arg a, /* const */ Section* section) { \ void* d = §ion->d.stmt_list; \ - return section_func[section->section_type](a, *(void**)d); \ + return prefix##_section_func[section->section_type](a, *(void**)d); \ } -#define HANDLE_EXP_FUNC(prefix, type, Arg) \ -DECL_EXP_FUNC(prefix, type, Arg) \ -ANN type prefix##_exp(const Arg arg, Exp exp) { \ - do CHECK_BB(exp_func[exp->exp_type](arg, &exp->d)) \ - while((exp = exp->next)); \ - return GW_OK; \ +#define HANDLE_EXP_FUNC(prefix, type, Arg) \ +DECL_EXP_FUNC(prefix, type, Arg) \ +ANN type prefix##_exp(const Arg arg, Exp exp) { \ + do CHECK_BB(prefix##_exp_func[exp->exp_type](arg, &exp->d)) \ + while((exp = exp->next)); \ + return GW_OK; \ } ANN m_bool scan1_exp(const Env, Exp); ANN m_bool scan2_exp(const Env, Exp); diff --git a/include/traverse.h b/include/traverse.h index 1a679e58..5ab16b32 100644 --- a/include/traverse.h +++ b/include/traverse.h @@ -7,16 +7,16 @@ ANN m_bool traverse_union_def(const Env, const Union_Def); ANN m_bool traverse_enum_def(const Env, const Enum_Def); ANN m_bool traverse_fptr_def(const Env, const Fptr_Def); ANN m_bool traverse_type_def(const Env env, const Type_Def); -ANN m_bool traverse_decl(const Env, const Exp_Decl*); +ANN m_bool traverse_exp(const Env, const Exp); ANN m_bool scan0_ast(const Env, Ast); ANN m_bool scan1_ast(const Env, Ast); ANN m_bool scan2_ast(const Env, Ast); ANN m_bool check_ast(const Env, Ast); -ANN m_bool scan1_exp_decl(const Env, const Exp_Decl*); -ANN m_bool scan2_exp_decl(const Env, const Exp_Decl*); -ANN Type check_exp_decl(const Env, const Exp_Decl*); +ANN m_bool scan1_exp(const Env, const Exp); +ANN m_bool scan2_exp(const Env, const Exp); +ANN Type check_exp(const Env, const Exp); ANN m_bool scan1_func_def(const Env, const Func_Def); ANN m_bool scan2_func_def(const Env, const Func_Def); diff --git a/src/emit/emit.c b/src/emit/emit.c index ca32d9a4..c6ce831c 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -600,7 +600,7 @@ ANN static m_bool emit_prim_unpack(const Emitter emit NUSED, const Tuple *tuple) DECL_PRIM_FUNC(emit, m_bool , Emitter); ANN static m_bool emit_prim(const Emitter emit, Exp_Primary *const prim) { - return prim_func[prim->prim_type](emit, &prim->d); + return emit_prim_func[prim->prim_type](emit, &prim->d); } ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, const uint emit_var) { @@ -1159,7 +1159,7 @@ DECL_EXP_FUNC(emit, m_bool, Emitter) ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) { do { - CHECK_BB(exp_func[exp->exp_type](emit, &exp->d)) + CHECK_BB(emit_exp_func[exp->exp_type](emit, &exp->d)) if(ref && isa(exp->type, emit->gwion->type[et_object]) > 0) { const Instr instr = emit_add_instr(emit, RegAddRef); instr->m_val = exp->emit_var; @@ -1570,7 +1570,7 @@ ANN static m_bool emit_stmt_match(const Emitter emit, const struct Stmt_Match_* DECL_STMT_FUNC(emit, m_bool , Emitter) ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt, const m_bool pop) { - CHECK_BB(stmt_func[stmt->stmt_type](emit, &stmt->d)) + CHECK_BB(emit_stmt_func[stmt->stmt_type](emit, &stmt->d)) if(pop && stmt->stmt_type == ae_stmt_exp && stmt->d.stmt_exp.val) pop_exp(emit, stmt->d.stmt_exp.val); return GW_OK; diff --git a/src/import/item.c b/src/import/item.c index 3459da6e..5d5ed543 100644 --- a/src/import/item.c +++ b/src/import/item.c @@ -37,7 +37,7 @@ ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, const m_uint* addr gwi->ck->exp->d.exp_decl.td->flag = flag; if(env->class_def && GET_FLAG(env->class_def, template)) return gwi_item_tmpl(gwi); - CHECK_BB(traverse_decl(env, &gwi->ck->exp->d.exp_decl)) + CHECK_BB(traverse_exp(env, gwi->ck->exp)) const Value value = gwi->ck->exp->d.exp_decl.list->self->value; SET_FLAG(value, builtin); const m_uint offset = value->from->offset; diff --git a/src/lib/tuple.c b/src/lib/tuple.c index a4b85e8b..93a295f9 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -138,7 +138,7 @@ static OP_CHECK(opck_at_tuple) { if(e->exp_type == ae_exp_decl) { DECL_OO(const Type, t, = (Type)VPTR(&bin->lhs->type->e->tuple->types, i)) e->d.exp_decl.td->xid->xid = insert_symbol(t->name); - CHECK_BO(traverse_decl(env, &e->d.exp_decl)) + CHECK_BO(traverse_exp(env, e)) bin->rhs->meta = ae_meta_var; } ++i; diff --git a/src/parse/check.c b/src/parse/check.c index ca18dd83..5003dbd1 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -15,7 +15,6 @@ #include "emit.h" #include "specialid.h" -ANN static Type check_exp(const Env env, Exp exp); ANN static m_bool check_stmt_list(const Env env, Stmt_List list); ANN m_bool check_class_def(const Env env, const Class_Def class_def); @@ -105,7 +104,7 @@ ANN static inline void clear_decl(const Env env, const Exp_Decl *decl) { ANN static Type no_xid(const Env env, const Exp_Decl *decl) { CHECK_OO((((Exp_Decl*)decl)->type = check_td(env, decl->td))) clear_decl(env, decl); - CHECK_BO(traverse_decl(env, decl)) + CHECK_BO(traverse_exp(env, exp_self(decl))) return decl->type; } @@ -351,7 +350,7 @@ describe_prim_xxx(unpack, env->gwion->type[et_tuple]) DECL_PRIM_FUNC(check, Type, Env); ANN static Type check_prim(const Env env, Exp_Primary *prim) { - return exp_self(prim)->type = prim_func[prim->prim_type](env, &prim->d); + return exp_self(prim)->type = check_prim_func[prim->prim_type](env, &prim->d); } ANN static Type at_depth(const Env env, const Array_Sub array); @@ -934,13 +933,13 @@ ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) { DECL_EXP_FUNC(check, Type, Env) -ANN static inline Type check_exp(const Env env, const Exp exp) { +ANN Type check_exp(const Env env, const Exp exp) { Exp curr = exp, next = NULL, prev = NULL; do { next = curr->next; - CHECK_OO((curr->type = exp_func[curr->exp_type](env, &curr->d))) - if(isa(curr->type, env->gwion->type[et_varloop]) > 0 && (prev || next)) - ERR_O(exp->pos, _("Varloop must be the only expression")) + CHECK_OO((curr->type = check_exp_func[curr->exp_type](env, &curr->d))) +// if(isa(curr->type, env->gwion->type[et_varloop]) > 0 && (prev || next)) +// ERR_O(exp->pos, _("Varloop must be the only expression")) if(env->func && isa(curr->type, env->gwion->type[et_lambda]) < 0 && isa(curr->type, env->gwion->type[et_function]) > 0 && !GET_FLAG(curr->type->e->d.func, pure)) UNSET_FLAG(env->func, pure); @@ -1229,7 +1228,7 @@ ANN static m_bool check_stmt_match(const Env env, const Stmt_Match stmt) { DECL_STMT_FUNC(check, m_bool , Env) ANN m_bool check_stmt(const Env env, const Stmt stmt) { - return stmt_func[stmt->stmt_type](env, &stmt->d); + return check_stmt_func[stmt->stmt_type](env, &stmt->d); } ANN static m_bool check_stmt_list(const Env env, Stmt_List l) { diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 5a04f013..32b68fb3 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -322,7 +322,7 @@ ANN m_bool scan1_union_def(const Env env, const Union_Def udef) { DECL_STMT_FUNC(scan1, m_bool, Env) ANN static inline m_bool scan1_stmt(const Env env, const Stmt stmt) { - return stmt_func[stmt->stmt_type](env, &stmt->d); + return scan1_stmt_func[stmt->stmt_type](env, &stmt->d); } ANN static m_bool scan1_stmt_list(const Env env, Stmt_List l) { diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 247d47f1..20451ee0 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -278,7 +278,7 @@ ANN m_bool scan2_union_def(const Env env, const Union_Def udef) { DECL_STMT_FUNC(scan2, m_bool, Env) ANN static m_bool scan2_stmt(const Env env, const Stmt stmt) { - return stmt_func[stmt->stmt_type](env, &stmt->d); + return scan2_stmt_func[stmt->stmt_type](env, &stmt->d); } ANN static m_bool scan2_stmt_list(const Env env, Stmt_List list) { diff --git a/src/parse/traverse.c b/src/parse/traverse.c index c56134d5..79a13c5b 100644 --- a/src/parse/traverse.c +++ b/src/parse/traverse.c @@ -10,10 +10,10 @@ ANN m_bool traverse_ast(const Env env, const Ast ast) { return check_ast(env, ast); } -ANN m_bool traverse_decl(const Env env, const Exp_Decl* decl) { - CHECK_BB(scan1_exp_decl(env, decl)) - CHECK_BB(scan2_exp_decl(env, decl)) - return check_exp_decl(env, decl) ? 1 : -1; +ANN m_bool traverse_exp(const Env env, const Exp exp) { + CHECK_BB(scan1_exp(env, exp)) + CHECK_BB(scan2_exp(env, exp)) + return check_exp(env, exp) ? 1 : -1; } ANN m_bool traverse_func_def(const Env env, const Func_Def def) { -- 2.43.0