From: fennecdjay Date: Wed, 31 Jan 2024 02:43:21 +0000 (+0100) Subject: :fire: unpointerize Exp X-Git-Tag: nightly~110 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=9ab7ceca0ad35af57559b0d8762884724ab1301e;p=gwion.git :fire: unpointerize Exp --- diff --git a/ast b/ast index 23c2894a..1c3afd60 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 23c2894a2dd6b0f0b3531f7995a3395020fc45bb +Subproject commit 1c3afd609f38c79cdfa58346c8dbc6112bedcca4 diff --git a/fmt b/fmt index 379c80d6..a1d3a168 160000 --- a/fmt +++ b/fmt @@ -1 +1 @@ -Subproject commit 379c80d6914e8e204739d49f97c45cfe386b749f +Subproject commit a1d3a1680d6f680199f6793f599629847a8f9759 diff --git a/include/array.h b/include/array.h index 7717f8cf..8399785e 100644 --- a/include/array.h +++ b/include/array.h @@ -22,5 +22,5 @@ typedef struct ArrayInfo_ { ANN Type check_array_access(const Env env, const Array_Sub array); ANN m_bool emit_array_access(const Emitter emit, struct ArrayAccessInfo *const info); -ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, const Exp args); +ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, Exp* args); #endif diff --git a/include/clean.h b/include/clean.h index c92d9a94..a0c0cac2 100644 --- a/include/clean.h +++ b/include/clean.h @@ -28,7 +28,7 @@ ANN static void clean_exp_slice(Clean *a, Exp_Slice *b); ANN static void clean_exp_if(Clean *a, Exp_If *b); ANN static void clean_exp_dot(Clean *a, Exp_Dot *b); ANN static void clean_exp_lambda(Clean *a, Exp_Lambda *b); -ANN static void clean_exp(Clean *a, Exp b); +ANN static void clean_exp(Clean *a, Exp* b); ANN static void clean_stmt_exp(Clean *a, Stmt_Exp b); ANN static void clean_stmt_for(Clean *a, Stmt_For b); ANN static void clean_stmt_each(Clean *a, Stmt_Each b); diff --git a/include/constant.h b/include/constant.h index 9f9d5fca..26113041 100644 --- a/include/constant.h +++ b/include/constant.h @@ -1,5 +1,5 @@ #ifndef __CONSTANT #define __CONSTANT -ANN m_bool constant_int(const Exp e); -ANN m_bool constant_float(const Exp e); +ANN m_bool constant_int(Exp* e); +ANN m_bool constant_float(Exp* e); #endif diff --git a/include/emit.h b/include/emit.h index 11aaf61d..030621f4 100644 --- a/include/emit.h +++ b/include/emit.h @@ -71,7 +71,7 @@ ANN2(1) Instr emit_add_instr(const Emitter, const f_instr) __attribute__((returns_nonnull)); ANN Code * emit_class_code(const Emitter, const m_str); -ANN m_bool emit_array_extend(const Emitter, const Type, const Exp); +ANN m_bool emit_array_extend(const Emitter, const Type, Exp*); ANN void emit_class_finish(const Emitter, const Nspc); ANN2(1, 2) m_bool emit_instantiate_object(const Emitter, const Type, const Array_Sub, @@ -80,9 +80,9 @@ ANN m_uint emit_code_offset(const Emitter emit); ANN m_uint emit_local(const Emitter emit, const Type t); ANN m_uint emit_localn(const Emitter emit, const Type t); ANN void* emit_localx(const Emitter emit, const Type t); -ANN m_uint emit_local_exp(const Emitter emit, const Exp); +ANN m_uint emit_local_exp(const Emitter emit, Exp*); ANN m_bool emit_exp_spork(const Emitter, const Exp_Unary *); -ANN m_bool emit_exp(const Emitter, const Exp); +ANN m_bool emit_exp(const Emitter, Exp*); ANN void emit_object_addref(const Emitter emit, const m_int size, const bool emit_var); diff --git a/include/import/checker.h b/include/import/checker.h index 22aa8b8d..6bb44b03 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -9,7 +9,7 @@ typedef struct ImportCK { // name_checker ? union { ID_List tmpl; Specialized_List sl; - Exp exp; + Exp* exp; }; union { Symbol xid; // union name diff --git a/include/import/internals.h b/include/import/internals.h index 2a665d59..07e855d3 100644 --- a/include/import/internals.h +++ b/include/import/internals.h @@ -38,7 +38,7 @@ ANN void gwi_body(const Gwi, const Section*); -ANN Exp make_exp(const Gwi gwi, const m_str type, const m_str name); +ANN Exp* make_exp(const Gwi gwi, const m_str type, const m_str name); ANN void gwi_reset(const Gwi gwi); ANN VM * gwi_vm(const Gwi); diff --git a/include/looper.h b/include/looper.h index 80e19952..4cebe6cd 100644 --- a/include/looper.h +++ b/include/looper.h @@ -6,7 +6,7 @@ typedef struct Looper Looper; typedef Instr (*f_looper)(const Emitter, const Looper *); struct Looper { - const Exp exp; + Exp* exp; Stmt *const stmt; /*const */ m_uint offset; const m_uint n; diff --git a/include/match.h b/include/match.h index 480421fb..11ac01dd 100644 --- a/include/match.h +++ b/include/match.h @@ -5,10 +5,10 @@ struct Match_ { struct Vector_ vec; }; -ANN static inline void match_map(struct Match_ *const match, Exp e) { +ANN static inline void match_map(struct Match_ *const match, Exp* e) { const Vector cond = &match->cond; vector_init(cond); - Exp next; + Exp* next; do { next = e->next; e->next = NULL; @@ -20,7 +20,8 @@ ANN static inline void match_unmap(struct Match_ *const match) { const Vector cond = &match->cond; const vtype sz = vector_size(cond); for (m_uint i = 0; i < sz - 1; ++i) { - const Exp e = (Exp)vector_at(cond, i), next = (Exp)vector_at(cond, i + 1); + Exp* e = (Exp*)vector_at(cond, i); + Exp* next = (Exp*)vector_at(cond, i + 1); e->next = next; } vector_release(cond); diff --git a/include/operator.h b/include/operator.h index c0fb06ca..1cebd8a4 100644 --- a/include/operator.h +++ b/include/operator.h @@ -66,7 +66,7 @@ struct Op_Import { }; struct Implicit { - Exp e; + Exp* e; Type t; loc_t loc; }; @@ -91,7 +91,7 @@ ANN static inline void operator_resume(struct Op_Import *opi) { *(uintptr_t *)opi->ret = opi->data; } -ANN static inline void set_decl_ref(const Exp e) { +ANN static inline void set_decl_ref(Exp* e) { if (e->exp_type == ae_exp_decl) SET_FLAG(e->d.exp_decl.var.vd.value, late); } diff --git a/include/parse.h b/include/parse.h index b8651de4..b17a1731 100644 --- a/include/parse.h +++ b/include/parse.h @@ -42,13 +42,13 @@ #define HANDLE_EXP_FUNC(prefix, type, Arg) \ DECL_EXP_FUNC(prefix, type, Arg) \ - ANN type prefix##_exp(const Arg arg, Exp exp) { \ + 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); +ANN m_bool scan1_exp(const Env, Exp*); +ANN m_bool scan2_exp(const Env, Exp*); #define describe_stmt_func(prefix, name, type, prolog, exp) \ ANN static m_bool prefix##_stmt_##name(const Env env, const type stmt) { \ @@ -83,7 +83,7 @@ xxx_cdef(scan0) xxx_cdef(scan1) xxx_cdef(scan2) xxx_cdef(check) scanx_fdef(const Env, void *, const Func_Def, const _exp_func); ANN m_bool check_subscripts(const Env, const Array_Sub, const m_bool is_decl); -ANN m_bool check_implicit(const Env env, const Exp e, const Type t); +ANN m_bool check_implicit(const Env env, Exp* e, const Type t); ANN m_bool ensure_traverse(const Env env, const Type t); ANN m_bool check_traverse_fdef(const Env env, const Func_Def fdef); @@ -100,7 +100,7 @@ ANN static inline void env_inline_mult(const Env env, const float mult) { if (env->func) env->func->inline_mult += mult; } -ANN static inline bool is_hole(const Env env, const Exp exp) { +ANN static inline bool is_hole(const Env env, Exp* exp) { const Symbol hole = insert_symbol("_"); if (exp->exp_type == ae_exp_primary) { if (exp->d.prim.prim_type == ae_prim_id) { @@ -110,7 +110,7 @@ ANN static inline bool is_hole(const Env env, const Exp exp) { return false; } -static inline bool exp_is_zero(const Exp exp) { +static inline bool exp_is_zero(Exp* exp) { return exp->exp_type == ae_exp_primary && exp->d.prim.prim_type == ae_prim_num && !exp->d.prim.d.gwint.num; @@ -125,7 +125,7 @@ ANN static inline bool not_upvalue(const Env env, const Value v) { ANN m_bool abstract_array(const Env env, const Array_Sub array); -ANN static inline bool is_static_call(const Gwion gwion, const Exp e) { +ANN static inline bool is_static_call(const Gwion gwion, Exp* e) { if (e->exp_type != ae_exp_dot) return true; const Exp_Dot *member = &e->d.exp_dot; if(unlikely(!strcmp(s_name(member->xid), "new"))) return true; diff --git a/include/partial.h b/include/partial.h index 0a6603e3..fed277cf 100644 --- a/include/partial.h +++ b/include/partial.h @@ -4,7 +4,7 @@ ANN Type partial_type(const Env, Exp_Call *const); ANN void print_signature(const Func f); -ANN static inline bool func_match_inner(const Env env, const Exp e, +ANN static inline bool func_match_inner(const Env env, Exp* e, const Type t, const bool implicit, const bool specific) { if (specific ? e->type == t : isa(e->type, t) > 0) // match @@ -12,7 +12,7 @@ ANN static inline bool func_match_inner(const Env env, const Exp e, return !implicit ? false : check_implicit(env, e, t) > 0; } -ANN static inline bool is_typed_hole(const Env env, const Exp exp) { +ANN static inline bool is_typed_hole(const Env env, Exp* exp) { return exp->exp_type == ae_exp_cast && is_hole(env, exp->d.exp_cast.exp); } #endif diff --git a/include/traverse.h b/include/traverse.h index 1e9fdb45..64385841 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_exp(const Env, const Exp); +ANN m_bool traverse_exp(const Env, 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(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_exp(const Env, Exp*); +ANN m_bool scan2_exp(const Env, Exp*); +ANN Type check_exp(const Env, Exp*); ANN m_bool scan0_func_def(const Env, const Func_Def); ANN m_bool scan1_func_def(const Env, const Func_Def); diff --git a/plug b/plug index a8194c5a..88b079e8 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit a8194c5a7b1b874d1475cb5af245770327605f9b +Subproject commit 88b079e8a888a883141170147c3c8e792360c8e1 diff --git a/src/clean.c b/src/clean.c index 7370c2ce..4dd6444e 100644 --- a/src/clean.c +++ b/src/clean.c @@ -133,7 +133,7 @@ ANN static void clean_exp_td(Clean *a, Type_Decl **b) { } DECL_EXP_FUNC(clean, void, Clean *) -ANN static void clean_exp(Clean *a, Exp b) { +ANN static void clean_exp(Clean *a, Exp* b) { clean_exp_func[b->exp_type](a, &b->d); if (b->next) clean_exp(a, b->next); } diff --git a/src/emit/emit.c b/src/emit/emit.c index 4b1efdbc..49986981 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -209,7 +209,7 @@ ANN static m_int frame_pop(const Emitter emit) { return _frame_pop(emit); } -ANN /*static */ m_bool emit_exp(const Emitter emit, Exp exp); +ANN /*static */ m_bool emit_exp(const Emitter emit, Exp* exp); ANN static m_bool emit_stmt_list(const Emitter emit, Stmt_List list); ANN static m_bool emit_exp_dot(const Emitter emit, const Exp_Dot *member); @@ -293,13 +293,13 @@ ANN void* emit_localx(const Emitter emit, const Type t) { return l; } -ANN m_uint emit_local_exp(const Emitter emit, const Exp e) { +ANN m_uint emit_local_exp(const Emitter emit, Exp* e) { Local *const l = emit_localx(emit, e->type); if(e->ref) e->ref->data = l; return l->offset; } -ANN m_uint emit_local_exp2(const Emitter emit, const Exp e) { +ANN m_uint emit_local_exp2(const Emitter emit, Exp* e) { Local *const l = emit_localx(emit, e->type); e->data = l; return l->offset; @@ -319,7 +319,7 @@ ANN static inline void maybe_ctor(const Emitter emit, const Type t) { ANN2(1, 2) static ArrayInfo *emit_array_extend_inner(const Emitter emit, const Type t, - const Exp e, const uint is_ref); + Exp* e, const uint is_ref); ANN static m_bool emit_pre_ctor(const Emitter emit, const Type type) { if (type->info->parent) { CHECK_BB(emit_pre_ctor(emit, type->info->parent)); @@ -360,7 +360,7 @@ ANN static m_bool emit_pre_constructor_array(const Emitter emit, } ANN2(1) -static m_bool extend_indices(const Emitter emit, Exp e, const m_uint depth) { +static m_bool extend_indices(const Emitter emit, Exp* e, const m_uint depth) { if (e) CHECK_BB(emit_exp(emit, e)); m_uint count = 0; while (e) { @@ -395,7 +395,7 @@ ANN static inline m_bool arrayinfo_ctor(const Emitter emit, ArrayInfo *info) { ANN2(1, 2) static ArrayInfo *emit_array_extend_inner(const Emitter emit, const Type t, - const Exp e, const uint is_ref) { + Exp* e, const uint is_ref) { CHECK_BO(extend_indices(emit, e, get_depth(t))); ArrayInfo * info = new_arrayinfo(emit, t, t->info->cdef->base.tag.loc); const Instr alloc = emit_add_instr(emit, ArrayAlloc); @@ -520,7 +520,7 @@ ANN VM_Code finalyze(const Emitter emit, const f_instr exec) { return code; } -ANN static inline m_uint exp_size(const Exp e) { +ANN static inline m_uint exp_size(Exp* e) { if (exp_getvar(e)) return SZ_INT; const Type type = e->cast_to ?: e->type; return type->size; @@ -543,14 +543,14 @@ ANN void emit_struct_addref(const Emitter emit, const Type t, const m_int size, } ANN2(1) -static void emit_exp_addref1(const Emitter emit, const Exp exp, m_int size) { +static void emit_exp_addref1(const Emitter emit, Exp* exp, m_int size) { const Type t = exp->cast_to ?: exp->type; if (tflag(t, tflag_compound)) emit_compound_addref(emit, exp->type, size, exp_getvar(exp)); } /*ANN2(1) -static void emit_exp_addref(const Emitter emit, Exp exp, +static void emit_exp_addref(const Emitter emit, Exp* exp, m_int size) { do { emit_exp_addref1(emit, exp, size); @@ -558,15 +558,15 @@ static void emit_exp_addref(const Emitter emit, Exp exp, } while ((exp = exp->next)); }*/ -ANN static inline m_bool emit_exp1(const Emitter emit, const Exp e) { - const Exp next = e->next; +ANN static inline m_bool emit_exp1(const Emitter emit, Exp* e) { + Exp* next = e->next; e->next = NULL; const m_bool ret = emit_exp(emit, e); e->next = next; return ret; } -ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp e) { +ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp* e) { do { CHECK_BB(emit_exp1(emit, e)); emit_exp_addref1(emit, e, -t->size); @@ -576,7 +576,7 @@ ANN static m_bool emit_prim_array_exp(const Emitter emit, const Type t, Exp e) { } ANN static m_bool emit_prim_array(const Emitter emit, const Array_Sub *data) { - Exp e = (*data)->exp; + Exp* e = (*data)->exp; const Type type = (*data)->type; const Type base = array_base_simple(type); if(!base->actual_size) CHECK_BB(emit_exp(emit, e)); @@ -594,7 +594,7 @@ ANN static m_bool emit_prim_array(const Emitter emit, const Array_Sub *data) { return GW_OK; } -ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e); +ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp* e); ANN static m_bool emit_range(const Emitter emit, Range *range) { if (range->start) @@ -609,7 +609,7 @@ ANN static m_bool emit_range(const Emitter emit, Range *range) { ANN static m_bool emit_prim_range(const Emitter emit, Range **data) { Range *range = *data; CHECK_BB(emit_range(emit, range)); - const Exp e = range->start ?: range->end; + Exp* e = range->start ?: range->end; const Symbol sym = insert_symbol("[:]"); assert(e); struct Op_Import opi = {.op = sym, @@ -625,22 +625,22 @@ static inline m_uint int2pow2(const m_uint x) { return x == 1 ? 2 : 1<<(64-__builtin_clzl(x)); } -ANN static m_bool emit_prim_dict(const Emitter emit, Exp *data) { - Exp e = *data; +ANN static m_bool emit_prim_dict(const Emitter emit, Exp* *data) { + Exp* e = *data; const Type key = e->type; const Type val = e->next->type; const Type t = dict_type(emit->gwion, key, val, e->loc); const Instr init = emit_add_instr(emit, dict_ctor_alt); - const Exp next = e->next; + Exp* next = e->next; e->next = NULL; - struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; - struct Exp_ call = { .exp_type = ae_exp_call, .d = { .exp_call = { .func = &func, .args = e}}}; + Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; + Exp call = { .exp_type = ae_exp_call, .d = { .exp_call = { .func = &func, .args = e}}}; CHECK_BB(traverse_exp(emit->env, &call)); e->next = next; m_uint count = 0; do { - const Exp next = e->next; - const Exp nnext = next->next; + Exp* next = e->next; + Exp* nnext = next->next; next->next = NULL; e->next = NULL; CHECK_BB(emit_exp(emit, e)); @@ -686,7 +686,7 @@ ANN m_bool emit_array_access(const Emitter emit, } ANN static m_bool emit_exp_array(const Emitter emit, const Exp_Array *array) { - const Exp e = exp_self(array); + Exp* e = exp_self(array); exp_setvar(array->base, get_emit_var(emit, array->base->type, exp_getvar(e))); CHECK_BB(emit_exp(emit, array->base)); struct ArrayAccessInfo info = { @@ -700,7 +700,7 @@ ANN static m_bool emit_exp_slice(const Emitter emit, const Exp_Slice *range) { CHECK_BB(emit_exp(emit, range->base)); CHECK_BB(emit_range(emit, range->range)); const Symbol sym = insert_symbol("[:]"); - const Exp e = range->range->start ?: range->range->end; + Exp* e = range->range->start ?: range->range->end; assert(e); struct Op_Import opi = {.op = sym, .lhs = e->type, @@ -771,13 +771,13 @@ ANN static m_bool emit_prim_str(const Emitter emit, const struct AstString *str) #define emit_prim_nil (void *)dummy_func -ANN static inline void interp_size(const Emitter emit, const Exp e) { +ANN static inline void interp_size(const Emitter emit, Exp* e) { const Type t = !tflag(e->type, tflag_ref) || safe_tflag(e->cast_to, tflag_ref) ? e->type : (Type)vector_front(&e->type->info->tuple->contains); emit_regsetimm(emit, t->size, SZ_INT); } -ANN static void emit_gack_type(const Emitter emit, const Exp e) { +ANN static void emit_gack_type(const Emitter emit, Exp* e) { if (e->exp_type == ae_exp_cast || (e->exp_type == ae_exp_primary && e->d.prim.prim_type == ae_prim_str)) return; @@ -786,10 +786,11 @@ ANN static void emit_gack_type(const Emitter emit, const Exp e) { emit_add_instr(emit, GackType); } -ANN /*static*/ m_bool emit_interp(const Emitter emit, const Exp exp) { +ANN /*static*/ m_bool emit_interp(const Emitter emit, Exp* exp) { emit_pushimm(emit, 0); //emit_local(emit, emit->gwion->type[et_int]); - Exp e = exp, next = NULL; + Exp* e = exp; + Exp* next = NULL; do { next = e->next; e->next = NULL; @@ -810,7 +811,7 @@ ANN /*static*/ m_bool emit_interp(const Emitter emit, const Exp exp) { return GW_OK; } -ANN static m_bool emit_prim_hack(const Emitter emit, const Exp *exp) { +ANN static m_bool emit_prim_hack(const Emitter emit, Exp* *exp) { CHECK_BB(emit_interp(emit, *exp)); if (!(emit->env->func && emit->env->func->def->base->tag.sym == insert_symbol("@gack"))) @@ -819,8 +820,8 @@ ANN static m_bool emit_prim_hack(const Emitter emit, const Exp *exp) { return GW_OK; } -ANN static m_bool emit_prim_interp(const Emitter emit, const Exp *exp) { - const Exp e = *exp; +ANN static m_bool emit_prim_interp(const Emitter emit, Exp* *exp) { + Exp* e = *exp; CHECK_BB(emit_interp(emit, e)); const Instr instr = emit_add_instr(emit, GackEnd); instr->m_val = 1; @@ -1141,7 +1142,7 @@ ANN /*static */ m_bool emit_exp_decl(const Emitter emit, Exp_Decl *const decl) { // see take exp -Exp nth_exp(Exp e, uint32_t n) { +Exp* nth_exp(Exp* e, uint32_t n) { for(uint32_t i = 0; i < n; i++) e = e->next; return e; @@ -1165,7 +1166,7 @@ ANN static inline void emit_return_pc(const Emitter emit, const m_uint val) { } } -ANN static inline void pop_exp(const Emitter emit, Exp e); +ANN static inline void pop_exp(const Emitter emit, Exp* e); ANN static inline void scoped_ini(const Emitter emit) { ++emit->env->scope->depth; @@ -1195,7 +1196,7 @@ ANN static inline bool check_inline(const Emitter emit, const Func f) { return f->weight < threshold; } -ANN static inline bool member_inlinable(const Emitter emit, const Func f, const Exp e) { +ANN static inline bool member_inlinable(const Emitter emit, const Func f, Exp* e) { if (f!= emit->env->func)return false; const Type owner_class = f->value_ref->from->owner_class; if (!owner_class) return true; @@ -1292,7 +1293,7 @@ ANN static inline bool is_new_struct(const Func f, const Type t) { } ANN static m_bool emit_new_struct(const Emitter emit,const Exp_Call *call) { - const Exp self = exp_self(call); + Exp* self = exp_self(call); const Type t = self->type; const m_int offset = self->ref ? emit->code->frame->curr_offset - t->size: emit_local(emit, t); const Instr back = self->ref ? (Instr)vector_pop(&emit->code->instr) : NULL; @@ -1342,7 +1343,7 @@ ANN static m_bool _emit_exp_call(const Emitter emit, const Exp_Call *call) { ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call *exp_call) { CHECK_BB(_emit_exp_call(emit, exp_call)); - const Exp e = exp_self(exp_call); + Exp* e = exp_self(exp_call); if (exp_getvar(e)) { const m_uint size = e->type->size; emit_regmove(emit, -size); @@ -1354,7 +1355,7 @@ ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call *exp_call) { return GW_OK; } -ANN static m_uint get_type_size(const Exp e) { +ANN static m_uint get_type_size(Exp* e) { if(tflag(e->type, tflag_ref)&& !safe_tflag(e->cast_to, tflag_ref)) { const Type base =(Type)vector_front(&e->type->info->tuple->contains); return base->size; @@ -1362,7 +1363,7 @@ ANN static m_uint get_type_size(const Exp e) { return e->type->size; } -ANN static m_uint pop_exp_size(Exp e) { +ANN static m_uint pop_exp_size(Exp* e) { const bool emit_addr = exp_getvar(e); m_uint size = 0; do size += !emit_addr ? get_type_size(e) : SZ_INT; @@ -1370,20 +1371,20 @@ ANN static m_uint pop_exp_size(Exp e) { return size; } -ANN static inline void pop_exp(const Emitter emit, Exp e) { +ANN static inline void pop_exp(const Emitter emit, Exp* e) { const m_uint size = pop_exp_size(e); if (size) emit_regmove(emit, -size); } -ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e) { +ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp* e) { CHECK_BB(emit_exp(emit, e)); if (e->next) pop_exp(emit, e->next); return GW_OK; } ANN static m_bool emit_exp_binary(const Emitter emit, const Exp_Binary *bin) { - const Exp lhs = bin->lhs; - const Exp rhs = bin->rhs; + Exp* lhs = bin->lhs; + Exp* rhs = bin->rhs; CHECK_BB(emit_exp_pop_next(emit, lhs)); CHECK_BB(emit_exp_pop_next(emit, rhs)); struct Op_Import opi = {.op = bin->op, @@ -1520,7 +1521,7 @@ typedef struct { static m_bool me_cmp(MemoizeEmitter *me, const Arg *arg) { const Emitter emit = me->emit; const Symbol sym = insert_symbol("?="); - struct Exp_ lhs = { + Exp lhs = { .exp_type = ae_exp_primary, .type = arg->type, .loc = arg->var.td->tag.loc, @@ -1528,7 +1529,7 @@ static m_bool me_cmp(MemoizeEmitter *me, const Arg *arg) { .prim = { .prim_type = ae_prim_id } } }; - struct Exp_ rhs = { + Exp rhs = { .exp_type = ae_exp_primary, .type = me->emit->gwion->type[et_bool], .loc = arg->var.td->tag.loc, @@ -1536,7 +1537,7 @@ static m_bool me_cmp(MemoizeEmitter *me, const Arg *arg) { .prim = { .prim_type = ae_prim_id } } }; - struct Exp_ bin = { + Exp bin = { .exp_type = ae_exp_binary, .type = arg->type, .loc = arg->var.td->tag.loc, @@ -1660,7 +1661,7 @@ static void push_spork_code(const Emitter emit, const m_str prefix, struct Sporker { const Stmt_List code; - const Exp exp; + Exp* exp; VM_Code vm_code; const Type type; const Capture_List captures; @@ -1746,7 +1747,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { // uint32_t offset = 0; m_uint offset = 0; if(emit->env->class_def && sporker.code) { - struct Exp_ exp = { + Exp exp = { .d = { .prim = { .d = { .var = insert_symbol("this") }, .prim_type = ae_prim_id @@ -1762,7 +1763,7 @@ ANN m_bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { for (uint32_t i = 0; i < caps->len; i++) { Capture *cap = mp_vector_at(caps, Capture, i); const Value v = cap->var.value; - struct Exp_ exp = { + Exp exp = { .d = { .prim = { .d = { .var = cap->var.tag.sym }, .value = v, @@ -1800,9 +1801,8 @@ ANN static m_bool emit_exp_unary(const Emitter emit, const Exp_Unary *unary) { return op_emit(emit, &opi); } -ANN static m_bool emit_implicit_cast(const Emitter emit, - const restrict Exp from, - const restrict Type to) { +ANN static m_bool emit_implicit_cast(const Emitter emit, + Exp* from, const Type to) { const struct Implicit imp = { .e=from, .t=to, . loc = from->loc}; // no pos struct Op_Import opi = {.op = insert_symbol("@implicit"), @@ -1814,7 +1814,7 @@ ANN static m_bool emit_implicit_cast(const Emitter emit, return op_emit(emit, &opi); } -ANN2(1,2) static Instr _flow(const Emitter emit, const Exp e, Instr *const instr, /*const */bool b) { +ANN2(1,2) static Instr _flow(const Emitter emit, Exp* e, Instr *const instr, /*const */bool b) { CHECK_BO(emit_exp_pop_next(emit, e)); { const Instr ex = (Instr)vector_back(&emit->code->instr); @@ -1846,7 +1846,7 @@ static void emit_maybe_stack(const Emitter emit, const Instr instr, const MaybeV } ANN static m_bool emit_exp_if(const Emitter emit, const Exp_If *exp_if) { - const Exp e = exp_if->if_exp ?: exp_if->cond; + Exp* e = exp_if->if_exp ?: exp_if->cond; Instr instr; struct M_Vector_ v = {}; const m_uint reg = emit_local(emit, emit->gwion->type[et_bool]); @@ -1945,8 +1945,8 @@ ANN static m_bool emit_exp_td(const Emitter emit, Type_Decl *td) { DECL_EXP_FUNC(emit, m_bool, Emitter) -ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp e) { - Exp exp = e; +ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp* e) { + Exp* exp = e; do { if (emit->info->debug && emit->status.line < e->loc.first.line) { const Instr instr = emit_add_instr(emit, DebugLine); @@ -2422,12 +2422,12 @@ ANN static m_bool emit_stmt_exp(const Emitter emit, return exp->val ? emit_exp(emit, exp->val) : GW_OK; } -ANN static m_bool emit_case_head(const Emitter emit, const Exp base, - const Exp e, const Symbol op, const Vector v) { +ANN static m_bool emit_case_head(const Emitter emit, Exp* base, + Exp* e, const Symbol op, const Vector v) { CHECK_BB(emit_exp1(emit, base)); CHECK_BB(emit_exp1(emit, e)); const Exp_Binary bin = {.lhs = base, .rhs = e, .op = op}; - struct Exp_ ebin = { .d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc }; + Exp ebin = { .d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc }; struct Op_Import opi = {.op = op, .lhs = base->type, .rhs = e->type, @@ -2450,16 +2450,16 @@ ANN static m_bool emit_case_body(const Emitter emit, return GW_OK; } -ANN static m_bool case_value(const Emitter emit, const Exp base, const Exp e) { +ANN static m_bool case_value(const Emitter emit, Exp* base, Exp* e) { const Value v = e->d.prim.value; v->from->offset = emit_local(emit, base->type); emit_regtomem4(emit, v->from->offset, base->type->size); return GW_OK; } -ANN Symbol case_basic_op(const Env env, const Type base, const Exp e); +ANN Symbol case_basic_op(const Env env, const Type base, Exp* e); #define CASE_PASS (Symbol)1 -ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e, +ANN static Symbol case_op(const Emitter emit, Exp* base, Exp* e, const Vector vec, const uint n) { if (e->exp_type == ae_exp_primary) { if (e->d.prim.prim_type == ae_prim_id) { @@ -2475,7 +2475,7 @@ ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e, } } else if (tflag(base->type, tflag_union) && e->exp_type == ae_exp_call) { - const Exp func = e->d.exp_call.func; + Exp* func = e->d.exp_call.func; if (func->d.prim.prim_type == ae_prim_id) { const Map map = &base->type->nspc->info->value->map; for (m_uint i = 0; i < map_size(map); ++i) { @@ -2502,7 +2502,7 @@ ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e, emit_regmove(emit, SZ_INT); CHECK_BO(emit_exp(emit, e)); const Exp_Binary bin = {.lhs = base, .rhs = e, .op = insert_symbol("?=")}; - struct Exp_ ebin = {.d = {.exp_binary = bin}, .loc = e->loc }; + Exp ebin = {.d = {.exp_binary = bin}, .loc = e->loc }; struct Op_Import opi = {.op = insert_symbol("?="), .lhs = base->type, .rhs = e->type, @@ -2517,10 +2517,10 @@ ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e, ANN static m_bool _emit_stmt_match_case(const Emitter emit, const struct Stmt_Match_ *stmt, const Vector v) { - Exp e = stmt->cond; + Exp* e = stmt->cond; const Vector cond = &emit->env->scope->match->cond; for (m_uint i = 0; i < vector_size(cond) && e; e = e->next, ++i) { - const Exp base = (Exp)vector_at(cond, i); + Exp* base = (Exp*)vector_at(cond, i); const Symbol op = case_op(emit, base, e, v, 0); if (op != CASE_PASS) CHECK_BB(emit_case_head(emit, base, e, op, v)); } diff --git a/src/import/import_checker.c b/src/import/import_checker.c index 0e69a6d2..fa412af0 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -22,8 +22,8 @@ struct td_checker { struct AC { m_str str; - Exp base; - Exp exp; + Exp* base; + Exp* exp; loc_t loc; m_uint depth; }; @@ -292,8 +292,8 @@ ANN static void td_fullname(const Env env, GwText *text, const Type t) { text_add(text, t->name); } -ANN Exp td2exp(const MemPool mp, const Type_Decl *td) { - Exp base = new_prim_id(mp, td->tag.sym, td->tag.loc); +ANN Exp* td2exp(const MemPool mp, const Type_Decl *td) { + Exp* base = new_prim_id(mp, td->tag.sym, td->tag.loc); Type_Decl *next = td->next; while(next) { base = new_exp_dot(mp, base, next->tag.sym, td->tag.loc); @@ -316,7 +316,7 @@ ANN static m_bool td_info_run(const Env env, struct td_info *info) { if(t) td_fullname(env, &info->fmt->ls->text, t); else { - const Exp exp = td2exp(gwion->mp, targ->d.td); + Exp* exp = td2exp(gwion->mp, targ->d.td); if(traverse_exp(env, exp) > 0) { if(is_class(gwion, exp->type)) { td_fullname(env, &info->fmt->ls->text, exp->type); @@ -325,7 +325,7 @@ ANN static m_bool td_info_run(const Env env, struct td_info *info) { } else GWION_ERR_B(targ->d.td->tag.loc, "invalid template argument"); } } else { - Exp exp = targ->d.exp; + Exp* exp = targ->d.exp; if(check_exp(env, targ->d.exp)) { if(!is_class(gwion, exp->type)) gwfmt_exp(info->fmt, exp); @@ -371,7 +371,7 @@ ANN static inline m_bool ac_exp(const Gwion gwion, const struct AC *ac) { GWION_ERR_B(ac->loc, "malformed array [][...]") } -ANN static void ac_add_exp(struct AC *ac, const Exp exp) { +ANN static void ac_add_exp(struct AC *ac, Exp* exp) { if (ac->exp) ac->exp = (ac->exp->next = exp); else @@ -390,7 +390,7 @@ ANN static m_bool _ac_run(const Gwion gwion, struct AC *const ac) { if (str != ac->str) { CHECK_BB(ac_num(gwion, ac, num)); CHECK_BB(ac_exp(gwion, ac)); - const Exp exp = new_prim_int(gwion->mp, num, ac->loc); + Exp* exp = new_prim_int(gwion->mp, num, ac->loc); // set type: otherwise could fail at emit time exp->type = gwion->type[et_int]; ac_add_exp(ac, exp); diff --git a/src/import/import_prim.c b/src/import/import_prim.c index 8e7a2b39..d4bece40 100644 --- a/src/import/import_prim.c +++ b/src/import/import_prim.c @@ -106,7 +106,7 @@ static OP_EMIT(opem_bit_exp) { static OP_CHECK(opck_bit_access) { Array_Sub array = data; - const Exp e = array->exp; + Exp* e = array->exp; if(e->next) ERR_N(e->next->loc, "too many expressions for bit access"); if(is_prim_int(e)) { m_int idx = e->d.prim.d.gwint.num; diff --git a/src/import/import_udef.c b/src/import/import_udef.c index ac958b7e..aeba45d6 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -15,7 +15,7 @@ #include "gwi.h" // move me -ANN Exp make_exp(const Gwi gwi, const m_str type, const m_str name) { +ANN Exp* make_exp(const Gwi gwi, const m_str type, const m_str name) { DECL_OO(Type_Decl *, td, = gwi_str2td(gwi, type)); struct Var_Decl_ vd; if(gwi_str2var(gwi, &vd, name) < 0) { diff --git a/src/lib/array.c b/src/lib/array.c index d49fd251..3ca56637 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -160,7 +160,7 @@ ANN static inline bool shift_match(const Type base, const Type more) { return get_depth(base) == get_depth(more); } -ANN static Type check_array_shift(const Env env, const Exp a, const Exp b, +ANN static Type check_array_shift(const Env env, Exp* a, Exp* b, const m_str str, const loc_t loc) { /* if(a->type == env->gwion->type[et_error] && b->type->array_depth > 1) @@ -268,7 +268,7 @@ static OP_CHECK(opck_array_cast) { } parent = parent->info->parent; } - struct Exp_ e = { .type = l, .loc = cast->exp->loc }; + Exp e = { .type = l, .loc = cast->exp->loc }; CHECK_BN(check_implicit(env, &e, r)); return t; } @@ -324,7 +324,7 @@ static OP_EMIT(opem_array_cast) { } static OP_CHECK(opck_array_slice) { - const Exp e = (Exp)data; + Exp* e = (Exp*)data; exp_setmeta(exp_self(e), 1); return e->d.exp_slice.base->type; } @@ -377,13 +377,13 @@ ANN static inline Type get_array_type(const Type type) { static OP_CHECK(opck_array) { const Array_Sub array = (Array_Sub)data; const Type t_int = env->gwion->type[et_int]; - Exp e = array->exp; + Exp* e = array->exp; do CHECK_BN(check_implicit(env, e, t_int)); while ((e = e->next)); const Type t = get_array_type(array->type); if (t->array_depth >= array->depth) return array_type(env, array_base(t), t->array_depth - array->depth, array->exp->loc); - const Exp curr = take_exp(array->exp, t->array_depth); + Exp* curr = take_exp(array->exp, t->array_depth); struct Array_Sub_ next = {curr->next, array_base(t), array->depth - t->array_depth}; @@ -423,10 +423,10 @@ ANN m_bool get_emit_var(const Emitter emit, const Type t, bool is_var) { return vars[1]; } -ANN static inline Exp emit_n_exp(const Emitter emit, +ANN static inline Exp* emit_n_exp(const Emitter emit, struct ArrayAccessInfo *const info) { - const Exp e = take_exp(info->array.exp, info->array.depth); - const Exp next = e->next; + Exp* e = take_exp(info->array.exp, info->array.depth); + Exp* next = e->next; e->next = NULL; struct Array_Sub_ partial = {info->array.exp, info->array.type, info->array.depth}; @@ -458,7 +458,7 @@ static OP_EMIT(opem_array_access) { struct Array_Sub_ next = {info->array.exp, array_base(t), info->array.depth - t->array_depth}; info->array = partial; - const Exp exp = emit_n_exp(emit, info); + Exp* exp = emit_n_exp(emit, info); next.exp = exp; info->array = next; return exp ? emit_array_access(emit, info) : GW_ERROR; @@ -881,7 +881,7 @@ static OP_EMIT(opem_array_each_init) { } -ANN static inline Type foreach_type(const Env env, const Exp exp) { +ANN static inline Type foreach_type(const Env env, Exp* exp) { const Type et = exp->type; DECL_OO(Type, base, = typedef_base(et)); DECL_OO(const Type, t, = array_base_simple(base)); @@ -897,7 +897,7 @@ ANN static inline Type foreach_type(const Env env, const Exp exp) { // rewrite me static OP_CHECK(opck_array_each_val) { - const Exp exp = (const Exp) data; + Exp* exp = (Exp*) data; DECL_ON(const Type, base, = foreach_type(env, exp)); CHECK_BN(ensure_traverse(env, base)); return ref_type(env->gwion, base, exp->loc); @@ -1185,12 +1185,12 @@ INSTR(ArrayAlloc) { } } -ANN static bool last_is_zero(Exp e) { +ANN static bool last_is_zero(Exp* e) { while(e->next) e = e->next; return exp_is_zero(e); } -ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, const Exp args) { +ANN2(1,2) m_bool check_array_instance(const Env env, Type_Decl *td, Exp* args) { if (!last_is_zero(td->array->exp)) { if (!args) ERR_B(td->tag.loc, "declaration of abstract type arrays needs lambda"); diff --git a/src/lib/closure.c b/src/lib/closure.c index 3b09eda4..24c47d31 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -15,16 +15,17 @@ #include "gack.h" #include "tmp_resolve.h" -ANN static Exp uncurry(const Env env, const Exp_Binary *bin) { +ANN static Exp* uncurry(const Env env, const Exp_Binary *bin) { const Stmt* stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, Stmt, 0); - const Exp ecall = stmt->d.stmt_exp.val; + Exp* ecall = stmt->d.stmt_exp.val; const Exp_Call *call = &ecall->d.exp_call; - Exp args = call->args; - Exp lhs = bin->lhs; - Exp base = NULL, tmp = NULL; + Exp* args = call->args; + Exp* lhs = bin->lhs; + Exp* base = NULL; + Exp *tmp = NULL; while(args) { if(args->exp_type != ae_exp_primary || args->d.prim.prim_type != ae_prim_id || *s_name(args->d.prim.d.var) != '@') { - const Exp next = args->next; + Exp* next = args->next; args->next = NULL; if(tmp) tmp = (tmp->next = cpy_exp(env->gwion->mp, args)); else base = (tmp = cpy_exp(env->gwion->mp, args)); @@ -34,7 +35,7 @@ ANN static Exp uncurry(const Env env, const Exp_Binary *bin) { free_exp(env->gwion->mp, base); return NULL; } - const Exp next = lhs->next; + Exp* next = lhs->next; lhs->next = NULL; if(tmp) tmp = (tmp->next = cpy_exp(env->gwion->mp, lhs)); else base = (tmp = cpy_exp(env->gwion->mp, lhs)); @@ -50,7 +51,7 @@ ANN static Exp uncurry(const Env env, const Exp_Binary *bin) { return NULL; } -ANN static Type mk_call(const Env env, const Exp e, const Exp func, const Exp args) { +ANN static Type mk_call(const Env env, Exp* e, Exp* func, Exp* args) { Exp_Call call = {.func = func, .args = args }; e->exp_type = ae_exp_call; e->d.exp_call = call; @@ -62,7 +63,7 @@ static OP_CHECK(opck_func_call) { if(!strncmp(bin->rhs->type->name, "partial:", 8)) { const Stmt* stmt = mp_vector_at(bin->rhs->type->info->func->def->d.code, Stmt, 0); const Exp_Call *call = &stmt->d.stmt_exp.val->d.exp_call; - DECL_ON(const Exp, args, = uncurry(env, bin)); + DECL_ON(Exp*, args, = uncurry(env, bin)); return mk_call(env, exp_self(bin), call->func, args); } return mk_call(env, exp_self(bin), bin->rhs, bin->lhs); @@ -126,7 +127,7 @@ ANN static m_bool emit_fptr_assign(const Emitter emit, const Type lhs, const Typ const Capture_List captures = fdef->captures; if(captures) { uint32_t offset = 0; - Exp e = new_prim_id(emit->gwion->mp, fdef->base->tag.sym, fdef->base->tag.loc); // free me + Exp* e = new_prim_id(emit->gwion->mp, fdef->base->tag.sym, fdef->base->tag.loc); // free me for(uint32_t i = 0; i < captures->len; i++) { Capture *const cap = mp_vector_at(captures, Capture, i); e->d.prim.d.var = cap->var.tag.sym; @@ -156,7 +157,7 @@ static OP_EMIT(opem_fptr_assign) { struct FptrInfo { Func lhs; const Func rhs; - const Exp exp; + Exp* exp; }; ANN static void _fptr_tmpl_push(const Env env, const Func f) { @@ -474,7 +475,7 @@ static void op_narg_err(const Env env, const Func_Def fdef, const loc_t loc) { env_set_error(env, true); } } -static m_bool op_call_narg(const Env env, Exp arg, const loc_t loc) { +static m_bool op_call_narg(const Env env, Exp* arg, const loc_t loc) { m_uint narg = 0; while (arg) { narg++; @@ -487,8 +488,8 @@ static m_bool op_call_narg(const Env env, Exp arg, const loc_t loc) { ANN Type check_op_call(const Env env, Exp_Call *const exp) { CHECK_BO(op_call_narg(env, exp->args, exp->func->loc)); - const Exp base = exp_self(exp); - const Exp op_exp = exp->func; + Exp* base = exp_self(exp); + Exp* op_exp = exp->func; base->exp_type = ae_exp_binary; Exp_Binary *bin = &base->d.exp_binary; bin->lhs = exp->args; @@ -543,17 +544,17 @@ static OP_CHECK(opck_op_impl) { const Symbol rhs_sym = insert_symbol("@rhs"); const Arg *arg0 = (Arg*)(func->def->base->args->ptr); const Arg *arg1 = (Arg*)(func->def->base->args->ptr + sizeof(Arg)); - struct Exp_ _lhs = { + Exp _lhs = { .d = {.prim = {.d = {.var = lhs_sym}, .prim_type = ae_prim_id}}, .exp_type = ae_exp_primary, .type = arg0->type, .loc = arg0->var.td->tag.loc}; - struct Exp_ _rhs = { + Exp _rhs = { .d = {.prim = {.d = {.var = rhs_sym}, .prim_type = ae_prim_id}}, .exp_type = ae_exp_primary, .type = arg1->type, .loc = arg1->var.td->tag.loc}; - struct Exp_ self = {.loc = impl->e->loc}; + Exp self = {.loc = impl->e->loc}; self.d.exp_binary.lhs = &_lhs; self.d.exp_binary.rhs = &_rhs; self.d.exp_binary.op = impl->e->d.prim.d.var; @@ -601,11 +602,11 @@ static OP_CHECK(opck_op_impl) { } free_mp_vector(env->gwion->mp, struct ScopeEffect, eff); } - const Exp lhs = + Exp* lhs = new_prim_id(env->gwion->mp, larg0->var.vd.tag.sym, impl->e->loc); - const Exp rhs = + Exp* rhs = new_prim_id(env->gwion->mp, larg1->var.vd.tag.sym, impl->e->loc); - const Exp bin = new_exp_binary(env->gwion->mp, lhs, impl->e->d.prim.d.var, + Exp* bin = new_exp_binary(env->gwion->mp, lhs, impl->e->d.prim.d.var, rhs, impl->e->loc); Stmt_List code = new_mp_vector(env->gwion->mp, Stmt, 1); mp_vector_set(code, Stmt, 0, MK_STMT(ae_stmt_return, impl->e->loc, diff --git a/src/lib/deep_equal.c b/src/lib/deep_equal.c index 50babccd..de953016 100644 --- a/src/lib/deep_equal.c +++ b/src/lib/deep_equal.c @@ -62,7 +62,7 @@ static void compound_get_member(const Env env, const Type t, const Vector v) { type_get_member(env->gwion, t, v); } -ANN static inline void check_deep_equal_exp(const Env env, const Exp e, const Vector v) { +ANN static inline void check_deep_equal_exp(const Env env, Exp* e, const Vector v) { vector_init(v); compound_get_member(env, e->type, v); if(tflag(e->type, tflag_struct)) @@ -103,7 +103,7 @@ static bool deep_check(const Env env, const Exp_Binary *bin, for(m_uint i = 0; i < lsz; i++) { const Value lval = (Value)vector_at(l, i), rval = (Value)vector_at(r, i); - struct Exp_ lexp = MK_DOT(env, bin->lhs, lval), + Exp lexp = MK_DOT(env, bin->lhs, lval), rexp = MK_DOT(env, bin->rhs, rval), temp = MK_BIN(lexp, rexp, bin); if(!check_exp(env, &temp)) @@ -144,9 +144,9 @@ static OP_CHECK(opck_deep_equal) { } struct DeepEmit { - Exp exp; + Exp* exp; Value val; - Exp tmp; + Exp* tmp; struct Vector_ vec; }; @@ -207,9 +207,9 @@ ANN static bool deep_emit(const Emitter emit, struct DeepEmits *ds) { for(m_uint i = 0; i < vector_size(&ds->lhs->vec); i++) { const Value lhs = (Value)vector_at(&ds->lhs->vec, i), rhs = (Value)vector_at(&ds->rhs->vec, i); - struct Exp_ lexp = MK_DOT(emit, ds->lhs->tmp, lhs); - struct Exp_ rexp = MK_DOT(emit, ds->rhs->tmp, rhs); - struct Exp_ temp = MK_BIN(lexp, rexp, ds->bin); + Exp lexp = MK_DOT(emit, ds->lhs->tmp, lhs); + Exp rexp = MK_DOT(emit, ds->rhs->tmp, rhs); + Exp temp = MK_BIN(lexp, rexp, ds->bin); temp.type=emit->gwion->type[et_bool]; if(emit_exp(emit, &temp) < 0) return false; vector_add(&ds->acc, (m_uint)emit_add_instr(emit, BranchEqInt)); diff --git a/src/lib/dict.c b/src/lib/dict.c index c5af5357..200be739 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -285,10 +285,10 @@ static INSTR(hmap_remove) { } static OP_CHECK(opck_dict_remove_toop) { - const Exp e = (Exp)data; + Exp* e = (Exp*)data; const Exp_Call *call = &e->d.exp_call; - const Exp func = call->func; - const Exp args = call->args; + Exp* func = call->func; + Exp* args = call->args; e->exp_type = ae_exp_binary; CHECK_OO(check_exp(env, e->d.exp_binary.rhs = cpy_exp(env->gwion->mp, func->d.exp_dot.base))); CHECK_OO(check_exp(env, e->d.exp_binary.lhs = args)); @@ -302,7 +302,7 @@ static OP_CHECK(opck_dict_remove_toop) { } ANN static m_bool emit_dict_iter(const Emitter emit, const HMapInfo *hinfo, - const struct Op_Import *opi, const Exp call, const Exp exp) { + const struct Op_Import *opi, Exp* call, Exp* exp) { emit_pushimm(emit, -1); // room for tombstone CHECK_BB(emit_exp(emit, call)); const m_uint pc = emit_code_size(emit); @@ -326,9 +326,9 @@ static OP_EMIT(_opem_dict_access) { const HMapInfo *hinfo = (HMapInfo*)array->type->nspc->class_data; const Type key = *(Type*)array->type->nspc->class_data; - struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; + Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; - struct Exp_ call = { + Exp call = { .exp_type = ae_exp_call, .d = { .exp_call = { @@ -337,9 +337,9 @@ static OP_EMIT(_opem_dict_access) { } } }; -struct Exp_ lhs = { .exp_type = ae_exp_primary, .type = key, .d = { .prim = { .prim_type = ae_prim_id } }}; -struct Exp_ rhs = { .exp_type = ae_exp_primary, .type = key, .d = { .prim = { .prim_type = ae_prim_id } }}; -struct Exp_ bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }}; +Exp lhs = { .exp_type = ae_exp_primary, .type = key, .d = { .prim = { .prim_type = ae_prim_id } }}; +Exp rhs = { .exp_type = ae_exp_primary, .type = key, .d = { .prim = { .prim_type = ae_prim_id } }}; +Exp bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }}; struct Op_Import opi = { .lhs = key, .rhs = key, @@ -400,9 +400,9 @@ if(info->is_var) { static OP_EMIT(opem_dict_remove) { Exp_Binary *bin = (Exp_Binary*)data; const Env env = emit->env; - struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; + Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; - struct Exp_ call = { + Exp call = { .exp_type = ae_exp_call, .d = { .exp_call = { @@ -414,9 +414,9 @@ static OP_EMIT(opem_dict_remove) { const Type t = bin->rhs->type; HMapInfo *const hinfo = (HMapInfo*)t->nspc->class_data; - struct Exp_ lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; - struct Exp_ rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; - struct Exp_ _bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }}; + Exp lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; + Exp rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; + Exp _bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }}; struct Op_Import opi = { .lhs = hinfo->key, .rhs = hinfo->key, @@ -445,7 +445,7 @@ ANN static m_bool emit_next_access(const Emitter emit, struct ArrayAccessInfo *c static OP_EMIT(opem_dict_access) { struct ArrayAccessInfo *const info = (struct ArrayAccessInfo *const)data; const Array_Sub array = &info->array; - const Exp enext = array->exp->next; + Exp* enext = array->exp->next; array->exp->next = NULL; const m_bool ret = _opem_dict_access(emit, data); array->exp->next = enext; @@ -457,9 +457,9 @@ static OP_CHECK(opck_dict_access) { const Array_Sub array = (Array_Sub)data; HMapInfo *const hinfo = (HMapInfo*)array->type->nspc->class_data; - struct Exp_ func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; + Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; - struct Exp_ call = { + Exp call = { .exp_type = ae_exp_call, .d = { .exp_call = { @@ -468,9 +468,9 @@ static OP_CHECK(opck_dict_access) { } } }; -struct Exp_ lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; -struct Exp_ rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; -struct Exp_ bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }}; +Exp lhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; +Exp rhs = { .exp_type = ae_exp_primary, .type = hinfo->key, .d = { .prim = { .prim_type = ae_prim_id } }}; +Exp bin = { .exp_type = ae_exp_binary, .d = { .exp_binary = { .lhs = &lhs, .rhs = &rhs, .op = insert_symbol("?=") } }}; struct Op_Import opi = { .lhs = hinfo->key, .rhs = hinfo->key, @@ -542,13 +542,13 @@ static OP_EMIT(opem_dict_each_init) { } static OP_CHECK(opck_dict_each_key) { - const Exp exp = (const Exp)data; + Exp* exp = (Exp*)data; HMapInfo *const hinfo = (HMapInfo*)exp->type->nspc->class_data; return hinfo->key; } static OP_CHECK(opck_dict_each_val) { - const Exp exp = (const Exp)data; + Exp* exp = (Exp*)data; HMapInfo *const hinfo = (HMapInfo*)exp->type->nspc->class_data; return hinfo->val; } diff --git a/src/lib/lib_class.c b/src/lib/lib_class.c index 7ed463dd..a9ea29a6 100644 --- a/src/lib/lib_class.c +++ b/src/lib/lib_class.c @@ -26,7 +26,7 @@ mk_class_instr(le, r, l) mk_class_instr(lt, r, l, &&l != r) static OP_CHECK(opck_class_call) { const Exp_Binary *bin = (Exp_Binary *)data; Exp_Call call = {.func = bin->rhs, .args = bin->lhs}; - Exp e = exp_self(bin); + Exp* e = exp_self(bin); e->exp_type = ae_exp_call; memcpy(&e->d.exp_call, &call, sizeof(Exp_Call)); return check_exp_call1(env, &e->d.exp_call) ?: env->gwion->type[et_error]; diff --git a/src/lib/object.c b/src/lib/object.c index 97cdc77b..0f5ffbba 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -120,7 +120,7 @@ static ID_EMIT(opem_this) { } static ID_CHECK(opck_super) { - const Exp self = exp_self(prim); + Exp* self = exp_self(prim); if(!env->func || is_ctor(env->func->def)) ERR_O(self->loc, "can't use 'super' outside of constructor"); const Type parent = env->class_def->info->parent; @@ -131,7 +131,7 @@ static ID_CHECK(opck_super) { static ID_EMIT(opem_super) { const Env env = emit->env; - const Exp self = exp_self(prim); + Exp* self = exp_self(prim); if(!self->is_call) ERR_B(self->loc, "can only use 'super' as a function call"); emit_regpushmem(emit, 0, SZ_INT, false); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 657b14d3..d5ec3eed 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -42,13 +42,13 @@ static OP_CHECK(opck_object_at) { static OP_CHECK(opck_object_instance) { Exp_Binary *bin = (Exp_Binary*)data; - Exp rhs = bin->rhs; + Exp* rhs = bin->rhs; if (rhs->exp_type != ae_exp_decl) return NULL; if (rhs->d.exp_decl.var.td->array) return NULL; - Exp lhs = bin->lhs; - Exp e = exp_self(bin); + Exp* lhs = bin->lhs; + Exp* e = exp_self(bin); Exp_Decl *const decl = &e->d.exp_decl; e->exp_type = ae_exp_decl; decl->var.td = cpy_type_decl(env->gwion->mp, rhs->d.exp_decl.var.td); @@ -124,7 +124,7 @@ ANN static void emit_dottmpl(const Emitter emit, const Func f) { } ANN static void emit_member_func(const Emitter emit, const Exp_Dot *member) { - const Exp self = exp_self(member); + Exp* self = exp_self(member); const Func f = self->type->info->func; if(is_new(f->def)) { @@ -185,7 +185,7 @@ ANN static inline Value get_value(const Env env, const Exp_Dot *member, return NULL; } -ANN static m_bool member_access(const Env env, const Exp exp, const Value value) { +ANN static m_bool member_access(const Env env, Exp* exp, const Value value) { if (!env->class_def || isa(env->class_def, value->from->owner_class) < 0) { if (GET_FLAG(value, private)) { gwerr_basic("invalid variable access", "is private", NULL, env->name, @@ -201,7 +201,7 @@ ANN static m_bool member_access(const Env env, const Exp exp, const Value value) OP_CHECK(opck_object_dot) { Exp_Dot *const member = (Exp_Dot *)data; - Exp self = exp_self(member); + Exp* self = exp_self(member); const m_str str = s_name(member->xid); const m_bool base_static = is_class(env->gwion, member->base->type); const Type the_base = diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 1d3f2d76..955cf06e 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -36,7 +36,7 @@ OP_CHECK(opck_usr_implicit) { } if(f) { // TODO: add call exp - struct Exp_ call = { .exp_type=ae_exp_call, + Exp call = { .exp_type=ae_exp_call, .d={.exp_call={.args=imp->e}}, .pos=imp->e->loc, .type=f->value_ref->type }; struct Op_Import opi = { .op=insert_symbol("@func_check"), .rhs=f->value_ref->type, .pos=imp->e->loc, .data=(uintptr_t)&call }; @@ -136,11 +136,11 @@ OP_CHECK(opck_new) { CHECK_BN(check_subscripts(env, array, 1)); } if(unary->ctor.exp) { - const Exp self = exp_self(unary); - const Exp args = cpy_exp(env->gwion->mp, unary->ctor.exp); - const Exp base = new_exp_unary2(env->gwion->mp, unary->op, unary->ctor.td, unary->ctor.exp, self->loc); + Exp* self = exp_self(unary); + Exp* args = cpy_exp(env->gwion->mp, unary->ctor.exp); + Exp* base = new_exp_unary2(env->gwion->mp, unary->op, unary->ctor.td, unary->ctor.exp, self->loc); base->type = t; - const Exp func = new_exp_dot(env->gwion->mp, base, insert_symbol("new"), self->loc); + Exp* func = new_exp_dot(env->gwion->mp, base, insert_symbol("new"), self->loc); self->d.exp_call.func = func; self->d.exp_call.args = args; self->d.exp_call.tmpl = NULL; diff --git a/src/lib/prim.c b/src/lib/prim.c index 10602199..d812defa 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -192,14 +192,14 @@ static INSTR(IntRange) { } static OP_CHECK(opck_int_range) { - const Exp exp = (Exp)data; + Exp* exp = (Exp*)data; const Range *range = exp->d.prim.d.range; - const Exp e = range->start ?: range->end; + Exp* e = range->start ?: range->end; return array_type(env, e->type, 1, e->loc); } static OP_EMIT(opem_int_range) { - const Exp exp = (Exp)data; + Exp* exp = (Exp*)data; const Instr instr = emit_add_instr(emit, IntRange); instr->m_val = (m_uint)exp->type; return GW_OK; @@ -298,7 +298,7 @@ static OP_CHECK(opck_cast_f2i) { const m_float f = cast->exp->d.prim.d.fnum; free_type_decl(env->gwion->mp, cast->td); free_exp(env->gwion->mp, cast->exp); - Exp e = exp_self(cast); + Exp* e = exp_self(cast); e->exp_type = ae_exp_primary; e->d.prim.prim_type = ae_prim_num; e->d.prim.d.gwint.num = f; @@ -306,7 +306,7 @@ static OP_CHECK(opck_cast_f2i) { return env->gwion->type[et_int]; } /* -ANN static void tofloat(Exp e, const m_int i) { +ANN static void tofloat(Exp* e, const m_int i) { e->exp_type = ae_exp_primary; e->d.prim.prim_type = ae_prim_float; e->d.prim.d.fnum = i; @@ -318,7 +318,7 @@ static OP_CHECK(opck_cast_i2f) { const m_int i = cast->exp->d.prim.d.gwint.num; free_type_decl(env->gwion->mp, cast->td); free_exp(env->gwion->mp, cast->exp); - Exp e = exp_self(cast); + Exp* e = exp_self(cast); e->exp_type = ae_exp_primary; e->d.prim.prim_type = ae_prim_float; e->d.prim.d.fnum = i; @@ -490,7 +490,7 @@ static GWION_IMPORT(dur) { return gwi_oper_end(gwi, "<=", float_le); } -static inline int is_now(const Env env, const Exp exp) { +static inline int is_now(const Env env, Exp* exp) { return exp->exp_type == ae_exp_primary && exp->d.prim.prim_type == ae_prim_id && exp->d.prim.d.var == insert_symbol("now"); diff --git a/src/lib/ref.c b/src/lib/ref.c index 4fd56d62..4aa4ad1c 100644 --- a/src/lib/ref.c +++ b/src/lib/ref.c @@ -24,7 +24,7 @@ ANN Type ref_type(const Gwion gwion, const Type t, const loc_t loc) { return str2type(gwion, c, loc); } -static m_bool ref_access(const Env env, const Exp e) { +static m_bool ref_access(const Env env, Exp* e) { const m_str access = exp_access(e); if (!access) return GW_OK; env_err(env, e->loc, _("operand is %s"), access); @@ -84,7 +84,7 @@ static OP_EMIT(opem_ref_contract_similar) { const struct Implicit *imp = (struct Implicit *)data; const Env env = emit->env; const Type base = (Type)vector_front(&imp->t->info->tuple->contains); - struct Exp_ cast = {.type=base, .d={.exp_cast={.exp=imp->e}}}; + Exp cast = {.type=base, .d={.exp_cast={.exp=imp->e}}}; struct Op_Import opi = {.op = insert_symbol("$"), .lhs = imp->e->type, .rhs = base, diff --git a/src/lib/sift.c b/src/lib/sift.c index 659948de..1234873a 100644 --- a/src/lib/sift.c +++ b/src/lib/sift.c @@ -12,14 +12,14 @@ static OP_CHECK(opck_sift) { Exp_Binary *bin = (Exp_Binary*)data; - const Exp lhs = bin->lhs; + Exp* lhs = bin->lhs; Stmt* stmt = mp_vector_at(lhs->d.exp_unary.code, Stmt, 0); Stmt* fst = mp_vector_at(stmt->d.stmt_flow.body->d.stmt_code.stmt_list, Stmt, 0); const Symbol chuck = insert_symbol(env->gwion->st, "=>"); - Exp next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->loc); + Exp* next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->loc); CHECK_BN(traverse_exp(env, next)); // how do we free it? fst->d.stmt_exp.val = next; - const Exp exp = exp_self(bin); + Exp* exp = exp_self(bin); exp->exp_type = lhs->exp_type; exp->d.exp_unary.code = lhs->d.exp_unary.code; exp->type = lhs->type; @@ -34,19 +34,19 @@ static OP_CHECK(opck_ctrl) { if(bin->lhs->exp_type == ae_exp_decl) ERR_N(bin->lhs->loc, _("can't use declaration to start sift `|>` operator")); const Symbol chuck = insert_symbol(env->gwion->st, "=>"); - Exp exp = exp_self(data); + Exp* exp = exp_self(data); - Exp func = cpy_exp(mp, exp); - const Exp dot = new_exp_dot(mp, func->d.exp_binary.lhs, insert_symbol(env->gwion->st, "last"), func->loc); - const Exp call = new_exp_call(mp, dot, NULL, func->loc); + Exp* func = cpy_exp(mp, exp); + Exp* dot = new_exp_dot(mp, func->d.exp_binary.lhs, insert_symbol(env->gwion->st, "last"), func->loc); + Exp* call = new_exp_call(mp, dot, NULL, func->loc); func->d.exp_binary.lhs = call; func->d.exp_binary.op = chuck; CHECK_BN(traverse_exp(env, func)); Stmt one = { .d = { .stmt_exp = { .val = func }}, .stmt_type = ae_stmt_exp, .loc = func->loc }; - Exp samp = new_prim_id(mp, insert_symbol(env->gwion->st, "samp"), func->loc); - Exp _now = new_prim_id(mp, insert_symbol(env->gwion->st, "now"), func->loc); - Exp time = new_exp_binary(mp, samp, chuck, _now, func->loc); + Exp* samp = new_prim_id(mp, insert_symbol(env->gwion->st, "samp"), func->loc); + Exp* _now = new_prim_id(mp, insert_symbol(env->gwion->st, "now"), func->loc); + Exp* time = new_exp_binary(mp, samp, chuck, _now, func->loc); CHECK_BN(traverse_exp(env, time)); Stmt two = { .d = { .stmt_exp = { .val = time }}, .stmt_type = ae_stmt_exp, .loc = func->loc }; @@ -57,7 +57,7 @@ static OP_CHECK(opck_ctrl) { mp_vector_set(slist, Stmt, 1, two); Stmt* stmt = new_stmt_code(mp, slist, func->loc); - const Exp cond = new_prim_id(mp, insert_symbol(env->gwion->st, "true"), func->loc); + Exp* cond = new_prim_id(mp, insert_symbol(env->gwion->st, "true"), func->loc); check_exp(env, cond); const Stmt_List code = new_mp_vector(mp, Stmt, 1); diff --git a/src/lib/string.c b/src/lib/string.c index a4b45207..3b60ffbf 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -26,7 +26,7 @@ describe_string_logical(eq, (!strcmp(STRING(lhs), STRING(rhs)))) describe_string_logical(neq, (strcmp(STRING(lhs), STRING(rhs)))) - static inline uint is_const_str(const Exp exp) { + static inline uint is_const_str(Exp* exp) { return exp->exp_type == ae_exp_primary && exp->d.prim.prim_type == ae_prim_str; } @@ -39,7 +39,7 @@ describe_string_logical(eq, (!strcmp(STRING(lhs), STRING(rhs)))) const int ret = __exp__; \ free_exp(env->gwion->mp, bin->lhs); \ free_exp(env->gwion->mp, bin->rhs); \ - const Exp e = exp_self(bin); \ + Exp* e = exp_self(bin); \ e->exp_type = ae_exp_primary; \ e->d.prim.prim_type = ae_prim_num; \ e->d.prim.d.gwint.num = ret; \ @@ -425,7 +425,7 @@ ANN Type check_array_access(const Env env, const Array_Sub array); static OP_CHECK(opck_string_access) { const Array_Sub array = (Array_Sub)data; - const Exp exp = array->exp; + Exp* exp = array->exp; if(!exp->next) return env->gwion->type[et_char]; struct Array_Sub_ next = { exp->next, env->gwion->type[et_char], array->depth - 1 }; @@ -465,8 +465,8 @@ static INSTR(string_at_set) { static OP_EMIT(opem_string_access) { struct ArrayAccessInfo *info = (struct ArrayAccessInfo*)data; - const Exp exp = info->array.exp; - const Exp next = exp->next; + Exp* exp = info->array.exp; + Exp* next = exp->next; CHECK_BB(emit_exp(emit, exp)); exp->next = next; emit_add_instr(emit, !info->is_var ? string_at : string_at_set); diff --git a/src/lib/union.c b/src/lib/union.c index 616cec3d..63829678 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -67,9 +67,9 @@ ANN void union_release(const VM_Shred shred, const Type t, const m_bit *data) { } static OP_CHECK(opck_union_is) { - const Exp e = (Exp)data; + Exp* e = (Exp*)data; const Exp_Call *call = &e->d.exp_call; - const Exp exp = call->args; + Exp* exp = call->args; if(!exp) ERR_N(e->loc, "Union.is() takes one argument of form id"); if (exp->exp_type != ae_exp_primary || exp->d.prim.prim_type != ae_prim_id) @@ -83,8 +83,8 @@ static OP_CHECK(opck_union_is) { for (m_uint i = 0; i < map_size(map); ++i) { const Value v = (Value)VVAL(map, i); if (!strcmp(s_name(exp->d.prim.d.var), v->name)) { - const Exp exp_func = call->func; - const Exp exp_args = call->args; + Exp* exp_func = call->func; + Exp* exp_args = call->args; e->exp_type = ae_exp_binary; e->d.exp_binary.lhs = cpy_exp(env->gwion->mp, exp_func); e->d.exp_binary.lhs->d.exp_dot.xid = @@ -114,13 +114,13 @@ static MFUN(union_new) { #undef insert_symbol static OP_CHECK(opck_union_new) { Exp_Call *call = (Exp_Call *)data; - const Exp name = call->args; + Exp* name = call->args; if (!name) ERR_N(call->func->loc, "Union constructor takes one or two arguments, " "'id' and 'value'"); if (name->exp_type != ae_exp_primary || name->d.prim.prim_type != ae_prim_id) ERR_N(call->func->loc, "Union constructor first argument me be an identifier"); - const Exp val = name->next; + Exp* val = name->next; const Type base = call->func->d.exp_dot.base->type; const Map map = &base->nspc->info->value->map; @@ -131,7 +131,7 @@ static OP_CHECK(opck_union_new) { name->d.prim.d.gwint.num = i; name->type = env->gwion->type[et_int]; if(!val && v->type == env->gwion->type[et_none]) { - const Exp e = new_prim_int(env->gwion->mp, SZ_INT, name->loc); + Exp* e = new_prim_int(env->gwion->mp, SZ_INT, name->loc); e->next = name; e->type = env->gwion->type[et_int]; name->next = new_prim_int(env->gwion->mp, 0, name->loc); @@ -145,7 +145,7 @@ static OP_CHECK(opck_union_new) { ERR_N(val->loc, "Invalid type '%s' for '%s', should be '%s'", t->name, v->name, v->type->name); } - const Exp e = new_prim_int(env->gwion->mp, t->size + SZ_INT, val->loc); + Exp* e = new_prim_int(env->gwion->mp, t->size + SZ_INT, val->loc); e->next = name; e->type = env->gwion->type[et_int]; call->args = e; diff --git a/src/parse/check.c b/src/parse/check.c index a9b81f33..decbd493 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -21,7 +21,7 @@ ANN 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); -ANN static Type check_internal(const Env env, const Symbol sym, const Exp e, +ANN static Type check_internal(const Env env, const Symbol sym, Exp* e, const Type t) { struct Implicit imp = {.e = e, .t = t, .loc = e->loc}; struct Op_Import opi = {.op = sym, @@ -32,7 +32,7 @@ ANN static Type check_internal(const Env env, const Symbol sym, const Exp e, return op_check(env, &opi); } -ANN m_bool check_implicit(const Env env, const Exp e, const Type t) { +ANN m_bool check_implicit(const Env env, Exp* e, const Type t) { if (e->type == t) return GW_OK; if (isa(e->type, t) > 0) return GW_OK; const Symbol sym = insert_symbol("@implicit"); @@ -43,7 +43,7 @@ ANN m_bool check_subscripts(Env env, const Array_Sub array, const m_bool is_decl) { CHECK_OB(check_exp(env, array->exp)); m_uint depth = 0; - Exp e = array->exp; + Exp* e = array->exp; do { if (is_decl) { if(check_implicit(env, e, env->gwion->type[et_int]) < 0) @@ -164,7 +164,7 @@ ANN Type check_exp_decl(const Env env, Exp_Decl *const decl) { if (decl->var.td->array && decl->var.td->array->exp) CHECK_OO(check_exp(env, decl->var.td->array->exp)); if (decl->args) { - const Exp e = new_exp_unary2(env->gwion->mp, insert_symbol("new"), cpy_type_decl(env->gwion->mp, decl->var.td), decl->args, decl->var.td->tag.loc); + Exp* e = new_exp_unary2(env->gwion->mp, insert_symbol("new"), cpy_type_decl(env->gwion->mp, decl->var.td), decl->args, decl->var.td->tag.loc); CHECK_OO(check_exp(env, e)); decl->args = e; e->ref = exp_self(decl); @@ -193,7 +193,7 @@ ANN Type check_exp_decl(const Env env, Exp_Decl *const decl) { return ret > 0 ? decl->var.vd.value->type : NULL; } -ANN static m_bool check_collection(const Env env, Type type, const Exp e, +ANN static m_bool check_collection(const Env env, Type type, Exp* e, const loc_t loc) { const Type common = find_common_anc(e->type, type); if (common) return GW_OK; @@ -210,7 +210,7 @@ ANN static m_bool check_collection(const Env env, Type type, const Exp e, return GW_ERROR; } -ANN static inline Type prim_array_match(const Env env, Exp e) { +ANN static inline Type prim_array_match(const Env env, Exp* e) { const Type type = e->type; bool err = false; const loc_t loc = e->loc; @@ -224,7 +224,7 @@ ANN static inline Type prim_array_match(const Env env, Exp e) { ANN static Type check_prim_array(const Env env, const Array_Sub *data) { const Array_Sub array = *data; - const Exp e = array->exp; + Exp* e = array->exp; if (!e) ERR_O(prim_pos(data), _("must provide values/expressions for array [...]")) CHECK_OO(check_exp(env, e)); @@ -246,7 +246,7 @@ ANN static Type check_prim_range(const Env env, Range **data) { Range *range = *data; CHECK_BO(check_range(env, range)); env_weight(env, 1); - const Exp e = range->start ?: range->end; + Exp* e = range->start ?: range->end; assert(e); const Symbol sym = insert_symbol("[:]"); struct Op_Import opi = {.op = sym, @@ -256,14 +256,14 @@ ANN static Type check_prim_range(const Env env, Range **data) { return op_check(env, &opi); } -ANN static Type check_prim_dict(const Env env, Exp *data) { - const Exp base = *data; +ANN static Type check_prim_dict(const Env env, Exp* *data) { + Exp* base = *data; CHECK_OO(check_exp(env, base)); const Type key = base->type; const Type val = base->next->type; bool err = false; const loc_t loc = base->loc; - Exp e = base; + Exp* e = base; env_weight(env, 1); do { if (check_collection(env, key, e, loc) < 0) err = true; @@ -372,14 +372,14 @@ ANN static m_bool check_upvalue(const Env env, const Exp_Primary *prim, const Va } ANN static Type prim_owned(const Env env, const Symbol *data) { - const Exp exp = exp_self(prim_exp(data)); + Exp* exp = exp_self(prim_exp(data)); const Value v = exp->d.prim.value; if(is_class(env->gwion, v->type) && env->class_def == v->type->info->base_type) // write it better return v->type->info->base_type; // if(v->from->owner_class && is_func(env->gwion, v->from->owner_class)) // return v->type; const m_str name = !GET_FLAG(v, static) ? "this" : v->from->owner_class->name; - const Exp base = + Exp* base = new_prim_id(env->gwion->mp, insert_symbol(name), prim_pos(data)); exp_setuse(base, 1); exp->exp_type = ae_exp_dot; @@ -472,13 +472,13 @@ ANN static Type check_prim_perform(const Env env, const Symbol *data) { return env->gwion->type[et_void]; } -ANN static Type check_prim_interp(const Env env, const Exp *exp) { +ANN static Type check_prim_interp(const Env env, Exp* *exp) { CHECK_OO(check_exp(env, *exp)); env_weight(env, 1); return env->gwion->type[et_string]; } -ANN static Type check_prim_hack(const Env env, const Exp *data) { +ANN static Type check_prim_hack(const Env env, Exp* *data) { if (env->func) unset_fflag(env->func, fflag_pure); CHECK_OO(check_prim_interp(env, data)); env_weight(env, 1); @@ -529,7 +529,7 @@ static ANN Type check_exp_slice(const Env env, const Exp_Slice *range) { CHECK_BO(check_range(env, range->range)); env_weight(env, 1); const Symbol sym = insert_symbol("[:]"); - const Exp e = range->range->start ?: range->range->end; + Exp* e = range->range->start ?: range->range->end; assert(e); struct Op_Import opi = {.op = sym, .lhs = e->type, @@ -577,11 +577,11 @@ ANN static Type tmplarg_match(const Env env, const Symbol xid, const Symbol tgt, } ANN2(1, 2) -static Func find_func_match_actual(const Env env, const Func f, const Exp exp, +static Func find_func_match_actual(const Env env, const Func f, Exp* exp, const bool implicit, const bool specific) { Func func = f; do { - Exp e = exp; + Exp* e = exp; Arg_List args = func->def->base->args; m_uint i = 0; const m_uint args_len = mp_vector_len(args); @@ -618,7 +618,7 @@ static Func find_func_match_actual(const Env env, const Func f, const Exp exp, ANN static Type check_exp_call(const Env env, Exp_Call *exp); ANN static Func call2ufcs(const Env env, Exp_Call *call, const Value v) { - const Exp this = call->func->d.exp_dot.base; + Exp* this = call->func->d.exp_dot.base; this->next = call->args; call->args = this; call->func->type = v->type; @@ -639,8 +639,8 @@ ANN static Func ufcs(const Env env, const Func up, Exp_Call *const call) { ANN Func find_func_match(const Env env, const Func up, Exp_Call *const call) { Func func; - const Exp exp = call->args; - const Exp args = + Exp* exp = call->args; + Exp* args = (exp && isa(exp->type, env->gwion->type[et_void]) < 0) ? exp : NULL; if ((func = find_func_match_actual(env, up, args, false, true)) || (func = find_func_match_actual(env, up, args, true, true)) || @@ -680,24 +680,21 @@ ANN static m_bool check_func_args(const Env env, Arg_List args) { return GW_OK; } -#define next_arg(type) \ - ANN static inline type next_arg_##type(const type e) { \ - const type next = e->next; \ - if (next) gw_err(", "); \ - return next; \ - } -next_arg(Exp) -//next_arg(Arg_List); +ANN static inline Exp* next_arg_exp(const Exp *e) { + Exp* next = e->next; + if (next) gw_err(", "); + return next; +} -ANN static void print_current_args(Exp e) { +ANN static void print_current_args(Exp* e) { gw_err(_("and not\n ")); do gw_err(" {G}%s{0}", e->type ? e->type->name : ""); - while ((e = next_arg_Exp(e))); + while ((e = next_arg_exp(e))); gw_err("\n"); } ANN2(1) -static void function_alternative(const Env env, const Type t, const Exp args, +static void function_alternative(const Env env, const Type t, Exp* args, const loc_t loc) { if (env->context && env->context->error) // needed for ufcs return; @@ -804,7 +801,7 @@ ANN static TmplArg_List check_template_args(const Env env, Exp_Call *exp, Specialized *spec = mp_vector_at(sl, Specialized, i); Arg_List args = fdef->base->args; const uint32_t args_len = mp_vector_len(args); - Exp template_arg = exp->args; + Exp* template_arg = exp->args; uint32_t count = 0; while (count < args_len && template_arg) { Arg *arg = mp_vector_at(args, Arg, count); @@ -825,7 +822,7 @@ ANN static TmplArg_List check_template_args(const Env env, Exp_Call *exp, ERR_O(exp->func->loc, _("not able to infer types for template call.")) if(spread) { - Exp e = exp->args; + Exp* e = exp->args; if(fdef->base->args) for(uint32_t i = 0; i < fdef->base->args->len && e; i++) e = e->next; while(e) { @@ -862,7 +859,7 @@ ANN static Type check_exp_call_template(const Env env, Exp_Call *exp) { ANN Type upvalue_type(const Env env, Capture *cap); ANN static m_bool lambda_args_ref(const Env env, Exp_Call *const call) { - Exp e = call->args; + Exp* e = call->args; CHECK_OB(check_exp(env, e)); do if(tflag(e->type, tflag_ref) && !safe_tflag(exp_self(e)->cast_to, tflag_ref)) exp_setvar(e, true); @@ -870,20 +867,21 @@ ANN static m_bool lambda_args_ref(const Env env, Exp_Call *const call) { return GW_OK; } -ANN2(1) static m_bool lambda_append_args(const Env env, Exp_Call *const call, const Exp add) { +ANN2(1) static m_bool lambda_append_args(const Env env, Exp_Call *const call, Exp* add) { if(!add) return GW_ERROR; if (call->args) { - Exp e = call->args; + Exp* e = call->args; while(e->next) e = e->next; e->next = add; } else call->args = add; return traverse_exp(env, add); } -ANN static Exp check_lambda_captures(const Env env, const Func_Def fdef) { +ANN static Exp* check_lambda_captures(const Env env, const Func_Def fdef) { if(!fdef->base->args) fdef->base->args = new_mp_vector(env->gwion->mp, Arg, 0); - Exp args = NULL, tmp; + Exp* args = NULL; + Exp* tmp; for(uint32_t i = 0; i < fdef->captures->len; i++) { Capture *const cap = mp_vector_at(fdef->captures, Capture, i); const Type t = upvalue_type(env, cap); @@ -896,7 +894,7 @@ ANN static Exp check_lambda_captures(const Env env, const Func_Def fdef) { (Var_Decl){ .tag = MK_TAG(cap->var.tag.sym, cap->var.tag.loc) } )}; mp_vector_add(env->gwion->mp, &fdef->base->args, Arg, arg); - const Exp exp = new_prim_id(env->gwion->mp, cap->var.tag.sym, cap->var.tag.loc); + Exp* exp = new_prim_id(env->gwion->mp, cap->var.tag.sym, cap->var.tag.loc); if(args) tmp = tmp->next = exp; else args = tmp = exp; } @@ -909,11 +907,11 @@ ANN static Type check_lambda_call(const Env env, Exp_Call *const exp) { const Func_Def fdef = exp->func->d.exp_lambda.def; const bool captures = !!fdef->captures; if (exp->args) CHECK_BO(lambda_args_ref(env, exp)); - const Exp _args = !captures ? NULL : check_lambda_captures(env, fdef); + Exp* _args = !captures ? NULL : check_lambda_captures(env, fdef); if(captures) CHECK_BO(lambda_append_args(env, exp, _args)); Exp_Lambda *l = &exp->func->d.exp_lambda; Arg_List args = l->def->base->args; - Exp e = exp->args; + Exp* e = exp->args; for(uint32_t i = 0; i < (args ? args->len : 0); i++) { if(!e) ERR_O(exp_self(exp)->loc, _("argument number does not match for lambda")) @@ -953,7 +951,7 @@ ANN m_bool func_check(const Env env, Exp_Call *const exp) { if (exp->args) CHECK_OB(check_exp(env, exp->args)); return call2ufcs(env, exp, t->info->func->value_ref) ? GW_OK : GW_ERROR; } - const Exp e = exp_self(exp); + Exp* e = exp_self(exp); struct Op_Import opi = {.op = insert_symbol("@func_check"), .rhs = t, .loc = e->loc, @@ -988,7 +986,7 @@ ANN Type call_type(const Env env, Exp_Call *const exp) { return op_check(env, &opi); } -ANN static inline bool is_super(const Exp func) { +ANN static inline bool is_super(Exp* func) { return func->exp_type == ae_exp_primary && func->d.prim.prim_type == ae_prim_id && !strcmp(s_name(func->d.prim.d.var), "super"); @@ -1017,7 +1015,7 @@ ANN Type _check_exp_call1(const Env env, Exp_Call *const exp) { return check_lambda_call(env, exp); if (exp->args) { CHECK_OO(check_exp(env, exp->args)); - Exp e = exp->args; + Exp* e = exp->args; do exp_setuse(e, true); while((e = e->next)); } @@ -1029,7 +1027,7 @@ ANN Type _check_exp_call1(const Env env, Exp_Call *const exp) { ? NULL : partial_type(env, exp); } -ANN static Type check_static(const Env env, const Exp e) { +ANN static Type check_static(const Env env, Exp* e) { const Type t = e->type; if(unlikely(!is_func(env->gwion, t)) || !t->info->func || @@ -1049,8 +1047,8 @@ ANN Type check_exp_call1(const Env env, Exp_Call *const exp) { if(_ret) return _ret; if(isa(exp->func->type, env->gwion->type[et_closure]) > 0) { if(exp->func->exp_type == ae_exp_dot && t->info->value->from->owner_class) { - const Exp args = exp->args; - const Exp this_arg = cpy_exp(env->gwion->mp, exp->func->d.exp_dot.base); + Exp* args = exp->args; + Exp* this_arg = cpy_exp(env->gwion->mp, exp->func->d.exp_dot.base); this_arg->next = args; exp->args = this_arg; const Type t = _check_exp_call1(env, exp); @@ -1077,9 +1075,9 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { bin->rhs->exp_type == ae_exp_unary && bin->rhs->d.exp_unary.unary_type == unary_td && !bin->rhs->d.exp_unary.ctor.td->array && !bin->rhs->d.exp_unary.ctor.exp) { - Exp lhs = bin->lhs; - Exp rhs = bin->rhs; - Exp e = exp_self(bin); + Exp* lhs = bin->lhs; + Exp* rhs = bin->rhs; + Exp* e = exp_self(bin); Exp_Unary *const unary = &e->d.exp_unary; e->exp_type = ae_exp_unary; unary->unary_type = unary_td; @@ -1147,7 +1145,7 @@ ANN static m_bool predefined_call(const Env env, const Type t, return GW_ERROR; } -ANN2(1) static inline bool is_partial(const Env env, Exp exp) { +ANN2(1) static inline bool is_partial(const Env env, Exp* exp) { while (exp) { if (is_hole(env, exp) || is_typed_hole(env, exp)) return true; @@ -1229,7 +1227,7 @@ ANN static Type check_exp_unary(const Env env, const Exp_Unary *unary) { return ret; } -ANN static Type _flow(const Env env, const Exp e, const m_bool b) { +ANN static Type _flow(const Env env, Exp* e, const m_bool b) { DECL_OO(const Type, type, = check_exp(env, e)); struct Op_Import opi = { .op = insert_symbol(b ? "@conditional" : "@unconditional"), @@ -1242,7 +1240,7 @@ ANN static Type _flow(const Env env, const Exp e, const m_bool b) { ANN static Type check_exp_if(const Env env, Exp_If *const exp_if) { if (!exp_if->if_exp) { - const Exp e = exp_if->if_exp = cpy_exp(env->gwion->mp, exp_if->cond); + Exp* e = exp_if->if_exp = cpy_exp(env->gwion->mp, exp_if->cond); scan1_exp(env, e); scan2_exp(env, e); } @@ -1283,9 +1281,9 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { env->gwion->mp, type2td(env->gwion, tdef->type, tdef->tag.loc), insert_symbol("@implicit"), args, ae_flag_none, tdef->tag.loc); set_fbflag(fb, fbflag_op); - const Exp helper = new_prim_id(env->gwion->mp, insert_symbol("@predicate"), + Exp* helper = new_prim_id(env->gwion->mp, insert_symbol("@predicate"), tdef->when->loc); - const Exp when = tdef->when; + Exp* when = tdef->when; tdef->when = NULL; when->next = helper; Stmt_List code = new_mp_vector(env->gwion->mp, Stmt, 2); @@ -1307,7 +1305,7 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { } // we handle the return after, so that we don't get *cant' use implicit // casting while defining it* - const Exp ret_id = new_prim_id(env->gwion->mp, insert_symbol("self"), when->loc); + Exp* ret_id = new_prim_id(env->gwion->mp, insert_symbol("self"), when->loc); ret_id->d.prim.value = new_value(env, tdef->type, "self", tdef->tag.loc); Stmt ret = { .stmt_type = ae_stmt_return, .d = { .stmt_exp = { .val = ret_id }}, @@ -1336,8 +1334,8 @@ ANN static Type check_exp_td(const Env env, Type_Decl **td) { DECL_EXP_FUNC(check, Type, Env) -ANN Type check_exp(const Env env, const Exp exp) { - Exp curr = exp; +ANN Type check_exp(const Env env, Exp* exp) { + Exp* curr = exp; if (!exp->type) { env_weight(env, 1); do { @@ -1401,7 +1399,7 @@ ANN static void check_idx(const Env env, const Type base, struct EachIdx_ *const /** sets for the key expression value with eg type *int* for an array or the *Key* type of a Dict **/ -ANN static m_bool check_each_idx(const Env env, const Exp exp, struct EachIdx_ *const idx) { +ANN static m_bool check_each_idx(const Env env, Exp* exp, struct EachIdx_ *const idx) { struct Op_Import opi = { .lhs = exp->type, .op = insert_symbol("@each_idx"), @@ -1415,7 +1413,7 @@ ANN static m_bool check_each_idx(const Env env, const Exp exp, struct EachIdx_ * /** return the base type for the foreach expression eg the base type of an array or the *Val* type of a Dict **/ -ANN static Type check_each_val(const Env env, const Exp exp) { +ANN static Type check_each_val(const Env env, Exp* exp) { struct Op_Import opi = { .lhs = exp->type, .op = insert_symbol("@each_val"), @@ -1440,7 +1438,7 @@ ANN static m_bool do_stmt_repeat(const Env env, const Stmt_Loop stmt) { return check_conts(env, stmt_self(stmt), stmt->body); } -ANN static inline m_bool repeat_type(const Env env, const Exp e) { +ANN static inline m_bool repeat_type(const Env env, Exp* e) { const Type t_int = env->gwion->type[et_int]; if (check_implicit(env, e, t_int) < 0) { char explain[40 + strlen(e->type->name)]; @@ -1546,7 +1544,7 @@ ANN static Value match_value(const Env env, const Type base, return v; } -ANN Symbol case_basic_op(const Env env, const Type base, const Exp e) { +ANN Symbol case_basic_op(const Env env, const Type base, Exp* e) { const Symbol _op = insert_symbol("=="); struct Op_Import opi = {.op = _op, .lhs = base, @@ -1558,7 +1556,7 @@ ANN Symbol case_basic_op(const Env env, const Type base, const Exp e) { : insert_symbol("?="); } -ANN static Symbol case_op(const Env env, const Type base, const Exp e) { +ANN static Symbol case_op(const Env env, const Type base, Exp* e) { if (e->exp_type == ae_exp_primary) { if (e->d.prim.prim_type == ae_prim_id) { if (e->d.prim.d.var == insert_symbol("_")) return NULL; @@ -1569,7 +1567,7 @@ ANN static Symbol case_op(const Env env, const Type base, const Exp e) { } } else if (tflag(base, tflag_union) && e->exp_type == ae_exp_call) { - const Exp func = e->d.exp_call.func; + Exp* func = e->d.exp_call.func; if (func->d.prim.prim_type == ae_prim_id) { const Value v = find_value(base, func->d.prim.d.var); if (v) { @@ -1583,21 +1581,21 @@ ANN static Symbol case_op(const Env env, const Type base, const Exp e) { return case_basic_op(env, base, e); } -ANN static m_bool match_case_exp(const Env env, Exp e) { - Exp last = e; +ANN static m_bool match_case_exp(const Env env, Exp* e) { + Exp* last = e; for (m_uint i = 0; i < vector_size(&env->scope->match->cond); e = e->next, ++i) { if (!e) ERR_B(last->loc, _("no enough to match")) last = e; - const Exp base = (Exp)vector_at(&env->scope->match->cond, i); + Exp* base = (Exp*)vector_at(&env->scope->match->cond, i); const Symbol op = case_op(env, base->type, e); if (op) { - const Exp next = e->next; + Exp* next = e->next; e->next = NULL; const Type t = check_exp(env, e); e->next = next; CHECK_OB(t); Exp_Binary bin = {.lhs = cpy_exp(env->gwion->mp, base), .rhs = cpy_exp(env->gwion->mp, e), .op = op}; - struct Exp_ ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc }; + Exp ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc }; CHECK_BB(traverse_exp(env, &ebin)); const Type ret = ebin.type; if(ebin.exp_type == ae_exp_binary) { @@ -1703,10 +1701,10 @@ ANN static m_bool check_stmt_pp(const Env env, const Stmt_PP stmt) { env->func->memoize = strtol(stmt->data + 7, NULL, 10); else if(stmt->pp_type == ae_pp_locale) { const loc_t loc = stmt_self(stmt)->loc; - const Exp id = new_prim_id(env->gwion->mp, stmt->xid, loc); - const Exp arg = new_prim_id(env->gwion->mp, insert_symbol("_"), loc); + Exp* id = new_prim_id(env->gwion->mp, stmt->xid, loc); + Exp* arg = new_prim_id(env->gwion->mp, insert_symbol("_"), loc); arg->next = stmt->exp; - const Exp call = new_exp_call(env->gwion->mp, id, arg, loc); + Exp* call = new_exp_call(env->gwion->mp, id, arg, loc); stmt->exp = call; CHECK_BB(traverse_exp(env, id)); CHECK_OB(partial_type(env, &call->d.exp_call)); @@ -2128,7 +2126,7 @@ ANN static bool class_def_has_body(Ast ast) { const Stmt* stmt = mp_vector_at(l, Stmt, i); if (stmt->stmt_type == ae_stmt_pp) continue; if (stmt->stmt_type == ae_stmt_exp) { - const Exp exp = stmt->d.stmt_exp.val; + Exp* exp = stmt->d.stmt_exp.val; if (!exp) continue; if (exp->exp_type != ae_exp_decl) return true; if (GET_FLAG(exp->d.exp_decl.var.td, late)) continue; diff --git a/src/parse/default_arg.c b/src/parse/default_arg.c index 6a389862..6d933de5 100644 --- a/src/parse/default_arg.c +++ b/src/parse/default_arg.c @@ -5,53 +5,53 @@ #include "gwion.h" #include "traverse.h" -ANN2(1,2) static Exp base_args(const MemPool p, const Arg_List args, Exp next, const uint32_t min) { +ANN2(1,2) static Exp* base_args(const MemPool p, const Arg_List args, Exp* next, const uint32_t min) { for(uint32_t i = min; i--;) { Arg *arg = mp_vector_at(args, Arg, i); - const Exp exp = new_prim_id(p, arg->var.vd.tag.sym, arg->var.vd.tag.loc); + Exp* exp = new_prim_id(p, arg->var.vd.tag.sym, arg->var.vd.tag.loc); exp->next = next; next = exp; } return next; } -ANN static Exp additional_args(const MemPool p, const Arg_List args, const uint32_t max) { - Exp next = NULL; +ANN static Exp* additional_args(const MemPool p, const Arg_List args, const uint32_t max) { + Exp* next = NULL; for(uint32_t i = max; i-- > args->len;) { Arg *arg = mp_vector_at(args, Arg, i); - const Exp exp = cpy_exp(p, arg->exp); + Exp* exp = cpy_exp(p, arg->exp); exp->next = next; next = exp; } return next; } -ANN static Exp mk_args(const MemPool p, const Arg_List args, const uint32_t max) { - const Exp next = additional_args(p, args, max); +ANN static Exp* mk_args(const MemPool p, const Arg_List args, const uint32_t max) { + Exp* next = additional_args(p, args, max); return base_args(p, args, next, args->len); } -ANN static Stmt_List code(const MemPool p, const Exp func, const Arg_List lst, +ANN static Stmt_List code(const MemPool p, Exp* func, const Arg_List lst, const uint32_t max, const ae_stmt_t type) { - const Exp arg = mk_args(p, lst, max); - const Exp call = new_exp_call(p, func, arg, func->loc); + Exp* arg = mk_args(p, lst, max); + Exp* call = new_exp_call(p, func, arg, func->loc); Stmt_List code = new_mp_vector(p, Stmt, 1); - mp_vector_set(code, Stmt, 0, MK_STMT(ae_stmt_return, func->loc, .stmt_exp = { .val = call})); + mp_vector_set(code, Stmt, 0, MK_STMT(type, func->loc, .stmt_exp = { .val = call})); return code; } ANN static Stmt_List std_code(const Env env, Func_Base *base, const uint32_t max) { const MemPool p = env->gwion->mp; - const Exp func = new_prim_id(p, base->tag.sym, base->tag.loc); + Exp* func = new_prim_id(p, base->tag.sym, base->tag.loc); return code(p, func, base->args, max, ae_stmt_return); } ANN static Stmt_List new_code(const Env env, Func_Base *base, const uint32_t max) { const MemPool p = env->gwion->mp; SymTable *st = env->gwion->st; - const Exp dbase = new_prim_id(p, insert_symbol(st, "this"), base->tag.loc); + Exp* dbase = new_prim_id(p, insert_symbol(st, "this"), base->tag.loc); const Symbol sym = insert_symbol(st, "new"); - const Exp func = new_exp_dot(p, dbase, sym, base->tag.loc); + Exp* func = new_exp_dot(p, dbase, sym, base->tag.loc); return code(p, func, base->args, max, ae_stmt_exp); } diff --git a/src/parse/operator.c b/src/parse/operator.c index eff79b81..ffeddd1d 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -14,7 +14,7 @@ #include "traverse.h" #include "clean.h" -typedef Type (*f_type)(const Env env, const Exp exp); +typedef Type (*f_type)(const Env env, Exp* exp); typedef struct M_Operator_ { Type lhs, rhs, ret; @@ -297,8 +297,8 @@ ANN void* op_get(const Env env, struct Op_Import *opi) { ANN static Type chuck_rewrite(const Env env, const struct Op_Import *opi, const m_str op, const size_t len) { Exp_Binary *base = (Exp_Binary*)opi->data; - const Exp lhs = cpy_exp(env->gwion->mp, base->lhs); // no need to copy - const Exp call = new_exp_call(env->gwion->mp, cpy_exp(env->gwion->mp, base->rhs), NULL, lhs->loc); + Exp* lhs = cpy_exp(env->gwion->mp, base->lhs); // no need to copy + Exp* call = new_exp_call(env->gwion->mp, cpy_exp(env->gwion->mp, base->rhs), NULL, lhs->loc); char c[len - 1]; strncpy(c, op, len - 2); c[len - 2] = '\0'; @@ -308,7 +308,7 @@ ANN static Type chuck_rewrite(const Env env, const struct Op_Import *opi, const env_set_error(env, true); return NULL; } - const Exp bin = new_exp_binary(env->gwion->mp, lhs, insert_symbol(env->gwion->st, c), call, exp_self(base)->loc); + Exp* bin = new_exp_binary(env->gwion->mp, lhs, insert_symbol(env->gwion->st, c), call, exp_self(base)->loc); base->lhs = bin; base->op = insert_symbol(env->gwion->st, "=>"); const Type ret = check_exp(env, exp_self(base)); diff --git a/src/parse/partial.c b/src/parse/partial.c index 89c0f9f9..7967900b 100644 --- a/src/parse/partial.c +++ b/src/parse/partial.c @@ -13,9 +13,9 @@ #include "parse.h" #include "partial.h" -ANN static Arg_List partial_arg_list(const Env env, const Arg_List base, const Exp e) { +ANN static Arg_List partial_arg_list(const Env env, const Arg_List base, Exp* e) { Arg_List args = new_mp_vector(env->gwion->mp, Arg, 0); - Exp next = e; + Exp* next = e; uint32_t i = 0; while(next) { if(is_hole(env, next) || is_typed_hole(env, next)) { @@ -38,35 +38,36 @@ ANN static inline Symbol partial_name(const Env env, const pos_t pos) { return insert_symbol(c); } -ANN2(1, 2) static inline Func_Base *partial_base(const Env env, const Func_Base *base, Exp earg, const loc_t loc) { +ANN2(1, 2) static inline Func_Base *partial_base(const Env env, const Func_Base *base, Exp* earg, const loc_t loc) { Arg_List args = earg ? partial_arg_list(env, base->args, earg) : NULL; Func_Base *fb = new_func_base(env->gwion->mp, base->td ? cpy_type_decl(env->gwion->mp, base->td) : NULL, partial_name(env, loc.first), args, ae_flag_none, loc); return fb; } -ANN static Exp partial_exp(const Env env, Arg_List args, Exp e, const uint i) { +ANN static Exp* partial_exp(const Env env, Arg_List args, Exp* e, const uint i) { if(is_hole(env, e) || is_typed_hole(env, e)) { char c[256]; sprintf(c, "@%u", i); - const Exp exp = new_prim_id(env->gwion->mp, insert_symbol(c), e->loc); + Exp* exp = new_prim_id(env->gwion->mp, insert_symbol(c), e->loc); exp->type = known_type(env, mp_vector_at(args, Arg, i)->var.td); exp->d.prim.value = new_value(env, exp->type, c, e->loc); valid_value(env, insert_symbol(c), exp->d.prim.value); return exp; } - const Exp next = e->next; + Exp* next = e->next; e->next = NULL; - const Exp exp = cpy_exp(env->gwion->mp, e); + Exp* exp = cpy_exp(env->gwion->mp, e); exp->type = e->type; e->next = next; return exp; } -ANN2(1) static Exp partial_call(const Env env, Arg_List args, Exp e) { - Exp base = NULL, arg; +ANN2(1) static Exp* partial_call(const Env env, Arg_List args, Exp* e) { + Exp* base = NULL; + Exp* arg; uint32_t i = 0; while(e) { - const Exp exp = partial_exp(env, args, e, i++); + Exp* exp = partial_exp(env, args, e, i++); if(base) arg = arg->next = exp; else arg = base = exp; e = e->next; @@ -75,10 +76,10 @@ ANN2(1) static Exp partial_call(const Env env, Arg_List args, Exp e) { } -ANN Func find_match(const Env env, Func func, const Exp exp, const bool implicit, +ANN Func find_match(const Env env, Func func, Exp* exp, const bool implicit, const bool specific) { do { - Exp e = exp; + Exp* e = exp; uint32_t i = 0; Arg_List args = func->def->base->args; uint32_t len = mp_vector_len(args); @@ -87,7 +88,7 @@ ANN Func find_match(const Env env, Func func, const Exp exp, const bool implicit const Arg *arg = mp_vector_at(args, Arg, i++); if(!is_hole(env, e)) { if(!is_typed_hole(env, e)) { - const Exp next = e->next; + Exp* next = e->next; e->next = NULL; const Type ret = check_exp(env, e); e->next = next; @@ -103,7 +104,7 @@ ANN Func find_match(const Env env, Func func, const Exp exp, const bool implicit return NULL; } -ANN Func find_match_actual(const Env env, const Func up, const Exp args) { +ANN Func find_match_actual(const Env env, const Func up, Exp* args) { return find_match(env, up, args, false, true) ?: find_match(env, up, args, true, true) ?: find_match(env, up, args, false, true) ?: @@ -111,7 +112,7 @@ ANN Func find_match_actual(const Env env, const Func up, const Exp args) { NULL; } -ANN static Func partial_match(const Env env, const Func up, const Exp args, const loc_t loc); +ANN static Func partial_match(const Env env, const Func up, Exp* args, const loc_t loc); ANN static void print_arg(Arg_List args) { for(uint32_t i = 0; i < args->len; i++) { @@ -132,7 +133,7 @@ ANN void print_signature(const Func f) { gw_err("\n"); } -ANN void ambiguity(const Env env, Func f, const Exp args, const loc_t loc) { +ANN void ambiguity(const Env env, Func f, Exp* args, const loc_t loc) { print_signature(f); while(f->next) { const Func next = partial_match(env, f->next, args, loc); @@ -141,7 +142,7 @@ ANN void ambiguity(const Env env, Func f, const Exp args, const loc_t loc) { } } -ANN static Func partial_match(const Env env, const Func up, const Exp args, const loc_t loc) { +ANN static Func partial_match(const Env env, const Func up, Exp* args, const loc_t loc) { const Func f = find_match_actual(env, up, args); if(f) { const Type t = f->value_ref->from->owner_class; @@ -164,16 +165,16 @@ ANN static Func partial_match(const Env env, const Func up, const Exp args, cons return NULL; } -ANN static Stmt_List partial_code(const Env env, Arg_List args, const Exp efun, const Exp earg) { - const Exp arg = partial_call(env, args, earg); - const Exp exp = new_exp_call(env->gwion->mp, efun, arg, efun->loc); +ANN static Stmt_List partial_code(const Env env, Arg_List args, Exp* efun, Exp* earg) { + Exp* arg = partial_call(env, args, earg); + Exp* exp = new_exp_call(env->gwion->mp, efun, arg, efun->loc); Stmt_List code = new_mp_vector(env->gwion->mp, Stmt, 1); mp_vector_set(code, Stmt, 0, MK_STMT(ae_stmt_return, efun->loc, .stmt_exp = { .val = exp })); return code; } -ANN static uint32_t count_args_exp(Exp args) { +ANN static uint32_t count_args_exp(Exp* args) { uint32_t i = 0; do i++; while ((args = args->next)); @@ -189,11 +190,11 @@ ANN static uint32_t count_args_func(Func f, const uint32_t i) { return max; } -ANN static Exp expand(const Env env, const Func func, const Exp e, const loc_t loc) { +ANN static Exp* expand(const Env env, const Func func, Exp* e, const loc_t loc) { const uint32_t i = count_args_exp(e); const uint32_t max = count_args_func(func, i); if(max > i) { - Exp args = e; + Exp* args = e; if(args) { while(args->next) args = args->next; args->next = new_prim_id(env->gwion->mp, insert_symbol("_"), loc); @@ -208,7 +209,7 @@ ANN Type partial_type(const Env env, Exp_Call *const call) { if(!base) ERR_O(call->func->loc, _("can't do partial application on a literal lambda")); const Func f = partial_match(env, base, call->args, call->func->loc); if(!f) { - const Exp e = expand(env, call->func->type->info->func, call->args, call->func->loc); + Exp* e = expand(env, call->func->type->info->func, call->args, call->func->loc); if(e) { call->args = e; return partial_type(env, call); @@ -218,7 +219,7 @@ ANN Type partial_type(const Env env, Exp_Call *const call) { nspc_push_value(env->gwion->mp, env->curr); Func_Base *const fbase = partial_base(env, f->def->base, call->args, call->func->loc); const Stmt_List code = partial_code(env, f->def->base->args, call->func, call->args); - const Exp exp = exp_self(call); + Exp* exp = exp_self(call); exp->d.exp_lambda.def = new_func_def(env->gwion->mp, fbase, code); exp->exp_type = ae_exp_lambda; const m_bool ret = traverse_func_def(env, exp->d.exp_lambda.def); diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 1618d08e..8128841c 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -213,7 +213,7 @@ static INSTR(StructAssign) { static OP_EMIT(opem_struct_assign) { const Exp_Binary *bin = data; const Type t = bin->lhs->type; - const Exp e = exp_self(bin); + Exp* e = exp_self(bin); if(tflag(t, tflag_release)) { const f_instr exec = !tflag(t, tflag_union) @@ -314,7 +314,7 @@ ANN static inline Type scan0_final(const Env env, Type_Decl *td) { ANN static Type cdef_parent(const Env env, const Class_Def cdef) { if (cflag(cdef, cflag_struct)) return env->gwion->type[et_compound]; if (!cdef->base.ext) return env->gwion->type[et_object]; - Exp e = cdef->base.ext->array ? cdef->base.ext->array->exp : NULL; + Exp* e = cdef->base.ext->array ? cdef->base.ext->array->exp : NULL; while(e) { if(!is_prim_int(e)) ERR_O(e->loc, "non null array type extension must be literal"); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 836fc163..8ae5b0ca 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -96,7 +96,7 @@ static inline m_bool scan1_defined(const Env env, const Var_Decl *var) { } ANN m_bool abstract_array(const Env env, const Array_Sub array) { - Exp e = array->exp; + Exp* e = array->exp; while(e) { if(!exp_is_zero(e)) ERR_B(e->loc, _("arrays of abstract type should use `0` size")); @@ -225,7 +225,7 @@ ANN static m_bool scan1_exp_post(const Env env, const Exp_Postfix *post) { ANN static m_bool scan1_exp_call(const Env env, const Exp_Call *exp_call) { if (exp_call->tmpl) return GW_OK; CHECK_BB(scan1_exp(env, exp_call->func)); - const Exp args = exp_call->args; + Exp* args = exp_call->args; return args ? scan1_exp(env, args) : GW_OK; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 071e9637..01397dfc 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -139,7 +139,7 @@ ANN static inline m_bool scan2_exp_call(const Env env, const Exp_Call *exp_call) { if (exp_call->tmpl) return GW_OK; CHECK_BB(scan2_exp(env, exp_call->func)); - const Exp args = exp_call->args; + Exp* args = exp_call->args; return args ? scan2_exp(env, args) : GW_OK; } diff --git a/src/parse/template.c b/src/parse/template.c index e27f9f57..27375076 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -62,7 +62,7 @@ ANN m_bool template_push(const Env env, const Type t) { } #include -ANN Exp td2exp(const MemPool mp, const Type_Decl *td); +ANN Exp* td2exp(const MemPool mp, const Type_Decl *td); ANN void check_call(const Env env, const Tmpl *tmpl) { for(uint32_t i = 0; i < tmpl->call->len; i++) { Specialized *spec = i < tmpl->list->len @@ -75,7 +75,7 @@ if(targ->type == tmplarg_td) { if(unlikely(spec->td)) { if(targ->type == tmplarg_td) { targ->type = tmplarg_exp; -const Exp exp = td2exp(env->gwion->mp, targ->d.td); +Exp* exp = td2exp(env->gwion->mp, targ->d.td); targ->d.exp = exp; } @@ -187,7 +187,7 @@ ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Speciali const Type t = known_type(env, base); if(t) { arg->type = tmplarg_exp; - Exp e = new_exp_td(env->gwion->mp, base, base->tag.loc); + Exp* e = new_exp_td(env->gwion->mp, base, base->tag.loc); arg->d.exp = new_exp_dot(env->gwion->mp, e, last->tag.sym, base->tag.loc); free_type_decl(env->gwion->mp, last); i--; diff --git a/src/parse/traverse.c b/src/parse/traverse.c index 749a069b..06c69f19 100644 --- a/src/parse/traverse.c +++ b/src/parse/traverse.c @@ -10,7 +10,7 @@ ANN m_bool traverse_ast(const Env env, Ast *const ast) { return check_ast(env, ast); } -ANN m_bool traverse_exp(const Env env, const Exp exp) { +ANN m_bool traverse_exp(const Env env, Exp* exp) { CHECK_BB(scan1_exp(env, exp)); CHECK_BB(scan2_exp(env, exp)); return check_exp(env, exp) ? 1 : -1;