コード例 #1
0
ファイル: typeinference.py プロジェクト: dsheffie/TFJ
 def record_bindings(body):
     for binding in select(body, AST.Bind):
         for x in select(AST.walk(binding.binder()), AST.Name):
             localtypes[x.id] = x.type
     for cond in select(body, AST.Cond):
         for cbody in cond.parameters[1:]:
             record_bindings(cbody)
コード例 #2
0
    def _Bind(self, ast):
        # Constraints produced by the RHS
        for c in self.visit_children(ast): yield c

        # Make binders in the LHS visible in the typing environment
        bindings = [(node.id, node.type) for node in AST.walk(ast.binder())
                                         if isinstance(node, AST.Name)]

        self.context.typings.update(dict(bindings))

        # Generate destructuring constraints (if any) in the LHS
        for c in self.visit(ast.binder()): yield c

        # XXX We only allow polymorphic bindings when the LHS is a
        #     single identifier.  Generalizing this would be nice but is
        #     fraught with peril if the RHS is not required to have a
        #     syntactically equivalent structure to the LHS.
        if isinstance(ast.binder(), AST.Name):
            M = self.context.monomorphs
            yield Generalizing(ast.binder().type, ast.value().type, M, ast)
        else:
            yield Equality(ast.binder().type, ast.value().type, ast)
コード例 #3
0
    def _Bind(self, ast):
        # Constraints produced by the RHS
        for c in self.visit_children(ast):
            yield c

        # Make binders in the LHS visible in the typing environment
        bindings = [(node.id, node.type) for node in AST.walk(ast.binder())
                    if isinstance(node, AST.Name)]

        self.context.typings.update(dict(bindings))

        # Generate destructuring constraints (if any) in the LHS
        for c in self.visit(ast.binder()):
            yield c

        # XXX We only allow polymorphic bindings when the LHS is a
        #     single identifier.  Generalizing this would be nice but is
        #     fraught with peril if the RHS is not required to have a
        #     syntactically equivalent structure to the LHS.
        if isinstance(ast.binder(), AST.Name):
            M = self.context.monomorphs
            yield Generalizing(ast.binder().type, ast.value().type, M, ast)
        else:
            yield Equality(ast.binder().type, ast.value().type, ast)
コード例 #4
0
 def _Bind(self, ast):
     self.rewrite_children(ast)
     binders = [v for v in S.walk(ast.binder()) if isinstance(v, S.Name)]
     self.locally_bound(binders)
     return ast
コード例 #5
0
ファイル: rewrites.py プロジェクト: zahangircse/copperhead
 def _Bind(self, ast):
     self.rewrite_children(ast)
     binders = [v for v in S.walk(ast.binder()) if isinstance(v, S.Name)]
     self.locally_bound(binders)
     return ast