Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 58321dd

Browse files
committed
all: Convert mp_uint_t to mp_unary_op_t/mp_binary_op_t where appropriate
The unary-op/binary-op enums are already defined, and there are no arithmetic tricks used with these types, so it makes sense to use the correct enum type for arguments that take these values. It also reduces code size quite a bit for nan-boxing builds.
1 parent be8e574 commit 58321dd

25 files changed

+54
-52
lines changed

extmod/modbtree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
281281
}
282282
}
283283

284-
STATIC mp_obj_t btree_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
284+
STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
285285
mp_obj_btree_t *self = MP_OBJ_TO_PTR(lhs_in);
286286
switch (op) {
287287
case MP_BINARY_OP_IN: {

extmod/modutimeq.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ STATIC mp_obj_t mod_utimeq_dump(mp_obj_t heap_in) {
189189
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_dump_obj, mod_utimeq_dump);
190190
#endif
191191

192-
STATIC mp_obj_t utimeq_unary_op(mp_uint_t op, mp_obj_t self_in) {
192+
STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
193193
mp_obj_utimeq_t *self = MP_OBJ_TO_PTR(self_in);
194194
switch (op) {
195195
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);

py/obj.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flag
505505
}
506506
}
507507

508-
mp_obj_t mp_generic_unary_op(mp_uint_t op, mp_obj_t o_in) {
508+
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
509509
switch (op) {
510510
case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT((mp_uint_t)o_in);
511511
default: return MP_OBJ_NULL; // op not supported

py/obj.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "py/misc.h"
3131
#include "py/qstr.h"
3232
#include "py/mpprint.h"
33+
#include "py/runtime0.h"
3334

3435
// This is the definition of the opaque MicroPython object type.
3536
// All concrete objects have an encoding within this type and the
@@ -429,8 +430,8 @@ typedef struct _mp_obj_iter_buf_t {
429430
typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind);
430431
typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
431432
typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args);
432-
typedef mp_obj_t (*mp_unary_op_fun_t)(mp_uint_t op, mp_obj_t);
433-
typedef mp_obj_t (*mp_binary_op_fun_t)(mp_uint_t op, mp_obj_t, mp_obj_t);
433+
typedef mp_obj_t (*mp_unary_op_fun_t)(mp_unary_op_t op, mp_obj_t);
434+
typedef mp_obj_t (*mp_binary_op_fun_t)(mp_binary_op_t op, mp_obj_t, mp_obj_t);
434435
typedef void (*mp_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
435436
typedef mp_obj_t (*mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
436437
typedef mp_obj_t (*mp_getiter_fun_t)(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
@@ -694,7 +695,7 @@ mp_obj_t mp_obj_id(mp_obj_t o_in);
694695
mp_obj_t mp_obj_len(mp_obj_t o_in);
695696
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL
696697
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
697-
mp_obj_t mp_generic_unary_op(mp_uint_t op, mp_obj_t o_in);
698+
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in);
698699

699700
// cell
700701
mp_obj_t mp_obj_cell_get(mp_obj_t self_in);
@@ -734,11 +735,11 @@ mp_int_t mp_float_hash(mp_float_t val);
734735
#else
735736
static inline mp_int_t mp_float_hash(mp_float_t val) { return (mp_int_t)val; }
736737
#endif
737-
mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
738+
mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
738739

739740
// complex
740741
void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
741-
mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NULL if op not supported
742+
mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NULL if op not supported
742743
#else
743744
#define mp_obj_is_float(o) (false)
744745
#endif

py/objarray.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args,
231231
}
232232
#endif
233233

234-
STATIC mp_obj_t array_unary_op(mp_uint_t op, mp_obj_t o_in) {
234+
STATIC mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
235235
mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in);
236236
switch (op) {
237237
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->len != 0);
@@ -240,7 +240,7 @@ STATIC mp_obj_t array_unary_op(mp_uint_t op, mp_obj_t o_in) {
240240
}
241241
}
242242

243-
STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
243+
STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
244244
mp_obj_array_t *lhs = MP_OBJ_TO_PTR(lhs_in);
245245
switch (op) {
246246
case MP_BINARY_OP_ADD: {

py/objbool.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
6363
}
6464
}
6565

66-
STATIC mp_obj_t bool_unary_op(mp_uint_t op, mp_obj_t o_in) {
66+
STATIC mp_obj_t bool_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
6767
if (op == MP_UNARY_OP_LEN) {
6868
return MP_OBJ_NULL;
6969
}
7070
mp_obj_bool_t *self = MP_OBJ_TO_PTR(o_in);
7171
return mp_unary_op(op, MP_OBJ_NEW_SMALL_INT(self->value));
7272
}
7373

74-
STATIC mp_obj_t bool_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
74+
STATIC mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
7575
mp_obj_bool_t *self = MP_OBJ_TO_PTR(lhs_in);
7676
return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(self->value), rhs_in);
7777
}

