class Bpl::Abstraction

Public Instance Methods

each_abstraction(program) click to toggle source
# File lib/bpl/passes/transformation/abstraction.rb, line 257
def each_abstraction(program)
  Enumerator.new do |y|
    program.each do |elem|
      elem.abstractions.each do |abs|
        y.yield(abs[:elems] ? abs : abs.merge({elems: [elem]}))
      end
    end
  end
end
run!(program) click to toggle source
# File lib/bpl/passes/transformation/abstraction.rb, line 267
def run! program

  # Just return the number of abstractable elements (?)
  if index =~ /count/
    n = each_abstraction(program).count
    program.each_child(&:remove)
    program.append_children(:declarations, bpl("assume {:count #{n}} true;"))
  end

  break_at_index = index ? [index.to_i,0].max : rand(1000)

  each_abstraction(program).sort{|a,b| a[:weight] <=> b[:weight]}.reverse.
  cycle.each_with_index do |abs,idx|
    if idx == break_at_index
      info "ABSTRACTION * #{abs[:description]} (weight=#{abs[:weight]})"
      abs[:elems].each do |elem|
        info
        info Printing.indent(elem.to_s).indent
      end
      info
      abs[:action].call
      invalidates :all
      break
    end
  end

end