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/builtin.c | |
parent | a71c83a1d1aeca1d81d7c673929f8e836dec131e (diff) | |
download | micropython-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/builtin.c')
-rw-r--r-- | py/builtin.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/py/builtin.c b/py/builtin.c index 91e54faedb..ef9e70c940 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -36,7 +36,7 @@ STATIC mp_obj_t mp_builtin___build_class__(uint n_args, const mp_obj_t *args) { mp_obj_t meta; if (n_args == 2) { // no explicit bases, so use 'type' - meta = (mp_obj_t)&mp_const_type; + meta = (mp_obj_t)&mp_type_type; } else { // use type of first base object meta = mp_obj_get_type(args[2]); @@ -142,7 +142,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { byte str[1] = {ord}; return mp_obj_new_str(str, 1, true); } else { - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_ValueError, "chr() arg not in range(0x110000)")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "chr() arg not in range(0x110000)")); } } @@ -187,7 +187,7 @@ STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { args[1] = MP_OBJ_NEW_SMALL_INT(i1 % i2); return rt_build_tuple(2, args); } else { - nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'", mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in))); + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'", mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in))); } } @@ -209,7 +209,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter); STATIC mp_obj_t mp_builtin_len(mp_obj_t o_in) { mp_obj_t len = mp_obj_len_maybe(o_in); if (len == NULL) { - nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "object of type '%s' has no len()", mp_obj_get_type_str(o_in))); + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object of type '%s' has no len()", mp_obj_get_type_str(o_in))); } else { return len; } @@ -229,7 +229,7 @@ STATIC mp_obj_t mp_builtin_max(uint n_args, const mp_obj_t *args) { } } if (max_obj == NULL) { - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_ValueError, "max() arg is an empty sequence")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "max() arg is an empty sequence")); } return max_obj; } else { @@ -258,7 +258,7 @@ STATIC mp_obj_t mp_builtin_min(uint n_args, const mp_obj_t *args) { } } if (min_obj == NULL) { - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_ValueError, "min() arg is an empty sequence")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_ValueError, "min() arg is an empty sequence")); } return min_obj; } else { @@ -278,7 +278,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_min_obj, 1, mp_builtin_min); STATIC mp_obj_t mp_builtin_next(mp_obj_t o) { mp_obj_t ret = rt_iternext(o); if (ret == mp_const_stop_iteration) { - nlr_jump(mp_obj_new_exception(MP_QSTR_StopIteration)); + nlr_jump(mp_obj_new_exception(&mp_type_StopIteration)); } else { return ret; } @@ -294,7 +294,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) { // TODO unicode return mp_obj_new_int(((const byte*)str)[0]); } else { - nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "ord() expected a character, but string of length %d found", len)); + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "ord() expected a character, but string of length %d found", len)); } } @@ -364,7 +364,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum); STATIC mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) { assert(n_args >= 1); if (n_args > 1) { - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, + nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "must use keyword argument for key function")); } mp_obj_t self = list_type.make_new((mp_obj_t)&list_type, 1, 0, args); |