blob: f79cb2e3062b77e2beeb6d8420814d8d50bf0d53 [file] [log] [blame]
Paul Sokolovskyf39d3b92014-03-30 23:14:55 +03001typedef enum {
2 MP_VM_RETURN_NORMAL,
3 MP_VM_RETURN_YIELD,
4 MP_VM_RETURN_EXCEPTION,
5} mp_vm_return_kind_t;
6
Damien Georged17926d2014-03-30 13:35:08 +01007void mp_init(void);
8void mp_deinit(void);
Damien George2326d522014-03-27 23:26:35 +00009
Damien Georged17926d2014-03-30 13:35:08 +010010void mp_check_nargs(int n_args, machine_uint_t n_args_min, machine_uint_t n_args_max, int n_kw, bool is_kw);
Dave Hylands51dabac2014-02-17 17:57:13 -080011
Damien Georgedf6567e2014-03-30 13:54:02 +010012mp_map_t *mp_locals_get(void);
13void mp_locals_set(mp_map_t *m);
14mp_map_t *mp_globals_get(void);
15void mp_globals_set(mp_map_t *m);
Damien429d7192013-10-04 19:53:11 +010016
Damien Georged17926d2014-03-30 13:35:08 +010017mp_obj_t mp_load_name(qstr qstr);
18mp_obj_t mp_load_global(qstr qstr);
19mp_obj_t mp_load_build_class(void);
20void mp_store_name(qstr qstr, mp_obj_t obj);
21void mp_store_global(qstr qstr, mp_obj_t obj);
22void mp_delete_name(qstr qstr);
Damien George66028ab2014-01-03 14:03:48 +000023
Damien Georged17926d2014-03-30 13:35:08 +010024mp_obj_t mp_unary_op(int op, mp_obj_t arg);
25mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs);
26
27mp_obj_t mp_load_const_dec(qstr qstr);
28mp_obj_t mp_load_const_str(qstr qstr);
29mp_obj_t mp_load_const_bytes(qstr qstr);
30
31mp_obj_t mp_get_cell(mp_obj_t cell);
32void mp_set_cell(mp_obj_t cell, mp_obj_t val);
33
34mp_obj_t mp_make_function_from_id(uint unique_code_id, bool free_unique_code, mp_obj_t def_args);
35mp_obj_t mp_make_function_n(int n_args, void *fun); // fun must have the correct signature for n_args fixed arguments
36mp_obj_t mp_make_function_var(int n_args_min, mp_fun_var_t fun);
37mp_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
38mp_obj_t mp_make_closure_from_id(uint unique_code_id, mp_obj_t closure_tuple, mp_obj_t def_args);
39
40mp_obj_t mp_call_function_0(mp_obj_t fun);
41mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg);
42mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
43mp_obj_t mp_call_function_n_kw_for_native(mp_obj_t fun_in, uint n_args_kw, const mp_obj_t *args);
44mp_obj_t mp_call_function_n_kw(mp_obj_t fun, uint n_args, uint n_kw, const mp_obj_t *args);
45mp_obj_t mp_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args);
Damien George230fec72014-03-30 21:21:24 +010046mp_obj_t mp_call_method_n_kw_var(bool have_self, uint n_args_n_kw, const mp_obj_t *args, mp_obj_t pos_seq, mp_obj_t kw_dict);
Damien Georged17926d2014-03-30 13:35:08 +010047
48mp_obj_t mp_build_tuple(int n_args, mp_obj_t *items);
49mp_obj_t mp_build_list(int n_args, mp_obj_t *items);
50mp_obj_t mp_list_append(mp_obj_t list, mp_obj_t arg);
51mp_obj_t mp_build_set(int n_args, mp_obj_t *items);
52mp_obj_t mp_store_set(mp_obj_t set, mp_obj_t item);
53void mp_unpack_sequence(mp_obj_t seq, uint num, mp_obj_t *items);
54mp_obj_t mp_build_map(int n_args);
55mp_obj_t mp_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value);
56mp_obj_t mp_load_attr(mp_obj_t base, qstr attr);
57void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest);
58void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t val);
59void mp_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
60
61mp_obj_t mp_getiter(mp_obj_t o);
62mp_obj_t mp_iternext_allow_raise(mp_obj_t o); // may return MP_OBJ_NULL instead of raising StopIteration()
63mp_obj_t mp_iternext(mp_obj_t o); // will always return MP_OBJ_NULL instead of raising StopIteration(...)
Paul Sokolovskyf39d3b92014-03-30 23:14:55 +030064mp_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 Georged17926d2014-03-30 13:35:08 +010065
66mp_obj_t mp_make_raise_obj(mp_obj_t o);
67
68extern mp_obj_t mp_sys_path;
Damien Georgedf6567e2014-03-30 13:54:02 +010069mp_map_t *mp_loaded_modules_get(void);
Damien Georged17926d2014-03-30 13:35:08 +010070mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level);
71mp_obj_t mp_import_from(mp_obj_t module, qstr name);
72void mp_import_all(mp_obj_t module);