feat: 添加了eigenmath支持,但是目前存在问题
This commit is contained in:
parent
dca783774d
commit
32ec5221d4
@ -1,15 +0,0 @@
|
|||||||
# Create an INTERFACE library for our C module.
|
|
||||||
add_library(usermod_cexample INTERFACE)
|
|
||||||
|
|
||||||
# Add our source files to the lib
|
|
||||||
target_sources(usermod_cexample INTERFACE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/examplemodule.c
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add the current directory as an include directory.
|
|
||||||
target_include_directories(usermod_cexample INTERFACE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Link our INTERFACE library to the usermod target.
|
|
||||||
target_link_libraries(usermod INTERFACE usermod_cexample)
|
|
||||||
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
// Used to get the time in the Timer class example.
|
// Used to get the time in the Timer class example.
|
||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
|
#include "py/misc.h"
|
||||||
|
#include "shared/readline/readline.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -44,12 +46,33 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#define STACKSIZE 100000 // evaluation stack
|
// #define STACKSIZE 100000 // evaluation stack
|
||||||
#define BLOCKSIZE 10000
|
// #define BLOCKSIZE 10000
|
||||||
#define MAXBLOCKS 2000
|
// #define MAXBLOCKS 2000
|
||||||
#define BUCKETSIZE 100
|
// #define BUCKETSIZE 100
|
||||||
#define STRBUFLEN 1000
|
// #define STRBUFLEN 1000
|
||||||
#define MAXDIM 24
|
// #define MAXDIM 24
|
||||||
|
|
||||||
|
// #define STACKSIZE 4096 // 栈大小从100000减到4096
|
||||||
|
// #define BLOCKSIZE 512 // 块大小从10000减到512
|
||||||
|
// #define MAXBLOCKS 64 // 最大块数从2000减到64
|
||||||
|
// #define BUCKETSIZE 32 // 哈希桶大小相应减小
|
||||||
|
// #define STRBUFLEN 256 // 字符串缓冲区减小
|
||||||
|
// #define MAXDIM 16 // 维度限制适当降低
|
||||||
|
|
||||||
|
// #define STACKSIZE 128 // 栈大小:128个元素(每个元素按4字节算约512字节)
|
||||||
|
// #define BLOCKSIZE 16 // 块大小:每个块包含16个atom
|
||||||
|
// #define MAXBLOCKS 64 // 最大块数:64块(16*64=1024个atom)
|
||||||
|
// #define BUCKETSIZE 4 // 哈希桶大小:仅保留4个桶
|
||||||
|
// #define STRBUFLEN 32 // 字符串缓冲区:每个字符串最大32字节
|
||||||
|
// #define MAXDIM 4 // 维度限制:降低到4维
|
||||||
|
|
||||||
|
#define STACKSIZE 512 // 进一步减小栈大小
|
||||||
|
#define BLOCKSIZE 128 // 减小块大小
|
||||||
|
#define MAXBLOCKS 64 // 减少最大块数
|
||||||
|
#define BUCKETSIZE 20 // 减小哈希桶
|
||||||
|
#define STRBUFLEN 256 // 减小字符串缓冲区
|
||||||
|
#define MAXDIM 16 // 降低维度限制
|
||||||
|
|
||||||
// MAXBLOCKS * BLOCKSIZE = 20,000,000 atoms
|
// MAXBLOCKS * BLOCKSIZE = 20,000,000 atoms
|
||||||
|
|
||||||
@ -1019,7 +1042,7 @@ alloc_str(void)
|
|||||||
void *
|
void *
|
||||||
alloc_mem(int n)
|
alloc_mem(int n)
|
||||||
{
|
{
|
||||||
void *p = malloc(n);
|
void *p = m_malloc(n);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
exit(1);
|
exit(1);
|
||||||
return p;
|
return p;
|
||||||
@ -1104,7 +1127,7 @@ mstr(uint32_t *u)
|
|||||||
|
|
||||||
if (n > len) {
|
if (n > len) {
|
||||||
if (buf)
|
if (buf)
|
||||||
free(buf);
|
m_free(buf);
|
||||||
buf = alloc_mem(n);
|
buf = alloc_mem(n);
|
||||||
len = n;
|
len = n;
|
||||||
}
|
}
|
||||||
@ -1486,7 +1509,7 @@ mnew(int n)
|
|||||||
void
|
void
|
||||||
mfree(uint32_t *u)
|
mfree(uint32_t *u)
|
||||||
{
|
{
|
||||||
free(u - 1);
|
m_free(u - 1);
|
||||||
bignum_count--;
|
bignum_count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5072,9 +5095,9 @@ eval_eigenvec(struct atom *p1)
|
|||||||
stopf("eigenvec");
|
stopf("eigenvec");
|
||||||
|
|
||||||
if (D)
|
if (D)
|
||||||
free(D);
|
m_free(D);
|
||||||
if (Q)
|
if (Q)
|
||||||
free(Q);
|
m_free(Q);
|
||||||
|
|
||||||
D = alloc_mem(n * n * sizeof (double));
|
D = alloc_mem(n * n * sizeof (double));
|
||||||
Q = alloc_mem(n * n * sizeof (double));
|
Q = alloc_mem(n * n * sizeof (double));
|
||||||
@ -9939,9 +9962,9 @@ nroots(void)
|
|||||||
n = tos - h; // number of coeffs on stack
|
n = tos - h; // number of coeffs on stack
|
||||||
|
|
||||||
if (cr)
|
if (cr)
|
||||||
free(cr);
|
m_free(cr);
|
||||||
if (ci)
|
if (ci)
|
||||||
free(ci);
|
m_free(ci);
|
||||||
|
|
||||||
cr = alloc_mem(n * sizeof (double));
|
cr = alloc_mem(n * sizeof (double));
|
||||||
ci = alloc_mem(n * sizeof (double));
|
ci = alloc_mem(n * sizeof (double));
|
||||||
@ -12715,7 +12738,7 @@ read_file(char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (read(fd, buf, n) != n) {
|
if (read(fd, buf, n) != n) {
|
||||||
free(buf);
|
m_free(buf);
|
||||||
close(fd);
|
close(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -15393,7 +15416,7 @@ fmt(void)
|
|||||||
|
|
||||||
if (m > fmt_buf_len) {
|
if (m > fmt_buf_len) {
|
||||||
if (fmt_buf)
|
if (fmt_buf)
|
||||||
free(fmt_buf);
|
m_free(fmt_buf);
|
||||||
fmt_buf = alloc_mem(m);
|
fmt_buf = alloc_mem(m);
|
||||||
fmt_buf_len = m;
|
fmt_buf_len = m;
|
||||||
}
|
}
|
||||||
@ -16742,11 +16765,11 @@ gc(void)
|
|||||||
|
|
||||||
switch (p->atomtype) {
|
switch (p->atomtype) {
|
||||||
case KSYM:
|
case KSYM:
|
||||||
free(p->u.ksym.name);
|
m_free(p->u.ksym.name);
|
||||||
ksym_count--;
|
ksym_count--;
|
||||||
break;
|
break;
|
||||||
case USYM:
|
case USYM:
|
||||||
free(p->u.usym.name);
|
m_free(p->u.usym.name);
|
||||||
usym_count--;
|
usym_count--;
|
||||||
break;
|
break;
|
||||||
case RATIONAL:
|
case RATIONAL:
|
||||||
@ -16755,11 +16778,11 @@ gc(void)
|
|||||||
break;
|
break;
|
||||||
case STR:
|
case STR:
|
||||||
if (p->u.str)
|
if (p->u.str)
|
||||||
free(p->u.str);
|
m_free(p->u.str);
|
||||||
string_count--;
|
string_count--;
|
||||||
break;
|
break;
|
||||||
case TENSOR:
|
case TENSOR:
|
||||||
free(p->u.tensor);
|
m_free(p->u.tensor);
|
||||||
tensor_count--;
|
tensor_count--;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -16864,21 +16887,31 @@ run_infile(char *infile)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
run(buf);
|
run(buf);
|
||||||
free(buf);
|
m_free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
run_stdin(void)
|
run_stdin(void)
|
||||||
{
|
{
|
||||||
static char inbuf[1000];
|
mp_printf(&mp_plat_print, "Eigenmath start %d\n", __LINE__);
|
||||||
for (;;) {
|
// static char inbuf[1000];
|
||||||
fputs("? ", stdout);
|
vstr_t* vstr_inbuf = vstr_new(1);
|
||||||
fflush(stdout);
|
|
||||||
fgets(inbuf, sizeof inbuf, stdin);
|
// for (;;) {
|
||||||
run(inbuf);
|
// fputs("? ", stdout);
|
||||||
}
|
// fflush(stdout);
|
||||||
|
// fgets(inbuf, sizeof inbuf, stdin);
|
||||||
|
int res = readline(vstr_inbuf,"eigenmath> ");
|
||||||
|
mp_printf(&mp_plat_print, "Eigenmath run:\n");
|
||||||
|
mp_printf(&mp_plat_print, "res=%d\n", res);
|
||||||
|
mp_printf(&mp_plat_print, "%s\n", vstr_inbuf->buf);
|
||||||
|
run(vstr_inbuf->buf);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
display(void)
|
display(void)
|
||||||
{
|
{
|
||||||
@ -16888,7 +16921,8 @@ display(void)
|
|||||||
void
|
void
|
||||||
printbuf(char *s, int color)
|
printbuf(char *s, int color)
|
||||||
{
|
{
|
||||||
fputs(s, stdout);
|
// fputs(s, stdout);
|
||||||
|
mp_printf(&mp_plat_print, "%s", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -17394,7 +17428,7 @@ run(char *buf)
|
|||||||
shuntflag = 0;
|
shuntflag = 0;
|
||||||
errorflag = 0;
|
errorflag = 0;
|
||||||
breakflag = 0;
|
breakflag = 0;
|
||||||
|
mp_printf(&mp_plat_print, "run() has param: %s\n", buf);
|
||||||
if (zero == NULL) {
|
if (zero == NULL) {
|
||||||
srand((unsigned) time(NULL));
|
srand((unsigned) time(NULL));
|
||||||
init_symbol_table();
|
init_symbol_table();
|
||||||
@ -17409,10 +17443,10 @@ run(char *buf)
|
|||||||
push_rational(1, 2);
|
push_rational(1, 2);
|
||||||
list(3);
|
list(3);
|
||||||
imaginaryunit = pop();
|
imaginaryunit = pop();
|
||||||
run_init_script();
|
// run_init_script();
|
||||||
}
|
}
|
||||||
|
mp_printf(&mp_plat_print, "start to run run_buf()\n");
|
||||||
run_buf(buf);
|
// run_buf(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -18015,7 +18049,7 @@ update_token_buf(char *a, char *b)
|
|||||||
|
|
||||||
if (m > token_buf_len) {
|
if (m > token_buf_len) {
|
||||||
if (token_buf)
|
if (token_buf)
|
||||||
free(token_buf);
|
m_free(token_buf);
|
||||||
token_buf = alloc_mem(m);
|
token_buf = alloc_mem(m);
|
||||||
token_buf_len = m;
|
token_buf_len = m;
|
||||||
}
|
}
|
||||||
@ -18621,6 +18655,16 @@ static mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) {
|
|||||||
// Calculate the addition and convert to MicroPython object.
|
// Calculate the addition and convert to MicroPython object.
|
||||||
return mp_obj_new_int(a + b);
|
return mp_obj_new_int(a + b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static mp_obj_t eigenmath_cmd() {
|
||||||
|
run_stdin();
|
||||||
|
// Calculate the addition and convert to MicroPython object.
|
||||||
|
return mp_obj_new_int(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static MP_DEFINE_CONST_FUN_OBJ_0(eigenmath_cmd_obj, eigenmath_cmd);
|
||||||
|
|
||||||
// Define a Python reference to the function above.
|
// Define a Python reference to the function above.
|
||||||
static MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints);
|
static MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints);
|
||||||
|
|
||||||
@ -18762,19 +18806,20 @@ MP_DEFINE_CONST_OBJ_TYPE(
|
|||||||
// and the MicroPython object reference.
|
// and the MicroPython object reference.
|
||||||
// All identifiers and strings are written as MP_QSTR_xxx and will be
|
// All identifiers and strings are written as MP_QSTR_xxx and will be
|
||||||
// optimized to word-sized integers by the build system (interned strings).
|
// optimized to word-sized integers by the build system (interned strings).
|
||||||
static const mp_rom_map_elem_t example_module_globals_table[] = {
|
static const mp_rom_map_elem_t eigenmath_module_globals_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cexample) },
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_eigenmath) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_add_ints), MP_ROM_PTR(&example_add_ints_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_add_ints), MP_ROM_PTR(&example_add_ints_obj) },
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_cmd), MP_ROM_PTR(&eigenmath_cmd_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&example_type_Timer) },
|
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&example_type_Timer) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_AdvancedTimer), MP_ROM_PTR(&example_type_AdvancedTimer) },
|
{ MP_ROM_QSTR(MP_QSTR_AdvancedTimer), MP_ROM_PTR(&example_type_AdvancedTimer) },
|
||||||
};
|
};
|
||||||
static MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table);
|
static MP_DEFINE_CONST_DICT(eigenmath_module_globals, eigenmath_module_globals_table);
|
||||||
|
|
||||||
// Define module object.
|
// Define module object.
|
||||||
const mp_obj_module_t example_user_cmodule = {
|
const mp_obj_module_t eigenmath_user_cmodule = {
|
||||||
.base = { &mp_type_module },
|
.base = { &mp_type_module },
|
||||||
.globals = (mp_obj_dict_t *)&example_module_globals,
|
.globals = (mp_obj_dict_t *)&eigenmath_module_globals,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register the module to make it available in Python.
|
// Register the module to make it available in Python.
|
||||||
MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule);
|
MP_REGISTER_MODULE(MP_QSTR_eigenmath, eigenmath_user_cmodule);
|
||||||
15
user_modules/eigenmath/micropython.cmake
Normal file
15
user_modules/eigenmath/micropython.cmake
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Create an INTERFACE library for our C module.
|
||||||
|
add_library(usermod_eigenmath INTERFACE)
|
||||||
|
|
||||||
|
# Add our source files to the lib
|
||||||
|
target_sources(usermod_eigenmath INTERFACE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/eigenmath.c
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add the current directory as an include directory.
|
||||||
|
target_include_directories(usermod_eigenmath INTERFACE
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Link our INTERFACE library to the usermod target.
|
||||||
|
target_link_libraries(usermod INTERFACE usermod_eigenmath)
|
||||||
@ -1,7 +1,7 @@
|
|||||||
CEXAMPLE_MOD_DIR := $(USERMOD_DIR)
|
CEXAMPLE_MOD_DIR := $(USERMOD_DIR)
|
||||||
|
|
||||||
# Add all C files to SRC_USERMOD.
|
# Add all C files to SRC_USERMOD.
|
||||||
SRC_USERMOD += $(CEXAMPLE_MOD_DIR)/examplemodule.c
|
SRC_USERMOD += $(CEXAMPLE_MOD_DIR)/eigenmath.c
|
||||||
|
|
||||||
# We can add our module folder to include paths if needed
|
# We can add our module folder to include paths if needed
|
||||||
# This is not actually needed in this example.
|
# This is not actually needed in this example.
|
||||||
@ -1,2 +1,2 @@
|
|||||||
include(${CMAKE_CURRENT_LIST_DIR}/cexample/micropython.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/eigenmath/micropython.cmake)
|
||||||
include(${CMAKE_CURRENT_LIST_DIR}/lv_binding_micropython/bindings.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/lv_binding_micropython/bindings.cmake)
|
||||||
Loading…
x
Reference in New Issue
Block a user