summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-09-23 11:47:01 +0100
committerDamien George <damien.p.george@gmail.com>2015-09-23 11:47:01 +0100
commitfbcaf0ea18d647adc445dc1029392c2a908cf540 (patch)
treea58fc009888d9cfdcb2dd5c07499e848228329fb /py
parente6978a4e26a17ef473e2aad78662d3bf29638578 (diff)
downloadmicropython-fbcaf0ea18d647adc445dc1029392c2a908cf540.tar.gz
micropython-fbcaf0ea18d647adc445dc1029392c2a908cf540.zip
py: Slightly simplify compile and emit of star/double-star arguments.
Saves a few bytes of code space and eliminates need for rot_two bytecode (hence saving RAM and execution time, by a tiny bit).
Diffstat (limited to 'py')
-rw-r--r--py/compile.c17
-rw-r--r--py/emitbc.c8
-rw-r--r--py/emitnative.c16
3 files changed, 12 insertions, 29 deletions
diff --git a/py/compile.c b/py/compile.c
index 9ac37c6d95..82a27bb0b8 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2252,11 +2252,18 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
}
// compile the star/double-star arguments if we had them
- if (star_args_node != NULL) {
- compile_node(comp, star_args_node->nodes[0]);
- }
- if (dblstar_args_node != NULL) {
- compile_node(comp, dblstar_args_node->nodes[0]);
+ // if we had one but not the other then we load "null" as a place holder
+ if (star_flags != 0) {
+ if (star_args_node == NULL) {
+ EMIT(load_null);
+ } else {
+ compile_node(comp, star_args_node->nodes[0]);
+ }
+ if (dblstar_args_node == NULL) {
+ EMIT(load_null);
+ } else {
+ compile_node(comp, dblstar_args_node->nodes[0]);
+ }
}
// emit the function/method call
diff --git a/py/emitbc.c b/py/emitbc.c
index 63e7bc3f9d..71ed4afd86 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -859,14 +859,6 @@ 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, mp_int_t 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) {
- if (!(star_flags & MP_EMIT_STAR_FLAG_SINGLE)) {
- // load dummy entry for non-existent pos_seq
- mp_emit_bc_load_null(emit);
- mp_emit_bc_rot_two(emit);
- } else if (!(star_flags & MP_EMIT_STAR_FLAG_DOUBLE)) {
- // load dummy entry for non-existent kw_dict
- mp_emit_bc_load_null(emit);
- }
emit_bc_pre(emit, stack_adj - (mp_int_t)n_positional - 2 * (mp_int_t)n_keyword - 2);
emit_write_bytecode_byte_uint(emit, bytecode_base + 1, (n_keyword << 8) | n_positional); // TODO make it 2 separate uints?
} else {
diff --git a/py/emitnative.c b/py/emitnative.c
index af7fbc5510..43dbcf06cb 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -2316,14 +2316,6 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u
} else {
assert(vtype_fun == VTYPE_PYOBJ);
if (star_flags) {
- if (!(star_flags & MP_EMIT_STAR_FLAG_SINGLE)) {
- // load dummy entry for non-existent pos_seq
- emit_native_load_null(emit);
- emit_native_rot_two(emit);
- } else if (!(star_flags & MP_EMIT_STAR_FLAG_DOUBLE)) {
- // load dummy entry for non-existent kw_dict
- emit_native_load_null(emit);
- }
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional + 2 * n_keyword + 3); // pointer to args
emit_call_with_2_imm_args(emit, MP_F_CALL_METHOD_N_KW_VAR, 0, REG_ARG_1, n_positional | (n_keyword << 8), REG_ARG_2);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
@@ -2340,14 +2332,6 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u
STATIC void emit_native_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) {
if (star_flags) {
- if (!(star_flags & MP_EMIT_STAR_FLAG_SINGLE)) {
- // load dummy entry for non-existent pos_seq
- emit_native_load_null(emit);
- emit_native_rot_two(emit);
- } else if (!(star_flags & MP_EMIT_STAR_FLAG_DOUBLE)) {
- // load dummy entry for non-existent kw_dict
- emit_native_load_null(emit);
- }
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional + 2 * n_keyword + 4); // pointer to args
emit_call_with_2_imm_args(emit, MP_F_CALL_METHOD_N_KW_VAR, 1, REG_ARG_1, n_positional | (n_keyword << 8), REG_ARG_2);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);