From 21b5a130c8eb905c8115ced8debfd71a57f1cf7d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 6 Feb 2020 15:53:49 -0600 Subject: [PATCH] Port to CircuitPython --- code/compat.h | 14 ++++++++++++++ code/fft.c | 1 + code/filter.c | 1 + code/linalg.c | 1 + code/ndarray.c | 14 +++++++++----- code/ndarray.h | 2 +- code/numerical.c | 1 + code/poly.c | 1 + code/ulab.c | 1 + code/vectorise.c | 1 + 10 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 code/compat.h diff --git a/code/compat.h b/code/compat.h new file mode 100644 index 0000000..41f1b3e --- /dev/null +++ b/code/compat.h @@ -0,0 +1,14 @@ +#ifndef MICROPY_INCLUDED_ULAB_COMPAT_H +#define MICROPY_INCLUDED_ULAB_COMPAT_H + +#pragma GCC diagnostic ignored "-Wshadow" + +#define mp_obj_is_type(obj, type) MP_OBJ_IS_TYPE(obj, type) +#define mp_obj_is_int(obj) MP_OBJ_IS_INT(obj) + +#define MP_ROM_NONE (MP_ROM_PTR(&mp_const_none_obj)) +#define MP_ROM_FALSE (mp_const_false) +#define MP_ROM_TRUE (mp_const_true) + +#endif // MICROPY_INCLUDED_ULAB_COMPAT_H + diff --git a/code/fft.c b/code/fft.c index c1f3e79..23d00f2 100644 --- a/code/fft.c +++ b/code/fft.c @@ -17,6 +17,7 @@ #include "py/binary.h" #include "py/obj.h" #include "py/objarray.h" +#include "compat.h" #include "ndarray.h" #include "fft.h" diff --git a/code/filter.c b/code/filter.c index f414e09..8501bf1 100644 --- a/code/filter.c +++ b/code/filter.c @@ -15,6 +15,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "py/misc.h" +#include "compat.h" #include "filter.h" #if ULAB_FILTER_CONVOLVE diff --git a/code/linalg.c b/code/linalg.c index dac47c3..7b154e4 100644 --- a/code/linalg.c +++ b/code/linalg.c @@ -15,6 +15,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "py/misc.h" +#include "compat.h" #include "linalg.h" #if ULAB_LINALG_TRANSPOSE diff --git a/code/ndarray.c b/code/ndarray.c index d89b6be..081786f 100644 --- a/code/ndarray.c +++ b/code/ndarray.c @@ -17,6 +17,7 @@ #include "py/binary.h" #include "py/obj.h" #include "py/objtuple.h" +#include "compat.h" #include "ndarray.h" // This function is copied verbatim from objarray.c @@ -165,11 +166,14 @@ STATIC uint8_t ndarray_init_helper(size_t n_args, const mp_obj_t *pos_args, mp_m return dtype; } -mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_arg_check_num(n_args, n_kw, 1, 2, true); - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, args + n_args); - uint8_t dtype = ndarray_init_helper(n_args, args, &kw_args); +mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 1, 2, true); + size_t n_kw = 0; + if (kw_args != 0) { + n_kw = kw_args->used; + } + mp_map_init_fixed_table(kw_args, n_kw, args + n_args); + uint8_t dtype = ndarray_init_helper(n_args, args, kw_args); size_t len1, len2=0, i=0; mp_obj_t len_in = mp_obj_len_maybe(args[0]); diff --git a/code/ndarray.h b/code/ndarray.h index d9eb4f3..002e2d8 100644 --- a/code/ndarray.h +++ b/code/ndarray.h @@ -58,7 +58,7 @@ void ndarray_assign_elements(mp_obj_array_t *, mp_obj_t , uint8_t , size_t *); ndarray_obj_t *create_new_ndarray(size_t , size_t , uint8_t ); mp_obj_t ndarray_copy(mp_obj_t ); -mp_obj_t ndarray_make_new(const mp_obj_type_t *, size_t , size_t , const mp_obj_t *); +mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); mp_obj_t ndarray_subscr(mp_obj_t , mp_obj_t , mp_obj_t ); mp_obj_t ndarray_getiter(mp_obj_t , mp_obj_iter_buf_t *); mp_obj_t ndarray_binary_op(mp_binary_op_t , mp_obj_t , mp_obj_t ); diff --git a/code/numerical.c b/code/numerical.c index 87a3540..d7a9ed9 100644 --- a/code/numerical.c +++ b/code/numerical.c @@ -17,6 +17,7 @@ #include "py/runtime.h" #include "py/builtin.h" #include "py/misc.h" +#include "compat.h" #include "numerical.h" enum NUMERICAL_FUNCTION_TYPE { diff --git a/code/poly.c b/code/poly.c index e7b1337..693b12c 100644 --- a/code/poly.c +++ b/code/poly.c @@ -12,6 +12,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "py/objarray.h" +#include "compat.h" #include "ndarray.h" #include "linalg.h" #include "poly.h" diff --git a/code/ulab.c b/code/ulab.c index 4578c2d..5cfb2c8 100644 --- a/code/ulab.c +++ b/code/ulab.c @@ -19,6 +19,7 @@ #include "py/objarray.h" #include "ulab.h" +#include "compat.h" #include "ndarray.h" #include "linalg.h" #include "vectorise.h" diff --git a/code/vectorise.c b/code/vectorise.c index 112fffa..0db7d3c 100644 --- a/code/vectorise.c +++ b/code/vectorise.c @@ -16,6 +16,7 @@ #include "py/binary.h" #include "py/obj.h" #include "py/objarray.h" +#include "compat.h" #include "vectorise.h" #ifndef MP_PI