diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-17 22:10:53 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-17 22:10:53 +0100 |
commit | 729f7b42d65c016c9d5f27fb8a8122869f06c129 (patch) | |
tree | 8d8d8c2a89ff9011b06650c256a2d5f2458c930c /py/emitnative.c | |
parent | de7c425139c92745280b62f7ebb756def96d072a (diff) | |
download | micropython-729f7b42d65c016c9d5f27fb8a8122869f06c129.tar.gz micropython-729f7b42d65c016c9d5f27fb8a8122869f06c129.zip |
py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.
mp_obj_t->subscr now does load/store/delete.
Diffstat (limited to 'py/emitnative.c')
-rw-r--r-- | py/emitnative.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/py/emitnative.c b/py/emitnative.c index 3046aef4d6..d86456244a 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -778,6 +778,18 @@ STATIC void emit_native_load_build_class(emit_t *emit) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } +STATIC void emit_native_load_subscr(emit_t *emit) { + vtype_kind_t vtype_lhs, vtype_rhs; + emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_2, &vtype_lhs, REG_ARG_1); + if (vtype_lhs == VTYPE_PYOBJ && vtype_rhs == VTYPE_PYOBJ) { + emit_call_with_imm_arg(emit, MP_F_OBJ_SUBSCR, mp_obj_subscr, (machine_uint_t)MP_OBJ_SENTINEL, REG_ARG_3); + emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); + } else { + printf("ViperTypeError: can't do subscr of types %d and %d\n", vtype_lhs, vtype_rhs); + assert(0); + } +} + STATIC void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) { vtype_kind_t vtype; #if N_X64 @@ -850,7 +862,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) { assert(vtype_index == VTYPE_PYOBJ); assert(vtype_base == VTYPE_PYOBJ); assert(vtype_value == VTYPE_PYOBJ); - emit_call(emit, MP_F_STORE_SUBSCR, mp_store_subscr); + emit_call(emit, MP_F_OBJ_SUBSCR, mp_obj_subscr); } STATIC void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) { @@ -882,8 +894,11 @@ STATIC void emit_native_delete_attr(emit_t *emit, qstr qstr) { } STATIC void emit_native_delete_subscr(emit_t *emit) { - // not supported - assert(0); + vtype_kind_t vtype_index, vtype_base; + emit_pre_pop_reg_reg(emit, &vtype_index, REG_ARG_2, &vtype_base, REG_ARG_1); // index, base + assert(vtype_index == VTYPE_PYOBJ); + assert(vtype_base == VTYPE_PYOBJ); + emit_call_with_imm_arg(emit, MP_F_OBJ_SUBSCR, mp_obj_subscr, (machine_uint_t)MP_OBJ_NULL, REG_ARG_3); } STATIC void emit_native_dup_top(emit_t *emit) { @@ -1328,6 +1343,7 @@ const emit_method_table_t EXPORT_FUN(method_table) = { emit_native_load_attr, emit_native_load_method, emit_native_load_build_class, + emit_native_load_subscr, emit_native_store_fast, emit_native_store_deref, emit_native_store_name, |