Mercurial > hg > Members > anatofuz > MoarVM
changeset 18:be886c9ae3f1
fix tail call eliminate
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 24 Oct 2018 20:14:36 +0900 |
parents | f4636c3adb79 |
children | 073d6fd557dc |
files | src/core/cbc-interp.cbc |
diffstat | 1 files changed, 31 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/core/cbc-interp.cbc Sat Oct 20 09:57:43 2018 +0900 +++ b/src/core/cbc-interp.cbc Wed Oct 24 20:14:36 2018 +0900 @@ -468,17 +468,20 @@ goto NEXT(i); } __code cbc_return_o(INTERP i){ - MVMObject *value = GET_REG(i->cur_op, 0,i).o; + static MVMObject *value; + value = GET_REG(i->cur_op, 0,i).o; if (MVM_spesh_log_is_logging(i->tc)) { - MVMROOT(i->tc, value, { - MVM_spesh_log_return_type(i->tc, value); - }); + do { + MVM_gc_root_temp_push(i->tc, (MVMCollectable **)&(value)); // This is invoke call elimination + MVM_spesh_log_return_type(i->tc, value); + MVM_gc_root_temp_pop(i->tc); + } while (0); } MVM_args_set_result_obj(i->tc, value, MVM_RETURN_CALLER_FRAME); if (MVM_frame_try_return(i->tc) == 0) goto return_label(i); goto NEXT(i); - } +} __code cbc_return(INTERP i){ if (MVM_spesh_log_is_logging(i->tc)) MVM_spesh_log_return_type(i->tc, NULL); @@ -967,9 +970,8 @@ i->tc->cur_frame->return_type = MVM_RETURN_VOID; i->cur_op += 2; i->tc->cur_frame->return_address = i->cur_op; - STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); + goto STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); } - goto NEXT(i); } __code cbc_invoke_i(INTERP i){ { @@ -987,9 +989,8 @@ i->tc->cur_frame->return_type = MVM_RETURN_INT; i->cur_op += 4; i->tc->cur_frame->return_address = i->cur_op; - STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); + goto STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); } - goto NEXT(i); } __code cbc_invoke_n(INTERP i){ { @@ -1007,12 +1008,10 @@ i->tc->cur_frame->return_type = MVM_RETURN_NUM; i->cur_op += 4; i->tc->cur_frame->return_address = i->cur_op; - STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); + goto STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); } - goto NEXT(i); } __code cbc_invoke_s(INTERP i){ - { MVMObject *code = GET_REG(i->cur_op, 2,i).o; MVMRegister *args = i->tc->cur_frame->args; MVMuint16 was_multi = 0; @@ -1027,8 +1026,7 @@ i->tc->cur_frame->return_type = MVM_RETURN_STR; i->cur_op += 4; i->tc->cur_frame->return_address = i->cur_op; - STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); - } + goto STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); goto NEXT(i); } __code cbc_invoke_o(INTERP i){ @@ -1046,7 +1044,7 @@ i->tc->cur_frame->return_type = MVM_RETURN_OBJ; i->cur_op += 4; i->tc->cur_frame->return_address = i->cur_op; - STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); + goto STABLE(code)->invoke(i->tc, code, i->cur_callsite, args); goto NEXT(i); } __code cbc_checkarity(INTERP i){ @@ -1512,7 +1510,8 @@ goto NEXT(i); } __code cbc_invokewithcapture(INTERP i){ - MVMObject *cobj = GET_REG(i->cur_op, 4,i).o; + static MVMObject *cobj; + cobj = GET_REG(i->cur_op, 4,i).o; if (IS_CONCRETE(cobj) && REPR(cobj)->ID == MVM_REPR_ID_MVMCallCapture) { MVMObject *code = GET_REG(i->cur_op, 2,i).o; MVMCallCapture *cc = (MVMCallCapture *)cobj; @@ -1975,7 +1974,8 @@ goto NEXT(i); } __code cbc_clone(INTERP i){ - MVMObject *value = GET_REG(i->cur_op, 2,i).o; + static MVMObject *value; + value = GET_REG(i->cur_op, 2,i).o; if (IS_CONCRETE(value)) { MVMROOT(i->tc, value, { MVMObject *cloned = REPR(value)->allocate(i->tc, STABLE(value)); @@ -2638,7 +2638,8 @@ goto NEXT(i); } __code cbc_setmethcache(INTERP i){ - MVMObject *iter = MVM_iter(i->tc, GET_REG(i->cur_op, 2,i).o); + static MVMObject *iter; + iter = MVM_iter(i->tc, GET_REG(i->cur_op, 2,i).o); MVMObject *cache; MVMSTable *stable; MVMROOT(i->tc, iter, { @@ -2646,7 +2647,7 @@ }); while (MVM_iter_istrue(i->tc, (MVMIter *)iter)) { - MVMRegister result; + static MVMRegister result; //invoke elimination was failed codesegment REPR(iter)->pos_funcs.shift(i->tc, STABLE(iter), iter, OBJECT_BODY(iter), &result, MVM_reg_obj); MVM_repr_bind_key_o(i->tc, cache, MVM_iterkey_s(i->tc, (MVMIter *)iter), @@ -3039,7 +3040,7 @@ } __code cbc_freshcoderef(INTERP i){ MVMObject * const cr = GET_REG(i->cur_op, 2,i).o; - MVMCode *ncr; + static MVMCode *ncr; //invoke tail call elimination if (REPR(cr)->ID != MVM_REPR_ID_MVMCode) MVM_exception_throw_adhoc(i->tc, "freshcoderef requires a coderef"); ncr = (MVMCode *)(GET_REG(i->cur_op, 0,i).o = MVM_repr_clone(i->tc, cr)); @@ -3157,8 +3158,12 @@ MVMString *name = GET_REG(i->cur_op, 2,i).s; const MVMContainerConfigurer *cc = MVM_6model_get_container_config(i->tc, name); if (cc == NULL) { - char *c_name = MVM_string_utf8_encode_C_string(i->tc, name); - char *waste[] = { c_name, NULL }; + static char *c_name; + //char *c_name = MVM_string_utf8_encode_C_string(i->tc, name); invoke elimination codesegment + c_name = MVM_string_utf8_encode_C_string(i->tc, name); + //char *waste[] = { c_name, NULL }; + static char *waste[] = { NULL, NULL }; + waste[0] = c_name; MVM_exception_throw_adhoc_free(i->tc, waste, "Cannot use unknown container spec %s", c_name); } @@ -3325,8 +3330,10 @@ i->cur_op += 2; goto NEXT(i); } -__code cbc_pushcompsc(INTERP i){ - MVMObject * const sc = GET_REG(i->cur_op, 0,i).o; +__code cbc_pushcompsc(INTERP i){ //lasterror + //MVMObject * const sc = GET_REG(i->cur_op, 0,i).o; + static MVMObject * sc; + sc = GET_REG(i->cur_op, 0,i).o; if (REPR(sc)->ID != MVM_REPR_ID_SCRef) MVM_exception_throw_adhoc(i->tc, "Can only push an SCRef with pushcompsc"); if (MVM_is_null(i->tc, i->tc->compiling_scs)) {