Class: SyntaxTree::YARV::GetConstant
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::GetConstant
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
getconstant performs a constant lookup and pushes the value of the constant onto the stack. It pops both the class it should look in and whether or not it should look globally as well.
### Usage
~~~ruby Constant ~~~
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name) ⇒ GetConstant
constructor
A new instance of GetConstant.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name) ⇒ GetConstant
1548 1549 1550 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1548 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
1546 1547 1548 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1546 def name @name end |
Instance Method Details
#call(vm) ⇒ Object
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1576 def call(vm) const_base, allow_nil = vm.pop(2) if const_base if const_base.const_defined?(name) vm.push(const_base.const_get(name)) return end elsif const_base.nil? && allow_nil vm.frame.nesting.reverse_each do |clazz| if clazz.const_defined?(name) vm.push(clazz.const_get(name)) return end end end raise NameError, "uninitialized constant #{name}" end |
#canonical ⇒ Object
1572 1573 1574 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1572 def canonical self end |
#disasm(fmt) ⇒ Object
1552 1553 1554 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1552 def disasm(fmt) fmt.instruction("getconstant", [fmt.object(name)]) end |
#length ⇒ Object
1560 1561 1562 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1560 def length 2 end |
#pops ⇒ Object
1564 1565 1566 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1564 def pops 2 end |
#pushes ⇒ Object
1568 1569 1570 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1568 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1556 1557 1558 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1556 def to_a(_iseq) [:getconstant, name] end |