From 3558f62fb5c21a19a518c2ba75860f0b5963219e Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 20 Apr 2014 17:50:40 +0100 Subject: 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. --- py/emitcpy.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'py/emitcpy.c') diff --git a/py/emitcpy.c b/py/emitcpy.c index 119cf818c..e90b5c428 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, -- cgit v1.2.3