[pypy-svn] r76145 - in pypy/branch/fast-forward: . pypy/jit/backend/llgraph pypy/jit/backend/llsupport pypy/jit/codewriter pypy/jit/codewriter/test pypy/jit/metainterp pypy/jit/metainterp/test pypy/rlib pypy/rlib/test pypy/rpython pypy/rpython/test pypy/translator/c/test

benjamin at codespeak.net benjamin at codespeak.net
Mon Jul 12 15:52:48 CEST 2010


Author: benjamin
Date: Mon Jul 12 15:52:46 2010
New Revision: 76145

Modified:
   pypy/branch/fast-forward/   (props changed)
   pypy/branch/fast-forward/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/fast-forward/pypy/jit/backend/llsupport/descr.py
   pypy/branch/fast-forward/pypy/jit/backend/llsupport/support.py
   pypy/branch/fast-forward/pypy/jit/codewriter/codewriter.py
   pypy/branch/fast-forward/pypy/jit/codewriter/jtransform.py
   pypy/branch/fast-forward/pypy/jit/codewriter/test/test_flatten.py
   pypy/branch/fast-forward/pypy/jit/metainterp/executor.py
   pypy/branch/fast-forward/pypy/jit/metainterp/test/test_recursive.py
   pypy/branch/fast-forward/pypy/rlib/rarithmetic.py
   pypy/branch/fast-forward/pypy/rlib/rdynload.py
   pypy/branch/fast-forward/pypy/rlib/test/test_rarithmetic.py
   pypy/branch/fast-forward/pypy/rpython/rstr.py
   pypy/branch/fast-forward/pypy/rpython/test/test_rstr.py
   pypy/branch/fast-forward/pypy/translator/c/test/test_typed.py
Log:
merge from trunk

Modified: pypy/branch/fast-forward/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/fast-forward/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/fast-forward/pypy/jit/backend/llgraph/llimpl.py	Mon Jul 12 15:52:46 2010
@@ -421,11 +421,9 @@
         global _last_exception
         assert _last_exception is None, "exception left behind"
         verbose = True
-        operations = self.loop.operations
-        opindex = 0
+        self.opindex = 0
         while True:
-            self.opindex = opindex
-            op = operations[opindex]
+            op = self.loop.operations[self.opindex]
             args = [self.getenv(v) for v in op.args]
             if not op.is_final():
                 try:
@@ -439,8 +437,8 @@
                         args = [self.getenv(v) for v in op.fail_args if v]
                         assert len(op.jump_target.inputargs) == len(args)
                         self.env = dict(zip(op.jump_target.inputargs, args))
-                        operations = op.jump_target.operations
-                        opindex = 0
+                        self.loop = op.jump_target
+                        self.opindex = 0
                         continue
                     else:
                         self._populate_fail_args(op)
@@ -465,14 +463,13 @@
                         raise Exception("op.result.concretetype is %r"
                                         % (RESTYPE,))
                     self.env[op.result] = x
-                opindex += 1
+                self.opindex += 1
                 continue
             if op.opnum == rop.JUMP:
                 assert len(op.jump_target.inputargs) == len(args)
                 self.env = dict(zip(op.jump_target.inputargs, args))
                 self.loop = op.jump_target
-                operations = self.loop.operations
-                opindex = 0
+                self.opindex = 0
                 _stats.exec_jumps += 1
             elif op.opnum == rop.FINISH:
                 if self.verbose:
@@ -1549,6 +1546,8 @@
 setannotation(do_getarrayitem_gc_int, annmodel.SomeInteger())
 setannotation(do_getarrayitem_gc_ptr, annmodel.SomePtr(llmemory.GCREF))
 setannotation(do_getarrayitem_gc_float, annmodel.SomeFloat())
+setannotation(do_getarrayitem_raw_int, annmodel.SomeInteger())
+setannotation(do_getarrayitem_raw_float, annmodel.SomeFloat())
 setannotation(do_getfield_gc_int, annmodel.SomeInteger())
 setannotation(do_getfield_gc_ptr, annmodel.SomePtr(llmemory.GCREF))
 setannotation(do_getfield_gc_float, annmodel.SomeFloat())
