lispytree.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:femtocode 作者: diana-hep 项目源码 文件源码
def pythoneval(self, args, debug=False):
        refs = [ast.Name("x{0}".format(i), ast.Load()) for i in xrange(len(args))]
        if sys.version_info[0] <= 2:
            params = ast.arguments([ast.Name("x{0}".format(i), ast.Param()) for i in xrange(len(args))], None, None, [])
            fcn = ast.FunctionDef("tmp", params, [ast.Return(self.pythonast(refs))], [])
        else:
            params = ast.arguments([ast.arg("x{0}".format(i), None) for i in xrange(len(args))], None, [], [], None, [])
            fcn = ast.FunctionDef("tmp", params, [ast.Return(self.pythonast(refs))], [], None)

        moduleast = ast.Module([fcn])
        fakeLineNumbers(moduleast)

        if debug:
            print(astToSource(fcn))

        modulecomp = compile(moduleast, "Femtocode", "exec")
        out = {"$importlib": importlib, "$math": math}
        exec(modulecomp, out)

        return out["tmp"](*args)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号