[pypy-svn] r67803 - in pypy/trunk/pypy: interpreter objspace/flow
antocuni at codespeak.net
antocuni at codespeak.net
Sat Sep 19 20:34:30 CEST 2009
Author: antocuni
Date: Sat Sep 19 20:34:29 2009
New Revision: 67803
Modified:
pypy/trunk/pypy/interpreter/generator.py
pypy/trunk/pypy/interpreter/pyframe.py
pypy/trunk/pypy/interpreter/pyopcode.py
pypy/trunk/pypy/objspace/flow/framestate.py
Log:
merge the blocklist branch: it turns the rpython list frame.blockstack into a
linked list. This way, it's more ootype-jit friendly (and slightly more
efficient in the non jit case too)
Modified: pypy/trunk/pypy/interpreter/generator.py
==============================================================================
--- pypy/trunk/pypy/interpreter/generator.py (original)
+++ pypy/trunk/pypy/interpreter/generator.py Sat Sep 19 20:34:29 2009
@@ -126,10 +126,12 @@
# Only bother raising an exception if the frame is still not
# finished and finally or except blocks are present.
if not self.frame.frame_finished_execution:
- for block in self.frame.blockstack:
+ block = self.frame.lastblock
+ while block is not None:
if not isinstance(block, LoopBlock):
self.descr_close()
return
+ block = block.previous
def __del__(self):
self._enqueue_for_destruction(self.space)
Modified: pypy/trunk/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyframe.py (original)
+++ pypy/trunk/pypy/interpreter/pyframe.py Sat Sep 19 20:34:29 2009
@@ -55,7 +55,8 @@
eval.Frame.__init__(self, space, w_globals, code.co_nlocals)
self.valuestack_w = [None] * code.co_stacksize
self.valuestackdepth = 0
- self.blockstack = []
+ self.lastblock = None
+ self.blockcount = 0
if space.config.objspace.honor__builtins__:
self.builtin = space.builtin.pick_builtin(w_globals)
# regular functions always have CO_OPTIMIZED and CO_NEWLOCALS.
@@ -66,6 +67,37 @@
self.f_lineno = code.co_firstlineno
ExecutionContext._init_chaining_attributes(self)
+ def append_block(self, block):
+ block.previous = self.lastblock
+ self.lastblock = block
+ self.blockcount += 1
+
+ def pop_block(self):
+ block = self.lastblock
+ self.lastblock = block.previous
+ self.blockcount -= 1
+ return block
+
+ def get_blocklist(self):
+ """Returns a list containing all the blocks in the frame"""
+ lst = [None] * self.blockcount
+ block = self.lastblock
+ i = 0
+ while block is not None:
+ lst[i] = block
+ i += 1
+ block = block.previous
+ return lst
+
+ def set_blocklist(self, lst):
+ self.lastblock = None
+ self.blockcount = 0
+ i = len(lst)
+ while i > 0:
+ block = lst[i-1]
+ i -= 1
+ self.append_block(block)
+
def get_builtin(self):
if self.space.config.objspace.honor__builtins__:
return self.builtin
@@ -277,7 +309,7 @@
values_w = self.valuestack_w[0:self.valuestackdepth]
w_valuestack = maker.slp_into_tuple_with_nulls(space, values_w)
- w_blockstack = nt([block._get_state_(space) for block in self.blockstack])
+ w_blockstack = nt([block._get_state_(space) for block in self.get_blocklist()])
w_fastlocals = maker.slp_into_tuple_with_nulls(space, self.fastlocals_w)
if self.last_exception is None:
w_exc_value = space.w_None
@@ -343,8 +375,8 @@
new_frame.f_back_forced = True
new_frame.builtin = space.interp_w(Module, w_builtin)
- new_frame.blockstack = [unpickle_block(space, w_blk)
- for w_blk in space.unpackiterable(w_blockstack)]
+ 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)
@@ -532,7 +564,7 @@
else:
addr += 1
- f_iblock = len(self.blockstack)
+ f_iblock = self.blockcount
min_iblock = f_iblock + min_delta_iblock
if new_lasti > self.last_instr:
new_iblock = f_iblock + delta_iblock
@@ -544,7 +576,7 @@
space.wrap("can't jump into the middle of a block"))
while f_iblock > new_iblock:
- block = self.blockstack.pop()
+ block = self.pop_block()
block.cleanup(self)
f_iblock -= 1
Modified: pypy/trunk/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyopcode.py (original)
+++ pypy/trunk/pypy/interpreter/pyopcode.py Sat Sep 19 20:34:29 2009
@@ -273,10 +273,10 @@
return next_instr
def unrollstack(self, unroller_kind):
- n = len(self.blockstack)
+ n = self.blockcount
n = hint(n, promote=True)
while n > 0:
- block = self.blockstack.pop()
+ block = self.pop_block()
n -= 1
if (block.handling_mask & unroller_kind) != 0:
return block
@@ -591,7 +591,7 @@
f.setdictscope(w_locals)
def POP_BLOCK(f, *ignored):
- block = f.blockstack.pop()
+ block = f.pop_block()
block.cleanup(f) # the block knows how to clean up the value stack
def end_finally(f):
@@ -860,15 +860,15 @@
def SETUP_LOOP(f, offsettoend, next_instr, *ignored):
block = LoopBlock(f, next_instr + offsettoend)
- f.blockstack.append(block)
+ f.append_block(block)
def SETUP_EXCEPT(f, offsettoend, next_instr, *ignored):
block = ExceptBlock(f, next_instr + offsettoend)
- f.blockstack.append(block)
+ f.append_block(block)
def SETUP_FINALLY(f, offsettoend, next_instr, *ignored):
block = FinallyBlock(f, next_instr + offsettoend)
- f.blockstack.append(block)
+ f.append_block(block)
def WITH_CLEANUP(f, *ignored):
# see comment in END_FINALLY for stack state
@@ -1130,6 +1130,7 @@
def __init__(self, frame, handlerposition):
self.handlerposition = handlerposition
self.valuestackdepth = frame.valuestackdepth
+ self.previous = None # this makes a linked list of blocks
def __eq__(self, other):
return (self.__class__ is other.__class__ and
@@ -1175,7 +1176,7 @@
# re-push the loop block without cleaning up the value stack,
# and jump to the beginning of the loop, stored in the
# exception's argument
- frame.blockstack.append(self)
+ frame.append_block(self)
return unroller.jump_to
else:
# jump to the end of the loop
Modified: pypy/trunk/pypy/objspace/flow/framestate.py
==============================================================================
--- pypy/trunk/pypy/objspace/flow/framestate.py (original)
+++ pypy/trunk/pypy/objspace/flow/framestate.py Sat Sep 19 20:34:29 2009
@@ -20,7 +20,7 @@
recursively_flatten(state.space, data)
self.mergeable = data
self.nonmergeable = (
- state.blockstack[:],
+ state.get_blocklist(),
state.last_instr, # == next_instr when between bytecodes
state.w_locals,
)
@@ -47,10 +47,11 @@
else:
frame.last_exception = OperationError(data[-2], data[-1])
(
- frame.blockstack[:],
+ blocklist,
frame.last_instr,
frame.w_locals,
) = self.nonmergeable
+ frame.set_blocklist(blocklist)
else:
raise TypeError("can't set framestate for %r" %
frame.__class__.__name__)
More information about the Pypy-commit
mailing list