Merge branch 'master' of github.com:micropython/micropython

This commit is contained in:
Damien George 2014-03-26 18:56:02 +00:00
commit 9c817b9465
2 changed files with 12 additions and 5 deletions

View File

@ -315,6 +315,7 @@ bool mp_obj_exception_match(mp_obj_t exc, const mp_obj_type_t *exc_type);
void mp_obj_exception_clear_traceback(mp_obj_t self_in);
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, machine_uint_t line, qstr block);
void mp_obj_exception_get_traceback(mp_obj_t self_in, machine_uint_t *n, machine_uint_t **values);
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
// str
extern const mp_obj_type_t str_type;

View File

@ -61,16 +61,22 @@ STATIC mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, uint n_args, uint n_
return o;
}
// Get exception "value" - that is, first argument, or None
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in) {
mp_obj_exception_t *self = self_in;
if (self->args.len == 0) {
return mp_const_none;
} else {
return self->args.items[0];
}
}
STATIC void exception_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
mp_obj_exception_t *self = self_in;
if (attr == MP_QSTR_args) {
dest[0] = &self->args;
} else if (self->base.type == &mp_type_StopIteration && attr == MP_QSTR_value) {
if (self->args.len == 0) {
dest[0] = mp_const_none;
} else {
dest[0] = self->args.items[0];
}
dest[0] = mp_obj_exception_get_value(self);
}
}