[pypy-svn] r13788 - in pypy/dist/pypy/rpython: . test

mwh at codespeak.net mwh at codespeak.net
Fri Jun 24 13:44:08 CEST 2005


Author: mwh
Date: Fri Jun 24 13:44:07 2005
New Revision: 13788

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/test/test_rfloat.py
Log:
rtyper support for float(int) + tests


Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Fri Jun 24 13:44:07 2005
@@ -1,7 +1,7 @@
 from pypy.translator.translator import Translator
 from pypy.tool.sourcetools import compile2
 from pypy.objspace.flow.model import Constant, Variable, last_exception
-from pypy.rpython.rarithmetic import intmask, r_uint
+from pypy.rpython.rarithmetic import intmask, r_uint, ovfcheck
 import py
 from pypy.rpython.lltype import _ptr, Ptr, Void, typeOf, malloc, cast_pointer
 from pypy.rpython.lltype import Array
@@ -247,6 +247,10 @@
     def op_bool_not(self, b):
         assert type(b) is bool
         return not b
+
+    def op_cast_float_to_int(self, f):
+        assert type(f) is float
+        return ovfcheck(int(f))
     
     def op_cast_char_to_int(self, b):
         assert type(b) is str and len(b) == 1

Modified: pypy/dist/pypy/rpython/test/test_rfloat.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rfloat.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rfloat.py	Fri Jun 24 13:44:07 2005
@@ -2,6 +2,7 @@
 from pypy.rpython.rtyper import RPythonTyper
 from pypy.annotation import model as annmodel
 from pypy.rpython.test import snippet
+from pypy.rpython.test.test_llinterp import make_interpreter
 
 
 class TestSnippet(object):
@@ -36,3 +37,14 @@
         # XXX TODO test if all binary operations are implemented
         for opname in annmodel.BINARY_OPERATIONS:
             print 'BINARY_OPERATIONS:', opname
+
+def test_int_conversion():
+    def fn(f):
+        return int(f)
+
+    ev_fun = make_interpreter(fn, [0.0])
+
+    assert ev_fun(1.0) == 1
+    assert type(ev_fun(1.0)) is int
+
+    assert ev_fun(2.34) == 2



More information about the Pypy-commit mailing list