ruby/lib/ruby_vm/rjit/context.rb

41 lines
1.2 KiB
Ruby
Raw Normal View History

2023-03-06 23:15:30 -08:00
module RubyVM::RJIT
2023-02-06 15:44:34 -08:00
class Context < Struct.new(
2023-02-08 00:47:01 -08:00
:stack_size, # @param [Integer] The number of values on the stack
:sp_offset, # @param [Integer] JIT sp offset relative to the interpreter's sp
:chain_depth, # @param [Integer] jit_chain_guard depth
2023-02-06 15:44:34 -08:00
)
2023-02-08 00:47:01 -08:00
def initialize(stack_size: 0, sp_offset: 0, chain_depth: 0) = super
2022-12-31 13:41:32 -08:00
2023-02-06 15:44:34 -08:00
def stack_push(size = 1)
self.stack_size += size
self.sp_offset += size
2023-02-08 17:17:36 -08:00
stack_opnd(0)
2023-02-06 15:44:34 -08:00
end
2023-01-02 22:53:14 -08:00
2023-02-06 15:44:34 -08:00
def stack_pop(size = 1)
2023-02-08 17:17:36 -08:00
opnd = stack_opnd(0)
2023-02-06 15:44:34 -08:00
self.stack_size -= size
self.sp_offset -= size
2023-02-08 17:17:36 -08:00
opnd
2023-02-06 15:44:34 -08:00
end
2023-02-08 11:10:04 -08:00
def stack_opnd(depth_from_top)
[SP, C.VALUE.size * (self.sp_offset - 1 - depth_from_top)]
end
2023-02-09 16:25:06 -08:00
def sp_opnd(offset_bytes = 0)
2023-02-08 11:10:04 -08:00
[SP, (C.VALUE.size * self.sp_offset) + offset_bytes]
end
# Create a new Context instance with a given stack_size and sp_offset adjusted
# accordingly. This is useful when you want to virtually rewind a stack_size for
# generating a side exit while considering past sp_offset changes on gen_save_sp.
def with_stack_size(stack_size)
ctx = self.dup
ctx.sp_offset -= ctx.stack_size - stack_size
ctx.stack_size = stack_size
ctx
end
2023-01-02 22:53:14 -08:00
end
2022-12-23 14:17:32 -08:00
end