Class: SyntaxTree::YARV::GetGlobal

Inherits:
Object
  • Object
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

Constructor Details

#initialize(name) ⇒ GetGlobal



1610
1611
1612
# File 'lib/syntax_tree/yarv/instructions.rb', line 1610

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



1608
1609
1610
# File 'lib/syntax_tree/yarv/instructions.rb', line 1608

def name
  @name
end

Instance Method Details

#call(vm) ⇒ Object



1638
1639
1640
1641
1642
# File 'lib/syntax_tree/yarv/instructions.rb', line 1638

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

#canonicalObject



1634
1635
1636
# File 'lib/syntax_tree/yarv/instructions.rb', line 1634

def canonical
  self
end

#disasm(fmt) ⇒ Object



1614
1615
1616
# File 'lib/syntax_tree/yarv/instructions.rb', line 1614

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

#lengthObject



1622
1623
1624
# File 'lib/syntax_tree/yarv/instructions.rb', line 1622

def length
  2
end

#popsObject



1626
1627
1628
# File 'lib/syntax_tree/yarv/instructions.rb', line 1626

def pops
  0
end

#pushesObject



1630
1631
1632
# File 'lib/syntax_tree/yarv/instructions.rb', line 1630

def pushes
  1
end

#to_a(_iseq) ⇒ Object



1618
1619
1620
# File 'lib/syntax_tree/yarv/instructions.rb', line 1618

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