diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-03-26 23:14:59 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-03-26 23:17:44 +0200 |
commit | 2447a5b582503b70936681702062704e2e9f44d3 (patch) | |
tree | 6f747fe74cc8400df1a23a74cbb0b9034df5bc60 /py/emitbc.c | |
parent | c12b2213c16ba8839981c362c4d5f133a84b374b (diff) | |
download | micropython-2447a5b582503b70936681702062704e2e9f44d3.tar.gz micropython-2447a5b582503b70936681702062704e2e9f44d3.zip |
py: Support closures with default args.
Diffstat (limited to 'py/emitbc.c')
-rw-r--r-- | py/emitbc.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index ef5da3a622..653b144875 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -722,16 +722,20 @@ STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_param emit_pre(emit, 1); emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION, scope->unique_code_id); } else { - emit_bc_build_tuple(emit, n_default_params); emit_pre(emit, 0); emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION_DEFARGS, scope->unique_code_id); } } STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { - assert(n_default_params == 0 && n_dict_params == 0); - emit_pre(emit, 0); - emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id); + assert(n_dict_params == 0); + if (n_default_params == 0) { + emit_pre(emit, 0); + emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id); + } else { + emit_pre(emit, -1); + emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE_DEFARGS, scope->unique_code_id); + } } STATIC void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { |