diff --git a/src/NodeToken.h b/src/NodeToken.h index 44b59bd..0942400 100644 --- a/src/NodeToken.h +++ b/src/NodeToken.h @@ -135,7 +135,7 @@ void initMem() // printf("We satrt with: %ld free and stack:%ld \n", __startmem, __startStackMemory); #endif } -void displayStat(char *text) +void displayStat(const char *text) { pushToConsole(string_format(" %s :max used memory: %ld maxstack:%ld started %d free mem:%ld consumed %ld time:%dms", text, __maxMemUsage, __MaxStackMemory, __startmem, esp_get_free_heap_size(), __startmem - esp_get_free_heap_size(), (__endtime - __starttime) / 240000)); } @@ -789,10 +789,14 @@ class NodeToken int cur_size = 0; if (_nodetype == extCallFunctionNode or _nodetype == callFunctionNode) { - cur_size = getChildAtPos(1)->children_size(); - for (int i = 0; i < getChildAtPos(2)->children_size(); i++) + NodeToken *child1 = getChildAtPos(1); + if (!child1) return cur_size; // nested extern call built without formal-param child — scalar, no spill needed + cur_size = child1->children_size(); + NodeToken *child2 = getChildAtPos(2); + if (!child2) return cur_size; + for (int i = 0; i < child2->children_size(); i++) { - int cmp = getChildAtPos(2)->getChildAtPos(i)->findMaxArgumentSize(); + int cmp = child2->getChildAtPos(i)->findMaxArgumentSize(); if (cmp > cur_size) cur_size = cmp; } diff --git a/src/asm_struct_enum.h b/src/asm_struct_enum.h index b3305a3..69d2eeb 100644 --- a/src/asm_struct_enum.h +++ b/src/asm_struct_enum.h @@ -109,7 +109,7 @@ class Text // _texts.push_back(cc); _it = _texts.begin(); } - int findText(char * str) + int findText(const char * str) { #ifdef __SPEED return -1; diff --git a/src/execute.h b/src/execute.h index 7dc67d8..331f801 100644 --- a/src/execute.h +++ b/src/execute.h @@ -6,6 +6,13 @@ #ifndef __RUN_CORE #define __RUN_CORE 0 #endif +#ifndef __LS_STACK_CAPS +#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32P4) + #define __LS_STACK_CAPS (MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT) +#else + #define __LS_STACK_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) +#endif +#endif using namespace std; #ifndef _MAX_PROG_AT_ONCE #define _MAX_PROG_AT_ONCE 10 @@ -507,7 +514,7 @@ class Executable if (__run_handle_index != 9999) { - vTaskDelete(*runningPrograms.getHandleByIndex(__run_handle_index)); + vTaskDeleteWithCaps(*runningPrograms.getHandleByIndex(__run_handle_index)); } _isRunning = false; @@ -531,7 +538,7 @@ class Executable #endif } - int _run(vector args, bool second_core, int core, Arguments arguments, string json) + int _run(vector args, bool second_core, int core, Arguments arguments, string json, uint32_t stack_size = 4096 * 2) { __run_handle_index = 9999; #ifndef __TEST_DEBUG @@ -580,7 +587,7 @@ class Executable taskname = string_format("_run_task_%d", __run_handle_index); else taskname = string_format("%s_%d", name.c_str(), __run_handle_index); - xTaskCreateUniversal(_run_task, taskname.c_str(), 4096 * 2, this, 3, (TaskHandle_t *)runningPrograms.getHandleByIndex(__run_handle_index), core); + xTaskCreatePinnedToCoreWithCaps(_run_task, taskname.c_str(), stack_size, this, 3, (TaskHandle_t *)runningPrograms.getHandleByIndex(__run_handle_index), core, __LS_STACK_CAPS); pushToConsole("Execution on going CTRL + k to stop", true); } @@ -695,7 +702,7 @@ class Executable } return false; } - void executeAsTask(string prog, int core, Arguments arguments, string json) + void executeAsTask(string prog, int core, Arguments arguments, string json, uint32_t stack_size = 8192) { // printf("herqsd sqdsq\n"); args.clear(); @@ -708,7 +715,7 @@ class Executable { vector __args; __args.push_back("@__" + prog); - _run(__args, true, core, arguments, json); + _run(__args, true, core, arguments, json, stack_size); } else { @@ -717,30 +724,30 @@ class Executable #endif } - void executeAsTask(string prog, int core, Arguments arguments) + void executeAsTask(string prog, int core, Arguments arguments, uint32_t stack_size = 8192) { - executeAsTask(prog, core, arguments, ""); + executeAsTask(prog, core, arguments, "", stack_size); } - void executeAsTask(string prog, Arguments arguments) + void executeAsTask(string prog, Arguments arguments, uint32_t stack_size = 8192) { - executeAsTask(prog, __RUN_CORE, arguments); + executeAsTask(prog, __RUN_CORE, arguments, stack_size); } - void executeAsTask(string prog) + void executeAsTask(string prog, uint32_t stack_size = 8192) { args.clear(); - executeAsTask(prog, __RUN_CORE, args); + executeAsTask(prog, __RUN_CORE, args, stack_size); } - void executeAsTask(string prog, int core) + void executeAsTask(string prog, int core, uint32_t stack_size = 8192) { args.clear(); - executeAsTask(prog, core, args); + executeAsTask(prog, core, args, stack_size); } - void executeAsTask(string prog, string json) + void executeAsTask(string prog, string json, uint32_t stack_size = 8192) { // printf("her\n"); args.clear(); - executeAsTask(prog, __RUN_CORE, args, json); + executeAsTask(prog, __RUN_CORE, args, json, stack_size); } #endif bool isRunning() @@ -802,7 +809,7 @@ static void _run_task(void *pvParameters) exec->_isRunning = false; runningPrograms.removeHandle(exec->__run_handle_index); isSyncalled = false; - vTaskDelete(NULL); + vTaskDeleteWithCaps(xTaskGetCurrentTaskHandle()); #endif } @@ -952,81 +959,81 @@ class _ScriptRuntime } } - void executeAsTask(string name, Arguments arguments) + void executeAsTask(string name, Arguments arguments, uint32_t stack_size = 8192) { Executable *exec = findExecutable(name); if (exec != NULL) { #ifndef __TEST_DEBUG - exec->executeAsTask("main", arguments); + exec->executeAsTask("main", arguments, stack_size); #endif } } - void executeAsTask(string name) + void executeAsTask(string name, uint32_t stack_size = 8192) { Executable *exec = findExecutable(name); if (exec != NULL) { #ifndef __TEST_DEBUG - exec->executeAsTask("main"); + exec->executeAsTask("main", stack_size); #endif } } - void executeAsTaskJ(string name, string json) + void executeAsTaskJ(string name, string json, uint32_t stack_size = 8192) { Executable *exec = findExecutable(name); if (exec != NULL) { #ifndef __TEST_DEBUG - exec->executeAsTask("main", json); + exec->executeAsTask("main", json, stack_size); #endif } } - void executeAsTask(string name, string function, Arguments arguments) + void executeAsTask(string name, string function, Arguments arguments, uint32_t stack_size = 8192) { Executable *exec = findExecutable(name); if (exec != NULL) { #ifndef __TEST_DEBUG - exec->executeAsTask(function, arguments); + exec->executeAsTask(function, arguments, stack_size); #endif } } - void executeAsTask(string name, string function) + void executeAsTask(string name, string function, uint32_t stack_size = 8192) { Executable *exec = findExecutable(name); if (exec != NULL) { #ifndef __TEST_DEBUG - exec->executeAsTask(function); + exec->executeAsTask(function, stack_size); #endif } } - void executeAsTask(string name, int core, Arguments args) + void executeAsTask(string name, int core, Arguments args, uint32_t stack_size = 8192) { Executable *exec = findExecutable(name); if (exec != NULL) { #ifndef __TEST_DEBUG - exec->executeAsTask("main", core, args); + exec->executeAsTask("main", core, args, stack_size); #endif } } - void executeAsTask(string name, int core) + void executeAsTask(string name, int core, uint32_t stack_size = 8192) { Executable *exec = findExecutable(name); if (exec != NULL) { #ifndef __TEST_DEBUG - exec->executeAsTask("main", core); + exec->executeAsTask("main", core, stack_size); #endif } } diff --git a/src/execute_asm.h b/src/execute_asm.h index 215e5fc..c173f89 100644 --- a/src/execute_asm.h +++ b/src/execute_asm.h @@ -556,7 +556,7 @@ void freeExecutable(executable *ex) if (ex->start_program != NULL) { - heap_caps_aligned_free(ex->start_program); + heap_caps_free(ex->start_program); } ex->start_program = NULL; diff --git a/src/functionlib.h b/src/functionlib.h index e1bb296..432bc7a 100644 --- a/src/functionlib.h +++ b/src/functionlib.h @@ -57,7 +57,7 @@ __ASM__ float __div(float a,float b)\n\ \"divn.s f0, f2, f6\"\n\ \"retw.n\"\n\ }@"; -char * _div[]={ +const char * _div[]={ "@___div(d|d):", "entry a1,16", "div0.s f3, f2", @@ -109,7 +109,8 @@ __ASM__ uint32_t rand(uint32_t mod) \n\ \"retw.n\" \n\ }@"; #else -string _rand="\__ASM__ uint32_t rand(uint32_t mod) \n\ +string _rand="\ +__ASM__ uint32_t rand(uint32_t mod) \n\ {\n\ \"entry a1,56\" \n\ //\"l32r a4,@_stack_rand(d)\" \n\