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.



4908
4909
4910
4911
# File 'lib/syntax_tree/yarv/instructions.rb', line 4908

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



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

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



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

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

#call(vm) ⇒ Object



4940
4941
4942
# File 'lib/syntax_tree/yarv/instructions.rb', line 4940

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

#deconstruct_keys(_keys) ⇒ Object



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

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

#disasm(fmt) ⇒ Object



4913
4914
4915
# File 'lib/syntax_tree/yarv/instructions.rb', line 4913

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

#lengthObject



4932
4933
4934
# File 'lib/syntax_tree/yarv/instructions.rb', line 4932

def length
  3
end

#popsObject



4936
4937
4938
# File 'lib/syntax_tree/yarv/instructions.rb', line 4936

def pops
  1
end

#to_a(iseq) ⇒ Object



4917
4918
4919
4920
4921
# File 'lib/syntax_tree/yarv/instructions.rb', line 4917

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