def patch_lamb_nodes(self): log("patch lamb nodes:") for expr in self.lamb_nodes: new_val = expr.value.lamb() pyc_lineage.bequeath_lineage(expr.value.from_node, new_val, self.__class__.__name__) expr.value = new_val log(" ->%s" % ast.dump(expr.value))
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 )