[pypy-svn] r13277 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Fri Jun 10 22:35:39 CEST 2005


Author: arigo
Date: Fri Jun 10 22:35:36 2005
New Revision: 13277

Added:
   pypy/dist/pypy/rpython/test/test_robject.py   (contents, props changed)
Modified:
   pypy/dist/pypy/rpython/robject.py
Log:
Support for all operations involving PyObjects -- basically just by deferring
the problem to the code generator.  GenC already knows what to do.


Modified: pypy/dist/pypy/rpython/robject.py
==============================================================================
--- pypy/dist/pypy/rpython/robject.py	(original)
+++ pypy/dist/pypy/rpython/robject.py	Fri Jun 10 22:35:36 2005
@@ -3,6 +3,7 @@
 from pypy.rpython.lltype import PyObject, Ptr, Void, Bool, pyobjectptr
 from pypy.rpython.rmodel import Repr, TyperError
 from pypy.rpython import rclass
+from pypy.tool.sourcetools import func_with_new_name
 
 
 class __extend__(annmodel.SomeObject):
@@ -23,15 +24,35 @@
 
 
 class PyObjRepr(Repr):
-    lowleveltype = Ptr(PyObject)
-
     def convert_const(self, value):
         return pyobjectptr(value)
 
 pyobj_repr = PyObjRepr()
-
-
-class ConstPyObjRepr(Repr):
-    lowleveltype = Void
-
-constpyobj_repr = ConstPyObjRepr()
+pyobj_repr.lowleveltype = Ptr(PyObject)
+constpyobj_repr = PyObjRepr()
+constpyobj_repr.lowleveltype = Void
+
+# ____________________________________________________________
+#
+#  All operations involving a PyObjRepr are "replaced" by themselves,
+#  after converting all other arguments to PyObjRepr as well.  This
+#  basically defers the operations to the care of the code generator.
+
+def make_operation(opname, cls=PyObjRepr):
+    def rtype_op(_, hop):
+        vlist = hop.inputargs(*([pyobj_repr]*hop.nb_args))
+        v = hop.genop(opname, vlist, resulttype = pyobj_repr)
+        return hop.llops.convertvar(v, pyobj_repr, hop.r_result)
+
+    funcname = 'rtype_' + opname
+    func = func_with_new_name(rtype_op, funcname)
+    assert funcname not in cls.__dict__  # can be in Repr; overriden then.
+    setattr(cls, funcname, func)
+
+
+for opname in annmodel.UNARY_OPERATIONS:
+    make_operation(opname)
+
+for opname in annmodel.BINARY_OPERATIONS:
+    make_operation(opname, pairtype(PyObjRepr, Repr))
+    make_operation(opname, pairtype(Repr, PyObjRepr))

Added: pypy/dist/pypy/rpython/test/test_robject.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/test/test_robject.py	Fri Jun 10 22:35:36 2005
@@ -0,0 +1,16 @@
+from pypy.translator.translator import Translator
+from pypy.rpython.lltype import *
+
+
+def rtype(fn, argtypes=[]):
+    t = Translator(fn)
+    t.annotate(argtypes)
+    t.specialize()
+    t.checkgraphs()
+    return t
+
+
+def test_set_del_item():
+    def dummyfn(obj):
+        return obj + 1
+    rtype(dummyfn, [object])



More information about the Pypy-commit mailing list