From c49b669b2d52f58c98854b531f93333f632c6b20 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sat, 17 Feb 2024 05:28:36 +0100 Subject: [PATCH] :art: more bool --- include/import.h | 2 +- include/import/checker.h | 3 +- include/operator.h | 16 +++--- plug | 2 +- src/emit/emit.c | 106 +++++++++++++++++++-------------------- src/import/import_prim.c | 14 +++--- src/lib/array.c | 34 ++++++------- src/lib/closure.c | 10 ++-- src/lib/deep_equal.c | 2 +- src/lib/dict.c | 38 +++++++------- src/lib/lib_class.c | 2 +- src/lib/lib_gack.c | 4 +- src/lib/modules.c | 2 +- src/lib/object_op.c | 38 +++++++------- src/lib/opfunc.c | 4 +- src/lib/prim.c | 4 +- src/lib/ref.c | 20 ++++---- src/lib/string.c | 4 +- src/lib/union.c | 16 +++--- src/lib/xork.c | 2 +- src/parse/operator.c | 8 +-- 21 files changed, 166 insertions(+), 165 deletions(-) diff --git a/include/import.h b/include/import.h index b3f85b5b..0a6242ff 100644 --- a/include/import.h +++ b/include/import.h @@ -25,7 +25,7 @@ typedef struct Gwi_ *Gwi; void a(const Type t NUSED, m_bit *const VALUE NUSED, \ const VM_Shred shred NUSED) #define OP_CHECK(a) ANN Type a(const Env env NUSED, void *data NUSED) -#define OP_EMIT(a) ANN m_bool a(const Emitter emit NUSED, void *data NUSED) +#define OP_EMIT(a) ANN bool a(const Emitter emit NUSED, void *data NUSED) #ifdef GWION_BUILTIN #define GWI_BB(a) \ { \ diff --git a/include/import/checker.h b/include/import/checker.h index 07913da0..dda8e370 100644 --- a/include/import/checker.h +++ b/include/import/checker.h @@ -33,7 +33,8 @@ typedef struct OperCK { // name_checker ? m_str ret; Symbol sym; Type (*ck)(Env, void *); // oper - m_bool (*em)(Emitter, void *); // oper should be opem + //bool (*em)(Emitter, void *); // oper should be opem + opem em; m_str lhs; // oper m_str rhs; // oper struct Vector_ effect; diff --git a/include/operator.h b/include/operator.h index 916e343c..bb589dac 100644 --- a/include/operator.h +++ b/include/operator.h @@ -44,7 +44,7 @@ } while (0) typedef Type (*opck)(const Env, void *); -typedef m_bool (*opem)(const Emitter, void *); +typedef bool (*opem)(const Emitter, void *); struct Op_Func { opck ck; @@ -76,14 +76,14 @@ struct TemplateScan { const Type_Decl *td; }; -ANN void op_cpy(const Env env, const struct Op_Import *opi); -ANN bool add_op(const Gwion gwion, const struct Op_Import *); +ANN void op_cpy(const Env env, const struct Op_Import *opi); +ANN bool add_op(const Gwion gwion, const struct Op_Import *); ANN void* op_get(const Env env, struct Op_Import *opi); -ANN Type op_check(const Env, struct Op_Import *); -ANN m_bool op_emit(const Emitter, const struct Op_Import *); -ANN bool operator_set_func(const struct Op_Import *); -ANN void free_op_map(Map map, struct Gwion_ *gwion); -ANN void free_op_tmpl(Vector v, struct Gwion_ *gwion); +ANN Type op_check(const Env, struct Op_Import *); +ANN bool op_emit(const Emitter, const struct Op_Import *); +ANN bool operator_set_func(const struct Op_Import *); +ANN void free_op_map(Map map, struct Gwion_ *gwion); +ANN void free_op_tmpl(Vector v, struct Gwion_ *gwion); ANN void operator_suspend(const Nspc, struct Op_Import *); ANN static inline void operator_resume(struct Op_Import *opi) { diff --git a/plug b/plug index 4d02ebd7..3df21f0b 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit 4d02ebd70bed8624438d5ebae1feabccedaa735d +Subproject commit 3df21f0b68d5bf2aa606119f7405f841feea3780 diff --git a/src/emit/emit.c b/src/emit/emit.c index bfc05886..b38b19d6 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -162,7 +162,7 @@ ANN static bool emit_defers(const Emitter emit) { m_uint i; for(i = vector_size(v) + 1; --i;) { Stmt* s = (Stmt*)vector_at(v, i - 1); - if(s) CHECK_b(emit_stmt(emit, s)); + if(s) CHECK_B(emit_stmt(emit, s)); } VLEN(v) = i; return true; @@ -173,7 +173,7 @@ ANN static bool emit_defers2(const Emitter emit) { for (m_uint i = vector_size(v) + 1; --i;) { Stmt* s = (Stmt*)vector_at(v, i - 1); if (!s) break; - CHECK_b(emit_stmt(emit, s)); + CHECK_B(emit_stmt(emit, s)); } return true; } @@ -346,7 +346,7 @@ ANN static bool emit_pre_constructor_array(const Emitter emit, const Instr instr = emit_add_instr(emit, ArrayStruct); instr->m_val = type->size; } - CHECK_b(emit_pre_ctor(emit, type)); + CHECK_B(emit_pre_ctor(emit, type)); if (!tflag(type, tflag_struct)) emit_add_instr(emit, ArrayBottom); else @@ -362,7 +362,7 @@ ANN static bool emit_pre_constructor_array(const Emitter emit, ANN2(1) static bool extend_indices(const Emitter emit, Exp* e, const m_uint depth) { - if (e) CHECK_b(emit_exp(emit, e)); + if (e) CHECK_B(emit_exp(emit, e)); m_uint count = 0; while (e) { ++count; @@ -388,7 +388,7 @@ ANN static inline bool arrayinfo_ctor(const Emitter emit, ArrayInfo *info) { const Type base = info->base; if (tflag(base, tflag_compound) && !GET_FLAG(base, abstract)) { - CHECK_b(emit_pre_constructor_array(emit, base)); + CHECK_B(emit_pre_constructor_array(emit, base)); info->is_obj = 1; } return true; @@ -434,7 +434,7 @@ bool emit_instantiate_object(const Emitter emit, const Type type, const Instr instr = emit_add_instr(emit, ObjectInstantiate); instr->m_val2 = (m_uint)type; } // maybe we should instantiate the first actual type - CHECK_b(emit_pre_ctor(emit, type)); + CHECK_B(emit_pre_ctor(emit, type)); } return true; } @@ -569,7 +569,7 @@ ANN static inline bool emit_exp1(const Emitter emit, Exp* e) { ANN static bool emit_prim_array_exp(const Emitter emit, const Type t, Exp* e) { do { - CHECK_b(emit_exp1(emit, e)); + CHECK_B(emit_exp1(emit, e)); emit_exp_addref1(emit, e, -t->size); emit_regmove(emit, - t->size + t->actual_size); } while((e = e->next)); @@ -580,8 +580,8 @@ ANN static bool emit_prim_array(const Emitter emit, const Array_Sub *data) { Exp* e = (*data)->exp; const Type type = (*data)->type; const Type base = array_base_simple(type); - if(!base->actual_size) CHECK_b(emit_exp(emit, e)); - else CHECK_b(emit_prim_array_exp(emit, base, e)); + if(!base->actual_size) CHECK_B(emit_exp(emit, e)); + else CHECK_B(emit_prim_array_exp(emit, base, e)); m_uint count = 0; do ++count; while ((e = e->next)); @@ -599,17 +599,17 @@ ANN static inline bool emit_exp_pop_next(const Emitter emit, Exp* e); ANN static bool emit_range(const Emitter emit, Range *range) { if (range->start) - CHECK_b(emit_exp_pop_next(emit, range->start)); + CHECK_B(emit_exp_pop_next(emit, range->start)); else emit_pushimm(emit, 0); if (range->end) - CHECK_b(emit_exp_pop_next(emit, range->end)); + CHECK_B(emit_exp_pop_next(emit, range->end)); else emit_pushimm(emit, -1); return true; } ANN static bool emit_prim_range(const Emitter emit, Range **data) { Range *range = *data; - CHECK_b(emit_range(emit, range)); + CHECK_B(emit_range(emit, range)); Exp* e = range->start ?: range->end; const Symbol sym = insert_symbol("[:]"); assert(e); @@ -617,7 +617,7 @@ ANN static bool emit_prim_range(const Emitter emit, Range **data) { .lhs = e->type, .loc = e->loc, .data = (uintptr_t)prim_exp(data)}; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); emit_local_exp(emit, prim_exp(data)); return true; } @@ -636,7 +636,7 @@ ANN static bool emit_prim_dict(const Emitter emit, Exp* *data) { e->next = NULL; 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_b(traverse_exp(emit->env, &call)); + CHECK_B(traverse_exp(emit->env, &call)); e->next = next; m_uint count = 0; do { @@ -660,7 +660,7 @@ ANN static bool emit_prim_dict(const Emitter emit, Exp* *data) { } e->next = next; CHECK_B(emit_exp(emit, &func)); - CHECK_b(emit_exp_call1(emit, func.type->info->func, + CHECK_B(emit_exp_call1(emit, func.type->info->func, func.type->info->func->def->base->ret_type->size, true)); count++; } while((e = e->next->next)); @@ -683,7 +683,7 @@ ANN bool emit_array_access(const Emitter emit, .lhs = info->array.exp->type, .rhs = info->array.type, .data = (uintptr_t)info}; - return op_emit(emit, &opi) > 0; + return op_emit(emit, &opi); } ANN static bool emit_exp_array(const Emitter emit, const Exp_Array *array) { @@ -708,7 +708,7 @@ ANN static bool emit_exp_slice(const Emitter emit, const Exp_Slice *range) { .rhs = range->base->type, .loc = e->loc, .data = (uintptr_t)exp_self(range)}; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); emit_local_exp(emit, exp_self(range)); return true; } @@ -748,7 +748,7 @@ ANN static bool emit_prim_float(const Emitter emit, const m_float *fnum) { ANN static bool emit_prim_char(const Emitter emit, const m_str *str) { char c; - CHECK_b(str2char(emit, *str, &c, prim_pos(str))); + CHECK_B(str2char(emit, *str, &c, prim_pos(str))); emit_pushimm(emit, c); return true; } @@ -834,7 +834,7 @@ ANN static bool emit_prim_interp(const Emitter emit, Exp* *exp) { ANN bool emit_ensure_func(const Emitter emit, const Func f) { const ValueFrom *from = f->value_ref->from; if(from->owner_class) - CHECK_b(ensure_emit(emit, from->owner_class)); + CHECK_B(ensure_emit(emit, from->owner_class)); if(f->code) return true; const m_uint scope = emit_push(emit, from->owner_class, from->owner); const bool ret = emit_func_def(emit, f->def); @@ -846,14 +846,14 @@ ANN static bool emit_prim_locale(const Emitter emit, const Symbol *id) { if(emit->locale->def->d.code) { const Stmt* stmt = mp_vector_at((emit->locale->def->d.code), Stmt, 0); const Func f = stmt->d.stmt_exp.val->d.exp_call.func->type->info->func; - CHECK_b(emit_ensure_func(emit, f)); + CHECK_B(emit_ensure_func(emit, f)); } - CHECK_b(emit_ensure_func(emit, emit->locale)); + CHECK_B(emit_ensure_func(emit, emit->locale)); comptime_ini(emit, "locale"); const M_Object string = new_string(emit->gwion, s_name(*id)); emit_pushimm(emit, (m_uint)string); emit_pushimm(emit, (m_uint)emit->locale->code); - CHECK_b(emit_exp_call1(emit, emit->locale, SZ_FLOAT, true)); + CHECK_B(emit_exp_call1(emit, emit->locale, SZ_FLOAT, true)); m_float ret; comptime_end(emit, SZ_FLOAT, &ret); if(ret == -1.0) @@ -878,7 +878,7 @@ ANN static bool emit_dot_static_data(const Emitter emit, const Value v, ANN static bool _decl_static(const Emitter emit, const Exp_Decl *decl, const Var_Decl *var_decl, const uint is_ref) { const Value v = var_decl->value; - if(!decl->args) CHECK_b(emit_instantiate_decl(emit, v->type, decl->var.td, is_ref)); + if(!decl->args) CHECK_B(emit_instantiate_decl(emit, v->type, decl->var.td, is_ref)); else CHECK_B(emit_exp(emit, decl->args)); CHECK_B(emit_dot_static_data(emit, v, 1)); emit_add_instr(emit, Assign); @@ -1013,7 +1013,7 @@ ANN static bool emit_exp_decl_non_static(const Emitter emit, const bool is_obj = isa(type, emit->gwion->type[et_object]) > 0; const bool emit_addr = (!is_obj || is_ref) ? emit_var : true; if (is_obj && !is_ref && !exp_self(decl)->ref) { - if(!decl->args) CHECK_b(emit_instantiate_decl(emit, type, decl->var.td, is_ref)); + if(!decl->args) CHECK_B(emit_instantiate_decl(emit, type, decl->var.td, is_ref)); else CHECK_B(emit_exp(emit, decl->args)); } f_instr *exec = (f_instr *)allocmember; @@ -1056,7 +1056,7 @@ ANN static bool emit_exp_decl_global(const Emitter emit, const Exp_Decl *decl, const bool is_obj = isa(type, emit->gwion->type[et_object]) > 0; const bool emit_addr = (!is_obj || is_ref) ? emit_var : true; if (is_obj && !is_ref) { - if(!decl->args) CHECK_b(emit_instantiate_decl(emit, type, decl->var.td, is_ref)); + if(!decl->args) CHECK_B(emit_instantiate_decl(emit, type, decl->var.td, is_ref)); else CHECK_B(emit_exp(emit, decl->args)); } if (type->size > SZ_INT) @@ -1106,7 +1106,7 @@ ANN static bool emit_decl(const Emitter emit, Exp_Decl *const decl) { struct Op_Import opi = {.lhs = t->info->base_type, .op = insert_symbol("@implicit"), .rhs = t}; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); } set_late(decl, vd); if (!decl->args && !exp_getvar(exp_self(decl)) && GET_FLAG(array_base_simple(v->type), abstract) && !GET_FLAG(decl->var.td, late) && @@ -1135,7 +1135,7 @@ ANN /*static */ bool emit_exp_decl(const Emitter emit, Exp_Decl *const decl) { const Type t = decl->type; if(decl->args && !strncmp(decl->args->type->name, "partial:", 8)) ERR_B(decl->args->loc, "unresolved partial"); - CHECK_b(ensure_emit(emit, t)); + CHECK_B(ensure_emit(emit, t)); const bool global = GET_FLAG(decl->var.td, global); const m_uint scope = !global ? emit->env->scope->depth : emit_push_global(emit); @@ -1308,7 +1308,7 @@ ANN static bool emit_new_struct(const Emitter emit,const Exp_Call *call) { else emit_regpushmem(emit, offset, t->size, true); if(tflag(t, tflag_ctor)) emit_ext_ctor(emit, t); emit_add_instr(emit, NoOp); - CHECK_b(emit_exp_call1(emit, call->func->type->info->func, t->size, is_static_call(emit->gwion, call->func))); // is a ctor, is_static is true + CHECK_B(emit_exp_call1(emit, call->func->type->info->func, t->size, is_static_call(emit->gwion, call->func))); // is a ctor, is_static is true return true; } @@ -1333,7 +1333,7 @@ ANN static bool _emit_exp_call(const Emitter emit, const Exp_Call *call) { .rhs = t, .data = (uintptr_t)call, .loc = exp_self(call)->loc}; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); } const Func f = t->info->func; if(unlikely(is_new_struct(f, exp_self(call)->type))) @@ -1342,7 +1342,7 @@ ANN static bool _emit_exp_call(const Emitter emit, const Exp_Call *call) { if (f != emit->env->func || (f && f->value_ref->from->owner_class)) CHECK_B(prepare_call(emit, call)); else CHECK_B(emit_func_args(emit, call)); - CHECK_b(emit_exp_call1(emit, f, exp_self(call)->type->size, is_static_call(emit->gwion, call->func))); + CHECK_B(emit_exp_call1(emit, f, exp_self(call)->type->size, is_static_call(emit->gwion, call->func))); } return true; } @@ -1398,7 +1398,7 @@ ANN static bool emit_exp_binary(const Emitter emit, const Exp_Binary *bin) { .rhs = rhs->type, .loc = exp_self(bin)->loc, .data = (uintptr_t)bin}; - return op_emit(emit, &opi) > 0; + return op_emit(emit, &opi); } ANN static bool emit_exp_cast(const Emitter emit, const Exp_Cast *cast) { @@ -1416,12 +1416,12 @@ ANN static bool emit_exp_post(const Emitter emit, const Exp_Postfix *post) { struct Op_Import opi = {.op = post->op, .lhs = post->exp->type, .data = (uintptr_t)post}; // no pos ? - return op_emit(emit, &opi) > 0; + return op_emit(emit, &opi); } ANN static inline bool traverse_emit_func_def(const Emitter emit, const Func_Def fdef) { - if (!fdef->base->ret_type) CHECK_b(traverse_func_def(emit->env, fdef)); + if (!fdef->base->ret_type) CHECK_B(traverse_func_def(emit->env, fdef)); return emit_func_def(emit, fdef); } @@ -1434,7 +1434,7 @@ ANN bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Value .func = (_envset_func)emit_cdef, .scope = scope, .flag = tflag_emit}; - CHECK_b(envset_pushv(&es, v)); + CHECK_B(envset_pushv(&es, v)); (void)emit_push(emit, v->from->owner_class, v->from->owner); const bool ret = traverse_emit_func_def(emit, fdef); emit_pop(emit, scope); @@ -1480,7 +1480,7 @@ ANN static bool emit_template_code(const Emitter emit, const Func f) { .func = (_envset_func)emit_cdef, .scope = scope, .flag = tflag_emit}; - CHECK_b(envset_pushv(&es, v)); + CHECK_B(envset_pushv(&es, v)); (void)emit_push(emit, v->from->owner_class, v->from->owner); const bool ret = emit_func_def(emit, f->def); envset_pop(&es, v->from->owner_class); @@ -1560,7 +1560,7 @@ static bool me_cmp(MemoizeEmitter *me, const Arg *arg) { .rhs = arg->type, .loc = me->fdef->base->tag.loc, .data = (uintptr_t)&bin.d}; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); const Instr instr = emit_add_instr(emit, BranchEqInt); vector_add(&me->branch, (vtype)instr); return true; @@ -1624,14 +1624,14 @@ ANN bool emit_exp_call1(const Emitter emit, const Func f, emit->status = (EmitterStatus){}; if(unlikely(fflag(f, fflag_fptr))) emit_fptr_call(emit, f); else if (unlikely(!f->code && emit->env->func != f)) { - if (fflag(f, fflag_tmpl)) CHECK_b(emit_template_code(emit, f)); + if (fflag(f, fflag_tmpl)) CHECK_B(emit_template_code(emit, f)); else //if(is_new(f->def))//if(tflag(f->value_ref->type, tflag_ftmpl)) { const Type t = f->value_ref->from->owner_class; if(t && (!emit->env->curr || isa(t, emit->env->class_def) < 0)) //!is_new(f->def) || f->value_ref->from->owner_class->array_depth) //if(f->value_ref->from->owner_class->array_depth) -CHECK_b(emit_ensure_func(emit, f)); +CHECK_B(emit_ensure_func(emit, f)); } } else if(is_static) push_func_code(emit, f); @@ -1694,7 +1694,7 @@ ANN static bool spork_prepare_func(const Emitter emit, const Type t = actual_type(emit->gwion, sp->exp->d.exp_call.func->type); const Func f = t->info->func; if(!f->code && f != emit->env->func) - CHECK_b(emit_ensure_func(emit, f)); + CHECK_B(emit_ensure_func(emit, f)); push_spork_code(emit, sp->is_spork ? SPORK_FUNC_PREFIX : FORK_CODE_PREFIX, sp->exp->loc); return emit_exp_call1(emit, f, f->def->base->ret_type->size, false); @@ -1761,7 +1761,7 @@ ANN bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { .type = emit->env->class_def, .exp_type = ae_exp_primary }; - CHECK_b(emit_exp(emit, &exp)); + CHECK_B(emit_exp(emit, &exp)); offset += SZ_INT; } if(sporker.captures) { @@ -1780,7 +1780,7 @@ ANN bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { }; if(cap->is_ref) exp_setvar(&exp, true); offset += exp_size(&exp); - CHECK_b(emit_exp(emit, &exp)); + CHECK_B(emit_exp(emit, &exp)); // emit_exp_addref(emit, &exp, -exp_size(&exp)); } } @@ -1796,7 +1796,7 @@ ANN bool emit_exp_spork(const Emitter emit, const Exp_Unary *unary) { ANN static bool emit_exp_unary(const Emitter emit, const Exp_Unary *unary) { const Type t = exp_self(unary)->type; const Type base = actual_type(emit->gwion, t); - CHECK_b(ensure_emit(emit, base)); + CHECK_B(ensure_emit(emit, base)); // no pos ? struct Op_Import opi = {.op = unary->op, .data = (uintptr_t)unary}; if (unary->unary_type == unary_exp && unary->op != insert_symbol("spork") && @@ -1804,7 +1804,7 @@ ANN static bool emit_exp_unary(const Emitter emit, const Exp_Unary *unary) { CHECK_B(emit_exp_pop_next(emit, unary->exp)); opi.rhs = unary->exp->type; } - return op_emit(emit, &opi) > 0; + return op_emit(emit, &opi); } ANN static bool emit_implicit_cast(const Emitter emit, @@ -1817,7 +1817,7 @@ ANN static bool emit_implicit_cast(const Emitter emit, .data = (m_uint)&imp, .loc = from->loc }; - return op_emit(emit, &opi) > 0; + return op_emit(emit, &opi); } ANN2(1,2) static Instr _flow(const Emitter emit, Exp* e, Instr *const instr, /*const */bool b) { @@ -1837,7 +1837,7 @@ ANN2(1,2) static Instr _flow(const Emitter emit, Exp* e, Instr *const instr, /*c .rhs = e->type, .loc = e->loc, .data = (uintptr_t)e}; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); return (Instr)vector_back(&emit->code->instr); } #define emit_flow(emit, b) _flow(emit, b, NULL, true) @@ -1932,7 +1932,7 @@ ANN static bool emit_exp_lambda(const Emitter emit, .func = (_envset_func)emit_cdef, .scope = emit->env->scope->depth, .flag = tflag_emit}; - CHECK_b(envset_pushv(&es, lambda->def->base->func->value_ref)); + CHECK_B(envset_pushv(&es, lambda->def->base->func->value_ref)); const bool ret = emit_lambda(emit, lambda); envset_pop(&es, lambda->owner); return ret; @@ -2173,7 +2173,7 @@ ANN static Instr each_op(const Emitter emit, const Looper *loop) { .op = insert_symbol("@each"), .data = (m_uint)loop }; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); return loop->instr; } @@ -2269,7 +2269,7 @@ _nspc_add_value(emit->env->curr, stmt->idx->var.tag.sym, stmt->idx->var.value); .op = insert_symbol("@each_init"), .data = (m_uint)&loop }; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); } const m_uint ini_pc = emit_code_size(emit); CHECK_B(looper_run(emit, &loop)); @@ -2439,7 +2439,7 @@ ANN static bool emit_case_head(const Emitter emit, Exp* base, .rhs = e->type, .data = (uintptr_t)&ebin.d.exp_binary, .loc = e->loc}; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); const Instr instr = emit_add_instr(emit, BranchEqInt); vector_add(v, (vtype)instr); return true; @@ -2514,7 +2514,7 @@ ANN static Symbol case_op(const Emitter emit, Exp* base, Exp* e, .rhs = e->type, .data = (uintptr_t)&ebin.d.exp_binary, .loc = e->loc}; - if(op_emit(emit, &opi) < 0) return false; + CHECK_B(op_emit(emit, &opi)); const Instr instr = emit_add_instr(emit, BranchEqInt); vector_add(vec, (vtype)instr); return CASE_PASS; @@ -2639,7 +2639,7 @@ ANN static bool emit_exp_dot(const Emitter emit, const Exp_Dot *member) { .rhs = exp_self(member)->type, .data = (uintptr_t)member, .loc = exp_self(member)->loc}; - return op_emit(emit, &opi) > 0; + return op_emit(emit, &opi); } ANN static inline void emit_func_def_init(const Emitter emit, const Func func) { @@ -2925,7 +2925,7 @@ ANN static inline bool emit_cdef(const Emitter emit, const Type t) { ANN static bool cdef_parent(const Emitter emit, const Class_Def cdef) { const bool tmpl = !!cdef->base.tmpl; - if (tmpl) CHECK_b(template_push_types(emit->env, cdef->base.tmpl)); + if (tmpl) CHECK_B(template_push_types(emit->env, cdef->base.tmpl)); const bool ret = emit_parent(emit, cdef); if (tmpl) nspc_pop_type(emit->gwion->mp, emit->env->curr); return ret; @@ -2966,7 +2966,7 @@ ANN static bool _emit_class_def(const Emitter emit, const Class_Def cdef) { const Class_Def c = t->info->cdef; if (c->base.ext && t->info->parent->info->cdef && !tflag(t->info->parent, tflag_emit)) // ????? - CHECK_b(cdef_parent(emit, c)); + CHECK_B(cdef_parent(emit, c)); if (c->base.tmpl) CHECK_B(emit_class_tmpl(emit, c->base.tmpl, c->base.type->nspc)); if (c->body) return scanx_body(emit->env, c, (_envset_func)emit_section_b, emit); diff --git a/src/import/import_prim.c b/src/import/import_prim.c index 16b3d8bc..e33bac8d 100644 --- a/src/import/import_prim.c +++ b/src/import/import_prim.c @@ -75,7 +75,7 @@ static INSTR(bit_get_fast) { static OP_EMIT(opem_bit_access) { struct ArrayAccessInfo *const info = (struct ArrayAccessInfo *)data; if(!is_prim_int(info->array.exp)) { - CHECK_b(emit_exp(emit, info->array.exp)); + CHECK_B(emit_exp(emit, info->array.exp)); const Instr check = emit_add_instr(emit, bit_check); check->m_val = info->array.type->actual_size * CHAR_BIT; if(!info->is_var) { @@ -95,13 +95,13 @@ static OP_EMIT(opem_bit_access) { instr->m_val = (offset / CHAR_BIT); } } - return GW_OK; + return true; } static OP_EMIT(opem_bit_exp) { bool *var = data; var[1] = var[0]; - return GW_OK; + return true; } static OP_CHECK(opck_bit_access) { @@ -150,7 +150,7 @@ static OP_EMIT(opem_bitset) { ? bin->lhs->type : bin->rhs->type; instr->m_val = t->actual_size; - return GW_OK; + return true; } static INSTR(bitcast) { @@ -165,7 +165,7 @@ static OP_EMIT(opem_bitcast) { const Instr instr = emit_add_instr(emit, bitcast); instr->m_val = -SZ_INT + t->actual_size; instr->m_val2 = SZ_INT - t->actual_size; - return GW_OK; + return true; } ANN2(1,2,3,5) static void prim_op(const Env env, const Type t, const m_str op, const opck ck, const opem em){ @@ -213,8 +213,8 @@ ANN Type mk_primitive(const Env env, const m_str name, const m_uint size) { prim_op(env, t, "$", opck_prim_cast, opem_bitcast); prim_implicit(env, t); } else if(size == SZ_INT) { - prim_op(env, t, ":=>", opck_rassign, (opem)dummy_func); - prim_op(env, t, "$", NULL, (opem)dummy_func); + prim_op(env, t, ":=>", opck_rassign, (opem)bdummy_func); + prim_op(env, t, "$", NULL, (opem)bdummy_func); prim_implicit(env, t); } // else provide function to get slices CHECK_O(mk_gack(env->gwion->mp, t, gack_prim)); diff --git a/src/lib/array.c b/src/lib/array.c index c1126e9f..df17b9cb 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -233,23 +233,23 @@ static INSTR(ArrayConcatRight) { static OP_EMIT(opem_array_sr) { const Exp_Binary *bin = (Exp_Binary *)data; if (shift_match(bin->lhs->type, bin->rhs->type)) - return emit_array_shift(emit, ArrayConcatRight) ? GW_OK : GW_ERROR; + return emit_array_shift(emit, ArrayConcatRight); emit_regmove(emit, -SZ_INT); if (tflag(bin->lhs->type, tflag_compound)) emit_compound_addref(emit, bin->lhs->type, -SZ_INT - bin->lhs->type->size, false); (void)emit_add_instr(emit, ArrayAppendFront); - return GW_OK; + return true; } static OP_EMIT(opem_array_sl) { const Exp_Binary *bin = (Exp_Binary *)data; if (shift_match(bin->rhs->type, bin->lhs->type)) - return emit_array_shift(emit, ArrayConcatLeft) ? GW_OK : GW_ERROR; + return emit_array_shift(emit, ArrayConcatLeft); if (tflag(bin->rhs->type, tflag_compound)) emit_compound_addref(emit, bin->rhs->type, -bin->rhs->type->size, false); emit_regmove(emit, -bin->rhs->type->size); emit_add_instr(emit, ArrayAppend); - return GW_OK; + return true; } // check me. use common ancestor maybe @@ -320,7 +320,7 @@ static OP_EMIT(opem_array_cast) { const m_uint ret_offset = emit_local(emit, t); emit_regtomem(emit, ret_offset, -SZ_INT); } - return GW_OK; + return true; } static OP_CHECK(opck_array_slice) { @@ -358,7 +358,7 @@ static INSTR(ArraySlice) { static OP_EMIT(opem_array_slice) { emit_add_instr(emit, ArraySlice); - return GW_OK; + return true; } static FREEARG(freearg_array) { @@ -390,9 +390,9 @@ static OP_CHECK(opck_array) { return check_array_access(env, &next) ?: env->gwion->type[et_error]; } -ANN static inline m_bool array_do(const Emitter emit, const Array_Sub array, +ANN static inline bool array_do(const Emitter emit, const Array_Sub array, const bool is_var) { - CHECK_b(emit_exp(emit, array->exp)); + CHECK_B(emit_exp(emit, array->exp)); const m_uint depth = array->depth; const m_uint offset = is_var ? SZ_INT : array->type->size; emit_regmove(emit, -(depth+1) * SZ_INT + offset); @@ -410,7 +410,7 @@ ANN static inline m_bool array_do(const Emitter emit, const Array_Sub array, } assert(access); access->udata.two = is_var; - return GW_OK; + return true; } ANN bool get_emit_var(const Emitter emit, const Type t, bool is_var) { @@ -419,7 +419,7 @@ ANN bool get_emit_var(const Emitter emit, const Type t, bool is_var) { struct Op_Import opi = {.op = insert_symbol("@array_init"), .lhs = t, .data = (uintptr_t)vars}; - if(op_emit(emit, &opi) != GW_OK) + if(!op_emit(emit, &opi)) return false; return vars[1]; } @@ -432,9 +432,9 @@ ANN static inline Exp* emit_n_exp(const Emitter emit, struct Array_Sub_ partial = {info->array.exp, info->array.type, info->array.depth}; const bool is_var = get_emit_var(emit, array_base(info->array.type), info->is_var); - const m_bool ret = array_do(emit, &partial, is_var); - e->next = next; - return ret > 0 ? next : NULL; + const bool ret = array_do(emit, &partial, is_var); + e->next = next; + return ret ? next : NULL; } ANN static Type emit_get_array_type(const Emitter emit, const Type t) { @@ -463,8 +463,8 @@ static OP_EMIT(opem_array_access) { next.exp = exp; info->array = next; if(exp) - return emit_array_access(emit, info) ? GW_OK : GW_ERROR; - return GW_ERROR; + return emit_array_access(emit, info); + return false; } static m_bit map_byte[BYTECODE_SZ * 5]; @@ -882,7 +882,7 @@ static OP_EMIT(opem_array_each_init) { Looper *loop = (Looper *)data; const Instr instr = emit_add_instr(emit, AutoUnrollInit); instr->m_val = loop->offset; - return GW_OK; + return true; } @@ -918,7 +918,7 @@ static OP_EMIT(opem_array_each) { instr->m_val2 = loop->offset + SZ_INT*2; vector_add(&loop->unroll_v, (m_uint)instr); } - return GW_OK; + return true; } ANN static void prepare_run(m_bit *const byte, const f_instr ini, diff --git a/src/lib/closure.c b/src/lib/closure.c index 4b7e81c0..7b023f77 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -118,7 +118,7 @@ static INSTR(fptr_assign) { *(M_Object*)REG(-SZ_INT) = o; } -ANN static m_bool emit_fptr_assign(const Emitter emit, const Type lhs, const Type rhs) { +ANN static bool emit_fptr_assign(const Emitter emit, const Type lhs, const Type rhs) { const Instr instr = emit_add_instr(emit, fptr_assign); if(rhs->info->cdef && get_tmpl(rhs)) instr->m_val = SZ_INT * 2; @@ -134,7 +134,7 @@ ANN static m_bool emit_fptr_assign(const Emitter emit, const Type lhs, const Typ e->d.prim.value = cap->var.value; e->type = cap->var.value->type; exp_setvar(e, cap->is_ref); - CHECK_b(emit_exp(emit, e)); + CHECK_B(emit_exp(emit, e)); if(!cap->is_ref && tflag(cap->temp->type, tflag_compound)) emit_compound_addref(emit, cap->temp->type, cap->temp->type->size, 0); offset += cap->temp->type->size; @@ -145,7 +145,7 @@ ANN static m_bool emit_fptr_assign(const Emitter emit, const Type lhs, const Typ instr->m_val2 = (m_uint)fdef; } } - return GW_OK; + return true; } static OP_EMIT(opem_fptr_assign) { @@ -530,7 +530,7 @@ static inline void op_impl_ensure_types(const Env env, const Func func) { static OP_EMIT(opem_op_impl) { struct Implicit *impl = (struct Implicit *)data; if(!impl->e->type->info->func->code) - CHECK_b(emit_ensure_func(emit, impl->e->type->info->func)); + CHECK_B(emit_ensure_func(emit, impl->e->type->info->func)); emit_pushimm(emit, (m_uint)impl->e->type->info->func->code); return emit_fptr_assign(emit, impl->e->type, impl->t); } @@ -704,7 +704,7 @@ static CTOR(fptr_ctor) { ANN bool tmpl_fptr(const Env env, const Fptr_Def fptr, const Func_Def fdef) { fptr->cdef->base.type->nspc->offset += SZ_INT * 3; env_push_type(env, fptr->cdef->base.type); - CHECK_b(traverse_func_def(env, fdef)); + CHECK_B(traverse_func_def(env, fdef)); builtin_func(env->gwion, fdef->base->func, fptr_ctor); set_tflag(fdef->base->func->value_ref->type, tflag_ftmpl); env_pop(env, 0); diff --git a/src/lib/deep_equal.c b/src/lib/deep_equal.c index 04c98396..f783dbb1 100644 --- a/src/lib/deep_equal.c +++ b/src/lib/deep_equal.c @@ -230,7 +230,7 @@ static OP_EMIT(opem_deep_equal) { const bool ret = deep_emit(emit, &ds); deep_emits_release(emit, &ds); emit_pop_scope(emit); - return ret ? GW_OK: GW_ERROR; + return ret; } GWION_IMPORT(deep_equal) { diff --git a/src/lib/dict.c b/src/lib/dict.c index f1bfc57f..daaf8b8e 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -301,14 +301,14 @@ static OP_CHECK(opck_dict_remove_toop) { return e->type = env->gwion->type[et_void]; } -ANN static m_bool emit_dict_iter(const Emitter emit, const HMapInfo *hinfo, +ANN static bool emit_dict_iter(const Emitter emit, const HMapInfo *hinfo, const struct Op_Import *opi, Exp* call, Exp* exp) { emit_pushimm(emit, -1); // room for tombstone - CHECK_b(emit_exp(emit, call)); + CHECK_B(emit_exp(emit, call)); const m_uint pc = emit_code_size(emit); const Instr iter = emit_add_instr(emit, hmap_iter); iter->m_val = hinfo->key->size + SZ_INT; - CHECK_b(emit_exp(emit, exp)); + CHECK_B(emit_exp(emit, exp)); op_emit(emit, opi); const Instr ok = emit_add_instr(emit, BranchNeqInt); emit_add_instr(emit, hmap_iter_inc); @@ -316,7 +316,7 @@ ANN static m_bool emit_dict_iter(const Emitter emit, const HMapInfo *hinfo, top->m_val = pc; ok->m_val = emit_code_size(emit); emit_regmove(emit, -SZ_INT); - return GW_OK; + return true; } static OP_EMIT(_opem_dict_access) { @@ -358,16 +358,16 @@ if(info->is_var) { const m_uint grow_pc = emit_code_size(emit); emit_add_instr(emit, hmap_grow_dec); const Instr endgrow = emit_add_instr(emit, BranchNeqInt); - CHECK_b(emit_exp(emit, call.d.exp_call.func)); - CHECK_b(emit_exp_call1(emit, call.d.exp_call.func->type->info->func, + CHECK_B(emit_exp(emit, call.d.exp_call.func)); + CHECK_B(emit_exp_call1(emit, call.d.exp_call.func->type->info->func, call.d.exp_call.func->type->info->func->def->base->ret_type->size, true)); emit_add_instr(emit, hmap_find); const Instr regrow = emit_add_instr(emit, BranchEqInt); regrow->m_val = grow_pc; nogrow->m_val = emit_code_size(emit); endgrow->m_val = emit_code_size(emit); - CHECK_b(emit_exp(emit, &call)); - CHECK_b(emit_exp(emit, array->exp)); + CHECK_B(emit_exp(emit, &call)); + CHECK_B(emit_exp(emit, array->exp)); const m_uint top_pc = emit_code_size(emit); const Instr idx = emit_add_instr(emit, hmap_iter_set_ini); idx->m_val = key->size; @@ -376,7 +376,7 @@ if(info->is_var) { const Instr iter = emit_add_instr(emit, hmap_iter_set); iter->m_val = key->size; const Instr fast = emit_add_instr(emit, BranchNeqInt); - CHECK_b(emit_exp(emit, array->exp)); + CHECK_B(emit_exp(emit, array->exp)); op_emit(emit, &opi); const Instr ok = emit_add_instr(emit, BranchNeqInt); @@ -389,12 +389,12 @@ if(info->is_var) { const Instr iseq = emit_add_instr(emit, hmap_addr); iseq->m_val = key->size; fast->m_val = emit_code_size(emit); - return GW_OK; + return true; } - CHECK_BB(emit_dict_iter(emit, hinfo, &opi, &call, array->exp)); + CHECK_B(emit_dict_iter(emit, hinfo, &opi, &call, array->exp)); const Instr pushval = emit_add_instr(emit, hmap_val); pushval->m_val2 = key->size; - return GW_OK; + return true; } static OP_EMIT(opem_dict_remove) { @@ -425,10 +425,10 @@ static OP_EMIT(opem_dict_remove) { }; CHECK_B(traverse_exp(env, &call)); - CHECK_BB(emit_dict_iter(emit, hinfo, &opi, &call, bin->lhs)); + CHECK_B(emit_dict_iter(emit, hinfo, &opi, &call, bin->lhs)); const Instr pushval = emit_add_instr(emit, hmap_remove); pushval->m_val2 = hinfo->key->size; - return GW_OK; + return true; } ANN static bool emit_next_access(const Emitter emit, struct ArrayAccessInfo *const info) { @@ -447,10 +447,10 @@ static OP_EMIT(opem_dict_access) { const Array_Sub array = &info->array; Exp* enext = array->exp->next; array->exp->next = NULL; - const m_bool ret = _opem_dict_access(emit, data); + const bool ret = _opem_dict_access(emit, data); array->exp->next = enext; - CHECK_BB(ret); - return !enext ? GW_OK : (emit_next_access(emit, info) ? GW_OK : GW_ERROR); + CHECK_B(ret); + return !enext ? GW_OK : emit_next_access(emit, info); } static OP_CHECK(opck_dict_access) { @@ -526,7 +526,7 @@ static OP_EMIT(opem_dict_each) { if(!loop->n) loop->instr = go; else vector_add(&loop->unroll_v, (m_uint)go); loop->init = true; - return GW_OK; + return true; } static INSTR(DictEachInit) { @@ -538,7 +538,7 @@ static OP_EMIT(opem_dict_each_init) { const Looper *loop = (Looper *)data; const Instr instr = emit_add_instr(emit, DictEachInit); instr->m_val = loop->offset; - return GW_OK; + return true; } static OP_CHECK(opck_dict_each_key) { diff --git a/src/lib/lib_class.c b/src/lib/lib_class.c index a9ea29a6..9f8273c0 100644 --- a/src/lib/lib_class.c +++ b/src/lib/lib_class.c @@ -42,7 +42,7 @@ static OP_EMIT(opem_implicit_class) { struct Implicit *imp = (struct Implicit*)data; const Type t = actual_type(emit->gwion, imp->e->type); emit_pushimm(emit, map_size(&t->nspc->info->value->map)); - return GW_OK; + return true; } static OP_CHECK(opck_implicit_class) { diff --git a/src/lib/lib_gack.c b/src/lib/lib_gack.c index e736d484..002de79b 100644 --- a/src/lib/lib_gack.c +++ b/src/lib/lib_gack.c @@ -30,12 +30,12 @@ static OP_EMIT(opem_gack_implicit) { struct Op_Import opi = {.lhs = t, .op = insert_symbol(emit->gwion->st, "@implicit"), .rhs = imp->t}; - CHECK_BB(op_emit(emit, &opi)); + CHECK_B(op_emit(emit, &opi)); emit_regmove(emit, -SZ_INT); const Instr cpy = emit_add_instr(emit, Reg2RegOther); // kind cpy->m_val = cpy->m_val2 = imp->t->size; } - return GW_OK; + return true; } GWION_IMPORT(gack) { diff --git a/src/lib/modules.c b/src/lib/modules.c index 2297adf4..4d22542f 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -269,7 +269,7 @@ static OP_EMIT(opem_usrugen) { Exp_Binary *bin = (Exp_Binary *)data; const Instr instr = emit_add_instr(emit, UsrUGenTick); instr->m_val = !!bin->lhs->type->info->func->value_ref->from->owner_class; - return GW_OK; + return true; } static GWION_IMPORT(usrugen) { diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 7a423eb1..aa8dd1e7 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -72,7 +72,7 @@ static OP_EMIT(opem_object_at) { (void)emit_add_instr(emit, ObjectAssign); else (void)emit_add_instr(emit, Assign); - return GW_OK; + return true; } static OP_CHECK(opck_object_cast) { @@ -199,9 +199,9 @@ ANN static m_bool member_access(const Env env, Exp* exp, const Value value) { OP_CHECK(opck_object_dot) { Exp_Dot *const member = (Exp_Dot *)data; 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 = + const m_str str = s_name(member->xid); + const bool base_static = is_class(env->gwion, member->base->type); + const Type the_base = base_static ? _class_base(member->base->type) : member->base->type; const Value value = get_value(env, member, the_base); if (!value) { @@ -239,17 +239,17 @@ OP_EMIT(opem_object_dot) { const Value value = find_value(t_base, member->xid); if (is_class(emit->gwion, value->type)) { emit_pushimm(emit, (m_uint)value->type); - return GW_OK; + return true; } if (tflag(t_base, tflag_struct) && !GET_FLAG(value, static)) { exp_setvar(member->base, true); - CHECK_b(emit_exp(emit, member->base)); + CHECK_B(emit_exp(emit, member->base)); } if (!is_class(emit->gwion, member->base->type) && (vflag(value, vflag_member) || (is_func(emit->gwion, exp_self(member)->type)))) { if (!tflag(t_base, tflag_struct)) - CHECK_b(emit_exp(emit, member->base)); + CHECK_B(emit_exp(emit, member->base)); } if (is_func(emit->gwion, exp_self(member)->type) && !fflag(exp_self(member)->type->info->func, fflag_fptr)) @@ -267,10 +267,10 @@ OP_EMIT(opem_object_dot) { !exp_getvar(exp_self(member)) && (GET_FLAG(value, static) || GET_FLAG(value, late))) emit_fast_except(emit, value->from, exp_self(member)->loc); - return GW_OK; + return true; } -ANN static m_bool scantmpl_class_def(const Env env, struct tmpl_info *info) { +ANN static bool scantmpl_class_def(const Env env, struct tmpl_info *info) { const Class_Def c = info->base->info->cdef; const Class_Def cdef = new_class_def( env->gwion->mp, c->flag, MK_TAG(info->name,c->base.tag.loc), @@ -285,10 +285,10 @@ ANN static m_bool scantmpl_class_def(const Env env, struct tmpl_info *info) { set_tflag(info->ret, tflag_cdef); } else free_class_def(env->gwion->mp, cdef); - return ret ? GW_OK : GW_ERROR; + return ret; } -ANN static m_bool scantmpl_union_def(const Env env, struct tmpl_info *info) { +ANN static bool scantmpl_union_def(const Env env, struct tmpl_info *info) { const Union_Def u = info->base->info->udef; const Union_Def udef = new_union_def( env->gwion->mp, cpy_variable_list(env->gwion->mp, u->l), u->tag.loc); @@ -303,14 +303,14 @@ ANN static m_bool scantmpl_union_def(const Env env, struct tmpl_info *info) { set_tflag(info->ret, tflag_udef); } else free_union_def(env->gwion->mp, udef); - return ret ? GW_OK : GW_ERROR; + return ret; } ANN static Type _scan_class(const Env env, struct tmpl_info *info) { if (info->base->info->parent != env->gwion->type[et_union]) - CHECK_BO(scantmpl_class_def(env, info)); + CHECK_O(scantmpl_class_def(env, info)); else - CHECK_BO(scantmpl_union_def(env, info)); + CHECK_O(scantmpl_union_def(env, info)); return info->ret; } @@ -339,14 +339,14 @@ static OP_EMIT(opem_not_object) { const Instr back = (Instr)vector_back(v); if (back->opcode == eGWOP_EXCEPT) { back->opcode = eIntNot; - return GW_OK; + return true; } else if (back->opcode == eOP_MAX && back->execute == fast_except) { back->opcode = eIntNot; - return GW_OK; + return true; } const Instr instr = emit_add_instr(emit, RegSetImm); instr->m_val2 = -SZ_INT; - return GW_OK; + return true; } static OP_EMIT(opem_uncond_object) { @@ -359,7 +359,7 @@ static OP_EMIT(opem_uncond_object) { } } emit_add_instr(emit, BranchNeqInt); - return GW_OK; + return true; } static OP_EMIT(opem_cond_object) { @@ -372,7 +372,7 @@ static OP_EMIT(opem_cond_object) { } } emit_add_instr(emit, BranchEqInt); - return GW_OK; + return true; } GWION_IMPORT(object_op) { diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 1c4fbbf7..f9dc3855 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -160,9 +160,9 @@ OP_CHECK(opck_new) { OP_EMIT(opem_new) { const Exp_Unary *unary = (Exp_Unary *)data; if(!tflag(exp_self(unary)->type, tflag_struct)) - CHECK_b(emit_instantiate_object(emit, exp_self(unary)->type, + CHECK_B(emit_instantiate_object(emit, exp_self(unary)->type, unary->ctor.td->array, 0)); if(!unary->ctor.exp) emit_local_exp(emit, exp_self(unary)); - return GW_OK; + return true; } diff --git a/src/lib/prim.c b/src/lib/prim.c index 4fce48bb..1439d139 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -103,7 +103,7 @@ static OP_EMIT(opem_##type##_##name) { \ instr->opcode = e##type##_##name##_imm; \ instr->val = bin->rhs->d.prim.d.member; \ } \ - return GW_OK; \ + return true; \ } #define BINARY_INT_EMIT(name) BINARY_OP_EMIT(name, int, gwint.num, m_val) @@ -202,7 +202,7 @@ static OP_EMIT(opem_int_range) { Exp* exp = (Exp*)data; const Instr instr = emit_add_instr(emit, IntRange); instr->m_val = (m_uint)exp->type; - return GW_OK; + return true; } #define UNARY_FOLD(ntype, name, TYPE, OP, func, ctype, exptype, member) \ diff --git a/src/lib/ref.c b/src/lib/ref.c index e82359dc..fa677ae1 100644 --- a/src/lib/ref.c +++ b/src/lib/ref.c @@ -24,16 +24,16 @@ 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, Exp* e) { +static bool ref_access(const Env env, Exp* e) { const m_str access = exp_access(e); - if (!access) return GW_OK; + if (!access) return true; env_err(env, e->loc, _("operand is %s"), access); - return GW_ERROR; + return false; } static OP_CHECK(opck_ref_implicit_similar) { const struct Implicit *imp = (struct Implicit *)data; - CHECK_BN(ref_access(env, imp->e)); + CHECK_ON(ref_access(env, imp->e)); exp_setvar(imp->e, 1); return imp->t; } @@ -54,16 +54,16 @@ static OP_EMIT(opem_ref_implicit_similar) { .lhs = base, .rhs = imp->t, .data = (m_uint)imp}; - CHECK_BB(op_emit(emit, &opi)); + CHECK_B(op_emit(emit, &opi)); emit_regmove(emit, -imp->e->type->size); exp_setvar(imp->e, true); imp->e->cast_to = NULL; - return emit_exp(emit, imp->e) > 0 ? GW_OK : GW_ERROR; + return emit_exp(emit, imp->e); } static OP_CHECK(opck_implicit_ref) { const struct Implicit *imp = (struct Implicit *)data; - CHECK_BN(ref_access(env, imp->e)); + CHECK_ON(ref_access(env, imp->e)); exp_setvar(imp->e, 1); imp->e->cast_to = imp->t; return imp->t; @@ -71,7 +71,7 @@ static OP_CHECK(opck_implicit_ref) { static OP_CHECK(opck_ref_contract_similar) { const struct Implicit *imp = (struct Implicit *)data; - CHECK_BN(ref_access(env, imp->e)); + CHECK_ON(ref_access(env, imp->e)); const Type base = (Type)vector_front(&imp->t->info->tuple->contains); struct Op_Import opi = {.op = insert_symbol("@implicit"), .lhs = imp->e->type, @@ -89,11 +89,11 @@ static OP_EMIT(opem_ref_contract_similar) { .lhs = imp->e->type, .rhs = base, .data = (m_uint)&cast}; - CHECK_BB(op_emit(emit, &opi)); + CHECK_B(op_emit(emit, &opi)); emit_regmove(emit, -imp->e->type->size); exp_setvar(imp->e, true); imp->e->cast_to = NULL; - return emit_exp(emit, imp->e) > 0 ? GW_OK : GW_ERROR; + return emit_exp(emit, imp->e); } ANN static void base2ref(Env env, const Type lhs, const Type rhs) { diff --git a/src/lib/string.c b/src/lib/string.c index bbdceacd..e7548b45 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -467,10 +467,10 @@ static OP_EMIT(opem_string_access) { struct ArrayAccessInfo *info = (struct ArrayAccessInfo*)data; Exp* exp = info->array.exp; Exp* next = exp->next; - CHECK_b(emit_exp(emit, exp)); + CHECK_B(emit_exp(emit, exp)); exp->next = next; emit_add_instr(emit, !info->is_var ? string_at : string_at_set); - return GW_OK; + return true; } GWION_IMPORT(string) { diff --git a/src/lib/union.c b/src/lib/union.c index 6356c609..6ad35d7e 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -24,7 +24,7 @@ static OP_CHECK(opck_none) { static OP_EMIT(opem_none) { emit_regmove(emit, -SZ_INT); - return GW_OK; + return true; } static INSTR(UnionIndex) { @@ -35,25 +35,25 @@ static OP_EMIT(opem_union_dot) { const Exp_Dot *member = (Exp_Dot *)data; const Map map = &member->base->type->nspc->info->value->map; exp_setvar(member->base, true); - CHECK_b(emit_exp(emit, member->base)); + CHECK_B(emit_exp(emit, member->base)); if (is_func(emit->gwion, exp_self(member)->type)) { // is_callable? can only be a func emit_pushimm(emit, (m_uint)exp_self(member)->type->info->func->code); - return GW_OK; + return true; } if (!strcmp(s_name(member->xid), "index")) { //emit_add_instr(emit, DotMember); emit_add_instr(emit, UnionIndex); - return GW_OK; + return true; } for (m_uint i = 0; i < map_size(map); ++i) { if (VKEY(map, i) == (m_uint)member->xid) { const Value v = (Value)VVAL(map, i); const uint emit_addr = exp_getvar(exp_self(member)); emit_unionmember(emit, i, v->type->size, emit_addr); - return GW_OK; + return true; } } - return GW_ERROR; + return false; } ANN void union_release(const VM_Shred shred, const Type t, const m_bit *data) { @@ -192,10 +192,10 @@ ANN GWION_IMPORT(union) { GWI_BB(gwi_class_end(gwi)) const struct Op_Func opfunc0 = {.ck = opck_union_is}; - CHECK_b(add_op_func_check(gwi->gwion->env, t_union, &opfunc0, 0)); + CHECK_B(add_op_func_check(gwi->gwion->env, t_union, &opfunc0, 0)); const struct Op_Func opfunc1 = {.ck = opck_union_new}; - CHECK_b(add_op_func_check(gwi->gwion->env, t_union, &opfunc1, 1)); + CHECK_B(add_op_func_check(gwi->gwion->env, t_union, &opfunc1, 1)); GWI_BB(gwi_oper_ini(gwi, "union", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_emi(gwi, opem_union_dot)) diff --git a/src/lib/xork.c b/src/lib/xork.c index 69f83316..5eaeb39a 100644 --- a/src/lib/xork.c +++ b/src/lib/xork.c @@ -80,7 +80,7 @@ static OP_CHECK(opck_spork) { static OP_EMIT(opem_spork) { const Exp_Unary *unary = (Exp_Unary *)data; - return emit_exp_spork(emit, unary) ? GW_OK : GW_ERROR; + return emit_exp_spork(emit, unary); } static FREEARG(freearg_xork) { vmcode_remref((VM_Code)instr->m_val, gwion); } diff --git a/src/parse/operator.c b/src/parse/operator.c index 132fa894..b145b114 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -392,7 +392,7 @@ ANN static bool handle_instr(const Emitter emit, const M_Operator *mo) { return true; } -ANN m_bool op_emit(const Emitter emit, const struct Op_Import *opi) { +ANN bool op_emit(const Emitter emit, const struct Op_Import *opi) { for (int i = 0; i < 2; ++i) { Nspc nspc = emit->env->curr; do { @@ -409,16 +409,16 @@ ANN m_bool op_emit(const Emitter emit, const struct Op_Import *opi) { !i ? operator_find2(v, l, r) : operator_find(v, l, r); if (mo) { if (mo->em) { - const m_bool ret = mo->em(emit, (void *)opi->data); + const bool ret = mo->em(emit, (void *)opi->data); if (ret) return ret; } else if (mo->func || mo->instr) - return handle_instr(emit, mo) ? GW_OK : GW_ERROR; + return handle_instr(emit, mo); } } while (r && (r = op_parent(emit->env, r))); } while (l && (l = op_parent(emit->env, l))); } while ((nspc = nspc->parent)); } - return GW_ERROR; + return false; } #define CONVERT(t) t != from ? t : to -- 2.43.0