standard.py 文件源码

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

项目:femtocode 作者: diana-hep 项目源码 文件源码
def buildexec(self, target, schema, args, argschemas, newname, references, tonative):
        predicates = args[:-1][0::3]
        antipredicates = args[:-1][1::3]
        consequents = args[:-1][2::3]
        alternate = args[-1]

        def isNone(expression):
            if sys.version_info[0] <= 2:
                return isinstance(expression, ast.Name) and expression.id == "None" and isinstance(expression.ctx, ast.Load)
            else:
                return isinstance(expression, ast.NameConstant) and expression.value is None

        def replaceNone(expression):
            return expression

        if isNullInt(schema):
            def replaceNone(expression):
                if isNone(expression):
                    return ast.Num(Number._intNaN)
                else:
                    return expression

        elif isNullFloat(schema):
            def replaceNone(expression):
                if isNone(expression):
                    return ast.Num(Number._floatNaN)
                else:
                    return expression

        chain = statementsToAst("""
            OUT = ALT
            """, OUT = target, ALT = replaceNone(alternate))

        for predicate, consequent in reversed(list(zip(predicates, consequents))):
            next = statementsToAst("""
                if PRED:
                    OUT = CONS
                else:
                    REPLACEME
                """, OUT = target, PRED = predicate, CONS = replaceNone(consequent))

            next[0].orelse = [chain[0]]   # replacing REPLACEME
            chain = next

        return chain
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号