Author: Ronan Lamy <[email protected]>
Branch: framestate
Changeset: r74619:092128f86b9d
Date: 2014-11-20 20:34 +0000
http://bitbucket.org/pypy/pypy/changeset/092128f86b9d/
Log: Make FlowSignal interface more convenient
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -1206,22 +1206,26 @@
def nomoreblocks(self):
raise BytecodeCorruption("misplaced bytecode - should not return")
+ def __eq__(self, other):
+ return type(other) is type(self) and other.args == self.args
+
class Return(FlowSignal):
"""Signals a 'return' statement.
- Argument is the wrapped object to return."""
-
+ Argument is the wrapped object to return.
+ """
def __init__(self, w_value):
self.w_value = w_value
def nomoreblocks(self):
raise Return(self.w_value)
- def state_unpack_variables(self):
+ @property
+ def args(self):
return [self.w_value]
@staticmethod
- def state_pack_variables(w_value):
+ def rebuild(w_value):
return Return(w_value)
class Raise(FlowSignal):
@@ -1234,11 +1238,12 @@
def nomoreblocks(self):
raise self
- def state_unpack_variables(self):
+ @property
+ def args(self):
return [self.w_exc.w_type, self.w_exc.w_value]
@staticmethod
- def state_pack_variables(w_type, w_value):
+ def rebuild(w_type, w_value):
return Raise(FSException(w_type, w_value))
class RaiseImplicit(Raise):
@@ -1248,11 +1253,12 @@
class Break(FlowSignal):
"""Signals a 'break' statement."""
- def state_unpack_variables(self):
+ @property
+ def args(self):
return []
@staticmethod
- def state_pack_variables():
+ def rebuild():
return Break.singleton
Break.singleton = Break()
@@ -1264,11 +1270,12 @@
def __init__(self, jump_to):
self.jump_to = jump_to
- def state_unpack_variables(self):
+ @property
+ def args(self):
return [const(self.jump_to)]
@staticmethod
- def state_pack_variables(w_jump_to):
+ def rebuild(w_jump_to):
return Continue(w_jump_to.value)
diff --git a/rpython/flowspace/framestate.py b/rpython/flowspace/framestate.py
--- a/rpython/flowspace/framestate.py
+++ b/rpython/flowspace/framestate.py
@@ -109,7 +109,7 @@
if not isinstance(unroller, FlowSignal):
i += 1
else:
- vars = unroller.state_unpack_variables()
+ vars = unroller.args
key = unroller.__class__, len(vars)
try:
tag = PICKLE_TAGS[key]
@@ -126,5 +126,5 @@
unrollerclass, argcount = UNPICKLE_TAGS[item]
arguments = lst[i + 1:i + 1 + argcount]
del lst[i + 1:i + 1 + argcount]
- unroller = unrollerclass.state_pack_variables(*arguments)
+ unroller = unrollerclass.rebuild(*arguments)
lst[i] = unroller
diff --git a/rpython/flowspace/test/test_flowcontext.py
b/rpython/flowspace/test/test_flowcontext.py
new file mode 100644
--- /dev/null
+++ b/rpython/flowspace/test/test_flowcontext.py
@@ -0,0 +1,15 @@
+""" Unit tests for flowcontext.py """
+import pytest
+from rpython.flowspace.model import Variable, FSException
+from rpython.flowspace.flowcontext import (
+ Return, Raise, RaiseImplicit, Continue, Break)
+
[email protected]('signal', [
+ Return(Variable()),
+ Raise(FSException(Variable(), Variable())),
+ #RaiseImplicit(FSException(Variable(), Variable())),
+ Break(),
+ Continue(42),
+])
+def test_signals(signal):
+ assert signal.rebuild(*signal.args) == signal
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit