Author: Ronan Lamy <[email protected]>
Branch: Opcode-class
Changeset: r63833:8fcf71337b33
Date: 2013-04-30 15:32 +0100
http://bitbucket.org/pypy/pypy/changeset/8fcf71337b33/
Log: Deal with FSFrame.last_instr a bit more explicitly
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -424,7 +424,7 @@
raise BytecodeCorruption("misplaced bytecode - should not return")
return block.handle(self, unroller)
- def getstate(self):
+ def getstate(self, next_pos):
# getfastscope() can return real None, for undefined locals
data = self.save_locals_stack()
if self.last_exception is None:
@@ -434,7 +434,7 @@
data.append(self.last_exception.w_type)
data.append(self.last_exception.w_value)
recursively_flatten(self.space, data)
- return FrameState(data, self.blockstack[:], self.last_instr)
+ return FrameState(data, self.blockstack[:], next_pos)
def setstate(self, state):
""" Reset the frame to the given state. """
@@ -446,7 +446,6 @@
self.last_exception = None
else:
self.last_exception = FSException(data[-2], data[-1])
- self.last_instr = state.next_instr
self.blockstack = state.blocklist[:]
def guessbool(self, w_condition, **kwds):
@@ -490,11 +489,12 @@
def record_block(self, block):
self.setstate(block.framestate)
+ next_pos = block.framestate.next_instr
self.recorder = block.make_recorder()
try:
while True:
- self.last_instr = self.handle_bytecode(self.last_instr)
- self.recorder.final_state = self.getstate()
+ next_pos = self.handle_bytecode(next_pos)
+ self.recorder.final_state = self.getstate(next_pos)
except ImplicitOperationError, e:
if isinstance(e.w_type, Constant):
@@ -577,6 +577,7 @@
def handle_bytecode(self, next_instr):
next_instr, opcode = self.pycode.read(next_instr)
try:
+ self.last_instr = opcode.offset
res = opcode.eval(self)
return res if res is not None else next_instr
except FSException, operr:
diff --git a/rpython/flowspace/test/test_framestate.py
b/rpython/flowspace/test/test_framestate.py
--- a/rpython/flowspace/test/test_framestate.py
+++ b/rpython/flowspace/test/test_framestate.py
@@ -25,55 +25,55 @@
def test_eq_framestate(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
- fs2 = frame.getstate()
+ fs1 = frame.getstate(0)
+ fs2 = frame.getstate(0)
assert fs1 == fs2
def test_neq_hacked_framestate(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
+ fs1 = frame.getstate(0)
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
- fs2 = frame.getstate()
+ fs2 = frame.getstate(0)
assert fs1 != fs2
def test_union_on_equal_framestates(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
- fs2 = frame.getstate()
+ fs1 = frame.getstate(0)
+ fs2 = frame.getstate(0)
assert fs1.union(fs2) == fs1
def test_union_on_hacked_framestates(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
+ fs1 = frame.getstate(0)
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
- fs2 = frame.getstate()
+ fs2 = frame.getstate(0)
assert fs1.union(fs2) == fs2 # fs2 is more general
assert fs2.union(fs1) == fs2 # fs2 is more general
def test_restore_frame(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
+ fs1 = frame.getstate(0)
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
frame.setstate(fs1)
- assert fs1 == frame.getstate()
+ assert fs1 == frame.getstate(0)
def test_copy(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
+ fs1 = frame.getstate(0)
fs2 = fs1.copy()
assert fs1 == fs2
def test_getvariables(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
+ fs1 = frame.getstate(0)
vars = fs1.getvariables()
assert len(vars) == 1
def test_getoutputargs(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
+ fs1 = frame.getstate(0)
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Variable()
- fs2 = frame.getstate()
+ fs2 = frame.getstate(0)
outputargs = fs1.getoutputargs(fs2)
# 'x' -> 'x' is a Variable
# locals_w[n-1] -> locals_w[n-1] is Constant(None)
@@ -81,9 +81,9 @@
def test_union_different_constants(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
+ fs1 = frame.getstate(0)
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(42)
- fs2 = frame.getstate()
+ fs2 = frame.getstate(0)
fs3 = fs1.union(fs2)
frame.setstate(fs3)
assert isinstance(frame.locals_stack_w[frame.pycode.co_nlocals-1],
@@ -91,7 +91,7 @@
def test_union_spectag(self):
frame = self.getframe(self.func_simple)
- fs1 = frame.getstate()
+ fs1 = frame.getstate(0)
frame.locals_stack_w[frame.pycode.co_nlocals-1] = Constant(SpecTag())
- fs2 = frame.getstate()
+ fs2 = frame.getstate(0)
assert fs1.union(fs2) is None # UnionError
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit