Beispiel #1
0
def macrorules(*rules):
    result = []
    for rule in rules:
        head = tuple(element(x) for x in rule[0])
        body = begin(*(element(x) for x in rule[1:]))
        result.append((head, body))
    return MacroRules(result)
Beispiel #2
0
def macrorules(*rules):
  result = []
  for rule in rules:
    head = tuple(element(x) for x in rule[0])
    body = begin(*(element(x) for x in rule[1:]))
    result.append((head, body))
  return MacroRules(result)
Beispiel #3
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 #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 begin(*exps):
    exps = tuple(element(e) for e in exps)
    if len(exps) == 1: return exps[0]
    else:
        result = []
        for exp in exps:
            if isinstance(exp, SpecialCall) and exp.command is Begin:
                result += list(exp.args)
            else:
                result.append(exp)
        return Begin(*result)
Beispiel #6
0
def begin(*exps):
  exps = tuple(element(e) for e in exps)
  if len(exps)==1: return exps[0]
  else:
    result = []
    for exp in exps:
      if isinstance(exp, SpecialCall) and exp.command is Begin:
        result += list(exp.args)
      else:
        result.append(exp)
    return Begin(*result)        
Beispiel #7
0
def unquote_splice(item):
  return UnquoteSplice(element(item))
Beispiel #8
0
def letrec(bindings, *body):
  return Letrec(tuple((element(var), element(value)) for var, value in bindings), 
                begin(*tuple(element(exp) for exp in body)))
Beispiel #9
0
def let(bindings, *body):
  bindings = tuple((var, element(value)) for var, value in bindings)
  return Let(bindings, begin(*body))
Beispiel #10
0
def lamda(params, *body):
  body = tuple(element(x) for x in body)
  return Lamda(params, begin(*body))
Beispiel #11
0
def exit_block(label=NONE, value=NONE):
  return ExitBlock(element(label), element(value))
Beispiel #12
0
def block(label, *exps):
  return Block(label, begin(*tuple(element(x) for x in exps)))
Beispiel #13
0
def let(bindings, *body):
    bindings = tuple((var, element(value)) for var, value in bindings)
    return Let(bindings, begin(*body))
Beispiel #14
0
def continue_block(label=NONE):
  return ContinueBlock(element(label))
Beispiel #15
0
def quasiquote(item):
  return Quasiquote(element(item))
Beispiel #16
0
def lamda(params, *body):
    body = tuple(element(x) for x in body)
    return Lamda(params, begin(*body))
Beispiel #17
0
def continue_block(label=NONE):
    return ContinueBlock(element(label))
Beispiel #18
0
def exit_block(label=NONE, value=NONE):
    return ExitBlock(element(label), element(value))
Beispiel #19
0
 def __call__(self, *args):
     return Apply(self, tuple(element(arg) for arg in args))
Beispiel #20
0
def macro(params, *body):
    body = tuple(element(x) for x in body)
    return Macro(params, begin(*body))
Beispiel #21
0
def macro(params, *body):
  body = tuple(element(x) for x in body)
  return Macro(params, begin(*body))
Beispiel #22
0
 def __call__(self, *args):
   return Apply(self, tuple(element(arg) for arg in args))
Beispiel #23
0
def letrec(bindings, *body):
    return Letrec(
        tuple((element(var), element(value)) for var, value in bindings), begin(*tuple(element(exp) for exp in body))
    )
Beispiel #24
0
def block(label, *exps):
    return Block(label, begin(*tuple(element(x) for x in exps)))
Beispiel #25
0
def unquote(item):
  return Unquote(element(item))