def visit_Bloc(self, node): bname = pyc_gen_name.new("bloc") new_bd = BlocDef( name = bname, body = node.body, params = [var_ref("fvs")] + node.args.args ) pyc_lineage.bequeath_lineage(node, new_bd, self.__class__.__name__) (def_node, d) = pyc_vis.visit( self, new_bd ) self.log(self.depth_fmt("bloc vars: %r" % d["bloc_vars"])) locals = pyc_localize.locals(node) self.log(self.depth_fmt("locals: %r" % locals)) #note: the params which were heapified will have their normal #name in this params set, and their heapified versions are initialized #as a local to the value of the non-heap param params = set(pyc_astvisitor.names(node.args)) | set(["fvs"]) self.log(self.depth_fmt("params: %r" % params)) d["free_vars"] = (d["free_vars"] | d["bloc_vars"]) - locals - params self.log(self.depth_fmt("free vars: %r" % d["free_vars"])) def_node.fvs = list(d["free_vars"]) fvs_inits = [] for i in range(0, len(def_node.fvs)): assign = make_assign( var_set(def_node.fvs[i]), #is it ok to use a canonical name for fvs? make_subn("fvs", ast.Load, i) ) pyc_lineage.bequeath_lineage(node, assign, self.__class__.__name__) fvs_inits.append(pyc_ir.txform( assign, tracer=self.tracer )) def_node.body = fvs_inits + def_node.body d["defs"].append(def_node) d["bloc_vars"] = set([]) return ( InjectFromBig(arg=CreateClosure( name = bname, #dont set tracer in this txform b.c. self.tracer will run on this tree free_vars = pyc_ir.txform( ast.List( elts = [var_ref(x) for x in def_node.fvs], ctx = ast.Load() ) ) )), d )
def visit_Bloc(self, node, heap_vars, dummy): locals = pyc_localize.locals(node) self.log(self.depth_fmt("locals: %r" % locals) ) prms = pyc_astvisitor.names(node.args) self.log(self.depth_fmt("params: %r" % prms) ) result_body = [ pyc_vis.visit(self, n, heap_vars, locals) for n in node.body ] #pass all params for locals and empty heap_vars #because none of the fn arg references should be "heapified" #because we copy those into new heapified vars before the function body. #due to above pyc_vis call, all references to these parameters will #have been converted to the new heapified version we will initialize #after we patch the lambda nodes result_args = pyc_vis.visit(self, node.args, {}, prms ) inits = self.init_local_heap_vars(locals, prms, heap_vars) return Bloc( args = result_args, body = inits + result_body )