[pypy-svn] r7545 - in pypy/trunk/src/pypy: interpreter objspace/flow objspace/flow/test

arigo at codespeak.net arigo at codespeak.net
Mon Nov 22 10:03:37 CET 2004


Author: arigo
Date: Mon Nov 22 10:03:36 2004
New Revision: 7545

Modified:
   pypy/trunk/src/pypy/interpreter/eval.py
   pypy/trunk/src/pypy/interpreter/executioncontext.py
   pypy/trunk/src/pypy/interpreter/generator.py
   pypy/trunk/src/pypy/objspace/flow/flowcontext.py
   pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
Log:
Reverted the execution contexts to the previous API (enter/leave) to avoid
breaking the trace object space.



Modified: pypy/trunk/src/pypy/interpreter/eval.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/eval.py	(original)
+++ pypy/trunk/src/pypy/interpreter/eval.py	Mon Nov 22 10:03:36 2004
@@ -67,10 +67,19 @@
             numlocals = len(code.getvarnames())
         self.fastlocals_w = [UNDEFINED]*numlocals  # flat list of wrapped locals
 
-    def run(self):
-        "Run the frame."
+    def resume(self):
+        "Resume the execution of the frame from its current state."
         executioncontext = self.space.getexecutioncontext()
-        return executioncontext.run_frame(self)
+        previous = executioncontext.enter(self)
+        try:
+            result = self.eval(executioncontext)
+        finally:
+            executioncontext.leave(previous)
+        return result
+
+    # running a frame is usually the same as resuming it from its
+    # initial state, but not for generator frames
+    run = resume
 
     def eval(self, executioncontext):
         "Abstract method to override."

Modified: pypy/trunk/src/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/executioncontext.py	(original)
+++ pypy/trunk/src/pypy/interpreter/executioncontext.py	Mon Nov 22 10:03:36 2004
@@ -9,18 +9,17 @@
         self.space = space
         self.framestack = Stack()
 
-    def run_frame(self, frame):
+    def enter(self, frame):
         locals = getthreadlocals()
         previous_ec = locals.executioncontext
         locals.executioncontext = self
         self.framestack.push(frame)
-        try:
-            w_result = frame.eval(self)
-        finally:
-            self.framestack.pop()
-            locals = getthreadlocals()
-            locals.executioncontext = previous_ec
-        return w_result
+        return previous_ec
+
+    def leave(self, previous_ec):
+        self.framestack.pop()
+        locals = getthreadlocals()
+        locals.executioncontext = previous_ec
 
     def get_w_builtins(self):
         if self.framestack.empty():

Modified: pypy/trunk/src/pypy/interpreter/generator.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/generator.py	(original)
+++ pypy/trunk/src/pypy/interpreter/generator.py	Mon Nov 22 10:03:36 2004
@@ -53,11 +53,10 @@
                                  space.wrap('generator already executing'))
         if self.frame.exhausted:
             raise OperationError(space.w_StopIteration, space.w_None) 
-        executioncontext = space.getexecutioncontext()
         self.running = True
         try:
             try:
-                return executioncontext.run_frame(self.frame)
+                return self.frame.resume()
             except OperationError, e:
                 if e.match(self.space, self.space.w_StopIteration):
                     raise OperationError(space.w_StopIteration, space.w_None) 

Modified: pypy/trunk/src/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/flowcontext.py	Mon Nov 22 10:03:36 2004
@@ -205,7 +205,7 @@
             except ExitFrame:
                 continue   # restarting a dead SpamBlock
             try:
-                w_result = self.run_frame(frame)
+                w_result = frame.resume()
             except OperationError, e:
                 link = Link([e.w_type, e.w_value], self.graph.exceptblock)
                 self.crnt_block.closeblock(link)

Modified: pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py	Mon Nov 22 10:03:36 2004
@@ -231,12 +231,10 @@
     def test_raise1(self):
         x = self.codetest(self.raise1)
         self.show(x)
-        assert len(x.startblock.operations) == 1
-        assert x.startblock.operations[0].opname == 'simple_call'
-        assert list(x.startblock.operations[0].args) == [Constant(IndexError)]
+        assert len(x.startblock.operations) == 0
         assert x.startblock.exits[0].args == [
             Constant(IndexError),
-            x.startblock.operations[0].result]
+            Constant(None)]         # no normalization
         assert x.startblock.exits[0].target is x.exceptblock
 
     #__________________________________________________________



More information about the Pypy-commit mailing list