Example #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
		)
Example #2
0
def vis_fn(visitor, node, name, scope):
    locs = locals(node)
    fnscope = locs | scope

    return ast.FunctionDef(
        name=name,
        args=pyc_vis.visit(visitor, node.args, fnscope),
        body=[pyc_vis.visit(visitor, n, fnscope) for n in node.body],
    )
Example #3
0
	def visit_Module(self, node):
		heap_vars = {}
		locs = pyc_localize.locals(node)
		locs = locs

		self.log("locals: %r" % locs)

		result = [pyc_vis.visit(self, n, heap_vars, locs) for n in node.body]
		inits = self.init_local_heap_vars(locs, set([]), heap_vars)

		self.log("heapify result: %r" % heap_vars)
		self.patch_lamb_nodes()		
		return ast.Module(
			body = inits + result
		)
Example #4
0
	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
		)
Example #5
0
    def visit_Module(self, node):
        locs = locals(node)
        self.log(self.depth_fmt("locals: %r" % locs))

        return ast.Module(body=[pyc_vis.visit(self, n, locs) for n in node.body])