diff options
-rw-r--r-- | py/objexcept.c | 4 | ||||
-rw-r--r-- | py/showbc.c | 20 | ||||
-rw-r--r-- | tests/basics/int-small.py | 2 | ||||
-rw-r--r-- | tests/basics/try2.py | 17 |
4 files changed, 40 insertions, 3 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index 8eb4e966e9..386e727636 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -12,8 +12,8 @@ #include "objtuple.h" // This is unified class for C-level and Python-level exceptions -// Python-level exception have empty ->msg and all arguments are in -// args tuple. C-level excepttion likely have ->msg and args is empty. +// Python-level exceptions have empty ->msg and all arguments are in +// args tuple. C-level exceptions likely have ->msg set, and args is empty. typedef struct mp_obj_exception_t { mp_obj_base_t base; mp_obj_t traceback; // a list object, holding (file,line,block) as numbers (not Python objects); a hack for now diff --git a/py/showbc.c b/py/showbc.c index d7ae17c2e3..8a12302531 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -215,11 +215,31 @@ void mp_byte_code_print(const byte *ip, int len) { printf("JUMP_IF_FALSE_OR_POP " UINT_FMT, ip + unum - ip_start); break; + case MP_BC_SETUP_LOOP: + DECODE_ULABEL; // loop labels are always forward + printf("SETUP_LOOP " UINT_FMT, ip + unum - ip_start); + break; + + case MP_BC_BREAK_LOOP: + DECODE_ULABEL; // loop labels are always forward + printf("BREAK_LOOP " UINT_FMT, ip + unum - ip_start); + break; + + case MP_BC_CONTINUE_LOOP: + DECODE_ULABEL; // loop labels are always forward + printf("CONTINUE_LOOP " UINT_FMT, ip + unum - ip_start); + break; + case MP_BC_SETUP_EXCEPT: DECODE_ULABEL; // except labels are always forward printf("SETUP_EXCEPT " UINT_FMT, ip + unum - ip_start); break; + case MP_BC_SETUP_FINALLY: + DECODE_ULABEL; // except labels are always forward + printf("SETUP_FINALLY " UINT_FMT, ip + unum - ip_start); + break; + case MP_BC_END_FINALLY: // if TOS is an exception, reraises the exception (3 values on TOS) // if TOS is an integer, does something else diff --git a/tests/basics/int-small.py b/tests/basics/int-small.py index be338c4a4c..53902c7e39 100644 --- a/tests/basics/int-small.py +++ b/tests/basics/int-small.py @@ -1,4 +1,4 @@ -# This test small int range for 32-bit machine +# This tests small int range for 32-bit machine a = 0x3fffff print(a) diff --git a/tests/basics/try2.py b/tests/basics/try2.py index 5cd74bec4b..5827699e90 100644 --- a/tests/basics/try2.py +++ b/tests/basics/try2.py @@ -21,3 +21,20 @@ try: bar() except NameError: print("except 1") + +# Check that exceptions across function boundaries work as expected +def func1(): + try: + print("try func1") + func2() + except NameError: + print("except func1") + +def func2(): + try: + print("try func2") + foo() + except TypeError: + print("except func2") + +func1() |