[pypy-svn] r24516 - in pypy/dist/pypy/translator/squeak: . test
nik at codespeak.net
nik at codespeak.net
Fri Mar 17 12:25:05 CET 2006
Author: nik
Date: Fri Mar 17 12:24:59 2006
New Revision: 24516
Modified:
pypy/dist/pypy/translator/squeak/opformatter.py
pypy/dist/pypy/translator/squeak/test/test_llops.py
Log:
support (almost) all integer operations for all integer types.
Modified: pypy/dist/pypy/translator/squeak/opformatter.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/opformatter.py (original)
+++ pypy/dist/pypy/translator/squeak/opformatter.py Fri Mar 17 12:24:59 2006
@@ -5,8 +5,8 @@
def _setup_int_masks():
"""Generates code for helpers to mask the various integer types."""
masks = {}
- for name, r_type in ("int", r_int), ("uint", r_uint), \
- ("llong", r_longlong), ("ullong", r_ulonglong):
+ # NB: behaviour of signed long longs is undefined on overflow
+ for name, r_type in ("int", r_int), ("uint", r_uint), ("ullong", r_ulonglong):
helper_name = "mask%s" % name.capitalize()
if name[0] == "u":
# Unsigned integer type
@@ -36,7 +36,7 @@
'abs': 'abs',
'is_true': 'isZero not',
'neg': 'negated',
- 'invert': 'bitInvert', # maybe bitInvert32?
+ 'invert': 'bitInvert',
'add': '+',
'sub': '-',
@@ -44,13 +44,25 @@
'mul': '*',
'div': '//',
'floordiv': '//',
- #'truediv': '/',: '/',
+ #'truediv': '/', # XXX fix this when we have float support
'mod': r'\\',
+ 'eq': '=',
+ 'ne': '~=',
+ 'lt': '<',
+ 'le': '<=',
+ 'gt': '>',
+ 'ge': '>=',
+ 'and': 'bitAnd',
+ 'or': 'bitOr',
+ 'lshift': '<<',
+ 'rshift': '>>',
+ 'xor': 'bitXor',
+ # XXX need to support x_ovf ops
}
number_opprefixes = "int", "uint", "llong", "ullong", "float"
- wrapping_ops = "neg", "invert", "add", "sub", "mul"
+ wrapping_ops = "neg", "invert", "add", "sub", "mul", "lshift"
int_masks = _setup_int_masks()
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 Fri Mar 17 12:24:59 2006
@@ -1,9 +1,10 @@
import sys
from pypy.translator.squeak.test.runtest import compile_function
-from pypy.rpython.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint, r_longlong, r_ulonglong
from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rpython.lltypesystem.lltype import Signed, Unsigned, Bool
+from pypy.rpython.lltypesystem.lltype import SignedLongLong, UnsignedLongLong
from pypy.rpython.test.test_llinterp import interpret
def optest(testcase):
@@ -11,7 +12,7 @@
RESTYPE = testcase[1]
args = testcase[2:]
- arg_signature = ", ".join(["v%s" % n for n in range(len(args))])
+ arg_signature = ", ".join(["a%s" % n for n in range(len(args))])
exec """def lloptest(%s):
return llop.%s(%s, %s)""" \
% (arg_signature, llopname, RESTYPE._name,
@@ -50,28 +51,63 @@
("sub", Signed, 1, 3),
("mul", Signed, 2, 3),
("div", Signed, 7, 3),
- ("floordiv", Signed, 7, 3),
+ ("floordiv", Signed, 7, 3), # XXX what about division by zero?
("floordiv", Signed, -7, 3),
("mod", Signed, 9, 4),
("mod", Signed, 9, -4),
+ ("eq", Bool, 1, 1),
+ ("eq", Bool, 1, 2),
+ ("ne", Bool, 1, 1),
+ ("ne", Bool, 1, 2),
+ ("lt", Bool, 1, 2),
+ ("le", Bool, 1, 2),
+ ("gt", Bool, 1, 2),
+ ("ge", Bool, 1, 2),
+]
+
+int_tests = general_tests + [
+ ("and", Signed, 9, 5),
+ ("and", Signed, 9, -5),
+ ("or", Signed, 4, 5),
+ ("or", Signed, 4, -5),
+ ("lshift", Signed, 16, 2),
+ ("rshift", Signed, 16, 2),
+ ("xor", Signed, 9, 5),
+ ("xor", Signed, 9, -5),
]
def test_intoperations():
- tests = adapt_tests(general_tests, int, Signed, "int") + [
+ tests = adapt_tests(int_tests, int, Signed, "int") + [
# binary wraparounds
("int_add", Signed, sys.maxint, 1),
("int_sub", Signed, -sys.maxint-1, 2),
("int_mul", Signed, sys.maxint/2, 3),
+ ("int_lshift", Signed, sys.maxint, 1),
]
for t in tests:
yield optest, t
def test_uintoperations():
- tests = adapt_tests(general_tests, r_uint, Unsigned, "uint") + [
+ tests = adapt_tests(int_tests, r_uint, Unsigned, "uint") + [
# binary wraparounds
("uint_add", Unsigned, r_uint(2*sys.maxint), r_uint(2)),
("uint_sub", Unsigned, r_uint(1), r_uint(3)),
("uint_mul", Unsigned, r_uint(sys.maxint), r_uint(3)),
+ ("uint_lshift", Unsigned, r_uint(2*sys.maxint), r_uint(1)),
+ ]
+ for t in tests:
+ yield optest, t
+
+def test_llongoperations():
+ tests = adapt_tests(general_tests, r_longlong, SignedLongLong, "llong")
+ for t in tests:
+ yield optest, t
+
+def test_ullongoperations():
+ tests = adapt_tests(general_tests, r_ulonglong, UnsignedLongLong, "ullong") + [
+ # binary wraparounds
+ ("ullong_add", UnsignedLongLong,
+ r_ulonglong(r_ulonglong.MASK), r_ulonglong(10)),
]
for t in tests:
yield optest, t
More information about the Pypy-commit
mailing list