44 #if MICROPY_DEBUG_VERBOSE // print debugging info 45 #define DEBUG_PRINT (1) 46 #define DEBUG_printf DEBUG_printf 47 #define DEBUG_OP_printf(...) DEBUG_printf(__VA_ARGS__) 48 #else // don't print debugging info 49 #define DEBUG_printf(...) (void)0 50 #define DEBUG_OP_printf(...) (void)0 63 #if MICROPY_ENABLE_SCHEDULER 68 #if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF 72 #if MICROPY_KBD_EXCEPTION 82 #ifdef MICROPY_PORT_INIT_FUNC 83 MICROPY_PORT_INIT_FUNC;
100 #if MICROPY_CAN_OVERRIDE_BUILTINS 105 #if MICROPY_PY_OS_DUPTERM 106 for (
size_t i = 0; i < MICROPY_PY_OS_DUPTERM; ++i) {
112 #if MICROPY_FSUSERMOUNT 123 #if MICROPY_PY_THREAD_GIL 135 #ifdef MICROPY_PORT_INIT_FUNC 136 MICROPY_PORT_DEINIT_FUNC;
144 if (mp_locals_get() != mp_globals_get()) {
158 #if MICROPY_CAN_OVERRIDE_BUILTINS 173 "name '%q' is not defined", qst));
182 #if MICROPY_CAN_OVERRIDE_BUILTINS 222 }
else if (MP_OBJ_IS_SMALL_INT(arg)) {
226 return mp_obj_new_bool(val != 0);
271 "unsupported type for %q: '%s'",
291 return mp_obj_new_bool(lhs == rhs);
322 for (
size_t i = 0; i < tuple->
len; i++) {
323 rhs = tuple->
items[i];
336 if (MP_OBJ_IS_SMALL_INT(lhs)) {
338 if (MP_OBJ_IS_SMALL_INT(rhs)) {
364 goto generic_binary_op;
398 long long res = (
long long)lhs_val * (
long long)rhs_val;
411 goto generic_binary_op;
426 #if MICROPY_PY_BUILTINS_FLOAT 432 return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val);
447 #if MICROPY_PY_BUILTINS_FLOAT 448 lhs = mp_obj_new_float(lhs_val);
449 goto generic_binary_op;
455 while (rhs_val > 0) {
478 goto generic_binary_op;
505 #if MICROPY_PY_BUILTINS_FLOAT 507 mp_obj_t res = mp_obj_float_binary_op(op, lhs_val, rhs);
513 #if MICROPY_PY_BUILTINS_COMPLEX 515 mp_obj_t res = mp_obj_complex_binary_op(op, lhs_val, 0, rhs);
571 #if MICROPY_PY_REVERSE_SPECIAL_METHODS 578 goto generic_binary_op;
591 "unsupported types for %q: '%s', '%s'",
626 return type->
call(fun_in, n_args, n_kw,
args);
646 #if !MICROPY_STACKLESS 655 uint n_args = n_args_n_kw & 0xff;
656 uint n_kw = (n_args_n_kw >> 8) & 0xff;
660 DEBUG_OP_printf(
"call method var (fun=%p, self=%p, n_args=%u, n_kw=%u, args=%p, seq=%p, dict=%p)\n", fun,
self, n_args, n_kw,
args, pos_seq, kw_dict);
672 uint kw_dict_len = 0;
683 args2_alloc = 1 + n_args + 2 * (n_kw + kw_dict_len);
688 args2[args2_len++] =
self;
704 args2_alloc = 1 + n_args + len + 2 * (n_kw + kw_dict_len);
709 args2[args2_len++] =
self;
714 args2_len += n_args + len;
720 args2_alloc = 1 + n_args + 2 * (n_kw + kw_dict_len) + 3;
725 args2[args2_len++] =
self;
737 if (args2_len >= args2_alloc) {
741 args2[args2_len++] = item;
746 uint pos_args_len = args2_len;
750 args2_len += 2 * n_kw;
759 assert(args2_len + 2 * map->
used <= args2_alloc);
760 for (
size_t i = 0; i < map->
alloc; i++) {
761 if (MP_MAP_SLOT_IS_FILLED(map, i)) {
767 args2[args2_len++] = key;
784 if (args2_len + 1 >= args2_alloc) {
785 uint new_alloc = args2_alloc * 2;
790 args2_alloc = new_alloc;
804 args2[args2_len++] = key;
805 args2[args2_len++] = value;
810 out_args->
args = args2;
811 out_args->
n_args = pos_args_len;
812 out_args->
n_kw = (args2_len - pos_args_len) / 2;
813 out_args->
n_alloc = args2_alloc;
834 }
else if (seq_len > num) {
837 for (
size_t i = 0; i < num; i++) {
838 items[i] = seq_items[num - 1 - i];
844 for (seq_len = 0; seq_len < num; seq_len++) {
849 items[num - 1 - seq_len] = el;
862 "need more than %d values to unpack", (
int)seq_len));
869 "too many values to unpack (expected %d)", (
int)num));
875 size_t num_left = num_in & 0xff;
876 size_t num_right = (num_in >> 8) & 0xff;
882 if (seq_len < num_left + num_right) {
885 for (
size_t i = 0; i < num_right; i++) {
886 items[i] = seq_items[seq_len - 1 - i];
888 items[num_right] =
mp_obj_new_list(seq_len - num_left - num_right, seq_items + num_left);
889 for (
size_t i = 0; i < num_left; i++) {
890 items[num_right + 1 + i] = seq_items[num_left - 1 - i];
899 for (seq_len = 0; seq_len < num_left; seq_len++) {
904 items[num_left + num_right + 1 - 1 - seq_len] = item;
910 if (rest->
len < num_right) {
914 for (
size_t i = 0; i < num_right; i++) {
915 items[num_right - 1 - i] = rest->
items[rest->
len - num_right + i];
926 "need more than %d values to unpack", (
int)seq_len));
944 #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG 950 typedef struct _mp_obj_checked_fun_t {
954 } mp_obj_checked_fun_t;
960 if (arg0_type != self->type) {
965 "argument should be a '%q' not a '%q'", self->type->
name, arg0_type->
name));
974 .
name = MP_QSTR_function,
975 .call = checked_fun_call,
979 mp_obj_checked_fun_t *o =
m_new_obj(mp_obj_checked_fun_t);
980 o->base.type = &mp_type_checked_fun;
986 #endif // MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG 1009 || (MP_OBJ_IS_OBJ(member)
1013 #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG 1023 dest[0] = mp_obj_new_checked_fun(type, member);
1050 #if MICROPY_CPYTHON_COMPAT 1051 }
else if (
attr == MP_QSTR___class__) {
1089 "type object '%q' has no attribute '%q'",
1093 "'%s' object has no attribute '%q'",
1115 "'%s' object has no attribute '%q'",
1131 if (iter_buf ==
NULL) {
1264 dest[2] = send_value;
1287 dest[2] = throw_value;
1299 *ret_val = throw_value;
1359 size_t pkg_name_len;
1362 const uint dot_name_len = pkg_name_len + 1 +
qstr_len(name);
1363 char *dot_name =
alloca(dot_name_len);
1364 memcpy(dot_name, pkg_name, pkg_name_len);
1365 dot_name[pkg_name_len] =
'.';
1385 for (
size_t i = 0; i < map->
alloc; i++) {
1386 if (MP_MAP_SLOT_IS_FILLED(map, i)) {
1395 #if MICROPY_ENABLE_COMPILER 1404 mp_globals_set(globals);
1405 mp_locals_set(locals);
1424 mp_globals_set(old_globals);
1425 mp_locals_set(old_locals);
1429 mp_globals_set(old_globals);
1430 mp_locals_set(old_locals);
1435 #endif // MICROPY_ENABLE_COMPILER 1438 DEBUG_printf(
"memory allocation failed, allocating %u bytes\n", (
uint)num_bytes);
1439 #if MICROPY_ENABLE_GC 1445 "memory allocation failed, allocating %u bytes", (
uint)num_bytes));
mp_map_t * mp_obj_dict_get_map(mp_obj_t self_in)
const mp_obj_dict_t mp_module_builtins_globals
const mp_obj_type_t mp_type_fun_builtin_var
mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg)
qstr qstr_from_strn(const char *str, size_t len)
bool mp_obj_is_exception_instance(mp_obj_t self_in)
const mp_obj_type_t mp_type_KeyboardInterrupt
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
void * memset(void *b, int c, size_t len)
mp_int_t mp_small_int_modulo(mp_int_t dividend, mp_int_t divisor)
const char * qstr_str(qstr q)
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items)
void mp_load_method_maybe(mp_obj_t obj, qstr attr, mp_obj_t *dest)
#define MICROPY_ERROR_REPORTING_TERSE
NORETURN void mp_raise_NotImplementedError(const char *msg)
const mp_obj_type_t mp_type_ZeroDivisionError
size_t mp_obj_dict_len(mp_obj_t self_in)
const mp_obj_type_t mp_type_TypeError
mp_obj_t mp_import_from(mp_obj_t module, qstr name)
mp_unary_op_fun_t unary_op
mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2)
#define MP_OBJ_IS_TYPE(o, t)
STATIC const uint8_t attr[]
#define m_del(type, ptr, num)
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt,...)
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type)
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)
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
#define DEBUG_printf(...)
const mp_obj_type_t mp_type_NotImplementedError
#define MP_OBJ_FROM_PTR(p)
mp_binary_op_fun_t binary_op
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2)
#define MP_OBJ_NEW_QSTR(qst)
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr)
const mp_obj_type_t mp_type_ImportError
#define MICROPY_ERROR_REPORTING_DETAILED
mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items)
const mp_obj_type_t mp_type_gen_instance
mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val)
bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y)
mp_obj_t mp_obj_new_int_from_ll(long long val)
mp_obj_dict_t * mp_obj_module_get_globals(mp_obj_t self_in)
mp_obj_t mp_call_function_0(mp_obj_t fun)
mp_obj_t mp_load_global(qstr qst)
mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_input_kind, mp_obj_dict_t *globals, mp_obj_dict_t *locals)
#define MP_OBJ_SMALL_INT_VALUE(o)
const mp_obj_type_t mp_type_NameError
mp_int_t mp_small_int_floor_divide(mp_int_t num, mp_int_t denom)
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)
#define mp_obj_is_float(o)
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)
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg)
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items)
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg)
void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args)
mp_obj_t mp_load_name(qstr qst)
const mp_obj_type_t mp_type_complex
mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args)
#define MP_OBJ_NEW_SMALL_INT(small_int)
#define MICROPY_ERROR_REPORTING
const mp_obj_type_t mp_type_staticmethod
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg)
const mp_obj_type_t mp_type_fun_builtin_2
bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type)
const char * mp_obj_str_get_data(mp_obj_t self_in, size_t *len)
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl)
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg)
const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME]
const mp_obj_type_t mp_type_OSError
#define MP_SMALL_INT_FITS(n)
NORETURN void mp_raise_OSError(int errno_)
void mp_init_emergency_exception_buf(void)
mp_obj_t mp_obj_str_intern(mp_obj_t str)
bool mp_obj_is_package(mp_obj_t module)
const mp_obj_type_t mp_type_str
mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs)
const mp_obj_type_t mp_type_ValueError
const mp_obj_type_t mp_type_MemoryError
mp_obj_t mp_load_build_class(void)
const mp_obj_type_t mp_type_GeneratorExit
mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in)
const mp_obj_type_t mp_type_fun_builtin_0
mp_obj_t mp_call_method_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args)
mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key)
mp_obj_t mp_obj_new_int(mp_int_t value)
NORETURN void m_malloc_fail(size_t num_bytes)
#define MICROPY_PY_BUILTINS_COMPILE
const mp_obj_type_t mp_type_type
const mp_obj_type_t mp_type_AttributeError
const mp_obj_module_t mp_module___main__
#define m_renew(type, ptr, old_num, new_num)
mp_parse_tree_t mp_parse(struct _mp_lexer_t *lex, mp_parse_input_kind_t input_kind)
mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args)
NORETURN void mp_raise_ValueError(const char *msg)
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value)
mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf)
mp_uint_t qstr_compute_hash(const byte *data, size_t len)
mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self)
#define mp_seq_copy(dest, src, len, item_t)
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)
void mp_convert_member_lookup(mp_obj_t self, const mp_obj_type_t *type, mp_obj_t member, mp_obj_t *dest)
const mp_obj_type_t mp_type_tuple
const mp_obj_type_t mp_type_dict
void mp_unpack_ex(mp_obj_t seq_in, size_t num_in, mp_obj_t *items)
const mp_obj_type_t mp_type_module
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)
const char * mp_obj_get_type_str(mp_const_obj_t o_in)
void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value)
void mp_obj_list_set_len(mp_obj_t self_in, size_t len)
bool mp_obj_is_exception_type(mp_obj_t self_in)
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)
const mp_obj_type_t mp_type_classmethod
#define MP_OBJ_STOP_ITERATION
mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args, mp_obj_iter_buf_t *iter_buf)
const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME]
#define MP_THREAD_GIL_ENTER()
mp_obj_t mp_iternext(mp_obj_t o_in)
const mp_obj_type_t mp_type_fun_builtin_3
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)
const mp_obj_type_t mp_type_fun_builtin_1
void mp_delete_name(qstr qst)
void mp_store_global(qstr qst, mp_obj_t obj)
NORETURN void mp_raise_TypeError(const char *msg)
#define MP_OBJ_IS_STR_OR_BYTES(o)
#define DEBUG_OP_printf(...)
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len)
const mp_obj_type_t mp_type_list
void mp_import_all(mp_obj_t module)
bool mp_obj_is_true(mp_obj_t arg)
#define GET_STR_HASH(str_obj_in, str_hash)
void * memcpy(void *dst, const void *src, size_t n)
const struct _mp_obj_tuple_t mp_const_empty_tuple_obj
struct _mp_obj_dict_t * locals_dict
#define mp_seq_cat(dest, src1, len1, src2, len2, item_t)