[pypy-commit] pypy default: Unsure, but it may be the case that int_is_true is better...
arigo
noreply at buildbot.pypy.org
Tue Jul 21 19:39:11 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r78628:8250500bac26
Date: 2015-07-21 19:39 +0200
http://bitbucket.org/pypy/pypy/changeset/8250500bac26/
Log: Unsure, but it may be the case that int_is_true is better...
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -480,8 +480,6 @@
}
_cast_from_Signed = {
lltype.Signed: None,
- #lltype.Bool: 'int_is_true', ---disabled, see test_cast_to_bool_1
- # in translator/c/test/test_lltyped.py
lltype.Char: 'cast_int_to_char',
lltype.UniChar: 'cast_int_to_unichar',
lltype.Float: 'cast_int_to_float',
@@ -503,6 +501,8 @@
if op:
v_value = llops.genop(op, [v_value], resulttype=TGT)
return v_value
+ elif ORIG is lltype.Signed and TGT is lltype.Bool:
+ return llops.genop('int_is_true', [v_value], resulttype=lltype.Bool)
else:
# use the generic operation if there is no alternative
return llops.genop('cast_primitive', [v_value], resulttype=TGT)
diff --git a/rpython/rtyper/test/test_rbuiltin.py b/rpython/rtyper/test/test_rbuiltin.py
--- a/rpython/rtyper/test/test_rbuiltin.py
+++ b/rpython/rtyper/test/test_rbuiltin.py
@@ -541,6 +541,14 @@
return lltype.cast_primitive(lltype.Signed, v)
res = self.interpret(llf, [rffi.r_short(123)], policy=LowLevelAnnotatorPolicy())
assert res == 123
+ def llf(v):
+ return lltype.cast_primitive(lltype.Bool, v)
+ res = self.interpret(llf, [2**24], policy=LowLevelAnnotatorPolicy())
+ assert res == True
+ def llf(v):
+ return lltype.cast_primitive(lltype.Bool, v)
+ res = self.interpret(llf, [rffi.r_longlong(2**48)], policy=LowLevelAnnotatorPolicy())
+ assert res == True
def test_force_cast(self):
def llfn(v):
More information about the pypy-commit
mailing list