diff options
author | David Lechner <david@lechnology.com> | 2020-03-24 21:39:46 -0500 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-03-31 16:54:00 +1100 |
commit | 1e99d29f362f8cccc60a36fcbd8590404c719f40 (patch) | |
tree | 05f686b181fdb078dbc2595809f2e24d2fa3a2db /py/emitbc.c | |
parent | bb70874111dbb246624a68c013e8f1c3245ca0d8 (diff) |
py/runtime: Allow multiple **args in a function call.
This is a partial implementation of PEP 448 to allow multiple ** unpackings
when calling a function or method.
The compiler is modified to encode the argument as a None: obj key-value
pair (similar to how regular keyword arguments are encoded as str: obj
pairs). The extra object that was pushed on the stack to hold a single **
unpacking object is no longer used and is removed.
The runtime is modified to decode this new format.
Signed-off-by: David Lechner <david@pybricks.com>
Diffstat (limited to 'py/emitbc.c')
-rw-r--r-- | py/emitbc.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index 1f5cd9d32..21ec12191 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -752,7 +752,9 @@ void mp_emit_bc_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_ov STATIC void emit_bc_call_function_method_helper(emit_t *emit, int stack_adj, mp_uint_t bytecode_base, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { if (star_flags) { - stack_adj -= (int)n_positional + 2 * (int)n_keyword + 2; + // each positional arg is one object, each kwarg is two objects, the key + // and the value and one extra object for the star args bitmap. + stack_adj -= (int)n_positional + 2 * (int)n_keyword + 1; emit_write_bytecode_byte_uint(emit, stack_adj, bytecode_base + 1, (n_keyword << 8) | n_positional); // TODO make it 2 separate uints? } else { stack_adj -= (int)n_positional + 2 * (int)n_keyword; |