39 #define TRACE(ip) printf("sp=%d ", (int)(sp - &code_state->state[0] + 1)); mp_bytecode_print2(ip, 1, code_state->fun_bc->const_table); 62 unum = (unum << 7) + (*ip & 0x7f); \ 63 } while ((*ip++ & 0x80) != 0) 64 #define DECODE_ULABEL size_t ulab = (ip[0] | (ip[1] << 8)); ip += 2 65 #define DECODE_SLABEL size_t slab = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2 67 #if MICROPY_PERSISTENT_CODE 70 qstr qst = ip[0] | ip[1] << 8; \ 74 void *ptr = (void*)(uintptr_t)code_state->fun_bc->const_table[unum] 77 mp_obj_t obj = (mp_obj_t)code_state->fun_bc->const_table[unum] 81 #define DECODE_QSTR qstr qst = 0; \ 83 qst = (qst << 7) + (*ip & 0x7f); \ 84 } while ((*ip++ & 0x80) != 0) 86 ip = (byte*)MP_ALIGN(ip, sizeof(void*)); \ 87 void *ptr = *(void**)ip; \ 90 ip = (byte*)MP_ALIGN(ip, sizeof(mp_obj_t)); \ 91 mp_obj_t obj = *(mp_obj_t*)ip; \ 92 ip += sizeof(mp_obj_t) 96 #define PUSH(val) *++sp = (val) 99 #define SET_TOP(val) *sp = (val) 101 #if MICROPY_PY_SYS_EXC_INFO 102 #define CLEAR_SYS_EXC_INFO() MP_STATE_VM(cur_exception) = NULL; 104 #define CLEAR_SYS_EXC_INFO() 107 #define PUSH_EXC_BLOCK(with_or_finally) do { \ 110 exc_sp->handler = ip + ulab; \ 111 exc_sp->val_sp = MP_TAGPTR_MAKE(sp, ((with_or_finally) << 1) | currently_in_except_block); \ 112 exc_sp->prev_exc = NULL; \ 113 currently_in_except_block = 0; \ 116 #define POP_EXC_BLOCK() \ 117 currently_in_except_block = MP_TAGPTR_TAG0(exc_sp->val_sp); \ 128 #define SELECTIVE_EXC_IP (0) 130 #define MARK_EXC_IP_SELECTIVE() { code_state->ip = ip; } 131 #define MARK_EXC_IP_GLOBAL() 133 #define MARK_EXC_IP_SELECTIVE() 134 #define MARK_EXC_IP_GLOBAL() { code_state->ip = ip; } 136 #if MICROPY_OPT_COMPUTED_GOTO 138 #define DISPATCH() do { \ 140 MARK_EXC_IP_GLOBAL(); \ 141 goto *entry_table[*ip++]; \ 143 #define DISPATCH_WITH_PEND_EXC_CHECK() goto pending_exception_check 144 #define ENTRY(op) entry_##op 145 #define ENTRY_DEFAULT entry_default 147 #define DISPATCH() break 148 #define DISPATCH_WITH_PEND_EXC_CHECK() goto pending_exception_check 149 #define ENTRY(op) case op 150 #define ENTRY_DEFAULT default 157 #define RAISE(o) do { nlr_pop(); nlr.ret_val = MP_OBJ_TO_PTR(o); goto exception_handler; } while (0) 159 #if MICROPY_STACKLESS 167 fastn = &code_state->
state[n_state - 1];
175 #if MICROPY_PY_THREAD_GIL && MICROPY_PY_THREAD_GIL_VM_DIVISOR 187 const byte *ip = code_state->
ip;
207 #if MICROPY_OPT_COMPUTED_GOTO 229 if ((ip[0] & 0x40) != 0) {
234 num = (num << 7) | (*ip & 0x7f);
235 }
while ((*ip++ & 0x80) != 0);
258 obj_shared = fastn[-unum];
277 #if !MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE 290 if (x < mp_locals_get()->map.alloc && mp_locals_get()->map.table[x].key == key) {
291 PUSH(mp_locals_get()->map.table[x].value);
295 *(
byte*)ip = (elem - &mp_locals_get()->map.table[0]) & 0xff;
306 #if !MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE 319 if (x < mp_globals_get()->map.alloc && mp_globals_get()->map.table[x].key == key) {
320 PUSH(mp_globals_get()->map.table[x].value);
324 *(
byte*)ip = (elem - &mp_globals_get()->map.table[0]) & 0xff;
335 #if !MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE 352 if (x < self->members.alloc && self->members.table[x].key == key) {
353 elem = &
self->members.table[x];
357 *(
byte*)ip = elem - &self->members.table[0];
359 goto load_attr_cache_fail;
366 load_attr_cache_fail:
403 fastn[-unum] =
POP();
427 #if !MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE 450 if (x < self->members.alloc && self->members.table[x].key == key) {
451 elem = &
self->members.table[x];
455 *(
byte*)ip = elem - &self->members.table[0];
457 goto store_attr_cache_fail;
460 elem->
value = sp[-1];
465 store_attr_cache_fail:
483 goto local_name_error;
493 goto local_name_error;
615 }
else if (MP_OBJ_IS_SMALL_INT(
TOP())) {
655 assert(exc_sp >= exc_stack);
673 while ((unum & 0x7f) > 0) {
675 assert(exc_sp >= exc_stack);
720 }
else if (MP_OBJ_IS_SMALL_INT(
TOP())) {
782 assert(exc_sp >= exc_stack);
788 assert(exc_sp >= exc_stack);
789 assert(currently_in_except_block);
822 #if MICROPY_PY_BUILTINS_SET 832 #if MICROPY_PY_BUILTINS_SLICE 854 if ((unum & 3) == 0) {
860 #if MICROPY_PY_BUILTINS_SET 881 sp += (unum & 0xff) + ((unum >> 8) & 0xff);
901 size_t n_closed_over = *ip++;
903 sp -= n_closed_over - 1;
910 size_t n_closed_over = *ip++;
912 sp -= 2 + n_closed_over - 1;
922 sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe);
923 #if MICROPY_STACKLESS 930 new_state->prev = code_state;
931 code_state = new_state;
935 #if MICROPY_STACKLESS_STRICT 937 deep_recursion_error:
954 sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 2;
955 #if MICROPY_STACKLESS 968 new_state->prev = code_state;
969 code_state = new_state;
973 #if MICROPY_STACKLESS_STRICT 975 goto deep_recursion_error;
989 sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 1;
990 #if MICROPY_STACKLESS 996 size_t n_args = unum & 0xff;
997 size_t n_kw = (unum >> 8) & 0xff;
1002 new_state->prev = code_state;
1003 code_state = new_state;
1005 goto run_code_state;
1007 #if MICROPY_STACKLESS_STRICT 1009 goto deep_recursion_error;
1025 sp -= (unum & 0xff) + ((unum >> 7) & 0x1fe) + 3;
1026 #if MICROPY_STACKLESS 1028 code_state->
ip = ip;
1029 code_state->
sp = sp;
1039 new_state->prev = code_state;
1040 code_state = new_state;
1042 goto run_code_state;
1044 #if MICROPY_STACKLESS_STRICT 1046 goto deep_recursion_error;
1062 if (currently_in_except_block) {
1066 while (exc_sp >= exc_stack) {
1078 finally_sp[1] = sp[0];
1079 sp = &finally_sp[1];
1092 code_state->
sp = sp;
1093 assert(exc_sp == exc_stack - 1);
1095 #if MICROPY_STACKLESS 1096 if (code_state->prev !=
NULL) {
1099 code_state = code_state->prev;
1100 *code_state->
sp = res;
1101 goto run_code_state;
1111 mp_warning(
"exception chaining not supported");
1119 if (e->prev_exc !=
NULL) {
1138 code_state->
ip = ip;
1139 code_state->
sp = sp;
1146 #define EXC_MATCH(exc, type) mp_obj_exception_match(exc, type) 1147 #define GENERATOR_EXIT_IF_NEEDED(t) if (t != MP_OBJ_NULL && EXC_MATCH(t, MP_OBJ_FROM_PTR(&mp_type_GeneratorExit))) { RAISE(t); } 1217 #if MICROPY_OPT_COMPUTED_GOTO 1273 #if !MICROPY_OPT_COMPUTED_GOTO 1277 pending_exception_check:
1280 #if MICROPY_ENABLE_SCHEDULER 1288 if (!mp_sched_num_pending()) {
1306 #if MICROPY_PY_THREAD_GIL 1307 #if MICROPY_PY_THREAD_GIL_VM_DIVISOR 1308 if (--gil_divisor == 0) {
1313 #if MICROPY_ENABLE_SCHEDULER 1330 #if MICROPY_PY_SYS_EXC_INFO 1334 #if SELECTIVE_EXC_IP 1336 code_state->
ip -= 1;
1340 if (code_state->
ip) {
1343 const byte *ip = code_state->
ip + 1;
1345 code_state->
ip = ip + ulab;
1347 goto outer_dispatch_loop;
1353 goto outer_dispatch_loop;
1358 #if MICROPY_STACKLESS 1373 size_t bc = code_state->
ip - ip;
1376 bc -= code_info_size;
1377 #if MICROPY_PERSISTENT_CODE 1378 qstr block_name = ip[0] | (ip[1] << 8);
1379 qstr source_file = ip[2] | (ip[3] << 8);
1387 size_t source_line = 1;
1391 if ((
c & 0x80) == 0) {
1399 l = ((
c << 4) & 0x700) | ip[1];
1413 while (currently_in_except_block) {
1416 assert(exc_sp >= exc_stack);
1425 if (exc_sp >= exc_stack) {
1427 currently_in_except_block = 1;
1436 code_state->
sp = sp;
1438 #if MICROPY_STACKLESS 1439 }
else if (code_state->prev !=
NULL) {
1441 code_state = code_state->prev;
1443 fastn = &code_state->
state[n_state - 1];
#define MP_BC_CALL_FUNCTION_VAR_KW
#define MP_BC_LOAD_CONST_FALSE
#define MP_BC_BUILD_TUPLE
const mp_obj_type_t mp_type_fun_bc
const struct _mp_obj_exception_t mp_const_MemoryError_obj
mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg)
mp_obj_dict_t * old_globals
#define MARK_EXC_IP_SELECTIVE()
bool mp_obj_is_exception_instance(mp_obj_t self_in)
mp_obj_t mp_obj_new_slice(mp_obj_t start, mp_obj_t stop, mp_obj_t step)
#define MP_BC_RAISE_VARARGS
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items)
#define MP_BC_GET_ITER_STACK
#define MP_BC_UNARY_OP_MULTI
#define MP_BC_IMPORT_FROM
#define MP_BC_LOAD_SUPER_METHOD
mp_obj_t mp_import_from(mp_obj_t module, qstr name)
STATIC const uint8_t attr[]
#define MP_BC_BINARY_OP_MULTI
#define m_del(type, ptr, num)
#define MP_BC_LOAD_CONST_SMALL_INT_MULTI
void mp_load_super_method(qstr attr, mp_obj_t *dest)
void mp_unpack_sequence(mp_obj_t seq_in, size_t num, mp_obj_t *items)
#define MP_OBJ_QSTR_VALUE(o)
const mp_obj_type_t mp_type_StopIteration
void mp_delete_global(qstr qst)
#define MP_BC_DUP_TOP_TWO
#define MP_BC_LOAD_CONST_NONE
#define EXC_MATCH(exc, type)
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
const mp_obj_type_t mp_type_NotImplementedError
#define MP_BC_LOAD_BUILD_CLASS
#define MP_OBJ_FROM_PTR(p)
#define MP_BC_IMPORT_NAME
#define MP_OBJ_NEW_QSTR(qst)
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr)
#define MP_BC_MAKE_FUNCTION_DEFARGS
#define MP_BC_MAKE_CLOSURE_DEFARGS
#define MP_BC_LOAD_CONST_TRUE
#define MP_BC_DELETE_DEREF
mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items)
#define MICROPY_VM_HOOK_INIT
#define MP_BC_CALL_METHOD_VAR_KW
#define MP_BC_CALL_FUNCTION
mp_obj_t mp_load_global(qstr qst)
#define MP_BC_POP_JUMP_IF_FALSE
#define MP_BC_BUILD_SLICE
#define MP_OBJ_SMALL_INT_VALUE(o)
#define MP_BC_DELETE_NAME
#define MP_BC_JUMP_IF_TRUE_OR_POP
#define MP_BC_LOAD_GLOBAL
#define MP_BC_MAKE_CLOSURE
mp_obj_t mp_obj_new_dict(size_t n_args)
const mp_obj_type_t mp_type_NameError
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo)
void mp_store_name(qstr qst, mp_obj_t obj)
NORETURN void mp_exc_recursion_depth(void)
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest)
mp_map_elem_t * mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind)
#define MICROPY_PY_BUILTINS_SET
#define MP_BC_DELETE_GLOBAL
#define MP_BC_UNPACK_SEQUENCE
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg)
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg)
mp_obj_t mp_load_name(qstr qst)
#define MP_BC_STORE_GLOBAL
#define MP_OBJ_NEW_SMALL_INT(small_int)
#define MICROPY_BEGIN_ATOMIC_SECTION()
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item)
#define GENERATOR_EXIT_IF_NEEDED(t)
#define MP_TAGPTR_TAG0(x)
#define MICROPY_PY_THREAD_GIL_VM_DIVISOR
#define MP_OBJ_ITER_BUF_NSLOTS
#define MP_BC_DELETE_FAST
#define MP_BC_LOAD_SUBSCR
#define MICROPY_VM_HOOK_LOOP
mp_obj_t mp_make_closure_from_raw_code(const mp_raw_code_t *rc, mp_uint_t n_closed_over, const mp_obj_t *args)
mp_uint_t mp_decode_uint_value(const byte *ptr)
mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_args, mp_obj_t def_kw_args)
mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs)
#define MP_BC_UNWIND_JUMP
mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items)
#define MP_BC_LOAD_CONST_OBJ
#define DISPATCH_WITH_PEND_EXC_CHECK()
#define MP_BC_CALL_METHOD
mp_obj_t mp_load_build_class(void)
#define MARK_EXC_IP_GLOBAL()
#define MP_BC_JUMP_IF_FALSE_OR_POP
mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in)
#define MP_TAGPTR_TAG1(x)
mp_obj_t mp_call_method_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args)
#define MICROPY_VM_HOOK_RETURN
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block)
#define MP_BC_WITH_CLEANUP
#define PUSH_EXC_BLOCK(with_or_finally)
#define MP_BC_SETUP_EXCEPT
#define MP_BC_LOAD_METHOD
#define MP_BC_LOAD_CONST_SMALL_INT
mp_code_state_t * mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, size_t n_kw, const mp_obj_t *args)
mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args)
#define MP_BC_LOAD_FAST_MULTI
void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj)
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value)
#define MP_BC_STORE_FAST_MULTI
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in)
STATIC void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args, mp_call_args_t *out_args)
mp_obj_t mp_make_raise_obj(mp_obj_t o)
#define MP_BC_MAKE_FUNCTION
#define MP_BC_END_FINALLY
#define MP_THREAD_GIL_EXIT()
void mp_unpack_ex(mp_obj_t seq_in, size_t num_in, mp_obj_t *items)
#define MP_BC_STORE_FAST_N
mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level)
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf)
void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value)
#define MICROPY_END_ATOMIC_SECTION(state)
mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val)
#define MP_BC_STORE_SUBSCR
#define MP_OBJ_STOP_ITERATION
#define MP_BC_SETUP_FINALLY
void mp_handle_pending_tail(mp_uint_t atomic_state)
const byte * mp_decode_uint_skip(const byte *ptr)
#define MP_THREAD_GIL_ENTER()
#define MP_BC_LOAD_CONST_STRING
mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp_obj_t inject_exc)
#define MP_BC_RETURN_VALUE
#define MP_BC_POP_JUMP_IF_TRUE
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value)
#define MP_BC_STORE_DEREF
#define MP_TAGPTR_MAKE(ptr, tag)
void mp_delete_name(qstr qst)
void mp_store_global(qstr qst, mp_obj_t obj)
#define MP_BC_IMPORT_STAR
#define MP_BC_YIELD_VALUE
void mp_import_all(mp_obj_t module)
bool mp_obj_is_true(mp_obj_t arg)
mp_obj_t mp_obj_cell_get(mp_obj_t self_in)
void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
const mp_obj_type_t mp_type_RuntimeError
#define MP_BC_LOAD_FAST_N
const struct _mp_obj_exception_t mp_const_GeneratorExit_obj