@@ -325,12 +325,19 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob
325
325
break ;
326
326
327
327
case MP_BC_END_FINALLY :
328
- // not implemented
328
+ // not fully implemented
329
329
// if TOS is an exception, reraises the exception (3 values on TOS)
330
- // if TOS is an integer, does something else
331
330
// if TOS is None, just pops it and continues
331
+ // if TOS is an integer, does something else
332
332
// else error
333
- assert (0 );
333
+ if (MP_OBJ_IS_TYPE (TOP (), & exception_type )) {
334
+ nlr_jump (TOP ());
335
+ }
336
+ if (TOP () == mp_const_none ) {
337
+ sp -- ;
338
+ } else {
339
+ assert (0 );
340
+ }
334
341
break ;
335
342
336
343
case MP_BC_GET_ITER :
@@ -361,6 +368,7 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob
361
368
// TODO need to work out how blocks work etc
362
369
// pops block, checks it's an exception block, and restores the stack, saving the 3 exception values to local threadstate
363
370
assert (exc_sp >= & exc_stack [0 ]);
371
+ assert (currently_in_except_block );
364
372
//sp = (mp_obj_t*)(*exc_sp--);
365
373
//exc_sp--; // discard ip
366
374
currently_in_except_block = (exc_sp [0 ] & 1 ); // restore previous state
@@ -517,6 +525,8 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob
517
525
// exception occurred
518
526
519
527
// set file and line number that the exception occurred at
528
+ // TODO: don't set traceback for exceptions re-raised by END_FINALLY.
529
+ // But consider how to handle nested exceptions.
520
530
if (MP_OBJ_IS_TYPE (nlr .ret_val , & exception_type )) {
521
531
machine_uint_t code_info_size = code_info [0 ] | (code_info [1 ] << 8 ) | (code_info [2 ] << 16 ) | (code_info [3 ] << 24 );
522
532
qstr source_file = code_info [4 ] | (code_info [5 ] << 8 ) | (code_info [6 ] << 16 ) | (code_info [7 ] << 24 );
0 commit comments