Closed GoogleCodeExporter closed 9 years ago
Hi,
I had implemented my own 'SLICE+1' bytecode support in PyMite 0.9 which might
be helpful to you. You actually need to modify two files in PyMite 0.9. They
are:
pymite-09/src/vm/interp.c
pymite-09/src/tools/pmImgCreator.py
I tested my implementation with the following simple code in ipm:
ipm> a=[1,2,3]
ipm> a[1:]
[2, 3]
You can patch your interp.c file with this:
567,614d566
< case SLICE_1:
< /* Implements TOS = TOS1[TOS:] */
<
< /* Create a copy if it is a list and remove
< items from [0:TOS-1] from this list */
< if ((OBJ_GET_TYPE(TOS) == OBJ_TYPE_INT)
< && (OBJ_GET_TYPE(TOS1) == OBJ_TYPE_LST))
< {
< t16 = (int16_t)((pPmInt_t)TOS)->val;
<
< if ( t16 <= -((pPmList_t)TOS1)->length )
< {
< t16 = 0; // No items to be removed
< }
< else if ( t16 > -((pPmList_t)TOS1)->length && t16 < 0 )
< {
< t16 = t16 % (int16_t)((pPmList_t)TOS1)->length;
< }
< else if ( t16 > (int16_t)((pPmList_t)TOS1)->length )
< {
< // All items will be removed
< t16 = (int16_t)((pPmList_t)TOS1)->length;
< }
<
< retval = list_copy(TOS1, &pobj2);
<
< PM_BREAK_IF_ERROR(retval);
<
< for (; t16 > 0; t16--)
< {
< retval = list_delItem(pobj2, 0);
< PM_BREAK_IF_ERROR(retval);
< }
<
< TOS = pobj2;
< }
<
< /* If TOS is an immutable sequence leave it (no op) */
<
< /* Raise a TypeError for types that can not be sliced */
< else if ((OBJ_GET_TYPE(TOS) != OBJ_TYPE_STR)
< && (OBJ_GET_TYPE(TOS) != OBJ_TYPE_TUP))
< {
< PM_RAISE(retval, PM_RET_EX_TYPE);
< break;
< }
< continue;
<
And patch your pmImgCreator.py with this:
150,151c150
< # "SLICE+1", "SLICE+2", "SLICE+3",
< "SLICE+2", "SLICE+3",
---
> "SLICE+1", "SLICE+2", "SLICE+3",
I hope it helps! Let me know if you have any questions.
Bin Huang
Original comment by bin.art...@gmail.com
on 15 Feb 2012 at 7:43
I'm expanding this issue to implement SLICE_1, 2 and 3 for List, Tuple and
String data types.
Original comment by dwhall...@gmail.com
on 19 Jun 2013 at 2:52
This issue was closed by revision a52d92e88c3e.
Original comment by dwhall...@gmail.com
on 19 Jun 2013 at 2:56
Original comment by dwhall...@gmail.com
on 19 Jun 2013 at 2:58
Original issue reported on code.google.com by
yodara...@gmail.com
on 9 Feb 2012 at 5:06