Author: Armin Rigo <[email protected]>
Branch: stacklet
Changeset: r46407:f791af9e2ed7
Date: 2011-08-10 11:26 +0200
http://bitbucket.org/pypy/pypy/changeset/f791af9e2ed7/

Log:    Rename at app-level "stacklet" into "continuation".

diff --git a/pypy/config/translationoption.py b/pypy/config/translationoption.py
--- a/pypy/config/translationoption.py
+++ b/pypy/config/translationoption.py
@@ -28,8 +28,8 @@
 
 translation_optiondescription = OptionDescription(
         "translation", "Translation Options", [
-    BoolOption("stacklet", "enable stackless features during compilation",
-               default=False, cmdline="--stacklet",
+    BoolOption("continuation", "enable single-shot continuations",
+               default=False, cmdline="--continuation",
                requires=[("translation.type_system", "lltype")]),
     ChoiceOption("type_system", "Type system to use when RTyping",
                  ["lltype", "ootype"], cmdline=None, default="lltype",
diff --git a/pypy/module/_stacklet/__init__.py 
b/pypy/module/_continuation/__init__.py
rename from pypy/module/_stacklet/__init__.py
rename to pypy/module/_continuation/__init__.py
--- a/pypy/module/_stacklet/__init__.py
+++ b/pypy/module/_continuation/__init__.py
@@ -3,14 +3,15 @@
 
 class Module(MixedModule):
     """
-    This module exposes stacklets directly.
+    This module exposes 'continuations'.
     """
 
     appleveldefs = {
-        'error': 'app_stacklet.error',
+        'error': 'app_continuation.error',
     }
 
     interpleveldefs = {
-        'newstacklet': 'interp_stacklet.stacklet_new',
-        'Stacklet': 'interp_stacklet.W_Stacklet',
+        'new': 'interp_continuation.stacklet_new',
+        'callcc': 'interp_continuation.stacklet_new',     # a synonym
+        'Continuation': 'interp_continuation.W_Stacklet',
     }
diff --git a/pypy/module/_stacklet/app_stacklet.py 
b/pypy/module/_continuation/app_continuation.py
rename from pypy/module/_stacklet/app_stacklet.py
rename to pypy/module/_continuation/app_continuation.py
--- a/pypy/module/_stacklet/app_stacklet.py
+++ b/pypy/module/_continuation/app_continuation.py
@@ -1,4 +1,4 @@
 
 
 class error(Exception):
-    "Usage error of the _stacklet module."
+    "Usage error of the _continuation module."
diff --git a/pypy/module/_stacklet/interp_stacklet.py 
b/pypy/module/_continuation/interp_continuation.py
rename from pypy/module/_stacklet/interp_stacklet.py
rename to pypy/module/_continuation/interp_continuation.py
--- a/pypy/module/_stacklet/interp_stacklet.py
+++ b/pypy/module/_continuation/interp_continuation.py
@@ -10,12 +10,15 @@
 from pypy.interpreter.gateway import interp2app
 from pypy.rlib.debug import ll_assert, fatalerror
 
+#
+# Note: a "continuation" at app-level is called a "stacklet" here.
+#
 
 class SThread(StackletThread):
 
     def __init__(self, space, ec):
         StackletThread.__init__(self, space.config)
-        w_module = space.getbuiltinmodule('_stacklet')
+        w_module = space.getbuiltinmodule('_continuation')
         self.space = space
         self.ec = ec
         self.w_error = space.getattr(w_module, space.wrap('error'))
@@ -119,7 +122,7 @@
             space = self.sthread.space
             raise OperationError(
                 self.sthread.w_error,
-                space.wrap("stacklet has already been resumed"))
+                space.wrap("continuation has already been resumed"))
 
     def switch(self, space):
         sthread = self.sthread
@@ -141,8 +144,8 @@
         return space.newbool(bool(self.h))
 
 W_Stacklet.typedef = TypeDef(
-    'Stacklet',
-    __module__ = '_stacklet',
+    'Continuation',
+    __module__ = '_continuation',
     switch     = interp2app(W_Stacklet.switch),
     is_pending = interp2app(W_Stacklet.is_pending),
     )
@@ -178,7 +181,7 @@
             return result.consume_handle()
         except OperationError, e:
             w_value = e.get_w_value(space)
-            msg = 'returning from new stacklet: ' + space.str_w(w_value)
+            msg = 'returning from _continuation.new: ' + space.str_w(w_value)
             raise OperationError(e.w_type, space.wrap(msg))
     #
     except Exception, e:
diff --git a/pypy/module/_stacklet/test/test_stacklet.py 
b/pypy/module/_continuation/test/test_stacklet.py
rename from pypy/module/_stacklet/test/test_stacklet.py
rename to pypy/module/_continuation/test/test_stacklet.py
--- a/pypy/module/_stacklet/test/test_stacklet.py
+++ b/pypy/module/_continuation/test/test_stacklet.py
@@ -4,13 +4,13 @@
 
 class AppTestStacklet:
     def setup_class(cls):
-        cls.space = gettestobjspace(usemodules=['_stacklet'])
+        cls.space = gettestobjspace(usemodules=['_continuation'])
         cls.w_translated = cls.space.wrap(
             os.path.join(os.path.dirname(__file__),
                          'test_translated.py'))
 
     def test_new_empty(self):
-        from _stacklet import newstacklet
+        from _continuation import new, callcc
         #
         def empty_callback(h):
             assert h.is_pending()
@@ -18,12 +18,15 @@
             return h
         #
         seen = []
-        h = newstacklet(empty_callback)
+        h = new(empty_callback)
         assert h is None
         assert seen == [1]
+        h = callcc(empty_callback)
+        assert h is None
+        assert seen == [1, 1]
 
     def test_bogus_return_value(self):
-        from _stacklet import error, newstacklet
+        from _continuation import new
         #
         def empty_callback(h):
             assert h.is_pending()
@@ -31,12 +34,12 @@
             return 42
         #
         seen = []
-        raises(TypeError, newstacklet, empty_callback)
+        raises(TypeError, new, empty_callback)
         assert len(seen) == 1
         assert not seen[0].is_pending()
 
     def test_propagate_exception(self):
-        from _stacklet import error, newstacklet
+        from _continuation import new
         #
         def empty_callback(h):
             assert h.is_pending()
@@ -44,12 +47,12 @@
             raise ValueError
         #
         seen = []
-        raises(ValueError, newstacklet, empty_callback)
+        raises(ValueError, new, empty_callback)
         assert len(seen) == 1
         assert not seen[0].is_pending()
 
     def test_callback_with_arguments(self):
-        from _stacklet import newstacklet
+        from _continuation import new
         #
         def empty_callback(h, *args, **kwds):
             assert h.is_pending()
@@ -59,7 +62,7 @@
             return h
         #
         seen = []
-        h = newstacklet(empty_callback, 42, 43, foo=44, bar=45)
+        h = new(empty_callback, 42, 43, foo=44, bar=45)
         assert h is None
         assert len(seen) == 3
         assert not seen[0].is_pending()
@@ -67,19 +70,22 @@
         assert seen[2] == {'foo': 44, 'bar': 45}
 
     def test_type_of_h(self):
-        from _stacklet import newstacklet, Stacklet
+        from _continuation import new, Continuation
         #
         def empty_callback(h):
             seen.append(type(h))
             return h
         #
         seen = []
-        h = newstacklet(empty_callback)
+        h = new(empty_callback)
         assert h is None
-        assert seen[0] is Stacklet
+        assert seen[0] is Continuation
+        # cannot directly instantiate this class
+        raises(TypeError, Continuation)
+        raises(TypeError, Continuation, None)
 
     def test_switch(self):
-        from _stacklet import newstacklet
+        from _continuation import new
         #
         def switchbackonce_callback(h):
             seen.append(1)
@@ -91,15 +97,30 @@
             return h2
         #
         seen = []
-        h = newstacklet(switchbackonce_callback)
+        h = new(switchbackonce_callback)
         seen.append(2)
         assert h.is_pending()
         h2 = h.switch()
         assert h2 is None
         assert seen == [1, 2, 3]
 
+    def test_continuation_error(self):
+        from _continuation import new, error
+        #
+        def empty_callback(h):
+            assert h.is_pending()
+            seen.append(h)
+            return h
+        #
+        seen = []
+        h = new(empty_callback)
+        assert h is None
+        [h] = seen
+        assert not h.is_pending()
+        raises(error, h.switch)
+
     def test_go_depth2(self):
-        from _stacklet import newstacklet
+        from _continuation import new
         #
         def depth2(h):
             seen.append(2)
@@ -107,18 +128,18 @@
         #
         def depth1(h):
             seen.append(1)
-            h2 = newstacklet(depth2)
+            h2 = new(depth2)
             assert h2 is None
             seen.append(3)
             return h
         #
         seen = []
-        h = newstacklet(depth1)
+        h = new(depth1)
         assert h is None
         assert seen == [1, 2, 3]
 
     def test_exception_depth2(self):
-        from _stacklet import newstacklet
+        from _continuation import new
         #
         def depth2(h):
             seen.append(2)
@@ -127,18 +148,18 @@
         def depth1(h):
             seen.append(1)
             try:
-                newstacklet(depth2)
+                new(depth2)
             except ValueError:
                 seen.append(3)
             return h
         #
         seen = []
-        h = newstacklet(depth1)
+        h = new(depth1)
         assert h is None
         assert seen == [1, 2, 3]
 
     def test_exception_with_switch(self):
-        from _stacklet import newstacklet
+        from _continuation import new
         #
         def depth1(h):
             seen.append(1)
@@ -147,13 +168,13 @@
             raise ValueError
         #
         seen = []
-        h = newstacklet(depth1)
+        h = new(depth1)
         seen.append(2)
         raises(ValueError, h.switch)
         assert seen == [1, 2, 3]
 
     def test_exception_with_switch_depth2(self):
-        from _stacklet import newstacklet
+        from _continuation import new
         #
         def depth2(h):
             seen.append(4)
@@ -165,7 +186,7 @@
             seen.append(1)
             h = h.switch()
             seen.append(3)
-            h2 = newstacklet(depth2)
+            h2 = new(depth2)
             seen.append(5)
             raises(ValueError, h2.switch)
             assert not h2.is_pending()
@@ -173,7 +194,7 @@
             raise KeyError
         #
         seen = []
-        h = newstacklet(depth1)
+        h = new(depth1)
         seen.append(2)
         raises(KeyError, h.switch)
         assert not h.is_pending()
diff --git a/pypy/module/_stacklet/test/test_translated.py 
b/pypy/module/_continuation/test/test_translated.py
rename from pypy/module/_stacklet/test/test_translated.py
rename to pypy/module/_continuation/test/test_translated.py
diff --git a/pypy/rlib/test/test_rstacklet.py b/pypy/rlib/test/test_rstacklet.py
--- a/pypy/rlib/test/test_rstacklet.py
+++ b/pypy/rlib/test/test_rstacklet.py
@@ -214,7 +214,7 @@
         config = get_pypy_config(translating=True)
         config.translation.gc = cls.gc
         if cls.gcrootfinder is not None:
-            config.translation.stacklet = True
+            config.translation.continuation = True
             config.translation.gcrootfinder = cls.gcrootfinder
             GCROOTFINDER = cls.gcrootfinder
         cls.config = config
diff --git a/pypy/rpython/memory/gctransform/framework.py 
b/pypy/rpython/memory/gctransform/framework.py
--- a/pypy/rpython/memory/gctransform/framework.py
+++ b/pypy/rpython/memory/gctransform/framework.py
@@ -484,7 +484,7 @@
                                     annmodel.SomeInteger())
 
         # thread support
-        if translator.config.translation.stacklet:
+        if translator.config.translation.continuation:
             root_walker.need_stacklet_support()
         if translator.config.translation.thread:
             root_walker.need_thread_support(self, getfn)
diff --git a/pypy/translator/goal/targetpypystandalone.py 
b/pypy/translator/goal/targetpypystandalone.py
--- a/pypy/translator/goal/targetpypystandalone.py
+++ b/pypy/translator/goal/targetpypystandalone.py
@@ -173,15 +173,10 @@
                 # command-line directly instead of via --allworkingmodules.
                 config.objspace.usemodules.thread = False
 
-        if config.translation.stacklet:
+        if config.translation.continuation:
             config.objspace.usemodules._stacklet = True
         elif config.objspace.usemodules._stacklet:
-            try:
-                config.translation.stacklet = True
-            except ConflictConfigError:
-                raise ConflictConfigError("please use the --stacklet option "
-                                          "to translate.py instead of "
-                                          "--withmod-_stacklet directly")
+            config.translation.continuation = True
 
         if not config.translation.rweakref:
             config.objspace.usemodules._weakref = False
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to