[pypy-svn] r23714 - in pypy/dist/pypy/rpython: ootypesystem test

nik at codespeak.net nik at codespeak.net
Tue Feb 28 00:12:11 CET 2006


Author: nik
Date: Tue Feb 28 00:12:01 2006
New Revision: 23714

Modified:
   pypy/dist/pypy/rpython/ootypesystem/rclass.py
   pypy/dist/pypy/rpython/ootypesystem/rpbc.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
(pedronis, nik)
change rpython/test_rpbc to run tests with both lltypesystem and ootypesystem
(only some for now, ultimately all of them). add simple_call __init__ support
to ootype.


Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rclass.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py	Tue Feb 28 00:12:01 2006
@@ -119,7 +119,14 @@
                 if mangled in allmethods:
                     raise TyperError("class attribute overrides method")
                 allclassattributes[mangled] = name, s_value
-                                
+
+        if '__init__' not in selfattrs and \
+                self.classdef.classdesc.find_source_for("__init__") is not None:
+            s_init = self.classdef.classdesc.s_get_value(self.classdef,
+                    '__init__')
+            mangled = mangle("__init__")
+            allmethods[mangled] = "__init__", s_init
+            
         #
         # hash() support
         if self.rtyper.needs_hash_support(self.classdef):

Modified: pypy/dist/pypy/rpython/ootypesystem/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rpbc.py	Tue Feb 28 00:12:01 2006
@@ -4,6 +4,7 @@
 from pypy.rpython.ootypesystem import ootype
 from pypy.rpython.ootypesystem.rclass import ClassRepr, InstanceRepr, mangle
 from pypy.rpython.ootypesystem.rclass import rtype_classes_is_
+from pypy.annotation import model as annmodel
 from pypy.annotation.pairtype import pairtype
 
 class ClassesPBCRepr(AbstractClassesPBCRepr):
@@ -15,6 +16,15 @@
             return hop.genop('runtimenew', [vclass], resulttype=resulttype)
 
         v_instance = rtype_new_instance(hop.rtyper, classdef, hop.llops)
+        s_init = classdef.classdesc.s_read_attribute('__init__')
+        if not isinstance(s_init, annmodel.SomeImpossibleValue):
+            vlist = hop.inputargs(self, *hop.args_r[1:])
+            mangled = mangle("__init__")
+            cname = hop.inputconst(ootype.Void, mangled)
+            hop.genop("oosend", [cname, v_instance] + vlist[1:],
+                    resulttype=ootype.Void)
+        else:
+            assert hop.nb_args == 1
         return v_instance
 
 class MethodImplementations(object):

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Tue Feb 28 00:12:01 2006
@@ -3,31 +3,6 @@
 from pypy.rpython.test.test_llinterp import interpret
 
 
-def test_easy_call():
-    def f(x):
-        return x+1
-    def g(y):
-        return f(y+2)
-    res = interpret(g, [5])
-    assert res == 8
-
-def test_multiple_call():
-    def f1(x):
-        return x+1
-    def f2(x):
-        return x+2
-    def g(y):
-        if y < 0:
-            f = f1
-        else:
-            f = f2
-        return f(y+3)
-    res = interpret(g, [-1])
-    assert res == 3
-    res = interpret(g, [1])
-    assert res == 6
-
-
 class MyBase:
     def m(self, x):
         return self.z + x
@@ -40,44 +15,6 @@
     def m(self, x, y):
         return x*y
 
-def test_method_call():
-    def f(a, b):
-        obj = MyBase()
-        obj.z = a
-        return obj.m(b)
-    res = interpret(f, [4, 5])
-    assert res == 9
-
-def test_virtual_method_call():
-    def f(a, b):
-        if a > 0:
-            obj = MyBase()
-        else:
-            obj = MySubclass()
-        obj.z = a
-        return obj.m(b)
-    res = interpret(f, [1, 2.3])
-    assert res == 3.3
-    res = interpret(f, [-1, 2.3])
-    assert res == -3.3
-
-def test_stranger_subclass_1():
-    def f1():
-        obj = MyStrangerSubclass()
-        obj.z = 100
-        return obj.m(6, 7)
-    res = interpret(f1, [])
-    assert res == 42
-
-def test_stranger_subclass_2():
-    def f2():
-        obj = MyStrangerSubclass()
-        obj.z = 100
-        return obj.m(6, 7) + MyBase.m(obj, 58)
-    res = interpret(f2, [])
-    assert res == 200
-
-
 class MyBaseWithInit:
     def __init__(self, a):
         self.a1 = a
