Implement proper exception type hierarchy.
Each built-in exception is now a type, with base type BaseException.
C exceptions are created by passing a pointer to the exception type to
make an instance of. When raising an exception from the VM, an
instance is created automatically if an exception type is raised (as
opposed to an exception instance).
Exception matching (RT_BINARY_OP_EXCEPTION_MATCH) is now proper.
Handling of parse error changed to match new exceptions.
mp_const_type renamed to mp_type_type for consistency.
diff --git a/py/objdict.c b/py/objdict.c
index 15e738d..31a80bd 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -60,7 +60,7 @@
// dict load
mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP);
if (elem == NULL) {
- nlr_jump(mp_obj_new_exception_msg(MP_QSTR_KeyError, "<value>"));
+ nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "<value>"));
} else {
return elem->value;
}
@@ -112,7 +112,7 @@
}
STATIC const mp_obj_type_t dict_it_type = {
- { &mp_const_type },
+ { &mp_type_type },
.name = MP_QSTR_iterator,
.iternext = dict_it_iternext,
};
@@ -187,7 +187,7 @@
if (elem == NULL || elem->value == NULL) {
if (deflt == NULL) {
if (lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND) {
- nlr_jump(mp_obj_new_exception_msg(MP_QSTR_KeyError, "<value>"));
+ nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "<value>"));
} else {
value = mp_const_none;
}
@@ -246,7 +246,7 @@
assert(MP_OBJ_IS_TYPE(self_in, &dict_type));
mp_obj_dict_t *self = self_in;
if (self->map.used == 0) {
- nlr_jump(mp_obj_new_exception_msg(MP_QSTR_KeyError, "popitem(): dictionary is empty"));
+ nlr_jump(mp_obj_new_exception_msg(&mp_type_KeyError, "popitem(): dictionary is empty"));
}
mp_obj_dict_it_t *iter = mp_obj_new_dict_iterator(self, 0);
@@ -276,7 +276,7 @@
|| value == mp_const_stop_iteration
|| stop != mp_const_stop_iteration) {
nlr_jump(mp_obj_new_exception_msg(
- MP_QSTR_ValueError,
+ &mp_type_ValueError,
"dictionary update sequence has the wrong length"));
} else {
mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
@@ -341,7 +341,7 @@
}
STATIC const mp_obj_type_t dict_view_it_type = {
- { &mp_const_type },
+ { &mp_type_type },
.name = MP_QSTR_iterator,
.iternext = dict_view_it_iternext,
.methods = NULL, /* set operations still to come */
@@ -385,7 +385,7 @@
STATIC const mp_obj_type_t dict_view_type = {
- { &mp_const_type },
+ { &mp_type_type },
.name = MP_QSTR_dict_view,
.print = dict_view_print,
.binary_op = dict_view_binary_op,
@@ -440,7 +440,7 @@
};
const mp_obj_type_t dict_type = {
- { &mp_const_type },
+ { &mp_type_type },
.name = MP_QSTR_dict,
.print = dict_print,
.make_new = dict_make_new,