[pypy-commit] pypy default: fix bz2. tests didn't find this.
Author: Justin Peel notmuchtot...@gmail.com Branch: Changeset: r46937:b4d8eb5fdf6c Date: 2011-08-31 00:17 -0600 http://bitbucket.org/pypy/pypy/changeset/b4d8eb5fdf6c/ Log:fix bz2. tests didn't find this. diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py --- a/pypy/module/bz2/interp_bz2.py +++ b/pypy/module/bz2/interp_bz2.py @@ -446,7 +446,9 @@ result = self.buffer[pos:pos + n] self.pos += n else: -result = self.buffer +pos = self.pos +assert pos = 0 +result = self.buffer[pos:] self.pos = 0 self.buffer = self.readlength += len(result) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Add a test for range().sort(key=). It works, but you have not
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46938:a3a90cb98864 Date: 2011-08-30 04:56 +0200 http://bitbucket.org/pypy/pypy/changeset/a3a90cb98864/ Log:Add a test for range().sort(key=). It works, but you have not to blink when looking at the list_sort implementation of ranges. diff --git a/pypy/objspace/std/test/test_rangeobject.py b/pypy/objspace/std/test/test_rangeobject.py --- a/pypy/objspace/std/test/test_rangeobject.py +++ b/pypy/objspace/std/test/test_rangeobject.py @@ -89,6 +89,9 @@ assert not self.not_forced(r) r.sort() assert r == range(1, 100) + [999] +r = range(10) +r.sort(key=lambda x: -x) +assert r == range(9, -1, -1) def test_pop(self): r = range(10) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy jit-duplicated_short_boxes: prevent short_boxes from blowing up too much
Author: Hakan Ardo ha...@debian.org Branch: jit-duplicated_short_boxes Changeset: r46940:dd9ad57ee821 Date: 2011-08-31 11:28 +0200 http://bitbucket.org/pypy/pypy/changeset/dd9ad57ee821/ Log:prevent short_boxes from blowing up too much diff --git a/pypy/jit/metainterp/optimizeopt/virtualstate.py b/pypy/jit/metainterp/optimizeopt/virtualstate.py --- a/pypy/jit/metainterp/optimizeopt/virtualstate.py +++ b/pypy/jit/metainterp/optimizeopt/virtualstate.py @@ -531,6 +531,8 @@ allops = None for i in range(len(op.getarglist())): arg = op.getarg(i) +if len(self.duplicates) 5: +debug_print(Refusing to duplicate short box %d times. % len(self.duplicates)) if arg in self.duplicates: if not allops: allops = [op] diff --git a/pypy/jit/tl/pypyjit_demo.py b/pypy/jit/tl/pypyjit_demo.py --- a/pypy/jit/tl/pypyjit_demo.py +++ b/pypy/jit/tl/pypyjit_demo.py @@ -2,22 +2,16 @@ pypyjit.set_param(threshold=200) -def main(a, b): -i = sa = 0 -while i 300: -if a 0: # Specialises the loop -pass -if b 2 and b 0: -pass -if (a b) = 0: -sa += 1 -if (a b) 2: -sa += 1 -i += 1 -return sa +def f(n): +pairs = [(0.0, 1.0), (2.0, 3.0)] * n +mag = 0 +for (x1, x2) in pairs: +dx = x1 - x2 +mag += ((dx * dx ) ** (-1.5)) +return n try: -print main(2, 1) +print f(301) except Exception, e: print Exception: , type(e) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: (arigo, hager): Started to build proper stack frames, also amde first calls work.
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r46941:f5ffdcff7e59 Date: 2011-08-31 12:05 +0200 http://bitbucket.org/pypy/pypy/changeset/f5ffdcff7e59/ Log:(arigo, hager): Started to build proper stack frames, also amde first calls work. diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py --- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py +++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py @@ -1395,6 +1395,23 @@ self.addi(ptr_reg, ptr_reg, basesize) self.stbx(value_reg, ptr_reg, offset_reg) +def emit_call(self, op, cpu): +call_addr = rffi.cast(lltype.Signed, op.getarg(0).value) +args = op.getarglist()[1:] +descr = op.getdescr() + +arg_reg = 3 +for arg in args: +self.mr(arg_reg, cpu.reg_map[arg]) +arg_reg += 1 + +self.load_word(0, call_addr) +self.mtctr(0) +self.bctrl() + +result = op.result +cpu.reg_map[result] = 3 + # unary integer operations # @@ -1540,6 +1557,9 @@ self.store_reg(cpu.next_free_register, addr) else: assert 0, arg type not suported +self.lwz(0, 1, 36) +self.mtlr(0) +self.addi(1, 1, 32) self.load_word(3, identifier) self.blr() diff --git a/pypy/jit/backend/ppc/runner.py b/pypy/jit/backend/ppc/runner.py --- a/pypy/jit/backend/ppc/runner.py +++ b/pypy/jit/backend/ppc/runner.py @@ -56,10 +56,11 @@ self.startpos = codebuilder.get_relative_pos() +self._make_prologue(codebuilder) self._walk_trace_ops(codebuilder, operations) self._make_epilogue(codebuilder) -f = codebuilder.assemble() +f = codebuilder.assemble(True) looptoken.ppc_code = f looptoken.codebuilder = codebuilder self.total_compiled_loops += 1 @@ -104,6 +105,11 @@ self.next_free_register += 1 return reg +def _make_prologue(self, codebuilder): +codebuilder.stwu(1, 1, -32) +codebuilder.mflr(0) +codebuilder.stw(0, 1, 36) + def _make_epilogue(self, codebuilder): for op_index, fail_index, guard, reglist in self.patch_list: curpos = codebuilder.get_relative_pos() @@ -129,6 +135,10 @@ descr.patch_pos = patch_pos descr.used_mem_indices = used_mem_indices +codebuilder.lwz(0, 1, 36) +codebuilder.mtlr(0) +codebuilder.addi(1, 1, 32) + codebuilder.li(3, fail_index) codebuilder.blr() ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: test_call passes, but implementation of CALL is still rudimental.
Author: hager sven.ha...@uni-duesseldorf.de Branch: ppc-jit-backend Changeset: r46942:909be9e8dbcb Date: 2011-08-31 12:30 +0200 http://bitbucket.org/pypy/pypy/changeset/909be9e8dbcb/ Log:test_call passes, but implementation of CALL is still rudimental. diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py --- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py +++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py @@ -1402,7 +1402,12 @@ arg_reg = 3 for arg in args: -self.mr(arg_reg, cpu.reg_map[arg]) +if isinstance(arg, Box): +self.mr(arg_reg, cpu.reg_map[arg]) +elif isinstance(arg, Const): +self.load_word(arg_reg, arg.value) +else: +assert 0, %s not supported yet % arg arg_reg += 1 self.load_word(0, call_addr) diff --git a/pypy/jit/backend/ppc/runner.py b/pypy/jit/backend/ppc/runner.py --- a/pypy/jit/backend/ppc/runner.py +++ b/pypy/jit/backend/ppc/runner.py @@ -60,7 +60,7 @@ self._walk_trace_ops(codebuilder, operations) self._make_epilogue(codebuilder) -f = codebuilder.assemble(True) +f = codebuilder.assemble() looptoken.ppc_code = f looptoken.codebuilder = codebuilder self.total_compiled_loops += 1 ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Support older versions of ctypes which don't have a c_bool.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46944:9b371e455b67 Date: 2011-08-31 15:00 +0200 http://bitbucket.org/pypy/pypy/changeset/9b371e455b67/ Log:Support older versions of ctypes which don't have a c_bool. diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py b/pypy/rpython/lltypesystem/ll2ctypes.py --- a/pypy/rpython/lltypesystem/ll2ctypes.py +++ b/pypy/rpython/lltypesystem/ll2ctypes.py @@ -113,7 +113,7 @@ rffi.LONGLONG: ctypes.c_longlong, rffi.ULONGLONG: ctypes.c_ulonglong, rffi.SIZE_T: ctypes.c_size_t, -lltype.Bool: ctypes.c_bool, +lltype.Bool: getattr(ctypes, c_bool, ctypes.c_long), llmemory.Address: ctypes.c_void_p, llmemory.GCREF:ctypes.c_void_p, llmemory.WeakRef: ctypes.c_void_p, # XXX ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: propagate the flags of ffi functions into the calldescr, so that call_release_gil will be able to inspect it and use the proper calling convention
Author: Antonio Cuni anto.c...@gmail.com Branch: Changeset: r46945:f411890255ef Date: 2011-08-31 15:06 +0200 http://bitbucket.org/pypy/pypy/changeset/f411890255ef/ Log:propagate the flags of ffi functions into the calldescr, so that call_release_gil will be able to inspect it and use the proper calling convention diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py --- a/pypy/jit/backend/llgraph/runner.py +++ b/pypy/jit/backend/llgraph/runner.py @@ -25,13 +25,14 @@ class Descr(history.AbstractDescr): def __init__(self, ofs, typeinfo, extrainfo=None, name=None, - arg_types=None, count_fields_if_immut=-1): + arg_types=None, count_fields_if_immut=-1, ffi_flags=0): self.ofs = ofs self.typeinfo = typeinfo self.extrainfo = extrainfo self.name = name self.arg_types = arg_types self.count_fields_if_immut = count_fields_if_immut +self.ffi_flags = ffi_flags def get_arg_types(self): return self.arg_types @@ -67,6 +68,9 @@ def count_fields_if_immutable(self): return self.count_fields_if_immut +def get_ffi_flags(self): +return self.ffi_flags + def __lt__(self, other): raise TypeError(cannot use comparison on Descrs) def __le__(self, other): @@ -114,14 +118,14 @@ return False def getdescr(self, ofs, typeinfo='?', extrainfo=None, name=None, - arg_types=None, count_fields_if_immut=-1): + arg_types=None, count_fields_if_immut=-1, ffi_flags=0): key = (ofs, typeinfo, extrainfo, name, arg_types, - count_fields_if_immut) + count_fields_if_immut, ffi_flags) try: return self._descrs[key] except KeyError: descr = Descr(ofs, typeinfo, extrainfo, name, arg_types, - count_fields_if_immut) + count_fields_if_immut, ffi_flags) self._descrs[key] = descr return descr @@ -326,7 +330,7 @@ return self.getdescr(0, token[0], extrainfo=extrainfo, arg_types=''.join(arg_types)) -def calldescrof_dynamic(self, ffi_args, ffi_result, extrainfo): +def calldescrof_dynamic(self, ffi_args, ffi_result, extrainfo, ffi_flags): from pypy.jit.backend.llsupport.ffisupport import get_ffi_type_kind from pypy.jit.backend.llsupport.ffisupport import UnsupportedKind arg_types = [] @@ -339,7 +343,8 @@ except UnsupportedKind: return None return self.getdescr(0, reskind, extrainfo=extrainfo, - arg_types=''.join(arg_types)) + arg_types=''.join(arg_types), + ffi_flags=ffi_flags) def grab_exc_value(self): diff --git a/pypy/jit/backend/llsupport/descr.py b/pypy/jit/backend/llsupport/descr.py --- a/pypy/jit/backend/llsupport/descr.py +++ b/pypy/jit/backend/llsupport/descr.py @@ -260,10 +260,12 @@ _clsname = '' loop_token = None arg_classes = '' # -- annotation hack +ffi_flags = 0 -def __init__(self, arg_classes, extrainfo=None): +def __init__(self, arg_classes, extrainfo=None, ffi_flags=0): self.arg_classes = arg_classes# string of r and i (ref/int) self.extrainfo = extrainfo +self.ffi_flags = ffi_flags def __repr__(self): res = '%s(%s)' % (self.__class__.__name__, self.arg_classes) @@ -284,6 +286,9 @@ def get_extra_info(self): return self.extrainfo +def get_ffi_flags(self): +return self.ffi_flags + def get_arg_types(self): return self.arg_classes @@ -391,8 +396,8 @@ _clsname = 'DynamicIntCallDescr' -def __init__(self, arg_classes, result_size, result_sign, extrainfo=None): -BaseIntCallDescr.__init__(self, arg_classes, extrainfo) +def __init__(self, arg_classes, result_size, result_sign, extrainfo=None, ffi_flags=0): +BaseIntCallDescr.__init__(self, arg_classes, extrainfo, ffi_flags) assert isinstance(result_sign, bool) self._result_size = chr(result_size) self._result_sign = result_sign diff --git a/pypy/jit/backend/llsupport/ffisupport.py b/pypy/jit/backend/llsupport/ffisupport.py --- a/pypy/jit/backend/llsupport/ffisupport.py +++ b/pypy/jit/backend/llsupport/ffisupport.py @@ -8,7 +8,7 @@ class UnsupportedKind(Exception): pass -def get_call_descr_dynamic(cpu, ffi_args, ffi_result, extrainfo=None): +def get_call_descr_dynamic(cpu, ffi_args, ffi_result, extrainfo=None, ffi_flags=0): Get a call descr: the types of result and args are represented by rlib.libffi.types.* try: @@ -20,18 +20,24 @@ if reskind == history.INT: size = intmask(ffi_result.c_size) signed = is_ffi_type_signed(ffi_result) -return
[pypy-commit] pypy default: Fix a test.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46949:efaa417ebadc Date: 2011-08-31 17:19 +0200 http://bitbucket.org/pypy/pypy/changeset/efaa417ebadc/ Log:Fix a test. diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py --- a/pypy/jit/metainterp/warmstate.py +++ b/pypy/jit/metainterp/warmstate.py @@ -124,7 +124,7 @@ # Hash of lltype or ootype object. # Only supports strings, unicodes and regular instances, # as well as primitives that can meaningfully be cast to Signed. -if isinstance(TYPE, lltype.Ptr): +if isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc': if TYPE.TO is rstr.STR or TYPE.TO is rstr.UNICODE: return rstr.LLHelpers.ll_strhash(x)# assumed not null else: @@ -140,7 +140,7 @@ else: return 0 else: -return lltype.cast_primitive(lltype.Signed, x) +return rffi.cast(lltype.Signed, x) @specialize.ll_and_arg(3) def set_future_value(cpu, j, value, typecode): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge heads
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46952:ececb40f961c Date: 2011-08-31 18:49 +0200 http://bitbucket.org/pypy/pypy/changeset/ececb40f961c/ Log:merge heads diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py --- a/pypy/jit/backend/llgraph/runner.py +++ b/pypy/jit/backend/llgraph/runner.py @@ -25,13 +25,14 @@ class Descr(history.AbstractDescr): def __init__(self, ofs, typeinfo, extrainfo=None, name=None, - arg_types=None, count_fields_if_immut=-1): + arg_types=None, count_fields_if_immut=-1, ffi_flags=0): self.ofs = ofs self.typeinfo = typeinfo self.extrainfo = extrainfo self.name = name self.arg_types = arg_types self.count_fields_if_immut = count_fields_if_immut +self.ffi_flags = ffi_flags def get_arg_types(self): return self.arg_types @@ -67,6 +68,9 @@ def count_fields_if_immutable(self): return self.count_fields_if_immut +def get_ffi_flags(self): +return self.ffi_flags + def __lt__(self, other): raise TypeError(cannot use comparison on Descrs) def __le__(self, other): @@ -114,14 +118,14 @@ return False def getdescr(self, ofs, typeinfo='?', extrainfo=None, name=None, - arg_types=None, count_fields_if_immut=-1): + arg_types=None, count_fields_if_immut=-1, ffi_flags=0): key = (ofs, typeinfo, extrainfo, name, arg_types, - count_fields_if_immut) + count_fields_if_immut, ffi_flags) try: return self._descrs[key] except KeyError: descr = Descr(ofs, typeinfo, extrainfo, name, arg_types, - count_fields_if_immut) + count_fields_if_immut, ffi_flags) self._descrs[key] = descr return descr @@ -326,7 +330,7 @@ return self.getdescr(0, token[0], extrainfo=extrainfo, arg_types=''.join(arg_types)) -def calldescrof_dynamic(self, ffi_args, ffi_result, extrainfo): +def calldescrof_dynamic(self, ffi_args, ffi_result, extrainfo, ffi_flags): from pypy.jit.backend.llsupport.ffisupport import get_ffi_type_kind from pypy.jit.backend.llsupport.ffisupport import UnsupportedKind arg_types = [] @@ -339,7 +343,8 @@ except UnsupportedKind: return None return self.getdescr(0, reskind, extrainfo=extrainfo, - arg_types=''.join(arg_types)) + arg_types=''.join(arg_types), + ffi_flags=ffi_flags) def grab_exc_value(self): diff --git a/pypy/jit/backend/llsupport/descr.py b/pypy/jit/backend/llsupport/descr.py --- a/pypy/jit/backend/llsupport/descr.py +++ b/pypy/jit/backend/llsupport/descr.py @@ -260,10 +260,12 @@ _clsname = '' loop_token = None arg_classes = '' # -- annotation hack +ffi_flags = 0 -def __init__(self, arg_classes, extrainfo=None): +def __init__(self, arg_classes, extrainfo=None, ffi_flags=0): self.arg_classes = arg_classes# string of r and i (ref/int) self.extrainfo = extrainfo +self.ffi_flags = ffi_flags def __repr__(self): res = '%s(%s)' % (self.__class__.__name__, self.arg_classes) @@ -284,6 +286,9 @@ def get_extra_info(self): return self.extrainfo +def get_ffi_flags(self): +return self.ffi_flags + def get_arg_types(self): return self.arg_classes @@ -391,8 +396,8 @@ _clsname = 'DynamicIntCallDescr' -def __init__(self, arg_classes, result_size, result_sign, extrainfo=None): -BaseIntCallDescr.__init__(self, arg_classes, extrainfo) +def __init__(self, arg_classes, result_size, result_sign, extrainfo=None, ffi_flags=0): +BaseIntCallDescr.__init__(self, arg_classes, extrainfo, ffi_flags) assert isinstance(result_sign, bool) self._result_size = chr(result_size) self._result_sign = result_sign diff --git a/pypy/jit/backend/llsupport/ffisupport.py b/pypy/jit/backend/llsupport/ffisupport.py --- a/pypy/jit/backend/llsupport/ffisupport.py +++ b/pypy/jit/backend/llsupport/ffisupport.py @@ -8,7 +8,7 @@ class UnsupportedKind(Exception): pass -def get_call_descr_dynamic(cpu, ffi_args, ffi_result, extrainfo=None): +def get_call_descr_dynamic(cpu, ffi_args, ffi_result, extrainfo=None, ffi_flags=0): Get a call descr: the types of result and args are represented by rlib.libffi.types.* try: @@ -20,18 +20,24 @@ if reskind == history.INT: size = intmask(ffi_result.c_size) signed = is_ffi_type_signed(ffi_result) -return DynamicIntCallDescr(arg_classes, size, signed, extrainfo) +return DynamicIntCallDescr(arg_classes, size, signed, extrainfo, +
[pypy-commit] pypy default: More failing tests.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46948:dc2cb75cbecb Date: 2011-08-31 17:18 +0200 http://bitbucket.org/pypy/pypy/changeset/dc2cb75cbecb/ Log:More failing tests. diff --git a/pypy/jit/metainterp/test/test_warmspot.py b/pypy/jit/metainterp/test/test_warmspot.py --- a/pypy/jit/metainterp/test/test_warmspot.py +++ b/pypy/jit/metainterp/test/test_warmspot.py @@ -263,6 +263,29 @@ pass # other case self.meta_interp(f1, [18]) +def test_bug_constant_rawptrs(self): +from pypy.rpython.lltypesystem import lltype, rffi +mydriver = JitDriver(greens=['a'], reds=['m']) +def f1(m): +a = lltype.nullptr(rffi.VOIDP.TO) +while m 0: +mydriver.jit_merge_point(a=a, m=m) +m = m - 1 +self.meta_interp(f1, [18]) + +def test_bug_rawptrs(self): +from pypy.rpython.lltypesystem import lltype, rffi +mydriver = JitDriver(greens=['a'], reds=['m']) +def f1(m): +a = lltype.malloc(rffi.VOIDP.TO, 5, flavor='raw') +while m 0: +mydriver.jit_merge_point(a=a, m=m) +m = m - 1 +if m == 10: +pass +lltype.free(a, flavor='raw') +self.meta_interp(f1, [18]) + class TestLLWarmspot(WarmspotTests, LLJitMixin): CPUClass = runner.LLtypeCPU 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 @@ -1283,6 +1283,8 @@ try: return p._obj._hash_cache_ except AttributeError: +assert self._T._gckind == 'gc' +assert self # not for NULL result = hash(p._obj) if cache: try: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: The other two tests are more difficult. Skip them now, after improving
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46950:1c3a9faf1d0a Date: 2011-08-31 17:36 +0200 http://bitbucket.org/pypy/pypy/changeset/1c3a9faf1d0a/ Log:The other two tests are more difficult. Skip them now, after improving the error message that they give. diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py --- a/pypy/jit/codewriter/support.py +++ b/pypy/jit/codewriter/support.py @@ -91,9 +91,12 @@ reds_v = op.args[2+numgreens:] assert len(reds_v) == numreds # -def _sort(args_v): +def _sort(args_v, is_green): from pypy.jit.metainterp.history import getkind lst = [v for v in args_v if v.concretetype is not lltype.Void] +if is_green: +assert len(lst) == len(args_v), ( +not supported so far: 'greens' variables contain Void) _kind2count = {'int': 1, 'ref': 2, 'float': 3} lst2 = sorted(lst, key=lambda v: _kind2count[getkind(v.concretetype)]) # a crash here means that you have to reorder the variable named in @@ -102,7 +105,7 @@ assert lst == lst2 return lst # -return (_sort(greens_v), _sort(reds_v)) +return (_sort(greens_v, True), _sort(reds_v, False)) def maybe_on_top_of_llinterp(rtyper, fnptr): # Run a generated graph on top of the llinterp for testing. diff --git a/pypy/jit/metainterp/test/test_warmspot.py b/pypy/jit/metainterp/test/test_warmspot.py --- a/pypy/jit/metainterp/test/test_warmspot.py +++ b/pypy/jit/metainterp/test/test_warmspot.py @@ -252,8 +252,8 @@ self.check_loops({'int_sub': 1, 'int_gt': 1, 'guard_true': 1, 'jump': 1}) -def test_bug_continuerunningnormally(self): -mydriver = JitDriver(greens=['a'], reds=['m']) +def test_void_red_variable(self): +mydriver = JitDriver(greens=[], reds=['a', 'm']) def f1(m): a = None while m 0: @@ -264,6 +264,7 @@ self.meta_interp(f1, [18]) def test_bug_constant_rawptrs(self): +py.test.skip(crashes because a is a constant) from pypy.rpython.lltypesystem import lltype, rffi mydriver = JitDriver(greens=['a'], reds=['m']) def f1(m): diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py --- a/pypy/jit/metainterp/warmspot.py +++ b/pypy/jit/metainterp/warmspot.py @@ -245,7 +245,8 @@ graph.startblock = support.split_before_jit_merge_point(*jmpp) graph.startblock.isstartblock = True # a crash in the following checkgraph() means that you forgot -# to list some variable in greens=[] or reds=[] in JitDriver. +# to list some variable in greens=[] or reds=[] in JitDriver, +# or that a jit_merge_point() takes a constant as an argument. checkgraph(graph) for v in graph.getargs(): assert isinstance(v, Variable) @@ -655,11 +656,13 @@ portalfunc_ARGS = [] nums = {} for i, ARG in enumerate(PORTALFUNC.ARGS): +kind = history.getkind(ARG) +assert kind != 'void' if i len(jd.jitdriver.greens): color = 'green' else: color = 'red' -attrname = '%s_%s' % (color, history.getkind(ARG)) +attrname = '%s_%s' % (color, kind) count = nums.get(attrname, 0) nums[attrname] = count + 1 portalfunc_ARGS.append((ARG, attrname, count)) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Test and fix.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46951:98ae5e7b6751 Date: 2011-08-31 18:47 +0200 http://bitbucket.org/pypy/pypy/changeset/98ae5e7b6751/ Log:Test and fix. diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py b/pypy/rpython/lltypesystem/ll2ctypes.py --- a/pypy/rpython/lltypesystem/ll2ctypes.py +++ b/pypy/rpython/lltypesystem/ll2ctypes.py @@ -1153,7 +1153,11 @@ # an OverflowError on the following line. cvalue = ctypes.cast(ctypes.c_void_p(cvalue), cresulttype) else: -cvalue = cresulttype(cvalue).value # mask high bits off if needed +try: +cvalue = cresulttype(cvalue).value # mask high bits off if needed +except TypeError: +cvalue = int(cvalue) # float - int +cvalue = cresulttype(cvalue).value # try again return ctypes2lltype(RESTYPE, cvalue) class ForceCastEntry(ExtRegistryEntry): diff --git a/pypy/rpython/lltypesystem/test/test_rffi.py b/pypy/rpython/lltypesystem/test/test_rffi.py --- a/pypy/rpython/lltypesystem/test/test_rffi.py +++ b/pypy/rpython/lltypesystem/test/test_rffi.py @@ -699,7 +699,10 @@ def test_cast(self): res = cast(SIZE_T, -1) assert type(res) is r_size_t -assert res == r_size_t(-1) +assert res == r_size_t(-1) +# +res = cast(lltype.Signed, 42.5) +assert res == 42 def test_rffi_sizeof(self): try: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Fix: tolower(), qsort(), and our own llhelper are all cdecl functions.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46953:87d17a472a16 Date: 2011-08-31 19:27 +0200 http://bitbucket.org/pypy/pypy/changeset/87d17a472a16/ Log:Fix: tolower(), qsort(), and our own llhelper are all cdecl functions. Important on Windows. diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py --- a/pypy/jit/backend/test/runner_test.py +++ b/pypy/jit/backend/test/runner_test.py @@ -468,7 +468,7 @@ assert longlong.getrealfloat(x) == 3.5 - 42 def test_call(self): -from pypy.rlib.libffi import types +from pypy.rlib.libffi import types, FUNCFLAG_CDECL def func_int(a, b): return a + b @@ -498,7 +498,7 @@ # then, try it with the dynamic calldescr dyn_calldescr = cpu.calldescrof_dynamic([ffi_type, ffi_type], ffi_type, EffectInfo.MOST_GENERAL, -ffi_flags=0) +ffi_flags=FUNCFLAG_CDECL) res = self.execute_operation(rop.CALL, [funcbox, BoxInt(num), BoxInt(num)], 'int', descr=dyn_calldescr) @@ -1945,7 +1945,7 @@ assert values == [1, 10] def test_call_to_c_function(self): -from pypy.rlib.libffi import CDLL, types, ArgChain +from pypy.rlib.libffi import CDLL, types, ArgChain, FUNCFLAG_CDECL from pypy.rpython.lltypesystem.ll2ctypes import libc_name libc = CDLL(libc_name) c_tolower = libc.getpointer('tolower', [types.uchar], types.sint) @@ -1957,7 +1957,7 @@ funcbox = ConstInt(heaptracker.adr2int(func_adr)) calldescr = cpu.calldescrof_dynamic([types.uchar], types.sint, EffectInfo.MOST_GENERAL, -ffi_flags=0) +ffi_flags=FUNCFLAG_CDECL) i1 = BoxInt() i2 = BoxInt() tok = BoxInt() @@ -2015,7 +2015,7 @@ types_size_t, types.pointer], types.void, EffectInfo.MOST_GENERAL, -ffi_flags=0) +ffi_flags=clibffi.FUNCFLAG_CDECL) i0 = BoxInt() i1 = BoxInt() i2 = BoxInt() ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Blindly check in this win32 test.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46955:0d75ab342438 Date: 2011-08-31 20:01 +0200 http://bitbucket.org/pypy/pypy/changeset/0d75ab342438/ Log:Blindly check in this win32 test. diff --git a/pypy/jit/backend/llsupport/descr.py b/pypy/jit/backend/llsupport/descr.py --- a/pypy/jit/backend/llsupport/descr.py +++ b/pypy/jit/backend/llsupport/descr.py @@ -289,6 +289,10 @@ def get_ffi_flags(self): return self.ffi_flags +def get_call_conv(self): +from pypy.rlib.clibffi import get_call_conv +return get_call_conv(self.ffi_flags) + def get_arg_types(self): return self.arg_classes diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py --- a/pypy/jit/backend/test/runner_test.py +++ b/pypy/jit/backend/test/runner_test.py @@ -2041,6 +2041,57 @@ assert len(glob.lst) 0 lltype.free(raw, flavor='raw') +def test_call_to_winapi_function(self): +from pypy.rlib.clibffi import _WIN32, FUNCFLAG_STDCALL +if not _WIN32: +py.test.skip(Windows test only) +from pypy.rlib.libffi import CDLL, types, ArgChain +from pypy.rlib.rwin32 import DWORD +libc = CDLL('KERNEL32') +c_GetCurrentDir = libc.getpointer('GetCurrentDirectoryA', + [types.ulong, types.pointer], + types.ulong) + +cwd = os.getcwd() +buflen = len(cwd) + 10 +buffer = lltype.malloc(rffi.CCHARP.TO, buflen, flavor='raw') +argchain = ArgChain().arg(rffi.cast(DWORD, buflen)).arg(buffer) +res = c_GetCurrentDir.call(argchain, DWORD) +assert rffi.cast(lltype.Signed, res) == len(cwd) +assert rffi.charp2strn(buffer, buflen) == cwd +lltype.free(buffer, flavor='raw') + +cpu = self.cpu +func_adr = llmemory.cast_ptr_to_adr(c_GetCurrentDir.funcsym) +funcbox = ConstInt(heaptracker.adr2int(func_adr)) +calldescr = cpu.calldescrof_dynamic([types.ulong, types.pointer], +types.ulong, +EffectInfo.MOST_GENERAL, +ffi_flags=FUNCFLAG_STDCALL) +i1 = BoxInt() +i2 = BoxInt() +i3 = BoxInt() +tok = BoxInt() +faildescr = BasicFailDescr(1) +ops = [ +ResOperation(rop.CALL_RELEASE_GIL, [funcbox, i1, i2], i3, + descr=calldescr), +ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr), +ResOperation(rop.FINISH, [i3], None, descr=BasicFailDescr(0)) +] +ops[1].setfailargs([]) +looptoken = LoopToken() +self.cpu.compile_loop([i1, i2], ops, looptoken) + +buffer = lltype.malloc(rffi.CCHARP.TO, buflen, flavor='raw') +self.cpu.set_future_value_int(0, buflen) +self.cpu.set_future_value_int(1, rffi.cast(lltype.Signed, buffer)) +fail = self.cpu.execute_token(looptoken) +assert fail.identifier == 0 +assert self.cpu.get_latest_value_int(0) == len(cwd) +assert rffi.charp2strn(buffer, buflen) == cwd +lltype.free(buffer, flavor='raw') + def test_guard_not_invalidated(self): cpu = self.cpu i0 = BoxInt() diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py --- a/pypy/rlib/clibffi.py +++ b/pypy/rlib/clibffi.py @@ -408,6 +408,13 @@ FUNCFLAG_USE_ERRNO = 8 FUNCFLAG_USE_LASTERROR = 16 +def get_call_conv(flags): +if _WIN32 and (flags FUNCFLAG_CDECL == 0): +return FFI_STDCALL +else: +return FFI_DEFAULT_ABI + + class AbstractFuncPtr(object): ll_cif = lltype.nullptr(FFI_CIFP.TO) ll_argtypes = lltype.nullptr(FFI_TYPE_PP.TO) @@ -427,11 +434,6 @@ self.ll_cif = lltype.malloc(FFI_CIFP.TO, flavor='raw', track_allocation=False) # freed by the __del__ -if _WIN32 and (flags FUNCFLAG_CDECL == 0): -cc = FFI_STDCALL -else: -cc = FFI_DEFAULT_ABI - if _MSVC: # This little trick works correctly with MSVC. # It returns small structures in registers @@ -441,7 +443,7 @@ elif restype.c_size = 8: restype = ffi_type_sint64 -res = c_ffi_prep_cif(self.ll_cif, cc, +res = c_ffi_prep_cif(self.ll_cif, get_call_conv(flags), rffi.cast(rffi.UINT, argnum), restype, self.ll_argtypes) if not res == FFI_OK: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: change bz2 test so that it reads chunks which don't divide evenly into test data's length
Author: Justin Peel notmuchtot...@gmail.com Branch: Changeset: r46956:13c94c0591c3 Date: 2011-08-31 13:32 -0600 http://bitbucket.org/pypy/pypy/changeset/13c94c0591c3/ Log:change bz2 test so that it reads chunks which don't divide evenly into test data's length diff --git a/pypy/module/bz2/test/test_bz2_file.py b/pypy/module/bz2/test/test_bz2_file.py --- a/pypy/module/bz2/test/test_bz2_file.py +++ b/pypy/module/bz2/test/test_bz2_file.py @@ -274,14 +274,14 @@ pass del bz2f # delete from this frame, which is captured in the traceback -def test_read_chunk10(self): +def test_read_chunk9(self): from bz2 import BZ2File self.create_temp_file() bz2f = BZ2File(self.temppath) text_read = while True: -data = bz2f.read(10) +data = bz2f.read(9) # 9 doesn't divide evenly into data length if not data: break text_read = %s%s % (text_read, data) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge heads
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46958:d5c039d3989a Date: 2011-08-31 21:36 +0200 http://bitbucket.org/pypy/pypy/changeset/d5c039d3989a/ Log:merge heads diff --git a/pypy/module/bz2/test/test_bz2_file.py b/pypy/module/bz2/test/test_bz2_file.py --- a/pypy/module/bz2/test/test_bz2_file.py +++ b/pypy/module/bz2/test/test_bz2_file.py @@ -274,14 +274,14 @@ pass del bz2f # delete from this frame, which is captured in the traceback -def test_read_chunk10(self): +def test_read_chunk9(self): from bz2 import BZ2File self.create_temp_file() bz2f = BZ2File(self.temppath) text_read = while True: -data = bz2f.read(10) +data = bz2f.read(9) # 9 doesn't divide evenly into data length if not data: break text_read = %s%s % (text_read, data) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: A test for the STDCALL calling convention, which runs also
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46959:9dab2e7df18f Date: 2011-08-31 20:50 +0200 http://bitbucket.org/pypy/pypy/changeset/9dab2e7df18f/ Log:A test for the STDCALL calling convention, which runs also on non- windows (but 32-bits only). diff --git a/pypy/jit/backend/x86/rx86.py b/pypy/jit/backend/x86/rx86.py --- a/pypy/jit/backend/x86/rx86.py +++ b/pypy/jit/backend/x86/rx86.py @@ -527,6 +527,7 @@ NOP = insn('\x90') RET = insn('\xC3') +RET16_i = insn('\xC2', immediate(1, 'h')) PUSH_r = insn(rex_nw, register(1), '\x50') PUSH_b = insn(rex_nw, '\xFF', orbyte(63), stack_bp(1)) diff --git a/pypy/jit/backend/x86/test/test_runner.py b/pypy/jit/backend/x86/test/test_runner.py --- a/pypy/jit/backend/x86/test/test_runner.py +++ b/pypy/jit/backend/x86/test/test_runner.py @@ -433,6 +433,90 @@ ops_offset[operations[2]] = ops_offset[None]) +def test_calling_convention(self): +if WORD != 4: +py.test.skip(32-bit only test) +from pypy.jit.backend.x86.regloc import eax, edx +from pypy.jit.backend.x86 import codebuf +from pypy.jit.codewriter.effectinfo import EffectInfo +from pypy.rlib.libffi import types +from pypy.rlib.clibffi import FFI_DEFAULT_ABI +try: +from pypy.rlib.clibffi import FFI_STDCALL +except ImportError: +FFI_STDCALL = 12345 # not on Windows, but we can still test + +for ffi in [FFI_DEFAULT_ABI, FFI_STDCALL]: +cpu = self.cpu +mc = codebuf.MachineCodeBlockWrapper() +mc.MOV_rs(eax.value, 4) # argument 1 +mc.MOV_rs(edx.value, 40) # argument 10 +mc.SUB_rr(eax.value, edx.value) # return arg1 - arg10 +if ffi == FFI_DEFAULT_ABI: +mc.RET() +else: +mc.RET16_i(40) +rawstart = mc.materialize(cpu.asmmemmgr, []) +# +calldescr = cpu.calldescrof_dynamic([types.slong] * 10, +types.slong, +EffectInfo.MOST_GENERAL, +ffi_flags=-1) +calldescr.get_call_conv = lambda: ffi # hack +funcbox = ConstInt(rawstart) +i1 = BoxInt() +i2 = BoxInt() +i3 = BoxInt() +i4 = BoxInt() +i5 = BoxInt() +i6 = BoxInt() +c = ConstInt(-1) +faildescr = BasicFailDescr(1) +# we must call it repeatedly: if the stack pointer gets increased +# by 40 bytes by the STDCALL call, and if we don't expect it, +# then we are going to get our stack emptied unexpectedly by +# several repeated calls +ops = [ +ResOperation(rop.CALL_RELEASE_GIL, + [funcbox, i1, c, c, c, c, c, c, c, c, i2], + i3, descr=calldescr), +ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr), + +ResOperation(rop.CALL_RELEASE_GIL, + [funcbox, i1, c, c, c, c, c, c, c, c, i2], + i4, descr=calldescr), +ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr), + +ResOperation(rop.CALL_RELEASE_GIL, + [funcbox, i1, c, c, c, c, c, c, c, c, i2], + i5, descr=calldescr), +ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr), + +ResOperation(rop.CALL_RELEASE_GIL, + [funcbox, i1, c, c, c, c, c, c, c, c, i2], + i6, descr=calldescr), +ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr), + +ResOperation(rop.FINISH, [i3, i4, i5, i6], None, + descr=BasicFailDescr(0)) +] +ops[1].setfailargs([]) +ops[3].setfailargs([]) +ops[5].setfailargs([]) +ops[7].setfailargs([]) +looptoken = LoopToken() +self.cpu.compile_loop([i1, i2], ops, looptoken) + +self.cpu.set_future_value_int(0, 123450) +self.cpu.set_future_value_int(1, 123408) +fail = self.cpu.execute_token(looptoken) +assert fail.identifier == 0 +assert self.cpu.get_latest_value_int(0) == 42 +assert self.cpu.get_latest_value_int(1) == 42 +assert self.cpu.get_latest_value_int(2) == 42 +assert self.cpu.get_latest_value_int(3) == 42 + + class TestDebuggingAssembler(object): def setup_method(self, meth): self.cpu = CPU(rtyper=None, stats=FakeStats()) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Translation fix. Of the kind bah what a hack.
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46961:ad4f57500e04 Date: 2011-08-31 21:22 +0200 http://bitbucket.org/pypy/pypy/changeset/ad4f57500e04/ Log:Translation fix. Of the kind bah what a hack. diff --git a/pypy/jit/backend/llsupport/descr.py b/pypy/jit/backend/llsupport/descr.py --- a/pypy/jit/backend/llsupport/descr.py +++ b/pypy/jit/backend/llsupport/descr.py @@ -291,7 +291,7 @@ def get_call_conv(self): from pypy.rlib.clibffi import get_call_conv -return get_call_conv(self.ffi_flags) +return get_call_conv(self.ffi_flags, True) def get_arg_types(self): return self.arg_classes diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py --- a/pypy/rlib/clibffi.py +++ b/pypy/rlib/clibffi.py @@ -408,11 +408,12 @@ FUNCFLAG_USE_ERRNO = 8 FUNCFLAG_USE_LASTERROR = 16 -def get_call_conv(flags): +def get_call_conv(flags, from_jit): if _WIN32 and (flags FUNCFLAG_CDECL == 0): return FFI_STDCALL else: return FFI_DEFAULT_ABI +get_call_conv._annspecialcase_ = 'specialize:arg(1)' # hack :-/ class AbstractFuncPtr(object): @@ -443,7 +444,7 @@ elif restype.c_size = 8: restype = ffi_type_sint64 -res = c_ffi_prep_cif(self.ll_cif, get_call_conv(flags), +res = c_ffi_prep_cif(self.ll_cif, get_call_conv(flags, False), rffi.cast(rffi.UINT, argnum), restype, self.ll_argtypes) if not res == FFI_OK: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: merge heads
Author: Armin Rigo ar...@tunes.org Branch: Changeset: r46962:ed5fdaa7fbb7 Date: 2011-08-31 21:38 +0200 http://bitbucket.org/pypy/pypy/changeset/ed5fdaa7fbb7/ Log:merge heads diff --git a/pypy/jit/backend/llsupport/descr.py b/pypy/jit/backend/llsupport/descr.py --- a/pypy/jit/backend/llsupport/descr.py +++ b/pypy/jit/backend/llsupport/descr.py @@ -291,7 +291,7 @@ def get_call_conv(self): from pypy.rlib.clibffi import get_call_conv -return get_call_conv(self.ffi_flags) +return get_call_conv(self.ffi_flags, True) def get_arg_types(self): return self.arg_classes diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py --- a/pypy/jit/backend/x86/assembler.py +++ b/pypy/jit/backend/x86/assembler.py @@ -34,6 +34,7 @@ from pypy.rlib.debug import (debug_print, debug_start, debug_stop, have_debug_prints) from pypy.rlib import rgc +from pypy.rlib.clibffi import FFI_DEFAULT_ABI from pypy.jit.backend.x86.jump import remap_frame_layout from pypy.jit.metainterp.history import ConstInt, BoxInt from pypy.jit.codewriter.effectinfo import EffectInfo @@ -1120,7 +1121,7 @@ return genop_cmp_guard_float def _emit_call(self, force_index, x, arglocs, start=0, tmp=eax, - argtypes=None): + argtypes=None, callconv=FFI_DEFAULT_ABI): if IS_X86_64: return self._emit_call_64(force_index, x, arglocs, start, argtypes) @@ -1149,6 +1150,16 @@ # x is a location self.mc.CALL(x) self.mark_gc_roots(force_index) +# +if callconv != FFI_DEFAULT_ABI: +self._fix_stdcall(callconv, p) + +def _fix_stdcall(self, callconv, p): +from pypy.rlib.clibffi import FFI_STDCALL +assert callconv == FFI_STDCALL +# it's a bit stupid, but we're just going to cancel the fact that +# the called function just added 'p' to ESP, by subtracting it again. +self.mc.SUB_ri(esp.value, p) def _emit_call_64(self, force_index, x, arglocs, start, argtypes): src_locs = [] @@ -2127,7 +2138,8 @@ tmp = eax self._emit_call(force_index, x, arglocs, 3, tmp=tmp, -argtypes=op.getdescr().get_arg_types()) +argtypes=op.getdescr().get_arg_types(), +callconv=op.getdescr().get_call_conv()) if IS_X86_32 and isinstance(resloc, StackLoc) and resloc.width == 8: # a float or a long long return diff --git a/pypy/jit/backend/x86/rx86.py b/pypy/jit/backend/x86/rx86.py --- a/pypy/jit/backend/x86/rx86.py +++ b/pypy/jit/backend/x86/rx86.py @@ -527,6 +527,7 @@ NOP = insn('\x90') RET = insn('\xC3') +RET16_i = insn('\xC2', immediate(1, 'h')) PUSH_r = insn(rex_nw, register(1), '\x50') PUSH_b = insn(rex_nw, '\xFF', orbyte(63), stack_bp(1)) diff --git a/pypy/jit/backend/x86/test/test_runner.py b/pypy/jit/backend/x86/test/test_runner.py --- a/pypy/jit/backend/x86/test/test_runner.py +++ b/pypy/jit/backend/x86/test/test_runner.py @@ -433,6 +433,91 @@ ops_offset[operations[2]] = ops_offset[None]) +def test_calling_convention(self): +if WORD != 4: +py.test.skip(32-bit only test) +from pypy.jit.backend.x86.regloc import eax, edx +from pypy.jit.backend.x86 import codebuf +from pypy.jit.codewriter.effectinfo import EffectInfo +from pypy.rlib.libffi import types, clibffi +had_stdcall = hasattr(clibffi, 'FFI_STDCALL') +if not had_stdcall:# not running on Windows, but we can still test +clibffi.FFI_STDCALL = 12345 +# +for ffi in [clibffi.FFI_DEFAULT_ABI, clibffi.FFI_STDCALL]: +cpu = self.cpu +mc = codebuf.MachineCodeBlockWrapper() +mc.MOV_rs(eax.value, 4) # argument 1 +mc.MOV_rs(edx.value, 40) # argument 10 +mc.SUB_rr(eax.value, edx.value) # return arg1 - arg10 +if ffi == clibffi.FFI_DEFAULT_ABI: +mc.RET() +else: +mc.RET16_i(40) +rawstart = mc.materialize(cpu.asmmemmgr, []) +# +calldescr = cpu.calldescrof_dynamic([types.slong] * 10, +types.slong, +EffectInfo.MOST_GENERAL, +ffi_flags=-1) +calldescr.get_call_conv = lambda: ffi # hack +funcbox = ConstInt(rawstart) +i1 = BoxInt() +i2 = BoxInt() +i3 = BoxInt() +i4 = BoxInt() +i5 = BoxInt() +i6 = BoxInt() +c = ConstInt(-1) +faildescr = BasicFailDescr(1) +# we must call it repeatedly: if the stack pointer gets increased +# by 40 bytes by
[pypy-commit] pypy default: micronumpy: added indexing by tuples to get/setitem
Author: Justin Peel notmuchtot...@gmail.com Branch: Changeset: r46964:93adb3d59791 Date: 2011-08-31 18:01 -0600 http://bitbucket.org/pypy/pypy/changeset/93adb3d59791/ Log:micronumpy: added indexing by tuples to get/setitem 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 @@ -3,6 +3,7 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty from pypy.module.micronumpy import interp_ufuncs, interp_dtype, signature +from pypy.objspace.std.sliceobject import W_SliceObject from pypy.rlib import jit from pypy.rpython.lltypesystem import lltype from pypy.tool.sourcetools import func_with_new_name @@ -217,7 +218,15 @@ return space.wrap([ + .join(concrete._getnums(True)) + ]) def descr_getitem(self, space, w_idx): -# TODO: indexing by tuples +# TODO: indexing by arrays and lists +if space.isinstance_w(w_idx, space.w_tuple): +length = space.len_w(w_idx) +if length == 0: +return space.wrap(self) +if length 1: # only one dimension for now. +raise OperationError(space.w_IndexError, + space.wrap(invalid index)) +w_idx = space.getitem(w_idx, space.wrap(0)) start, stop, step, slice_length = space.decode_index4(w_idx, self.find_size()) if step == 0: # Single index @@ -231,8 +240,19 @@ return space.wrap(res) def descr_setitem(self, space, w_idx, w_value): -# TODO: indexing by tuples and lists +# TODO: indexing by arrays and lists self.invalidated() +if space.isinstance_w(w_idx, space.w_tuple): +length = space.len_w(w_idx) +if length 1: # only one dimension for now. +raise OperationError(space.w_IndexError, + space.wrap(invalid index)) +if length == 0: +w_idx = W_SliceObject(space.wrap(0), + space.wrap(self.find_size()), + space.wrap(1)) +else: +w_idx = space.getitem(w_idx, space.wrap(0)) start, stop, step, slice_length = space.decode_index4(w_idx, self.find_size()) if step == 0: diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -102,6 +102,16 @@ assert a[-1] == 8 raises(IndexError, a[-6]) +def test_getitem_tuple(self): +from numpy import array +a = array(range(5)) +raises(IndexError, a[(1,2)]) +for i in xrange(5): +assert a[(i,)] == i +b = a[()] +for i in xrange(5): +assert a[i] == b[i] + def test_setitem(self): from numpy import array a = array(range(5)) @@ -110,6 +120,17 @@ raises(IndexError, a[5] = 0.0) raises(IndexError, a[-6] = 3.0) +def test_setitem_tuple(self): +from numpy import array +a = array(range(5)) +raises(IndexError, a[(1,2)] = [0,1]) +for i in xrange(5): +a[(i,)] = i+1 +assert a[i] == i+1 +a[()] = range(5) +for i in xrange(5): +assert a[i] == i + def test_setslice_array(self): from numpy import array a = array(range(5)) @@ -541,4 +562,4 @@ a = fromstring(self.data) for i in range(4): assert a[i] == i + 1 -raises(ValueError, fromstring, abc) \ No newline at end of file +raises(ValueError, fromstring, abc) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix my slice creation in micronumpy
Author: Justin Peel notmuchtot...@gmail.com Branch: Changeset: r46965:e31726cdf996 Date: 2011-08-31 19:51 -0600 http://bitbucket.org/pypy/pypy/changeset/e31726cdf996/ Log:fix my slice creation in micronumpy 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 @@ -3,7 +3,6 @@ from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty from pypy.module.micronumpy import interp_ufuncs, interp_dtype, signature -from pypy.objspace.std.sliceobject import W_SliceObject from pypy.rlib import jit from pypy.rpython.lltypesystem import lltype from pypy.tool.sourcetools import func_with_new_name @@ -248,7 +247,7 @@ raise OperationError(space.w_IndexError, space.wrap(invalid index)) if length == 0: -w_idx = W_SliceObject(space.wrap(0), +w_idx = space.newslice(space.wrap(0), space.wrap(self.find_size()), space.wrap(1)) else: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Add Int16 dtype with tests
Author: Justin Peel notmuchtot...@gmail.com Branch: Changeset: r46966:4218de3c70f9 Date: 2011-08-31 21:20 -0600 http://bitbucket.org/pypy/pypy/changeset/4218de3c70f9/ Log:Add Int16 dtype with tests diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -286,6 +286,19 @@ class W_Int8Dtype(IntegerArithmeticDtype, W_Int8Dtype): def unwrap(self, space, w_item): return self.adapt_val(space.int_w(space.int(w_item))) +assert W_Int8Dtype.num_bytes == 1 + +W_Int16Dtype = create_low_level_dtype( +num = 3, kind = SIGNEDLTR, name = int16, +aliases = [int16], +applevel_types = [], +T = rffi.SHORT, +valtype = rffi.SHORT._type, +) +class W_Int16Dtype(IntegerArithmeticDtype, W_Int16Dtype): +def unwrap(self, space, w_item): +return self.adapt_val(space.int_w(space.int(w_item))) +assert W_Int16Dtype.num_bytes == 2 W_Int32Dtype = create_low_level_dtype( num = 5, kind = SIGNEDLTR, name = int32, @@ -323,7 +336,7 @@ ALL_DTYPES = [ W_BoolDtype, -W_Int8Dtype, W_Int32Dtype, W_Int64Dtype, +W_Int8Dtype, W_Int16Dtype, W_Int32Dtype, W_Int64Dtype, W_Float64Dtype ] @@ -353,4 +366,4 @@ kind = interp_attrproperty(kind, cls=W_Dtype), shape = GetSetProperty(W_Dtype.descr_get_shape), ) -W_Dtype.typedef.acceptable_as_base_class = False \ No newline at end of file +W_Dtype.typedef.acceptable_as_base_class = False diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -82,10 +82,20 @@ assert a[1] == 1 def test_add_int8(self): -from numpy import array +from numpy import array, dtype a = array(range(5), dtype=int8) b = a + a +assert b.dtype is dtype(int8) +for i in range(5): +assert b[i] == i * 2 + +def test_add_int16(self): +from numpy import array, dtype + +a = array(range(5), dtype=int16) +b = a + a +assert b.dtype is dtype(int16) for i in range(5): assert b[i] == i * 2 @@ -98,4 +108,4 @@ from numpy import dtype # You can't subclass dtype -raises(TypeError, type, Foo, (dtype,), {}) \ No newline at end of file +raises(TypeError, type, Foo, (dtype,), {}) diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -84,6 +84,9 @@ a = array(range(5), dtype=int8) assert str(a) == [0 1 2 3 4] +a = array(range(5), dtype=int16) +assert str(a) == [0 1 2 3 4] + def test_str_slice(self): from numpy import array, zeros a = array(range(5), float) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: style nits + code duplication removal
Author: Alex Gaynor alex.gay...@gmail.com Branch: Changeset: r46968:a54cf959dccb Date: 2011-08-31 23:25 -0400 http://bitbucket.org/pypy/pypy/changeset/a54cf959dccb/ Log:style nits + code duplication removal diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -53,7 +53,9 @@ VOID_TP = lltype.Ptr(lltype.Array(lltype.Void, hints={'nolength': True, uncast_on_llgraph: True})) -def create_low_level_dtype(num, kind, name, aliases, applevel_types, T, valtype): +def create_low_level_dtype(num, kind, name, aliases, applevel_types, T, valtype, +expected_size=None): + class Box(BaseBox): def __init__(self, val): self.val = val @@ -113,6 +115,8 @@ W_LowLevelDtype.aliases = aliases W_LowLevelDtype.applevel_types = applevel_types W_LowLevelDtype.num_bytes = rffi.sizeof(T) +if expected_size is not None: +assert W_LowLevelDtype.num_bytes == expected_size return W_LowLevelDtype @@ -282,11 +286,10 @@ applevel_types = [], T = rffi.SIGNEDCHAR, valtype = rffi.SIGNEDCHAR._type, +expected_size = 1, ) class W_Int8Dtype(IntegerArithmeticDtype, W_Int8Dtype): -def unwrap(self, space, w_item): -return self.adapt_val(space.int_w(space.int(w_item))) -assert W_Int8Dtype.num_bytes == 1 +pass W_Int16Dtype = create_low_level_dtype( num = 3, kind = SIGNEDLTR, name = int16, @@ -294,11 +297,10 @@ applevel_types = [], T = rffi.SHORT, valtype = rffi.SHORT._type, +expected_size = 2, ) class W_Int16Dtype(IntegerArithmeticDtype, W_Int16Dtype): -def unwrap(self, space, w_item): -return self.adapt_val(space.int_w(space.int(w_item))) -assert W_Int16Dtype.num_bytes == 2 +pass W_Int32Dtype = create_low_level_dtype( num = 5, kind = SIGNEDLTR, name = int32, @@ -306,6 +308,7 @@ applevel_types = [], T = rffi.INT, valtype = rffi.INT._type, +expected_size = 4, ) class W_Int32Dtype(IntegerArithmeticDtype, W_Int32Dtype): pass @@ -316,6 +319,7 @@ applevel_types = [long], T = rffi.LONGLONG, valtype = rffi.LONGLONG._type, +expected_size = 8, ) class W_Int64Dtype(IntegerArithmeticDtype, W_Int64Dtype): pass @@ -326,6 +330,7 @@ applevel_types = [float], T = lltype.Float, valtype = float, +expected_size = 8, ) class W_Float64Dtype(FloatArithmeticDtype, W_Float64Dtype): def unwrap(self, space, w_item): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy unsigned-dtypes: Add UInt32 dtype
Author: Justin Peel notmuchtot...@gmail.com Branch: unsigned-dtypes Changeset: r46969:779c6bc0669f Date: 2011-08-31 22:15 -0600 http://bitbucket.org/pypy/pypy/changeset/779c6bc0669f/ Log:Add UInt32 dtype diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -14,6 +14,7 @@ from pypy.rpython.lltypesystem import lltype, rffi +UNSIGNEDLTR = u SIGNEDLTR = i BOOLLTR = b FLOATINGLTR = f @@ -313,6 +314,17 @@ class W_Int32Dtype(IntegerArithmeticDtype, W_Int32Dtype): pass +W_UInt32Dtype = create_low_level_dtype( +num = 6, kind = UNSIGNEDLTR, name = uint32, +aliases = [I], +applevel_types = [], +T = rffi.UINT, +valtype = rffi.UINT._type, +expected_size = 4, +) +class W_UInt32Dtype(IntegerArithmeticDtype, W_UInt32Dtype): +pass + W_Int64Dtype = create_low_level_dtype( num = 9, kind = SIGNEDLTR, name = int64, aliases = [], @@ -341,7 +353,8 @@ ALL_DTYPES = [ W_BoolDtype, -W_Int8Dtype, W_Int16Dtype, W_Int32Dtype, W_Int64Dtype, +W_Int8Dtype, W_Int16Dtype, W_Int32Dtype, W_UInt32Dtype, +W_Int64Dtype, W_Float64Dtype ] diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -99,6 +99,15 @@ for i in range(5): assert b[i] == i * 2 +def test_add_uint32(self): +from numpy import array, dtype + +a = array(range(5), dtype=I) +b = a + a +assert b.dtype is dtype(I) +for i in range(5): +assert b[i] == i * 2 + def test_shape(self): from numpy import dtype ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy unsigned-dtypes: Add UInt8 dtype
Author: Justin Peel notmuchtot...@gmail.com Branch: unsigned-dtypes Changeset: r46971:1f12ec631b17 Date: 2011-08-31 22:41 -0600 http://bitbucket.org/pypy/pypy/changeset/1f12ec631b17/ Log:Add UInt8 dtype diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -292,6 +292,17 @@ class W_Int8Dtype(IntegerArithmeticDtype, W_Int8Dtype): pass +W_UInt8Dtype = create_low_level_dtype( +num = 1, kind = SIGNEDLTR, name = uint8, +aliases = [uint8], +applevel_types = [], +T = rffi.UCHAR, +valtype = rffi.UCHAR._type, +expected_size = 1, +) +class W_UInt8Dtype(IntegerArithmeticDtype, W_UInt8Dtype): +pass + W_Int16Dtype = create_low_level_dtype( num = 3, kind = SIGNEDLTR, name = int16, aliases = [int16], ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-dtype: unary functions actually aren't working. Simplified the Call1 class.
Author: Justin Peel notmuchtot...@gmail.com Branch: numpy-dtype Changeset: r46970:2062025cf412 Date: 2011-08-24 00:17 -0600 http://bitbucket.org/pypy/pypy/changeset/2062025cf412/ Log:unary functions actually aren't working. Simplified the Call1 class. diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py --- a/pypy/module/micronumpy/__init__.py +++ b/pypy/module/micronumpy/__init__.py @@ -24,7 +24,7 @@ #'maximum': 'interp_ufuncs.maximum', #'minimum': 'interp_ufuncs.minimum', #'multiply': 'interp_ufuncs.multiply', -#'negative': 'interp_ufuncs.negative', +'negative': 'interp_ufuncs.negative', #'reciprocal': 'interp_ufuncs.reciprocal', #'sign': 'interp_ufuncs.sign', #'subtract': 'interp_ufuncs.subtract', 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 @@ -59,14 +59,14 @@ return self descr_neg = _unaryop_impl(interp_ufuncs.negative) -descr_abs = _unaryop_impl(interp_ufuncs.absolute) +#descr_abs = _unaryop_impl(interp_ufuncs.absolute) def _binop_impl(w_ufunc): def impl(self, space, w_other): return w_ufunc(space, self, w_other) return func_with_new_name(impl, binop_%s_impl % w_ufunc.__name__) -descr_add = _binop_impl(interp_ufuncs.add) +#descr_add = _binop_impl(interp_ufuncs.add) #descr_sub = _binop_impl(interp_ufuncs.subtract) #descr_mul = _binop_impl(interp_ufuncs.multiply) #descr_div = _binop_impl(interp_ufuncs.divide) @@ -273,7 +273,7 @@ #w_value = new_numarray(space, w_value, self.dtype) #else: w_value = convert_to_array(space, w_value) -concrete.setslice(space, start, stop, step, +concrete.setslice(start, stop, step, slice_length, w_value) def descr_mean(self, space): @@ -328,10 +328,8 @@ Class for representing virtual arrays, such as binary ops or ufuncs -def __init__(self, signature): +def __init__(self): BaseArray.__init__(self) -self.forced_result = None -self.signature = signature def _del_sources(self): # Function for deleting references to source arrays, to allow garbage-collecting them @@ -352,38 +350,17 @@ #i += 1 #return result -def force_if_needed(self): -if self.forced_result is None: -self.forced_result = self.compute() -self._del_sources() - -def get_concrete(self): -self.force_if_needed() -return self.forced_result - -def eval(self, i): -if self.forced_result is not None: -return self.forced_result.eval(i) -return self._eval(i) - -def find_size(self): -if self.forced_result is not None: -# The result has been computed and sources may be unavailable -return self.forced_result.find_size() -return self._find_size() - -def find_dtype(self): -return self.dtype - def make_call1(_dtype): class Call1(VirtualArray): _immutable_fields_ = [function, values] dtype = _dtype def __init__(self, function, values, signature): -VirtualArray.__init__(self, signature) +VirtualArray.__init__(self) self.function = function self.values = values +self.forced_result = None +self.signature = signature def _del_sources(self): self.values = None @@ -393,17 +370,41 @@ signature = self.signature result_size = self.find_size() result = create_sdarray(result_size, _dtype) -while i result_size: -#numpy_driver.jit_merge_point(signature=signature, -# result_size=result_size, i=i, -# self=self, result=result) -result.setitem(i, self.eval(i)) -i += 1 +result.setslice(0, result_size, 1, result_size, self) +#while i result_size: +##numpy_driver.jit_merge_point(signature=signature, +## result_size=result_size, i=i, +## self=self, result=result) +#result.setitem(i, self.eval(i)) +#i += 1 return result def _find_size(self): return self.values.find_size() +def force_if_needed(self): +if self.forced_result is None: +self.forced_result = self.compute() +self._del_sources() + +def get_concrete(self): +self.force_if_needed() +return
[pypy-commit] pypy unsigned-dtypes: Add UInt16 dtype
Author: Justin Peel notmuchtot...@gmail.com Branch: unsigned-dtypes Changeset: r46972:178ebefab2a6 Date: 2011-08-31 22:42 -0600 http://bitbucket.org/pypy/pypy/changeset/178ebefab2a6/ Log:Add UInt16 dtype diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -314,6 +314,17 @@ class W_Int16Dtype(IntegerArithmeticDtype, W_Int16Dtype): pass +W_UInt16Dtype = create_low_level_dtype( +num = 3, kind = SIGNEDLTR, name = uint16, +aliases = [uint16], +applevel_types = [], +T = rffi.USHORT, +valtype = rffi.USHORT._type, +expected_size = 2, +) +class W_UInt16Dtype(IntegerArithmeticDtype, W_UInt16Dtype): +pass + W_Int32Dtype = create_low_level_dtype( num = 5, kind = SIGNEDLTR, name = int32, aliases = [i], ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] Notification: pypy
You have received a notification from Justin Peel. Hi, I forked pypy. My fork is at https://bitbucket.org/justinpeel/pypy. -- Disable notifications at https://bitbucket.org/account/notifications/ ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit