Class: SyntaxTree::YARV::PutSpecialObject

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

Constructor Details

#initialize(object) ⇒ PutSpecialObject

Returns a new instance of PutSpecialObject.



5038
5039
5040
# File 'lib/syntax_tree/yarv/instructions.rb', line 5038

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



5036
5037
5038
# File 'lib/syntax_tree/yarv/instructions.rb', line 5036

def object
  @object
end

Instance Method Details

#==(other) ⇒ Object



5054
5055
5056
# File 'lib/syntax_tree/yarv/instructions.rb', line 5054

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

#call(vm) ⇒ Object



5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
# File 'lib/syntax_tree/yarv/instructions.rb', line 5074

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

#canonicalObject



5070
5071
5072
# File 'lib/syntax_tree/yarv/instructions.rb', line 5070

def canonical
  self
end

#deconstruct_keys(_keys) ⇒ Object



5050
5051
5052
# File 'lib/syntax_tree/yarv/instructions.rb', line 5050

def deconstruct_keys(_keys)
  { object: object }
end

#disasm(fmt) ⇒ Object



5042
5043
5044
# File 'lib/syntax_tree/yarv/instructions.rb', line 5042

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

#lengthObject



5058
5059
5060
# File 'lib/syntax_tree/yarv/instructions.rb', line 5058

def length
  2
end

#popsObject



5062
5063
5064
# File 'lib/syntax_tree/yarv/instructions.rb', line 5062

def pops
  0
end

#pushesObject



5066
5067
5068
# File 'lib/syntax_tree/yarv/instructions.rb', line 5066

def pushes
  1
end

#to_a(_iseq) ⇒ Object



5046
5047
5048
# File 'lib/syntax_tree/yarv/instructions.rb', line 5046

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