[pypy-commit] pypy translation-cleanup: Clean up yield handling in flow space
rlamy
noreply at buildbot.pypy.org
Thu Aug 30 18:38:08 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r56989:b55ecb0a4176
Date: 2012-08-10 18:43 +0100
http://bitbucket.org/pypy/pypy/changeset/b55ecb0a4176/
Log: Clean up yield handling in flow space
Bypass PyFrame.dispatch which swallows exception FlowSpaceFrame
should handle itself and simply implement YIELD_VALUE as an ordinary
bytecode without control flow implications.
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
@@ -6,6 +6,7 @@
from pypy.interpreter.argument import ArgumentsForTranslation
from pypy.interpreter.astcompiler.consts import CO_GENERATOR
from pypy.interpreter.pycode import PyCode, cpython_code_signature
+from pypy.interpreter.pyopcode import Return, Yield
from pypy.objspace.flow import operation
from pypy.objspace.flow.model import *
from pypy.objspace.flow.framestate import (FrameState, recursively_unflatten,
@@ -431,20 +432,21 @@
def run(self, ec):
self.frame_finished_execution = False
while True:
- w_result = self.dispatch(self.pycode, self.last_instr, ec)
- if self.frame_finished_execution:
- return w_result
- else:
- self.generate_yield(ec, w_result)
+ co_code = self.pycode.co_code
+ next_instr = self.last_instr
+ try:
+ while True:
+ next_instr = self.handle_bytecode(co_code, next_instr, ec)
+ except Return:
+ return self.popvalue()
- def generate_yield(self, ec, w_result):
+ def YIELD_VALUE(self, _, next_instr):
assert self.is_generator
- ec.recorder.crnt_block.operations.append(
- SpaceOperation('yield', [w_result], Variable()))
- # we must push a dummy value that will be POPped: it's the .send()
- # passed into the generator
+ w_result = self.popvalue()
+ self.space.do_operation('yield', w_result)
+ # XXX yield expressions not supported. This will blow up if the value
+ # isn't popped straightaway.
self.pushvalue(None)
- self.last_instr += 1
def SETUP_WITH(self, offsettoend, next_instr):
# A simpler version than the 'real' 2.7 one:
More information about the pypy-commit
mailing list