Skip to content

Commit ea76369

Browse files
authored
Implement opt_freeze and opt_uminus (ruby#49)
1 parent 6643ace commit ea76369

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

yjit_codegen.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,40 @@ gen_opt_empty_p(jitstate_t* jit, ctx_t* ctx)
17311731
return gen_opt_send_without_block(jit, ctx);
17321732
}
17331733

1734+
static codegen_status_t
1735+
gen_opt_str_freeze(jitstate_t* jit, ctx_t* ctx)
1736+
{
1737+
if (!assume_bop_not_redefined(jit->block, STRING_REDEFINED_OP_FLAG, BOP_FREEZE)) {
1738+
return YJIT_CANT_COMPILE;
1739+
}
1740+
1741+
VALUE str = jit_get_arg(jit, 0);
1742+
jit_mov_gc_ptr(jit, cb, REG0, str);
1743+
1744+
// Push the return value onto the stack
1745+
x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_STRING);
1746+
mov(cb, stack_ret, REG0);
1747+
1748+
return YJIT_KEEP_COMPILING;
1749+
}
1750+
1751+
static codegen_status_t
1752+
gen_opt_str_uminus(jitstate_t* jit, ctx_t* ctx)
1753+
{
1754+
if (!assume_bop_not_redefined(jit->block, STRING_REDEFINED_OP_FLAG, BOP_UMINUS)) {
1755+
return YJIT_CANT_COMPILE;
1756+
}
1757+
1758+
VALUE str = jit_get_arg(jit, 0);
1759+
jit_mov_gc_ptr(jit, cb, REG0, str);
1760+
1761+
// Push the return value onto the stack
1762+
x86opnd_t stack_ret = ctx_stack_push(ctx, TYPE_STRING);
1763+
mov(cb, stack_ret, REG0);
1764+
1765+
return YJIT_KEEP_COMPILING;
1766+
}
1767+
17341768
static codegen_status_t
17351769
gen_opt_not(jitstate_t* jit, ctx_t* ctx)
17361770
{
@@ -2827,6 +2861,8 @@ yjit_init_codegen(void)
28272861
yjit_reg_op(BIN(opt_ltlt), gen_opt_ltlt);
28282862
yjit_reg_op(BIN(opt_nil_p), gen_opt_nil_p);
28292863
yjit_reg_op(BIN(opt_empty_p), gen_opt_empty_p);
2864+
yjit_reg_op(BIN(opt_str_freeze), gen_opt_str_freeze);
2865+
yjit_reg_op(BIN(opt_str_uminus), gen_opt_str_uminus);
28302866
yjit_reg_op(BIN(opt_not), gen_opt_not);
28312867
yjit_reg_op(BIN(opt_getinlinecache), gen_opt_getinlinecache);
28322868
yjit_reg_op(BIN(branchif), gen_branchif);

0 commit comments

Comments
 (0)