diff options
author | Damien George <damien.p.george@gmail.com> | 2018-05-19 00:41:40 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-05-23 00:22:44 +1000 |
commit | 26b5754092134b53e03eed8c5e6c580d28a2a829 (patch) | |
tree | 64277980ddb209b7feeecdab2e4099b8b9bf38bc /py/emitnative.c | |
parent | e686c940525c5b87d02e3dd7bfcdec23cfa996dd (diff) |
py/emit: Combine build tuple/list/map emit funcs into one.
Reduces code size by:
bare-arm: -24
minimal x86: -192
unix x64: -288
unix nanbox: -184
stm32: -72
cc3200: -16
esp8266: -148
esp32: -32
Diffstat (limited to 'py/emitnative.c')
-rw-r--r-- | py/emitnative.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/py/emitnative.c b/py/emitnative.c index 26bcebfcb..3b4e9edb2 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -1923,26 +1923,18 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { } } -STATIC void emit_native_build_tuple(emit_t *emit, mp_uint_t n_args) { +STATIC void emit_native_build(emit_t *emit, mp_uint_t n_args, int kind) { // for viper: call runtime, with types of args // if wrapped in byte_array, or something, allocates memory and fills it + MP_STATIC_ASSERT(MP_F_BUILD_TUPLE + MP_EMIT_BUILD_TUPLE == MP_F_BUILD_TUPLE); + MP_STATIC_ASSERT(MP_F_BUILD_TUPLE + MP_EMIT_BUILD_LIST == MP_F_BUILD_LIST); + MP_STATIC_ASSERT(MP_F_BUILD_TUPLE + MP_EMIT_BUILD_MAP == MP_F_BUILD_MAP); emit_native_pre(emit); - emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items - emit_call_with_imm_arg(emit, MP_F_BUILD_TUPLE, n_args, REG_ARG_1); - emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple -} - -STATIC void emit_native_build_list(emit_t *emit, mp_uint_t n_args) { - emit_native_pre(emit); - emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items - emit_call_with_imm_arg(emit, MP_F_BUILD_LIST, n_args, REG_ARG_1); - emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new list -} - -STATIC void emit_native_build_map(emit_t *emit, mp_uint_t n_args) { - emit_native_pre(emit); - emit_call_with_imm_arg(emit, MP_F_BUILD_MAP, n_args, REG_ARG_1); - emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map + if (kind == MP_EMIT_BUILD_TUPLE || kind == MP_EMIT_BUILD_LIST) { + emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items + } + emit_call_with_imm_arg(emit, MP_F_BUILD_TUPLE + kind, n_args, REG_ARG_1); + emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple/list/map } STATIC void emit_native_store_map(emit_t *emit) { @@ -2255,9 +2247,7 @@ const emit_method_table_t EXPORT_FUN(method_table) = { emit_native_pop_except, emit_native_unary_op, emit_native_binary_op, - emit_native_build_tuple, - emit_native_build_list, - emit_native_build_map, + emit_native_build, emit_native_store_map, #if MICROPY_PY_BUILTINS_SET emit_native_build_set, |