class SyntaxTree::YARV::SetLocal

### Summary

‘setlocal` sets the value of a local variable on a frame determined by the level and index arguments. The level is the number of frames back to look and the index is the index in the local table. It pops the value it is setting off the stack.

### Usage

~~~ruby value = 5 tap { tap { value = 10 } } ~~~

Attributes

index[R]
level[R]

Public Class Methods

new(index, level) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5173
def initialize(index, level)
  @index = index
  @level = level
end

Public Instance Methods

==(other) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5192
def ==(other)
  other.is_a?(SetLocal) && other.index == index && other.level == level
end
call(vm) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5204
def call(vm)
  vm.local_set(index, level, vm.pop)
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5188
def deconstruct_keys(_keys)
  { index: index, level: level }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5178
def disasm(fmt)
  fmt.instruction("setlocal", [fmt.local(index, explicit: level)])
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5196
def length
  3
end
pops() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5200
def pops
  1
end
to_a(iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 5182
def to_a(iseq)
  current = iseq
  level.times { current = current.parent_iseq }
  [:setlocal, current.local_table.offset(index), level]
end