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

nik at codespeak.net nik at codespeak.net
Mon Mar 13 17:54:36 CET 2006


Author: nik
Date: Mon Mar 13 17:54:34 2006
New Revision: 24315

Modified:
   pypy/dist/pypy/translator/squeak/gensqueak.py
   pypy/dist/pypy/translator/squeak/test/test_llops.py
Log:
revamping testing of llops again, specializing low-level functions
directly (thanks for the hint, pedronis).


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 17:54:34 2006
@@ -248,7 +248,9 @@
         'intSub:':       Selector('-', 1),
         'intEq:':        Selector('=', 1),
         'intMul:':       Selector('*', 1),
+        'intDiv:':       Selector('//', 1),
         'intFloordiv:':  Selector('//', 1),
+        'intAbs':        Selector('abs', 0),
     }
 
     def render_body(self, startblock):

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	Mon Mar 13 17:54:34 2006
@@ -1,47 +1,37 @@
 from pypy.translator.squeak.test.runtest import compile_function
-from pypy.translator.translator import TranslationContext
-from pypy.objspace.flow.operation import FunctionByName
-from pypy.objspace.flow.model import *
+from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
+from pypy.rpython.lltypesystem.lloperation import llop
+from pypy.rpython.lltypesystem.lltype import Signed
+from pypy.rpython.test.test_llinterp import interpret
 
 def optest(testcase):
-    opname = testcase[0]
-    llopname = testcase[1]
+    llopname = testcase[0]
+    RESTYPE = testcase[1] 
     args = testcase[2:]
 
-    # This code adpated from translator/c/test/test_operation.py
-    inputvars = [Variable() for _ in args]
-    block = Block(inputvars)
-    op = SpaceOperation(opname, inputvars, Variable())
-    block.operations.append(op)
-    graph = FunctionGraph('operationdummy', block)
-    block.closeblock(Link([op.result], graph.returnblock))
+    llopfunc = getattr(llop, llopname)
+    arg_signature = ", ".join(["v%s" % n for n in range(len(args))])
+    exec """def lloptest(%s):
+        return llop.%s(%s, %s)""" \
+                % (arg_signature, llopname, RESTYPE._name,
+                   arg_signature)
 
     annotation = [type(a) for a in args]
-    sqfunc = compile_function(operationdummy, annotation, graph)
-
-    # Make sure we actually test what we intend to test
-    found_llop = False
-    for op in sqfunc.graph.startblock.operations:
-        if op.opname == llopname:
-            found_llop = True
-            break
-    assert found_llop
-
-    expected_result = FunctionByName[opname](*args)
-    assert sqfunc(*args) == str(expected_result)
-
-def operationdummy(v1, v2):
-    pass
+    sqfunc = compile_function(lloptest, annotation)
+    res = interpret(lloptest, args, policy=LowLevelAnnotatorPolicy())
+    assert sqfunc(*args) == str(res)
 
 def test_intoperations():
     tests = [
         # XXX Must handle overflows for all integer ops
-        ("add", "int_add", 1, 2),
-        ("sub", "int_sub", 1, 3),
-        ("mul", "int_mul", 2, 3),
-        # I think int_div and int_truediv are currently never generated
-        ("floordiv", "int_floordiv", 7, 3),
-        ("floordiv", "int_floordiv", -7, 3),
+        ("int_add", Signed, 1, 2),
+        ("int_sub", Signed, 1, 3),
+        ("int_mul", Signed, 2, 3),
+        ("int_div", Signed, 7, 3),
+        ("int_floordiv", Signed, 7, 3),
+        ("int_floordiv", Signed, -7, 3),
+        ("int_abs", Signed, 7),
+        ("int_abs", Signed, -7),
     ]
     for t in tests:
         yield optest, t



More information about the Pypy-commit mailing list