[pypy-svn] r76433 - in pypy/branch/interplevel-array/pypy: jit/tl module/array objspace/std
hakanardo at codespeak.net
hakanardo at codespeak.net
Mon Aug 2 18:01:45 CEST 2010
Author: hakanardo
Date: Mon Aug 2 18:01:43 2010
New Revision: 76433
Modified:
pypy/branch/interplevel-array/pypy/jit/tl/pypyjit_demo.py
pypy/branch/interplevel-array/pypy/module/array/interp_array.py
pypy/branch/interplevel-array/pypy/objspace/std/model.py
Log:
Single type passes pypyjit.py
Modified: pypy/branch/interplevel-array/pypy/jit/tl/pypyjit_demo.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/jit/tl/pypyjit_demo.py (original)
+++ pypy/branch/interplevel-array/pypy/jit/tl/pypyjit_demo.py Mon Aug 2 18:01:43 2010
@@ -37,18 +37,22 @@
## t2 = time.time()
## print t2 - t1
-from array import array
-def f(img):
- i=0
- sa=0
- while i<4:
- sa+=img[i]
- i+=1
- return sa
-
-img=array('i',(1,2,3,4))
-print f(img)
+try:
+ from array import array
+ def f(img):
+ i=0
+ sa=0
+ while i<4:
+ sa+=img[i]
+ i+=1
+ return sa
+ img=array('i',(1,2,3,4))
+ print f(img)
+except Exception, e:
+ print "Exception: ", type(e)
+ print e
+
## def f():
## a=7
## i=0
Modified: pypy/branch/interplevel-array/pypy/module/array/interp_array.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/module/array/interp_array.py (original)
+++ pypy/branch/interplevel-array/pypy/module/array/interp_array.py Mon Aug 2 18:01:43 2010
@@ -127,7 +127,7 @@
'I': TypeCode(rffi.UINT, 'int_w', True),
'l': TypeCode(rffi.LONG, 'int_w', True, True),
'L': TypeCode(rffi.ULONG, 'bigint_w'), # Overflow handled by rbigint.touint() which
- # corresponds to the C-type unsigned long
+ # corresponds to the C-type unsigned long
'f': TypeCode(lltype.SingleFloat, 'float_w'),
'd': TypeCode(lltype.Float, 'float_w'),
}
@@ -311,13 +311,17 @@
w_lst = space.getitem(w_lst, w_slice)
w_a=mytype.w_class(self.space)
w_a.fromsequence(w_lst)
+ elif step == 0:
+ raise ValueError, 'getitem__Array_Slice with step zero'
else:
size = (stop - start) / step
if (stop - start) % step > 0: size += 1
w_a=mytype.w_class(self.space)
w_a.setlen(size)
- for j,i in enumerate(range(start, stop, step)):
- w_a.buffer[j]=self.buffer[i]
+ j = 0
+ for i in range(start, stop, step):
+ w_a.buffer[j] = self.buffer[i]
+ j += 1
return w_a
def getslice__Array_ANY_ANY(space, self, w_i, w_j):
@@ -341,9 +345,13 @@
space.setitem(w_lst, w_idx, w_item)
self.setlen(0)
self.fromsequence(w_lst)
+ elif step == 0:
+ raise ValueError, 'setitem__Array_Slice with step zero'
else:
- for j,i in enumerate(range(start, stop, step)):
- self.buffer[i]=w_item.buffer[j]
+ j = 0
+ for i in range(start, stop, step):
+ self.buffer[i] = w_item.buffer[j]
+ j += 1
def setslice__Array_ANY_ANY_ANY(space, self, w_i, w_j, w_x):
space.setitem(self, space.newslice(w_i, w_j, space.w_None), w_x)
@@ -361,19 +369,19 @@
# List interface
def array_count__Array_ANY(space, self, w_val):
- val = self.item_w(w_val)
cnt = 0
for i in range(self.len):
- if self.buffer[i] == val:
+ w_item = getitem__Array_ANY(space, self, space.wrap(i))
+ if space.is_true(space.eq(w_item, w_val)):
cnt += 1
return space.wrap(cnt)
def array_index__Array_ANY(space, self, w_val):
- val = self.item_w(w_val)
cnt = 0
for i in range(self.len):
- if self.buffer[i] == val:
+ w_item = getitem__Array_ANY(space, self, space.wrap(i))
+ if space.is_true(space.eq(w_item, w_val)):
return space.wrap(i)
msg = 'array.index(x): x not in list'
raise OperationError(space.w_ValueError, space.wrap(msg))
@@ -504,7 +512,8 @@
item = space.str_w(w_item)
if len(item) < size:
n = len(item) % self.itemsize
- if n != 0: item = item[0:-(len(item) % self.itemsize)]
+ elems = max(0,len(item)-(len(item) % self.itemsize))
+ if n != 0: item = item[0:elems]
w_item = space.wrap(item)
array_fromstring__Array_ANY(space, self, w_item)
msg = "not enough items in file"
@@ -610,9 +619,17 @@
def init__Array(space, self, args):
args.parse_obj(None, 'array', init_signature, init_defaults)
- W_Array.__name__ = 'W_ArrayType_'+mytype.typecode
mytype.w_class = W_Array
+ # Annotator seems to mess up if the names are not unique
+ name = 'ArrayType'+mytype.typecode
+ W_Array.__name__ = 'W_' + name
+ import re
+ for n,f in locals().items():
+ new,n = re.subn('_Array_', '_%s_' % name, n)
+ if n>0:
+ f.__name__ = new
+
from pypy.objspace.std.sliceobject import W_SliceObject
from pypy.objspace.std.listobject import W_ListObject
from pypy.objspace.std.unicodeobject import W_UnicodeObject
Modified: pypy/branch/interplevel-array/pypy/objspace/std/model.py
==============================================================================
--- pypy/branch/interplevel-array/pypy/objspace/std/model.py (original)
+++ pypy/branch/interplevel-array/pypy/objspace/std/model.py Mon Aug 2 18:01:43 2010
@@ -88,6 +88,7 @@
import pypy.objspace.std.default # register a few catch-all multimethods
import pypy.objspace.std.marshal_impl # install marshal multimethods
+ import pypy.module.array
# the set of implementation types
self.typeorder = {
More information about the Pypy-commit
mailing list