@@ -1560,6 +1559,8 @@
 setannotation(do_setarrayitem_gc_int, annmodel.s_None)
 setannotation(do_setarrayitem_gc_ptr, annmodel.s_None)
 setannotation(do_setarrayitem_gc_float, annmodel.s_None)
+setannotation(do_setarrayitem_raw_int, annmodel.s_None)
+setannotation(do_setarrayitem_raw_float, annmodel.s_None)
 setannotation(do_setfield_gc_int, annmodel.s_None)
 setannotation(do_setfield_gc_ptr, annmodel.s_None)
 setannotation(do_setfield_gc_float, annmodel.s_None)

Modified: pypy/branch/fast-forward/pypy/jit/backend/llsupport/descr.py
==============================================================================
--- pypy/branch/fast-forward/pypy/jit/backend/llsupport/descr.py	(original)
+++ pypy/branch/fast-forward/pypy/jit/backend/llsupport/descr.py	Mon Jul 12 15:52:46 2010
@@ -23,10 +23,10 @@
         self._cache_call = {}
 
     def init_size_descr(self, STRUCT, sizedescr):
-        pass
+        assert isinstance(STRUCT, lltype.GcStruct)
 
     def init_array_descr(self, ARRAY, arraydescr):
-        pass
+        assert isinstance(ARRAY, lltype.GcArray)
 
 
 # ____________________________________________________________
@@ -205,7 +205,8 @@
         assert basesize == arraydescr.get_base_size(False)
         assert itemsize == arraydescr.get_item_size(False)
         assert ofslength == arraydescr.get_ofs_length(False)
-        gccache.init_array_descr(ARRAY, arraydescr)
+        if isinstance(ARRAY, lltype.GcArray):
+            gccache.init_array_descr(ARRAY, arraydescr)
         cache[ARRAY] = arraydescr
         return arraydescr
 

Modified: pypy/branch/fast-forward/pypy/jit/backend/llsupport/support.py
==============================================================================
--- pypy/branch/fast-forward/pypy/jit/backend/llsupport/support.py	(original)
+++ pypy/branch/fast-forward/pypy/jit/backend/llsupport/support.py	Mon Jul 12 15:52:46 2010
@@ -30,7 +30,13 @@
 
     funcobj = get_funcobj(fnptr)
     if hasattr(funcobj, 'graph'):
-        llinterp = LLInterpreter(rtyper)  #, exc_data_ptr=exc_data_ptr)
+        # cache the llinterp; otherwise the remember_malloc/remember_free
+        # done on the LLInterpreter don't match
+        try:
+            llinterp = rtyper._on_top_of_llinterp_llinterp
+        except AttributeError:
+            llinterp = LLInterpreter(rtyper)  #, exc_data_ptr=exc_data_ptr)
+            rtyper._on_top_of_llinterp_llinterp = llinterp
         def on_top_of_llinterp(*args):
             real_args = process_args(args)
             return llinterp.eval_graph(funcobj.graph, real_args)

Modified: pypy/branch/fast-forward/pypy/jit/codewriter/codewriter.py
==============================================================================
--- pypy/branch/fast-forward/pypy/jit/codewriter/codewriter.py	(original)
+++ pypy/branch/fast-forward/pypy/jit/codewriter/codewriter.py	Mon Jul 12 15:52:46 2010
@@ -14,11 +14,12 @@
 class CodeWriter(object):
     callcontrol = None    # for tests
 
-    def __init__(self, cpu=None, jitdrivers_sd=[]):
+    def __init__(self, cpu=None, jitdrivers_sd=[], debug=False):
         self.cpu = cpu
         self.assembler = Assembler()
         self.callcontrol = CallControl(cpu, jitdrivers_sd)
         self._seen_files = set()
