[pypy-commit] pypy default: Progress.

arigo noreply at buildbot.pypy.org
Wed Dec 7 17:40:00 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r50257:65c9c70b487b
Date: 2011-12-07 14:29 +0100
http://bitbucket.org/pypy/pypy/changeset/65c9c70b487b/

Log:	Progress.

diff --git a/pypy/objspace/fake/checkmodule.py b/pypy/objspace/fake/checkmodule.py
--- a/pypy/objspace/fake/checkmodule.py
+++ b/pypy/objspace/fake/checkmodule.py
@@ -1,7 +1,50 @@
-from pypy.objspace.fake.objspace import FakeObjSpace
-from pypy.translator.driver import TranslationDriver
+from pypy.objspace.fake.objspace import FakeObjSpace, W_Root, is_root
+from pypy.interpreter import gateway
+
+
+class ModuleChecker(object):
+
+    def __init__(self):
+        self.space = FakeObjSpace()
+
+    def load_module(self, modname):
+        space = self.space
+        mod = __import__('pypy.module.%s' % modname, None, None, ['__doc__'])
+        # force computation and record what we wrap
+        del space.seen_wrap[:]
+        module = mod.Module(space, W_Root())
+        for name in module.loaders:
+            module._load_lazily(space, name)
+        self.seen = space.seen_wrap[:]
+
+    def collect_entry_points(self):
+        self.entry_points = []
+        for value in self.seen:
+            if isinstance(value, gateway.interp2app):
+                self.collect_interp2app(value)
+
+    def collect_interp2app(self, interp2app):
+        space = self.space
+        activation = interp2app._code.activation
+        scopelen = interp2app._code.sig.scope_length()
+        scope_w = [W_Root()] * scopelen
+        #
+        def check():
+            w_result = activation._run(space, scope_w)
+            is_root(w_result)
+        #
+        self.entry_points.append(check)
+
+    def check_translates(self):
+        def entry_point():
+            for fn in entry_points:
+                fn()
+        entry_points = self.entry_points
+        self.space.translates(entry_point)
 
 
 def checkmodule(modname):
-    space = FakeObjSpace()
-    xxx
+    checker = ModuleChecker()
+    checker.load_module(modname)
+    checker.collect_entry_points()
+    checker.check_translates()
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -1,19 +1,29 @@
 from pypy.interpreter.baseobjspace import W_Root, ObjSpace
+from pypy.interpreter import argument
 from pypy.translator.driver import TranslationDriver
 from pypy.annotation.model import SomeInstance, s_None
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.rpython.lltypesystem import lltype
 from pypy.tool.sourcetools import compile2, func_with_new_name
+from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib.objectmodel import we_are_translated
 
 
 def is_root(w_obj):
     assert isinstance(w_obj, W_Root)
+is_root.expecting = W_Root
+
+def is_arguments(arg):
+    assert isinstance(arg, argument.Arguments)
+is_arguments.expecting = argument.Arguments
+
 
 class Entry(ExtRegistryEntry):
-    _about_ = is_root
+    _about_ = is_root, is_arguments
 
     def compute_result_annotation(self, s_w_obj):
-        s_inst = SomeInstance(self.bookkeeper.getuniqueclassdef(W_Root),
+        cls = self.instance.expecting
+        s_inst = SomeInstance(self.bookkeeper.getuniqueclassdef(cls),
                               can_be_None=True)
         assert s_inst.contains(s_w_obj)
         return s_None
@@ -26,6 +36,35 @@
 
 class FakeObjSpace(ObjSpace):
 
+    def __init__(self):
+        self.seen_wrap = []
+        ObjSpace.__init__(self)
+
+    w_None = W_Root()
+    w_False = W_Root()
+    w_True = W_Root()
+
+    def newdict(self, module=False, instance=False, classofinstance=None,
+                strdict=False):
+        return W_Root()
+
+    def wrap(self, x):
+        if not we_are_translated():
+            self.seen_wrap.append(x)
+        return W_Root()
+    wrap._annspecialcase_ = "specialize:argtype(1)"
+
+    def call_args(self, w_func, args):
+        is_root(w_func)
+        is_arguments(args)
+        return W_Root()
+
+    def gettypefor(self, cls):
+        assert issubclass(cls, W_Root)
+        return W_Root()
+
+    # ----------
+
     def translates(self, func, argtypes=None):
         if argtypes is None:
             nb_args = func.func_code.co_argcount
diff --git a/pypy/objspace/fake/test/test_checkmodule.py b/pypy/objspace/fake/test/test_checkmodule.py
new file mode 100644
--- /dev/null
+++ b/pypy/objspace/fake/test/test_checkmodule.py
@@ -0,0 +1,5 @@
+from pypy.objspace.fake.checkmodule import checkmodule
+
+
+def test_itertools_module():
+    checkmodule('itertools')
diff --git a/pypy/objspace/fake/test/test_objspace.py b/pypy/objspace/fake/test/test_objspace.py
--- a/pypy/objspace/fake/test/test_objspace.py
+++ b/pypy/objspace/fake/test/test_objspace.py
@@ -27,3 +27,17 @@
                     getattr(space, name)(*args_w)
             #
             space.translates(f)
+
+    def test_newdict(self):
+        space = self.space
+        space.translates(lambda: (space.newdict(),
+                                  space.newdict(strdict=True)))
+
+    def test_constants(self):
+        space = self.space
+        space.translates(lambda: (space.w_None, space.w_True, space.w_False))
+
+    def test_wrap(self):
+        space = self.space
+        space.translates(lambda: (space.wrap(42), space.wrap(42.5),
+                                  space.wrap("foo")))


More information about the pypy-commit mailing list