summaryrefslogtreecommitdiffstatshomepage
path: root/py/objdict.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-02-15 16:10:44 +0000
committerDamien George <damien.p.george@gmail.com>2014-02-15 16:10:44 +0000
commitc5966128c7c8a768f6726f299d85d5daef6bed48 (patch)
treefea6913ae43d722078a837d8c7fd9a1e459f3891 /py/objdict.c
parenta71c83a1d1aeca1d81d7c673929f8e836dec131e (diff)
downloadmicropython-c5966128c7c8a768f6726f299d85d5daef6bed48.tar.gz
micropython-c5966128c7c8a768f6726f299d85d5daef6bed48.zip
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.
Diffstat (limited to 'py/objdict.c')
-rw-r--r--py/objdict.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/py/objdict.c b/py/objdict.c
index 15e738dff1..31a80bd6cb 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -60,7 +60,7 @@ STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
// 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 @@ mp_obj_t dict_it_iternext(mp_obj_t self_in) {
}
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 @@ STATIC mp_obj_t dict_get_helper(mp_map_t *self, mp_obj_t key, mp_obj_t deflt, mp
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 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) {
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 @@ STATIC mp_obj_t dict_update(mp_obj_t self_in, mp_obj_t iterable) {
|| 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 mp_obj_t dict_view_it_iternext(mp_obj_t self_in) {
}
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 mp_obj_t dict_view_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
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 @@ STATIC const mp_method_t dict_type_methods[] = {
};
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,