Class: SyntaxTree::YARV::PutSpecialObject

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

Overview

### Summary

‘putspecialobject` pushes one of three special objects onto the stack. These are either the VM core special object, the class base special object, or the constant base special object.

### Usage

~~~ruby alias foo bar ~~~

Constant Summary collapse

OBJECT_VMCORE =
1
OBJECT_CBASE =
2
OBJECT_CONST_BASE =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(object) ⇒ PutSpecialObject

Returns a new instance of PutSpecialObject.



4720
4721
4722
# File 'lib/syntax_tree/yarv/instructions.rb', line 4720

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



4718
4719
4720
# File 'lib/syntax_tree/yarv/instructions.rb', line 4718

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



4736
4737
4738
# File 'lib/syntax_tree/yarv/instructions.rb', line 4736

def ==(other)
  other.is_a?(PutSpecialObject) && other.object == object
end

#call(vm) ⇒ Object



4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
# File 'lib/syntax_tree/yarv/instructions.rb', line 4748

def call(vm)
  case object
  when OBJECT_VMCORE
    vm.push(vm.frozen_core)
  when OBJECT_CBASE
    value = vm.frame._self
    value = value.singleton_class unless value.is_a?(Class)
    vm.push(value)
  when OBJECT_CONST_BASE
    vm.push(vm.const_base)
  end
end

#deconstruct_keys(_keys) ⇒ Object



4732
4733
4734
# File 'lib/syntax_tree/yarv/instructions.rb', line 4732

def deconstruct_keys(_keys)
  { object: object }
end

#disasm(fmt) ⇒ Object



4724
4725
4726
# File 'lib/syntax_tree/yarv/instructions.rb', line 4724

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

#lengthObject



4740
4741
4742
# File 'lib/syntax_tree/yarv/instructions.rb', line 4740

def length
  2
end

#pushesObject



4744
4745
4746
# File 'lib/syntax_tree/yarv/instructions.rb', line 4744

def pushes
  1
end

#to_a(_iseq) ⇒ Object



4728
4729
4730
# File 'lib/syntax_tree/yarv/instructions.rb', line 4728

def to_a(_iseq)
  [:putspecialobject, object]
end