[pypy-svn] r26019 - in pypy/dist/pypy: rpython/rctypes translator/c translator/c/test translator/goal

arigo at codespeak.net arigo at codespeak.net
Thu Apr 20 10:52:50 CEST 2006


Author: arigo
Date: Thu Apr 20 10:52:48 2006
New Revision: 26019

Modified:
   pypy/dist/pypy/rpython/rctypes/rpyobject.py
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/c/test/test_lltyped.py
   pypy/dist/pypy/translator/goal/targetdemomodule.py
Log:
Minor fixes/tests to make targetdemomodule.py compile.


Modified: pypy/dist/pypy/rpython/rctypes/rpyobject.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rpyobject.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/rpyobject.py	Thu Apr 20 10:52:48 2006
@@ -1,7 +1,8 @@
+from pypy.annotation.pairtype import pairtype
 from pypy.rpython.rmodel import inputconst
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.rctypes.rmodel import CTypesValueRepr
-from pypy.rpython.robject import pyobj_repr
+from pypy.rpython.robject import PyObjRepr, pyobj_repr
 
 
 class CTypesPyObjRepr(CTypesValueRepr):
@@ -20,3 +21,10 @@
         v_pyobj, v_attr, v_newvalue = hop.inputargs(self, lltype.Void,
                                                     pyobj_repr)
         self.setvalue(hop.llops, v_pyobj, v_newvalue)
+
+
+class __extend__(pairtype(CTypesPyObjRepr, PyObjRepr)):
+    # conversion used by wrapper.py in genc when returning a py_object
+    # from a function exposed in a C extension module
+    def convert_from_to((r_from, r_to), v, llops):
+        return r_from.getvalue(llops, v)

Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Thu Apr 20 10:52:48 2006
@@ -427,18 +427,17 @@
         assert isinstance(op.args[1], Constant)
         STRUCT = self.lltypemap(op.args[0]).TO
         structdef = self.db.gettypedefnode(STRUCT)
-        fieldname = structdef.c_struct_field_name(op.args[1].value)
-        return self.generic_get(op, '%s%s->%s' % (ampersand,
-                                                  self.expr(op.args[0]),
-                                                  fieldname))
+        expr = ampersand + structdef.ptr_access_expr(self.expr(op.args[0]),
+                                                     op.args[1].value)
+        return self.generic_get(op, expr)
 
     def OP_SETFIELD(self, op):
         assert isinstance(op.args[1], Constant)
         STRUCT = self.lltypemap(op.args[0]).TO
         structdef = self.db.gettypedefnode(STRUCT)
-        fieldname = structdef.c_struct_field_name(op.args[1].value)
-        return self.generic_set(op, '%s->%s' % (self.expr(op.args[0]),
-                                                fieldname))
+        expr = structdef.ptr_access_expr(self.expr(op.args[0]),
+                                         op.args[1].value)
+        return self.generic_set(op, expr)
 
     OP_BARE_SETFIELD = OP_SETFIELD
 

Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Thu Apr 20 10:52:48 2006
@@ -55,13 +55,14 @@
         pfname = db.get(pf)
         self.exports[self.entrypoint.func_name] = pf
         for obj in exports:
-            objname = None
             if type(obj) is tuple:
                 objname, obj = obj
+            elif hasattr(obj, '__name__'):
+                objname = obj.__name__
+            else:
+                objname = None
             po = self.getentrypointptr(obj)
             poname = db.get(po)
-            if hasattr(obj, '__name__'):
-                objname = obj.__name__
             objname = objname or poname
             if objname in self.exports:
                 raise NameError, 'duplicate name in export: %s is %s and %s' % (

Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py	(original)
+++ pypy/dist/pypy/translator/c/node.py	Thu Apr 20 10:52:48 2006
@@ -102,6 +102,10 @@
         fldname = self.c_struct_field_name(fldname)
         return '%s.%s' % (baseexpr, fldname)
 
+    def ptr_access_expr(self, baseexpr, fldname):
+        fldname = self.c_struct_field_name(fldname)
+        return '%s->%s' % (baseexpr, fldname)
+
     def definition(self):
         if self.STRUCT._hints.get('external'):      # XXX hack
             return
@@ -187,6 +191,9 @@
     def access_expr(self, baseexpr, index):
         return '%s.items[%d]' % (baseexpr, index)
 
+    def ptr_access_expr(self, baseexpr, index):
+        return '%s->items[%d]' % (baseexpr, index)
+
     def definition(self):
         gcpolicy = self.db.gcpolicy
         yield 'struct %s {' % self.name
@@ -267,6 +274,8 @@
             index = int(index[4:])
         return '%s[%d]' % (baseexpr, index)
 
+    ptr_access_expr = access_expr
+
     def definition(self):
         return []    # no declaration is needed
 

Modified: pypy/dist/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_lltyped.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_lltyped.py	Thu Apr 20 10:52:48 2006
@@ -36,7 +36,7 @@
             a3 = big.a3
             a42 = big.a42
             a7[0] = -1
-            a7[6] = -2
+            a7.item6 = -2
             a3[0].v = -3
             a3[2].v = -4
             a42[0][0] = -5
@@ -44,7 +44,7 @@
             assert a7[0] == -1
             assert a7[6] == -2
             assert a3[0].v == -3
-            assert a3[2].v == -4
+            assert a3.item2.v == -4
             assert a42[0][0] == -5
             assert a42[5][6] == -6
             return len(a42)*100 + len(a42[4])

Modified: pypy/dist/pypy/translator/goal/targetdemomodule.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetdemomodule.py	(original)
+++ pypy/dist/pypy/translator/goal/targetdemomodule.py	Thu Apr 20 10:52:48 2006
@@ -1,4 +1,5 @@
 from pypy.module._demo import demo
+from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
 
 from ctypes import *
 
@@ -67,7 +68,7 @@
 # _____ Define and setup target ___
 
 def target(*args):
-    return entry_point, [int]
+    return entry_point, [int], PyPyAnnotatorPolicy()
 
 
 if __name__ == '__main__':



More information about the Pypy-commit mailing list