summaryrefslogtreecommitdiff
path: root/py/emitbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-03-26 23:09:14 +0000
committerDamien George <damien.p.george@gmail.com>2014-03-26 23:09:14 +0000
commitd6f94340916bc5eabcf51d7afea523885adce818 (patch)
treebc59b126181dcf37868b72f5edbb6e74c1b0c1f3 /py/emitbc.c
parenteed6f26bed82969e3c9954159b17fe2733f4cb42 (diff)
parent2447a5b582503b70936681702062704e2e9f44d3 (diff)
Merge pull request #381 from pfalcon/closure-defargs
py: Support closures with default args.
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index ef5da3a62..653b14487 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -722,16 +722,20 @@ STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_param
emit_pre(emit, 1);
emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION, scope->unique_code_id);
} else {
- emit_bc_build_tuple(emit, n_default_params);
emit_pre(emit, 0);
emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION_DEFARGS, scope->unique_code_id);
}
}
STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
- assert(n_default_params == 0 && n_dict_params == 0);
- emit_pre(emit, 0);
- emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id);
+ assert(n_dict_params == 0);
+ if (n_default_params == 0) {
+ emit_pre(emit, 0);
+ emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id);
+ } else {
+ emit_pre(emit, -1);
+ emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE_DEFARGS, scope->unique_code_id);
+ }
}
STATIC void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {