[pypy-svn] r22599 - pypy/dist/pypy/rpython/lltypesystem

ac at codespeak.net ac at codespeak.net
Tue Jan 24 16:03:11 CET 2006


Author: ac
Date: Tue Jan 24 16:03:11 2006
New Revision: 22599

Modified:
   pypy/dist/pypy/rpython/lltypesystem/llmemory.py
Log:
(mwh, arre)
Implement sketches of sizeof and itemoffsetof. These can not
be reasonably annotated and rtyped.



Modified: pypy/dist/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/llmemory.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/llmemory.py	Tue Jan 24 16:03:11 2006
@@ -89,12 +89,24 @@
 
 
 def sizeof(TYPE, n=None):
-    pass
-
+    if n is None:
+        assert not TYPE._is_varsize()
+        return ItemOffset(TYPE)
+    else:
+        if isinstance(TYPE, Array):
+            return itemoffsetof(TYPE, n)
+        elif isinstance(TYPE, Struct):
+            return FieldOffset(TYPE, TYPE._arrayfld) + \
+                   itemoffsetof(TYPE._flds[TYPE._arrayfld], n)
+        else:
+            raise Exception("don't know how to take the size of a %r"%TYPE)
+                   
 def offsetof(TYPE, fldname):
     assert fldname in TYPE._flds
     return FieldOffset(TYPE, fldname)
 
+def itemoffsetof(TYPE, n=0):
+    return ArrayItemsOffset(TYPE) + ItemOffset(TYPE.OF) * n
 # -------------------------------------------------------------
 
 class fakeaddress(object):



More information about the Pypy-commit mailing list