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.



5850
5851
5852
5853
# File 'lib/syntax_tree/yarv/instructions.rb', line 5850

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

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



5848
5849
5850
# File 'lib/syntax_tree/yarv/instructions.rb', line 5848

def length
  @length
end

#optionsObject (readonly)

Returns the value of attribute options.



5848
5849
5850
# File 'lib/syntax_tree/yarv/instructions.rb', line 5848

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



5867
5868
5869
5870
# File 'lib/syntax_tree/yarv/instructions.rb', line 5867

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

#call(vm) ⇒ Object



5880
5881
5882
# File 'lib/syntax_tree/yarv/instructions.rb', line 5880

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

#deconstruct_keys(_keys) ⇒ Object



5863
5864
5865
# File 'lib/syntax_tree/yarv/instructions.rb', line 5863

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

#disasm(fmt) ⇒ Object



5855
5856
5857
# File 'lib/syntax_tree/yarv/instructions.rb', line 5855

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

#popsObject



5872
5873
5874
# File 'lib/syntax_tree/yarv/instructions.rb', line 5872

def pops
  length
end

#pushesObject



5876
5877
5878
# File 'lib/syntax_tree/yarv/instructions.rb', line 5876

def pushes
  1
end

#to_a(_iseq) ⇒ Object



5859
5860
5861
# File 'lib/syntax_tree/yarv/instructions.rb', line 5859

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