[pypy-svn] r23030 - in pypy/dist/pypy/jit: . test

arigo at codespeak.net arigo at codespeak.net
Sat Feb 4 18:28:07 CET 2006


Author: arigo
Date: Sat Feb  4 18:28:05 2006
New Revision: 23030

Modified:
   pypy/dist/pypy/jit/hintmodel.py
   pypy/dist/pypy/jit/test/test_hint_annotation.py
Log:
* added some more operations to the base SomeLLAbstractValue class
* added a HintError exception for detected hint() inconsistencies
* two tests about HintError -- the second one is subject to discussion:
    I don't see how the annotations we get in the second test could be
    rtyped.  I don't see (at the moment) how we can carry "green" variables
    along the exit links of a "red" exitswitch...



Modified: pypy/dist/pypy/jit/hintmodel.py
==============================================================================
--- pypy/dist/pypy/jit/hintmodel.py	(original)
+++ pypy/dist/pypy/jit/hintmodel.py	Sat Feb  4 18:28:05 2006
@@ -21,6 +21,9 @@
                        uint_gt uint_lt uint_le uint_ge uint_eq uint_ne
                        getarrayitem""".split()
 
+class HintError(Exception):
+    pass
+
 class OriginFlags(object):
 
     fixed = False
@@ -140,6 +143,14 @@
     def same_as(hs_v1):
         return hs_v1
 
+    def hint(hs_v1, hs_flags):
+        if hs_flags.const.get('variable', False): # only for testing purposes!!!
+            return SomeLLAbstractVariable(hs_c1.concretetype)
+        if hs_flags.const.get('concrete', False):
+            raise HintError("cannot make a concrete from %r" % (hs_v1,))
+        if hs_flags.const.get('forget', False):
+            XXX    # not implemented
+
 class __extend__(SomeLLAbstractConstant):
 
     def hint(hs_c1, hs_flags):
@@ -151,8 +162,7 @@
             hs_concrete = reorigin(hs_c1)
             hs_concrete.eager_concrete = True
             return hs_concrete 
-        else:
-            assert hs_flags.const['forget']
+        if hs_flags.const.get('forget', False):
             assert isinstance(hs_c1, SomeLLAbstractConstant)
             return reorigin(hs_c1)
 
@@ -283,8 +293,21 @@
 
 class __extend__(pairtype(SomeLLAbstractValue, SomeLLAbstractValue)):
 
-    def int_add((hs_v1, hs_v2)):
-        return SomeLLAbstractVariable(lltype.Signed)
+    def define_binary(TYPE):
+        def var_binary((hs_v1, hs_v2)):
+            return SomeLLAbstractVariable(TYPE)
+        return var_binary
+
+    int_mul = int_mod = int_sub = int_add = define_binary(lltype.Signed)
+    int_floordiv = int_rshift = int_and = int_add 
+
+    uint_mul = uint_mod = uint_sub = uint_add = define_binary(lltype.Unsigned)
+    uint_floordiv = uint_rshift = uint_and = uint_add
+
+    int_lt = int_le = int_ge = int_ne = int_gt = int_eq = define_binary(lltype.Bool)
+    uint_lt = uint_le = uint_ge = uint_ne = uint_gt = uint_eq = int_eq
+
+    char_gt = char_lt = char_le = char_ge = char_eq = char_ne = int_eq
 
     def getarrayitem((hs_v1, hs_v2)):
         return SomeLLAbstractVariable(hs_v1.concretetype.TO.OF)

Modified: pypy/dist/pypy/jit/test/test_hint_annotation.py
==============================================================================
--- pypy/dist/pypy/jit/test/test_hint_annotation.py	(original)
+++ pypy/dist/pypy/jit/test/test_hint_annotation.py	Sat Feb  4 18:28:05 2006
@@ -377,3 +377,23 @@
         return acc
     assert ll_plus_minus("+-+", 0, 2) == 2
     hannotate(ll_plus_minus, [str, int, int])
+
+def test_invalid_hint_1():
+    S = lltype.GcStruct('S', ('x', lltype.Signed))
+    def ll_getitem_switch(s):
+        n = s.x    # -> variable
+        return hint(n, concrete=True)
+    py.test.raises(HintError, hannotate,
+                   ll_getitem_switch, [annmodel.SomePtr(lltype.Ptr(S))])
+
+def test_invalid_hint_2():
+    S = lltype.GcStruct('S', ('x', lltype.Signed))
+    def ll_getitem_switch(s):
+        if s.x > 0:   # variable exitswitch
+            sign = 1
+        else:
+            sign = -1
+        return hint(sign, concrete=True)
+    py.test.skip("in-progress: I think we expect a HintError here, do we?")
+    py.test.raises(HintError, hannotate,
+                   ll_getitem_switch, [annmodel.SomePtr(lltype.Ptr(S))])



More information about the Pypy-commit mailing list