[pypy-svn] r23785 - in pypy/dist/pypy: rpython/lltypesystem rpython/lltypesystem/test rpython/rctypes/test translator/c translator/c/test

goden at codespeak.net goden at codespeak.net
Tue Feb 28 22:05:26 CET 2006


Author: goden
Date: Tue Feb 28 22:05:19 2006
New Revision: 23785

Modified:
   pypy/dist/pypy/rpython/lltypesystem/lltype.py
   pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
   pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/c/test/test_symbolic.py
Log:
(micktwomey, arigo, goden)
- new variant of low level array type with no length
- fixed a test for rctypes
- added conditional viewing of the flow graph for certain tests
- added support for low level arrays with no length to the c backend.



Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py	Tue Feb 28 22:05:19 2006
@@ -738,7 +738,12 @@
 
     def __len__(self):
         if isinstance(self._T, Array):
+            if self._T._hints.get('nolength', False):
+                raise TypeError("%r instance has no length attribute" %
+                                    (self._T,))
+
             return len(self._obj.items)
+
         raise TypeError("%r instance is not an array" % (self._T,))
 
     def __repr__(self):

Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py	Tue Feb 28 22:05:19 2006
@@ -508,3 +508,8 @@
          assert typeOf(res) == TGT
          assert res == expect
         
+def test_array_with_no_length():
+    A = GcArray(Signed, hints={'nolength': True})
+    a = malloc(A, 10)
+    py.test.raises(TypeError, len, a)
+

Modified: pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py	Tue Feb 28 22:05:19 2006
@@ -300,10 +300,13 @@
 
     def test_annotate_struct(self):
         a = RPythonAnnotator()
-        s = a.build_types(py_testfunc_struct, [int])
+        s = a.build_types(py_testfunc_struct, [tagpoint])
         assert s.knowntype == int
+        
+        if conftest.option.view:
+            a.translator.view()
 
-    def test_annotate_struct(self):
+    def test_annotate_struct2(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_testfunc_struct_id, [tagpoint])
@@ -324,6 +327,9 @@
         s = a.build_types(py_create_point,[])
         assert s.knowntype == int
 
+        if conftest.option.view:
+            a.translator.view()
+
     def test_annotate_byval(self):
         t = TranslationContext()
         a = t.buildannotator()
@@ -407,8 +413,8 @@
         try:
             t.buildrtyper().specialize()
         finally:
-            #d#t.view()
-            pass
+            if conftest.option.view:
+                t.view()
 
     def test_specialize_struct_1(self):
         t = TranslationContext()
@@ -467,12 +473,17 @@
         s = a.build_types(py_test_annotate_array, [])
         assert s.knowntype == c_int_10
 
+        if conftest.option.view:
+            a.translator.view()
+
     def test_annotate_array_access(self):
         t = TranslationContext()
         a = t.buildannotator()
         s = a.build_types(py_test_annotate_array_content, [])
         assert s.knowntype == int
-        #d#t.view()
+
+        if conftest.option.view:
+            t.view()
 
     def test_annotate_pointer_access_as_array(self):
         """

Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py	(original)
+++ pypy/dist/pypy/translator/c/node.py	Tue Feb 28 22:05:19 2006
@@ -182,7 +182,8 @@
         yield 'struct %s {' % self.name
         for fname, typename in self.gcfields:
             yield '\t' + cdecl(typename, fname) + ';'
-        yield '\tlong length;'
+        if not self.ARRAY._hints.get('nolength', False):
+            yield '\tlong length;'
         line = '%s;' % cdecl(self.itemtypename, 'items[%d]'% self.varlength)
         if self.ARRAY.OF is Void:    # strange
             line = '/* %s */' % line
@@ -216,7 +217,10 @@
 
     def debug_offsets(self):
         # generate three offsets for debugging inspection
-        yield 'offsetof(struct %s, length)' % (self.name,)
+        if not self.ARRAY._hints.get('nolength', False):
+            yield 'offsetof(struct %s, length)' % (self.name,)
+        else:
+            yield '-1'
         if self.ARRAY.OF is not Void:
             yield 'offsetof(struct %s, items[0])' % (self.name,)
             yield 'offsetof(struct %s, items[1])' % (self.name,)

Modified: pypy/dist/pypy/translator/c/test/test_symbolic.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_symbolic.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_symbolic.py	Tue Feb 28 22:05:19 2006
@@ -25,6 +25,16 @@
     res = fn()
     assert res == 12
 
+def test_sizeof_array_with_no_length():
+    A = lltype.Array(lltype.Signed, hints={'nolength': True})
+    arraysize = llmemory.sizeof(A, 10)
+    signedsize = llmemory.sizeof(lltype.Signed)
+    def f():
+        return arraysize-signedsize*10
+    fn, t = getcompiled(f, [])
+    res = fn()
+    assert res == 0
+
 def test_itemoffsetof():
     ARRAY = lltype.GcArray(lltype.Signed)
     itemoffsets = [llmemory.itemoffsetof(ARRAY, i) for i in range(5)]



More information about the Pypy-commit mailing list