py/objcomplex.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, si
117117
}
118118
}
119119

120-
STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) {
120+
STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
121121
mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in);
122122
switch (op) {
123123
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->real != 0 || o->imag != 0);
@@ -128,7 +128,7 @@ STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) {
128128
}
129129
}
130130

131-
STATIC mp_obj_t complex_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
131+
STATIC mp_obj_t complex_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
132132
mp_obj_complex_t *lhs = MP_OBJ_TO_PTR(lhs_in);
133133
return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in);
134134
}
@@ -171,7 +171,7 @@ void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag) {
171171
*imag = self->imag;
172172
}
173173

174-
mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in) {
174+
mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in) {
175175
mp_float_t rhs_real, rhs_imag;
176176
mp_obj_get_complex(rhs_in, &rhs_real, &rhs_imag); // can be any type, this function will convert to float (if possible)
177177
switch (op) {

py/objdict.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ STATIC mp_obj_t dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
100100
return dict_out;
101101
}
102102

103-
STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) {
103+
STATIC mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
104104
mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
105105
switch (op) {
106106
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->map.used != 0);
@@ -115,7 +115,7 @@ STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) {
115115
}
116116
}
117117

118-
STATIC mp_obj_t dict_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
118+
STATIC mp_obj_t dict_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
119119
mp_obj_dict_t *o = MP_OBJ_TO_PTR(lhs_in);
120120
switch (op) {
121121
case MP_BINARY_OP_IN: {
@@ -482,7 +482,7 @@ STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
482482
mp_print_str(print, "])");
483483
}
484484

485-
STATIC mp_obj_t dict_view_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
485+
STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
486486
// only supported for the 'keys' kind until sets and dicts are refactored
487487
mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(lhs_in);
488488
if (o->kind != MP_DICT_VIEW_KEYS) {

py/objfloat.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size
155155
}
156156
}
157157

158-
STATIC mp_obj_t float_unary_op(mp_uint_t op, mp_obj_t o_in) {
158+
STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
159159
mp_float_t val = mp_obj_float_get(o_in);
160160
switch (op) {
161161
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(val != 0);
@@ -166,7 +166,7 @@ STATIC mp_obj_t float_unary_op(mp_uint_t op, mp_obj_t o_in) {
166166
}
167167
}
168168

169-
STATIC mp_obj_t float_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
169+
STATIC mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
170170
mp_float_t lhs_val = mp_obj_float_get(lhs_in);
171171
#if MICROPY_PY_BUILTINS_COMPLEX
172172
if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_complex)) {
@@ -239,7 +239,7 @@ STATIC void mp_obj_float_divmod(mp_float_t *x, mp_float_t *y) {
239239
*y = mod;
240240
}
241241

242-
mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_in) {
242+
mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t rhs_in) {
243243
mp_float_t rhs_val = mp_obj_get_float(rhs_in); // can be any type, this function will convert to float (if possible)
244244
switch (op) {
245245
case MP_BINARY_OP_ADD:

py/objint.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,12 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
325325
}
326326

327327
// This is called for operations on SMALL_INT that are not handled by mp_unary_op
328-
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
328+
mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
329329
return MP_OBJ_NULL; // op not supported
330330
}
331331

