[pypy-svn] r22524 - in pypy/dist/pypy: rpython/l3interp rpython/l3interp/test translator/c translator/c/src

mwh at codespeak.net mwh at codespeak.net
Mon Jan 23 15:24:46 CET 2006


Author: mwh
Date: Mon Jan 23 15:24:41 2006
New Revision: 22524

Modified:
   pypy/dist/pypy/rpython/l3interp/convertgraph.py
   pypy/dist/pypy/rpython/l3interp/l3interp.py
   pypy/dist/pypy/rpython/l3interp/model.py
   pypy/dist/pypy/rpython/l3interp/test/test_convert.py
   pypy/dist/pypy/translator/c/database.py
   pypy/dist/pypy/translator/c/primitive.py
   pypy/dist/pypy/translator/c/src/address.h
Log:
(arre, mwh)
some support in genc for offsets.  reenable the test from test_convert and
the getfield_int l3 operation.


Modified: pypy/dist/pypy/rpython/l3interp/convertgraph.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/convertgraph.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/convertgraph.py	Mon Jan 23 15:24:41 2006
@@ -3,7 +3,7 @@
 from pypy.rpython.l3interp.model import Op
 from pypy.objspace.flow import model as flowmodel
 from pypy.rpython.lltypesystem import lltype
-from pypy.rpython.memory.lladdress import OffsetOf, fakeaddress
+from pypy.rpython.lltypesystem.llmemory import OffsetOf, fakeaddress
 
 
 class LL2L3Converter(object):

Modified: pypy/dist/pypy/rpython/l3interp/l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/l3interp.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/l3interp.py	Mon Jan 23 15:24:41 2006
@@ -2,6 +2,8 @@
 from pypy.rpython.memory import lladdress
 from pypy.rpython.rarithmetic import r_uint
 from pypy.interpreter.miscutils import InitializedClass
+from pypy.rpython.lltypesystem.llmemory import fakeaddress, OffsetOf
+from pypy.rpython.lltypesystem import lltype
 
 class L3Exception(Exception):
     pass
@@ -40,11 +42,20 @@
         return L3Pointer(args_ptr.pop())
     raise AssertionError("stacks corrupted")
 
+constant_offset = OffsetOf(lltype.Void)
+constant_fakeaddress = fakeaddress(None)
+
 class L3Frame(object):
     
     def __init__(self, graph, stack_int, stack_dbl, stack_ptr):
         self.graph = graph
         self.block = self.graph.startblock
+        if self.block.constants_ptr is None:
+            self.block.constants_ptr = [constant_fakeaddress]
+            self.block.constants_ptr = None
+        if self.block.constants_offset is None:
+            self.block.constants_offset = [constant_offset]
+            self.block.constants_offset = None
         self.i = 0
         self.stack_int = stack_int
         self.stack_dbl = stack_dbl
@@ -140,7 +151,7 @@
         self.stack_dbl.append(x)
         raise L3Return
 
-    def op_ptr_return(self):
+    def op_adr_return(self):
         x = self.getptr()
         self.restorestacks()
         self.stack_ptr.append(x)
@@ -169,11 +180,14 @@
         else:
             self.stack_int.append(0)
 
-    def later_op_getfield_int(self):
+    def op_getfield_int(self):
         p = self.getptr()
         o = self.getoffset()
         self.stack_int.append((p + o).signed[0])
 
+    def op_flavored_malloc(self):
+        self.stack_ptr.append(constant_fakeaddress)
+
     def op_direct_call(self):
         block = self.block
         assert block.called_graphs is not None

Modified: pypy/dist/pypy/rpython/l3interp/model.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/model.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/model.py	Mon Jan 23 15:24:41 2006
@@ -1,6 +1,5 @@
-from pypy.rpython.memory import lladdress
 from pypy.objspace.flow import model as flowmodel
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, llmemory
 
 very_low_level_ops = [
     'nop',
@@ -87,7 +86,7 @@
 
 
 primitives = [lltype.Signed, lltype.Unsigned, lltype.Float, lltype.Char,
-              lltype.UniChar, lladdress.Address, lltype.Void]
+              lltype.UniChar, llmemory.Address, lltype.Void]
 
 primitive_to_number = {}
 for i, p in enumerate(primitives):
