Class: SyntaxTree::YARV::GetLocal
Overview
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
value = 5
tap { tap { value } }
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?
Constructor Details
#initialize(index, level) ⇒ GetLocal
Returns a new instance of GetLocal.
1884
1885
1886
1887
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1884
def initialize(index, level)
@index = index
@level = level
end
|
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
1882
1883
1884
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1882
def index
@index
end
|
#level ⇒ Object
Returns the value of attribute level.
1882
1883
1884
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1882
def level
@level
end
|
Instance Method Details
#==(other) ⇒ Object
1903
1904
1905
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1903
def ==(other)
other.is_a?(GetLocal) && other.index == index && other.level == level
end
|
#call(vm) ⇒ Object
1915
1916
1917
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1915
def call(vm)
vm.push(vm.local_get(index, level))
end
|
#deconstruct_keys(_keys) ⇒ Object
1899
1900
1901
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1899
def deconstruct_keys(_keys)
{ index: index, level: level }
end
|
#disasm(fmt) ⇒ Object
1889
1890
1891
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1889
def disasm(fmt)
fmt.instruction("getlocal", [fmt.local(index, explicit: level)])
end
|
#length ⇒ Object
1907
1908
1909
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1907
def length
3
end
|
#pushes ⇒ Object
1911
1912
1913
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1911
def pushes
1
end
|
#to_a(iseq) ⇒ Object
1893
1894
1895
1896
1897
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 1893
def to_a(iseq)
current = iseq
level.times { current = current.parent_iseq }
[:getlocal, current.local_table.offset(index), level]
end
|