332332
// This is called for operations on SMALL_INT that are not handled by mp_binary_op
333-
mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
333+
mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
334334
return mp_obj_int_binary_op_extra_cases(op, lhs_in, rhs_in);
335335
}
336336

@@ -382,7 +382,7 @@ mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
382382

383383
// This dispatcher function is expected to be independent of the implementation of long int
384384
// It handles the extra cases for integer-like arithmetic
385-
mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
385+
mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
386386
if (rhs_in == mp_const_false) {
387387
// false acts as 0
388388
return mp_binary_op(op, lhs_in, MP_OBJ_NEW_SMALL_INT(0));

py/objint.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ mp_obj_t mp_obj_int_from_bytes_impl(bool big_endian, size_t len, const byte *buf
5858
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf);
5959
int mp_obj_int_sign(mp_obj_t self_in);
6060
mp_obj_t mp_obj_int_abs(mp_obj_t self_in);
61-
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in);
62-
mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
63-
mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
61+
mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in);
62+
mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
63+
mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
6464
mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus);
6565

6666
#endif // MICROPY_INCLUDED_PY_OBJINT_H

py/objint_longlong.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
118118
}
119119
}
120120

121-
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
121+
mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
122122
mp_obj_int_t *o = o_in;
123123
switch (op) {
124124
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->val != 0);
@@ -134,7 +134,7 @@ mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
134134
}
135135
}
136136

137-
mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
137+
mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
138138
long long lhs_val;
139139
long long rhs_val;
140140

py/objint_mpz.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
162162
}
163163
}
164164

165-
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
165+
mp_obj_t mp_obj_int_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
166166
mp_obj_int_t *o = MP_OBJ_TO_PTR(o_in);
167167
switch (op) {
168168
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(!mpz_is_zero(&o->mpz));
@@ -174,7 +174,7 @@ mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
174174
}
175175
}
176176

177-
mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
177+
mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
178178
const mpz_t *zlhs;
179179
const mpz_t *zrhs;
180180
mpz_t z_int;

py/objlist.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ STATIC bool list_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in)
9999
return mp_seq_cmp_objs(op, self->items, self->len, another->items, another->len);
100100
}
101101

102-
STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) {
102+
STATIC mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
103103
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
104104
switch (op) {
105105
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
@@ -114,7 +114,7 @@ STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) {
114114
}
115115
}
116116

117-
STATIC mp_obj_t list_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
117+
STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
118118
mp_obj_list_t *o = MP_OBJ_TO_PTR(lhs);
119119
switch (op) {
120120
case MP_BINARY_OP_ADD: {

py/objrange.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ STATIC mp_int_t range_len(mp_obj_range_t *self) {
130130
return len;
131131
}
132132

133-
STATIC mp_obj_t range_unary_op(mp_uint_t op, mp_obj_t self_in) {
133+
STATIC mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
134134
mp_obj_range_t *self = MP_OBJ_TO_PTR(self_in);
135135
mp_int_t len = range_len(self);
136136
switch (op) {

py/objset.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ STATIC mp_obj_t set_union(mp_obj_t self_in, mp_obj_t other_in) {
455455
}
456456
STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union);
457457

458-
STATIC mp_obj_t set_unary_op(mp_uint_t op, mp_obj_t self_in) {
458+
STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
459459
mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in);
460460
switch (op) {
461461
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->set.used != 0);
@@ -480,7 +480,7 @@ STATIC mp_obj_t set_unary_op(mp_uint_t op, mp_obj_t self_in) {
480480
}
481481
}
482482

483-
STATIC mp_obj_t set_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
483+
STATIC mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
484484
mp_obj_t args[] = {lhs, rhs};
485485
#if MICROPY_PY_BUILTINS_FROZENSET
486486
bool update = MP_OBJ_IS_TYPE(lhs, &mp_type_set);

py/objstr.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ const byte *find_subbytes(const byte *haystack, size_t hlen, const byte *needle,
280280
// Note: this function is used to check if an object is a str or bytes, which
281281
// works because both those types use it as their binary_op method. Revisit
282282
// MP_OBJ_IS_STR_OR_BYTES if this fact changes.
283-
mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
283+
mp_obj_t mp_obj_str_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
284284
// check for modulo
285285
if (op == MP_BINARY_OP_MODULO) {
286286
mp_obj_t *args = &rhs_in;
@@ -380,9 +380,10 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
380380
case MP_BINARY_OP_MORE:
381381
case MP_BINARY_OP_MORE_EQUAL:
382382
return mp_obj_new_bool(mp_seq_cmp_bytes(op, lhs_data, lhs_len, rhs_data, rhs_len));
383-
}
384383

385-
return MP_OBJ_NULL; // op not supported
384+
default:
385+
return MP_OBJ_NULL; // op not supported
386+
}
386387
}
387388

388389
#if !MICROPY_PY_BUILTINS_STR_UNICODE

py/objstr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
6767
mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args);
6868
mp_obj_t mp_obj_new_str_of_type(const mp_obj_type_t *type, const byte* data, size_t len);
6969

