From bdcbf0fcd1ebda674c9f233920b409082824522c Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 26 Mar 2014 23:15:35 +0000 Subject: [PATCH] py: Restore CPython compatibility in compiler for closures with def args. --- py/compile.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/py/compile.c b/py/compile.c index dc001cd88f..f18c228450 100644 --- a/py/compile.c +++ b/py/compile.c @@ -766,9 +766,13 @@ void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_kind) { // stuff for lambda and comprehensions and generators void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_params, int n_default_params) { +#if !MICROPY_EMIT_CPYTHON + // in Micro Python we put the default params into a tuple using the bytecode if (n_default_params) { EMIT_ARG(build_tuple, n_default_params); } +#endif + // make closed over variables, if any // ensure they are closed over in the order defined in the outer scope (mainly to agree with CPython) int nfree = 0; @@ -791,14 +795,12 @@ void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_ } } } - if (nfree > 0) { - EMIT_ARG(build_tuple, nfree); - } // make the function/closure if (nfree == 0) { EMIT_ARG(make_function, this_scope, n_dict_params, n_default_params); } else { + EMIT_ARG(build_tuple, nfree); EMIT_ARG(make_closure, this_scope, n_dict_params, n_default_params); } }