37 #if MICROPY_DEBUG_VERBOSE // print debugging info 38 #define DEBUG_PRINT (1) 39 #else // don't print debugging info 40 #define DEBUG_PRINT (0) 41 #define DEBUG_printf(...) (void)0 56 return self->fun._0();
61 .
name = MP_QSTR_function,
70 return self->fun._1(
args[0]);
75 .
name = MP_QSTR_function,
84 return self->fun._2(
args[0],
args[1]);
89 .
name = MP_QSTR_function,
103 .
name = MP_QSTR_function,
113 mp_arg_check_num(n_args, n_kw, self->n_args_min, self->n_args_max, self->is_kw);
122 return self->fun.kw(n_args,
args, &kw_args);
127 return self->fun.var(n_args,
args);
133 .
name = MP_QSTR_function,
143 #if MICROPY_PERSISTENT_CODE 144 return code_info[0] | (code_info[1] << 8);
150 #if MICROPY_EMIT_NATIVE 156 #if MICROPY_EMIT_NATIVE 157 if (fun->
base.type == &mp_type_fun_native) {
173 #if MICROPY_CPYTHON_COMPAT 184 for (
size_t i = 0; i < sz; i++) {
190 #define dump_args(...) (void)0 196 #define VM_MAX_STATE_ON_STACK (11 * sizeof(mp_uint_t)) 199 #define VM_DETECT_STACK_OVERFLOW (0) 201 #if MICROPY_STACKLESS 218 code_state->
fun_bc =
self;
224 mp_globals_set(self->globals);
239 DEBUG_printf(
"Func n_def_args: %d\n", self->n_def_args);
245 #if VM_DETECT_STACK_OVERFLOW 255 if (code_state ==
NULL) {
260 code_state->
fun_bc =
self;
266 mp_globals_set(self->globals);
270 #if VM_DETECT_STACK_OVERFLOW 272 if (code_state->
sp < code_state->
state) {
273 printf(
"VM stack underflow: " INT_FMT "\n", code_state->
sp - code_state->
state);
282 bool overflow =
true;
283 for (
size_t i = 0; i < n_state -
self->n_pos_args -
self->n_kwonly_args; i++) {
290 printf(
"VM stack overflow state=%p n_state+1=" UINT_FMT "\n", code_state->
state, n_state);
299 result = *code_state->
sp;
304 result = code_state->
state[n_state - 1];
308 if (state_size != 0) {
319 #if MICROPY_PY_FUNCTION_ATTRS 325 if (
attr == MP_QSTR___name__) {
333 .
name = MP_QSTR_function,
334 #if MICROPY_CPYTHON_COMPAT 335 .print = fun_bc_print,
339 #if MICROPY_PY_FUNCTION_ATTRS 345 size_t n_def_args = 0;
346 size_t n_extra_args = 0;
350 n_def_args = def_args->
len;
351 n_extra_args = def_args->
len;
361 if (def_args !=
NULL) {
373 #if MICROPY_EMIT_NATIVE 379 return fun(self_in, n_args, n_kw,
args);
384 .
name = MP_QSTR_function,
385 .call = fun_native_call,
391 o->
base.type = &mp_type_fun_native;
395 #endif // MICROPY_EMIT_NATIVE 400 #if MICROPY_EMIT_NATIVE 402 typedef struct _mp_obj_fun_viper_t {
407 } mp_obj_fun_viper_t;
409 typedef mp_uint_t (*viper_fun_0_t)(void);
416 mp_obj_fun_viper_t *
self = self_in;
424 ret = ((viper_fun_0_t)fun)();
425 }
else if (n_args == 1) {
427 }
else if (n_args == 2) {
429 }
else if (n_args == 3) {
434 ret = ((viper_fun_4_t)fun)(
447 .
name = MP_QSTR_function,
448 .call = fun_viper_call,
453 mp_obj_fun_viper_t *o =
m_new_obj(mp_obj_fun_viper_t);
454 o->base.type = &mp_type_fun_viper;
456 o->fun_data = fun_data;
457 o->type_sig = type_sig;
461 #endif // MICROPY_EMIT_NATIVE 466 #if MICROPY_EMIT_INLINE_ASM 468 typedef struct _mp_obj_fun_asm_t {
475 typedef mp_uint_t (*inline_asm_fun_0_t)(void);
484 if (MP_OBJ_IS_SMALL_INT(obj)) {
501 #if MICROPY_PY_BUILTINS_FLOAT 504 return (
mp_int_t)mp_obj_float_get(obj);
526 mp_obj_fun_asm_t *
self = self_in;
534 ret = ((inline_asm_fun_0_t)fun)();
535 }
else if (n_args == 1) {
536 ret = ((inline_asm_fun_1_t)fun)(convert_obj_for_inline_asm(
args[0]));
537 }
else if (n_args == 2) {
538 ret = ((inline_asm_fun_2_t)fun)(convert_obj_for_inline_asm(
args[0]), convert_obj_for_inline_asm(
args[1]));
539 }
else if (n_args == 3) {
540 ret = ((inline_asm_fun_3_t)fun)(convert_obj_for_inline_asm(
args[0]), convert_obj_for_inline_asm(
args[1]), convert_obj_for_inline_asm(
args[2]));
544 ret = ((inline_asm_fun_4_t)fun)(
545 convert_obj_for_inline_asm(
args[0]),
546 convert_obj_for_inline_asm(
args[1]),
547 convert_obj_for_inline_asm(
args[2]),
548 convert_obj_for_inline_asm(
args[3])
557 .
name = MP_QSTR_function,
558 .call = fun_asm_call,
563 mp_obj_fun_asm_t *o =
m_new_obj(mp_obj_fun_asm_t);
564 o->base.type = &mp_type_fun_asm;
566 o->fun_data = fun_data;
567 o->type_sig = type_sig;
571 #endif // MICROPY_EMIT_INLINE_ASM
mp_obj_dict_t * old_globals
mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table)
STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
qstr mp_obj_fun_get_name(mp_const_obj_t fun_in)
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp_obj_t inject_exc)
const mp_obj_type_t mp_type_float
#define MP_OBJ_IS_TYPE(o, t)
STATIC const uint8_t attr[]
void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table)
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in)
#define DEBUG_printf(...)
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
#define MP_OBJ_FROM_PTR(p)
STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
#define MP_OBJ_NEW_QSTR(qst)
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
#define VM_MAX_STATE_ON_STACK
qstr mp_obj_code_get_name(const byte *code_info)
#define MP_OBJ_SMALL_INT_VALUE(o)
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in)
STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items)
const mp_obj_type_t mp_type_fun_bc
#define m_new_obj_var(obj_type, var_type, var_num)
mp_obj_t mp_obj_new_fun_asm(size_t n_args, void *fun_data, mp_uint_t type_sig)
const char * mp_obj_str_get_data(mp_obj_t self_in, size_t *len)
mp_obj_t(* mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args)
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type)
#define m_del_var(obj_type, var_type, var_num, ptr)
mp_uint_t mp_decode_uint_value(const byte *ptr)
mp_obj_t mp_obj_new_fun_viper(size_t n_args, void *fun_data, mp_uint_t type_sig)
const mp_obj_type_t mp_type_fun_builtin_var
const mp_uint_t * const_table
void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args)
const mp_obj_type_t mp_type_fun_builtin_3
STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
const mp_obj_type_t mp_type_type
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)
const mp_obj_type_t mp_type_fun_builtin_1
const mp_obj_type_t mp_type_fun_builtin_0
mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data, const mp_uint_t *const_table)
const mp_obj_type_t mp_type_tuple
STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
STATIC mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type)
const byte * mp_decode_uint_skip(const byte *ptr)
const mp_obj_type_t mp_type_fun_builtin_2
int mp_printf(const mp_print_t *print, const char *fmt,...)
const mp_obj_type_t mp_type_int
#define MICROPY_MAKE_POINTER_CALLABLE(p)
const mp_obj_type_t mp_type_list
void * memcpy(void *dst, const void *src, size_t n)
#define m_new_obj_var_maybe(obj_type, var_type, var_num)