From eaf2e054c3e6520c3954065fb06025680281a5ca Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 20 Feb 2018 19:47:39 +1100 Subject: [PATCH] py: Switch to use #if instead of if-stmt for remaining misc items. --- py/objdict.c | 8 ++++++-- py/objstr.c | 6 +++++- py/runtime.c | 7 +++++-- py/vm.c | 8 ++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/py/objdict.c b/py/objdict.c index 0a85bcbe..954a43a6 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -61,9 +61,11 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ { kind = PRINT_REPR; } - if (MICROPY_PY_COLLECTIONS_ORDEREDDICT && self->base.type != &mp_type_dict) { + #if MICROPY_PY_COLLECTIONS_ORDEREDDICT + if (self->base.type != &mp_type_dict) { mp_printf(print, "%q(", self->base.type->name); } + #endif mp_print_str(print, "{"); size_t cur = 0; mp_map_elem_t *next = NULL; @@ -77,9 +79,11 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ mp_obj_print_helper(print, next->value, kind); } mp_print_str(print, "}"); - if (MICROPY_PY_COLLECTIONS_ORDEREDDICT && self->base.type != &mp_type_dict) { + #if MICROPY_PY_COLLECTIONS_ORDEREDDICT + if (self->base.type != &mp_type_dict) { mp_print_str(print, ")"); } + #endif } STATIC mp_obj_t dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { diff --git a/py/objstr.c b/py/objstr.c index e83e5bda..21948f73 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -429,11 +429,15 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { #endif size_t index_val = mp_get_index(type, self_len, index, false); // If we have unicode enabled the type will always be bytes, so take the short cut. - if (MICROPY_PY_BUILTINS_STR_UNICODE || type == &mp_type_bytes) { + #if MICROPY_PY_BUILTINS_STR_UNICODE + return MP_OBJ_NEW_SMALL_INT(self_data[index_val]); + #else + if (type == &mp_type_bytes) { return MP_OBJ_NEW_SMALL_INT(self_data[index_val]); } else { return mp_obj_new_str_via_qstr((char*)&self_data[index_val], 1); } + #endif } else { return MP_OBJ_NULL; // op not supported } diff --git a/py/runtime.c b/py/runtime.c index 2cac5295..9b9227a1 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1414,10 +1414,13 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, false); mp_obj_t ret; - if (MICROPY_PY_BUILTINS_COMPILE && globals == NULL) { + #if MICROPY_PY_BUILTINS_COMPILE + if (globals == NULL) { // for compile only, return value is the module function ret = module_fun; - } else { + } else + #endif + { // execute module function and get return value ret = mp_call_function_0(module_fun); } diff --git a/py/vm.c b/py/vm.c index 9b01a113..f2d94e0a 100644 --- a/py/vm.c +++ b/py/vm.c @@ -841,14 +841,14 @@ unwind_jump:; if ((unum & 3) == 0) { mp_obj_list_append(obj, sp[0]); sp--; - } else if (!MICROPY_PY_BUILTINS_SET || (unum & 3) == 1) { - mp_obj_dict_store(obj, sp[0], sp[-1]); - sp -= 2; #if MICROPY_PY_BUILTINS_SET - } else { + } else if ((unum & 3) == 2) { mp_obj_set_store(obj, sp[0]); sp--; #endif + } else { + mp_obj_dict_store(obj, sp[0], sp[-1]); + sp -= 2; } // next opcode is always JUMP ip += 1; -- GitLab