[pypy-commit] pypy translation-cleanup: Replace FrameState.restoreframe() with FlowSpaceFrame.setstate()
rlamy
noreply at buildbot.pypy.org
Fri Aug 10 10:03:25 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r56672:08e65805abea
Date: 2012-08-08 01:35 +0100
http://bitbucket.org/pypy/pypy/changeset/08e65805abea/
Log: Replace FrameState.restoreframe() with FlowSpaceFrame.setstate()
diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -8,7 +8,7 @@
from pypy.interpreter.pycode import PyCode, cpython_code_signature
from pypy.objspace.flow import operation
from pypy.objspace.flow.model import *
-from pypy.objspace.flow.framestate import FrameState
+from pypy.objspace.flow.framestate import FrameState, recursively_unflatten
from pypy.rlib import jit
from pypy.tool.stdlib_opcode import host_bytecode_spec
@@ -33,7 +33,7 @@
def patchframe(self, frame):
if self.dead:
raise StopFlowing
- self.framestate.restoreframe(frame)
+ frame.setstate(self.framestate)
return BlockRecorder(self)
@@ -437,6 +437,19 @@
class FlowSpaceFrame(pyframe.CPythonFrame):
+ def setstate(self, state):
+ """ Reset the frame to the given state. """
+ data = state.mergeable[:]
+ recursively_unflatten(self.space, data)
+ self.restore_locals_stack(data[:-2]) # Nones == undefined locals
+ if data[-2] == Constant(None):
+ assert data[-1] == Constant(None)
+ self.last_exception = None
+ else:
+ self.last_exception = OperationError(data[-2], data[-1])
+ blocklist, self.last_instr, self.w_locals = state.nonmergeable
+ self.set_blocklist(blocklist)
+
def SETUP_WITH(self, offsettoend, next_instr):
# A simpler version than the 'real' 2.7 one:
# directly call manager.__enter__(), don't use special lookup functions
diff --git a/pypy/objspace/flow/framestate.py b/pypy/objspace/flow/framestate.py
--- a/pypy/objspace/flow/framestate.py
+++ b/pypy/objspace/flow/framestate.py
@@ -27,33 +27,13 @@
elif isinstance(state, tuple):
self.mergeable, self.nonmergeable = state
else:
- raise TypeError("can't get framestate for %r" %
+ raise TypeError("can't get framestate for %r" %
state.__class__.__name__)
self.next_instr = self.nonmergeable[1]
for w1 in self.mergeable:
assert isinstance(w1, (Variable, Constant)) or w1 is None, (
'%r found in frame state' % w1)
- def restoreframe(self, frame):
- if isinstance(frame, PyFrame):
- data = self.mergeable[:]
- recursively_unflatten(frame.space, data)
- frame.restore_locals_stack(data[:-2]) # Nones == undefined locals
- if data[-2] == Constant(None):
- assert data[-1] == Constant(None)
- frame.last_exception = None
- else:
- frame.last_exception = OperationError(data[-2], data[-1])
- (
- 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__)
-
def copy(self):
"Make a copy of this state in which all Variables are fresh."
newstate = []
diff --git a/pypy/objspace/flow/test/test_framestate.py b/pypy/objspace/flow/test/test_framestate.py
--- a/pypy/objspace/flow/test/test_framestate.py
+++ b/pypy/objspace/flow/test/test_framestate.py
@@ -8,7 +8,7 @@
class TestFrameState:
def setup_class(cls):
- cls.space = FlowObjSpace()
+ cls.space = FlowObjSpace()
def getframe(self, func):
space = self.space
@@ -64,7 +64,7 @@
frame = self.getframe(self.func_simple)
fs1 = FrameState(frame)
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
- fs1.restoreframe(frame)
+ frame.setstate(fs1)
assert fs1 == FrameState(frame)
def test_copy(self):
@@ -77,7 +77,7 @@
frame = self.getframe(self.func_simple)
fs1 = FrameState(frame)
vars = fs1.getvariables()
- assert len(vars) == 1
+ assert len(vars) == 1
def test_getoutputargs(self):
frame = self.getframe(self.func_simple)
@@ -95,7 +95,7 @@
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(42)
fs2 = FrameState(frame)
fs3 = fs1.union(fs2)
- fs3.restoreframe(frame)
+ frame.setstate(fs3)
assert isinstance(frame.locals_stack_w[frame.pycode.co_nlocals-1],
Variable) # generalized
More information about the pypy-commit
mailing list