Class: SyntaxTree::YARV::OptGetConstantPath

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/yarv/instructions.rb

Overview

### Summary

opt_getconstant_path performs a constant lookup on a chain of constant names. It accepts as its argument an array of constant names, and pushes the value of the constant onto the stack.

### Usage

~~~ruby ::Object ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names) ⇒ OptGetConstantPath

Returns a new instance of OptGetConstantPath.



3040
3041
3042
# File 'lib/syntax_tree/yarv/instructions.rb', line 3040

def initialize(names)
  @names = names
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



3038
3039
3040
# File 'lib/syntax_tree/yarv/instructions.rb', line 3038

def names
  @names
end

Instance Method Details

#call(vm) ⇒ Object



3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
# File 'lib/syntax_tree/yarv/instructions.rb', line 3069

def call(vm)
  current = vm.frame._self
  current = current.class unless current.is_a?(Class)

  names.each do |name|
    current = name == :"" ? Object : current.const_get(name)
  end

  vm.push(current)
end

#canonicalObject



3065
3066
3067
# File 'lib/syntax_tree/yarv/instructions.rb', line 3065

def canonical
  self
end

#disasm(fmt) ⇒ Object



3044
3045
3046
3047
# File 'lib/syntax_tree/yarv/instructions.rb', line 3044

def disasm(fmt)
  cache = "<ic:0 #{names.join("::")}>"
  fmt.instruction("opt_getconstant_path", [cache])
end

#lengthObject



3053
3054
3055
# File 'lib/syntax_tree/yarv/instructions.rb', line 3053

def length
  2
end

#popsObject



3057
3058
3059
# File 'lib/syntax_tree/yarv/instructions.rb', line 3057

def pops
  0
end

#pushesObject



3061
3062
3063
# File 'lib/syntax_tree/yarv/instructions.rb', line 3061

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3049
3050
3051
# File 'lib/syntax_tree/yarv/instructions.rb', line 3049

def to_a(_iseq)
  [:opt_getconstant_path, names]
end