+        self.debug = debug
 
     def transform_func_to_jitcode(self, func, values, type_system='lltype'):
         """For testing."""
@@ -60,7 +61,8 @@
         self.assembler.assemble(ssarepr, jitcode)
         #
         # print the resulting assembler
-        self.print_ssa_repr(ssarepr, portal_jd, verbose)
+        if self.debug:
+            self.print_ssa_repr(ssarepr, portal_jd, verbose)
 
     def make_jitcodes(self, verbose=False):
         log.info("making JitCodes...")

Modified: pypy/branch/fast-forward/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/fast-forward/pypy/jit/codewriter/jtransform.py	(original)
+++ pypy/branch/fast-forward/pypy/jit/codewriter/jtransform.py	Mon Jul 12 15:52:46 2010
@@ -667,7 +667,7 @@
             return self._rewrite_symmetric(op)
 
     def _is_gc(self, v):
-        return v.concretetype.TO._gckind == 'gc'
+        return getattr(getattr(v.concretetype, "TO", None), "_gckind", "?") == 'gc'
 
     def _rewrite_cmp_ptrs(self, op):
         if self._is_gc(op.args[0]):
@@ -701,6 +701,42 @@
             #return op
             raise NotImplementedError("cast_ptr_to_int")
 
+    def rewrite_op_force_cast(self, op):
+        from pypy.rpython.lltypesystem.rffi import size_and_sign, sizeof
+        from pypy.rlib.rarithmetic import intmask
+        assert not self._is_gc(op.args[0])
+        size1, unsigned1 = size_and_sign(op.args[0].concretetype)
+        size2, unsigned2 = size_and_sign(op.result.concretetype)
+        if size2 >= sizeof(lltype.Signed):
+            return     # the target type is LONG or ULONG
+        #
+        def bounds(size, unsigned):
+            if unsigned:
+                return 0, 1<<(8*size)
+            else:
+                return -(1<<(8*size-1)), 1<<(8*size-1)
+        min1, max1 = bounds(size1, unsigned1)
+        min2, max2 = bounds(size2, unsigned2)
+        if min2 <= min1 <= max1 <= max2:
+            return     # the target type includes the source range
+        #
+        result = []
+        v1 = op.args[0]
+        if min2:
+            c_min2 = Constant(min2, lltype.Signed)
+            v2 = Variable(); v2.concretetype = lltype.Signed
+            result.append(SpaceOperation('int_sub', [v1, c_min2], v2))
+        else:
+            v2 = v1
+        c_mask = Constant(int((1<<(8*size2))-1), lltype.Signed)
+        v3 = Variable(); v3.concretetype = lltype.Signed
+        result.append(SpaceOperation('int_and', [v2, c_mask], v3))
+        if min2:
+            result.append(SpaceOperation('int_add', [v3, c_min2], op.result))
+        else:
+            result[-1].result = op.result
+        return result
+
     # ----------
     # Renames, from the _old opname to the _new one.
     # The new operation is optionally further processed by rewrite_operation().

