diff options
Diffstat (limited to 'lib/ruby_vm/rjit/context.rb')
-rw-r--r-- | lib/ruby_vm/rjit/context.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/ruby_vm/rjit/context.rb b/lib/ruby_vm/rjit/context.rb new file mode 100644 index 0000000000..e834b42999 --- /dev/null +++ b/lib/ruby_vm/rjit/context.rb @@ -0,0 +1,30 @@ +module RubyVM::MJIT + class Context < Struct.new( + :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 + ) + def initialize(stack_size: 0, sp_offset: 0, chain_depth: 0) = super + + def stack_push(size = 1) + self.stack_size += size + self.sp_offset += size + stack_opnd(0) + end + + def stack_pop(size = 1) + opnd = stack_opnd(0) + self.stack_size -= size + self.sp_offset -= size + opnd + end + + def stack_opnd(depth_from_top) + [SP, C.VALUE.size * (self.sp_offset - 1 - depth_from_top)] + end + + def sp_opnd(offset_bytes = 0) + [SP, (C.VALUE.size * self.sp_offset) + offset_bytes] + end + end +end |