Exemplo n.º 1
0
    def run(self, func_or_ast, pyx_header):
        self.__pyx_header = pyx_header

        # we already has a AST: just run it
        if isinstance(func_or_ast, ast.AST):
            cyast = self.visit(func_or_ast)
        else:
            check_argument(isinstance(func_or_ast, types.FunctionType))
            # ignore varargs and keywords
            self.__func_params_name_list = inspect.getfullargspec(func_or_ast).args
            self.__globals = func_or_ast.__globals__
            cyast = self.parse(inspect.getsource(func_or_ast))

        writer = patch_cython_codewriter(CodeWriter())
        cycode = "\n".join(writer.write(cyast).lines)
        return cycode
Exemplo n.º 2
0
 def codeToLines(self, tree):
     writer = CodeWriter()
     writer.write(tree)
     return writer.result.lines
Exemplo n.º 3
0
 def compile(self, source):
     """Compile source into cython code."""
     cyast = self.parse(source)
     writer = patch_cython_codewriter(CodeWriter())
     return "\n".join(writer.write(cyast).lines)