Skip to content

Commit

Permalink
Port over putstring
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb authored and k0kubun committed Aug 26, 2022
1 parent 46d4912 commit 1b0e0f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 8 additions & 0 deletions bootstraptest/test_yjit_new_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def foo(n)
foo(7)
}

# putstring
assert_equal 'foo', %q{
def foo(n)
"foo"
end
foo(7)
}

# TODO: progress towards getting branches and calls working
=begin
def foo(n)
Expand Down
17 changes: 11 additions & 6 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,28 +1754,31 @@ fn gen_newhash(
KeepCompiling
}
*/

fn gen_putstring(
jit: &mut JITState,
ctx: &mut Context,
cb: &mut CodeBlock,
asm: &mut Assembler,
_ocb: &mut OutlinedCb,
) -> CodegenStatus {
let put_val = jit_get_arg(jit, 0);

// Save the PC and SP because the callee will allocate
jit_prepare_routine_call(jit, ctx, cb, REG0);
jit_prepare_routine_call(jit, ctx, asm);

mov(cb, C_ARG_REGS[0], REG_EC);
jit_mov_gc_ptr(jit, cb, C_ARG_REGS[1], put_val);
call_ptr(cb, REG0, rb_ec_str_resurrect as *const u8);
let str_opnd = asm.ccall(
rb_ec_str_resurrect as *const u8,
vec![EC, put_val.into()]
);

let stack_top = ctx.stack_push(Type::CString);
mov(cb, stack_top, RAX);
asm.mov(stack_top, str_opnd);

KeepCompiling
}

/*
// Push Qtrue or Qfalse depending on whether the given keyword was supplied by
// the caller
fn gen_checkkeyword(
Expand Down Expand Up @@ -6018,7 +6021,9 @@ fn get_gen_fn(opcode: VALUE) -> Option<InsnGenFn> {
YARVINSN_opt_str_uminus => Some(gen_opt_str_uminus),
YARVINSN_splatarray => Some(gen_splatarray),
YARVINSN_newrange => Some(gen_newrange),
*/
YARVINSN_putstring => Some(gen_putstring),
/*
YARVINSN_expandarray => Some(gen_expandarray),
YARVINSN_defined => Some(gen_defined),
YARVINSN_checkkeyword => Some(gen_checkkeyword),
Expand Down

0 comments on commit 1b0e0f3

Please sign in to comment.