Class: SyntaxTree::YARV::GetGlobal
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::GetGlobal
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
getglobal pushes the value of a global variables onto the stack.
### Usage
~~~ruby $$ ~~~
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(name) ⇒ GetGlobal
constructor
A new instance of GetGlobal.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(name) ⇒ GetGlobal
Returns a new instance of GetGlobal.
1804 1805 1806 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1804 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
1802 1803 1804 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1802 def name @name end |
Instance Method Details
#==(other) ⇒ Object
1820 1821 1822 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1820 def ==(other) other.is_a?(GetGlobal) && other.name == name end |
#call(vm) ⇒ Object
1840 1841 1842 1843 1844 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1840 def call(vm) # Evaluating the name of the global variable because there isn't a # reflection API for global variables. vm.push(eval(name.to_s, binding, __FILE__, __LINE__)) end |
#canonical ⇒ Object
1836 1837 1838 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1836 def canonical self end |
#deconstruct_keys(_keys) ⇒ Object
1816 1817 1818 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1816 def deconstruct_keys(_keys) { name: name } end |
#disasm(fmt) ⇒ Object
1808 1809 1810 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1808 def disasm(fmt) fmt.instruction("getglobal", [fmt.object(name)]) end |
#length ⇒ Object
1824 1825 1826 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1824 def length 2 end |
#pops ⇒ Object
1828 1829 1830 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1828 def pops 0 end |
#pushes ⇒ Object
1832 1833 1834 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1832 def pushes 1 end |
#to_a(_iseq) ⇒ Object
1812 1813 1814 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 1812 def to_a(_iseq) [:getglobal, name] end |