Modified: pypy/branch/fast-forward/pypy/jit/codewriter/test/test_flatten.py
==============================================================================
--- pypy/branch/fast-forward/pypy/jit/codewriter/test/test_flatten.py	(original)
+++ pypy/branch/fast-forward/pypy/jit/codewriter/test/test_flatten.py	Mon Jul 12 15:52:46 2010
@@ -729,3 +729,108 @@
             int_between %i0, %i1, %i2 -> %i3
             int_return %i3
         """, transform=True)
+
+    def test_force_cast(self):
+        from pypy.rpython.lltypesystem import rffi
+
+        for FROM, TO, expected in [
+            (rffi.SIGNEDCHAR, rffi.SIGNEDCHAR, ""),
+            (rffi.SIGNEDCHAR, rffi.UCHAR, "int_and %i0, $255 -> %i1"),
+            (rffi.SIGNEDCHAR, rffi.SHORT, ""),
+            (rffi.SIGNEDCHAR, rffi.USHORT, "int_and %i0, $65535 -> %i1"),
+            (rffi.SIGNEDCHAR, rffi.LONG, ""),
+            (rffi.SIGNEDCHAR, rffi.ULONG, ""),
+
+            (rffi.UCHAR, rffi.SIGNEDCHAR, """int_sub %i0, $-128 -> %i1
+                                             int_and %i1, $255 -> %i2
+                                             int_add %i2, $-128 -> %i3"""),
+            (rffi.UCHAR, rffi.UCHAR, ""),
+            (rffi.UCHAR, rffi.SHORT, ""),
+            (rffi.UCHAR, rffi.USHORT, ""),
+            (rffi.UCHAR, rffi.LONG, ""),
+            (rffi.UCHAR, rffi.ULONG, ""),
+
+            (rffi.SHORT, rffi.SIGNEDCHAR, """int_sub %i0, $-128 -> %i1
+                                             int_and %i1, $255 -> %i2
+                                             int_add %i2, $-128 -> %i3"""),
+            (rffi.SHORT, rffi.UCHAR, "int_and %i0, $255 -> %i1"),
+            (rffi.SHORT, rffi.SHORT, ""),
+            (rffi.SHORT, rffi.USHORT, "int_and %i0, $65535 -> %i1"),
+            (rffi.SHORT, rffi.LONG, ""),
+            (rffi.SHORT, rffi.ULONG, ""),
+
+            (rffi.USHORT, rffi.SIGNEDCHAR, """int_sub %i0, $-128 -> %i1
+                                              int_and %i1, $255 -> %i2
+                                              int_add %i2, $-128 -> %i3"""),
+            (rffi.USHORT, rffi.UCHAR, "int_and %i0, $255 -> %i1"),
+            (rffi.USHORT, rffi.SHORT, """int_sub %i0, $-32768 -> %i1
+                                         int_and %i1, $65535 -> %i2
+                                         int_add %i2, $-32768 -> %i3"""),
+            (rffi.USHORT, rffi.USHORT, ""),
+            (rffi.USHORT, rffi.LONG, ""),
+            (rffi.USHORT, rffi.ULONG, ""),
+
+            (rffi.LONG, rffi.SIGNEDCHAR, """int_sub %i0, $-128 -> %i1
+                                            int_and %i1, $255 -> %i2
+                                            int_add %i2, $-128 -> %i3"""),
+            (rffi.LONG, rffi.UCHAR, "int_and %i0, $255 -> %i1"),
+            (rffi.LONG, rffi.SHORT, """int_sub %i0, $-32768 -> %i1
+                                       int_and %i1, $65535 -> %i2
+                                       int_add %i2, $-32768 -> %i3"""),
+            (rffi.LONG, rffi.USHORT, "int_and %i0, $65535 -> %i1"),
+            (rffi.LONG, rffi.LONG, ""),
+            (rffi.LONG, rffi.ULONG, ""),
+
+            (rffi.ULONG, rffi.SIGNEDCHAR, """int_sub %i0, $-128 -> %i1
+                                             int_and %i1, $255 -> %i2
+                                             int_add %i2, $-128 -> %i3"""),
+            (rffi.ULONG, rffi.UCHAR, "int_and %i0, $255 -> %i1"),
+            (rffi.ULONG, rffi.SHORT, """int_sub %i0, $-32768 -> %i1
+                                        int_and %i1, $65535 -> %i2
+                                        int_add %i2, $-32768 -> %i3"""),
+            (rffi.ULONG, rffi.USHORT, "int_and %i0, $65535 -> %i1"),
+            (rffi.ULONG, rffi.LONG, ""),
+            (rffi.ULONG, rffi.ULONG, ""),
+            ]:
+            expected = [s.strip() for s in expected.splitlines()]
+            check_force_cast(FROM, TO, expected, 42)
+            check_force_cast(FROM, TO, expected, -42)
+            expected.append('int_return %i' + str(len(expected)))
+            expected = '\n'.join(expected)
+            #
+            def f(n):
+                return rffi.cast(TO, n)
+            self.encoding_test(f, [rffi.cast(FROM, 42)], expected,
+                               transform=True)
+
+    def test_force_cast_pointer(self):
+        from pypy.rpython.lltypesystem import rffi
+        def h(p):
+            return rffi.cast(rffi.VOIDP, p)
+        self.encoding_test(h, [lltype.nullptr(rffi.CCHARP.TO)], """
+            int_return %i0
+        """, transform=True)
+
+
+def check_force_cast(FROM, TO, operations, value):
+    """Check that the test is correctly written..."""
+    from pypy.rpython.lltypesystem import rffi
+    import re
+    r = re.compile('(\w+) \%i\d, \$(-?\d+)')
+    #
+    value = rffi.cast(FROM, value)
+    value = rffi.cast(lltype.Signed, value)
+    #
+    expected_value = rffi.cast(TO, value)
+    expected_value = rffi.cast(lltype.Signed, expected_value)
+    #
+    for op in operations:
+        match = r.match(op)
+        assert match, "line %r does not match regexp" % (op,)
+        opname = match.group(1)
+        if   opname == 'int_add': value += int(match.group(2))
+        elif opname == 'int_sub': value -= int(match.group(2))
+        elif opname == 'int_and': value &= int(match.group(2))
+        else: assert 0, opname
+    #
+    assert rffi.cast(lltype.Signed, value) == expected_value

Modified: pypy/branch/fast-forward/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/fast-forward/pypy/jit/metainterp/executor.py	(original)
+++ pypy/branch/fast-forward/pypy/jit/metainterp/executor.py	Mon Jul 12 15:52:46 2010
@@ -91,7 +91,7 @@
         return BoxInt(cpu.bh_getarrayitem_gc_i(arraydescr, array, index))
 
 def do_getarrayitem_raw(cpu, _, arraybox, indexbox, arraydescr):
-    array = arraybox.getint()
+    array = arraybox.getref_base()
     index = indexbox.getint()
     assert not arraydescr.is_array_of_pointers()
     if arraydescr.is_array_of_floats():

Modified: pypy/branch/fast-forward/pypy/jit/metainterp/test/test_recursive.py
==============================================================================
--- pypy/branch/fast-forward/pypy/jit/metainterp/test/test_recursive.py	(original)
+++ pypy/branch/fast-forward/pypy/jit/metainterp/test/test_recursive.py	Mon Jul 12 15:52:46 2010
@@ -523,7 +523,7 @@
     def test_trace_from_start(self):
         def p(pc, code):
             code = hlstr(code)
-            return "%s %d %s" % (code, pc, code[pc])
+            return "'%s' at %d: %s" % (code, pc, code[pc])
         def c(pc, code):
             return "l" not in hlstr(code)
         myjitdriver = JitDriver(greens=['pc', 'code'], reds=['n'],
@@ -537,9 +537,9 @@
                 op = code[pc]
                 if op == "+":
                     n += 7
-                if op == "-":
+                elif op == "-":
                     n -= 1
-                if op == "c":
+                elif op == "c":
                     n = f('---', n)
                 elif op == "l":
                     if n > 0:
@@ -556,6 +556,7 @@
             result = 0
             for i in range(m):
                 result += f('+-cl--', i)
+        g(50)
         self.meta_interp(g, [50], backendopt=True)
         self.check_tree_loop_count(3)
         self.check_history(int_add=1)

Modified: pypy/branch/fast-forward/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rarithmetic.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rarithmetic.py	Mon Jul 12 15:52:46 2010
@@ -33,7 +33,7 @@
 
 
 """
