2022-01-20 18:16:08 +08:00
|
|
|
#include "PikaStdTask_Task.h"
|
2022-01-20 21:50:38 +08:00
|
|
|
#include "BaseObj.h"
|
2022-01-20 18:16:08 +08:00
|
|
|
#include "PikaVM.h"
|
|
|
|
|
|
|
|
extern PikaObj* __pikaMain;
|
|
|
|
void PikaStdTask_Task___init__(PikaObj* self) {
|
2022-01-20 21:59:43 +08:00
|
|
|
pikaVM_runAsm(self,
|
2022-01-23 21:31:07 +08:00
|
|
|
"B0\n"
|
|
|
|
"0 RUN calls_always.__init__\n"
|
|
|
|
"0 RUN calls_when.__init__\n"
|
|
|
|
"0 RUN assert_when.__init__\n"
|
|
|
|
"0 RUN calls_period.__init__\n"
|
|
|
|
"0 RUN assert_period.__init__\n"
|
|
|
|
"0 RUN time_period.__init__\n");
|
2022-01-21 02:03:36 +08:00
|
|
|
obj_setPtr(__pikaMain, "__calls_always", obj_getPtr(self, "calls_always"));
|
|
|
|
obj_setPtr(__pikaMain, "__calls_when", obj_getPtr(self, "calls_when"));
|
|
|
|
obj_setPtr(__pikaMain, "__assert_when", obj_getPtr(self, "assert_when"));
|
2022-01-23 21:31:07 +08:00
|
|
|
obj_setPtr(__pikaMain, "__calls_period", obj_getPtr(self, "calls_period"));
|
|
|
|
obj_setPtr(__pikaMain, "__assert_period",
|
|
|
|
obj_getPtr(self, "assert_period"));
|
|
|
|
obj_setPtr(__pikaMain, "__time_period", obj_getPtr(self, "time_period"));
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
2022-01-20 21:50:38 +08:00
|
|
|
|
2022-01-20 18:16:08 +08:00
|
|
|
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
2022-01-23 00:13:16 +08:00
|
|
|
pikaVM_runAsm(self, "B0\n1 REF fun_todo\n0 RUN calls_always.append\n");
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
2022-01-20 21:50:38 +08:00
|
|
|
|
2022-01-21 02:03:36 +08:00
|
|
|
void PikaStdTask_Task_call_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
|
|
|
obj_setArg(self, "fun_when", fun_when);
|
|
|
|
pikaVM_runAsm(self,
|
2022-01-23 21:31:07 +08:00
|
|
|
"B0\n"
|
|
|
|
"1 REF fun_todo\n"
|
|
|
|
"0 RUN calls_when.append\n"
|
|
|
|
"B0\n"
|
|
|
|
"1 REF fun_when\n"
|
|
|
|
"0 RUN assert_when.append\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdTask_Task_call_period_ms(PikaObj* self,
|
|
|
|
Arg* fun_todo,
|
|
|
|
int period_ms) {
|
|
|
|
obj_setArg(self, "fun_todo", fun_todo);
|
|
|
|
obj_setInt(self, "period_ms", period_ms);
|
|
|
|
pikaVM_runAsm(self,
|
|
|
|
"B0\n"
|
|
|
|
"1 REF fun_todo\n"
|
|
|
|
"0 RUN calls_period.append\n"
|
|
|
|
"B0\n"
|
|
|
|
"1 REF period_ms\n"
|
|
|
|
"0 RUN assert_period.append\n"
|
|
|
|
"B0\n"
|
|
|
|
"1 REF 0\n"
|
|
|
|
"0 RUN time_period.append\n");
|
2022-01-21 02:03:36 +08:00
|
|
|
}
|
2022-01-20 18:16:08 +08:00
|
|
|
|
|
|
|
void PikaStdTask_Task_run_once(PikaObj* self) {
|
2022-01-23 21:50:05 +08:00
|
|
|
/* Python
|
|
|
|
if calls_period.len() > 0:
|
|
|
|
platformGetTick()
|
|
|
|
*/
|
|
|
|
pikaVM_runAsm(self,
|
|
|
|
"B0\n"
|
|
|
|
"1 RUN calls_period.len\n"
|
|
|
|
"1 NUM 0\n"
|
|
|
|
"0 OPT >\n"
|
|
|
|
"0 JEZ 1\n"
|
|
|
|
"B1\n"
|
|
|
|
"0 RUN platformGetTick\n"
|
|
|
|
"B0\n");
|
2022-01-23 21:31:07 +08:00
|
|
|
/* transfer the tick to pikaMain */
|
|
|
|
obj_setInt(__pikaMain, "__tick", obj_getInt(self, "tick"));
|
|
|
|
/* Python
|
2022-01-23 21:50:05 +08:00
|
|
|
len = __calls_always.len()
|
|
|
|
for i in range(0, len):
|
|
|
|
if len == 0:
|
|
|
|
break
|
|
|
|
todo = __calls_always[i]
|
|
|
|
todo()
|
|
|
|
*/
|
|
|
|
pikaVM_runAsm(__pikaMain,
|
|
|
|
"B0\n"
|
|
|
|
"0 RUN __calls_always.len\n"
|
|
|
|
"0 OUT len\n"
|
|
|
|
"B0\n"
|
|
|
|
"2 NUM 0\n"
|
|
|
|
"2 REF len\n"
|
|
|
|
"1 RUN range\n"
|
|
|
|
"0 RUN iter\n"
|
|
|
|
"0 OUT _l0\n"
|
|
|
|
"0 REF _r1\n"
|
|
|
|
"0 REF _r2\n"
|
|
|
|
"0 REF _r3\n"
|
|
|
|
"0 OUT _l0.a1\n"
|
|
|
|
"0 OUT _l0.a2\n"
|
|
|
|
"0 OUT _l0.a3\n"
|
|
|
|
"B0\n"
|
|
|
|
"0 RUN _l0.__next__\n"
|
|
|
|
"0 OUT i\n"
|
|
|
|
"0 EST i\n"
|
|
|
|
"0 JEZ 2\n"
|
|
|
|
"B1\n"
|
|
|
|
"1 REF len\n"
|
|
|
|
"1 NUM 0\n"
|
|
|
|
"0 OPT ==\n"
|
|
|
|
"0 JEZ 1\n"
|
|
|
|
"B2\n"
|
|
|
|
"0 BRK\n"
|
|
|
|
"B1\n"
|
|
|
|
"1 REF __calls_always\n"
|
|
|
|
"1 REF i\n"
|
|
|
|
"0 RUN __get__\n"
|
|
|
|
"0 OUT todo\n"
|
|
|
|
"B1\n"
|
|
|
|
"0 RUN todo\n"
|
|
|
|
"B0\n"
|
|
|
|
"0 JMP -1\n"
|
|
|
|
"B0\n"
|
|
|
|
"0 DEL _l0\n"
|
|
|
|
"B0\n");
|
|
|
|
|
|
|
|
/* Python
|
|
|
|
__len = __calls_when.len()
|
2022-01-23 21:31:07 +08:00
|
|
|
for i in range(0, __len):
|
|
|
|
if __len == 0:
|
|
|
|
break
|
2022-01-23 21:50:05 +08:00
|
|
|
when = __assert_when[i]
|
|
|
|
if when():
|
|
|
|
todo = __calls_when[i]
|
2022-01-23 21:31:07 +08:00
|
|
|
todo()
|
|
|
|
*/
|
|
|
|
pikaVM_runAsm(__pikaMain,
|
|
|
|
"B0\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"0 RUN __calls_when.len\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"0 OUT __len\n"
|
|
|
|
"B0\n"
|
|
|
|
"2 NUM 0\n"
|
|
|
|
"2 REF __len\n"
|
|
|
|
"1 RUN range\n"
|
|
|
|
"0 RUN iter\n"
|
|
|
|
"0 OUT _l0\n"
|
|
|
|
"0 REF _r1\n"
|
|
|
|
"0 REF _r2\n"
|
|
|
|
"0 REF _r3\n"
|
|
|
|
"0 OUT _l0.a1\n"
|
|
|
|
"0 OUT _l0.a2\n"
|
|
|
|
"0 OUT _l0.a3\n"
|
|
|
|
"B0\n"
|
|
|
|
"0 RUN _l0.__next__\n"
|
|
|
|
"0 OUT i\n"
|
|
|
|
"0 EST i\n"
|
|
|
|
"0 JEZ 2\n"
|
|
|
|
"B1\n"
|
|
|
|
"1 REF __len\n"
|
|
|
|
"1 NUM 0\n"
|
|
|
|
"0 OPT ==\n"
|
|
|
|
"0 JEZ 1\n"
|
|
|
|
"B2\n"
|
|
|
|
"0 BRK\n"
|
|
|
|
"B1\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"1 REF __assert_when\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"1 REF i\n"
|
|
|
|
"0 RUN __get__\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"0 OUT when\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"B1\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"0 RUN when\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"0 JEZ 1\n"
|
|
|
|
"B2\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"1 REF __calls_when\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"1 REF i\n"
|
|
|
|
"0 RUN __get__\n"
|
|
|
|
"0 OUT todo\n"
|
|
|
|
"B2\n"
|
|
|
|
"0 RUN todo\n"
|
|
|
|
"B0\n"
|
|
|
|
"0 JMP -1\n"
|
|
|
|
"B0\n"
|
|
|
|
"0 DEL _l0\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"B0\n");
|
2022-01-23 21:31:07 +08:00
|
|
|
/* Python
|
2022-01-23 21:50:05 +08:00
|
|
|
__len = __calls_period.len()
|
2022-01-23 21:31:07 +08:00
|
|
|
for i in range(0, __len):
|
|
|
|
if __len == 0:
|
|
|
|
break
|
2022-01-23 21:50:05 +08:00
|
|
|
time = __time_period[i]
|
|
|
|
if __tick > __time_period[i]:
|
|
|
|
todo = __calls_period[i]
|
2022-01-23 21:31:07 +08:00
|
|
|
todo()
|
2022-01-23 21:50:05 +08:00
|
|
|
__time_period[i] = __tick + __assert_period[i]
|
2022-01-23 21:31:07 +08:00
|
|
|
*/
|
|
|
|
pikaVM_runAsm(__pikaMain,
|
|
|
|
"B0\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"0 RUN __calls_period.len\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"0 OUT __len\n"
|
|
|
|
"B0\n"
|
|
|
|
"2 NUM 0\n"
|
|
|
|
"2 REF __len\n"
|
|
|
|
"1 RUN range\n"
|
|
|
|
"0 RUN iter\n"
|
|
|
|
"0 OUT _l0\n"
|
|
|
|
"0 REF _r1\n"
|
|
|
|
"0 REF _r2\n"
|
|
|
|
"0 REF _r3\n"
|
|
|
|
"0 OUT _l0.a1\n"
|
|
|
|
"0 OUT _l0.a2\n"
|
|
|
|
"0 OUT _l0.a3\n"
|
|
|
|
"B0\n"
|
|
|
|
"0 RUN _l0.__next__\n"
|
|
|
|
"0 OUT i\n"
|
|
|
|
"0 EST i\n"
|
|
|
|
"0 JEZ 2\n"
|
|
|
|
"B1\n"
|
|
|
|
"1 REF __len\n"
|
|
|
|
"1 NUM 0\n"
|
|
|
|
"0 OPT ==\n"
|
|
|
|
"0 JEZ 1\n"
|
|
|
|
"B2\n"
|
|
|
|
"0 BRK\n"
|
|
|
|
"B1\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"1 REF __time_period\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"1 REF i\n"
|
|
|
|
"0 RUN __get__\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"0 OUT time\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"B1\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"1 REF __tick\n"
|
|
|
|
"2 REF __time_period\n"
|
|
|
|
"2 REF i\n"
|
|
|
|
"1 RUN __get__\n"
|
|
|
|
"0 OPT >\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"0 JEZ 1\n"
|
|
|
|
"B2\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"1 REF __calls_period\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"1 REF i\n"
|
|
|
|
"0 RUN __get__\n"
|
|
|
|
"0 OUT todo\n"
|
|
|
|
"B2\n"
|
|
|
|
"0 RUN todo\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"B2\n"
|
|
|
|
"1 REF __time_period\n"
|
|
|
|
"1 REF i\n"
|
|
|
|
"2 REF __tick\n"
|
|
|
|
"3 REF __assert_period\n"
|
|
|
|
"3 REF i\n"
|
|
|
|
"2 RUN __get__\n"
|
|
|
|
"1 OPT +\n"
|
|
|
|
"1 STR __time_period\n"
|
|
|
|
"0 RUN __set__\n"
|
2022-01-23 21:31:07 +08:00
|
|
|
"B0\n"
|
|
|
|
"0 JMP -1\n"
|
|
|
|
"B0\n"
|
|
|
|
"0 DEL _l0\n"
|
2022-01-23 21:50:05 +08:00
|
|
|
"B0 \n");
|
2022-01-20 18:16:08 +08:00
|
|
|
}
|
|
|
|
|
2022-01-20 21:50:38 +08:00
|
|
|
void PikaStdTask_Task_run_always(PikaObj* self) {
|
|
|
|
while (1) {
|
2022-01-20 18:16:08 +08:00
|
|
|
PikaStdTask_Task_run_once(self);
|
|
|
|
}
|
|
|
|
}
|
2022-01-23 21:31:07 +08:00
|
|
|
|
|
|
|
void PikaStdTask_Task_platformGetTick(PikaObj* self) {
|
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
|
|
|
}
|