Skip to content

Commit 8759ee1

Browse files
maximecbnoahgibbs
authored andcommittedOct 20, 2021
Implement setn bytecode (#15)
1 parent 7793436 commit 8759ee1

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
@@ -456,6 +456,13 @@ yjit_gen_block(block_t *block, rb_execution_context_t *ec)
456456
}
457457
}
458458

459+
static codegen_status_t
460+
gen_nop(jitstate_t* jit, ctx_t* ctx)
461+
{
462+
// Do nothing
463+
return YJIT_KEEP_COMPILING;
464+
}
465+
459466
static codegen_status_t
460467
gen_dup(jitstate_t* jit, ctx_t* ctx)
461468
{
@@ -471,10 +478,22 @@ gen_dup(jitstate_t* jit, ctx_t* ctx)
471478
return YJIT_KEEP_COMPILING;
472479
}
473480

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

@@ -2220,8 +2239,9 @@ yjit_init_codegen(void)
22202239
leave_exit_code = yjit_gen_leave_exit(cb);
22212240

22222241
// Map YARV opcodes to the corresponding codegen functions
2223-
yjit_reg_op(BIN(dup), gen_dup);
22242242
yjit_reg_op(BIN(nop), gen_nop);
2243+
yjit_reg_op(BIN(dup), gen_dup);
2244+
yjit_reg_op(BIN(setn), gen_setn);
22252245
yjit_reg_op(BIN(pop), gen_pop);
22262246
yjit_reg_op(BIN(putnil), gen_putnil);
22272247
yjit_reg_op(BIN(putobject), gen_putobject);

0 commit comments

Comments
 (0)
Failed to load comments.