// args are in reverse order in the array mp_obj_t bound_meth_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { mp_obj_bound_meth_t *self = self_in; if (n_args == 0) { return rt_call_function_n(self->meth, 1, &self->self); } else if (n_args == 1) { mp_obj_t args2[2]; args2[1] = self->self; args2[0] = args[0]; return rt_call_function_n(self->meth, 2, args2); } else { // TODO not implemented assert(0); return mp_const_none; //return rt_call_function_2(self->meth, n_args + 1, self->self + args); } }
// args are in reverse order in the array mp_obj_t closure_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) { mp_obj_closure_t *self = self_in; // concatenate args and closed-over-vars, in reverse order // TODO perhaps cache this array so we don't need to create it each time we are called mp_obj_t *args2 = m_new(mp_obj_t, self->n_closed + n_args); memcpy(args2, args, n_args * sizeof(mp_obj_t)); for (int i = 0; i < self->n_closed; i++) { args2[n_args + i] = self->closed[self->n_closed - 1 - i]; } // call the function with the new vars array return rt_call_function_n(self->fun, n_args + self->n_closed, args2); }