[pypy-commit] pypy default: A bug and fix in the dict insertion code. Interestingly, CPython has

2012-10-28 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r58529:a18b9bbc6530
Date: 2012-10-28 08:11 +0100
http://bitbucket.org/pypy/pypy/changeset/a18b9bbc6530/

Log:A bug and fix in the dict insertion code. Interestingly, CPython
has the same bug until changes in 3.3 fixed it.

diff --git a/pypy/rpython/lltypesystem/lltype.py 
b/pypy/rpython/lltypesystem/lltype.py
--- a/pypy/rpython/lltypesystem/lltype.py
+++ b/pypy/rpython/lltypesystem/lltype.py
@@ -1651,10 +1651,7 @@
 if n  0:
 raise ValueError, negative array length
 _parentable.__init__(self, TYPE)
-try:
-myrange = range(n)
-except OverflowError:
-raise MemoryError(definitely too many items)
+myrange = self._check_range(n)
 self.items = [TYPE.OF._allocate(initialization=initialization,
 parent=self, parentindex=j)
   for j in myrange]
@@ -1664,6 +1661,14 @@
 def __repr__(self):
 return '%s' % (self,)
 
+def _check_range(self, n):
+# checks that it's ok to make an array of size 'n', and returns
+# range(n).  Explicitly overridden by some tests.
+try:
+return range(n)
+except OverflowError:
+raise MemoryError(definitely too many items)
+
 def _str_item(self, item):
 if isinstance(item, _uninitialized):
 return '#'
diff --git a/pypy/rpython/lltypesystem/rdict.py 
b/pypy/rpython/lltypesystem/rdict.py
--- a/pypy/rpython/lltypesystem/rdict.py
+++ b/pypy/rpython/lltypesystem/rdict.py
@@ -4,6 +4,7 @@
  rtype_newdict)
 from pypy.rpython.lltypesystem import lltype
 from pypy.rlib import objectmodel, jit
+from pypy.rlib.debug import ll_assert
 from pypy.rlib.rarithmetic import r_uint, intmask, LONG_BIT
 from pypy.rpython import rmodel
 from pypy.rpython.error import TyperError
@@ -462,22 +463,30 @@
 def _ll_dict_setitem_lookup_done(d, key, value, hash, i):
 valid = (i  HIGHEST_BIT) == 0
 i = i  MASK
-everused = d.entries.everused(i)
-# set up the new entry
 ENTRY = lltype.typeOf(d.entries).TO.OF
 entry = d.entries[i]
-entry.value = value
-if valid:
-return
+if not d.entries.everused(i):
+# a new entry that was never used before
+ll_assert(not valid, valid but not everused)
+rc = d.resize_counter - 3
+if rc = 0:   # if needed, resize the dict -- before the insertion
+ll_dict_resize(d)
+i = ll_dict_lookup_clean(d, hash)  # then redo the lookup for 'key'
+entry = d.entries[i]
+rc = d.resize_counter - 3
+ll_assert(rc  0, ll_dict_resize failed?)
+d.resize_counter = rc
+if hasattr(ENTRY, 'f_everused'): entry.f_everused = True
+entry.value = value
+else:
+# override an existing or deleted entry
+entry.value = value
+if valid:
+return
 entry.key = key
 if hasattr(ENTRY, 'f_hash'):  entry.f_hash = hash
 if hasattr(ENTRY, 'f_valid'): entry.f_valid = True
 d.num_items += 1
-if not everused:
-if hasattr(ENTRY, 'f_everused'): entry.f_everused = True
-d.resize_counter -= 3
-if d.resize_counter = 0:
-ll_dict_resize(d)
 
 def ll_dict_insertclean(d, key, value, hash):
 # Internal routine used by ll_dict_resize() to insert an item which is
@@ -534,8 +543,9 @@
 # make a 'new_size' estimate and shrink it if there are many
 # deleted entry markers.  See CPython for why it is a good idea to
 # quadruple the dictionary size as long as it's not too big.
-if d.num_items  5: new_estimate = d.num_items * 2
-else:   new_estimate = d.num_items * 4
+num_items = d.num_items + 1
+if num_items  5: new_estimate = num_items * 2
+else: new_estimate = num_items * 4
 new_size = DICT_INITSIZE
 while new_size = new_estimate:
 new_size *= 2
diff --git a/pypy/rpython/test/test_rdict.py b/pypy/rpython/test/test_rdict.py
--- a/pypy/rpython/test/test_rdict.py
+++ b/pypy/rpython/test/test_rdict.py
@@ -970,6 +970,39 @@
 DICT = lltype.typeOf(llres.item1)
 assert sorted(DICT.TO.entries.TO.OF._flds) == ['f_hash', 'key', 
'value']
 
+def test_memoryerror_should_not_insert(self):
+# This shows a misbehaviour that also exists in CPython 2.7, but not
+# any more in CPython 3.3.  The behaviour is that even if a dict
+# insertion raises MemoryError, the new item is still inserted.
+# If we catch the MemoryError, we can keep inserting new items until
+# the dict table is completely full.  Then the next insertion loops
+# forever.  This test only checks that after a MemoryError the
+# new item was not inserted.
+def _check_small_range(self, n):
+if n = 128:
+raise MemoryError
+return range(n)
+

[pypy-commit] cffi default: Allow '[...]' when declaring a global array, and interpret it like '[]'.

2012-10-28 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1013:3bb5d49c0c00
Date: 2012-10-28 09:42 +0100
http://bitbucket.org/cffi/cffi/changeset/3bb5d49c0c00/

Log:Allow '[...]' when declaring a global array, and interpret it like
'[]'.

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -162,7 +162,7 @@
 decl)
 #
 if decl.name:
-tp = self._get_type(node)
+tp = self._get_type(node, partial_length_ok=True)
 if self._is_constant_declaration(node):
 self._declare('constant ' + decl.name, tp)
 else:
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1275,3 +1275,15 @@
 result = posix.read(fdr, 256)
 posix.close(fdr)
 assert result == bXhello, 42!\n
+
+def test_global_array_with_missing_length():
+ffi = FFI()
+ffi.cdef(int fooarray[];)
+lib = ffi.verify(int fooarray[50];)
+assert repr(lib.fooarray).startswith(cdata 'int *')
+
+def test_global_array_with_dotdotdot_length():
+ffi = FFI()
+ffi.cdef(int fooarray[...];)
+lib = ffi.verify(int fooarray[50];)
+assert repr(lib.fooarray).startswith(cdata 'int *')
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: implement unrolling of arraycopy over non-virtual and small sources

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r58530:a2711f030e6c
Date: 2012-10-28 15:24 +0100
http://bitbucket.org/pypy/pypy/changeset/a2711f030e6c/

