Class: Rubinius::ToolSet.current::TS::AST::Match2

Inherits:
Node
  • Object
show all
Defined in:
lib/rubinius/ast/control_flow.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#ascii_graph, #attributes, #children, #defined, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk

Constructor Details

#initialize(line, pattern, value) ⇒ Match2

Returns a new instance of Match2.



468
469
470
471
472
# File 'lib/rubinius/ast/control_flow.rb', line 468

def initialize(line, pattern, value)
  @line = line
  @pattern = pattern
  @value = value
end

Instance Attribute Details

#patternObject

Returns the value of attribute pattern.



466
467
468
# File 'lib/rubinius/ast/control_flow.rb', line 466

def pattern
  @pattern
end

#valueObject

Returns the value of attribute value.



466
467
468
# File 'lib/rubinius/ast/control_flow.rb', line 466

def value
  @value
end

Instance Method Details

#bytecode(g) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'lib/rubinius/ast/control_flow.rb', line 474

def bytecode(g)
  pos(g)

  @pattern.bytecode(g)
  @value.bytecode(g)
  g.send :=~, 1
  if @pattern.kind_of? RegexLiteral
    regexp = Regexp.new(@pattern.source)
    # TODO: this code cannot just use Rubinius-specific methods.
    # Fix without using respond_to?.
    if regexp.respond_to? :name_table
      if table = regexp.name_table
        table.sort_by { |name, idx| idx }.each do |name, idx|
          local = g.state.scope.new_local name
          g.last_match 5, idx.last - 1

          case local
          when Compiler::LocalVariable
            g.set_local local.slot
          when Compiler::EvalLocalVariable
            g.push_variables
            g.swap
            g.push_literal name
            g.swap
            g.send :set_eval_local, 2, false
          else
            raise CompileError, "unknown type of local #{local.inspect}"
          end

          g.pop
        end
      end
    end
  end
end

#to_sexpObject



510
511
512
# File 'lib/rubinius/ast/control_flow.rb', line 510

def to_sexp
  [:match2, @pattern.to_sexp, @value.to_sexp]
end