Class: SyntaxTree::YARV::GetBlockParam

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

Overview

### Summary

getblockparam is a similar instruction to getlocal in that it looks for a local variable in the current instruction sequence’s local table and walks recursively up the parent instruction sequences until it finds it. The local it retrieves, however, is a special block local that was passed to the current method. It pushes the value of the block local onto the stack.

### Usage

~~~ruby def foo(&block)

block

end ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, level) ⇒ GetBlockParam

Returns a new instance of GetBlockParam.



1386
1387
1388
1389
# File 'lib/syntax_tree/yarv/instructions.rb', line 1386

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1384
1385
1386
# File 'lib/syntax_tree/yarv/instructions.rb', line 1384

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



1384
1385
1386
# File 'lib/syntax_tree/yarv/instructions.rb', line 1384

def level
  @level
end

Instance Method Details

#call(vm) ⇒ Object



1417
1418
1419
# File 'lib/syntax_tree/yarv/instructions.rb', line 1417

def call(vm)
  vm.push(vm.local_get(index, level))
end

#canonicalObject



1413
1414
1415
# File 'lib/syntax_tree/yarv/instructions.rb', line 1413

def canonical
  self
end

#disasm(fmt) ⇒ Object



1391
1392
1393
# File 'lib/syntax_tree/yarv/instructions.rb', line 1391

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

#lengthObject



1401
1402
1403
# File 'lib/syntax_tree/yarv/instructions.rb', line 1401

def length
  3
end

#popsObject



1405
1406
1407
# File 'lib/syntax_tree/yarv/instructions.rb', line 1405

def pops
  0
end

#pushesObject



1409
1410
1411
# File 'lib/syntax_tree/yarv/instructions.rb', line 1409

def pushes
  1
end

#to_a(iseq) ⇒ Object



1395
1396
1397
1398
1399
# File 'lib/syntax_tree/yarv/instructions.rb', line 1395

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