runtime.h 3.45 KB
Newer Older
1
2
3
4
5
6
typedef enum {
    MP_VM_RETURN_NORMAL,
    MP_VM_RETURN_YIELD,
    MP_VM_RETURN_EXCEPTION,
} mp_vm_return_kind_t;

7
typedef enum {
8
9
10
11
12
13
14
15
16
    MP_ARG_BOOL      = 0x001,
    MP_ARG_INT       = 0x002,
    MP_ARG_OBJ       = 0x003,
    MP_ARG_KIND_MASK = 0x0ff,
    MP_ARG_REQUIRED  = 0x100,
    MP_ARG_KW_ONLY   = 0x200,
} mp_arg_flag_t;

typedef union _mp_arg_val_t {
17
18
19
    bool u_bool;
    machine_int_t u_int;
    mp_obj_t u_obj;
20
} mp_arg_val_t;
21

22
typedef struct _mp_arg_t {
23
24
    qstr qstr;
    machine_uint_t flags;
25
26
    mp_arg_val_t defval;
} mp_arg_t;
27

Damien George's avatar
Damien George committed
28
29
30
void mp_init(void);
void mp_deinit(void);

31
void mp_arg_check_num(uint n_args, uint n_kw, uint n_args_min, uint n_args_max, bool takes_kw);
32
void mp_arg_parse_all(uint n_pos, const mp_obj_t *pos, mp_map_t *kws, uint n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
Damien George's avatar
Damien George committed
33

34
35
36
37
mp_obj_dict_t *mp_locals_get(void);
void mp_locals_set(mp_obj_dict_t *d);
mp_obj_dict_t *mp_globals_get(void);
void mp_globals_set(mp_obj_dict_t *d);
Damien George's avatar
Damien George committed
38
39
40
41
42
43
44

mp_obj_t mp_load_name(qstr qstr);
mp_obj_t mp_load_global(qstr qstr);
mp_obj_t mp_load_build_class(void);
void mp_store_name(qstr qstr, mp_obj_t obj);
void mp_store_global(qstr qstr, mp_obj_t obj);
void mp_delete_name(qstr qstr);
45
void mp_delete_global(qstr qstr);
Damien George's avatar
Damien George committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

mp_obj_t mp_unary_op(int op, mp_obj_t arg);
mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs);

mp_obj_t mp_load_const_dec(qstr qstr);
mp_obj_t mp_load_const_str(qstr qstr);
mp_obj_t mp_load_const_bytes(qstr qstr);

mp_obj_t mp_make_function_n(int n_args, void *fun); // fun must have the correct signature for n_args fixed arguments
mp_obj_t mp_make_function_var(int n_args_min, mp_fun_var_t fun);
mp_obj_t mp_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun); // min and max are inclusive

mp_obj_t mp_call_function_0(mp_obj_t fun);
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg);
mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
mp_obj_t mp_call_function_n_kw_for_native(mp_obj_t fun_in, uint n_args_kw, const mp_obj_t *args);
mp_obj_t mp_call_function_n_kw(mp_obj_t fun, uint n_args, uint n_kw, const mp_obj_t *args);
mp_obj_t mp_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args);
64
mp_obj_t mp_call_method_n_kw_var(bool have_self, uint n_args_n_kw, const mp_obj_t *args);
Damien George's avatar
Damien George committed
65
66

void mp_unpack_sequence(mp_obj_t seq, uint num, mp_obj_t *items);
67
void mp_unpack_ex(mp_obj_t seq, uint num, mp_obj_t *items);
Damien George's avatar
Damien George committed
68
69
70
mp_obj_t mp_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value);
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr);
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest);
Damien George's avatar
Damien George committed
71
void mp_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest);
Damien George's avatar
Damien George committed
72
73
74
void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t val);

mp_obj_t mp_getiter(mp_obj_t o);
75
76
mp_obj_t mp_iternext_allow_raise(mp_obj_t o); // may return MP_OBJ_STOP_ITERATION instead of raising StopIteration()
mp_obj_t mp_iternext(mp_obj_t o); // will always return MP_OBJ_STOP_ITERATION instead of raising StopIteration(...)
77
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);
Damien George's avatar
Damien George committed
78
79
80

mp_obj_t mp_make_raise_obj(mp_obj_t o);

Damien George's avatar
Damien George committed
81
mp_map_t *mp_loaded_modules_get(void);
Damien George's avatar
Damien George committed
82
83
84
mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level);
mp_obj_t mp_import_from(mp_obj_t module, qstr name);
void mp_import_all(mp_obj_t module);
85
86
87
88
89

extern struct _mp_obj_list_t mp_sys_path_obj;
extern struct _mp_obj_list_t mp_sys_argv_obj;
#define mp_sys_path ((mp_obj_t)&mp_sys_path_obj)
#define mp_sys_argv ((mp_obj_t)&mp_sys_argv_obj)