[pypy-svn] r24538 - in pypy/dist/pypy/translator/squeak: . test

nik at codespeak.net nik at codespeak.net
Sat Mar 18 16:03:00 CET 2006


Author: nik
Date: Sat Mar 18 16:02:58 2006
New Revision: 24538

Modified:
   pypy/dist/pypy/translator/squeak/opformatter.py
   pypy/dist/pypy/translator/squeak/test/test_llops.py
Log:
implement various casts for ints, all as noops.


Modified: pypy/dist/pypy/translator/squeak/opformatter.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/opformatter.py	(original)
+++ pypy/dist/pypy/translator/squeak/opformatter.py	Sat Mar 18 16:02:58 2006
@@ -159,9 +159,9 @@
     op_cast_char_to_int = noop
     op_cast_unichar_to_int = noop
 
-    def op_cast_int_to_char(self, op):
-        # XXX incomplete
-        return Assignment(op.result, op.args[0])
-
-    op_cast_int_to_unichar = op_cast_int_to_char
+    op_cast_int_to_char = noop
+    op_cast_int_to_unichar = noop
+    op_cast_int_to_uint = noop
+    op_cast_int_to_longlong = noop
+    # XXX to_float missing
 

Modified: pypy/dist/pypy/translator/squeak/test/test_llops.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/test/test_llops.py	(original)
+++ pypy/dist/pypy/translator/squeak/test/test_llops.py	Sat Mar 18 16:02:58 2006
@@ -20,11 +20,17 @@
     llfunctest(lloptest, args)
 
 def llfunctest(llfunc, args):
+    expected_res = llinterpret(llfunc, args)
+    res = sqinterpret(llfunc, args)
+    assert res == str(expected_res).lower() # lowercasing for booleans
+
+def sqinterpret(llfunc, args):
     annotation = [type(a) for a in args]
     sqfunc = compile_function(llfunc, annotation)
-    expected_res = interpret(llfunc, args, policy=LowLevelAnnotatorPolicy())
-    res = sqfunc(*args)
-    assert res == str(expected_res).lower() # lowercasing for booleans
+    return sqfunc(*args)
+
+def llinterpret(llfunc, args):
+    return interpret(llfunc, args, policy=LowLevelAnnotatorPolicy())
 
 def adapt_tests(tests, type, RESTYPE, prefix):
     adapted = []
@@ -161,3 +167,17 @@
                     % (repr(from_type("a")), repr(from_type("b")), from_name)
         yield llfunctest, lloptest, (1,)
 
+def test_cast_int():
+    tests = [("char", Char), ("unichar", UniChar),
+             ("longlong", SignedLongLong), ("uint", Unsigned)]
+    for target_name, target_type in tests:
+        exec """def lloptest(i):
+            return llop.cast_int_to_%s(%s, i)""" \
+                    % (target_name, target_type._name)
+        args = (2,)
+        expected_res = llinterpret(lloptest, args)
+        res = int(sqinterpret(lloptest, args))
+        if isinstance(expected_res, (str, unicode)):
+            res = chr(res)
+        assert expected_res == res
+



More information about the Pypy-commit mailing list