[pypy-svn] r23072 - in pypy/dist/pypy: annotation rpython rpython/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Feb 6 16:29:50 CET 2006
Author: cfbolz
Date: Mon Feb 6 16:29:47 2006
New Revision: 23072
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:
implement cast_ptr_to_adr
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Mon Feb 6 16:29:47 2006
@@ -315,6 +315,9 @@
def robjmodel_hint(s, **kwds_s):
return s
+def robjmodel_cast_ptr_to_adr(s):
+ return SomeAddress()
+
def rstack_yield_current_frame_to_caller():
return SomeExternalObject(pypy.rpython.rstack.frame_stack_top)
@@ -360,6 +363,7 @@
BUILTIN_ANALYZERS[pypy.rpython.objectmodel.hlinvoke] = robjmodel_hlinvoke
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.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 Mon Feb 6 16:29:47 2006
@@ -3,7 +3,7 @@
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.memory import lladdress
from pypy.rpython.ootypesystem import ootype
-from pypy.rpython.objectmodel import FREED_OBJECT
+from pypy.rpython import objectmodel
import sys
import math
@@ -429,6 +429,10 @@
self.llt.Struct))
return self.llt.cast_ptr_to_int(ptr1)
+ def op_cast_ptr_to_adr(self, ptr):
+ assert isinstance(ptr, self.llt._ptr)
+ return objectmodel.cast_ptr_to_adr(ptr)
+
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 Mon Feb 6 16:29:47 2006
@@ -45,6 +45,11 @@
obj.__class__ = FREED_OBJECT
+def cast_ptr_to_adr(obj):
+ from pypy.rpython.memory.lltypesimulation import simulatorptr
+ assert isinstance(obj, simulatorptr)
+ return obj._address
+
# __ 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 Mon Feb 6 16:29:47 2006
@@ -436,3 +436,11 @@
return hop.genop('hint', [v, c_hint], resulttype=v.concretetype)
BUILTIN_TYPER[objectmodel.hint] = rtype_hint
+
+def rtype_cast_ptr_to_adr(hop):
+ vlist = hop.inputargs(hop.args_r[0])
+ assert isinstance(vlist[0].concretetype, lltype.Ptr)
+ return hop.genop('cast_ptr_to_adr', vlist,
+ resulttype = llmemory.Address)
+
+BUILTIN_TYPER[objectmodel.cast_ptr_to_adr] = rtype_cast_ptr_to_adr
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 Mon Feb 6 16:29:47 2006
@@ -165,3 +165,21 @@
return x
res = interpret(f, [])
assert res == 5
+
+def test_cast_ptr_to_adr():
+ from pypy.rpython import objectmodel
+ from pypy.rpython.memory.test.test_llinterpsim import interpret
+ class A(object):
+ pass
+ def f(x):
+ if x:
+ a = A()
+ else:
+ a = None
+ adr_a = objectmodel.cast_ptr_to_adr(a)
+ return bool(adr_a)
+ res = interpret(f, [1])
+ assert res
+ res = interpret(f, [0])
+ assert not res
+
More information about the Pypy-commit
mailing list