[pypy-svn] r54023 - in pypy/branch/io-improvements/pypy: rpython rpython/lltypesystem rpython/lltypesystem/test translator/c translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Tue Apr 22 19:05:38 CEST 2008
Author: arigo
Date: Tue Apr 22 19:05:37 2008
New Revision: 54023
Modified:
pypy/branch/io-improvements/pypy/rpython/llinterp.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/ll2ctypes.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py
pypy/branch/io-improvements/pypy/translator/c/funcgen.py
pypy/branch/io-improvements/pypy/translator/c/test/test_lltyped.py
Log:
(docgok, arigo)
Yet Another Casting Operation. This one corresponds to rffi.cast
(ll2ctypes.force_cast). It's needed to run on top the llinter the tests using
this kind of cast.
Modified: pypy/branch/io-improvements/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/llinterp.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/llinterp.py Tue Apr 22 19:05:37 2008
@@ -701,6 +701,11 @@
lltype.ContainerType)
return getattr(obj, field)
+ def op_force_cast(self, RESTYPE, obj):
+ from pypy.rpython.lltypesystem import ll2ctypes
+ return ll2ctypes.force_cast(RESTYPE, obj)
+ op_force_cast.need_result_type = True
+
def op_cast_int_to_ptr(self, RESTYPE, int1):
return lltype.cast_int_to_ptr(RESTYPE, int1)
op_cast_int_to_ptr.need_result_type = True
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/ll2ctypes.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/ll2ctypes.py Tue Apr 22 19:05:37 2008
@@ -704,14 +704,12 @@
return annmodel.lltype_to_annotation(RESTYPE)
def specialize_call(self, hop):
- from pypy.rpython.rbuiltin import gen_cast
hop.exception_cannot_occur()
s_RESTYPE = hop.args_s[0]
assert s_RESTYPE.is_constant()
RESTYPE = s_RESTYPE.const
v_arg = hop.inputarg(hop.args_r[1], arg=1)
- TYPE1 = v_arg.concretetype
- return gen_cast(hop.llops, RESTYPE, v_arg)
+ return hop.genop('force_cast', [v_arg], resulttype = RESTYPE)
def typecheck_ptradd(T):
# --- ptradd() is only for pointers to non-GC, no-length arrays.
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/lloperation.py Tue Apr 22 19:05:37 2008
@@ -317,6 +317,7 @@
'cast_float_to_uint': LLOp(canfold=True), # XXX need OverflowError?
'cast_float_to_longlong':LLOp(canfold=True),
'truncate_longlong_to_int':LLOp(canfold=True),
+ 'force_cast': LLOp(sideeffects=False), # only for rffi.cast()
# __________ pointer operations __________
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Tue Apr 22 19:05:37 2008
@@ -382,9 +382,8 @@
buf = rffi.cast(rffi.VOIDP, b)
return buf[2]
assert f() == 'z'
- # XXX let's say we don't run it on top of llinterp
- #res = interpret(f, [])
- #assert res == 'z'
+ res = interpret(f, [])
+ assert res == 'z'
def test_funcptr1(self):
def dummy(n):
Modified: pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py (original)
+++ pypy/branch/io-improvements/pypy/rpython/lltypesystem/test/test_rffi.py Tue Apr 22 19:05:37 2008
@@ -527,8 +527,8 @@
graph = graphof(a.translator, f)
s = summary(graph)
# there should be not too many operations here by now
- expected = {'cast_int_to_uint': 1, 'direct_call': 1,
- 'cast_primitive': 2, 'cast_int_to_float': 1}
+ print s
+ expected = {'force_cast': 3, 'cast_int_to_float': 1, 'direct_call': 1}
for k, v in expected.items():
assert s[k] == v
Modified: pypy/branch/io-improvements/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/io-improvements/pypy/translator/c/funcgen.py (original)
+++ pypy/branch/io-improvements/pypy/translator/c/funcgen.py Tue Apr 22 19:05:37 2008
@@ -696,6 +696,8 @@
typename = cdecl(self.db.gettype(TYPE), '')
return "%(result)s = (%(typename)s)(%(val)s);" % locals()
+ OP_FORCE_CAST = OP_CAST_PRIMITIVE # xxx the same logic works
+
def OP_RESUME_POINT(self, op):
return '/* resume point %s */'%(op.args[0],)
Modified: pypy/branch/io-improvements/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/branch/io-improvements/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/branch/io-improvements/pypy/translator/c/test/test_lltyped.py Tue Apr 22 19:05:37 2008
@@ -304,6 +304,23 @@
res = fn(100)
assert res == 100 + len(list(names))
+ def test_force_cast(self):
+ from pypy.rpython.annlowlevel import llstr
+ from pypy.rpython.lltypesystem.rstr import STR
+ from pypy.rpython.lltypesystem import rffi, llmemory, lltype
+ P = lltype.Ptr(lltype.FixedSizeArray(lltype.Char, 1))
+
+ def f():
+ a = llstr("xyz")
+ b = (llmemory.cast_ptr_to_adr(a) + llmemory.offsetof(STR, 'chars')
+ + llmemory.itemoffsetof(STR.chars, 0))
+ buf = rffi.cast(rffi.VOIDP, b)
+ return buf[2]
+
+ fn = self.getcompiled(f, [])
+ res = fn()
+ assert res == 'z'
+
def test_array_nolength(self):
A = Array(Signed, hints={'nolength': True})
a1 = malloc(A, 3, immortal=True)
More information about the Pypy-commit
mailing list