diff options
author | Damien George <damien.p.george@gmail.com> | 2014-02-15 16:10:44 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-02-15 16:10:44 +0000 |
commit | c5966128c7c8a768f6726f299d85d5daef6bed48 (patch) | |
tree | fea6913ae43d722078a837d8c7fd9a1e459f3891 /py/objstr.c | |
parent | a71c83a1d1aeca1d81d7c673929f8e836dec131e (diff) |
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/objstr.c')
-rw-r--r-- | py/objstr.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/py/objstr.c b/py/objstr.c index 6ccd23995..a1291a220 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -124,7 +124,7 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } else { // Message doesn't match CPython, but we don't have so much bytes as they // to spend them on verbose wording - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "index must be int")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "index must be int")); } case RT_BINARY_OP_ADD: @@ -235,7 +235,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { return mp_obj_str_builder_end(joined_str); bad_arg: - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "?str.join expecting a list of str's")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "?str.join expecting a list of str's")); } #define is_ws(c) ((c) == ' ' || (c) == '\t') @@ -387,7 +387,7 @@ mp_obj_t str_format(uint n_args, const mp_obj_t *args) { } else { while (str < top && *str != '}') str++; if (arg_i >= n_args) { - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_IndexError, "tuple index out of range")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_IndexError, "tuple index out of range")); } // TODO: may be PRINT_REPR depending on formatting code mp_obj_print_helper((void (*)(void*, const char*, ...))vstr_printf, vstr, args[arg_i], PRINT_STR); @@ -507,7 +507,7 @@ STATIC const mp_method_t str_type_methods[] = { }; const mp_obj_type_t str_type = { - { &mp_const_type }, + { &mp_type_type }, .name = MP_QSTR_str, .print = str_print, .binary_op = str_binary_op, @@ -517,7 +517,7 @@ const mp_obj_type_t str_type = { // Reuses most of methods from str const mp_obj_type_t bytes_type = { - { &mp_const_type }, + { &mp_type_type }, .name = MP_QSTR_bytes, .print = str_print, .binary_op = str_binary_op, @@ -589,7 +589,7 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) { void bad_implicit_conversion(mp_obj_t self_in) __attribute__((noreturn)); void bad_implicit_conversion(mp_obj_t self_in) { - nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "Can't convert '%s' object to str implicitly", mp_obj_get_type_str(self_in))); + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "Can't convert '%s' object to str implicitly", mp_obj_get_type_str(self_in))); } uint mp_obj_str_get_hash(mp_obj_t self_in) { @@ -667,7 +667,7 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } STATIC const mp_obj_type_t str_it_type = { - { &mp_const_type }, + { &mp_type_type }, .name = MP_QSTR_iterator, .iternext = str_it_iternext, }; @@ -685,7 +685,7 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) { } STATIC const mp_obj_type_t bytes_it_type = { - { &mp_const_type }, + { &mp_type_type }, .name = MP_QSTR_iterator, .iternext = bytes_it_iternext, }; |