From ded0a1efa5744235fbb4cd07c96598018a3661eb Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 3 Jan 2014 02:48:56 +0200 Subject: Implement BUILD_SLICE opcode (2-arg version). --- py/vm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'py/vm.c') diff --git a/py/vm.c b/py/vm.c index c549e2b49..35dcbea52 100644 --- a/py/vm.c +++ b/py/vm.c @@ -410,6 +410,18 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t ** sp++; break; + case MP_BC_BUILD_SLICE: + DECODE_UINT; + if (unum == 2) { + obj2 = POP(); + obj1 = TOP(); + SET_TOP(mp_obj_new_slice(obj1, obj2, NULL)); + } else { + printf("3-argument slice is not supported\n"); + assert(0); + } + break; + case MP_BC_UNPACK_SEQUENCE: DECODE_UINT; rt_unpack_sequence(sp[0], unum, sp - unum + 1); -- cgit v1.2.3 From e606cb656165aff2424fb6ca45f09d606246d073 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 4 Jan 2014 01:34:23 +0200 Subject: slice: Allow building with MICROPY_ENABLE_SLICE=0. --- py/objstr.c | 2 ++ py/vm.c | 2 ++ 2 files changed, 4 insertions(+) (limited to 'py/vm.c') diff --git a/py/objstr.c b/py/objstr.c index 54dd087a4..8e3e9d902 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -35,6 +35,7 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (MP_OBJ_IS_SMALL_INT(rhs_in)) { // TODO: This implements byte string access for single index so far return mp_obj_new_int(lhs_str[mp_obj_get_int(rhs_in)]); +#if MICROPY_ENABLE_SLICE } else if (MP_OBJ_IS_TYPE(rhs_in, &slice_type)) { int start, stop, step; mp_obj_slice_get(rhs_in, &start, &stop, &step); @@ -47,6 +48,7 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { stop = len + stop; } return mp_obj_new_str(qstr_from_strn_copy(lhs_str + start, stop - start)); +#endif } else { // Throw TypeError here assert(0); diff --git a/py/vm.c b/py/vm.c index 35dcbea52..382780640 100644 --- a/py/vm.c +++ b/py/vm.c @@ -410,6 +410,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t ** sp++; break; +#if MICROPY_ENABLE_SLICE case MP_BC_BUILD_SLICE: DECODE_UINT; if (unum == 2) { @@ -421,6 +422,7 @@ bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t ** assert(0); } break; +#endif case MP_BC_UNPACK_SEQUENCE: DECODE_UINT; -- cgit v1.2.3