summaryrefslogtreecommitdiffstatshomepage
path: root/py/runtime.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-01 15:05:04 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-01 15:38:22 +0200
commit90750029df8d7fd24600cc4fe4c98a5b80731f28 (patch)
tree7e04bc8f0a079b79a7efcd634615ef3204f3f0ac /py/runtime.c
parent532f2c30f66c9ff1e4f2aded29b98ba0db5ec341 (diff)
downloadmicropython-90750029df8d7fd24600cc4fe4c98a5b80731f28.tar.gz
micropython-90750029df8d7fd24600cc4fe4c98a5b80731f28.zip
Implement default function arguments (for Python functions).
TODO: Decide if we really need separate bytecode for creating functions with default arguments - we would need same for closures, then there're keywords arguments too. Having all combinations is a small exponential explosion, likely we need just 2 cases - simplest (no defaults, no kw), and full - defaults & kw.
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/py/runtime.c b/py/runtime.c
index ee8d720c22..77e596c5d0 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -674,7 +674,7 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
return mp_const_none;
}
-mp_obj_t rt_make_function_from_id(int unique_code_id) {
+mp_obj_t rt_make_function_from_id(int unique_code_id, mp_obj_t def_args) {
DEBUG_OP_printf("make_function_from_id %d\n", unique_code_id);
if (unique_code_id < 1 || unique_code_id >= next_unique_code_id) {
// illegal code id
@@ -686,7 +686,7 @@ mp_obj_t rt_make_function_from_id(int unique_code_id) {
mp_obj_t fun;
switch (c->kind) {
case MP_CODE_BYTE:
- fun = mp_obj_new_fun_bc(c->n_args, c->n_state, c->u_byte.code);
+ fun = mp_obj_new_fun_bc(c->n_args, def_args, c->n_state, c->u_byte.code);
break;
case MP_CODE_NATIVE:
fun = rt_make_function_n(c->n_args, c->u_native.fun);
@@ -710,7 +710,7 @@ mp_obj_t rt_make_function_from_id(int unique_code_id) {
mp_obj_t rt_make_closure_from_id(int unique_code_id, mp_obj_t closure_tuple) {
DEBUG_OP_printf("make_closure_from_id %d\n", unique_code_id);
// make function object
- mp_obj_t ffun = rt_make_function_from_id(unique_code_id);
+ mp_obj_t ffun = rt_make_function_from_id(unique_code_id, MP_OBJ_NULL);
// wrap function in closure object
return mp_obj_new_closure(ffun, closure_tuple);
}