diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-07 17:29:16 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-07 17:29:16 +0000 |
commit | c06763a0207dde7f2060f7b1670a0b99298a01f8 (patch) | |
tree | 2f28c6e8824849f167a9b133c2d23c3c55c727d9 /py/runtime.c | |
parent | 880ce2d7fabc127b4bca7b6f2ea8b82d0977045f (diff) | |
download | micropython-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/runtime.c')
-rw-r--r-- | py/runtime.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/py/runtime.c b/py/runtime.c index 6bc71abff7..d1625f6e3d 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -683,10 +683,20 @@ mp_obj_t rt_call_function_n(mp_obj_t fun_in, int n_args, const mp_obj_t *args) { // args are in reverse order in the array; keyword arguments come first, value then key // eg: (value1, key1, value0, key0, arg1, arg0) -mp_obj_t rt_call_function_n_kw(mp_obj_t fun, uint n_args, uint n_kw, const mp_obj_t *args) { - // TODO - assert(0); - return mp_const_none; +mp_obj_t rt_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp_obj_t *args) { + // TODO merge this and _n into a single, smarter thing + DEBUG_OP_printf("calling function %p(n_args=%d, n_kw=%d, args=%p)\n", fun_in, n_args, n_kw, args); + + if (MP_OBJ_IS_SMALL_INT(fun_in)) { + nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "'int' object is not callable")); + } else { + mp_obj_base_t *fun = fun_in; + if (fun->type->call_n_kw != NULL) { + return fun->type->call_n_kw(fun_in, n_args, n_kw, args); + } else { + nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "'%s' object is not callable", fun->type->name)); + } + } } // args contains: arg(n_args-1) arg(n_args-2) ... arg(0) self/NULL fun |