diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-26 23:15:35 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-26 23:15:35 +0000 |
commit | bdcbf0fcd1ebda674c9f233920b409082824522c (patch) | |
tree | 9af5f9a686746fdb992fb5bf16f11d4331c35acf /py/compile.c | |
parent | d6f94340916bc5eabcf51d7afea523885adce818 (diff) | |
download | micropython-bdcbf0fcd1ebda674c9f233920b409082824522c.tar.gz micropython-bdcbf0fcd1ebda674c9f233920b409082824522c.zip |
py: Restore CPython compatibility in compiler for closures with def args.
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 8 |
1 files 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); } } |