Skip to content

Commit a1b18b3

Browse files
committed
py: Removing dangling "else" to improve code format consistency.
1 parent 4b23e98 commit a1b18b3

File tree

8 files changed

+39
-32
lines changed

8 files changed

+39
-32
lines changed

py/binary.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,19 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
297297
if (mp_obj_is_type(val_in, &mp_type_int)) {
298298
mp_obj_int_to_bytes_impl(val_in, struct_type == '>', size, p);
299299
return;
300-
} else
300+
}
301301
#endif
302-
{
303-
val = mp_obj_get_int(val_in);
304-
// zero/sign extend if needed
305-
if (BYTES_PER_WORD < 8 && size > sizeof(val)) {
306-
int c = (is_signed(val_type) && (mp_int_t)val < 0) ? 0xff : 0x00;
307-
memset(p, c, size);
308-
if (struct_type == '>') {
309-
p += size - sizeof(val);
310-
}
302+
303+
val = mp_obj_get_int(val_in);
304+
// zero/sign extend if needed
305+
if (BYTES_PER_WORD < 8 && size > sizeof(val)) {
306+
int c = (is_signed(val_type) && (mp_int_t)val < 0) ? 0xff : 0x00;
307+
memset(p, c, size);
308+
if (struct_type == '>') {
309+
p += size - sizeof(val);
311310
}
312311
}
312+
break;
313313
}
314314

315315
mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val);

py/emitinlinethumb.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,10 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
521521
} else {
522522
goto unknown_op;
523523
}
524-
} else
524+
return;
525+
}
525526
#endif
527+
526528
if (n_args == 0) {
527529
if (op == MP_QSTR_nop) {
528530
asm_thumb_op16(&emit->as, ASM_THUMB_OP_NOP);

py/emitnative.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -2318,15 +2318,19 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
23182318
int reg_rhs = REG_ARG_3;
23192319
emit_pre_pop_reg_flexible(emit, &vtype_rhs, &reg_rhs, REG_RET, REG_ARG_2);
23202320
emit_pre_pop_reg(emit, &vtype_lhs, REG_ARG_2);
2321+
23212322
#if !(N_X64 || N_X86)
2322-
if (op == MP_BINARY_OP_LSHIFT) {
2323-
ASM_LSL_REG_REG(emit->as, REG_ARG_2, reg_rhs);
2324-
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
2325-
} else if (op == MP_BINARY_OP_RSHIFT) {
2326-
ASM_ASR_REG_REG(emit->as, REG_ARG_2, reg_rhs);
2323+
if (op == MP_BINARY_OP_LSHIFT || op == MP_BINARY_OP_RSHIFT) {
2324+
if (op == MP_BINARY_OP_LSHIFT) {
2325+
ASM_LSL_REG_REG(emit->as, REG_ARG_2, reg_rhs);
2326+
} else {
2327+
ASM_ASR_REG_REG(emit->as, REG_ARG_2, reg_rhs);
2328+
}
23272329
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
2328-
} else
2330+
return;
2331+
}
23292332
#endif
2333+
23302334
if (op == MP_BINARY_OP_OR) {
23312335
ASM_OR_REG_REG(emit->as, REG_ARG_2, reg_rhs);
23322336
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);

py/objdict.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ STATIC mp_obj_t dict_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_
141141
}
142142
}
143143
return e1 == NULL && e2 == NULL ? mp_const_true : mp_const_false;
144-
} else
144+
}
145145
#endif
146+
146147
if (mp_obj_is_type(rhs_in, &mp_type_dict)) {
147148
mp_obj_dict_t *rhs = MP_OBJ_TO_PTR(rhs_in);
148149
if (o->map.used != rhs->map.used) {

py/objfloat.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,12 @@ STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
159159

160160
STATIC mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
161161
mp_float_t lhs_val = mp_obj_float_get(lhs_in);
162-
#if MICROPY_PY_BUILTINS_COMPLEX
162+
#if MICROPY_PY_BUILTINS_COMPLEX
163163
if (mp_obj_is_type(rhs_in, &mp_type_complex)) {
164164
return mp_obj_complex_binary_op(op, lhs_val, 0, rhs_in);
165-
} else
166-
#endif
167-
{
168-
return mp_obj_float_binary_op(op, lhs_val, rhs_in);
169165
}
166+
#endif
167+
return mp_obj_float_binary_op(op, lhs_val, rhs_in);
170168
}
171169

172170
const mp_obj_type_t mp_type_float = {

py/objfun.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,12 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
456456
return (mp_uint_t)mp_obj_str_get_data(obj, &l);
457457
} else {
458458
const mp_obj_type_t *type = mp_obj_get_type(obj);
459-
#if MICROPY_PY_BUILTINS_FLOAT
459+
#if MICROPY_PY_BUILTINS_FLOAT
460460
if (type == &mp_type_float) {
461461
// convert float to int (could also pass in float registers)
462462
return (mp_int_t)mp_obj_float_get(obj);
463-
} else
464-
#endif
463+
}
464+
#endif
465465
if (type == &mp_type_tuple || type == &mp_type_list) {
466466
// pointer to start of tuple (could pass length, but then could use len(x) for that)
467467
size_t len;

py/objint_mpz.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
194194
return mp_obj_int_binary_op_extra_cases(op, lhs_in, rhs_in);
195195
}
196196

197-
#if MICROPY_PY_BUILTINS_FLOAT
197+
#if MICROPY_PY_BUILTINS_FLOAT
198198
if (op == MP_BINARY_OP_TRUE_DIVIDE || op == MP_BINARY_OP_INPLACE_TRUE_DIVIDE) {
199199
if (mpz_is_zero(zrhs)) {
200200
goto zero_division_error;
201201
}
202202
mp_float_t flhs = mpz_as_float(zlhs);
203203
mp_float_t frhs = mpz_as_float(zrhs);
204204
return mp_obj_new_float(flhs / frhs);
205-
} else
206-
#endif
205+
}
206+
#endif
207207

208208
if (op >= MP_BINARY_OP_INPLACE_OR && op < MP_BINARY_OP_CONTAINS) {
209209
mp_obj_int_t *res = mp_obj_int_new_mpz();

py/runtime.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -1056,12 +1056,14 @@ void mp_load_method_maybe(mp_obj_t obj, qstr attr, mp_obj_t *dest) {
10561056
const mp_obj_type_t *type = mp_obj_get_type(obj);
10571057

10581058
// look for built-in names
1059-
#if MICROPY_CPYTHON_COMPAT
1059+
#if MICROPY_CPYTHON_COMPAT
10601060
if (attr == MP_QSTR___class__) {
10611061
// a.__class__ is equivalent to type(a)
10621062
dest[0] = MP_OBJ_FROM_PTR(type);
1063-
} else
1064-
#endif
1063+
return;
1064+
}
1065+
#endif
1066+
10651067
if (attr == MP_QSTR___next__ && type->iternext != NULL) {
10661068
dest[0] = MP_OBJ_FROM_PTR(&mp_builtin_next_obj);
10671069
dest[1] = obj;

0 commit comments

Comments
 (0)