From cd06304cebe1bfbb8580fb31361ed5bbe6b8d0cb Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sat, 12 Dec 2020 12:45:01 +0100 Subject: [PATCH] :art: emit_exp_call1 now boolean --- include/emit.h | 2 +- src/emit/emit.c | 16 ++++++---------- src/parse/operator.c | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/include/emit.h b/include/emit.h index a3204bda..868b5289 100644 --- a/include/emit.h +++ b/include/emit.h @@ -34,7 +34,7 @@ struct Emitter_ { ANEW ANN Emitter new_emitter(MemPool); ANN void free_emitter(MemPool, Emitter); ANN m_bool emit_ast(const Env env, Ast ast); -ANN Instr emit_exp_call1(const Emitter, const Func); +ANN m_bool emit_exp_call1(const Emitter, const Func); 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); diff --git a/src/emit/emit.c b/src/emit/emit.c index a59c34ca..087cd29d 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -846,7 +846,7 @@ ANN static m_bool prepare_call(const Emitter emit, const Exp_Call* exp_call) { ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call* exp_call) { CHECK_BB(prepare_call(emit, exp_call)) if(exp_call->m_func) - CHECK_OB(emit_exp_call1(emit, exp_call->m_func)) + CHECK_BB(emit_exp_call1(emit, exp_call->m_func)) else { struct Op_Import opi = { .op=insert_symbol("@ctor"), .rhs=exp_call->func->info->type->info->base_type, .data=(uintptr_t)exp_call, .pos=exp_self(exp_call)->pos, .op_type=op_exp }; @@ -1093,12 +1093,12 @@ ANN static Instr emit_call(const Emitter emit, const Func f) { return emit_add_instr(emit, Overflow); } -ANN Instr emit_exp_call1(const Emitter emit, const Func f) { +ANN m_bool emit_exp_call1(const Emitter emit, const Func f) { const int tmpl = fflag(f, fflag_tmpl); if(!f->code || (fflag(f, fflag_ftmpl) && !vflag(f->value_ref, vflag_builtin))) { if(tmpl && !is_fptr(emit->gwion, f->value_ref->type)) { if(emit->env->func != f) - CHECK_BO(emit_template_code(emit, f)) + CHECK_BB(emit_template_code(emit, f)) else { // recursive function. (maybe should be used only for global funcs) const Instr back = (Instr) vector_size(&emit->code->instr) ? (Instr)vector_back(&emit->code->instr) : emit_add_instr(emit, RegPushImm); @@ -1112,7 +1112,7 @@ ANN Instr emit_exp_call1(const Emitter emit, const Func f) { back->m_val = (m_uint)f; } else { // ensure env? - CHECK_BO(emit_func_def(emit, f->def)) + CHECK_BB(emit_func_def(emit, f->def)) const Instr instr = emit_add_instr(emit, RegSetImm); instr->m_val = (m_uint)f->code; instr->m_val2 = -SZ_INT; @@ -1157,7 +1157,7 @@ ANN Instr emit_exp_call1(const Emitter emit, const Func f) { const Instr instr = emit_call(emit, f); instr->m_val = f->def->base->ret_type->size; instr->m_val2 = offset; - return instr; + return GW_OK; } ANN static void emit_exp_spork_finish(const Emitter emit, const m_uint depth) { @@ -1200,10 +1200,6 @@ static void push_spork_code(const Emitter emit, const m_str prefix, const loc_t emit_push_code(emit, c); } -ANN static m_bool call_spork_func(const Emitter emit, const Exp_Call *exp) { - return emit_exp_call1(emit, exp->m_func) ? GW_OK : GW_ERROR; -} - struct Sporker { const Stmt code; const Exp exp; @@ -1223,7 +1219,7 @@ ANN static m_bool spork_prepare_code(const Emitter emit, const struct Sporker *s ANN static m_bool spork_prepare_func(const Emitter emit, const struct Sporker *sp) { push_spork_code(emit, sp->is_spork ? SPORK_FUNC_PREFIX : FORK_CODE_PREFIX, sp->exp->pos); - return call_spork_func(emit, &sp->exp->d.exp_call); + return emit_exp_call1(emit, sp->exp->d.exp_call.m_func); } ANN static VM_Code spork_prepare(const Emitter emit, const struct Sporker *sp) { diff --git a/src/parse/operator.c b/src/parse/operator.c index d5181711..56089f33 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -223,12 +223,12 @@ ANN static Instr handle_instr(const Emitter emit, const M_Operator* mo) { if(mo->func) { const Instr push = emit_add_instr(emit, mo->func->code ? RegPushImm : SetFunc); push->m_val = ((m_uint)mo->func->code ?:(m_uint)mo->func); - const Instr instr = emit_exp_call1(emit, mo->func); + CHECK_BO(emit_exp_call1(emit, mo->func)) if(mo->func->def->base->xid == insert_symbol(emit->gwion->st, "@conditionnal")) return emit_add_instr(emit, BranchEqInt); if(mo->func->def->base->xid == insert_symbol(emit->gwion->st, "@unconditionnal")) return emit_add_instr(emit, BranchNeqInt); - return instr; + return push; } return emit_add_instr(emit, mo->instr); } -- 2.43.0