From: Jérémie Astor Date: Thu, 16 Sep 2021 18:42:33 +0000 (+0200) Subject: :art: fast_except improvs X-Git-Tag: nightly~441 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=4ee4e240b3f60e10185e37d17c0305ef4ec6e14c;p=gwion.git :art: fast_except improvs --- diff --git a/include/instr.h b/include/instr.h index 6f268351..141e1e57 100644 --- a/include/instr.h +++ b/include/instr.h @@ -44,6 +44,8 @@ INSTR(DtorReturn); INSTR(ComplexReal); INSTR(ComplexImag); + +INSTR(fast_except); /* function */ INSTR(DtorReturn); diff --git a/src/emit/emit.c b/src/emit/emit.c index 3bd06805..79f48b2a 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -461,7 +461,8 @@ ANN static m_bool emit_symbol_builtin(const Emitter emit, const Symbol *data) { // prevent invalid access to global variables if(!exp_getvar(exp_self(prim_self(data))) && isa(v->type, emit->gwion->type[et_object]) > 0) { - const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); +// const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); + const Instr instr = emit_add_instr(emit, fast_except); instr->m_val = -SZ_INT; // use m_val2 to set some info? } @@ -516,7 +517,8 @@ ANN static m_bool _emit_symbol(const Emitter emit, const Symbol *data) { if (GET_FLAG(v, late) && !exp_getvar(prim_exp(data)) && (isa(v->type, emit->gwion->type[et_object]) > 0 || is_fptr(emit->gwion, v->type))) { - const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); +// const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); + const Instr instr = emit_add_instr(emit, fast_except); instr->m_val = -SZ_INT; } return GW_OK; @@ -643,7 +645,8 @@ ANN m_bool emit_array_access(const Emitter emit, .data = (uintptr_t)info}; if (!info->is_var && (GET_FLAG(info->array.type, abstract) || type_ref(info->array.type))) { - const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); +// const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); + const Instr instr = emit_add_instr(emit, fast_except); instr->m_val = -SZ_INT; } return op_emit(emit, &opi); @@ -1528,7 +1531,7 @@ ANN m_bool emit_exp_call1(const Emitter emit, const Func f, if (vector_size(&emit->code->instr) && vflag(f->value_ref, vflag_member) && is_fptr(emit->gwion, f->value_ref->type)) { const Instr back = (Instr)vector_back(&emit->code->instr); - const bool is_except = back->opcode == eGWOP_EXCEPT; + const bool is_except = back->opcode == eGWOP_EXCEPT || (back->opcode == eOP_MAX && back->execute == fast_except); const Instr base = !is_except ? back : (Instr)vector_at(&emit->code->instr, @@ -1873,7 +1876,8 @@ ANN2(1) /*static */ m_bool emit_exp(const Emitter emit, /* const */ Exp e) { exp_getuse(e) && !exp_getvar(e) && GET_FLAG(e->d.exp_decl.list->self->value, late)) { // e->exp_type == ae_exp_decl && !exp_getvar(e)) { - const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); +// const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); + const Instr instr = emit_add_instr(emit, fast_except); instr->m_val = -SZ_INT; } } while ((exp = exp->next)); diff --git a/src/lib/instr.c b/src/lib/instr.c index f843970f..a6697344 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -144,3 +144,10 @@ INSTR(SetCtor) { VAL = *(m_uint *)(shred->reg + SZ_INT) = (m_uint)t->nspc->pre_ctor; VAL2 = SZ_INT; } + +INSTR(fast_except) { + if(*(m_uint*)REG((m_int)instr->m_val)) { + BYTE(eNoOp) + } else + handle(shred, "NullPtrException"); +} diff --git a/src/lib/object_op.c b/src/lib/object_op.c index f0d39370..0850151e 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -261,7 +261,8 @@ OP_EMIT(opem_object_dot) { if((isa(value->type, emit->gwion->type[et_object]) > 0 || is_fptr(emit->gwion, value->type)) && !exp_getvar(exp_self(member)) && (GET_FLAG(value, static) || GET_FLAG(value, late))) { - const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); +// const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); + const Instr instr = emit_add_instr(emit, fast_except); instr->m_val = -SZ_INT; } return GW_OK; @@ -349,6 +350,9 @@ static OP_EMIT(opem_not_object) { if (back->opcode == eGWOP_EXCEPT) { back->opcode = eIntNot; return GW_OK; + } else if (back->opcode == eOP_MAX && back->execute == fast_except) { + back->opcode = eIntNot; + return GW_OK; } const Instr instr = emit_add_instr(emit, RegSetImm); instr->m_val2 = -SZ_INT; @@ -358,7 +362,7 @@ static OP_EMIT(opem_not_object) { static OP_EMIT(opem_uncond_object) { const Vector v = &emit->code->instr; const Instr back = (Instr)vector_at(v, vector_size(v) -2); - if (back->opcode == eGWOP_EXCEPT) { + if (back->opcode == eGWOP_EXCEPT || (back->opcode == eOP_MAX && back->execute == fast_except)) { free_instr(emit->gwion, back); vector_rem(v, vector_size(v) - 2); } @@ -369,7 +373,7 @@ static OP_EMIT(opem_uncond_object) { static OP_EMIT(opem_cond_object) { const Vector v = &emit->code->instr; const Instr back = (Instr)vector_at(v, vector_size(v) -2); - if (back->opcode == eGWOP_EXCEPT) { + if (back->opcode == eGWOP_EXCEPT || (back->opcode == eOP_MAX && back->execute == fast_except)) { free_instr(emit->gwion, back); vector_rem(v, vector_size(v) - 2); }