Esempio n. 1
0
    def descr__setstate__(self, space, w_args):
        from pypy.module._pickle_support import maker  # helper fns
        from pypy.interpreter.pycode import PyCode
        from pypy.interpreter.module import Module

        args_w = space.unpackiterable(w_args)
        w_f_back, w_builtin, w_pycode, w_valuestack, w_blockstack, w_exc_value, w_tb, w_globals, w_last_instr, w_finished, w_f_lineno, w_fastlocals, w_f_locals, w_f_trace, w_instr_lb, w_instr_ub, w_instr_prev, w_cells = (
            args_w
        )

        new_frame = self
        pycode = space.interp_w(PyCode, w_pycode)

        if space.is_w(w_cells, space.w_None):
            closure = None
            cellvars = []
        else:
            from pypy.interpreter.nestedscope import Cell

            cells_w = space.unpackiterable(w_cells)
            cells = [space.interp_w(Cell, w_cell) for w_cell in cells_w]
            ncellvars = len(pycode.co_cellvars)
            cellvars = cells[:ncellvars]
            closure = cells[ncellvars:]

        # do not use the instance's __init__ but the base's, because we set
        # everything like cells from here
        PyFrame.__init__(self, space, pycode, w_globals, closure)
        f_back = space.interp_w(PyFrame, w_f_back, can_be_None=True)
        new_frame.f_backref = jit.non_virtual_ref(f_back)

        new_frame.builtin = space.interp_w(Module, w_builtin)
        new_frame.set_blocklist([unpickle_block(space, w_blk) for w_blk in space.unpackiterable(w_blockstack)])
        values_w = maker.slp_from_tuple_with_nulls(space, w_valuestack)
        for w_value in values_w:
            new_frame.pushvalue(w_value)
        if space.is_w(w_exc_value, space.w_None):
            new_frame.last_exception = None
        else:
            from pypy.interpreter.pytraceback import PyTraceback

            tb = space.interp_w(PyTraceback, w_tb)
            new_frame.last_exception = OperationError(space.type(w_exc_value), w_exc_value, tb)
        new_frame.last_instr = space.int_w(w_last_instr)
        new_frame.frame_finished_execution = space.is_true(w_finished)
        new_frame.f_lineno = space.int_w(w_f_lineno)
        new_frame.fastlocals_w = maker.slp_from_tuple_with_nulls(space, w_fastlocals)

        if space.is_w(w_f_trace, space.w_None):
            new_frame.w_f_trace = None
        else:
            new_frame.w_f_trace = w_f_trace

        new_frame.instr_lb = space.int_w(w_instr_lb)  # the three for tracing
        new_frame.instr_ub = space.int_w(w_instr_ub)
        new_frame.instr_prev = space.int_w(w_instr_prev)

        self._setcellvars(cellvars)
        # XXX what if the frame is in another thread??
        space.frame_trace_action.fire()
Esempio n. 2
0
 def enter(self, ec):
     ec.topframeref = jit.non_virtual_ref(self.topframe)
     ec.w_tracefunc = self.w_tracefunc
     ec.profilefunc = self.profilefunc
     ec.w_profilefuncarg = self.w_profilefuncarg
     ec.is_tracing = self.is_tracing
     ec.space.frame_trace_action.fire()
Esempio n. 3
0
def resume_frame(space, w_frame):
    from pypy.interpreter.pyframe import PyFrame
    frame = space.interp_w(PyFrame, w_frame, can_be_None=True)
    w_result = space.w_None
    operr = None
    executioncontext = frame.space.getexecutioncontext()
    while frame is not None:
        code = frame.pycode.co_code
        instr = frame.last_instr
        opcode = ord(code[instr])
        map = pythonopcode.opmap
        call_ops = [map['CALL_FUNCTION'], map['CALL_FUNCTION_KW'], map['CALL_FUNCTION_VAR'],
                    map['CALL_FUNCTION_VAR_KW'], map['CALL_METHOD']]
        assert opcode in call_ops
        instr += 1
        oparg = ord(code[instr]) | ord(code[instr + 1]) << 8
        nargs = oparg & 0xff
        nkwds = (oparg >> 8) & 0xff
        if nkwds == 0:     # only positional arguments
            # fast paths leaves things on the stack, pop them
            if space.config.objspace.opcodes.CALL_METHOD and opcode == map['CALL_METHOD']:
                frame.dropvalues(nargs + 2)
            elif opcode == map['CALL_FUNCTION']:
                frame.dropvalues(nargs + 1)

        # small hack: unlink frame out of the execution context, because
        # execute_frame will add it there again
        executioncontext.topframeref = jit.non_virtual_ref(frame.f_backref())
        frame.last_instr = instr + 1 # continue after the call
        try:
            w_result = frame.execute_frame(w_result, operr)
        except OperationError, operr:
            pass
        frame = frame.f_backref()
