diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-01 15:05:04 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-02-01 15:38:22 +0200 |
commit | 90750029df8d7fd24600cc4fe4c98a5b80731f28 (patch) | |
tree | 7e04bc8f0a079b79a7efcd634615ef3204f3f0ac /py/emitbc.c | |
parent | 532f2c30f66c9ff1e4f2aded29b98ba0db5ec341 (diff) |
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/emitbc.c')
-rw-r--r-- | py/emitbc.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index d74b06525..10a93d5b6 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -664,9 +664,15 @@ static void emit_bc_unpack_ex(emit_t *emit, int n_left, int n_right) { } static void emit_bc_make_function(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, 1); - emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION, scope->unique_code_id); + assert(n_dict_params == 0); + if (n_default_params != 0) { + 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); + } else { + emit_pre(emit, 1); + emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION, scope->unique_code_id); + } } static void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { |