Skip to content

Commit 4fff26a

Browse files
committed
vm: Factor out exception block setup to a macro.
Will be reused in WITH bytecodes.
1 parent c47fd2d commit 4fff26a

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

py/vm.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ typedef enum {
4444
#define TOP() (*sp)
4545
#define SET_TOP(val) *sp = (val)
4646

47+
#define SETUP_BLOCK() \
48+
DECODE_ULABEL; /* except labels are always forward */ \
49+
++exc_sp; \
50+
exc_sp->opcode = op; \
51+
exc_sp->handler = ip + unum; \
52+
exc_sp->val_sp = MP_TAGPTR_MAKE(sp, currently_in_except_block); \
53+
currently_in_except_block = 0; /* in a try block now */
54+
4755
mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, const mp_obj_t *args2, uint n_args2, mp_obj_t *ret) {
4856
const byte *ip = code;
4957

@@ -398,12 +406,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
398406
// matched against: POP_BLOCK or POP_EXCEPT (anything else?)
399407
case MP_BC_SETUP_EXCEPT:
400408
case MP_BC_SETUP_FINALLY:
401-
DECODE_ULABEL; // except labels are always forward
402-
++exc_sp;
403-
exc_sp->opcode = op;
404-
exc_sp->handler = ip + unum;
405-
exc_sp->val_sp = MP_TAGPTR_MAKE(sp, currently_in_except_block);
406-
currently_in_except_block = 0; // in a try block now
409+
SETUP_BLOCK();
407410
break;
408411

409412
case MP_BC_END_FINALLY:

0 commit comments

Comments
 (0)