def MAKE_CLOSURE(f, numdefaults, *ignored): w_codeobj = f.popvalue() codeobj = f.space.interp_w(pycode.PyCode, w_codeobj) if codeobj.magic >= 0xa0df281: # CPython 2.5 AST branch merge w_freevarstuple = f.popvalue() freevars = [f.space.interp_w(Cell, cell) for cell in f.space.viewiterable(w_freevarstuple)] else: nfreevars = len(codeobj.co_freevars) freevars = [f.space.interp_w(Cell, f.popvalue()) for i in range(nfreevars)] freevars.reverse() defaultarguments = [f.popvalue() for i in range(numdefaults)] defaultarguments.reverse() fn = function.Function(f.space, codeobj, f.w_globals, defaultarguments, freevars) f.pushvalue(f.space.wrap(fn))
def MAKE_CLOSURE(self, numdefaults, next_instr): w_codeobj = self.popvalue() codeobj = self.space.interp_w(pycode.PyCode, w_codeobj) if codeobj.magic >= 0xa0df281: # CPython 2.5 AST branch merge w_freevarstuple = self.popvalue() freevars = [ self.space.interp_w(Cell, cell) for cell in self.space.fixedview(w_freevarstuple) ] else: n = len(codeobj.co_freevars) freevars = [None] * n while True: n -= 1 if n < 0: break freevars[n] = self.space.interp_w(Cell, self.popvalue()) defaultarguments = self.popvalues(numdefaults) fn = function.Function(self.space, codeobj, self.w_globals, defaultarguments, freevars) self.pushvalue(self.space.wrap(fn))
def MAKE_FUNCTION(f, numdefaults, *ignored): w_codeobj = f.popvalue() codeobj = f.space.interp_w(PyCode, w_codeobj) defaultarguments = f.popvalues(numdefaults) fn = function.Function(f.space, codeobj, f.w_globals, defaultarguments) f.pushvalue(f.space.wrap(fn))