Class: SyntaxTree::YARV::ToRegExp

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

Overview

### Summary

‘toregexp` pops a number of values off the stack, combines them into a new regular expression, and pushes the new regular expression onto the stack.

### Usage

~~~ruby /foo #bar/ ~~~

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instruction

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

Constructor Details

#initialize(options, length) ⇒ ToRegExp

Returns a new instance of ToRegExp.



5691
5692
5693
5694
# File 'lib/syntax_tree/yarv/instructions.rb', line 5691

def initialize(options, length)
  @options = options
  @length = length
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



5689
5690
5691
# File 'lib/syntax_tree/yarv/instructions.rb', line 5689

def length
  @length
end

#optionsObject (readonly)

Returns the value of attribute options.



5689
5690
5691
# File 'lib/syntax_tree/yarv/instructions.rb', line 5689

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



5708
5709
5710
5711
# File 'lib/syntax_tree/yarv/instructions.rb', line 5708

def ==(other)
  other.is_a?(ToRegExp) && other.options == options &&
    other.length == length
end

#call(vm) ⇒ Object



5721
5722
5723
# File 'lib/syntax_tree/yarv/instructions.rb', line 5721

def call(vm)
  vm.push(Regexp.new(vm.pop(length).join, options))
end

#deconstruct_keys(_keys) ⇒ Object



5704
5705
5706
# File 'lib/syntax_tree/yarv/instructions.rb', line 5704

def deconstruct_keys(_keys)
  { options: options, length: length }
end

#disasm(fmt) ⇒ Object



5696
5697
5698
# File 'lib/syntax_tree/yarv/instructions.rb', line 5696

def disasm(fmt)
  fmt.instruction("toregexp", [fmt.object(options), fmt.object(length)])
end

#popsObject



5713
5714
5715
# File 'lib/syntax_tree/yarv/instructions.rb', line 5713

def pops
  length
end

#pushesObject



5717
5718
5719
# File 'lib/syntax_tree/yarv/instructions.rb', line 5717

def pushes
  1
end

#to_a(_iseq) ⇒ Object



5700
5701
5702
# File 'lib/syntax_tree/yarv/instructions.rb', line 5700

def to_a(_iseq)
  [:toregexp, options, length]
end