summaryrefslogtreecommitdiff
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-20 17:50:40 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-20 17:50:40 +0100
commit3558f62fb5c21a19a518c2ba75860f0b5963219e (patch)
treecf8626118be5d0169ec0f1cd0482563595704c4e /py/compile.c
parentbc5f0c19775e23b4f0621d52de47fb9438a78ba2 (diff)
py: Making closures now passes pointer to stack, not a tuple for vars.
Closed over variables are now passed on the stack, instead of creating a tuple and passing that. This way memory for the closed over variables can be allocated within the closure object itself. See issue #510 for background.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/py/compile.c b/py/compile.c
index b0f1f9e00..57f6f1546 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -889,8 +889,7 @@ void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_pos_d
if (nfree == 0) {
EMIT_ARG(make_function, this_scope, n_pos_defaults, n_kw_defaults);
} else {
- EMIT_ARG(build_tuple, nfree);
- EMIT_ARG(make_closure, this_scope, n_pos_defaults, n_kw_defaults);
+ EMIT_ARG(make_closure, this_scope, nfree, n_pos_defaults, n_kw_defaults);
}
}
@@ -957,6 +956,8 @@ void compile_funcdef_param(compiler_t *comp, mp_parse_node_t pn) {
// we need to do this here before we start building the map for the default keywords
if (comp->num_default_params > 0) {
EMIT_ARG(build_tuple, comp->num_default_params);
+ } else {
+ EMIT(load_null); // sentinel indicating empty default positional args
}
// first default dict param, so make the map
EMIT_ARG(build_map, 0);
@@ -1009,6 +1010,7 @@ qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint
// the default keywords args may have already made the tuple; if not, do it now
if (comp->num_default_params > 0 && comp->num_dict_params == 0) {
EMIT_ARG(build_tuple, comp->num_default_params);
+ EMIT(load_null); // sentinel indicating empty default keyword args
}
#endif