Beispiel #1
0
def compile_optimize(exp):
  compiler = Compiler()
  exp = il.element(exp).alpha(Environment(), compiler)
  exp = exp.cps(compiler, done())
  env = Environment()
  compiler.lamda_stack = [exp]
  exp.analyse(compiler)
  return exp.optimize(env, compiler)
Beispiel #2
0
def compile_optimize(exp):
    compiler = Compiler()
    exp = il.element(exp).alpha(Environment(), compiler)
    exp = exp.cps(compiler, done())
    env = Environment()
    compiler.lamda_stack = [exp]
    exp.analyse(compiler)
    return exp.optimize(env, compiler)
Beispiel #3
0
def compile(exp):
    compiler = Compiler()
    exp = il.element(exp).cps(compiler, done())
    env = Environment()
    exp = exp.optimize(env, compiler)
    exps, has_statement = exp.pythonize(Environment(), compiler)
    compiler = Compiler()
    return begin(*exps).to_code(compiler)
Beispiel #4
0
def compile_to_python(exp, env, done=None):
    '''assemble steps from dao expression to python code'''
    original_exp = exp
    compiler = Compiler()
    if done is None:
        done = il.Done(compiler.new_var(il.ConstLocalVar('v')))
    compiler.exit_block_cont_map = {}
    compiler.continue_block_cont_map = {}
    compiler.protect_cont = done
    if env is None: env = Environment()
    exp = element(exp)
    exp = exp.alpha(env, compiler)
    exp = exp.cps(compiler, done)
    exp.analyse(compiler)
    env = Environment()
    exp = exp.optimize(env, compiler)
    #exp = exp.tail_recursive_convert()
    function = compiler.new_var(il.ConstLocalVar('compiled_dao_function'))
    exp = il.Function(function, (), exp)
    exp = il.begin(*exp.pythonize(env, compiler)[0])
    if isinstance(exp, il.Begin):
        exp = exp.statements[0]
    exp.body = exp.body.replace_return_with_yield()
    compiler = Compiler()
    result = exp.to_code(compiler)
    return prelude + result
Beispiel #5
0
def compile_to_python(exp, env, done=None): 
  '''assemble steps from dao expression to python code'''
  original_exp = exp
  compiler = Compiler()
  if done is None:
    done = il.Done(compiler.new_var(il.ConstLocalVar('v')))
  compiler.exit_block_cont_map = {}
  compiler.continue_block_cont_map = {}
  compiler.protect_cont = done
  if env is None: env = Environment()
  exp = element(exp)
  exp = exp.alpha(env, compiler)
  exp = exp.cps(compiler, done)
  exp.analyse(compiler)
  env = Environment()
  exp = exp.optimize(env, compiler)
  #exp = exp.tail_recursive_convert()
  function = compiler.new_var(il.ConstLocalVar('compiled_dao_function'))
  exp = il.Function(function, (), exp)
  exp = il.begin(*exp.pythonize(env, compiler)[0])
  if isinstance(exp, il.Begin):
    exp = exp.statements[0]
  exp.body = exp.body.replace_return_with_yield()
  compiler = Compiler()
  result = exp.to_code(compiler)
  return prelude + result
Beispiel #6
0
def cps(exp):
    return il.element(exp).cps(Compiler(), done())
Beispiel #7
0
def optimize(exp):
    compiler = Compiler()
    env = Environment()
    compiler.lamda_stack = [exp]
    exp.analyse(compiler)
    return exp.optimize(env, compiler)
Beispiel #8
0
def alpha(exp):
    env = Environment()
    compiler = Compiler()
    return exp.alpha(env, compiler)
Beispiel #9
0
def optimize(exp):
  compiler = Compiler()
  env = Environment()
  compiler.lamda_stack = [exp]
  exp.analyse(compiler)
  return exp.optimize(env, compiler)
Beispiel #10
0
def generate_code(exp):
    exps, has_statement = il.element(exp).pythonize(Environment(), Compiler())
    compiler = Compiler()
    return begin(*exps).to_code(compiler)