Skip to content

Commit e584708

Browse files
authoredApr 28, 2021
Implement setn bytecode (#15)
1 parent 56a7e7c commit e584708

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed
 

‎yjit_codegen.c

+23-3
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ yjit_gen_block(block_t *block, rb_execution_context_t *ec)
454454
}
455455
}
456456

457+
static codegen_status_t
458+
gen_nop(jitstate_t* jit, ctx_t* ctx)
459+
{
460+
// Do nothing
461+
return YJIT_KEEP_COMPILING;
462+
}
463+
457464
static codegen_status_t
458465
gen_dup(jitstate_t* jit, ctx_t* ctx)
459466
{
@@ -469,10 +476,22 @@ gen_dup(jitstate_t* jit, ctx_t* ctx)
469476
return YJIT_KEEP_COMPILING;
470477
}
471478

479+
// set Nth stack entry to stack top
472480
static codegen_status_t
473-
gen_nop(jitstate_t* jit, ctx_t* ctx)
481+
gen_setn(jitstate_t* jit, ctx_t* ctx)
474482
{
475-
// Do nothing
483+
rb_num_t n = (rb_num_t)jit_get_arg(jit, 0);
484+
485+
// Get the top value and its type
486+
val_type_t top_type = ctx_get_opnd_type(ctx, OPND_STACK(0));
487+
x86opnd_t top_val = ctx_stack_pop(ctx, 0);
488+
489+
// Set the destination and its type
490+
ctx_set_opnd_type(ctx, OPND_STACK(n), top_type);
491+
x86opnd_t dst_opnd = ctx_stack_opnd(ctx, (int32_t)n);
492+
mov(cb, REG0, top_val);
493+
mov(cb, dst_opnd, REG0);
494+
476495
return YJIT_KEEP_COMPILING;
477496
}
478497

@@ -2219,8 +2238,9 @@ yjit_init_codegen(void)
22192238
leave_exit_code = yjit_gen_leave_exit(cb);
22202239

22212240
// Map YARV opcodes to the corresponding codegen functions
2222-
yjit_reg_op(BIN(dup), gen_dup);
22232241
yjit_reg_op(BIN(nop), gen_nop);
2242+
yjit_reg_op(BIN(dup), gen_dup);
2243+
yjit_reg_op(BIN(setn), gen_setn);
22242244
yjit_reg_op(BIN(pop), gen_pop);
22252245
yjit_reg_op(BIN(putnil), gen_putnil);
22262246
yjit_reg_op(BIN(putobject), gen_putobject);

0 commit comments

Comments
 (0)
Failed to load comments.