Esempio n. 4
0
 def f(n):
     res1 = -42
     while n > 0:
         myjitdriver.jit_merge_point(n=n, res1=res1)
         x = X()
         res1 = residual(non_virtual_ref(x))
         n -= 1
     return res1
Esempio n. 5
0
 def f(n):
     res1 = -42
     while n > 0:
         myjitdriver.jit_merge_point(n=n, res1=res1)
         x = X()
         res1 = residual(non_virtual_ref(x))
         n -= 1
     return res1
Esempio n. 6
0
 def enter(self, ec):
     ec.topframeref = jit.non_virtual_ref(self.topframe)
     ec.framestackdepth = self.framestackdepth
     ec.w_tracefunc = self.w_tracefunc
     ec.profilefunc = self.profilefunc
     ec.w_profilefuncarg = self.w_profilefuncarg
     ec.is_tracing = self.is_tracing
     ec.space.frame_trace_action.fire()
Esempio n. 7
0
    def build_flow(self):
        if self.is_generator:
            self.produce_generator_mark()
        while self.pendingblocks:
            block = self.pendingblocks.popleft()
            frame = self.create_frame()
            try:
                self.recorder = block.patchframe(frame)
            except StopFlowing:
                continue  # restarting a dead SpamBlock
            try:
                old_frameref = self.topframeref
                self.topframeref = jit.non_virtual_ref(frame)
                self.crnt_frame = frame
                try:
                    frame.frame_finished_execution = False
                    while True:
                        w_result = frame.dispatch(frame.pycode,
                                                  frame.last_instr, self)
                        if frame.frame_finished_execution:
                            break
                        else:
                            self.generate_yield(frame, w_result)
                finally:
                    self.crnt_frame = None
                    self.topframeref = old_frameref

            except operation.OperationThatShouldNotBePropagatedError, e:
                raise Exception(
                    'found an operation that always raises %s: %s' %
                    (self.space.unwrap(e.w_type).__name__,
                     self.space.unwrap(e.get_w_value(self.space))))

            except operation.ImplicitOperationError, e:
                if isinstance(e.w_type, Constant):
                    exc_cls = e.w_type.value
                else:
                    exc_cls = Exception
                msg = "implicit %s shouldn't occur" % exc_cls.__name__
                w_type = Constant(AssertionError)
                w_value = Constant(AssertionError(msg))
                link = self.make_link([w_type, w_value],
                                      self.graph.exceptblock)
                self.recorder.crnt_block.closeblock(link)
Esempio n. 8
0
    def build_flow(self):
        if self.is_generator:
            self.produce_generator_mark()
        while self.pendingblocks:
            block = self.pendingblocks.popleft()
            frame = self.create_frame()
            try:
                self.recorder = block.patchframe(frame)
            except StopFlowing:
                continue   # restarting a dead SpamBlock
            try:
                old_frameref = self.topframeref
                self.topframeref = jit.non_virtual_ref(frame)
                self.crnt_frame = frame
                try:
                    frame.frame_finished_execution = False
                    while True:
                        w_result = frame.dispatch(frame.pycode,
                                                  frame.last_instr,
                                                  self)
                        if frame.frame_finished_execution:
                            break
                        else:
                            self.generate_yield(frame, w_result)
                finally:
                    self.crnt_frame = None
                    self.topframeref = old_frameref

            except operation.OperationThatShouldNotBePropagatedError, e:
                raise Exception(
                    'found an operation that always raises %s: %s' % (
                        self.space.unwrap(e.w_type).__name__,
                        self.space.unwrap(e.get_w_value(self.space))))

            except operation.ImplicitOperationError, e:
                if isinstance(e.w_type, Constant):
                    exc_cls = e.w_type.value
                else:
                    exc_cls = Exception
                msg = "implicit %s shouldn't occur" % exc_cls.__name__
                w_type = Constant(AssertionError)
                w_value = Constant(AssertionError(msg))
                link = self.make_link([w_type, w_value], self.graph.exceptblock)
                self.recorder.crnt_block.closeblock(link)
