Class: SyntaxTree::YARV::ToRegExp

Inherits:
Object
  • Object
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

Constructor Details

#initialize(options, length) ⇒ ToRegExp

Returns a new instance of ToRegExp.



5342
5343
5344
5345
# File 'lib/syntax_tree/yarv/instructions.rb', line 5342

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

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



5340
5341
5342
# File 'lib/syntax_tree/yarv/instructions.rb', line 5340

def length
  @length
end

#optionsObject (readonly)

Returns the value of attribute options.



5340
5341
5342
# File 'lib/syntax_tree/yarv/instructions.rb', line 5340

def options
  @options
end

Instance Method Details

#call(vm) ⇒ Object



5367
5368
5369
# File 'lib/syntax_tree/yarv/instructions.rb', line 5367

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

#canonicalObject



5363
5364
5365
# File 'lib/syntax_tree/yarv/instructions.rb', line 5363

def canonical
  self
end

#disasm(fmt) ⇒ Object



5347
5348
5349
# File 'lib/syntax_tree/yarv/instructions.rb', line 5347

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

#popsObject



5355
5356
5357
# File 'lib/syntax_tree/yarv/instructions.rb', line 5355

def pops
  length
end

#pushesObject



5359
5360
5361
# File 'lib/syntax_tree/yarv/instructions.rb', line 5359

def pushes
  1
end

#to_a(_iseq) ⇒ Object



5351
5352
5353
# File 'lib/syntax_tree/yarv/instructions.rb', line 5351

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