Commit 3056509e authored by Damien George's avatar Damien George
Browse files

py: Rename and reorder parameters in emit_make_function/closure.

In preparation for implementing default keyword arguments.
parent e0f2979a
...@@ -774,11 +774,14 @@ void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_kind) { ...@@ -774,11 +774,14 @@ void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_kind) {
} }
// stuff for lambda and comprehensions and generators // stuff for lambda and comprehensions and generators
void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_params, int n_default_params) { void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_pos_defaults, int n_kw_defaults) {
assert(n_pos_defaults >= 0);
assert(n_kw_defaults >= 0);
#if !MICROPY_EMIT_CPYTHON #if !MICROPY_EMIT_CPYTHON
// in Micro Python we put the default params into a tuple using the bytecode // in Micro Python we put the default params into a tuple using the bytecode
if (n_default_params) { if (n_pos_defaults) {
EMIT_ARG(build_tuple, n_default_params); EMIT_ARG(build_tuple, n_pos_defaults);
} }
#endif #endif
...@@ -807,10 +810,10 @@ void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_ ...@@ -807,10 +810,10 @@ void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_
// make the function/closure // make the function/closure
if (nfree == 0) { if (nfree == 0) {
EMIT_ARG(make_function, this_scope, n_dict_params, n_default_params); EMIT_ARG(make_function, this_scope, n_pos_defaults, n_kw_defaults);
} else { } else {
EMIT_ARG(build_tuple, nfree); EMIT_ARG(build_tuple, nfree);
EMIT_ARG(make_closure, this_scope, n_dict_params, n_default_params); EMIT_ARG(make_closure, this_scope, n_pos_defaults, n_kw_defaults);
} }
} }
...@@ -921,7 +924,7 @@ qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint ...@@ -921,7 +924,7 @@ qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint
scope_t *fscope = (scope_t*)pns->nodes[4]; scope_t *fscope = (scope_t*)pns->nodes[4];
// make the function // make the function
close_over_variables_etc(comp, fscope, comp->param_pass_num_dict_params, comp->param_pass_num_default_params); close_over_variables_etc(comp, fscope, comp->param_pass_num_default_params, comp->param_pass_num_dict_params);
// restore variables // restore variables
comp->have_bare_star = old_have_bare_star; comp->have_bare_star = old_have_bare_star;
......
...@@ -97,8 +97,8 @@ typedef struct _emit_method_table_t { ...@@ -97,8 +97,8 @@ typedef struct _emit_method_table_t {
void (*build_slice)(emit_t *emit, int n_args); void (*build_slice)(emit_t *emit, int n_args);
void (*unpack_sequence)(emit_t *emit, int n_args); void (*unpack_sequence)(emit_t *emit, int n_args);
void (*unpack_ex)(emit_t *emit, int n_left, int n_right); void (*unpack_ex)(emit_t *emit, int n_left, int n_right);
void (*make_function)(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params); void (*make_function)(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults);
void (*make_closure)(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params); void (*make_closure)(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults);
void (*call_function)(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg); void (*call_function)(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg);
void (*call_method)(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg); void (*call_method)(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg);
void (*return_value)(emit_t *emit); void (*return_value)(emit_t *emit);
......
...@@ -726,9 +726,9 @@ STATIC void emit_bc_unpack_ex(emit_t *emit, int n_left, int n_right) { ...@@ -726,9 +726,9 @@ STATIC void emit_bc_unpack_ex(emit_t *emit, int n_left, int n_right) {
emit_write_byte_code_byte_uint(emit, MP_BC_UNPACK_EX, n_left | (n_right << 8)); emit_write_byte_code_byte_uint(emit, MP_BC_UNPACK_EX, n_left | (n_right << 8));
} }
STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
assert(n_dict_params == 0); assert(n_kw_defaults == 0);
if (n_default_params == 0) { if (n_pos_defaults == 0) {
emit_bc_pre(emit, 1); emit_bc_pre(emit, 1);
emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION, scope->unique_code_id); emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_FUNCTION, scope->unique_code_id);
} else { } else {
...@@ -737,9 +737,9 @@ STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_param ...@@ -737,9 +737,9 @@ STATIC void emit_bc_make_function(emit_t *emit, scope_t *scope, int n_dict_param
} }
} }
STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { STATIC void emit_bc_make_closure(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
assert(n_dict_params == 0); assert(n_kw_defaults == 0);
if (n_default_params == 0) { if (n_pos_defaults == 0) {
emit_bc_pre(emit, 0); emit_bc_pre(emit, 0);
emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id); emit_write_byte_code_byte_uint(emit, MP_BC_MAKE_CLOSURE, scope->unique_code_id);
} else { } else {
......
...@@ -759,19 +759,19 @@ STATIC void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) { ...@@ -759,19 +759,19 @@ STATIC void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) {
} }
} }
STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
load_cpy_const_code_and_name(emit, scope->simple_name); load_cpy_const_code_and_name(emit, scope->simple_name);
emit_pre(emit, -1 - n_default_params - 2 * n_dict_params, 3); emit_pre(emit, -1 - n_pos_defaults - 2 * n_kw_defaults, 3);
if (emit->pass == PASS_3) { if (emit->pass == PASS_3) {
printf("MAKE_FUNCTION %d\n", (n_dict_params << 8) | n_default_params); printf("MAKE_FUNCTION %d\n", (n_kw_defaults << 8) | n_pos_defaults);
} }
} }
STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
load_cpy_const_code_and_name(emit, scope->simple_name); load_cpy_const_code_and_name(emit, scope->simple_name);
emit_pre(emit, -2 - n_default_params - 2 * n_dict_params, 3); emit_pre(emit, -2 - n_pos_defaults - 2 * n_kw_defaults, 3);
if (emit->pass == PASS_3) { if (emit->pass == PASS_3) {
printf("MAKE_CLOSURE %d\n", (n_dict_params << 8) | n_default_params); printf("MAKE_CLOSURE %d\n", (n_kw_defaults << 8) | n_pos_defaults);
} }
} }
......
...@@ -1142,15 +1142,15 @@ STATIC void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) { ...@@ -1142,15 +1142,15 @@ STATIC void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) {
assert(0); assert(0);
} }
STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
// call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them // call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them
assert(n_default_params == 0 && n_dict_params == 0); assert(n_pos_defaults == 0 && n_kw_defaults == 0);
emit_native_pre(emit); emit_native_pre(emit);
emit_call_with_imm_arg(emit, MP_F_MAKE_FUNCTION_FROM_ID, mp_make_function_from_id, scope->unique_code_id, REG_ARG_1); emit_call_with_imm_arg(emit, MP_F_MAKE_FUNCTION_FROM_ID, mp_make_function_from_id, scope->unique_code_id, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
} }
STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
assert(0); assert(0);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment