[pypy-commit] pypy continulet-no-frame-loop-2: WIP: (antocuni, arigato): refactor things so that we no longer need a bottomframe, and that the bottom-most frame of each continulet is always None: this mimics more closely the stack of greenlets on CPython, and avoid building frame cycles. The corresponding test_f_back_* are failing right now because they are still checking the old behavior

antocuni pypy.commits at gmail.com
Thu Nov 16 11:30:09 EST 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: continulet-no-frame-loop-2
Changeset: r93058:55154dad821a
Date: 2017-11-16 17:28 +0100
http://bitbucket.org/pypy/pypy/changeset/55154dad821a/

Log:	WIP: (antocuni, arigato): refactor things so that we no longer need
	a bottomframe, and that the bottom-most frame of each continulet is
	always None: this mimics more closely the stack of greenlets on
	CPython, and avoid building frame cycles. The corresponding
	test_f_back_* are failing right now because they are still checking
	the old behavior

diff --git a/pypy/module/_continuation/interp_continuation.py b/pypy/module/_continuation/interp_continuation.py
--- a/pypy/module/_continuation/interp_continuation.py
+++ b/pypy/module/_continuation/interp_continuation.py
@@ -1,6 +1,7 @@
 from rpython.rlib.rstacklet import StackletThread
 from rpython.rlib import jit
 from pypy.interpreter.error import OperationError, get_cleared_operation_error
+from pypy.interpreter.error import oefmt
 from pypy.interpreter.executioncontext import ExecutionContext
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.typedef import TypeDef
@@ -30,17 +31,9 @@
             raise geterror(self.space, "continulet already __init__ialized")
         sthread = build_sthread(self.space)
         #
-        # hackish: build the frame "by hand", passing it the correct arguments
         space = self.space
-        w_args, w_kwds = __args__.topacked()
-        bottomframe = space.createframe(get_entrypoint_pycode(space),
-                                        get_w_module_dict(space), None)
-        bottomframe.locals_cells_stack_w[0] = self
-        bottomframe.locals_cells_stack_w[1] = w_callable
-        bottomframe.locals_cells_stack_w[2] = w_args
-        bottomframe.locals_cells_stack_w[3] = w_kwds
-        bottomframe.last_exception = get_cleared_operation_error(space)
-        self.bottomframe = bottomframe
+        self.w_callable = w_callable
+        self.__args__ = __args__.prepend(self)
         #
         global_state.origin = self
         self.sthread = sthread
@@ -221,9 +214,14 @@
     self = global_state.origin
     self.h = h
     global_state.clear()
+    self.backframeref = self.sthread.ec.topframeref
+    self.sthread.ec.topframeref = jit.vref_None
     try:
-        frame = self.bottomframe
-        w_result = frame.execute_frame()
+        w_res = self.descr_switch()
+        if w_res is not self.space.w_None:
+            raise oefmt(self.space.w_TypeError,
+                        "can't send non-None value to a just-started continulet")
+        w_result = self.space.call_args(self.w_callable, self.__args__)
     except Exception as e:
         global_state.propagate_exception = e
     else:
@@ -241,9 +239,9 @@
     self.h, origin.h = origin.h, h
     #
     current = sthread.ec.topframeref
-    sthread.ec.topframeref = self.bottomframe.f_backref
-    self.bottomframe.f_backref = origin.bottomframe.f_backref
-    origin.bottomframe.f_backref = current
+    sthread.ec.topframeref = self.backframeref
+    self.backframeref = origin.backframeref
+    origin.backframeref = current
     #
     return get_result()
 


More information about the pypy-commit mailing list