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

nik at codespeak.net nik at codespeak.net
Mon Mar 13 14:57:47 CET 2006


Author: nik
Date: Mon Mar 13 14:57:45 2006
New Revision: 24301

Added:
   pypy/dist/pypy/translator/squeak/test/test_llops.py
Modified:
   pypy/dist/pypy/translator/squeak/gensqueak.py
   pypy/dist/pypy/translator/squeak/test/runtest.py
Log:
make some tests for low-level integer operations pass.


Modified: pypy/dist/pypy/translator/squeak/gensqueak.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/gensqueak.py	(original)
+++ pypy/dist/pypy/translator/squeak/gensqueak.py	Mon Mar 13 14:57:45 2006
@@ -245,7 +245,10 @@
         'classof':       Selector('class', 0),
         'sameAs':        Selector('yourself', 0), 
         'intAdd:':       Selector('+', 1),
+        'intSub:':       Selector('-', 1),
         'intEq:':        Selector('=', 1),
+        'intMul:':       Selector('*', 1),
+        'intFloordiv:':  Selector('//', 1),
     }
 
     def render_body(self, startblock):

Modified: pypy/dist/pypy/translator/squeak/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/squeak/test/runtest.py	Mon Mar 13 14:57:45 2006
@@ -43,6 +43,7 @@
         t = TranslationContext()
         t.buildannotator().build_types(func, annotation)
         t.buildrtyper(type_system="ootype").specialize()
+        self.graph = t.graphs[0]
         if conftest.option.view:
            t.viewcg()
         return GenSqueak(udir, t)

Added: pypy/dist/pypy/translator/squeak/test/test_llops.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/squeak/test/test_llops.py	Mon Mar 13 14:57:45 2006
@@ -0,0 +1,38 @@
+from pypy.translator.squeak.test.runtest import compile_function
+
+def optest(testcase):
+    opname = testcase[0]
+    opstring = testcase[1]
+    args = testcase[2:]
+    annotation = [type(a) for a in args]
+    func = opfunction(opstring, args)
+    sqfunc = compile_function(func, annotation)
+
+    # Make sure we actually test what we intend to test
+    found_llop = False
+    for op in sqfunc.graph.startblock.operations:
+        if op.opname == opname:
+            found_llop = True
+            break
+    assert found_llop
+
+    assert sqfunc(*args) == str(func(*args))
+
+def opfunction(opstring, annotation):
+    exec """def fn(v1, v2):
+                return v1 %s v2""" % opstring
+    return fn
+
+def test_intoperations():
+    tests = [
+        # XXX Must handle overflows for all integer ops
+        ("int_add", "+", 1, 2),
+        ("int_sub", "-", 1, 3),
+        ("int_mul", "*", 2, 3),
+        # XXX how to produce int_div and int_truediv?
+        ("int_floordiv", "//", 7, 3),
+        ("int_floordiv", "//", -7, 3),
+    ]
+    for t in tests:
+        yield optest, t
+



More information about the Pypy-commit mailing list