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, #compile, #execute, #rest?

Constructor Details

#initialize(pats, op_str) ⇒ LogicalOp

Returns a new instance of LogicalOp.



214
215
216
217
# File 'lib/patm.rb', line 214

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

Instance Method Details

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



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/patm.rb', line 218

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)
    srcs << s
    ctxs << c
  end

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