Beispiel #1
0
	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
		)
Beispiel #2
0
	def init_heap_var(self, hv, value):
		return make_assign(
			var_set(hv),
			pyc_ir.txform(
				ast.List(
					elts = [value],
					ctx = ast.Load()
				)
			)
		)
Beispiel #3
0
	def heapify_name(self, node, new_name):
		return pyc_ir.txform(make_subn(new_name, node.ctx.__class__, 0))