Class: SyntaxTree::YARV::OptGetConstantPath

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

Methods inherited from Instruction

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

Constructor Details

#initialize(names) ⇒ OptGetConstantPath

Returns a new instance of OptGetConstantPath.



3260
3261
3262
# File 'lib/syntax_tree/yarv/instructions.rb', line 3260

def initialize(names)
  @names = names
end

Instance Attribute Details

#namesObject (readonly)

Returns the value of attribute names.



3258
3259
3260
# File 'lib/syntax_tree/yarv/instructions.rb', line 3258

def names
  @names
end

Instance Method Details

#==(other) ⇒ Object



3277
3278
3279
# File 'lib/syntax_tree/yarv/instructions.rb', line 3277

def ==(other)
  other.is_a?(OptGetConstantPath) && other.names == names
end

#call(vm) ⇒ Object



3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
# File 'lib/syntax_tree/yarv/instructions.rb', line 3289

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

#deconstruct_keys(_keys) ⇒ Object



3273
3274
3275
# File 'lib/syntax_tree/yarv/instructions.rb', line 3273

def deconstruct_keys(_keys)
  { names: names }
end

#disasm(fmt) ⇒ Object



3264
3265
3266
3267
# File 'lib/syntax_tree/yarv/instructions.rb', line 3264

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

#lengthObject



3281
3282
3283
# File 'lib/syntax_tree/yarv/instructions.rb', line 3281

def length
  2
end

#pushesObject



3285
3286
3287
# File 'lib/syntax_tree/yarv/instructions.rb', line 3285

def pushes
  1
end

#to_a(_iseq) ⇒ Object



3269
3270
3271
# File 'lib/syntax_tree/yarv/instructions.rb', line 3269

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