Log:implement unrolling of arraycopy over non-virtual and small sources

diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py 
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -426,14 +426,31 @@
 source_start_box = self.get_constant_box(op.getarg(3))
 dest_start_box = self.get_constant_box(op.getarg(4))
 length = self.get_constant_box(op.getarg(5))
-if (source_value.is_virtual() and source_start_box and dest_start_box
-and length and (dest_value.is_virtual() or length.getint() = 8)):
+if (source_start_box and dest_start_box
+and length and (dest_value.is_virtual() or length.getint() = 8) 
and
+(source_value.is_virtual() or length.getint() = 8)):
 from pypy.jit.metainterp.optimizeopt.virtualize import VArrayValue
-assert isinstance(source_value, VArrayValue)
 source_start = source_start_box.getint()
 dest_start = dest_start_box.getint()
 for index in range(length.getint()):
-val = source_value.getitem(index + source_start)
+# XXX fish fish fish
+arraydescr = 
op.getdescr().get_extra_info().write_descrs_arrays[0]
+if source_value.is_virtual():
+assert isinstance(source_value, VArrayValue)
+val = source_value.getitem(index + source_start)
+else:
+if arraydescr.is_array_of_pointers():
+resbox = BoxPtr()
+elif arraydescr.is_array_of_floats():
+resbox = BoxFloat()
+else:
+resbox = BoxInt()
+newop = ResOperation(rop.GETARRAYITEM_GC,
+  [op.getarg(1),
+   ConstInt(index + source_start)], resbox,
+   descr=arraydescr)
+self.optimizer.propagate_forward(newop)
+val = self.getvalue(resbox)
 if dest_value.is_virtual():
 dest_value.setitem(index + dest_start, val)
 else:
@@ -441,7 +458,7 @@
  [op.getarg(2),
   ConstInt(index + dest_start),
   val.get_key_box()], None,