@@ -113,6 +112,7 @@
         self.constants_int = constants_int
         self.constants_dbl = constants_dbl
         self.constants_ptr = constants_ptr
+        
         self.constants_offset = constants_offset
         self.called_graphs = called_graphs
 

Modified: pypy/dist/pypy/rpython/l3interp/test/test_convert.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/test/test_convert.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/test/test_convert.py	Mon Jan 23 15:24:41 2006
@@ -40,7 +40,7 @@
     assert isinstance(result, l3interp.L3Integer)
     assert result.intval == 1
     
-def dont_test_convert_getfield():
+def test_convert_getfield():
     class C:
         def __init__(self, x):
             self.x = x

Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py	(original)
+++ pypy/dist/pypy/translator/c/database.py	Mon Jan 23 15:24:41 2006
@@ -2,6 +2,8 @@
      Primitive, Ptr, typeOf, RuntimeTypeInfo, \
      Struct, Array, FuncType, PyObject, Void, \
      ContainerType, OpaqueType
+from pypy.rpython.lltypesystem.llmemory import Offset, Address
+from pypy.rpython.memory.lladdress import NULL
 from pypy.translator.c.primitive import PrimitiveName, PrimitiveType
 from pypy.translator.c.primitive import PrimitiveErrorValue
 from pypy.translator.c.node import StructDefNode, ArrayDefNode
@@ -119,7 +121,19 @@
                 raise Exception("don't know about %r" % (T,))
         else:
             T = typeOf(obj)
-            if isinstance(T, Primitive):
+            if T is Offset:
+                assert len(obj.fldnames) <= 1
+                if len(obj.fldnames) == 0:
+                    return '0 /*offsetof*/'
+                else:
+                    return 'offsetof(%s, %s)'%(
+                        self.gettype(obj.TYPE), obj.fldnames[0])
+            elif T is Address and obj is not NULL:
+                if obj.ob is None:
+                    return 'NULL'
+                else:
+                    return self.get(obj.ob)
+            elif isinstance(T, Primitive):
                 return PrimitiveName[T](obj)
             elif isinstance(T, Ptr):
                 if obj:   # test if the ptr is non-NULL

Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py	(original)
+++ pypy/dist/pypy/translator/c/primitive.py	Mon Jan 23 15:24:41 2006
@@ -1,6 +1,6 @@
 import sys
 from pypy.rpython.lltypesystem.lltype import *
-from pypy.rpython.lltypesystem.llmemory import Address
+from pypy.rpython.lltypesystem.llmemory import Address, Offset
 from pypy.rpython.memory.lladdress import NULL
 
 # ____________________________________________________________
@@ -58,7 +58,6 @@
     assert value == NULL
     return 'NULL' 
 
-
 PrimitiveName = {
     Signed:   name_signed,
     SignedLongLong:   name_signedlonglong,
@@ -83,6 +82,7 @@
     Bool:     'char @',
     Void:     'void @',
     Address:  'void* @',
+    Offset:   'long @',
     }
 
 PrimitiveErrorValue = {
@@ -96,4 +96,5 @@
     Bool:     '((char) -1)',
     Void:     '/* error */',
     Address:  'NULL',
+    Offset:   '0',
     }

Modified: pypy/dist/pypy/translator/c/src/address.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/address.h	(original)
+++ pypy/dist/pypy/translator/c/src/address.h	Mon Jan 23 15:24:41 2006
@@ -8,6 +8,7 @@
 #define OP_ADR_DELTA(x,y,r,err) r = ((char *)(x) - (char *)(y))
 #define OP_ADR_SUB(x,y,r,err)   r = ((char *)(x) - (y))
 #define OP_ADR_ADD(x,y,r,err)   r = ((char *)(x) + (y))
+#define OP_ADR_OFFSET_ADD(x,y,r,err)   r = ((char *)(x) + (y))
 
 #define OP_ADR_EQ(x,y,r,err)	  r = ((x) == (y))
 #define OP_ADR_NE(x,y,r,err)	  r = ((x) != (y))
@@ -30,3 +31,4 @@
  
 #define OP_RAW_FREE(x,r,err)        free(x);
 #define OP_RAW_MEMCOPY(x,y,size,r,err) memcpy(y,x,size);
+



More information about the Pypy-commit mailing list