Class: SyntaxTree::YARV::CheckType
Overview
### Summary
‘checktype` checks if the value on top of the stack is of a certain type. The type is the only argument. It pops the value off the stack and pushes a boolean onto the stack indicating whether or not the value is of the given type.
### Usage
~~~ruby foo in [bar] ~~~
Constant Summary
collapse
- TYPE_OBJECT =
0x01
- TYPE_CLASS =
0x02
- TYPE_MODULE =
0x03
- TYPE_FLOAT =
0x04
- TYPE_STRING =
0x05
- TYPE_REGEXP =
0x06
- TYPE_ARRAY =
0x07
- TYPE_HASH =
0x08
- TYPE_STRUCT =
0x09
- TYPE_BIGNUM =
0x0a
- TYPE_FILE =
0x0b
- TYPE_DATA =
0x0c
- TYPE_MATCH =
0x0d
- TYPE_COMPLEX =
0x0e
- TYPE_RATIONAL =
0x0f
- TYPE_NIL =
0x11
- TYPE_TRUE =
0x12
- TYPE_FALSE =
0x13
- TYPE_SYMBOL =
0x14
- TYPE_FIXNUM =
0x15
- TYPE_UNDEF =
0x16
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Instruction
#branch_targets, #canonical, #falls_through?, #leaves?, #side_effects?
Constructor Details
#initialize(type) ⇒ CheckType
Returns a new instance of CheckType.
526
527
528
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 526
def initialize(type)
@type = type
end
|
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
524
525
526
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 524
def type
@type
end
|
Instance Method Details
#==(other) ⇒ Object
588
589
590
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 588
def ==(other)
other.is_a?(CheckType) && other.type == type
end
|
#call(vm) ⇒ Object
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 608
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
|
#deconstruct_keys(_keys) ⇒ Object
584
585
586
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 584
def deconstruct_keys(_keys)
{ type: type }
end
|
#length ⇒ Object
592
593
594
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 592
def length
2
end
|
#pops ⇒ Object
596
597
598
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 596
def pops
1
end
|
#pushes ⇒ Object
600
601
602
603
604
605
606
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 600
def pushes
2
end
|
#to_a(_iseq) ⇒ Object
580
581
582
|
# File 'lib/syntax_tree/yarv/instructions.rb', line 580
def to_a(_iseq)
[:checktype, type]
end
|