@@ -87,11 +24,90 @@
         MyBaseWithInit.__init__(self, a)
         self.b1 = b
 
-def test_class_init():
-    def f(a):
-        instance = MyBaseWithInit(a)
-        return instance.a1
-    assert interpret(f, [5]) == 5
+
+class BaseTestRPBC:
+
+    def test_easy_call(self):
+        def f(x):
+            return x+1
+        def g(y):
+            return f(y+2)
+        res = interpret(g, [5], type_system=self.ts)
+        assert res == 8
+
+    def test_multiple_call(self):
+        def f1(x):
+            return x+1
+        def f2(x):
+            return x+2
+        def g(y):
+            if y < 0:
+                f = f1
+            else:
+                f = f2
+            return f(y+3)
+        res = interpret(g, [-1], type_system=self.ts)
+        assert res == 3
+        res = interpret(g, [1], type_system=self.ts)
+        assert res == 6
+
+
+    def test_method_call(self):
+        def f(a, b):
+            obj = MyBase()
+            obj.z = a
+            return obj.m(b)
+        res = interpret(f, [4, 5], type_system=self.ts)
+        assert res == 9
+
+    def test_virtual_method_call(self):
+        def f(a, b):
+            if a > 0:
+                obj = MyBase()
+            else:
+                obj = MySubclass()
+            obj.z = a
+            return obj.m(b)
+        res = interpret(f, [1, 2.3], type_system=self.ts)
+        assert res == 3.3
+        res = interpret(f, [-1, 2.3], type_system=self.ts)
+        assert res == -3.3
+
+    def test_stranger_subclass_1(self):
+        def f1():
+            obj = MyStrangerSubclass()
+            obj.z = 100
+            return obj.m(6, 7)
+        res = interpret(f1, [], type_system=self.ts)
+        assert res == 42
+
+    def test_stranger_subclass_2(self):
+        def f2():
+            obj = MyStrangerSubclass()
+            obj.z = 100
+            return obj.m(6, 7) + MyBase.m(obj, 58)
+        res = interpret(f2, [], type_system=self.ts)
+        assert res == 200
+
+
+    def test_class_init(self):
+        def f(a):
+            instance = MyBaseWithInit(a)
+            return instance.a1
+        assert interpret(f, [5], type_system=self.ts) == 5
+
+    def test_class_init_2(self):
+        def f(a, b):
+            instance = MySubclassWithInit(a, b)
+            return instance.a1 * instance.b1
+        assert interpret(f, [6, 7], type_system=self.ts) == 42
+
+    def test_class_calling_init(self):
+        def f():
+            instance = MySubclassWithInit(1, 2)
+            instance.__init__(3, 4)
+            return instance.a1 * instance.b1
+        assert interpret(f, [], type_system=self.ts) == 12
 
 def test_class_init_w_kwds():
     def f(a):
@@ -99,25 +115,12 @@
         return instance.a1
     assert interpret(f, [5]) == 5
 
-def test_class_init_2():
-    def f(a, b):
-        instance = MySubclassWithInit(a, b)
-        return instance.a1 * instance.b1
-    assert interpret(f, [6, 7]) == 42
-
 def test_class_init_2_w_kwds():
     def f(a, b):
         instance = MySubclassWithInit(a, b=b)
         return instance.a1 * instance.b1
     assert interpret(f, [6, 7]) == 42
 
-def test_class_calling_init():
-    def f():
-        instance = MySubclassWithInit(1, 2)
-        instance.__init__(3, 4)
-        return instance.a1 * instance.b1
-    assert interpret(f, []) == 12
-
 
 class Freezing:
     def _freeze_(self):
@@ -1308,3 +1311,13 @@
     for i in [0, 1]:
         res = interpret(f, [i, 1234])
         assert res == f(i, 1234)
+
+
+class TestLltype(BaseTestRPBC):
+
+    ts = "lltype"
+
+class TestOotype(BaseTestRPBC):
+
+    ts = "ootype"
+



More information about the Pypy-commit mailing list