lispytree.py 文件源码

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

项目:femtocode 作者: diana-hep 项目源码 文件源码
def build(fcn, args, original=None):
        if all(isinstance(x, Literal) for x in args):
            empty = SymbolTable()
            schema, typedargs, subempty = fcn.buildtyped(args, empty)
            if isinstance(schema, Impossible):
                if schema.reason is not None:
                    reason = "\n\n    " + schema.reason
                else:
                    reason = ""
                complain("Function \"{0}\" does not accept arguments with the given literal types:\n\n    {0}({1}){2}".format(fcn.name, ",\n    {0} ".format(" " * len(fcn.name)).join(pretty(x.schema, prefix="     " + " " * len(fcn.name)).lstrip() for x in typedargs), reason), original)
            else:
                return Literal(fcn.pythoneval([x.value for x in args]), original)

        else:
            if fcn.associative:
                newargs = []
                for arg in args:
                    if isinstance(arg, Call) and arg.fcn == fcn:
                        newargs.extend(arg.args)
                    else:
                        newargs.append(arg)
            else:
                newargs = args

            return Call(fcn, newargs, original)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号