Esempio n. 9
0
    def descr__setstate__(self, space, w_args):
        from pypy.module._pickle_support import maker  # helper fns
        from pypy.interpreter.pycode import PyCode
        from pypy.interpreter.module import Module
        args_w = space.unpackiterable(w_args)
        w_f_back, w_builtin, w_pycode, w_valuestack, w_blockstack, w_exc_value, w_tb,\
            w_globals, w_last_instr, w_finished, w_f_lineno, w_fastlocals, w_f_locals, \
            w_f_trace, w_instr_lb, w_instr_ub, w_instr_prev_plus_one, w_cells = args_w

        new_frame = self
        pycode = space.interp_w(PyCode, w_pycode)

        if space.is_w(w_cells, space.w_None):
            closure = None
            cellvars = []
        else:
            from pypy.interpreter.nestedscope import Cell
            cells_w = space.unpackiterable(w_cells)
            cells = [space.interp_w(Cell, w_cell) for w_cell in cells_w]
            ncellvars = len(pycode.co_cellvars)
            cellvars = cells[:ncellvars]
            closure = cells[ncellvars:]

        # do not use the instance's __init__ but the base's, because we set
        # everything like cells from here
        # XXX hack
        from pypy.interpreter.function import Function
        outer_func = Function(space, None, closure=closure, forcename="fake")
        PyFrame.__init__(self, space, pycode, w_globals, outer_func)
        f_back = space.interp_w(PyFrame, w_f_back, can_be_None=True)
        new_frame.f_backref = jit.non_virtual_ref(f_back)

        new_frame.builtin = space.interp_w(Module, w_builtin)
        new_frame.set_blocklist([
            unpickle_block(space, w_blk)
            for w_blk in space.unpackiterable(w_blockstack)
        ])
        values_w = maker.slp_from_tuple_with_nulls(space, w_valuestack)
        for w_value in values_w:
            new_frame.pushvalue(w_value)
        if space.is_w(w_exc_value, space.w_None):
            new_frame.last_exception = None
        else:
            from pypy.interpreter.pytraceback import PyTraceback
            tb = space.interp_w(PyTraceback, w_tb)
            new_frame.last_exception = OperationError(space.type(w_exc_value),
                                                      w_exc_value, tb)
        new_frame.last_instr = space.int_w(w_last_instr)
        new_frame.frame_finished_execution = space.is_true(w_finished)
        new_frame.f_lineno = space.int_w(w_f_lineno)
        fastlocals_w = maker.slp_from_tuple_with_nulls(space, w_fastlocals)
        new_frame.locals_stack_w[:len(fastlocals_w)] = fastlocals_w

        if space.is_w(w_f_trace, space.w_None):
            new_frame.w_f_trace = None
        else:
            new_frame.w_f_trace = w_f_trace

        new_frame.instr_lb = space.int_w(w_instr_lb)  #the three for tracing
        new_frame.instr_ub = space.int_w(w_instr_ub)
        new_frame.instr_prev_plus_one = space.int_w(w_instr_prev_plus_one)

        self._setcellvars(cellvars)
        # XXX what if the frame is in another thread??
        space.frame_trace_action.fire()
Esempio n. 10
0
 def restore_top_frame(space, w_frame, w_saved):
     while w_frame.f_backref():
         w_frame = w_frame.f_backref()
     w_frame.f_backref = non_virtual_ref(w_saved)
Esempio n. 11
0
 def restore_top_frame(space, w_frame, w_saved):
     while w_frame.f_backref():
         w_frame = w_frame.f_backref()
     w_frame.f_backref = non_virtual_ref(w_saved)
Esempio n. 12
0
 def f(n):
     if n > 0:
         return virtual_ref(Y())
     else:
         return non_virtual_ref(Z())