summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitcpy.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/emitcpy.c
parentbc5f0c19775e23b4f0621d52de47fb9438a78ba2 (diff)
downloadmicropython-3558f62fb5c21a19a518c2ba75860f0b5963219e.tar.gz
micropython-3558f62fb5c21a19a518c2ba75860f0b5963219e.zip
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/emitcpy.c')
-rw-r--r--py/emitcpy.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/py/emitcpy.c b/py/emitcpy.c
index 119cf818cf..e90b5c428a 100644
--- a/py/emitcpy.c
+++ b/py/emitcpy.c
@@ -228,6 +228,11 @@ STATIC void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) {
}
}
+STATIC void emit_cpy_load_null(emit_t *emit) {
+ // unused for cpy
+ assert(0);
+}
+
STATIC void emit_cpy_load_fast(emit_t *emit, qstr qstr, uint id_flags, int local_num) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
@@ -764,7 +769,8 @@ STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, uint n_pos_defa
}
}
-STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
+STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, uint n_closed_over, uint n_pos_defaults, uint n_kw_defaults) {
+ emit_cpy_build_tuple(emit, n_closed_over);
load_cpy_const_code_and_name(emit, scope->simple_name);
emit_pre(emit, -2 - n_pos_defaults - 2 * n_kw_defaults, 3);
if (emit->pass == PASS_3) {
@@ -815,6 +821,7 @@ const emit_method_table_t emit_cpython_method_table = {
emit_cpy_load_const_id,
emit_cpy_load_const_str,
emit_cpy_load_const_verbatim_str,
+ emit_cpy_load_null,
emit_cpy_load_fast,
emit_cpy_load_deref,
emit_cpy_load_closure,