diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-07 14:49:22 -0800 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-07 14:49:22 -0800 |
commit | 777575712b9e102d9ddf81cfe253e8d789f28d0a (patch) | |
tree | 35233d743ef212601735d5a9b333dc67ea24f742 /py/runtime.c | |
parent | 1e40840b3b082deb1ed14e2d82e448684b96ed0d (diff) | |
parent | 3391e190680d3625a166bb6573df26e1bda30af2 (diff) | |
download | micropython-777575712b9e102d9ddf81cfe253e8d789f28d0a.tar.gz micropython-777575712b9e102d9ddf81cfe253e8d789f28d0a.zip |
Merge pull request #105 from chipaca/listsort
A more python-style list.sort. And keyword arguments.
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 dce8c7b96a..962d539c04 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -689,10 +689,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 |