Commit eaf2e054 authored by Damien George's avatar Damien George

py: Switch to use #if instead of if-stmt for remaining misc items.

parent de145578
...@@ -61,9 +61,11 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ ...@@ -61,9 +61,11 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
{ {
kind = PRINT_REPR; 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); mp_printf(print, "%q(", self->base.type->name);
} }
#endif
mp_print_str(print, "{"); mp_print_str(print, "{");
size_t cur = 0; size_t cur = 0;
mp_map_elem_t *next = NULL; 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_ ...@@ -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_obj_print_helper(print, next->value, kind);
} }
mp_print_str(print, "}"); 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, ")"); 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) { 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) {
......
...@@ -429,11 +429,15 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { ...@@ -429,11 +429,15 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
#endif #endif
size_t index_val = mp_get_index(type, self_len, index, false); 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 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]); return MP_OBJ_NEW_SMALL_INT(self_data[index_val]);
} else { } else {
return mp_obj_new_str_via_qstr((char*)&self_data[index_val], 1); return mp_obj_new_str_via_qstr((char*)&self_data[index_val], 1);
} }
#endif
} else { } else {
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
} }
......
...@@ -1414,10 +1414,13 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i ...@@ -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 module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, false);
mp_obj_t ret; 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 // for compile only, return value is the module function
ret = module_fun; ret = module_fun;
} else { } else
#endif
{
// execute module function and get return value // execute module function and get return value
ret = mp_call_function_0(module_fun); ret = mp_call_function_0(module_fun);
} }
......
...@@ -841,14 +841,14 @@ unwind_jump:; ...@@ -841,14 +841,14 @@ unwind_jump:;
if ((unum & 3) == 0) { if ((unum & 3) == 0) {
mp_obj_list_append(obj, sp[0]); mp_obj_list_append(obj, sp[0]);
sp--; 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 #if MICROPY_PY_BUILTINS_SET
} else { } else if ((unum & 3) == 2) {
mp_obj_set_store(obj, sp[0]); mp_obj_set_store(obj, sp[0]);
sp--; sp--;
#endif #endif
} else {
mp_obj_dict_store(obj, sp[0], sp[-1]);
sp -= 2;
} }
// next opcode is always JUMP // next opcode is always JUMP
ip += 1; ip += 1;
......
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