Class: SyntaxTree::YARV::SetLocal
Overview
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
value = 5
tap { tap { value = 10 } }
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #pushes, #side_effects?
Constructor Details
#initialize(index, level) ⇒ SetLocal
Returns a new instance of SetLocal.
5219
5220
5221
5222
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5219
def initialize(index, level)
@index = index
@level = level
end
|
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
5217
5218
5219
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5217
def index
@index
end
|
#level ⇒ Object
Returns the value of attribute level.
5217
5218
5219
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5217
def level
@level
end
|
Instance Method Details
#==(other) ⇒ Object
5238
5239
5240
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5238
def ==(other)
other.is_a?(SetLocal) && other.index == index && other.level == level
end
|
#call(vm) ⇒ Object
5250
5251
5252
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5250
def call(vm)
vm.local_set(index, level, vm.pop)
end
|
#deconstruct_keys(_keys) ⇒ Object
5234
5235
5236
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5234
def deconstruct_keys(_keys)
{ index: index, level: level }
end
|
#disasm(fmt) ⇒ Object
5224
5225
5226
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5224
def disasm(fmt)
fmt.instruction("setlocal", [fmt.local(index, explicit: level)])
end
|
#length ⇒ Object
5242
5243
5244
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5242
def length
3
end
|
#pops ⇒ Object
5246
5247
5248
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5246
def pops
1
end
|
#to_a(iseq) ⇒ Object
5228
5229
5230
5231
5232
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 5228
def to_a(iseq)
current = iseq
level.times { current = current.parent_iseq }
[:setlocal, current.local_table.offset(index), level]
end
|