Class: SyntaxTree::YARV::GetInstanceVariable
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::GetInstanceVariable
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
getinstancevariable pushes the value of an instance variable onto the stack. It uses an inline cache to avoid having to look up the instance variable in the class hierarchy every time.
This instruction has two forms, but both have the same structure. Before Ruby 3.2, the inline cache corresponded to both the get and set instructions and could be shared. Since Ruby 3.2, it uses object shapes instead so the caches are unique per instruction.
### Usage
~~~ruby ~~~
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name, cache) ⇒ GetInstanceVariable
constructor
A new instance of GetInstanceVariable.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name, cache) ⇒ GetInstanceVariable
1665 1666 1667 1668 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1665 def initialize(name, cache) @name = name @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
1663 1664 1665 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1663 def cache @cache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1663 1664 1665 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1663 def name @name end |
Instance Method Details
#call(vm) ⇒ Object
1697 1698 1699 1700 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1697 def call(vm) method = Object.instance_method(:instance_variable_get) vm.push(method.bind(vm.frame._self).call(name)) end |
#canonical ⇒ Object
1693 1694 1695 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1693 def canonical self end |
#disasm(fmt) ⇒ Object
1670 1671 1672 1673 1674 1675 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1670 def disasm(fmt) fmt.instruction( "getinstancevariable", [fmt.object(name), fmt.inline_storage(cache)] ) end |
#length ⇒ Object
1681 1682 1683 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1681 def length 3 end |
#pops ⇒ Object
1685 1686 1687 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1685 def pops 0 end |
#pushes ⇒ Object
1689 1690 1691 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1689 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1677 1678 1679 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1677 def to_a(_iseq) [:getinstancevariable, name, cache] end |