70-
mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
70+
mp_obj_t mp_obj_str_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
7171
mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags);
7272

7373
const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, size_t self_len,

py/objstrunicode.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ STATIC void uni_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
100100
}
101101
}
102102

103-
STATIC mp_obj_t uni_unary_op(mp_uint_t op, mp_obj_t self_in) {
103+
STATIC mp_obj_t uni_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
104104
GET_STR_DATA_LEN(self_in, str_data, str_len);
105105
switch (op) {
106106
case MP_UNARY_OP_BOOL:

py/objtuple.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ STATIC bool tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in
118118
return mp_seq_cmp_objs(op, self->items, self->len, another->items, another->len);
119119
}
120120

121-
mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in) {
121+
mp_obj_t mp_obj_tuple_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
122122
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
123123
switch (op) {
124124
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
@@ -135,7 +135,7 @@ mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in) {
135135
}
136136
}
137137

138-
mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
138+
mp_obj_t mp_obj_tuple_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
139139
mp_obj_tuple_t *o = MP_OBJ_TO_PTR(lhs);
140140
switch (op) {
141141
case MP_BINARY_OP_ADD:

py/objtuple.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ typedef struct _mp_rom_obj_tuple_t {
4141
} mp_rom_obj_tuple_t;
4242

4343
void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind);
44-
mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in);
45-
mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs);
44+
mp_obj_t mp_obj_tuple_unary_op(mp_unary_op_t op, mp_obj_t self_in);
45+
mp_obj_t mp_obj_tuple_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs);
4646
mp_obj_t mp_obj_tuple_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value);
4747
mp_obj_t mp_obj_tuple_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf);
4848

py/objtype.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ const qstr mp_unary_op_method_name[] = {
345345
[MP_UNARY_OP_NOT] = MP_QSTR_, // don't need to implement this, used to make sure array has full size
346346
};
347347

348-
STATIC mp_obj_t instance_unary_op(mp_uint_t op, mp_obj_t self_in) {
348+
STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
349349
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
350350

351351
#if MICROPY_PY_SYS_GETSIZEOF
@@ -452,7 +452,7 @@ const qstr mp_binary_op_method_name[] = {
452452
[MP_BINARY_OP_EXCEPTION_MATCH] = MP_QSTR_, // not implemented, used to make sure array has full size
453453
};
454454

455-
STATIC mp_obj_t instance_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
455+
STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
456456
// Note: For ducktyping, CPython does not look in the instance members or use
457457
// __getattr__ or __getattribute__. It only looks in the class dictionary.
458458
mp_obj_instance_t *lhs = MP_OBJ_TO_PTR(lhs_in);

0 commit comments

Comments
 (0)