mirror of https://github.com/arendst/Tasmota.git
Merge pull request #13701 from s-hadinger/berry_preinit_optim
Berry simplified preinit and autoexec
This commit is contained in:
commit
2b7b314488
|
@ -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
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue