[pypy-svn] r37396 - in pypy/dist/pypy: annotation rpython/ootypesystem translator/cli translator/cli/test

antocuni at codespeak.net antocuni at codespeak.net
Fri Jan 26 16:35:43 CET 2007


Author: antocuni
Date: Fri Jan 26 16:35:42 2007
New Revision: 37396

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/rpython/ootypesystem/rootype.py
   pypy/dist/pypy/translator/cli/dotnet.py
   pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
Use SomeCliInstance instead of SomeOOInstance was not a good
idea. Revert to the old behaviour and add support for nullable
SomeOOInstance.



Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Fri Jan 26 16:35:42 2007
@@ -753,6 +753,8 @@
 from pypy.annotation.model import ll_to_annotation, annotation_to_lltype
 from pypy.rpython.ootypesystem import ootype
 
+_make_none_union('SomeOOInstance', 'ootype=obj.ootype, can_be_None=True')
+
 class __extend__(pairtype(SomePtr, SomePtr)):
     def union((p1, p2)):
         assert p1.ll_ptrtype == p2.ll_ptrtype,("mixing of incompatible pointer types: %r, %r" %

Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Fri Jan 26 16:35:42 2007
@@ -541,8 +541,9 @@
         self.ootype = ootype
 
 class SomeOOInstance(SomeObject):
-    def __init__(self, ootype):
+    def __init__(self, ootype, can_be_None=False):
         self.ootype = ootype
+        self.can_be_None = can_be_None
 
 class SomeOOBoundMeth(SomeObject):
     immutable = True

Modified: pypy/dist/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rootype.py	Fri Jan 26 16:35:42 2007
@@ -62,6 +62,12 @@
         vlist = hop.inputargs(self)
         return hop.genop('oononnull', vlist, resulttype=ootype.Bool)
 
+    def convert_const(self, value):
+        if value is None:
+            return ootype.null(self.lowleveltype)
+        else:
+            return Repr.convert_const(self, value)
+
 
 class __extend__(pairtype(OOInstanceRepr, OOInstanceRepr)):
     def rtype_is_((r_ins1, r_ins2), hop):

Modified: pypy/dist/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/dotnet.py	(original)
+++ pypy/dist/pypy/translator/cli/dotnet.py	Fri Jan 26 16:35:42 2007
@@ -24,7 +24,7 @@
 
     def simple_call(self, *s_args):
         assert self.is_constant()
-        return SomeCliInstance(self.const._INSTANCE)
+        return SomeOOInstance(self.const._INSTANCE)
 
     def rtyper_makerepr(self, rtyper):
         return CliClassRepr(self.const)
@@ -48,23 +48,10 @@
         return self.__class__, self.cli_class, self.meth_name
 
 
-class SomeCliInstance(SomeOOInstance):
-    def __init__(self, ootype, can_be_None=False):
-        SomeOOInstance.__init__(self, ootype)
-        self.can_be_None= can_be_None
-
-    def __repr__(self):
-        return '%s(%s, can_be_None=%s)' % (self.__class__.__name__, self.ootype, self.can_be_None)
-
-    def rtyper_makerepr(self, rtyper):
-        return CliInstanceRepr(self.ootype)
-
-_make_none_union('SomeCliInstance', 'ootype=obj.ootype, can_be_None=True', globals())
-
-class __extend__(pairtype(SomeCliInstance, SomeInteger)):
+class __extend__(pairtype(SomeOOInstance, SomeInteger)):
     def getitem((ooinst, index)):
         if ooinst.ootype._isArray:
-            return SomeCliInstance(ooinst.ootype._ELEMENT)
+            return SomeOOInstance(ooinst.ootype._ELEMENT)
         return s_ImpossibleValue
 
     def setitem((ooinst, index), s_value):
@@ -115,14 +102,8 @@
         cDesc = hop.inputconst(ootype.Void, desc)
         return hop.genop("direct_call", [cDesc] + vlist, resulttype=resulttype)
 
-class CliInstanceRepr(OOInstanceRepr):
-    def convert_const(self, value):
-        if value is None:
-            return ootype.null(self.lowleveltype)
-        else:
-            return OOInstanceRepr.convert_const(self, value)
 
-class __extend__(pairtype(CliInstanceRepr, IntegerRepr)):
+class __extend__(pairtype(OOInstanceRepr, IntegerRepr)):
 
     def rtype_getitem((r_inst, r_int), hop):
         if not r_inst.lowleveltype._isArray:
@@ -160,7 +141,7 @@
 
     def lltype_to_annotation(cls, TYPE):
         if isinstance(TYPE, NativeInstance):
-            return SomeCliInstance(TYPE)
+            return SomeOOInstance(TYPE)
         elif TYPE is ootype.Char:
             return SomeChar()
         elif TYPE is ootype.String:
@@ -339,7 +320,7 @@
     _about_ = box
 
     def compute_result_annotation(self, x_s):
-        return SomeCliInstance(CLR.System.Object._INSTANCE)
+        return SomeOOInstance(CLR.System.Object._INSTANCE)
 
     def specialize_call(self, hop):
         v_obj, = hop.inputargs(*hop.args_r)
@@ -358,7 +339,7 @@
     _about_ = unbox
 
     def compute_result_annotation(self, x_s, type_s):
-        assert isinstance(x_s, SomeCliInstance)
+        assert isinstance(x_s, SomeOOInstance)
         assert x_s.ootype == CLR.System.Object._INSTANCE
         assert type_s.is_constant()
         TYPE = type_s.const
@@ -406,7 +387,7 @@
         cls = exc_s.classdef.classdesc.pyobj
         assert issubclass(cls, Exception)
         NATIVE_INSTANCE = cls._rpython_hints['NATIVE_INSTANCE']
-        return SomeCliInstance(NATIVE_INSTANCE)
+        return SomeOOInstance(NATIVE_INSTANCE)
 
     def specialize_call(self, hop):
         v_obj, = hop.inputargs(*hop.args_r)
@@ -429,7 +410,7 @@
         TYPE = type_s.const._INSTANCE
         fullname = '%s.%s[]' % (TYPE._namespace, TYPE._classname)
         cliArray = load_class_maybe(fullname)
-        return SomeCliInstance(cliArray._INSTANCE)
+        return SomeOOInstance(cliArray._INSTANCE)
 
     def specialize_call(self, hop):
         c_type, v_length = hop.inputargs(*hop.args_r)
@@ -450,7 +431,7 @@
                       (i, TYPE, arg_s.ootype)
         fullname = '%s.%s[]' % (TYPE._namespace, TYPE._classname)
         cliArray = load_class_maybe(fullname)
-        return SomeCliInstance(cliArray._INSTANCE)
+        return SomeOOInstance(cliArray._INSTANCE)
 
     def specialize_call(self, hop):
         vlist = hop.inputargs(*hop.args_r)
@@ -476,7 +457,7 @@
         from query import load_class_maybe
         assert cliClass_s.is_constant()
         cliType = load_class_maybe('System.Type')
-        return SomeCliInstance(cliType._INSTANCE)
+        return SomeOOInstance(cliType._INSTANCE)
 
     def specialize_call(self, hop):
         v_type, = hop.inputargs(*hop.args_r)

Modified: pypy/dist/pypy/translator/cli/test/test_dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_dotnet.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_dotnet.py	Fri Jan 26 16:35:42 2007
@@ -5,7 +5,7 @@
 from pypy.rpython.ootypesystem.ootype import meth, Meth, Char, Signed, Float, String,\
      ROOT, overload, Instance, new
 from pypy.translator.cli.test.runtest import CliTest
-from pypy.translator.cli.dotnet import SomeCliClass, SomeCliStaticMethod, SomeCliInstance,\
+from pypy.translator.cli.dotnet import SomeCliClass, SomeCliStaticMethod,\
      NativeInstance, CLR, box, unbox, OverloadingResolver, NativeException,\
      native_exc, new_array, init_array, typeof
 
@@ -74,7 +74,7 @@
             return ArrayList()
         a = RPythonAnnotator()
         s = a.build_types(fn, [])
-        assert isinstance(s, SomeCliInstance)
+        assert isinstance(s, annmodel.SomeOOInstance)
         assert isinstance(s.ootype, NativeInstance)
         assert s.ootype._name == '[mscorlib]System.Collections.ArrayList'
 
@@ -83,7 +83,7 @@
             return box(42)
         a = RPythonAnnotator()
         s = a.build_types(fn, [])
-        assert isinstance(s, SomeCliInstance)
+        assert isinstance(s, annmodel.SomeOOInstance)
         assert s.ootype._name == '[mscorlib]System.Object'
 
     def test_unbox(self):
@@ -100,7 +100,7 @@
             return x.ToArray()
         a = RPythonAnnotator()
         s = a.build_types(fn, [])
-        assert isinstance(s, SomeCliInstance)
+        assert isinstance(s, annmodel.SomeOOInstance)
         assert s.ootype._isArray
         assert s.ootype._ELEMENT._name == '[mscorlib]System.Object'
 
@@ -110,7 +110,7 @@
             return x[0]
         a = RPythonAnnotator()
         s = a.build_types(fn, [])
-        assert isinstance(s, SomeCliInstance)
+        assert isinstance(s, annmodel.SomeOOInstance)
         assert s.ootype._name == '[mscorlib]System.Object'
 
     def test_mix_None_and_instance(self):
@@ -121,7 +121,7 @@
                 return box(42)
         a = RPythonAnnotator()
         s = a.build_types(fn, [bool])
-        assert isinstance(s, SomeCliInstance)
+        assert isinstance(s, annmodel.SomeOOInstance)
         assert s.can_be_None == True
 
 
@@ -297,11 +297,14 @@
         assert res is True
 
     def test_mix_None_and_instance(self):
-        def fn(x):
-            if x:
-                return None
+        def g(x):
+            return x
+        def fn(flag):
+            if flag:
+                x = None
             else:
-                return box(42)
+                x = box(42)
+            return g(x)
         res = self.interpret(fn, [1])
         assert res is None
 



More information about the Pypy-commit mailing list