[pypy-svn] r14056 - in pypy/dist/pypy/translator/llvm2: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Fri Jul 1 20:34:45 CEST 2005
Author: cfbolz
Date: Fri Jul 1 20:34:45 2005
New Revision: 14056
Modified:
pypy/dist/pypy/translator/llvm2/funcnode.py
pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
Log:
(ludal, cfbolz):
fixed is_true for ints, uints and floats
Modified: pypy/dist/pypy/translator/llvm2/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcnode.py (original)
+++ pypy/dist/pypy/translator/llvm2/funcnode.py Fri Jul 1 20:34:45 2005
@@ -180,8 +180,24 @@
fromtype = self.db.repr_arg_type(op.args[0])
self.codewriter.cast(targetvar, fromtype, fromvar, targettype)
- int_is_true = cast_bool_to_int = cast_primitive
+ cast_bool_to_int = cast_primitive
cast_bool_to_uint = uint_is_true = cast_primitive
+
+ def int_is_true(self, op):
+ self.codewriter.binaryop("setne",
+ self.db.repr_arg(op.result),
+ self.db.repr_arg_type(op.args[0]),
+ self.db.repr_arg(op.args[0]),
+ "0")
+
+ uint_is_true = int_is_true
+
+ def float_is_true(self, op):
+ self.codewriter.binaryop("setne",
+ self.db.repr_arg(op.result),
+ self.db.repr_arg_type(op.args[0]),
+ self.db.repr_arg(op.args[0]),
+ "0.0")
def direct_call(self, op):
assert len(op.args) >= 1
Modified: pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm.py Fri Jul 1 20:34:45 2005
@@ -18,7 +18,7 @@
## def setup_module(mod):
## mod.llvm_found = is_on_path("llvm-as")
-def compile_function(function, annotate):
+def compile_function(function, annotate, view=False):
t = Translator(function)
a = t.annotate(annotate)
t.specialize()
@@ -60,6 +60,20 @@
assert f(1) == 1
assert f(2) == 2
+def test_primitive_is_true():
+ def var_is_true(v):
+ return bool(v)
+ f = compile_function(var_is_true, [int])
+ assert f(256)
+ assert not f(0)
+ f = compile_function(var_is_true, [r_uint])
+ assert f(r_uint(256))
+ assert not f(r_uint(0))
+ f = compile_function(var_is_true, [float])
+ assert f(256.0)
+ assert not f(0.0)
+
+
def test_uint_ops():
def ops(i):
x = r_uint(0)
More information about the Pypy-commit
mailing list