[pypy-svn] r6630 - pypy/trunk/src/pypy/translator
arigo at codespeak.net
arigo at codespeak.net
Tue Sep 21 20:40:29 CEST 2004
Author: arigo
Date: Tue Sep 21 20:40:28 2004
New Revision: 6630
Modified:
pypy/trunk/src/pypy/translator/genc.h
pypy/trunk/src/pypy/translator/genc.py
pypy/trunk/src/pypy/translator/genc_op.py
pypy/trunk/src/pypy/translator/genc_typeset.py
Log:
Bug fixes and progress on arrays...
Modified: pypy/trunk/src/pypy/translator/genc.h
==============================================================================
--- pypy/trunk/src/pypy/translator/genc.h (original)
+++ pypy/trunk/src/pypy/translator/genc.h Tue Sep 21 20:40:28 2004
@@ -142,9 +142,12 @@
PyErr_Occurred()) goto err;
#define OP_NEWARRAY(name,len,r,err) if (!(r=alloclist_##name(len))) goto err;
-#define OP_NEWARRAY_SET(name,r,i,f,v) ((PyList_##name*) r)->ob_item[i].f=v;
-#define OP_NEWARRAY_SET_o(name,r,i,f,o) ((PyList_##name*) r)->ob_item[i].f=o; \
+#define OP_NEWARRAY_SET(name,a,i,f,v) ((PyList_##name*) a)->ob_item[i].f=v;
+#define OP_NEWARRAY_SET_o(name,a,i,f,o) ((PyList_##name*) a)->ob_item[i].f=o; \
Py_INCREF(o);
+#define OP_GETARRAYITEM(name,a,i,f,r) r=((PyList_##name*) a)->ob_item[i].f;
+#define OP_GETARRAYITEM_o(name,a,i,f,r) r=((PyList_##name*) a)->ob_item[i].f; \
+ Py_INCREF(r);
/************************************************************/
/*** The rest is produced by genc.py ***/
Modified: pypy/trunk/src/pypy/translator/genc.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genc.py (original)
+++ pypy/trunk/src/pypy/translator/genc.py Tue Sep 21 20:40:28 2004
@@ -317,7 +317,11 @@
return self.llarrays[lltypes] # already seen
s = '_'.join(lltypes)
- name = ''.join([('a'<=c<='z' or '0'<=c<='9') and c or '_' for c in s])
+ name = ''.join([('a'<=c<='z' or
+ 'A'<=c<='Z' or
+ '0'<=c<='9') and c or '_'
+ for c in s])
+ name = name or 'void'
name += '_%d' % len(self.llarrays)
self.llarrays[lltypes] = name
@@ -333,7 +337,7 @@
print >> f, self.C_LIST_FOOTER % info
print >> f, self.C_LIST_DEALLOC_HEADER % info
- lldecref = self.typeset.rawoperations['xdecref']
+ lldecref = self.typeset.rawoperations['decref']
line = lldecref(llvars1)
code = line.write()
if code:
@@ -472,12 +476,12 @@
C_LIST_DEALLOC_LOOP_HEADER = (
''' int i = op->ob_size;
- ListItem_%(name)s item = op->ob_item + i;
- while (--i >= 0) {''')
+ ListItem_%(name)s* item = op->ob_item + i;
+ while (--i >= 0) {
+ --item;''')
C_LIST_DEALLOC_LOOP_FOOTER = (
-''' --item;
- }''')
+''' }''')
C_LIST_DEALLOC_FOOTER = (
''' PyMem_Free(op->ob_item);
@@ -535,7 +539,7 @@
else {
PyMem_Free(buffer);
}
- return o;
+ return (PyObject*) o;
}
'''
Modified: pypy/trunk/src/pypy/translator/genc_op.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genc_op.py (original)
+++ pypy/trunk/src/pypy/translator/genc_op.py Tue Sep 21 20:40:28 2004
@@ -165,18 +165,63 @@
args = stuff[:-2]
result = stuff[-2]
err = stuff[-1]
- ls = ['OP_NEWARRAY(%s, %d, %s, %s)' % (self.typename,
- len(args) / len(self.lltypes),
- result,
- err)]
- for i in range(0, len(args), len(self.lltypes)):
+ if len(args) == len(self.lltypes) == 0:
+ arraylen = 0
+ else:
+ assert len(args) % len(self.lltypes) == 0
+ arraylen = len(args) / len(self.lltypes)
+ ls = ['OP_NEWARRAY(%s, %d, %s, %s)' % (
+ self.typename, arraylen, result, err)]
+ for i in range(arraylen):
for j in range(len(self.lltypes)):
if self.lltypes[j] == 'PyObject*':
typecode = '_o'
else:
typecode = ''
+ a = args[i*len(self.lltypes) + j]
ls.append('OP_NEWARRAY_SET%s(%s, %s, %d, a%d, %s)' % (
- typecode, self.typename, result, i, j, args[i+j]))
+ typecode, self.typename, result, i, j, a))
+ return '\n'.join(ls)
+
+class LoAllocAndSetArray(LoC):
+ can_fail = True
+ typename = PARAMETER # the name of the PyList_Xxx type in the C source
+ lltypes = PARAMETER # the C types needed to represent each array item
+ # self.args: [length, input_item.., output PyObject]
+ def writestr(self, length, *stuff):
+ input = stuff[:-2]
+ result = stuff[-2]
+ err = stuff[-1]
+ assert len(input) == len(self.lltypes)
+ ls = ['OP_NEWARRAY(%s, %s, %s, %s)' % (
+ self.typename, length, result, err)]
+ if len(self.lltypes) > 0:
+ ls.append('{ int i; for (i=0; i<%s; i++) {' % length)
+ for j in range(len(self.lltypes)):
+ if self.lltypes[j] == 'PyObject*':
+ typecode = '_o'
+ else:
+ typecode = ''
+ a = input[j]
+ ls.append('\tOP_NEWARRAY_SET%s(%s, %s, i, a%d, %s)' % (
+ typecode, self.typename, result, j, a))
+ ls.append('} }')
+ return '\n'.join(ls)
+
+class LoGetArrayItem(LoC):
+ typename = PARAMETER # the name of the PyList_Xxx type in the C source
+ lltypes = PARAMETER # the C types needed to represent each array item
+ # self.args: [PyObject, int_index, output_item..]
+ def writestr(self, array, index, *output):
+ assert len(output) == len(self.lltypes)
+ ls = []
+ for j in range(len(self.lltypes)):
+ if self.lltypes[j] == 'PyObject*':
+ typecode = '_o'
+ else:
+ typecode = ''
+ ls.append('OP_GETARRAYITEM%s(%s, %s, %s, a%d, %s)' % (
+ typecode, self.typename, array, index, j, output[j]))
return '\n'.join(ls)
class LoGetAttr(LoC):
Modified: pypy/trunk/src/pypy/translator/genc_typeset.py
==============================================================================
--- pypy/trunk/src/pypy/translator/genc_typeset.py (original)
+++ pypy/trunk/src/pypy/translator/genc_typeset.py Tue Sep 21 20:40:28 2004
@@ -171,6 +171,18 @@
lltypes = r.r_item.impl,
)
+ def extend_OP_ALLOC_AND_SET(self, hltypes):
+ if len(hltypes) != 3:
+ return
+ # we have LoAllocAndSetArray
+ r_length, r_input, r = hltypes
+ if isinstance(r, CList):
+ sig = (R_INT, r.r_item, r)
+ yield sig, genc_op.LoAllocAndSetArray.With(
+ typename = r.typename,
+ lltypes = r.r_item.impl,
+ )
+
def extend_OP_NEWTUPLE(self, hltypes):
# We can use LoCopy to virtually build a tuple because
# the tuple representation 'rt' is just the collection of all the
@@ -326,6 +338,18 @@
llclass = llclass,
)
+ def extend_OP_GETITEM(self, hltypes):
+ if len(hltypes) != 3:
+ return
+ r, r_index, r_result = hltypes
+ # reading from a CList
+ if isinstance(r, CList):
+ sig = (r, R_INT, r.r_item)
+ yield sig, genc_op.LoGetArrayItem.With(
+ typename = r.typename,
+ lltypes = r.r_item.impl,
+ )
+
# ____________________________________________________________
def parse_operation_templates(self):
More information about the Pypy-commit
mailing list