Class: SyntaxTree::YARV::SetBlockParam

Inherits:
Instruction show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

‘setblockparam` sets the value of a block 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 def foo(&bar)

bar = baz

end ~~~

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) ⇒ SetBlockParam

Returns a new instance of SetBlockParam.



4896
4897
4898
4899
# File 'lib/syntax_tree/yarv/instructions.rb', line 4896

def initialize(index, level)
  @index = index
  @level = level
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



4894
4895
4896
# File 'lib/syntax_tree/yarv/instructions.rb', line 4894

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



4894
4895
4896
# File 'lib/syntax_tree/yarv/instructions.rb', line 4894

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



4915
4916
4917
4918
# File 'lib/syntax_tree/yarv/instructions.rb', line 4915

def ==(other)
  other.is_a?(SetBlockParam) && other.index == index &&
    other.level == level
end

#call(vm) ⇒ Object



4928
4929
4930
# File 'lib/syntax_tree/yarv/instructions.rb', line 4928

def call(vm)
  vm.local_set(index, level, vm.pop)
end

#deconstruct_keys(_keys) ⇒ Object



4911
4912
4913
# File 'lib/syntax_tree/yarv/instructions.rb', line 4911

def deconstruct_keys(_keys)
  { index: index, level: level }
end

#disasm(fmt) ⇒ Object



4901
4902
4903
# File 'lib/syntax_tree/yarv/instructions.rb', line 4901

def disasm(fmt)
  fmt.instruction("setblockparam", [fmt.local(index, explicit: level)])
end

#lengthObject



4920
4921
4922
# File 'lib/syntax_tree/yarv/instructions.rb', line 4920

def length
  3
end

#popsObject



4924
4925
4926
# File 'lib/syntax_tree/yarv/instructions.rb', line 4924

def pops
  1
end

#to_a(iseq) ⇒ Object



4905
4906
4907
4908
4909
# File 'lib/syntax_tree/yarv/instructions.rb', line 4905

def to_a(iseq)
  current = iseq
  level.times { current = current.parent_iseq }
  [:setblockparam, current.local_table.offset(index), level]
end