diff --git a/lib/libesp32/Berry/default/berry_conf.h b/lib/libesp32/Berry/default/berry_conf.h index 3360b9082..e11d6c3cb 100644 --- a/lib/libesp32/Berry/default/berry_conf.h +++ b/lib/libesp32/Berry/default/berry_conf.h @@ -100,6 +100,12 @@ **/ #define BE_STACK_FREE_MIN 20 +/* Macro: BE_STACK_START + * Set the starting size of the stack at VM creation. + * Default: 50 + **/ +#define BE_STACK_START 100 + /* Macro: BE_CONST_SEARCH_SIZE * Constants in function are limited to 255. However the compiler * will look for a maximum of pre-existing constants to avoid diff --git a/lib/libesp32/Berry/default/embedded/autoconf.be b/lib/libesp32/Berry/default/embedded/autoconf.be index 3f9586e04..a30ed2044 100644 --- a/lib/libesp32/Berry/default/embedded/autoconf.be +++ b/lib/libesp32/Berry/default/embedded/autoconf.be @@ -293,6 +293,7 @@ autoconf_module.init = def (m) self._error = nil end + # called by the synthetic event `preinit` def preinit() if self._archive == nil return end # try to launch `preinit.be` @@ -327,6 +328,7 @@ autoconf_module.init = def (m) end end + # called by the synthetic event `autoexec` def autoexec() if self._archive == nil return end # try to launch `preinit.be` diff --git a/lib/libesp32/Berry/src/be_vm.c b/lib/libesp32/Berry/src/be_vm.c index ac2ede585..48834910e 100644 --- a/lib/libesp32/Berry/src/be_vm.c +++ b/lib/libesp32/Berry/src/be_vm.c @@ -453,8 +453,8 @@ BERRY_API bvm* be_vm_new(void) be_stack_init(vm, &vm->refstack, sizeof(binstance*)); be_stack_init(vm, &vm->exceptstack, sizeof(struct bexecptframe)); be_stack_init(vm, &vm->tracestack, sizeof(bcallsnapshot)); - vm->stack = be_malloc(vm, sizeof(bvalue) * BE_STACK_FREE_MIN); - vm->stacktop = vm->stack + BE_STACK_FREE_MIN; + vm->stack = be_malloc(vm, sizeof(bvalue) * BE_STACK_START); + vm->stacktop = vm->stack + BE_STACK_START; vm->reg = vm->stack; vm->top = vm->reg; be_globalvar_init(vm); diff --git a/tasmota/xdrv_52_9_berry.ino b/tasmota/xdrv_52_9_berry.ino index 46cc5692f..84a7b962a 100644 --- a/tasmota/xdrv_52_9_berry.ino +++ b/tasmota/xdrv_52_9_berry.ino @@ -241,34 +241,6 @@ int32_t callBerryEventDispatcher(const char *type, const char *cmd, int32_t idx, return ret; } -// call a method in autoconf -int32_t callBerryAutoconf(const char * method) { - int32_t ret = 0; - bvm *vm = berry.vm; - - if (nullptr == vm) { return ret; } - checkBeTop(); - be_getglobal(vm, "autoconf"); - if (!be_isnil(vm, -1)) { - be_getmethod(vm, -1, method); - if (!be_isnil(vm, -1)) { - be_pushvalue(vm, -2); - BrTimeoutStart(); - ret = be_pcall(vm, 1); // 1 arg - BrTimeoutReset(); - if (ret != 0) { - BerryDumpErrorAndClear(vm, false); // log in Tasmota console only - return ret; - } - be_pop(vm, 1); // remove instance - } - be_pop(vm, 1); // remove method - } - be_pop(vm, 1); // remove instance object - checkBeTop(); - return ret; -} - /*********************************************************************************************\ * VM Observability \*********************************************************************************************/ @@ -364,9 +336,9 @@ void BerryInit(void) { AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_BERRY "Berry initialized, RAM used=%u"), callBerryGC()); berry_init_ok = true; - // Run 'autoconf.preinit()' - callBerryAutoconf("preinit"); - + // we generate a synthetic event `autoexec` + callBerryEventDispatcher(PSTR("preinit"), nullptr, 0, nullptr); + // Run pre-init BrLoad("preinit.be"); // run 'preinit.be' if present } while (0); @@ -790,9 +762,6 @@ bool Xdrv52(uint8_t function) // break; case FUNC_LOOP: if (!berry.autoexec_done) { - // Run 'autoconf.preinit()' - callBerryAutoconf("autoexec"); - // we generate a synthetic event `autoexec` callBerryEventDispatcher(PSTR("autoexec"), nullptr, 0, nullptr);