diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-03-23 21:48:29 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-03-26 15:40:58 +0200 |
commit | 962b1cd1b120d777636ce8195d14f3d686e96619 (patch) | |
tree | ba8b703fb70d32457e8f2cbeb176ec7b822cfa9f /py/objexcept.c | |
parent | 4b2b7ceca7915d014a191d3776bc29bdbc5faf02 (diff) | |
download | micropython-962b1cd1b120d777636ce8195d14f3d686e96619.tar.gz micropython-962b1cd1b120d777636ce8195d14f3d686e96619.zip |
objgenerator: Implement return with value and .close() method.
Return with value gets converted to StopIteration(value). Implementation
keeps optimizing against creating of possibly unneeded exception objects,
so there're considerable refactoring to implement these features.
Diffstat (limited to 'py/objexcept.c')
-rw-r--r-- | py/objexcept.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index de9bf1694f..f96523ed23 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -8,6 +8,8 @@ #include "qstr.h" #include "obj.h" #include "objtuple.h" +#include "runtime.h" +#include "runtime0.h" // This is unified class for C-level and Python-level exceptions // Python-level exceptions have empty ->msg and all arguments are in @@ -156,6 +158,11 @@ mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type) { return mp_obj_new_exception_msg_varg(exc_type, NULL); } +mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, uint n_args, const mp_obj_t *args) { + assert(exc_type->make_new == mp_obj_exception_make_new); + return exc_type->make_new((mp_obj_t)exc_type, n_args, 0, args); +} + mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg) { return mp_obj_new_exception_msg_varg(exc_type, msg); } @@ -202,6 +209,13 @@ bool mp_obj_is_exception_instance(mp_obj_t self_in) { return mp_obj_get_type(self_in)->make_new == mp_obj_exception_make_new; } +// return true if exception (type or instance) is a subclass of given +// exception type. +bool mp_obj_exception_match(mp_obj_t exc, const mp_obj_type_t *exc_type) { + // TODO: move implementation from RT_BINARY_OP_EXCEPTION_MATCH here. + return rt_binary_op(RT_BINARY_OP_EXCEPTION_MATCH, exc, (mp_obj_t)exc_type) == mp_const_true; +} + void mp_obj_exception_clear_traceback(mp_obj_t self_in) { // make sure self_in is an exception instance assert(mp_obj_get_type(self_in)->make_new == mp_obj_exception_make_new); |