Sha256: a60927a39742ce8ff96a50a157f65d2600c925971e47c802691693e94edd9d82

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

module Alf
  class Compiler

    def supports_reuse?
      false
    end

    def join(plan)
      nil
    end

    def call(expr)
      Plan.new(self).compile(expr)
    end

    def compile(plan, expr, compiled, usage_count)
      send(to_method_name(expr), plan, expr, *compiled)
    end

    def on_leaf_operand(plan, expr)
      expr.to_cog(plan)
    end

    def on_shortcut(plan, expr, *compiled)
      plan.__compile{|p| expr.expand }
    end

    def on_missing(plan, expr, *compiled)
      raise NotSupportedError, "Unable to compile `#{expr}` (#{self})"
    end

    def on_unsupported(plan, expr, *args)
      raise NotSupportedError, "Unsupported expression `#{expr}`"
    end

  private

    def to_method_name(expr)
      case expr
      when Algebra::Operator
        name = expr.class.rubycase_name
        meth = :"on_#{name}"
        meth = :"on_shortcut" if expr.is_a?(Algebra::Shortcut) and !respond_to?(meth)
        meth = :"on_missing"  if !respond_to?(meth)
        meth
      when Algebra::Operand
        :on_leaf_operand
      else
        :on_unsupported
      end
    end

  end # class Compiler
end # module Alf
require_relative 'compiler/plan'
require_relative 'compiler/cog'
require_relative 'compiler/default'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/compiler.rb
alf-core-0.16.2 lib/alf/compiler.rb
alf-core-0.16.1 lib/alf/compiler.rb
alf-core-0.16.0 lib/alf/compiler.rb