Class: SyntaxTree::YARV::GetBlockParam
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::GetBlockParam
- 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
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(index, level) ⇒ GetBlockParam
constructor
A new instance of GetBlockParam.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(iseq) ⇒ Object
Constructor Details
#initialize(index, level) ⇒ GetBlockParam
Returns a new instance of GetBlockParam.
1545 1546 1547 1548 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1545 def initialize(index, level) @index = index @level = level end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
1543 1544 1545 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1543 def index @index end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
1543 1544 1545 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1543 def level @level end |
Instance Method Details
#==(other) ⇒ Object
1564 1565 1566 1567 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1564 def ==(other) other.is_a?(GetBlockParam) && other.index == index && other.level == level end |
#call(vm) ⇒ Object
1585 1586 1587 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1585 def call(vm) vm.push(vm.local_get(index, level)) end |
#canonical ⇒ Object
1581 1582 1583 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1581 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
1560 1561 1562 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1560 def deconstruct_keys(_keys) { index: index, level: level } end |
#disasm(fmt) ⇒ Object
1550 1551 1552 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1550 def disasm(fmt) fmt.instruction("getblockparam", [fmt.local(index, explicit: level)]) end |
#length ⇒ Object
1569 1570 1571 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1569 def length 3 end |
#pops ⇒ Object
1573 1574 1575 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1573 def pops 0 end |
#pushes ⇒ Object
1577 1578 1579 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1577 def pushes 1 end |
#to_a(iseq) ⇒ Object
1554 1555 1556 1557 1558 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1554 def to_a(iseq) current = iseq level.times { current = iseq.parent_iseq } [:getblockparam, current.local_table.offset(index), level] end |