Class: SyntaxTree::YARV::GetGlobal

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

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(name) ⇒ GetGlobal

Returns a new instance of GetGlobal.



1773
1774
1775
# File 'lib/syntax_tree/yarv/instructions.rb', line 1773

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



1771
1772
1773
# File 'lib/syntax_tree/yarv/instructions.rb', line 1771

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



1789
1790
1791
# File 'lib/syntax_tree/yarv/instructions.rb', line 1789

def ==(other)
  other.is_a?(GetGlobal) && other.name == name
end

#call(vm) ⇒ Object



1801
1802
1803
1804
1805
# File 'lib/syntax_tree/yarv/instructions.rb', line 1801

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

#deconstruct_keys(_keys) ⇒ Object



1785
1786
1787
# File 'lib/syntax_tree/yarv/instructions.rb', line 1785

def deconstruct_keys(_keys)
  { name: name }
end

#disasm(fmt) ⇒ Object



1777
1778
1779
# File 'lib/syntax_tree/yarv/instructions.rb', line 1777

def disasm(fmt)
  fmt.instruction("getglobal", [fmt.object(name)])
end

#lengthObject



1793
1794
1795
# File 'lib/syntax_tree/yarv/instructions.rb', line 1793

def length
  2
end

#pushesObject



1797
1798
1799
# File 'lib/syntax_tree/yarv/instructions.rb', line 1797

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1781
1782
1783
# File 'lib/syntax_tree/yarv/instructions.rb', line 1781

def to_a(_iseq)
  [:getglobal, name]
end