Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r50265:90f0debd374c
Date: 2011-12-07 16:00 +0100
http://bitbucket.org/pypy/pypy/changeset/90f0debd374c/

Log:    Some progress.

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,4 +1,5 @@
-from pypy.interpreter.baseobjspace import W_Root, ObjSpace, SpaceCache
+from pypy.interpreter.baseobjspace import W_Root, ObjSpace
+from pypy.interpreter.baseobjspace import Wrappable, SpaceCache
 from pypy.interpreter import argument, gateway
 from pypy.interpreter.typedef import TypeDef
 from pypy.annotation.model import SomeInstance, s_None
@@ -6,12 +7,64 @@
 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
+from pypy.rlib.objectmodel import instantiate, we_are_translated
 from pypy.rlib.nonconst import NonConstant
 from pypy.rlib.rarithmetic import r_uint
 from pypy.translator.translator import TranslationContext
 
 
+class W_MyObject(Wrappable):
+    typedef = None
+
+    def getdict(self, space):
+        return w_obj_or_none()
+
+    def getdictvalue(self, space, attr):
+        attr + "xx"   # check that it's a string
+        return w_obj_or_none()
+
+    def setdictvalue(self, space, attr, w_value):
+        attr + "xx"   # check that it's a string
+        is_root(w_value)
+        return NonConstant(True)
+
+    def deldictvalue(self, space, attr):
+        attr + "xx"   # check that it's a string
+        return NonConstant(True)
+
+    def setdict(self, space, w_dict):
+        is_root(w_dict)
+
+    def setclass(self, space, w_subtype):
+        is_root(w_subtype)
+
+    def str_w(self, space):
+        return NonConstant("foobar")
+
+    def unicode_w(self, space):
+        return NonConstant(u"foobar")
+
+    def int_w(self, space):
+        return NonConstant(-42)
+    
+    def uint_w(self, space):
+        return r_uint(NonConstant(42))
+    
+    def bigint_w(self, space):
+        from pypy.rlib.rbigint import rbigint
+        return rbigint.fromint(NonConstant(42))
+
+
+def w_some_obj():
+    if NonConstant(False):
+        return W_Root()
+    return W_MyObject()
+
+def w_obj_or_none():
+    if NonConstant(False):
+        return None
+    return w_some_obj()
+
 def is_root(w_obj):
     assert isinstance(w_obj, W_Root)
 is_root.expecting = W_Root
@@ -43,31 +96,10 @@
         self._seen_extras = []
         ObjSpace.__init__(self)
 
-    def str_w(self, w_obj):
-        is_root(w_obj)
-        return NonConstant("foobar")
-
-    def int_w(self, w_obj):
-        is_root(w_obj)
-        return NonConstant(-42)
-
     def float_w(self, w_obj):
         is_root(w_obj)
         return NonConstant(42.5)
 
-    def uint_w(self, w_obj):
-        is_root(w_obj)
-        return r_uint(NonConstant(42))
-
-    def bigint_w(self, w_obj):
-        from pypy.rlib.rbigint import rbigint
-        is_root(w_obj)
-        return rbigint.fromint(NonConstant(42))
-
-    def unicode_w(self, w_obj):
-        is_root(w_obj)
-        return NonConstant(u"foobar")
-
     def is_true(self, w_obj):
         is_root(w_obj)
         return NonConstant(False)
@@ -78,21 +110,21 @@
 
     def newdict(self, module=False, instance=False, classofinstance=None,
                 strdict=False):
-        return W_Root()
+        return w_some_obj()
 
     def newtuple(self, list_w):
         is_root(list_w[NonConstant(0)])
-        return W_Root()
+        return w_some_obj()
 
     def newlist(self, list_w):
         is_root(list_w[NonConstant(0)])
-        return W_Root()
+        return w_some_obj()
 
     def newslice(self, w_start, w_end, w_step):
         is_root(w_start)
         is_root(w_end)
         is_root(w_step)
-        return W_Root()
+        return w_some_obj()
 
     def marshal_w(self, w_obj):
         "NOT_RPYTHON"
@@ -101,14 +133,14 @@
     def wrap(self, x):
         if isinstance(x, gateway.interp2app):
             self._see_interp2app(x)
-        return W_Root()
+        return w_some_obj()
     wrap._annspecialcase_ = "specialize:argtype(1)"
 
     def _see_interp2app(self, interp2app):
         "NOT_RPYTHON"
         activation = interp2app._code.activation
         def check():
-            scope_w = [W_Root()] * NonConstant(42)
+            scope_w = [w_some_obj()] * NonConstant(42)
             w_result = activation._run(self, scope_w)
             is_root(w_result)
         check = func_with_new_name(check, 'check__' + interp2app.name)
@@ -117,23 +149,25 @@
     def call_args(self, w_func, args):
         is_root(w_func)
         is_arguments(args)
-        return W_Root()
+        return w_some_obj()
 
     def gettypefor(self, cls):
         return self.gettypeobject(cls.typedef)
 
     def gettypeobject(self, typedef):
+        assert typedef is not None
         return self.fromcache(TypeCache).getorbuild(typedef)
 
     def unpackiterable(self, w_iterable, expected_length=-1):
         is_root(w_iterable)
         if expected_length < 0:
             expected_length = 3
-        return [W_Root()] * expected_length
+        return [w_some_obj()] * expected_length
 
     def allocate_instance(self, cls, w_subtype):
-        "NOT_RPYTHON"
-        xxx
+        is_root(w_subtype)
+        return instantiate(cls)
+    allocate_instance._annspecialcase_ = "specialize:arg(1)"
 
     # ----------
 
@@ -173,16 +207,16 @@
     for name in (ObjSpace.ConstantTable +
                  ObjSpace.ExceptionTable +
                  ['int', 'str', 'float', 'long', 'tuple', 'list', 'dict']):
-        setattr(FakeObjSpace, 'w_' + name, W_Root())
+        setattr(FakeObjSpace, 'w_' + name, w_some_obj())
     #
     for (name, _, arity, _) in ObjSpace.MethodTable:
         args = ['w_%d' % i for i in range(arity)]
         d = {'is_root': is_root,
-             'W_Root': W_Root}
+             'w_some_obj': w_some_obj}
         exec compile2("""\
             def meth(self, %s):
                 %s
-                return W_Root()
+                return w_some_obj()
         """ % (', '.join(args),
                '; '.join(['is_root(%s)' % arg for arg in args]))) in d
         meth = func_with_new_name(d['meth'], name)
@@ -200,4 +234,4 @@
         assert isinstance(typedef, TypeDef)
         for value in typedef.rawdict.values():
             cache.space.wrap(value)
-        return W_Root()
+        return w_some_obj()
diff --git a/pypy/objspace/fake/test/test_checkmodule.py 
b/pypy/objspace/fake/test/test_checkmodule.py
--- a/pypy/objspace/fake/test/test_checkmodule.py
+++ b/pypy/objspace/fake/test/test_checkmodule.py
@@ -52,5 +52,6 @@
     space.translates()
     assert check
 
+
 def test_itertools_module():
     checkmodule('itertools')
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to