[pypy-svn] r66004 - in pypy/branch/pyjitpl5-2/pypy: interpreter objspace/std
fijal at codespeak.net
fijal at codespeak.net
Sat Jun 27 01:01:46 CEST 2009
Author: fijal
Date: Sat Jun 27 01:01:44 2009
New Revision: 66004
Modified:
pypy/branch/pyjitpl5-2/pypy/interpreter/executioncontext.py
pypy/branch/pyjitpl5-2/pypy/interpreter/miscutils.py
pypy/branch/pyjitpl5-2/pypy/objspace/std/typeobject.py
Log:
Change framestack to linked list, using f_back as a link.
Modified: pypy/branch/pyjitpl5-2/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/branch/pyjitpl5-2/pypy/interpreter/executioncontext.py (original)
+++ pypy/branch/pyjitpl5-2/pypy/interpreter/executioncontext.py Sat Jun 27 01:01:44 2009
@@ -1,11 +1,11 @@
import sys
-from pypy.interpreter.miscutils import Stack
+from pypy.interpreter.miscutils import PseudoStack
from pypy.interpreter.error import OperationError
from pypy.rlib.rarithmetic import LONG_BIT
from pypy.rlib.unroll import unrolling_iterable
def new_framestack():
- return Stack()
+ return PseudoStack()
def app_profile_call(space, w_callable, frame, event, w_arg):
space.call_function(w_callable,
@@ -32,10 +32,7 @@
if self.framestack.depth() > self.space.sys.recursionlimit:
raise OperationError(self.space.w_RuntimeError,
self.space.wrap("maximum recursion depth exceeded"))
- try:
- frame.f_back = self.framestack.top()
- except IndexError:
- frame.f_back = None
+ frame.f_back = self.framestack.top()
if not frame.hide():
self.framestack.push(frame)
@@ -78,14 +75,14 @@
# the following interface is for pickling and unpickling
def getstate(self, space):
# we just save the framestack
- items = [space.wrap(item) for item in self.framestack.items]
+ items = [space.wrap(item) for item in self.framestack.getitems()]
return space.newtuple(items)
def setstate(self, space, w_state):
from pypy.interpreter.pyframe import PyFrame
- items = [space.interp_w(PyFrame, w_item)
- for w_item in space.unpackiterable(w_state)]
- self.framestack.items = items
+ topitem = space.getitem(w_state, space.wrap(-1))
+ self.framestack._top = topitem
+ self.framestack._depth = space.int_w(space.len(w_state))
# coroutine: I think this is all, folks!
@@ -126,13 +123,12 @@
self._trace(frame, 'c_exception', w_exc)
def _llprofile(self, event, w_arg):
- fr = self.framestack.items
space = self.space
w_callback = self.profilefunc
if w_callback is not None:
frame = None
- if fr:
- frame = fr[0]
+ if fr.bottom():
+ frame = fr.bottom()
self.profilefunc(space, self.w_profilefuncarg, frame, event, w_arg)
def call_trace(self, frame):
@@ -197,7 +193,7 @@
if func is not None:
if w_arg is None:
raise ValueError("Cannot call setllprofile with real None")
- for frame in self.framestack.items:
+ for frame in self.framestack.getitems():
frame.is_being_profiled = True
self.w_profilefuncarg = w_arg
Modified: pypy/branch/pyjitpl5-2/pypy/interpreter/miscutils.py
==============================================================================
--- pypy/branch/pyjitpl5-2/pypy/interpreter/miscutils.py (original)
+++ pypy/branch/pyjitpl5-2/pypy/interpreter/miscutils.py Sat Jun 27 01:01:44 2009
@@ -9,6 +9,41 @@
class RootStack:
pass
+class PseudoStack(RootStack):
+ _annspecialcase_ = 'speclize:ctr_location'
+
+ def __init__(self):
+ self._top = None
+ self._depth = 0
+
+ def top(self, position=0):
+ next = self._top
+ while position > 0:
+ next = next.f_back
+ position -= 1
+ return next
+
+ def push(self, next):
+ self._top = next
+ self._depth += 1
+
+ def pop(self):
+ next = self._top
+ self._top = next.f_back
+ self._depth -= 1
+ return next
+
+ def depth(self):
+ return self._depth
+
+ def getitems(self):
+ items = []
+ next = self._top
+ while next is not None:
+ items.append(next)
+ next = next.f_back
+ return items
+
class Stack(RootStack):
"""Utility class implementing a stack."""
Modified: pypy/branch/pyjitpl5-2/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/pyjitpl5-2/pypy/objspace/std/typeobject.py (original)
+++ pypy/branch/pyjitpl5-2/pypy/objspace/std/typeobject.py Sat Jun 27 01:01:44 2009
@@ -534,15 +534,13 @@
# initialize __module__ in the dict (user-defined types only)
if '__module__' not in w_self.dict_w:
space = w_self.space
- try:
- caller = space.getexecutioncontext().framestack.top()
- except IndexError:
- pass
- else:
- w_globals = caller.w_globals
- w_name = space.finditem(w_globals, space.wrap('__name__'))
- if w_name is not None:
- w_self.dict_w['__module__'] = w_name
+ caller = space.getexecutioncontext().framestack.top()
+ if caller is None:
+ return
+ w_globals = caller.w_globals
+ w_name = space.finditem(w_globals, space.wrap('__name__'))
+ if w_name is not None:
+ w_self.dict_w['__module__'] = w_name
def compute_mro(w_self):
if w_self.is_heaptype():
More information about the Pypy-commit
mailing list