Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 4, 2023
1 parent 84205f7 commit 716c856
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3933,7 +3933,7 @@ iseq_specialized_instruction(rb_iseq_t *iseq, INSN *iobj)
switch (vm_ci_mid(ci)) {
case idNew:
iobj->insn_id = BIN(opt_new);
iobj->operands[1] = (VALUE)new_callinfo(iseq, idInitialize, vm_ci_argc(ci), vm_ci_flag(ci) | VM_CALL_FCALL, vm_ci_kwarg(ci), FALSE);
iobj->operands[1] = (VALUE)new_callinfo(iseq, idInitialize, vm_ci_argc(ci) - vm_ci_kwarg(ci)->keyword_len, vm_ci_flag(ci) | VM_CALL_FCALL, vm_ci_kwarg(ci), FALSE);
break;
default:
iobj->insn_id = BIN(opt_send_without_block);
Expand Down
38 changes: 24 additions & 14 deletions insns.def
Original file line number Diff line number Diff line change
Expand Up @@ -838,22 +838,32 @@ opt_new
// attr rb_snum_t sp_inc = sp_inc_of_sendish(cd->ci);
// attr rb_snum_t comptime_sp_inc = sp_inc_of_sendish(ci);
{
VALUE recv = TOPN(vm_ci_argc(cd->ci));

val = vm_opt_new_alloc(GET_ISEQ(), recv, cd);
if (val != Qundef) {
TOPN(vm_ci_argc(cd->ci)) = val;
fprintf(stderr, "opt!\n");
if (vm_sendish(ec, GET_CFP(), cd_initialize, VM_BLOCK_HANDLER_NONE, mexp_search_method) == Qundef) {
val = Qundef;
}
}
int argc = vm_ci_argc(cd->ci);
VM_ASSERT((int)vm_ci_argc(cd_initialize->ci) == argc);

if (val == Qundef) {
fprintf(stderr, "de-opt!\n");
VALUE recv = TOPN(argc);
val = Qundef;

VALUE new_obj = vm_opt_new_alloc(GET_ISEQ(), recv, cd);
if (new_obj != Qundef) {
TOPN(argc) = new_obj;

val = vm_sendish(ec, GET_CFP(), cd_initialize, VM_BLOCK_HANDLER_NONE, mexp_search_method);
// FIXME: somehow the `initialize` return is what end up being the `.new` return, instead of `new_obj`.
// I don't get why.

JIT_EXEC(ec, val);

VALUE bh = VM_BLOCK_HANDLER_NONE;
val = vm_sendish(ec, GET_CFP(), cd, bh, mexp_search_method);
if (val == Qundef) {
RESTORE_REGS();
NEXT_INSN();
}
else {
val = new_obj;
}
}
else if (val == Qundef) {
val = vm_sendish(ec, GET_CFP(), cd, VM_BLOCK_HANDLER_NONE, mexp_search_method);
JIT_EXEC(ec, val);

if (val == Qundef) {
Expand Down
2 changes: 2 additions & 0 deletions internal/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ static inline void RBASIC_CLEAR_CLASS(VALUE obj);
static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass);
static inline void RBASIC_SET_CLASS(VALUE obj, VALUE klass);
VALUE rb_class_alloc(VALUE klass);
VALUE rb_obj_initialize(VALUE _self);


RUBY_SYMBOL_EXPORT_BEGIN
/* object.c (export) */
Expand Down
6 changes: 5 additions & 1 deletion object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,11 @@ rb_class_search_ancestor(VALUE cl, VALUE c)
*
* Returns a new BasicObject.
*/
#define rb_obj_initialize rb_obj_dummy0
VALUE
rb_obj_initialize(VALUE _self)
{
return Qnil;
}

/*
* Not documented
Expand Down

0 comments on commit 716c856

Please sign in to comment.