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

antocuni at codespeak.net antocuni at codespeak.net
Mon Oct 9 21:20:20 CEST 2006


Author: antocuni
Date: Mon Oct  9 21:20:19 2006
New Revision: 33073

Modified:
   pypy/dist/pypy/rpython/ootypesystem/rbuiltin.py
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
Log:
Set the 'meta' field when calling objmodel.instantiate().



Modified: pypy/dist/pypy/rpython/ootypesystem/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rbuiltin.py	Mon Oct  9 21:20:19 2006
@@ -67,19 +67,25 @@
 
 def rtype_instantiate(hop):
     if hop.args_s[0].is_constant():
-        INSTANCE = hop.s_result.rtyper_makerepr(hop.rtyper).lowleveltype
-        v_instance = hop.inputconst(ootype.Void, INSTANCE)
-        hop2 = hop.copy()
-        hop2.r_s_popfirstarg()
-        s_instance = hop.rtyper.annotator.bookkeeper.immutablevalue(INSTANCE)
-        hop2.v_s_insertfirstarg(v_instance, s_instance)
-        return rtype_new(hop2)
+##        INSTANCE = hop.s_result.rtyper_makerepr(hop.rtyper).lowleveltype
+##        v_instance = hop.inputconst(ootype.Void, INSTANCE)
+##        hop2 = hop.copy()
+##        hop2.r_s_popfirstarg()
+##        s_instance = hop.rtyper.annotator.bookkeeper.immutablevalue(INSTANCE)
+##        hop2.v_s_insertfirstarg(v_instance, s_instance)
+##        return rtype_new(hop2)
+        r_instance = hop.s_result.rtyper_makerepr(hop.rtyper)
+        return r_instance.new_instance(hop.llops)
     else:
-        INSTANCE = hop.s_result.rtyper_makerepr(hop.rtyper).lowleveltype
+        r_instance = hop.s_result.rtyper_makerepr(hop.rtyper)
+        INSTANCE = r_instance.lowleveltype
         c_instance = hop.inputconst(ootype.Void, INSTANCE)
         v_cls = hop.inputarg(hop.args_r[0], arg=0)
         v_obj = hop.gendirectcall(ll_instantiate, c_instance, v_cls)
-        return hop.genop('oodowncast', [v_obj], resulttype=hop.r_result.lowleveltype)
+        v_instance = hop.genop('oodowncast', [v_obj], resulttype=hop.r_result.lowleveltype)
+        c_meta = hop.inputconst(ootype.Void, "meta")
+        hop.genop("oosetfield", [v_instance, c_meta, v_cls], resulttype=ootype.Void)
+        return v_instance
 
 def ll_instantiate(INST, C):
     return ootype.runtimenew(C.class_)

Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py	Mon Oct  9 21:20:19 2006
@@ -391,3 +391,25 @@
     
 class TestOOtype(BaseTestRbuiltin, OORtypeMixin):
     from pypy.rpython.ootypesystem.module import ll_os
+
+    def test_instantiate_meta(self):
+        class A:
+            pass
+        def f():
+            return instantiate(A)
+        res = self.interpret(f, [])
+        assert res.meta # check that it's not null
+
+    def test_instantiate_multiple_meta(self):
+        class A:
+            pass
+        class B(A):
+            pass
+        def f(i):
+            if i == 1:
+                cls = A
+            else:
+                cls = B
+            return instantiate(cls)
+        res = self.interpret(f, [1])
+        assert res.meta # check that it's not null



More information about the Pypy-commit mailing list