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/objgenerator.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/objgenerator.c')
-rw-r--r-- | py/objgenerator.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/py/objgenerator.c b/py/objgenerator.c index 4e7d3a199b..226b902daf 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -28,17 +28,17 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp const byte *bc_code; mp_obj_fun_bc_get(self_fun, &bc_n_args, &bc_n_state, &bc_code); if (n_args != bc_n_args) { - nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "function takes %d positional arguments but %d were given", bc_n_args, n_args)); + nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "function takes %d positional arguments but %d were given", bc_n_args, n_args)); } if (n_kw != 0) { - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "function does not take keyword arguments")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "function does not take keyword arguments")); } return mp_obj_new_gen_instance(bc_code, bc_n_state, n_args, args); } const mp_obj_type_t gen_wrap_type = { - { &mp_const_type }, + { &mp_type_type }, .name = MP_QSTR_generator, .call = gen_wrap_call, }; @@ -77,7 +77,7 @@ STATIC mp_obj_t gen_next_send(mp_obj_t self_in, mp_obj_t send_value) { } if (self->sp == self->state - 1) { if (send_value != mp_const_none) { - nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "can't send non-None value to a just-started generator")); + nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "can't send non-None value to a just-started generator")); } } else { *self->sp = send_value; @@ -108,10 +108,12 @@ mp_obj_t gen_instance_iternext(mp_obj_t self_in) { STATIC mp_obj_t gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) { mp_obj_t ret = gen_next_send(self_in, send_value); 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; } - return ret; } + STATIC MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_send_obj, gen_instance_send); STATIC const mp_method_t gen_type_methods[] = { @@ -120,7 +122,7 @@ STATIC const mp_method_t gen_type_methods[] = { }; const mp_obj_type_t gen_instance_type = { - { &mp_const_type }, + { &mp_type_type }, .name = MP_QSTR_generator, .print = gen_instance_print, .getiter = gen_instance_getiter, |