[pypy-svn] r23096 - in pypy/dist/pypy: annotation rpython rpython/test

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Feb 7 12:12:55 CET 2006


Author: cfbolz
Date: Tue Feb  7 12:12:54 2006
New Revision: 23096

Modified:
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/objectmodel.py
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/rpython/test/test_objectmodel.py
Log:
(cfbolz, mwh) implement cast_adr_to_ptr


Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Tue Feb  7 12:12:54 2006
@@ -318,6 +318,10 @@
 def robjmodel_cast_ptr_to_adr(s):
     return SomeAddress()
 
+def robjmodel_cast_adr_to_ptr(s, s_type):
+    assert s_type.is_constant()
+    return SomePtr(s_type.const)
+
 def rstack_yield_current_frame_to_caller():
     return SomeExternalObject(pypy.rpython.rstack.frame_stack_top)
     
@@ -364,6 +368,7 @@
 BUILTIN_ANALYZERS[pypy.rpython.objectmodel.keepalive_until_here] = robjmodel_keepalive_until_here
 BUILTIN_ANALYZERS[pypy.rpython.objectmodel.hint] = robjmodel_hint
 BUILTIN_ANALYZERS[pypy.rpython.objectmodel.cast_ptr_to_adr] = robjmodel_cast_ptr_to_adr
+BUILTIN_ANALYZERS[pypy.rpython.objectmodel.cast_adr_to_ptr] = robjmodel_cast_adr_to_ptr
 BUILTIN_ANALYZERS[pypy.rpython.rstack.yield_current_frame_to_caller] = (
     rstack_yield_current_frame_to_caller)
 

Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Tue Feb  7 12:12:54 2006
@@ -236,7 +236,7 @@
             assert isinstance(operation.args[0], Variable)
         vals = [self.getval(x) for x in operation.args]
         # if these special cases pile up, do something better here
-        if operation.opname in ['cast_pointer', 'ooupcast', 'oodowncast']:
+        if operation.opname in ['cast_pointer', 'ooupcast', 'oodowncast', 'cast_adr_to_ptr']:
             vals.insert(0, operation.result.concretetype)
         retval = ophandler(*vals)
         self.setvar(operation.result, retval)
@@ -433,6 +433,10 @@
         assert isinstance(ptr, self.llt._ptr)
         return objectmodel.cast_ptr_to_adr(ptr)
 
+    def op_cast_adr_to_ptr(self, TYPE, adr):
+        assert self.llt.typeOf(adr) == llmemory.Address
+        return objectmodel.cast_adr_to_ptr(adr, TYPE)
+
     def op_cast_int_to_float(self, i):
         assert type(i) is int
         return float(i)

Modified: pypy/dist/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/objectmodel.py	(original)
+++ pypy/dist/pypy/rpython/objectmodel.py	Tue Feb  7 12:12:54 2006
@@ -52,6 +52,10 @@
     assert isinstance(obj, simulatorptr)
     return obj._address
 
+def cast_adr_to_ptr(adr, EXPECTED_TYPE):
+    from pypy.rpython.memory.lltypesimulation import simulatorptr
+    return simulatorptr(EXPECTED_TYPE, adr)
+   
 # __ hlinvoke XXX this doesn't seem completely the right place for this
 
 def hlinvoke(repr, llcallable, *args):

Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Tue Feb  7 12:12:54 2006
@@ -2,7 +2,7 @@
 from pypy.annotation import model as annmodel
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem import lltype, rclass
-from pypy.rpython import rarithmetic, objectmodel, rstack, rint
+from pypy.rpython import rarithmetic, objectmodel, rstack, rint, raddress
 from pypy.rpython.error import TyperError
 from pypy.rpython.rmodel import Repr, IntegerRepr
 from pypy.rpython.rrange import rtype_builtin_range, rtype_builtin_xrange 
@@ -444,4 +444,12 @@
     return hop.genop('cast_ptr_to_adr', vlist,
                      resulttype = llmemory.Address)
 
+def rtype_cast_adr_to_ptr(hop):
+    assert isinstance(hop.args_r[0], raddress.AddressRepr)
+    adr, TYPE = hop.inputargs(hop.args_r[0], lltype.Void)
+    return hop.genop('cast_adr_to_ptr', [adr],
+                     resulttype = TYPE.value)
+
 BUILTIN_TYPER[objectmodel.cast_ptr_to_adr] = rtype_cast_ptr_to_adr
+BUILTIN_TYPER[objectmodel.cast_adr_to_ptr] = rtype_cast_adr_to_ptr
+

Modified: pypy/dist/pypy/rpython/test/test_objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_objectmodel.py	(original)
+++ pypy/dist/pypy/rpython/test/test_objectmodel.py	Tue Feb  7 12:12:54 2006
@@ -183,3 +183,16 @@
     res = interpret(f, [0])
     assert not res
 
+def test_cast_adr_to_ptr():
+    from pypy.rpython import objectmodel
+    from pypy.rpython.memory.test.test_llinterpsim import interpret
+    from pypy.rpython.lltypesystem import lltype
+    S = lltype.GcStruct("S", ("x", lltype.Signed))
+    Sptr = lltype.Ptr(S)
+    def f():
+        s1 = lltype.malloc(S)
+        adr = objectmodel.cast_ptr_to_adr(s1)
+        s2 = objectmodel.cast_adr_to_ptr(adr, Sptr)
+        return s1 == s2
+    res = interpret(f, [])
+    assert res



More information about the Pypy-commit mailing list