summaryrefslogtreecommitdiffstatshomepage
path: root/py/obj.h
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-07 17:29:16 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-07 17:29:16 +0000
commitc06763a0207dde7f2060f7b1670a0b99298a01f8 (patch)
tree2f28c6e8824849f167a9b133c2d23c3c55c727d9 /py/obj.h
parent880ce2d7fabc127b4bca7b6f2ea8b82d0977045f (diff)
downloadmicropython-c06763a0207dde7f2060f7b1670a0b99298a01f8.tar.gz
micropython-c06763a0207dde7f2060f7b1670a0b99298a01f8.zip
This implements a better (more python-conformant) list.sort.
It's not really about that, though; it's about me figuring out a sane way forward for keyword-argument functions (and function metadata). But it's useful as is, and shouldn't break any existing code, so here you have it; I'm going to park it in my mind for a bit while sorting out the rest of the dict branch.
Diffstat (limited to 'py/obj.h')
-rw-r--r--py/obj.h30
1 files changed, 17 insertions, 13 deletions
diff --git a/py/obj.h b/py/obj.h
index 1ba7427cbb..e4e64fca71 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -43,12 +43,16 @@ struct _mp_obj_base_t {
#define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name
-#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 0, 0, fun_name}
-#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 1, 1, fun_name}
-#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 2, 2, fun_name}
-#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 3, 3, fun_name}
-#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, (~((machine_uint_t)0)), fun_name}
-#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, n_args_max, fun_name}
+#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, 0, 0, fun_name}
+#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, 1, 1, fun_name}
+#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, 2, 2, fun_name}
+#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, 3, 3, fun_name}
+#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, n_args_min, (~((machine_uint_t)0)), fun_name}
+#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, false, n_args_min, n_args_max, fun_name}
+#define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, true, 0, (~((machine_uint_t)0)), fun_name}
+
+// Need to declare this here so we are not dependent on map.h
+struct _mp_map_t;
// Type definitions for methods
@@ -58,10 +62,12 @@ typedef mp_obj_t (*mp_fun_2_t)(mp_obj_t, mp_obj_t);
typedef mp_obj_t (*mp_fun_3_t)(mp_obj_t, mp_obj_t, mp_obj_t);
typedef mp_obj_t (*mp_fun_t)(void);
typedef mp_obj_t (*mp_fun_var_t)(int n, const mp_obj_t *);
+typedef mp_obj_t (*mp_fun_kw_t)(mp_obj_t*, struct _mp_map_t*);
typedef void (*mp_print_fun_t)(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o);
typedef 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
typedef 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
+typedef 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
typedef mp_obj_t (*mp_unary_op_fun_t)(int op, mp_obj_t);
typedef mp_obj_t (*mp_binary_op_fun_t)(int op, mp_obj_t, mp_obj_t);
@@ -77,6 +83,7 @@ struct _mp_obj_type_t {
mp_make_new_fun_t make_new; // to make an instance of the type
mp_call_n_fun_t call_n;
+ mp_call_n_kw_fun_t call_n_kw;
mp_unary_op_fun_t unary_op; // can return NULL if op not supported
mp_binary_op_fun_t binary_op; // can return NULL if op not supported
@@ -118,10 +125,6 @@ extern const mp_obj_t mp_const_empty_tuple;
extern const mp_obj_t mp_const_ellipsis;
extern const mp_obj_t mp_const_stop_iteration; // special object indicating end of iteration (not StopIteration exception!)
-// Need to declare this here so we are not dependent on map.h
-
-struct _mp_map_t;
-
// General API for objects
mp_obj_t mp_obj_new_none(void);
@@ -144,8 +147,8 @@ mp_obj_t mp_obj_new_fun_asm(uint n_args, void *fun);
mp_obj_t mp_obj_new_gen_wrap(uint n_locals, uint n_stack, mp_obj_t fun);
mp_obj_t mp_obj_new_gen_instance(const byte *bytecode, uint n_state, int n_args, const mp_obj_t *args);
mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_obj_t closure_tuple);
-mp_obj_t mp_obj_new_tuple(uint n, mp_obj_t *items);
-mp_obj_t mp_obj_new_tuple_reverse(uint n, mp_obj_t *items);
+mp_obj_t mp_obj_new_tuple(uint n, const mp_obj_t *items);
+mp_obj_t mp_obj_new_tuple_reverse(uint n, const mp_obj_t *items);
mp_obj_t mp_obj_new_list(uint n, mp_obj_t *items);
mp_obj_t mp_obj_new_list_reverse(uint n, mp_obj_t *items);
mp_obj_t mp_obj_new_dict(int n_args);
@@ -234,7 +237,8 @@ void mp_obj_slice_get(mp_obj_t self_in, machine_int_t *start, machine_int_t *sto
// functions
typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM)
mp_obj_base_t base;
- machine_uint_t n_args_min; // inclusive
+ bool is_kw : 1;
+ machine_uint_t n_args_min : (sizeof(machine_uint_t) - 1); // inclusive
machine_uint_t n_args_max; // inclusive
void *fun;
// TODO add mp_map_t *globals