Skip to content

Commit

Permalink
RJIT: Implement setclassvariable
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 19, 2023
1 parent 8510f33 commit 71bcab4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/ruby_vm/rjit/insn_compiler.rb
Expand Up @@ -18,7 +18,7 @@ def compile(jit, ctx, asm, insn)
asm.incr_counter(:rjit_insns_count)
asm.comment("Insn: #{insn.name}")

# 82/102
# 83/102
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
Expand All @@ -31,7 +31,7 @@ def compile(jit, ctx, asm, insn)
when :getinstancevariable then getinstancevariable(jit, ctx, asm)
when :setinstancevariable then setinstancevariable(jit, ctx, asm)
when :getclassvariable then getclassvariable(jit, ctx, asm)
# setclassvariable
when :setclassvariable then setclassvariable(jit, ctx, asm)
when :opt_getconstant_path then opt_getconstant_path(jit, ctx, asm)
when :getconstant then getconstant(jit, ctx, asm)
# setconstant
Expand Down Expand Up @@ -556,7 +556,22 @@ def getclassvariable(jit, ctx, asm)
KeepCompiling
end

# setclassvariable
# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]
def setclassvariable(jit, ctx, asm)
# rb_vm_setclassvariable can raise exceptions.
jit_prepare_routine_call(jit, ctx, asm)

asm.mov(C_ARGS[0], [CFP, C.rb_control_frame_t.offsetof(:iseq)])
asm.mov(C_ARGS[1], CFP)
asm.mov(C_ARGS[2], jit.operand(0))
asm.mov(C_ARGS[3], ctx.stack_pop(1))
asm.mov(C_ARGS[4], jit.operand(1))
asm.call(C.rb_vm_setclassvariable)

KeepCompiling
end

# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
Expand Down Expand Up @@ -1251,6 +1266,9 @@ def definedivar(jit, ctx, asm)

# checkmatch

# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]
def checkkeyword(jit, ctx, asm)
# When a keyword is unspecified past index 32, a hash will be used
# instead. This can only happen in iseqs taking more than 32 keywords.
Expand Down
1 change: 1 addition & 0 deletions rjit_c.c
Expand Up @@ -496,6 +496,7 @@ extern rb_event_flag_t rb_rjit_global_events;
extern void rb_vm_setinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, VALUE val, IVC ic);
extern VALUE rb_vm_throw(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t throw_state, VALUE throwobj);
extern VALUE rb_reg_new_ary(VALUE ary, int opt);
extern void rb_vm_setclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, VALUE val, ICVARC ic);

#include "rjit_c.rbinc"

Expand Down
4 changes: 4 additions & 0 deletions rjit_c.rb
Expand Up @@ -625,6 +625,10 @@ def C.rb_vm_opt_newarray_min
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_min) }
end

def C.rb_vm_setclassvariable
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_setclassvariable) }
end

def C.rb_vm_setinstancevariable
Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_setinstancevariable) }
end
Expand Down
1 change: 1 addition & 0 deletions tool/rjit/bindgen.rb
Expand Up @@ -542,6 +542,7 @@ def push_target(target)
rb_reg_new_ary
rb_ary_clear
rb_str_intern
rb_vm_setclassvariable
],
types: %w[
CALL_DATA
Expand Down

0 comments on commit 71bcab4

Please sign in to comment.