summaryrefslogtreecommitdiff
path: root/py/emitnative.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-22 22:18:42 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-23 00:23:36 +1000
commit436e0d4c54ab22050072d392f0822e555bcc70f1 (patch)
tree17a1accb1b578441b9068f3dd005b32d46b3dc68 /py/emitnative.c
parentd97906ca9a0f1e0728cefb930d458bb8fba3bd17 (diff)
py/emit: Merge build set/slice into existing build emit function.
Reduces code size by: bare-arm: +0 minimal x86: +0 unix x64: -368 unix nanbox: -248 stm32: -128 cc3200: -48 esp8266: -184 esp32: -40
Diffstat (limited to 'py/emitnative.c')
-rw-r--r--py/emitnative.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index e06198bc9..331e4cf18 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1950,18 +1950,29 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
}
}
+#if MICROPY_PY_BUILTINS_SLICE
+STATIC void emit_native_build_slice(emit_t *emit, mp_uint_t n_args);
+#endif
+
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);
+ MP_STATIC_ASSERT(MP_F_BUILD_TUPLE + MP_EMIT_BUILD_SET == MP_F_BUILD_SET);
+ #if MICROPY_PY_BUILTINS_SLICE
+ if (kind == MP_EMIT_BUILD_SLICE) {
+ emit_native_build_slice(emit, n_args);
+ return;
+ }
+ #endif
emit_native_pre(emit);
- if (kind == MP_EMIT_BUILD_TUPLE || kind == MP_EMIT_BUILD_LIST) {
+ if (kind == MP_EMIT_BUILD_TUPLE || kind == MP_EMIT_BUILD_LIST || kind == MP_EMIT_BUILD_SET) {
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
+ emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple/list/map/set
}
STATIC void emit_native_store_map(emit_t *emit) {
@@ -1974,15 +1985,6 @@ STATIC void emit_native_store_map(emit_t *emit) {
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // map
}
-#if MICROPY_PY_BUILTINS_SET
-STATIC void emit_native_build_set(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_SET, n_args, REG_ARG_1);
- emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new set
-}
-#endif
-
#if MICROPY_PY_BUILTINS_SLICE
STATIC void emit_native_build_slice(emit_t *emit, mp_uint_t n_args) {
DEBUG_printf("build_slice %d\n", n_args);
@@ -2266,12 +2268,6 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
emit_native_binary_op,
emit_native_build,
emit_native_store_map,
- #if MICROPY_PY_BUILTINS_SET
- emit_native_build_set,
- #endif
- #if MICROPY_PY_BUILTINS_SLICE
- emit_native_build_slice,
- #endif
emit_native_store_comp,
emit_native_unpack_sequence,
emit_native_unpack_ex,