- descr=source_value.arraydescr)
+ descr=arraydescr)
 self.emit_operation(newop)
 return True
 if length and length.getint() == 0:
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -3239,6 +3239,42 @@
 '''
 self.optimize_loop(ops, expected)
 
+def test_arraycopy_not_virtual_2(self):
+ops = '''
+[p0]
+p1 = new_array(3, descr=arraydescr)
+call(0, p0, p1, 0, 0, 3, descr=arraycopydescr)
+i0 = getarrayitem_gc(p1, 0, descr=arraydescr)
+jump(i0)
+'''
+expected = '''
+[p0]
+i0 = getarrayitem_gc(p0, 0, descr=arraydescr)
+i1 = getarrayitem_gc(p0, 1, descr=arraydescr) # removed by the backend
+i2 = getarrayitem_gc(p0, 2, descr=arraydescr) # removed by the backend
+jump(i0)
+'''
+self.optimize_loop(ops, expected)
+
+def test_arraycopy_not_virtual_3(self):
+ops = '''
+[p0, p1]
+call(0, p0, p1, 0, 0, 3, descr=arraycopydescr)
+i0 = getarrayitem_gc(p1, 0, descr=arraydescr)
+jump(i0)
+'''
+expected = '''
+[p0, p1]
+i0 = getarrayitem_gc(p0, 0, descr=arraydescr)
+i1 = getarrayitem_gc(p0, 1, descr=arraydescr)
+i2 = getarrayitem_gc(p0, 2, descr=arraydescr)
+setarrayitem_gc(p1, 0, i0, descr=arraydescr)
+setarrayitem_gc(p1, 1, i1, descr=arraydescr)
+setarrayitem_gc(p1, 2, i2, descr=arraydescr)
+jump(i0)
+'''
+self.optimize_loop(ops, expected)
+
 def test_arraycopy_no_elem(self):
  this was actually observed in the wild
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: issue35: meh, Python 2.7 decided to drop complete support for 'buffer'

2012-10-28 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r1014:14eff35bfad7
Date: 2012-10-28 16:18 +0100
http://bitbucket.org/cffi/cffi/changeset/14eff35bfad7/

Log:issue35: meh, Python 2.7 decided to drop complete support for
'buffer' object at the same time that 'memoryview' was added. Work
around.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -4275,7 +4275,7 @@
 return NULL;
 }
 /*WRITE(cd-c_data, size)*/
-#if PY_MAJOR_VERSION  3
+#if PY_MAJOR_VERSION  3  !defined(PyMemoryView_Check)   /* Python 2.6 */
 return PyBuffer_FromReadWriteMemory(cd-c_data, size);
 #else
 {
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -9,7 +9,7 @@
 type_or_class = type
 mandatory_b_prefix = ''
 mandatory_u_prefix = 'u'
-readbuf = str
+readbuf = lambda buf: buf[:]
 bufchar = lambda x: x
 bytechr = chr
 class U(object):
@@ -1839,7 +1839,7 @@
 c[2] = b'-'
 buf[:2] = b'HI'
 assert string(c) == b'HI-there'
-if sys.version_info  (3,) or sys.version_info = (3, 3):
+if sys.version_info  (2, 7) or sys.version_info = (3, 3):
 assert buf[:4:2] == b'H-'
 if '__pypy__' not in sys.builtin_module_names:
 # XXX pypy doesn't support the following assignment so far
diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py
--- a/cffi/backend_ctypes.py
+++ b/cffi/backend_ctypes.py
@@ -980,7 +980,7 @@
 return b._to_string(maxlen)
 
 def buffer(self, bptr, size=-1):
-if sys.version_info = (3,):
+if sys.version_info = (2, 7):
 # buf = bptr._as_ctype_ptr
 # return memoryview(buf.contents)
 if isinstance(bptr, CTypesGenericPtr):
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -1074,7 +1074,7 @@
 b = ffi.buffer(a)
 except NotImplementedError as e:
 py.test.skip(str(e))
-if sys.version  '3':
+if sys.version_info  (2, 7):
 assert type(b) is buffer
 content = str(b)
 else:
@@ -1098,7 +1098,7 @@
 b = ffi.buffer(a)
 except NotImplementedError as e:
 py.test.skip(str(e))
-if sys.version  '3':
+if sys.version_info  (2, 7):
 assert type(b) is buffer
 content = str(b)
 else:
@@ -1120,7 +1120,7 @@
 b = ffi.buffer(a, 1)
 except NotImplementedError as e:
 py.test.skip(str(e))
-if sys.version  '3':
+if sys.version_info  (2, 7):
 assert type(b) is buffer
 content = str(b)
 else:
@@ -1144,8 +1144,8 @@
 ffi.buffer(a1)
 except NotImplementedError as e:
 py.test.skip(str(e))
-if sys.version  '3':
-assert str(ffi.buffer(a1)) == str(ffi.buffer(a2, 4*10))
+if sys.version_info  (3,):
+assert ffi.buffer(a1)[:] == ffi.buffer(a2, 4*10)[:]
 else:
 assert ffi.buffer(a1).tobytes() == ffi.buffer(a2, 4*10).tobytes()
 
@@ -1169,6 +1169,24 @@
 f.close()
 os.unlink(filename)
 
+def test_ffi_buffer_with_io(self):
+ffi = FFI(backend=self.Backend())
+import io, array
+f = io.BytesIO()
+a = ffi.new(int[], list(range(1005)))
+try:
+ffi.buffer(a, 512)
+except NotImplementedError as e:
+py.test.skip(str(e))
+f.write(ffi.buffer(a, 1000 * ffi.sizeof(int)))
+f.seek(0)
+assert f.read() == array.array('i', range(1000)).tostring()
+f.seek(0)
+b = ffi.new(int[], 1005)
+f.readinto(ffi.buffer(b, 1000 * ffi.sizeof(int)))
+assert list(a)[:1000] + [0] * (len(a)-1000) == list(b)
+f.close()
+
 def test_array_in_struct(self):
 ffi = FFI(backend=self.Backend())
 ffi.cdef(struct foo_s { int len; short data[5]; };)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy result-in-resops: move a hack from store_final_boxes_in_guard

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: result-in-resops
Changeset: r58531:5548cd817164
Date: 2012-10-28 17:04 +0100
http://bitbucket.org/pypy/pypy/changeset/5548cd817164/

Log:move a hack from store_final_boxes_in_guard

diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py 
b/pypy/jit/metainterp/optimizeopt/optimizer.py
--- a/pypy/jit/metainterp/optimizeopt/optimizer.py
+++ b/pypy/jit/metainterp/optimizeopt/optimizer.py
@@ -573,6 +573,7 @@
 raise compile.giveup()
 descr.store_final_boxes(op, newboxes)
 #
+xxx
 if op.getopnum() == rop.GUARD_VALUE:
 xxx
 if self.getvalue(op.getarg(0)).is_bool_box:
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py 
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -5,7 +5,8 @@
  CONST_0
 from pypy.jit.metainterp.resoperation import (opboolinvers, opboolreflex, rop,
   ConstInt, make_hashable_int,
-  create_resop_2, Const)
+  create_resop_2, Const,
+  create_resop_1)
 from pypy.rlib.rarithmetic import highest_bit
 
 
@@ -194,7 +195,7 @@
   'always fail')
 return
 if emit_operation:
-return self.getforwarded(op)
+return op
 
 def postprocess_guard(self, op, constbox):
 value = self.getforwarded(op.getarg(0))
@@ -270,6 +271,17 @@
 value.last_guard = None
 emit_operation = False
 else:
+if not value.is_constant() and value.returns_bool_result():
+constvalue = op.getarg(1).getint()
+if constvalue == 0:
+newop = create_resop_1(rop.GUARD_FALSE, None,
+   op.getarg(0))
+elif constvalue == 1: 
+newop = create_resop_1(rop.GUARD_TRUE, None,
+   op.getarg(0))
+else:
+raise AssertionError(uh?)
+return newop
 emit_operation = True
 constbox = op.getarg(1)
 assert isinstance(constbox, Const)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix imports

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r58532:83532451dc20
Date: 2012-10-28 17:09 +0100
http://bitbucket.org/pypy/pypy/changeset/83532451dc20/

Log:fix imports

diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py 
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -5,7 +5,7 @@
 from pypy.jit.metainterp.optimizeopt.optimizer import *
 from pypy.jit.metainterp.optimizeopt.util import _findall, 
make_dispatcher_method
 from pypy.jit.metainterp.resoperation import (opboolinvers, opboolreflex, rop,
-ResOperation)
+ResOperation, BoxPtr, BoxInt, BoxFloat)
 from pypy.rlib.rarithmetic import highest_bit
 
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: remove an import * and fix import locations

2012-10-28 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: 
Changeset: r58533:b28deb1c63e7
Date: 2012-10-28 09:12 -0700
http://bitbucket.org/pypy/pypy/changeset/b28deb1c63e7/

Log:remove an import * and fix import locations

diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py 
b/pypy/jit/metainterp/optimizeopt/optimizer.py
--- a/pypy/jit/metainterp/optimizeopt/optimizer.py
+++ b/pypy/jit/metainterp/optimizeopt/optimizer.py
@@ -1,17 +1,17 @@
 from pypy.jit.metainterp import jitprof, resume, compile
 from pypy.jit.metainterp.executor import execute_nonspec
-from pypy.jit.metainterp.history import BoxInt, BoxFloat, Const, ConstInt, 
REF, INT
+from pypy.jit.metainterp.history import BoxInt, BoxFloat, Const, ConstInt, REF
 from pypy.jit.metainterp.optimizeopt.intutils import IntBound, IntUnbounded, \
  ImmutableIntUnbounded, \
  IntLowerBound, MININT, 
MAXINT
-from pypy.jit.metainterp.optimizeopt.util import (make_dispatcher_method,
-args_dict)
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
 from pypy.jit.metainterp.resoperation import rop, ResOperation, AbstractResOp
 from pypy.jit.metainterp.typesystem import llhelper, oohelper
 from pypy.tool.pairtype import extendabletype
-from pypy.rlib.debug import debug_start, debug_stop, debug_print
+from pypy.rlib.debug import debug_print
 from pypy.rlib.objectmodel import specialize
 
+
 LEVEL_UNKNOWN= '\x00'
 LEVEL_NONNULL= '\x01'
 LEVEL_KNOWNCLASS = '\x02' # might also mean KNOWNARRAYDESCR, for arrays
@@ -20,6 +20,8 @@
 MODE_ARRAY   = '\x00'
 MODE_STR = '\x01'
 MODE_UNICODE = '\x02'
+
+
 class LenBound(object):
 def __init__(self, mode, descr, bound):
 self.mode = mode
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py 
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -1,11 +1,14 @@
 from pypy.jit.codewriter.effectinfo import EffectInfo
-from pypy.jit.metainterp.history import ConstInt, make_hashable_int
+from pypy.jit.metainterp import compile
+from pypy.jit.metainterp.history import (Const, ConstInt, BoxInt, BoxFloat,
+BoxPtr, make_hashable_int)
 from pypy.jit.metainterp.optimize import InvalidLoop
 from pypy.jit.metainterp.optimizeopt.intutils import IntBound
-from pypy.jit.metainterp.optimizeopt.optimizer import *
+from pypy.jit.metainterp.optimizeopt.optimizer import (Optimization, REMOVED,
+CONST_0, CONST_1)
 from pypy.jit.metainterp.optimizeopt.util import _findall, 
make_dispatcher_method
 from pypy.jit.metainterp.resoperation import (opboolinvers, opboolreflex, rop,
-ResOperation, BoxPtr, BoxInt, BoxFloat)
+ResOperation)
 from pypy.rlib.rarithmetic import highest_bit
 
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix some imports

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r58534:b9840b6692d4
Date: 2012-10-28 17:46 +0100
http://bitbucket.org/pypy/pypy/changeset/b9840b6692d4/

Log:fix some imports

diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py 
b/pypy/jit/metainterp/optimizeopt/unroll.py
--- a/pypy/jit/metainterp/optimizeopt/unroll.py
+++ b/pypy/jit/metainterp/optimizeopt/unroll.py
@@ -4,6 +4,7 @@
 from pypy.jit.metainterp.history import TreeLoop, TargetToken, JitCellToken
 from pypy.jit.metainterp.jitexc import JitException
 from pypy.jit.metainterp.optimize import InvalidLoop
+from pypy.rlib.debug import debug_print, debug_start, debug_stop
 from pypy.jit.metainterp.optimizeopt.optimizer import *
 from pypy.jit.metainterp.optimizeopt.generalize import KillHugeIntBounds
 from pypy.jit.metainterp.inliner import Inliner
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy result-in-resops: first real virtual test

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: result-in-resops
Changeset: r58535:a08cae4bda5b
Date: 2012-10-28 18:21 +0100
http://bitbucket.org/pypy/pypy/changeset/a08cae4bda5b/

Log:first real virtual test

diff --git a/pypy/jit/metainterp/optimizeopt/heap.py 
b/pypy/jit/metainterp/optimizeopt/heap.py
--- a/pypy/jit/metainterp/optimizeopt/heap.py
+++ b/pypy/jit/metainterp/optimizeopt/heap.py
@@ -368,21 +368,29 @@
 return pendingfields
 
 def optimize_GETFIELD_GC_i(self, op):
-structvalue = self.getvalue(op.getarg(0))
+structvalue = self.getforwarded(op.getarg(0))
 cf = self.field_cache(op.getdescr())
 fieldvalue = cf.getfield_from_cache(self, structvalue)
 if fieldvalue is not None:
 self.replace(op, fieldvalue.op)
 return
 # default case: produce the operation
-structvalue.ensure_nonnull()
-self.emit_operation(op)
-# then remember the result of reading the field
-fieldvalue = self.getvalue(op)
-cf.remember_field_value(structvalue, fieldvalue, op)
+structvalue.setknownnonnull(True)
+return op
+
 optimize_GETFIELD_GC_r = optimize_GETFIELD_GC_i
 optimize_GETFIELD_GC_f = optimize_GETFIELD_GC_i
 
+def postprocess_GETFIELD_GC_i(self, op):
+# then remember the result of reading the field
+structvalue = self.getforwarded(op.getarg(0))
+fieldvalue = self.getforwarded(op)
+cf = self.field_cache(op.getdescr())
+cf.remember_field_value(structvalue, fieldvalue, op)
+
+postprocess_GETFIELD_GC_r = postprocess_GETFIELD_GC_i
+postprocess_GETFIELD_GC_f = postprocess_GETFIELD_GC_i
+
 def optimize_GETFIELD_GC_PURE_i(self, op):
 structvalue = self.getvalue(op.getarg(0))
 cf = self.field_cache(op.getdescr())
diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py 
b/pypy/jit/metainterp/optimizeopt/optimizer.py
--- a/pypy/jit/metainterp/optimizeopt/optimizer.py
+++ b/pypy/jit/metainterp/optimizeopt/optimizer.py
@@ -561,6 +561,7 @@
 
 def store_final_boxes_in_guard(self, op):
 return op # XXX we disable it for tests
+
 assert op.getdescr() is None
 descr = op.invent_descr(self.jitdriver_sd, self.metainterp_sd)
 op.setdescr(descr)
@@ -573,29 +574,6 @@
 raise compile.giveup()
 descr.store_final_boxes(op, newboxes)
 #
-xxx
-if op.getopnum() == rop.GUARD_VALUE:
-xxx
-if self.getvalue(op.getarg(0)).is_bool_box:
-# Hack: turn guard_value(bool) into guard_true/guard_false.
-# This is done after the operation is emitted to let
-# store_final_boxes_in_guard set the guard_opnum field of the
-# descr to the original rop.GUARD_VALUE.
-constvalue = op.getarg(1).getint()
-if constvalue == 0:
-newop = create_resop_1(rop.GUARD_FALSE, None,
-   op.getarg(0))
-elif constvalue == 1: 
-newop = create_resop_1(rop.GUARD_TRUE, None,
-   op.getarg(0))
-else:
-raise AssertionError(uh?)
-newop.set_extra(failargs, op.get_extra(failargs))
-self.replace(op, newop)
-return newop
-else:
-# a real GUARD_VALUE.  Make it use one counter per value.
-descr.make_a_counter_per_value(op)
 return op
 
 def optimize_default(self, op):
diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py 
b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -440,8 +440,8 @@
 fieldvalue = self.optimizer.new_const(op.getdescr())
 self.optimizer.replace(op, fieldvalue)
 else:
-value.ensure_nonnull()
-self.emit_operation(op)
+value.setknownnonnull(True)
+return op
 optimize_GETFIELD_GC_r = optimize_GETFIELD_GC_i
 optimize_GETFIELD_GC_f = optimize_GETFIELD_GC_i
 
diff --git a/pypy/jit/metainterp/virtualmodel.py 
b/pypy/jit/metainterp/virtualmodel.py
--- a/pypy/jit/metainterp/virtualmodel.py
+++ b/pypy/jit/metainterp/virtualmodel.py
@@ -1,5 +1,6 @@
 
-from pypy.jit.metainterp.resoperation import rop, opclasses
+from pypy.jit.metainterp.resoperation import rop, opclasses, create_resop_2
+from pypy.rlib.objectmodel import we_are_translated
 
 NEW_WITH_VTABLE = opclasses[rop.NEW_WITH_VTABLE]
 
@@ -34,8 +35,19 @@
 
 def force(self, optimizer):
 if not self._is_forced:
+self._is_forced = True
 optimizer.emit_operation(self)
-self._is_forced = True
+iteritems = self._fields.iteritems()
+if not we_are_translated(): 

[pypy-commit] pypy result-in-resops: fix those tests, they're still fine

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: result-in-resops
Changeset: r58536:eb30095a8f30
Date: 2012-10-28 18:25 +0100
http://bitbucket.org/pypy/pypy/changeset/eb30095a8f30/

Log:fix those tests, they're still fine

diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -615,9 +615,9 @@
 escape(i3)
 p1 = new_with_vtable(ConstClass(node_vtable))
 p1sub = new_with_vtable(ConstClass(node_vtable2))
-setfield_gc(p1, i1, descr=valuedescr)
 setfield_gc(p1sub, i1, descr=valuedescr)
 setfield_gc(p1, p1sub, descr=nextdescr)
+setfield_gc(p1, i1, descr=valuedescr)
 jump(i1, p1, p2)
 
 # The same as test_p123_simple, but with a virtual containing another
@@ -630,10 +630,10 @@
 p3sub = getfield_gc_r(p3, descr=nextdescr)
 i3 = getfield_gc_i(p3sub, descr=valuedescr)
 escape(i3)
-p1 = new_with_vtable(ConstClass(node_vtable))
 p2sub = new_with_vtable(ConstClass(node_vtable2))
 setfield_gc(p2sub, i1, descr=valuedescr)
 setfield_gc(p2, p2sub, descr=nextdescr)
+p1 = new_with_vtable(ConstClass(node_vtable))
 jump(i1, p1, p2)
 
 # The same as test_p123_simple, but in the end the old p2 contains
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: disable the optimization until we find a better way

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r58538:c7efa45ae2a5
Date: 2012-10-28 18:38 +0100
http://bitbucket.org/pypy/pypy/changeset/c7efa45ae2a5/

Log:disable the optimization until we find a better way

diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py 
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -431,15 +431,16 @@
 length = self.get_constant_box(op.getarg(5))
 if (source_start_box and dest_start_box
 and length and (dest_value.is_virtual() or length.getint() = 8) 
and
-(source_value.is_virtual() or length.getint() = 8)):
+(source_value.is_virtual())): # or length.getint() = 8)):
 from pypy.jit.metainterp.optimizeopt.virtualize import VArrayValue
 source_start = source_start_box.getint()
 dest_start = dest_start_box.getint()
 for index in range(length.getint()):
 # XXX fish fish fish
-arraydescr = 
op.getdescr().get_extra_info().write_descrs_arrays[0]
+#arraydescr = 
op.getdescr().get_extra_info().write_descrs_arrays[0]
+assert isinstance(source_value, VArrayValue)
+arraydescr = source_value.arraydescr
 if source_value.is_virtual():
-assert isinstance(source_value, VArrayValue)
 val = source_value.getitem(index + source_start)
 else:
 if arraydescr.is_array_of_pointers():
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: a failing test

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r58539:d7db0a927f92
Date: 2012-10-28 18:41 +0100
http://bitbucket.org/pypy/pypy/changeset/d7db0a927f92/

Log:a failing test

diff --git a/pypy/jit/metainterp/test/test_list.py 
b/pypy/jit/metainterp/test/test_list.py
--- a/pypy/jit/metainterp/test/test_list.py
+++ b/pypy/jit/metainterp/test/test_list.py
@@ -128,6 +128,17 @@
 res = self.interp_operations(f, [], listops=True)
 assert res == 10
 
+def test_arraycopy_bug(self): 
+def f():
+l = [1, 2, 3, 4]
+l2 = [1, 2, 3, 4]
+l[2] = 13
+l2[0:len(l2)] = l[:]
+return l2[0] + l2[1] + l2[2] + l2[3]
+
+res = self.interp_operations(f, [], listops=True)
+assert res == 10   
+
 def test_arraycopy_full(self):
 jitdriver = JitDriver(greens = [], reds = ['n'])
 def f(n):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Tweak ll_arraycopy() to fix again the issue of the missing arraydescr

2012-10-28 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r58540:a18331247b12
Date: 2012-10-28 18:45 +0100
http://bitbucket.org/pypy/pypy/changeset/a18331247b12/

Log:Tweak ll_arraycopy() to fix again the issue of the missing
arraydescr among the calldescr.get_extra_info().

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -188,7 +188,7 @@
 src = py.code.Source(
 def %(name)s(%(arglist)s):
 if not we_are_translated():
-typecheck(%(arglist)s)
+typecheck(%(arglist)s)# pypy.rlib.objectmodel
 return %(name)s_original(%(arglist)s)
  % dict(name=f.func_name, arglist=arglist))
 #
diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -145,8 +145,11 @@
 from pypy.rlib.objectmodel import keepalive_until_here
 
 # XXX: Hack to ensure that we get a proper effectinfo.write_descrs_arrays
-if NonConstant(False):
-dest[dest_start] = source[source_start]
+# and also, maybe, speed up very small cases
+if length = 1:
+if length == 1:
+dest[dest_start] = source[source_start]
+return
 
 # supports non-overlapping copies only
 if not we_are_translated():
diff --git a/pypy/rlib/test/test_rgc.py b/pypy/rlib/test/test_rgc.py
--- a/pypy/rlib/test/test_rgc.py
+++ b/pypy/rlib/test/test_rgc.py
@@ -134,6 +134,23 @@
 
 assert check.called
 
+def test_ll_arraycopy_small():
+TYPE = lltype.GcArray(lltype.Signed)
+for length in range(5):
+a1 = lltype.malloc(TYPE, 10)
+a2 = lltype.malloc(TYPE, 6)
+org1 = range(20, 30)
+org2 = range(50, 56)
+for i in range(len(a1)): a1[i] = org1[i]
+for i in range(len(a2)): a2[i] = org2[i]
+rgc.ll_arraycopy(a1, a2, 4, 2, length)
+for i in range(10):
+assert a1[i] == org1[i]
+for i in range(6):
+if 2 = i  2 + length:
+assert a2[i] == a1[i+2]
+else:
+assert a2[i] == org2[i]
 
 
 def test_ll_shrink_array_1():
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix the test.

2012-10-28 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r58541:e7004e804a53
Date: 2012-10-28 18:46 +0100
http://bitbucket.org/pypy/pypy/changeset/e7004e804a53/

Log:Fix the test.

diff --git a/pypy/jit/metainterp/test/test_list.py 
b/pypy/jit/metainterp/test/test_list.py
--- a/pypy/jit/metainterp/test/test_list.py
+++ b/pypy/jit/metainterp/test/test_list.py
@@ -137,7 +137,7 @@
 return l2[0] + l2[1] + l2[2] + l2[3]
 
 res = self.interp_operations(f, [], listops=True)
-assert res == 10   
+assert res == f()
 
 def test_arraycopy_full(self):
 jitdriver = JitDriver(greens = [], reds = ['n'])
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: some speedups

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r58543:e5eb07255e76
Date: 2012-10-28 19:22 +0100
http://bitbucket.org/pypy/pypy/changeset/e5eb07255e76/

Log:some speedups

diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py 
b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -381,6 +381,8 @@
 class ConcreteArray(BaseConcreteArray):
 def __init__(self, shape, dtype, order, strides, backstrides):
 make_sure_not_resized(shape)
+make_sure_not_resized(strides)
+make_sure_not_resized(backstrides)
 self.shape = shape
 self.size = support.product(shape) * dtype.get_size()
 self.storage = dtype.itemtype.malloc(self.size)
@@ -389,8 +391,8 @@
 self.strides = strides
 self.backstrides = backstrides
 
-def create_iter(self, shape):
-if shape == self.get_shape():
+def create_iter(self, shape=None):
+if shape is None or shape == self.get_shape():
 return ConcreteArrayIterator(self)
 r = calculate_broadcast_strides(self.strides, self.backstrides,
 self.get_shape(), shape)
@@ -426,8 +428,8 @@
 def fill(self, box):
 loop.fill(self, box.convert_to(self.dtype))
 
-def create_iter(self, shape):
-if shape != self.get_shape():
+def create_iter(self, shape=None):
+if shape is not None and shape != self.get_shape():
 r = calculate_broadcast_strides(self.strides, self.backstrides,
 self.get_shape(), shape)
 return MultiDimViewIterator(self.parent,
diff --git a/pypy/module/micronumpy/arrayimpl/scalar.py 
b/pypy/module/micronumpy/arrayimpl/scalar.py
--- a/pypy/module/micronumpy/arrayimpl/scalar.py
+++ b/pypy/module/micronumpy/arrayimpl/scalar.py
@@ -34,7 +34,7 @@
 def get_shape(self):
 return []
 
-def create_iter(self, shape):
+def create_iter(self, shape=None):
 return ScalarIterator(self.value)
 
 def get_scalar_value(self):
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -190,7 +190,7 @@
 return space.call_function(cache.w_array_str, self)
 
 def dump_data(self):
-i = self.create_iter(self.get_shape())
+i = self.create_iter()
 first = True
 dtype = self.get_dtype()
 s = StringBuilder()
@@ -206,8 +206,6 @@
 return s.build()
 
 def create_iter(self, shape=None):
-if shape is None:
-shape = self.get_shape()
 return self.implementation.create_iter(shape)
 
 def create_axis_iter(self, shape, dim):
@@ -396,7 +394,7 @@
 if self.get_size()  1:
 raise OperationError(space.w_ValueError, space.wrap(
 The truth value of an array with more than one element is 
ambiguous. Use a.any() or a.all()))
-iter = self.create_iter(self.get_shape())
+iter = self.create_iter()
 return space.wrap(space.is_true(iter.getitem()))
 
 def _binop_impl(ufunc_name):
@@ -681,7 +679,7 @@
 if ndmin  len(shape):
 shape = [1] * (ndmin - len(shape)) + shape
 arr = W_NDimArray.from_shape(shape, dtype, order=order)
-arr_iter = arr.create_iter(arr.get_shape())
+arr_iter = arr.create_iter()
 for w_elem in elems_w:
 arr_iter.setitem(dtype.coerce(space, w_elem))
 arr_iter.next()
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -89,7 +89,7 @@
   reds = ['obj', 'obj_iter', 'cur_value'])
 
 def compute_reduce(obj, calc_dtype, func, done_func, identity):
-obj_iter = obj.create_iter(obj.get_shape())
+obj_iter = obj.create_iter()
 if identity is None:
 cur_value = obj_iter.getitem().convert_to(calc_dtype)
 obj_iter.next()
@@ -109,7 +109,7 @@
 return cur_value
 
 def fill(arr, box):
-arr_iter = arr.create_iter(arr.get_shape())
+arr_iter = arr.create_iter()
 while not arr_iter.done():
 arr_iter.setitem(box)
 arr_iter.next()
@@ -159,7 +159,7 @@
 
 def do_axis_reduce(shape, func, arr, dtype, axis, out, identity):
 out_iter = out.create_axis_iter(arr.get_shape(), axis)
-arr_iter = arr.create_iter(arr.get_shape())
+arr_iter = arr.create_iter()
 if identity is not None:
 identity = identity.convert_to(dtype)
 shapelen = len(shape)
@@ -192,7 +192,7 @@
 result = 0
 idx = 1
 dtype = arr.get_dtype()
-iter = arr.create_iter(arr.get_shape())
+iter = arr.create_iter()
 cur_best = iter.getitem()
 iter.next()
 shapelen = len(arr.get_shape())
diff --git 

[pypy-commit] pypy result-in-resops: cleanups and pass one more test

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: result-in-resops
Changeset: r58544:d0dcc32ecfe4
Date: 2012-10-28 19:33 +0100
http://bitbucket.org/pypy/pypy/changeset/d0dcc32ecfe4/

Log:cleanups and pass one more test

diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py 
b/pypy/jit/metainterp/optimizeopt/optimizer.py
--- a/pypy/jit/metainterp/optimizeopt/optimizer.py
+++ b/pypy/jit/metainterp/optimizeopt/optimizer.py
@@ -250,13 +250,6 @@
 def __init__(self):
 pass # make rpython happy
 
-#def propagate_forward(self, op):
-#raise NotImplementedError
-
-#def emit_operation(self, op):
-#self.last_emitted_operation = op
-#self.next_optimization.propagate_forward(op)
-
 def process_inputargs(self, args):
 pass
 
@@ -416,21 +409,6 @@
 def replace(self, op, with_):
 self.getforwarded(op)._forwarded = with_
 
-def copy_op_if_modified_by_optimization(self, op):
-
-new_op = op.copy_if_modified_by_optimization(self)
-if new_op is not op:
-self.replace(op, new_op)
-return new_op
-
-# XXX some RPython magic needed
-def copy_and_change(self, op, *args, **kwds):
-xxx
-new_op = op.copy_and_change(*args, **kwds)
-if new_op is not op:
-self.replace(op, new_op)
-return new_op
-
 def ensure_imported(self, value):
 pass
 
@@ -513,10 +491,11 @@
 for opt in self.optimizations:
 opt.process_inputargs(self.loop.inputargs)
 while i  len(self.loop.operations):
-op = self.loop.operations[i]
-orig_op = op
+orig_op = self.loop.operations[i]
+op = orig_op
 for opt in self.optimizations:
 op = opt.optimize_operation(op)
+# result can be either None, the same thing or a new operation
 if op is None:
 break
 else:
diff --git a/pypy/jit/metainterp/optimizeopt/pure.py 
b/pypy/jit/metainterp/optimizeopt/pure.py
--- a/pypy/jit/metainterp/optimizeopt/pure.py
+++ b/pypy/jit/metainterp/optimizeopt/pure.py
@@ -46,7 +46,6 @@
 else:
 self.pure_operations.set(orig_op, op)
 self.remember_emitting_pure(op)
-
 # otherwise, the operation remains
 if nextop:
 return nextop
@@ -62,14 +61,11 @@
 self.replace(op, oldop)
 self.last_emitted_operation = REMOVED
 return
-else:
-new_op = self.optimizer.getforwarded(op)
-self.pure_operations.set(new_op, op)
-self.remember_emitting_pure(op)
-
+new_op = self.optimizer.getforwarded(op)
+self.pure_operations.set(op, new_op)
+self.remember_emitting_pure(new_op)
 # replace CALL_PURE with just CALL
-xxx
-self.emit_operation(self.optimizer.copy_and_change(op, opnum))
+return new_op.make_forwarded_copy(opnum)
 return optimize_CALL_PURE
 optimize_CALL_PURE_i = _new_optimize_call_pure(rop.CALL_i)
 optimize_CALL_PURE_f = _new_optimize_call_pure(rop.CALL_f)
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py 
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -81,7 +81,7 @@
 elif v2.is_null():
 self.optimizer.replace(op, op.getarg(0))
 else:
-self.emit_operation(op)
+return op
 
 def optimize_INT_SUB(self, op):
 v2 = self.getforwarded(op.getarg(1))
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: seems my hacks made assertion worse

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r58545:67c628463599
Date: 2012-10-28 20:27 +0100
http://bitbucket.org/pypy/pypy/changeset/67c628463599/

Log:seems my hacks made assertion worse

diff --git a/py/_code/source.py b/py/_code/source.py
--- a/py/_code/source.py
+++ b/py/_code/source.py
@@ -118,7 +118,7 @@
 # 1. find the start of the statement
 from codeop import compile_command
 end = None
-for start in range(lineno, -1, max(-1, lineno - 10)):
+for start in range(lineno, -1, -1):
 if assertion:
 line = self.lines[start]
 # the following lines are not fully tested, change with care
@@ -135,9 +135,9 @@
 compile_command(trysource)
 except (SyntaxError, OverflowError, ValueError):
 continue
- 
+
 # 2. find the end of the statement
-for end in range(lineno+1, min(len(self)+1, lineno + 10)):
+for end in range(lineno+1, len(self)+1):
 trysource = self[start:end]
 if trysource.isparseable():
 return start, end
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: grr, my font sucks

2012-10-28 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r58546:aba6cf7fc006
Date: 2012-10-28 20:34 +0100
http://bitbucket.org/pypy/pypy/changeset/aba6cf7fc006/

Log:grr, my font sucks

diff --git a/pypy/module/micronumpy/strides.py 
b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -30,7 +30,7 @@
 rstrides[j] = strides[i] * chunk.step
 rbackstrides[j] = strides[i] * (chunk.lgt - 1) * chunk.step
 rshape[j] = chunk.lgt
-j += i
+j += 1
 rstart += strides[i] * chunk.start
 # add a reminder
 s = i + 1
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: make it possible to compare rbigints with == and != for testing

2012-10-28 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: 
Changeset: r58548:12f7aa38e6e2
Date: 2012-10-28 15:15 -0700
http://bitbucket.org/pypy/pypy/changeset/12f7aa38e6e2/

Log:make it possible to compare rbigints with == and != for testing

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -119,6 +119,17 @@
 self.size = size or len(digits)
 self.sign = sign
 
+# __eq__ and __ne__ method exist for testingl only, they are not RPython!
+def __eq__(self, other):
+# NOT_RPYTHON
+if not isinstance(other, rbigint):
+return NotImplemented
+return self.eq(other)
+
+def __ne__(self, other):
+# NOT_RPYTHON
+return not (self == other)
+
 def digit(self, x):
 Return the x'th digit, as an int.
 return self._digits[x]
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -1,14 +1,19 @@
 from __future__ import division
+
+import operator
+import sys
+from random import random, randint, sample
+
 import py
-import operator, sys, array
-from random import random, randint, sample
-from pypy.rlib.rbigint import rbigint, SHIFT, MASK, KARATSUBA_CUTOFF
-from pypy.rlib.rbigint import _store_digit, _mask_digit
-from pypy.rlib.rfloat import NAN
+
 from pypy.rlib import rbigint as lobj
 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, intmask
+from pypy.rlib.rbigint import (rbigint, SHIFT, MASK, KARATSUBA_CUTOFF,
+_store_digit, _mask_digit)
+from pypy.rlib.rfloat import NAN
 from pypy.rpython.test.test_llinterp import interpret
 
+
 class TestRLong(object):
 def test_simple(self):
 for op1 in [-2, -1, 0, 1, 2, 50]:
@@ -112,6 +117,17 @@
 rl = rbigint.fromint(sys.maxint).add(rbigint.fromint(42))
 assert rl.touint() == result
 
+def test_eq_ne_operators(self):
+a1 = rbigint.fromint(12)
+a2 = rbigint.fromint(12)
+a3 = rbigint.fromint(123)
+
+assert a1 == a2
+assert a1 != a3
+assert not (a1 != a2)
+assert not (a1 == a3)
+
+
 def gen_signs(l):
 for s in l:
 if s == 0:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy.float16: work in progress

2012-10-28 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: numpypy.float16
Changeset: r58549:919585f4f4a8
Date: 2012-10-28 19:45 +0200
http://bitbucket.org/pypy/pypy/changeset/919585f4f4a8/

Log:work in progress

diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -921,24 +921,31 @@
 
 class Float16(BaseType, Float):
 _attrs_ = ()
+T = rffi.USHORT
 
-T = rffi.FLOAT
 BoxType = interp_boxes.W_Float16Box
 format_code = e
 
+def _coerce(self, space, w_item):
+return self.box(space.float_w(space.call_function(space.w_float, 
w_item)))
+
+def str_format(self, box):
+return float2string(self.for_computation(self.unbox(box)), g,
+rfloat.DTSF_STR_PRECISION)
+
+def for_computation(self, v):
+return float(v)
+
+def default_fromstring(self, space):
+return self.box(-1.0)
+
+@specialize.argtype(1)
+def box(self, value):
+xxx
+
 class NonNativeFloat16(BaseType, NonNativeFloat):
 _attrs_ = ()
 
-T = rffi.FLOAT
-BoxType = interp_boxes.W_Float16Box
-format_code = e
-
-class Float16(BaseType, Float):
-_attrs_ = ()
-
-def get_element_size(self):
-return 16
-
 BoxType = interp_boxes.W_Float16Box
 format_code = e
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy.float16: fix promotion of UInt64 - Float64, obscure use of indexes in builtin_types

2012-10-28 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: numpypy.float16
Changeset: r58551:935d79f359c2
Date: 2012-10-29 05:40 +0200
http://bitbucket.org/pypy/pypy/changeset/935d79f359c2/

Log:fix promotion of UInt64 - Float64, obscure use of indexes in
builtin_types

diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -407,7 +407,7 @@
 dtypenum = dt2.num + 1
 # UInt64 + signed = Float64
 if dt2.num == 10:
-dtypenum += 1
+dtypenum += 2
 newdtype = interp_dtype.get_dtype_cache(space).builtin_dtypes[dtypenum]
 
 if (newdtype.itemtype.get_element_size()  dt2.itemtype.get_element_size() 
or
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: remove old cruft

2012-10-28 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: 
Changeset: r58553:a11f3b7e7b8e
Date: 2012-10-29 05:58 +0200
http://bitbucket.org/pypy/pypy/changeset/a11f3b7e7b8e/

Log:remove old cruft

diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -275,14 +275,6 @@
 arr.storage[i] = arg[i]
 return W_StringBox(arr, 0, arr.dtype)
 
-# Running entire test suite needs this function to succeed,
-# running single test_stringarray succeeds without it.
-# With convert_to() test_ztranslation fails since 
-# W_CharacterBox is not a W_GenericBox.
-# Why is it needed for multiple tests?
-#def convert_to(self, dtype):
-#xxx
-
 class W_UnicodeBox(W_CharacterBox):
 def descr__new__unicode_box(space, w_subtype, w_arg):
 from pypy.module.micronumpy.interp_dtype import new_unicode_dtype
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge heads

2012-10-28 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: 
Changeset: r58554:0856e88f3e3e
Date: 2012-10-29 06:03 +0200
http://bitbucket.org/pypy/pypy/changeset/0856e88f3e3e/

Log:merge heads

diff --git a/pypy/rlib/rbigint.py b/pypy/rlib/rbigint.py
--- a/pypy/rlib/rbigint.py
+++ b/pypy/rlib/rbigint.py
@@ -119,6 +119,17 @@
 self.size = size or len(digits)
 self.sign = sign
 
+# __eq__ and __ne__ method exist for testingl only, they are not RPython!
+def __eq__(self, other):
+# NOT_RPYTHON
+if not isinstance(other, rbigint):
+return NotImplemented
+return self.eq(other)
+
+def __ne__(self, other):
+# NOT_RPYTHON
+return not (self == other)
+
 def digit(self, x):
 Return the x'th digit, as an int.
 return self._digits[x]
diff --git a/pypy/rlib/test/test_rbigint.py b/pypy/rlib/test/test_rbigint.py
--- a/pypy/rlib/test/test_rbigint.py
+++ b/pypy/rlib/test/test_rbigint.py
@@ -1,14 +1,19 @@
 from __future__ import division
+
+import operator
+import sys
+from random import random, randint, sample
+
 import py
-import operator, sys, array
-from random import random, randint, sample
-from pypy.rlib.rbigint import rbigint, SHIFT, MASK, KARATSUBA_CUTOFF
-from pypy.rlib.rbigint import _store_digit, _mask_digit
-from pypy.rlib.rfloat import NAN
+
 from pypy.rlib import rbigint as lobj
 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong, intmask
+from pypy.rlib.rbigint import (rbigint, SHIFT, MASK, KARATSUBA_CUTOFF,
+_store_digit, _mask_digit)
+from pypy.rlib.rfloat import NAN
 from pypy.rpython.test.test_llinterp import interpret
 
+
 class TestRLong(object):
 def test_simple(self):
 for op1 in [-2, -1, 0, 1, 2, 50]:
@@ -112,6 +117,17 @@
 rl = rbigint.fromint(sys.maxint).add(rbigint.fromint(42))
 assert rl.touint() == result
 
+def test_eq_ne_operators(self):
+a1 = rbigint.fromint(12)
+a2 = rbigint.fromint(12)
+a3 = rbigint.fromint(123)
+
+assert a1 == a2
+assert a1 != a3
+assert not (a1 != a2)
+assert not (a1 == a3)
+
+
 def gen_signs(l):
 for s in l:
 if s == 0:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy.float16: flesh out Float16 type

2012-10-28 Thread mattip
Author: mattip matti.pi...@gmail.com
Branch: numpypy.float16
Changeset: r58552:7bfd4719be6c
Date: 2012-10-29 05:56 +0200
http://bitbucket.org/pypy/pypy/changeset/7bfd4719be6c/

Log:flesh out Float16 type

diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -922,13 +922,11 @@
 class Float16(BaseType, Float):
 _attrs_ = ()
 T = rffi.USHORT
+_COMPUTATION_T = rffi.FLOAT
 
 BoxType = interp_boxes.W_Float16Box
 format_code = e
 
-def _coerce(self, space, w_item):
-return self.box(space.float_w(space.call_function(space.w_float, 
w_item)))
-
 def str_format(self, box):
 return float2string(self.for_computation(self.unbox(box)), g,
 rfloat.DTSF_STR_PRECISION)
@@ -941,7 +939,24 @@
 
 @specialize.argtype(1)
 def box(self, value):
-xxx
+return self.BoxType(
+rffi.cast(self._COMPUTATION_T, value))
+
+def unbox(self, box):
+assert isinstance(box, self.BoxType)
+return box.tofloat()
+
+def store(self, arr, i, offset, box):
+raw_storage_setitem(arr.storage, i+offset, box.tobytes())
+
+def _read(self, storage, i, offset):
+byte_rep = raw_storage_getitem(self.T, storage, i + offset)
+return self.BoxType.val_to_float(byte_rep)
+
+def read(self, arr, i, offset, dtype=None):
+val = self._read(arr.storage, i, offset)
+return self.BoxType(val)
+
 
 class NonNativeFloat16(BaseType, NonNativeFloat):
 _attrs_ = ()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit