Class: SyntaxTree::YARV::GetBlockParam

Inherits:
Instruction 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

Methods inherited from Instruction

#branch_targets, #canonical, #falls_through?, #leaves?, #pops, #side_effects?

Constructor Details

#initialize(index, level) ⇒ GetBlockParam

Returns a new instance of GetBlockParam.



1431
1432
1433
1434
# File 'lib/syntax_tree/yarv/instructions.rb', line 1431

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



1429
1430
1431
# File 'lib/syntax_tree/yarv/instructions.rb', line 1429

def index
  @index
end

#levelObject (readonly)

Returns the value of attribute level.



1429
1430
1431
# File 'lib/syntax_tree/yarv/instructions.rb', line 1429

def level
  @level
end

Instance Method Details

#==(other) ⇒ Object



1450
1451
1452
1453
# File 'lib/syntax_tree/yarv/instructions.rb', line 1450

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

#call(vm) ⇒ Object



1463
1464
1465
# File 'lib/syntax_tree/yarv/instructions.rb', line 1463

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

#deconstruct_keys(_keys) ⇒ Object



1446
1447
1448
# File 'lib/syntax_tree/yarv/instructions.rb', line 1446

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

#disasm(fmt) ⇒ Object



1436
1437
1438
# File 'lib/syntax_tree/yarv/instructions.rb', line 1436

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

#lengthObject



1455
1456
1457
# File 'lib/syntax_tree/yarv/instructions.rb', line 1455

def length
  3
end

#pushesObject



1459
1460
1461
# File 'lib/syntax_tree/yarv/instructions.rb', line 1459

def pushes
  1
end

#to_a(iseq) ⇒ Object



1440
1441
1442
1443
1444
# File 'lib/syntax_tree/yarv/instructions.rb', line 1440

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