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.



4954
4955
4956
4957
# File 'lib/syntax_tree/yarv/instructions.rb', line 4954

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



4952
4953
4954
# File 'lib/syntax_tree/yarv/instructions.rb', line 4952

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



4952
4953
4954
# File 'lib/syntax_tree/yarv/instructions.rb', line 4952

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



4973
4974
4975
4976
# File 'lib/syntax_tree/yarv/instructions.rb', line 4973

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

#call(vm) ⇒ Object



4986
4987
4988
# File 'lib/syntax_tree/yarv/instructions.rb', line 4986

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

#deconstruct_keys(_keys) ⇒ Object



4969
4970
4971
# File 'lib/syntax_tree/yarv/instructions.rb', line 4969

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

#disasm(fmt) ⇒ Object



4959
4960
4961
# File 'lib/syntax_tree/yarv/instructions.rb', line 4959

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

#lengthObject



4978
4979
4980
# File 'lib/syntax_tree/yarv/instructions.rb', line 4978

def length
  3
end

#popsObject



4982
4983
4984
# File 'lib/syntax_tree/yarv/instructions.rb', line 4982

def pops
  1
end

#to_a(iseq) ⇒ Object



4963
4964
4965
4966
4967
# File 'lib/syntax_tree/yarv/instructions.rb', line 4963

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