def visit_Assign(self, node): if isinstance(node.nodes[0], AssAttr): # explicate the expression on the assign expr = self.visit(node.expr) # explicate the expression on assignment attribute attrexpr = self.visit(node.nodes[0].expr) return Discard(CallFunc(Name('set_attr'),[attrexpr, Const(node.nodes[0].attrname), expr])) else: return P2Explicate.visit_Assign(self, node)
def visit_Assign(self, node): if isinstance(node.nodes[0], AssAttr): # explicate the expression on the assign expr = self.visit(node.expr) # explicate the expression on assignment attribute attrexpr = self.visit(node.nodes[0].expr) return Discard( CallFunc( Name('set_attr'), [attrexpr, Const(node.nodes[0].attrname), expr])) else: return P2Explicate.visit_Assign(self, node)
def __init__(self, varalloc, handleLambdas=True): P2Explicate.__init__(self, varalloc, handleLambdas)
def __init__(self, explicate): self.log = logging.getLogger('compiler.heapify') self.explicate = P2Explicate(explicate.varalloc, False) self.freevars = P2FreeVars() self.heapvarset = set([])
v = self.visit(node.code) # Return our new lambda with the new set of argument names, and paramAllocs, paramInits, and localAllocs # prepended to the list of statements. return Lambda(argnames, node.defaults, node.flags, Stmt(paramAllocs + paramInits + localAllocs + v.nodes)) def visit_CallFuncIndirect(self, node): return CallFuncIndirect(self.visit(node.node), [self.visit(x) for x in node.args]) if __name__ == "__main__": import sys, compiler import logging.config if len(sys.argv) < 2: sys.exit(1) # configure logging logging.config.fileConfig('logging.cfg') testcases = sys.argv[1:] for testcase in testcases: p2unique = P2UniquifyVars() p2explicator = P2Explicate(VariableAllocator()) p2heap = P2Heapify(p2explicator) ast = compiler.parseFile(testcase) unique = p2unique.transform(ast) explicated = p2explicator.explicate(unique) ast = p2heap.transform(explicated) print prettyAST(ast) #print ast
import sys, compiler from p2uniquifyvars import P2UniquifyVars from p2explicate import P2Explicate from p2heapify import P2Heapify from p2closureconvert import P2ClosureConversion from p2flattener import P2Flattener from p2insselector import P2InstructionSelector from p2regallocator import P2RegAllocator from p2ifinsselector import P2IfInstructionSelector if len(sys.argv) < 2: sys.exit(1) testcases = sys.argv[1:] for testcase in testcases: varalloc = VariableAllocator() p2unique = P2UniquifyVars() p2explicator = P2Explicate(varalloc) p2heap = P2Heapify(p2explicator) p2closure = P2ClosureConversion(p2explicator, varalloc) p2flatten = P2Flattener(varalloc) p2insselector = P2InstructionSelector(varalloc) ifinsselector = P2IfInstructionSelector(varalloc, p2insselector.labelalloc) ast = compiler.parseFile(testcase) unique = p2unique.transform(ast) explicated = p2explicator.explicate(unique) heaped = p2heap.transform(explicated) astlist = p2closure.transform(heaped) for ast in astlist: ast = p2flatten.flatten(ast) program = p2insselector.transform(ast)