Class: SyntaxTree::YARV::SetBlockParam

Inherits:
Object
  • Object
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

Constructor Details

#initialize(index, level) ⇒ SetBlockParam



4570
4571
4572
4573
# File 'lib/syntax_tree/yarv/instructions.rb', line 4570

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



4568
4569
4570
# File 'lib/syntax_tree/yarv/instructions.rb', line 4568

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



4568
4569
4570
# File 'lib/syntax_tree/yarv/instructions.rb', line 4568

def level
  @level
end

Instance Method Details

#call(vm) ⇒ Object



4601
4602
4603
# File 'lib/syntax_tree/yarv/instructions.rb', line 4601

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

#canonicalObject



4597
4598
4599
# File 'lib/syntax_tree/yarv/instructions.rb', line 4597

def canonical
  self
end

#disasm(fmt) ⇒ Object



4575
4576
4577
# File 'lib/syntax_tree/yarv/instructions.rb', line 4575

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

#lengthObject



4585
4586
4587
# File 'lib/syntax_tree/yarv/instructions.rb', line 4585

def length
  3
end

#popsObject



4589
4590
4591
# File 'lib/syntax_tree/yarv/instructions.rb', line 4589

def pops
  1
end

#pushesObject



4593
4594
4595
# File 'lib/syntax_tree/yarv/instructions.rb', line 4593

def pushes
  0
end

#to_a(iseq) ⇒ Object



4579
4580
4581
4582
4583
# File 'lib/syntax_tree/yarv/instructions.rb', line 4579

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