Class: SyntaxTree::YARV::CheckMatch
- Inherits:
-
Object
- Object
- SyntaxTree::YARV::CheckMatch
- Defined in:
- lib/syntax_tree/yarv/instructions.rb
Overview
### Summary
checkmatch checks if the current pattern matches the current value. It pops the target and the pattern off the stack and pushes a boolean onto the stack if it matches or not.
### Usage
~~~ruby foo in Foo ~~~
Constant Summary collapse
- VM_CHECKMATCH_TYPE_WHEN =
1- VM_CHECKMATCH_TYPE_CASE =
2- VM_CHECKMATCH_TYPE_RESCUE =
3- VM_CHECKMATCH_TYPE_MASK =
0x03- VM_CHECKMATCH_ARRAY =
0x04
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #call(vm) ⇒ Object
- #canonical ⇒ Object
- #disasm(fmt) ⇒ Object
-
#initialize(type) ⇒ CheckMatch
constructor
A new instance of CheckMatch.
- #length ⇒ Object
- #pops ⇒ Object
- #pushes ⇒ Object
- #to_a(_iseq) ⇒ Object
Constructor Details
#initialize(type) ⇒ CheckMatch
410 411 412 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 410 def initialize(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
408 409 410 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 408 def type @type end |
Instance Method Details
#call(vm) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 438 def call(vm) target, pattern = vm.pop(2) vm.push( if type & VM_CHECKMATCH_ARRAY > 0 pattern.any? { |item| check?(item, target) } else check?(pattern, target) end ) end |
#canonical ⇒ Object
434 435 436 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 434 def canonical self end |
#disasm(fmt) ⇒ Object
414 415 416 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 414 def disasm(fmt) fmt.instruction("checkmatch", [fmt.object(type)]) end |
#length ⇒ Object
422 423 424 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 422 def length 2 end |
#pops ⇒ Object
426 427 428 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 426 def pops 2 end |
#pushes ⇒ Object
430 431 432 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 430 def pushes 1 end |
#to_a(_iseq) ⇒ Object
418 419 420 |
# File 'lib/syntax_tree/yarv/instructions.rb', line 418 def to_a(_iseq) [:checkmatch, type] end |