|
33 | 33 | #include "shared-bindings/synthio/Math.h"
|
34 | 34 | #include "shared-module/synthio/Math.h"
|
35 | 35 |
|
| 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 | + |
36 | 39 | MAKE_ENUM_VALUE(synthio_math_operation_type, math_op, SUM, OP_SUM);
|
37 | 40 | MAKE_ENUM_VALUE(synthio_math_operation_type, math_op, ADD_SUB, OP_ADD_SUB);
|
38 | 41 | MAKE_ENUM_VALUE(synthio_math_operation_type, math_op, PRODUCT, OP_PRODUCT);
|
@@ -110,9 +113,21 @@ MAKE_ENUM_MAP(synthio_math_operation) {
|
110 | 113 | MAKE_ENUM_MAP_ENTRY(math_op, ABS),
|
111 | 114 | };
|
112 | 115 |
|
| 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 | + |
113 | 124 | STATIC MP_DEFINE_CONST_DICT(synthio_math_operation_locals_dict, synthio_math_operation_locals_table);
|
114 | 125 | 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 | + )); |
116 | 131 |
|
117 | 132 | //| class Math:
|
118 | 133 | //| """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
|
151 | 166 | mp_arg_val_t args[MP_ARRAY_SIZE(math_properties)];
|
152 | 167 | mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(math_properties), math_properties, args);
|
153 | 168 |
|
| 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)]) { |
154 | 173 | synthio_math_obj_t *self = m_new_obj(synthio_math_obj_t);
|
155 | 174 | self->base.base.type = &synthio_math_type;
|
156 | 175 |
|
|
0 commit comments