Class: Patm::Pattern::LogicalOp

Inherits:
Patm::Pattern show all
Defined in:
lib/patm.rb

Direct Known Subclasses

And, Or

Instance Method Summary collapse

Methods inherited from Patm::Pattern

#&, #[], build_from, build_from_array, build_from_hash, #compile, #execute, #opt

Constructor Details

#initialize(name, pats, op_str) ⇒ LogicalOp

Returns a new instance of LogicalOp.



439
440
441
442
443
# File 'lib/patm.rb', line 439

def initialize(name, pats, op_str)
  @name = name
  @pats = pats
  @op_str = op_str
end

Instance Method Details

#compile_internal(free_index, target_name = "_obj") ⇒ Object



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/patm.rb', line 444

def compile_internal(free_index, target_name = "_obj")
  srcs = []
  i = free_index
  ctxs = []
  @pats.each do|pat|
    s, c, i = pat.compile_internal(i, target_name)
    if !s && @op_str == '||' # dirty...
      srcs << 'true'
    else
      srcs << s
    end
    ctxs << c
  end

  [
    srcs.compact.map{|s| "(#{s})" }.join(" #{@op_str}\n"),
    ctxs.flatten(1),
    i
  ]
end

#inspectObject



470
471
472
# File 'lib/patm.rb', line 470

def inspect
  "#{@name}(#{@pats.map(&:inspect).join(',')})"
end

#opt?Boolean

Returns:

  • (Boolean)


467
468
469
# File 'lib/patm.rb', line 467

def opt?
  @pats.any?(&:opt?)
end

#rest?Boolean

Returns:

  • (Boolean)


464
465
466
# File 'lib/patm.rb', line 464

def rest?
  @pats.any?(&:rest?)
end