-import math
+import sys, math
 from pypy.rpython import extregistry
 from pypy.rlib import objectmodel
 
@@ -206,14 +206,23 @@
     "NOT_RPYTHON"
     return _local_ovfcheck(int(long(a) << b))
 
-FL_MAXINT = float(LONG_TEST-1)
-FL_MININT = float(-LONG_TEST)
-
-def ovfcheck_float_to_int(x):
-    _, intp = math.modf(x)
-    if FL_MININT < intp < FL_MAXINT:
-        return int(intp)
-    raise OverflowError
+# Strange things happening for float to int on 64 bit:
+# int(float(i)) != i  because of rounding issues.
+# These are the minimum and maximum float value that can
+# successfully be casted to an int.
+if sys.maxint == 2147483647:
+    def ovfcheck_float_to_int(x):
+        if -2147483649.0 < x < 2147483648.0:
+            return int(x)
+        raise OverflowError
+else:
+    # The following values are not quite +/-sys.maxint.
+    # Note the "<= x <" here, as opposed to "< x <" above.
+    # This is justified by test_typed in translator/c/test.
+    def ovfcheck_float_to_int(x):
+        if -9223372036854776832.0 <= x < 9223372036854775296.0:
+            return int(x)
+        raise OverflowError
 
 def compute_restype(self_type, other_type):
     if self_type is other_type:

