Skip to content

Commit c084ab9

Browse files
committed
synthio: Enable synthio.MathOperation.SUM(3,4,5)
1 parent 76101c0 commit c084ab9

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

shared-bindings/synthio/Math.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include "shared-bindings/synthio/Math.h"
3434
#include "shared-module/synthio/Math.h"
3535

36+
static const mp_arg_t math_properties[4];
37+
STATIC mp_obj_t synthio_math_make_new_common(mp_arg_val_t args[MP_ARRAY_SIZE(math_properties)]);
38+
3639
MAKE_ENUM_VALUE(synthio_math_operation_type, math_op, SUM, OP_SUM);
3740
MAKE_ENUM_VALUE(synthio_math_operation_type, math_op, ADD_SUB, OP_ADD_SUB);
3841
MAKE_ENUM_VALUE(synthio_math_operation_type, math_op, PRODUCT, OP_PRODUCT);
@@ -110,9 +113,21 @@ MAKE_ENUM_MAP(synthio_math_operation) {
110113
MAKE_ENUM_MAP_ENTRY(math_op, ABS),
111114
};
112115

116+
117+
STATIC mp_obj_t mathop_call(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
118+
mp_arg_val_t args[4];
119+
args[0].u_obj = fun;
120+
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(math_properties) - 1, math_properties + 1, &args[1]);
121+
return synthio_math_make_new_common(args);
122+
}
123+
113124
STATIC MP_DEFINE_CONST_DICT(synthio_math_operation_locals_dict, synthio_math_operation_locals_table);
114125
MAKE_PRINTER(synthio, synthio_math_operation);
115-
MAKE_ENUM_TYPE(synthio, MathOperation, synthio_math_operation);
126+
MAKE_ENUM_TYPE(synthio, MathOperation, synthio_math_operation,
127+
.flags = MP_TYPE_FLAG_EXTENDED,
128+
MP_TYPE_EXTENDED_FIELDS(
129+
.call = mathop_call,
130+
));
116131

117132
//| class Math:
118133
//| """An arithmetic block
@@ -151,6 +166,10 @@ STATIC mp_obj_t synthio_math_make_new(const mp_obj_type_t *type_in, size_t n_arg
151166
mp_arg_val_t args[MP_ARRAY_SIZE(math_properties)];
152167
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(math_properties), math_properties, args);
153168

169+
return synthio_math_make_new_common(args);
170+
}
171+
172+
STATIC mp_obj_t synthio_math_make_new_common(mp_arg_val_t args[MP_ARRAY_SIZE(math_properties)]) {
154173
synthio_math_obj_t *self = m_new_obj(synthio_math_obj_t);
155174
self->base.base.type = &synthio_math_type;
156175

0 commit comments

Comments
 (0)