summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorHierophect <hierophect@gmail.com>2020-01-06 11:31:25 -0500
committerHierophect <hierophect@gmail.com>2020-01-06 11:31:25 -0500
commitfff5f8eb65d02fcf028e769010439703d96adac4 (patch)
treec23490afca8f218c222af81cd0d0db8e8baadc52 /py
parent7198cc8ed6d079aa54fa975b6c781c865271c136 (diff)
parent776c9b011c26f9833f392fcf8270d20a4bbc8031 (diff)
Merge remote-tracking branch 'upstream/master' into stm32-meowbit
Diffstat (limited to 'py')
-rw-r--r--py/obj.c2
-rw-r--r--py/objlist.c8
-rw-r--r--py/objnamedtuple.c12
-rw-r--r--py/objnamedtuple.h1
-rw-r--r--py/objtuple.c1
-rw-r--r--py/objtype.c10
6 files changed, 25 insertions, 9 deletions
diff --git a/py/obj.c b/py/obj.c
index bd2aaf9d2..09e71be4d 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -489,6 +489,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
mp_obj_type_t *type = mp_obj_get_type(base);
+
if (type->subscr != NULL) {
mp_obj_t ret = type->subscr(base, index, value);
// May have called port specific C code. Make sure it didn't mess up the heap.
@@ -496,7 +497,6 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
if (ret != MP_OBJ_NULL) {
return ret;
}
- // TODO: call base classes here?
}
if (value == MP_OBJ_NULL) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
diff --git a/py/objlist.c b/py/objlist.c
index ea38e64e5..b32f82085 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -159,11 +159,11 @@ STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
}
STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
+ mp_obj_list_t *self = mp_instance_cast_to_native_base(self_in, &mp_type_list);
if (value == MP_OBJ_NULL) {
// delete
#if MICROPY_PY_BUILTINS_SLICE
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
- mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
mp_raise_NotImplementedError(NULL);
@@ -179,12 +179,11 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
return mp_const_none;
}
#endif
- mp_obj_t args[2] = {self_in, index};
+ mp_obj_t args[2] = {self, index};
list_pop(2, args);
return mp_const_none;
} else if (value == MP_OBJ_SENTINEL) {
// load
- mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
#if MICROPY_PY_BUILTINS_SLICE
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
mp_bound_slice_t slice;
@@ -201,7 +200,6 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
} else {
#if MICROPY_PY_BUILTINS_SLICE
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
- mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
size_t value_len; mp_obj_t *value_items;
mp_obj_get_array(value, &value_len, &value_items);
mp_bound_slice_t slice_out;
@@ -230,7 +228,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
return mp_const_none;
}
#endif
- mp_obj_list_store(self_in, index, value);
+ mp_obj_list_store(self, index, value);
return mp_const_none;
}
}
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c
index a044fe3ff..a0a64f9b2 100644
--- a/py/objnamedtuple.c
+++ b/py/objnamedtuple.c
@@ -31,6 +31,7 @@
#include "py/runtime.h"
#include "py/objstr.h"
#include "py/objnamedtuple.h"
+#include "py/objtype.h"
#include "supervisor/shared/translate.h"
@@ -70,6 +71,15 @@ void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t ki
mp_obj_attrtuple_print_helper(print, fields, &o->tuple);
}
+mp_obj_t namedtuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
+ mp_obj_type_t *type = mp_obj_get_type(self_in);
+ // Check for subclasses of namedtuple and unpack if needed.
+ if (type->parent != &mp_type_tuple) {
+ self_in = ((mp_obj_instance_t*) self_in)->subobj[0];
+ }
+ return mp_obj_tuple_subscr(self_in, index, value);
+}
+
void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
if (dest[0] == MP_OBJ_NULL) {
// load attribute
@@ -167,7 +177,7 @@ STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t
o->base.unary_op = mp_obj_tuple_unary_op;
o->base.binary_op = mp_obj_tuple_binary_op;
o->base.attr = namedtuple_attr;
- o->base.subscr = mp_obj_tuple_subscr;
+ o->base.subscr = namedtuple_subscr;
o->base.getiter = mp_obj_tuple_getiter;
o->base.parent = &mp_type_tuple;
return MP_OBJ_FROM_PTR(o);
diff --git a/py/objnamedtuple.h b/py/objnamedtuple.h
index 0ea0d2862..5a7512e3a 100644
--- a/py/objnamedtuple.h
+++ b/py/objnamedtuple.h
@@ -49,6 +49,7 @@ typedef struct _mp_obj_namedtuple_t {
void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind);
size_t mp_obj_namedtuple_find_field(const mp_obj_namedtuple_type_t *type, qstr name);
+mp_obj_t namedtuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
mp_obj_namedtuple_type_t *mp_obj_new_namedtuple_base(size_t n_fields, mp_obj_t *fields);
mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
diff --git a/py/objtuple.c b/py/objtuple.c
index ed13cdcef..2b483f8b8 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -178,6 +178,7 @@ mp_obj_t mp_obj_tuple_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
}
mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
+
if (value == MP_OBJ_SENTINEL) {
// load
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
diff --git a/py/objtype.c b/py/objtype.c
index 0212a78da..a5e733208 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -34,6 +34,7 @@
#include "py/objtype.h"
#include "py/runtime.h"
+#include "supervisor/shared/stack.h"
#include "supervisor/shared/translate.h"
#if MICROPY_DEBUG_VERBOSE // print debugging info
@@ -851,8 +852,13 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
mp_obj_class_lookup(&lookup, self->base.type);
meth_args = 3;
}
- if (member[0] == MP_OBJ_SENTINEL) {
- return mp_obj_subscr(self->subobj[0], index, value);
+ if (member[0] == MP_OBJ_SENTINEL) { // native base subscr exists
+ mp_obj_type_t *subobj_type = mp_obj_get_type(self->subobj[0]);
+ // return mp_obj_subscr(self->subobj[0], index, value, instance);
+ mp_obj_t ret = subobj_type->subscr(self_in, index, value);
+ // May have called port specific C code. Make sure it didn't mess up the heap.
+ assert_heap_ok();
+ return ret;
} else if (member[0] != MP_OBJ_NULL) {
mp_obj_t args[3] = {self_in, index, value};
// TODO probably need to call mp_convert_member_lookup, and use mp_call_method_n_kw