Modified: pypy/branch/fast-forward/pypy/rlib/rdynload.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/rdynload.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/rdynload.py	Mon Jul 12 15:52:46 2010
@@ -18,8 +18,6 @@
 
 if _WIN32:
     from pypy.rlib import rwin32
-
-if _WIN32:
     includes = ['windows.h']
 else:
     includes = ['dlfcn.h']

Modified: pypy/branch/fast-forward/pypy/rlib/test/test_rarithmetic.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rlib/test/test_rarithmetic.py	(original)
+++ pypy/branch/fast-forward/pypy/rlib/test/test_rarithmetic.py	Mon Jul 12 15:52:46 2010
@@ -271,26 +271,29 @@
     assert ovfcheck_float_to_int(13.0) == 13
     assert ovfcheck_float_to_int(-1.0) == -1
     assert ovfcheck_float_to_int(-13.0) == -13
-    #  strange things happening for float to int on 64 bit
-    maxint32 = 2 ** 31 - 1
-    assert ovfcheck_float_to_int(float(maxint32-1)) == maxint32-1
-    #assert ovfcheck_float_to_int(float(maxint32)) == maxint32
-    assert ovfcheck_float_to_int(float(-maxint32)) == -maxint32
-    #assert ovfcheck_float_to_int(float(-maxint32-1)) == -maxint32-1
-
-    try:
-        ovfcheck_float_to_int(float(-sys.maxint-1)-1)
-    except OverflowError:
-        pass
-    else:
-        assert False
-
-    try:
-        ovfcheck_float_to_int(float(sys.maxint)+1)
-    except OverflowError:
-        pass
-    else:
-        assert False
+
+    # strange things happening for float to int on 64 bit:
+    # int(float(i)) != i  because of rounding issues
+    x = sys.maxint
+    while int(float(x)) > sys.maxint:
+        x -= 1
+    assert ovfcheck_float_to_int(float(x)) == int(float(x))
+
+    x = sys.maxint + 1
+    while int(float(x)) <= sys.maxint:
+        x += 1
+    py.test.raises(OverflowError, ovfcheck_float_to_int, x)
+
+    x = -sys.maxint-1
+    while int(float(x)) < -sys.maxint-1:
+        x += 1
+    assert ovfcheck_float_to_int(float(x)) == int(float(x))
+
+    x = -sys.maxint-1
+    while int(float(x)) >= -sys.maxint-1:
+        x -= 1
+    py.test.raises(OverflowError, ovfcheck_float_to_int, x)
+
 
 def test_abs():
     assert type(abs(r_longlong(1))) is r_longlong

Modified: pypy/branch/fast-forward/pypy/rpython/rstr.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rpython/rstr.py	(original)
+++ pypy/branch/fast-forward/pypy/rpython/rstr.py	Mon Jul 12 15:52:46 2010
@@ -291,7 +291,11 @@
         if not hop.args_s[1].is_constant():
             raise TyperError("encoding must be constant")
         encoding = hop.args_s[1].const
