blob: c2182863a14e32e32dc46c173026c836f1c030c8 [file] [log] [blame]
Damiend99b0522013-12-21 18:17:45 +00001// All Micro Python objects are at least this type
2// It must be of pointer size
3
4typedef machine_ptr_t mp_obj_t;
5typedef machine_const_ptr_t mp_const_obj_t;
6
7// Integers that fit in a pointer have this type
8// (do we need to expose this in the public API?)
9
10typedef machine_int_t mp_small_int_t;
11
12// The machine floating-point type used for float and complex numbers
Damien660365e2013-12-17 18:27:24 +000013
14#if MICROPY_ENABLE_FLOAT
Damiend99b0522013-12-21 18:17:45 +000015typedef machine_float_t mp_float_t;
Damien660365e2013-12-17 18:27:24 +000016#endif
17
Damien George97209d32014-01-07 15:58:30 +000018// Anything that wants to be a Micro Python object must have
19// mp_obj_base_t as its first member (except NULL and small ints)
Damien660365e2013-12-17 18:27:24 +000020
ian-v7a16fad2014-01-06 09:52:29 -080021struct _mp_obj_type_t;
Damiend99b0522013-12-21 18:17:45 +000022struct _mp_obj_base_t {
ian-v7a16fad2014-01-06 09:52:29 -080023 const struct _mp_obj_type_t *type;
Damiend99b0522013-12-21 18:17:45 +000024};
ian-v7a16fad2014-01-06 09:52:29 -080025typedef struct _mp_obj_base_t mp_obj_base_t;
Damiend99b0522013-12-21 18:17:45 +000026
27// The NULL object is used to indicate the absence of an object
28// It *cannot* be used when an mp_obj_t is expected, except where explicitly allowed
29
30#define MP_OBJ_NULL ((mp_obj_t)NULL)
31
Damien George38a2da62014-01-08 17:33:12 +000032// These macros check for small int, qstr or object, and access small int and qstr values
33// - xxxx...xxx1: a small int, bits 1 and above are the value
34// - xxxx...xx10: a qstr, bits 2 and above are the value
35// - xxxx...xx00: a pointer to an mp_obj_base_t
Damiend99b0522013-12-21 18:17:45 +000036
Paul Sokolovsky757ac812014-01-12 17:06:25 +020037// In SMALL_INT, next-to-highest bits is used as sign, so both must match for value in range
38#define MP_OBJ_FITS_SMALL_INT(n) ((((n) ^ ((n) << 1)) & WORD_MSBIT_HIGH) == 0)
Damiend99b0522013-12-21 18:17:45 +000039#define MP_OBJ_IS_SMALL_INT(o) ((((mp_small_int_t)(o)) & 1) != 0)
Damien George38a2da62014-01-08 17:33:12 +000040#define MP_OBJ_IS_QSTR(o) ((((mp_small_int_t)(o)) & 3) == 2)
41#define MP_OBJ_IS_OBJ(o) ((((mp_small_int_t)(o)) & 3) == 0)
42#define MP_OBJ_IS_TYPE(o, t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t)))
43
Damiend99b0522013-12-21 18:17:45 +000044#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_small_int_t)(o)) >> 1)
Damien George38a2da62014-01-08 17:33:12 +000045#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((small_int) << 1) | 1))
46
47#define MP_OBJ_QSTR_VALUE(o) (((mp_small_int_t)(o)) >> 2)
48#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((machine_uint_t)qstr) << 2) | 2))
Damiend99b0522013-12-21 18:17:45 +000049
50// These macros are used to declare and define constant function objects
51// You can put "static" in front of the definitions to make them local
52
53#define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name
54
John R. Lenton270112f2014-01-07 18:01:08 +000055#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, is_kw, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, is_kw, n_args_min, n_args_max, (void *)fun_name}
56#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 0, 0, (mp_fun_0_t)fun_name)
57#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 1, 1, (mp_fun_1_t)fun_name)
58#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 2, 2, (mp_fun_2_t)fun_name)
59#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 3, 3, (mp_fun_3_t)fun_name)
60#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, n_args_min, (~((machine_uint_t)0)), (mp_fun_var_t)fun_name)
61#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, n_args_min, n_args_max, (mp_fun_var_t)fun_name)
John R. Lenton88cb1e62014-01-13 19:55:18 +000062#define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, true, n_args_min, (~((machine_uint_t)0)), (mp_fun_kw_t)fun_name)
John R. Lentonc06763a2014-01-07 17:29:16 +000063
Damien Georgeeae16442014-01-11 19:22:29 +000064// These macros are used to declare and define constant staticmethond and classmethod objects
65// You can put "static" in front of the definitions to make them local
66
67#define MP_DECLARE_CONST_STATICMETHOD_OBJ(obj_name) extern const mp_obj_staticmethod_t obj_name
68#define MP_DECLARE_CONST_CLASSMETHOD_OBJ(obj_name) extern const mp_obj_classmethod_t obj_name
69
70#define MP_DEFINE_CONST_STATICMETHOD_OBJ(obj_name, fun_name) const mp_obj_staticmethod_t obj_name = {{&mp_type_staticmethod}, fun_name}
71#define MP_DEFINE_CONST_CLASSMETHOD_OBJ(obj_name, fun_name) const mp_obj_classmethod_t obj_name = {{&mp_type_classmethod}, fun_name}
72
John R. Lentonc06763a2014-01-07 17:29:16 +000073// Need to declare this here so we are not dependent on map.h
74struct _mp_map_t;
Damien George062478e2014-01-09 20:57:50 +000075struct _mp_map_elem_t;
76enum _mp_map_lookup_kind_t;
Damiend99b0522013-12-21 18:17:45 +000077
78// Type definitions for methods
79
80typedef mp_obj_t (*mp_fun_0_t)(void);
81typedef mp_obj_t (*mp_fun_1_t)(mp_obj_t);
82typedef mp_obj_t (*mp_fun_2_t)(mp_obj_t, mp_obj_t);
John R. Lenton45a87442014-01-04 01:15:01 +000083typedef mp_obj_t (*mp_fun_3_t)(mp_obj_t, mp_obj_t, mp_obj_t);
Damiend99b0522013-12-21 18:17:45 +000084typedef mp_obj_t (*mp_fun_t)(void);
85typedef mp_obj_t (*mp_fun_var_t)(int n, const mp_obj_t *);
Damien Georgedfc0bac2014-01-07 23:18:54 +000086typedef mp_obj_t (*mp_fun_kw_t)(mp_obj_t, struct _mp_map_t*);
Damiend99b0522013-12-21 18:17:45 +000087
88typedef void (*mp_print_fun_t)(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o);
Damien George71c51812014-01-04 20:21:15 +000089typedef mp_obj_t (*mp_make_new_fun_t)(mp_obj_t type_in, int n_args, const mp_obj_t *args); // args are in reverse order in the array
Damiend99b0522013-12-21 18:17:45 +000090typedef mp_obj_t (*mp_call_n_fun_t)(mp_obj_t fun, int n_args, const mp_obj_t *args); // args are in reverse order in the array
John R. Lentonc06763a2014-01-07 17:29:16 +000091typedef mp_obj_t (*mp_call_n_kw_fun_t)(mp_obj_t fun, int n_args, int n_kw, const mp_obj_t *args); // args are in reverse order in the array
Damiend99b0522013-12-21 18:17:45 +000092typedef mp_obj_t (*mp_unary_op_fun_t)(int op, mp_obj_t);
93typedef mp_obj_t (*mp_binary_op_fun_t)(int op, mp_obj_t, mp_obj_t);
Damien George062478e2014-01-09 20:57:50 +000094typedef void (*mp_load_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest); // for fail, do nothing; for attr, dest[1] = value; for method, dest[0] = self, dest[1] = method
95typedef bool (*mp_store_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t value); // return true if store succeeded
Damiend99b0522013-12-21 18:17:45 +000096
97typedef struct _mp_method_t {
Damien660365e2013-12-17 18:27:24 +000098 const char *name;
Damiend99b0522013-12-21 18:17:45 +000099 mp_const_obj_t fun;
100} mp_method_t;
101
Paul Sokolovsky5b15daf2014-01-07 20:12:26 +0200102// Buffer protocol
103typedef struct _buffer_info_t {
104 // if we'd bother to support various versions of structure
105 // (with different number of fields), we can distinguish
106 // them with ver = sizeof(struct). Cons: overkill for *micro*?
107 //int ver; // ?
108
109 void *buf;
110 machine_int_t len;
111
112 // Rationale: have array.array and have SIMD operations on them
113 // Cons: users can pass item size to processing functions themselves,
114 // though that's not "plug&play"
115 // int itemsize;
116
117 // Rationale: to load arbitrary-sized sprites directly to LCD
118 // Cons: a bit adhoc usecase
119 // int stride;
120} buffer_info_t;
121#define BUFFER_READ (1)
122#define BUFFER_WRITE (2)
123#define BUFFER_RW (BUFFER_READ | BUFFER_WRITE)
124typedef struct _mp_buffer_p_t {
125 machine_int_t (*get_buffer)(mp_obj_t obj, buffer_info_t *bufinfo, int flags);
126} mp_buffer_p_t;
127
128// Stream protocol
129typedef struct _mp_stream_p_t {
130 // On error, functions should return -1 and fill in *errcode (values are
131 // implementation-dependent, but will be exposed to user, e.g. via exception).
132 machine_int_t (*read)(mp_obj_t obj, void *buf, machine_uint_t size, int *errcode);
133 machine_int_t (*write)(mp_obj_t obj, const void *buf, machine_uint_t size, int *errcode);
134 // add seek() ?
135} mp_stream_p_t;
136
Damiend99b0522013-12-21 18:17:45 +0000137struct _mp_obj_type_t {
138 mp_obj_base_t base;
139 const char *name;
140 mp_print_fun_t print;
Damien George71c51812014-01-04 20:21:15 +0000141 mp_make_new_fun_t make_new; // to make an instance of the type
Damiend99b0522013-12-21 18:17:45 +0000142
143 mp_call_n_fun_t call_n;
John R. Lentonc06763a2014-01-07 17:29:16 +0000144 mp_call_n_kw_fun_t call_n_kw;
Damiend99b0522013-12-21 18:17:45 +0000145 mp_unary_op_fun_t unary_op; // can return NULL if op not supported
146 mp_binary_op_fun_t binary_op; // can return NULL if op not supported
147
148 mp_fun_1_t getiter;
149 mp_fun_1_t iternext;
150
Paul Sokolovsky5b15daf2014-01-07 20:12:26 +0200151 // Alternatively, pointer(s) to interfaces to save space
152 // in mp_obj_type_t at the expense of extra pointer and extra dereference
153 // when actually used.
154 mp_buffer_p_t buffer_p;
155 mp_stream_p_t stream_p;
156
ian-v7a16fad2014-01-06 09:52:29 -0800157 const mp_method_t *methods;
Damiend99b0522013-12-21 18:17:45 +0000158
Damien George062478e2014-01-09 20:57:50 +0000159 mp_load_attr_fun_t load_attr;
160 mp_store_attr_fun_t store_attr;
Damien George004cdce2014-01-09 21:43:51 +0000161
162 // these are for dynamically created types (classes)
163 mp_obj_t bases_tuple;
164 mp_obj_t locals_dict;
Damien George062478e2014-01-09 20:57:50 +0000165
Damiend99b0522013-12-21 18:17:45 +0000166 /*
167 What we might need to add here:
168
Damiend99b0522013-12-21 18:17:45 +0000169 store_subscr list dict
170
171 len str tuple list map
172 abs float complex
173 hash bool int none str
174 equal int str
175 less int
176 get_array_n tuple list
177
178 unpack seq list tuple
Damiend99b0522013-12-21 18:17:45 +0000179 */
180};
181
ian-v7a16fad2014-01-06 09:52:29 -0800182typedef struct _mp_obj_type_t mp_obj_type_t;
Damiend99b0522013-12-21 18:17:45 +0000183
184// Constant objects, globally accessible
185
186extern const mp_obj_type_t mp_const_type;
187extern const mp_obj_t mp_const_none;
188extern const mp_obj_t mp_const_false;
189extern const mp_obj_t mp_const_true;
Damien George71c51812014-01-04 20:21:15 +0000190extern const mp_obj_t mp_const_empty_tuple;
Damien Georgee9906ac2014-01-04 18:44:46 +0000191extern const mp_obj_t mp_const_ellipsis;
Damiend99b0522013-12-21 18:17:45 +0000192extern const mp_obj_t mp_const_stop_iteration; // special object indicating end of iteration (not StopIteration exception!)
193
Damiend99b0522013-12-21 18:17:45 +0000194// General API for objects
195
Damien George004cdce2014-01-09 21:43:51 +0000196mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
Damiend99b0522013-12-21 18:17:45 +0000197mp_obj_t mp_obj_new_none(void);
198mp_obj_t mp_obj_new_bool(bool value);
Damien George6baf76e2013-12-30 22:32:17 +0000199mp_obj_t mp_obj_new_cell(mp_obj_t obj);
Damiend99b0522013-12-21 18:17:45 +0000200mp_obj_t mp_obj_new_int(machine_int_t value);
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200201mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value);
202mp_obj_t mp_obj_new_int_from_long_str(const char *s);
Damiend99b0522013-12-21 18:17:45 +0000203mp_obj_t mp_obj_new_str(qstr qstr);
204#if MICROPY_ENABLE_FLOAT
205mp_obj_t mp_obj_new_float(mp_float_t val);
206mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
207#endif
208mp_obj_t mp_obj_new_exception(qstr id);
209mp_obj_t mp_obj_new_exception_msg(qstr id, const char *msg);
210mp_obj_t mp_obj_new_exception_msg_1_arg(qstr id, const char *fmt, const char *a1);
211mp_obj_t mp_obj_new_exception_msg_2_args(qstr id, const char *fmt, const char *a1, const char *a2);
Damien George6c73ca12014-01-08 18:11:23 +0000212mp_obj_t mp_obj_new_exception_msg_varg(qstr id, const char *fmt, ...); // counts args by number of % symbols in fmt, excluding %%; can only handle void* sizes (ie no float/double!)
Damiend99b0522013-12-21 18:17:45 +0000213mp_obj_t mp_obj_new_range(int start, int stop, int step);
214mp_obj_t mp_obj_new_range_iterator(int cur, int stop, int step);
215mp_obj_t mp_obj_new_fun_bc(int n_args, uint n_state, const byte *code);
216mp_obj_t mp_obj_new_fun_asm(uint n_args, void *fun);
Damien George6baf76e2013-12-30 22:32:17 +0000217mp_obj_t mp_obj_new_gen_wrap(uint n_locals, uint n_stack, mp_obj_t fun);
Damien George0ff88392014-01-02 20:57:05 +0000218mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, uint n_state, int n_args, const mp_obj_t *args);
Damiend99b0522013-12-21 18:17:45 +0000219mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_obj_t closure_tuple);
John R. Lentonc06763a2014-01-07 17:29:16 +0000220mp_obj_t mp_obj_new_tuple(uint n, const mp_obj_t *items);
221mp_obj_t mp_obj_new_tuple_reverse(uint n, const mp_obj_t *items);
Damiend99b0522013-12-21 18:17:45 +0000222mp_obj_t mp_obj_new_list(uint n, mp_obj_t *items);
223mp_obj_t mp_obj_new_list_reverse(uint n, mp_obj_t *items);
224mp_obj_t mp_obj_new_dict(int n_args);
225mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items);
Paul Sokolovsky1c6de112014-01-03 02:41:17 +0200226mp_obj_t mp_obj_new_slice(mp_obj_t start, mp_obj_t stop, mp_obj_t step);
Damiend99b0522013-12-21 18:17:45 +0000227mp_obj_t mp_obj_new_bound_meth(mp_obj_t self, mp_obj_t meth);
Damien George28708622014-01-02 21:30:26 +0000228mp_obj_t mp_obj_new_module(qstr module_name);
Damiend99b0522013-12-21 18:17:45 +0000229
Damien Georgeb97669a2014-01-08 11:47:55 +0000230mp_obj_t mp_obj_get_type(mp_obj_t o_in);
Damiend99b0522013-12-21 18:17:45 +0000231const char *mp_obj_get_type_str(mp_obj_t o_in);
232
233void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in);
234void mp_obj_print(mp_obj_t o);
235
236bool mp_obj_is_callable(mp_obj_t o_in);
237machine_int_t mp_obj_hash(mp_obj_t o_in);
238bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2);
239bool mp_obj_less(mp_obj_t o1, mp_obj_t o2);
240
241machine_int_t mp_obj_get_int(mp_obj_t arg);
242#if MICROPY_ENABLE_FLOAT
243mp_float_t mp_obj_get_float(mp_obj_t self_in);
244void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
245#endif
246qstr mp_obj_get_qstr(mp_obj_t arg);
247mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o, machine_int_t n);
248uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index);
John R. Lenton4bee76e2014-01-10 11:25:03 +0000249mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return NULL */
Damiend99b0522013-12-21 18:17:45 +0000250
251// none
252extern const mp_obj_type_t none_type;
253
254// bool
255extern const mp_obj_type_t bool_type;
John R. Lentonb8698fc2014-01-11 00:58:59 +0000256#define MP_BOOL(x) (x ? mp_const_true : mp_const_false)
Damiend99b0522013-12-21 18:17:45 +0000257
258// cell
259mp_obj_t mp_obj_cell_get(mp_obj_t self_in);
260void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj);
261
Damien George71c51812014-01-04 20:21:15 +0000262// int
263extern const mp_obj_type_t int_type;
264
Damienb86e3f92013-12-29 17:17:43 +0000265// exception
266extern const mp_obj_type_t exception_type;
267qstr mp_obj_exception_get_type(mp_obj_t self_in);
268
Damiend99b0522013-12-21 18:17:45 +0000269// str
270extern const mp_obj_type_t str_type;
271qstr mp_obj_str_get(mp_obj_t self_in);
272
273#if MICROPY_ENABLE_FLOAT
274// float
275extern const mp_obj_type_t float_type;
276mp_float_t mp_obj_float_get(mp_obj_t self_in);
Damien Georgee2e3d112014-01-06 22:13:00 +0000277mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs);
Damiend99b0522013-12-21 18:17:45 +0000278
279// complex
280extern const mp_obj_type_t complex_type;
281void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
Damien Georgee2e3d112014-01-06 22:13:00 +0000282mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in);
Damiend99b0522013-12-21 18:17:45 +0000283#endif
284
285// tuple
286extern const mp_obj_type_t tuple_type;
287void mp_obj_tuple_get(mp_obj_t self_in, uint *len, mp_obj_t **items);
John R. Lenton07205ec2014-01-13 02:31:00 +0000288void mp_obj_tuple_del(mp_obj_t self_in);
Damiend99b0522013-12-21 18:17:45 +0000289
290// list
291extern const mp_obj_type_t list_type;
292mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
293void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items);
294void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
Damien George0f592032014-01-14 23:18:35 +0000295mp_obj_t mp_obj_list_sort(mp_obj_t args, struct _mp_map_t *kwargs);
Damiend99b0522013-12-21 18:17:45 +0000296
John R. Lenton39b174e2014-01-15 01:10:09 +0000297// map (the python builtin, not the dict implementation detail)
298extern const mp_obj_type_t map_type;
299
John R. Lenton9daa7892014-01-14 23:55:01 +0000300// enumerate
301extern const mp_obj_type_t enumerate_type;
302
John R. Lentonfca456b2014-01-15 01:37:08 +0000303// filter
304extern const mp_obj_type_t filter_type;
305
Damiend99b0522013-12-21 18:17:45 +0000306// dict
307extern const mp_obj_type_t dict_type;
Damiendae7eb72013-12-29 22:32:51 +0000308uint mp_obj_dict_len(mp_obj_t self_in);
Damiend99b0522013-12-21 18:17:45 +0000309mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
Damien George062478e2014-01-09 20:57:50 +0000310struct _mp_map_t *mp_obj_dict_get_map(mp_obj_t self_in);
Damiend99b0522013-12-21 18:17:45 +0000311
312// set
Damien George71c51812014-01-04 20:21:15 +0000313extern const mp_obj_type_t set_type;
Damiend99b0522013-12-21 18:17:45 +0000314void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item);
315
Paul Sokolovsky1c6de112014-01-03 02:41:17 +0200316// slice
317extern const mp_obj_type_t slice_type;
318void mp_obj_slice_get(mp_obj_t self_in, machine_int_t *start, machine_int_t *stop, machine_int_t *step);
319
John R. Lenton07205ec2014-01-13 02:31:00 +0000320// zip
321extern const mp_obj_type_t zip_type;
322
323
Damiend99b0522013-12-21 18:17:45 +0000324// functions
Damien George66028ab2014-01-03 14:03:48 +0000325typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM)
Damiend99b0522013-12-21 18:17:45 +0000326 mp_obj_base_t base;
John R. Lentonc06763a2014-01-07 17:29:16 +0000327 bool is_kw : 1;
328 machine_uint_t n_args_min : (sizeof(machine_uint_t) - 1); // inclusive
Damiend99b0522013-12-21 18:17:45 +0000329 machine_uint_t n_args_max; // inclusive
Damien660365e2013-12-17 18:27:24 +0000330 void *fun;
Damien George66028ab2014-01-03 14:03:48 +0000331 // TODO add mp_map_t *globals
332 // for const function objects, make an empty, const map
333 // such functions won't be able to access the global scope, but that's probably okay
Damiend99b0522013-12-21 18:17:45 +0000334} mp_obj_fun_native_t;
Damien George97209d32014-01-07 15:58:30 +0000335
Damiend99b0522013-12-21 18:17:45 +0000336extern const mp_obj_type_t fun_native_type;
337extern const mp_obj_type_t fun_bc_type;
338void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte **code);
Damien660365e2013-12-17 18:27:24 +0000339
Damiend99b0522013-12-21 18:17:45 +0000340// generator
341extern const mp_obj_type_t gen_instance_type;
Damien660365e2013-12-17 18:27:24 +0000342
Damien George28708622014-01-02 21:30:26 +0000343// module
344extern const mp_obj_type_t module_type;
345mp_obj_t mp_obj_new_module(qstr module_name);
346struct _mp_map_t *mp_obj_module_get_globals(mp_obj_t self_in);
Damien Georgeeae16442014-01-11 19:22:29 +0000347
348// staticmethod and classmethod types; defined here so we can make const versions
349
350extern const mp_obj_type_t mp_type_staticmethod;
351extern const mp_obj_type_t mp_type_classmethod;
352
353typedef struct _mp_obj_staticmethod_t {
354 mp_obj_base_t base;
355 mp_obj_t fun;
356} mp_obj_staticmethod_t;
357
358typedef struct _mp_obj_classmethod_t {
359 mp_obj_base_t base;
360 mp_obj_t fun;
361} mp_obj_classmethod_t;