class SyntaxTree::YARV::GetLocal

### Summary

‘getlocal` fetches the value of a local variable from 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 pushes the value it finds onto the stack.

### Usage

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

Attributes

index[R]
level[R]

Public Class Methods

new(index, level) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1831
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 1850
def ==(other)
  other.is_a?(GetLocal) && other.index == index && other.level == level
end
call(vm) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1862
def call(vm)
  vm.push(vm.local_get(index, level))
end
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1846
def deconstruct_keys(_keys)
  { index: index, level: level }
end
disasm(fmt) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1836
def disasm(fmt)
  fmt.instruction("getlocal", [fmt.local(index, explicit: level)])
end
length() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1854
def length
  3
end
pushes() click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1858
def pushes
  1
end
to_a(iseq) click to toggle source
# File lib/syntax_tree/yarv/instructions.rb, line 1840
def to_a(iseq)
  current = iseq
  level.times { current = current.parent_iseq }
  [:getlocal, current.local_table.offset(index), level]
end