-        v_self = hop.inputarg(self.repr, 0)
+        if encoding == "ascii":
+            expect = self.lowleveltype   # can be a UniChar
+        else:
+            expect = self.repr           # must be a regular unicode string
+        v_self = hop.inputarg(expect, 0)
         hop.exception_is_here()
         if encoding == "ascii":
             return hop.gendirectcall(self.ll_str, v_self)
@@ -418,7 +422,17 @@
             sourcevars.append((v_item, r_arg))
 
         return r_str.ll.do_stringformat(hop, sourcevars)
-                
+
+
+class __extend__(AbstractCharRepr):
+    def ll_str(self, ch):
+        return self.ll.ll_chr2str(ch)
+
+class __extend__(AbstractUniCharRepr):
+    def ll_str(self, ch):
+        # xxx suboptimal, maybe
+        return str(unicode(ch))
+
 
 class __extend__(AbstractCharRepr,
                  AbstractUniCharRepr):
@@ -436,9 +450,6 @@
 
     get_ll_fasthash_function = get_ll_hash_function
 
-    def ll_str(self, ch):
-        return self.ll.ll_chr2str(ch)
-
     def rtype_len(_, hop):
         return hop.inputconst(Signed, 1)
 

Modified: pypy/branch/fast-forward/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/branch/fast-forward/pypy/rpython/test/test_rstr.py	(original)
+++ pypy/branch/fast-forward/pypy/rpython/test/test_rstr.py	Mon Jul 12 15:52:46 2010
@@ -870,6 +870,24 @@
         res = self.interpret(f, [1])
         assert self.ll_to_string(res) == "hello"
 
+    def test_str_unichar(self):
+        def f(i):
+            c = u"abc"
+            return str(c[i])[0]
+        assert self.interpret(f, [1]) == "b"
+
+    def test_encode_char(self):
+        def f(i):
+            c = u"abc"
+            return c[i].encode("ascii")
+        assert self.ll_to_string(self.interpret(f, [0])) == "a"
+
+    def test_encode_char_latin1(self):
+        def f(i):
+            c = u"abc"
+            return c[i].encode("latin-1")
+        assert self.ll_to_string(self.interpret(f, [0])) == "a"
+
 def FIXME_test_str_to_pystringobj():
     def f(n):
         if n >= 0:

Modified: pypy/branch/fast-forward/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/branch/fast-forward/pypy/translator/c/test/test_typed.py	(original)
+++ pypy/branch/fast-forward/pypy/translator/c/test/test_typed.py	Mon Jul 12 15:52:46 2010
@@ -789,3 +789,37 @@
             return u'hello' + unichr(i)
         f = self.getcompiled(func, [int])
         assert f(0x1234) == u'hello\u1234'
+
+    def test_ovfcheck_float_to_int(self):
+        from pypy.rlib.rarithmetic import ovfcheck_float_to_int
+
+        def func(fl):
+            try:
+                return ovfcheck_float_to_int(fl)
+            except OverflowError:
+                return -666
+        f = self.getcompiled(func, [float])
+        assert f(-123.0) == -123
+
+        for frac in [0.0, 0.01, 0.99]:
+            # strange things happening for float to int on 64 bit:
+            # int(float(i)) != i  because of rounding issues
+            x = sys.maxint
+            while int(x + frac) > sys.maxint:
+                x -= 1
+            assert f(x + frac) == int(x + frac)
+
+            x = sys.maxint
+            while int(x - frac) <= sys.maxint:
+                x += 1
+            assert f(x - frac) == -666
+
+            x = -sys.maxint-1
+            while int(x - frac) < -sys.maxint-1:
+                x += 1
+            assert f(x - frac) == int(x - frac)
+
+            x = -sys.maxint-1
+            while int(x + frac) >= -sys.maxint-1:
+                x -= 1
+            assert f(x + frac) == -666



More information about the Pypy-commit mailing list