Exemple #1
0
 def execute(self, code, arguments, inputs, record_trace=True):
     arguments = [(arg, code_types.str_to_type(tp))
                  for arg, tp in arguments.items()]
     if data.is_flat_code(code):
         try:
             code, _ = data.unflatten_code(code, 'lisp')
         except:
             return ExecutionResult(None, None)
     try:
         code_lisp.test_lisp_validity(self.lisp_units, code,
                                      dict(arguments), code_types.Type.T)
     except (ValueError, KeyError, TypeError):
         return ExecutionResult(None, None)
     t = code_trace.CodeTrace() if record_trace else None
     func = code_lisp.compile_func(self.lisp_units,
                                   'main',
                                   code,
                                   arguments,
                                   code_types.Type.T,
                                   trace=t)
     try:
         result = func(*[inputs[arg] for arg, _ in arguments])
     except Exception:
         raise ExecutorRuntimeException()
     return ExecutionResult(result, t)
Exemple #2
0
 def format_code(self, tree, seq, lang):
     if tree is not None:
         return data.format_code(tree, lang)
     else:
         try:
             tree, complete = data.unflatten_code(seq, lang)
         except:
             complete = False
         if complete:
             return data.format_code(tree, lang)
         return ' '.join(seq)
Exemple #3
0
def seq_to_tree(seq):
    #from algolisp code
    code, _ = data.unflatten_code(seq, 'lisp')
    return code