[pypy-svn] r28455 - in pypy/dist/pypy/translator/cli: . src

antocuni at codespeak.net antocuni at codespeak.net
Wed Jun 7 16:10:44 CEST 2006


Author: antocuni
Date: Wed Jun  7 16:10:43 2006
New Revision: 28455

Modified:
   pypy/dist/pypy/translator/cli/cts.py
   pypy/dist/pypy/translator/cli/database.py
   pypy/dist/pypy/translator/cli/oopspec.py
   pypy/dist/pypy/translator/cli/src/pypylib.cs
Log:
(antocuni, arigo)

Handle List of Void correctly.

The problem is that .NET don't allow us to use the void type as a real
type, so we have to workaround this. The solution for List(Void) is to
have a special-cased class whose methods don't take care of parameters
of ITEMTYPE type, then we special-cased some place for taking care of
this.

Probably in the future we will need a similar solution for Dict with
Void keys or values, and so on.



Modified: pypy/dist/pypy/translator/cli/cts.py
==============================================================================
--- pypy/dist/pypy/translator/cli/cts.py	(original)
+++ pypy/dist/pypy/translator/cli/cts.py	Wed Jun  7 16:10:43 2006
@@ -15,6 +15,7 @@
 py.log.setconsumer("cli", ansi_log) 
 
 PYPY_LIST = '[pypylib]pypy.runtime.List`1<%s>'
+PYPY_LIST_OF_VOID = '[pypylib]pypy.runtime.ListOfVoid'
 PYPY_DICT = '[pypylib]pypy.runtime.Dict`2<%s, %s>'
 PYPY_DICT_ITEMS_ITERATOR = '[pypylib]pypy.runtime.DictItemsIterator`2<%s, %s>'
 
@@ -76,12 +77,11 @@
             name = self.db.pending_record(t)
             return self.__class(name, include_class)
         elif isinstance(t, ootype.StaticMethod):
-            #return 'void' # TODO: is it correct to ignore StaticMethod?
             return self.db.record_delegate_type(t)
         elif isinstance(t, ootype.List):
             item_type = self.lltype_to_cts(t._ITEMTYPE)
-            if item_type == 'void': # special case: CLI doesn't allow List of void; use int instead
-                item_type = 'int32'
+            if item_type == 'void': # special case: List of Void
+                return PYPY_LIST_OF_VOID
             return self.__class(PYPY_LIST % item_type, include_class)
         elif isinstance(t, ootype.Dict):
             key_type = self.lltype_to_cts(t._KEYTYPE)
@@ -131,7 +131,7 @@
                 METH = oopspec.get_method(TYPE, name)
             class_name = self.lltype_to_cts(TYPE)
             ret_type = self.lltype_to_cts(METH.RESULT)
-            arg_types = [self.lltype_to_cts(arg) for arg in METH.ARGS]
+            arg_types = [self.lltype_to_cts(arg) for arg in METH.ARGS if arg is not ootype.Void]
             arg_list = ', '.join(arg_types)
             return '%s %s::%s(%s)' % (ret_type, class_name, name, arg_list), False
 

Modified: pypy/dist/pypy/translator/cli/database.py
==============================================================================
--- pypy/dist/pypy/translator/cli/database.py	(original)
+++ pypy/dist/pypy/translator/cli/database.py	Wed Jun  7 16:10:43 2006
@@ -1,4 +1,4 @@
-from pypy.translator.cli.cts import CTS
+from pypy.translator.cli.cts import CTS, PYPY_LIST_OF_VOID
 from pypy.translator.cli.function import Function
 from pypy.translator.cli.class_ import Class
 from pypy.translator.cli.record import Record
@@ -336,7 +336,7 @@
         if ITEMTYPE is ootype.Void:
             ilasm.opcode('dup')
             AbstractConst.load(self.db, ootype.Signed, len(self.list._list), ilasm)            
-            meth = 'void class [pypylib]pypy.runtime.List`1<int32>::_ll_resize(int32)'
+            meth = 'void class %s::_ll_resize(int32)' % PYPY_LIST_OF_VOID
             ilasm.call_method(meth, False)
             return
         

Modified: pypy/dist/pypy/translator/cli/oopspec.py
==============================================================================
--- pypy/dist/pypy/translator/cli/oopspec.py	(original)
+++ pypy/dist/pypy/translator/cli/oopspec.py	Wed Jun  7 16:10:43 2006
@@ -1,4 +1,4 @@
-from pypy.rpython.ootypesystem.ootype import List, Meth, Void
+from pypy.rpython.ootypesystem import ootype
 
 def get_method_name(graph, op):
     try:
@@ -29,19 +29,24 @@
     else:
         return None # explicit is better than implicit :-)
 
-def get_method(obj, name):
+def get_method(TYPE, name):
     try:
-        return obj._GENERIC_METHODS[name]
+        # special case: when having List of Void, look at the concrete
+        # methods, not the generic ones
+        if isinstance(TYPE, ootype.List) and TYPE._ITEMTYPE is ootype.Void:
+            return TYPE._METHODS[name]
+        else:
+            return TYPE._GENERIC_METHODS[name]
     except KeyError:
-        t = type(obj)
+        t = type(TYPE)
         return BUILTIN_METHODS[t][name]
 
 BUILTIN_TYPES = {
-    'list': List
+    'list': ootype.List
     }
 
 BUILTIN_METHODS = {
-    List : {
-        'Add': Meth([List.ITEMTYPE_T], Void)
+    ootype.List : {
+        'Add': ootype.Meth([ootype.List.ITEMTYPE_T], ootype.Void)
         }
     } 

Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/pypylib.cs	(original)
+++ pypy/dist/pypy/translator/cli/src/pypylib.cs	Wed Jun  7 16:10:43 2006
@@ -94,28 +94,28 @@
                 this.RemoveRange(length, diff);
             }
         }
+    }
 
-        /*
-        public void append(T item)
-        {
-            this.Add(item);
-        }
-
-        public void extend(List<T> other)
-        {
-            this.AddRange(other);
-        }
-
-        public void remove_range(int start, int count)
-        {
-            this.RemoveRange(start, count);
-        }
+    public class ListOfVoid
+    {
+        int Count = 0;
 
-        public int index(T item)
+        public override string ToString()
         {
-            return this.IndexOf(item);
-        }
-        */
+            // TODO: use StringBuilder instead
+            string res = "[";
+            for(int i=0; i<this.Count; i++)
+                res += "None, ";
+            res += "]";
+            return res;
+        }
+
+        public int ll_length() { return this.Count; }
+        public void ll_getitem_fast(int index) { }
+        public void ll_setitem_fast(int index) { }
+        public void _ll_resize(int length) { this.Count = length; }
+        public void _ll_resize_ge(int length) { this.Count = length; }
+        public void _ll_resize_le(int length) { this.Count = length; }
     }
 
     public class Dict<TKey, TValue>: System.Collections.Generic.Dictionary<TKey, TValue>



More information about the Pypy-commit mailing list