class SyntaxTree::YARV::CheckType
~~~
foo in [bar]
~~~ruby
### Usage
given type.
a boolean onto the stack indicating whether or not the value is of the
The type is the only argument. It pops the value off the stack and pushes
`checktype` checks if the value on top of the stack is of a certain type.
### Summary
def ==(other)
def ==(other) other.is_a?(CheckType) && other.type == type end
def call(vm)
def call(vm) object = vm.pop result = case type when TYPE_OBJECT raise NotImplementedError, "checktype TYPE_OBJECT" when TYPE_CLASS object.is_a?(Class) when TYPE_MODULE object.is_a?(Module) when TYPE_FLOAT object.is_a?(Float) when TYPE_STRING object.is_a?(String) when TYPE_REGEXP object.is_a?(Regexp) when TYPE_ARRAY object.is_a?(Array) when TYPE_HASH object.is_a?(Hash) when TYPE_STRUCT object.is_a?(Struct) when TYPE_BIGNUM raise NotImplementedError, "checktype TYPE_BIGNUM" when TYPE_FILE object.is_a?(File) when TYPE_DATA raise NotImplementedError, "checktype TYPE_DATA" when TYPE_MATCH raise NotImplementedError, "checktype TYPE_MATCH" when TYPE_COMPLEX object.is_a?(Complex) when TYPE_RATIONAL object.is_a?(Rational) when TYPE_NIL object.nil? when TYPE_TRUE object == true when TYPE_FALSE object == false when TYPE_SYMBOL object.is_a?(Symbol) when TYPE_FIXNUM object.is_a?(Integer) when TYPE_UNDEF raise NotImplementedError, "checktype TYPE_UNDEF" end vm.push(result) end
def deconstruct_keys(_keys)
def deconstruct_keys(_keys) { type: type } end
def disasm(fmt)
def disasm(fmt) name = case type when TYPE_OBJECT "T_OBJECT" when TYPE_CLASS "T_CLASS" when TYPE_MODULE "T_MODULE" when TYPE_FLOAT "T_FLOAT" when TYPE_STRING "T_STRING" when TYPE_REGEXP "T_REGEXP" when TYPE_ARRAY "T_ARRAY" when TYPE_HASH "T_HASH" when TYPE_STRUCT "T_STRUCT" when TYPE_BIGNUM "T_BIGNUM" when TYPE_FILE "T_FILE" when TYPE_DATA "T_DATA" when TYPE_MATCH "T_MATCH" when TYPE_COMPLEX "T_COMPLEX" when TYPE_RATIONAL "T_RATIONAL" when TYPE_NIL "T_NIL" when TYPE_TRUE "T_TRUE" when TYPE_FALSE "T_FALSE" when TYPE_SYMBOL "T_SYMBOL" when TYPE_FIXNUM "T_FIXNUM" when TYPE_UNDEF "T_UNDEF" end fmt.instruction("checktype", [name]) end
def initialize(type)
def initialize(type) @type = type end
def length
def length 2 end
def pops
def pops 1 end
def pushes
def pushes # TODO: This is incorrect. The instruction only pushes a single value # onto the stack. However, if this is set to 1, we no longer match the # output of RubyVM::InstructionSequence. So leaving this here until we # can investigate further. 2 end
def to_a(_iseq)
def to_a(_iseq) [:checktype, type] end