mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
update PikaStdTask
This commit is contained in:
parent
0592c44d71
commit
f5fab030c0
@ -54,9 +54,14 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
|
||||
"0 DEL _l0\n"
|
||||
"B0\n");
|
||||
obj_run(__pikaMain,
|
||||
"for i in range(0, __calls_when.len()):\n"
|
||||
" if __assert_when[i]():\n"
|
||||
" __calls_when()\n");
|
||||
"len = __calls_when.len()\n"
|
||||
"for i in range(0, len):\n"
|
||||
" if len == 0:\n"
|
||||
" break\n"
|
||||
" when = __assert_when[i]\n"
|
||||
" if when():\n"
|
||||
" todo = __calls_when[i]\n"
|
||||
" todo()\n");
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_run_always(PikaObj* self) {
|
||||
|
0
port/linux/api-make-linux.sh
Normal file → Executable file
0
port/linux/api-make-linux.sh
Normal file → Executable file
0
port/linux/api-make-win10.sh
Normal file → Executable file
0
port/linux/api-make-win10.sh
Normal file → Executable file
0
port/linux/api-make.sh
Normal file → Executable file
0
port/linux/api-make.sh
Normal file → Executable file
0
port/linux/ci_benchmark.sh
Normal file → Executable file
0
port/linux/ci_benchmark.sh
Normal file → Executable file
0
port/linux/gtest.sh
Normal file → Executable file
0
port/linux/gtest.sh
Normal file → Executable file
0
port/linux/init.sh
Normal file → Executable file
0
port/linux/init.sh
Normal file → Executable file
0
port/linux/install_dependency.sh
Normal file → Executable file
0
port/linux/install_dependency.sh
Normal file → Executable file
0
port/linux/make.sh
Normal file → Executable file
0
port/linux/make.sh
Normal file → Executable file
@ -13,8 +13,12 @@ def todo2():
|
||||
def todo3():
|
||||
print('task 3 running...')
|
||||
|
||||
def when3():
|
||||
return True
|
||||
|
||||
task = PikaStdTask.Task()
|
||||
task.call_always(todo1)
|
||||
task.call_always(todo2)
|
||||
# task.call_when(todo3, when3)
|
||||
|
||||
task.run_once()
|
||||
|
@ -54,9 +54,14 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
|
||||
"0 DEL _l0\n"
|
||||
"B0\n");
|
||||
obj_run(__pikaMain,
|
||||
"for i in range(0, __calls_when.len()):\n"
|
||||
" if __assert_when[i]():\n"
|
||||
" __calls_when()\n");
|
||||
"len = __calls_when.len()\n"
|
||||
"for i in range(0, len):\n"
|
||||
" if len == 0:\n"
|
||||
" break\n"
|
||||
" when = __assert_when[i]\n"
|
||||
" if when():\n"
|
||||
" todo = __calls_when[i]\n"
|
||||
" todo()\n");
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_run_always(PikaObj* self) {
|
||||
|
0
port/linux/pkg-push.sh
Normal file → Executable file
0
port/linux/pkg-push.sh
Normal file → Executable file
0
port/linux/pull-core.sh
Normal file → Executable file
0
port/linux/pull-core.sh
Normal file → Executable file
0
port/linux/push-core.sh
Normal file → Executable file
0
port/linux/push-core.sh
Normal file → Executable file
0
port/linux/run.sh
Normal file → Executable file
0
port/linux/run.sh
Normal file → Executable file
0
port/linux/test-banchmark.sh
Normal file → Executable file
0
port/linux/test-banchmark.sh
Normal file → Executable file
@ -1893,7 +1893,11 @@ TEST(parser, test__) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
Args* buffs = New_strBuff();
|
||||
char* lines = (char*)
|
||||
"calls_always.append(fun_todo)";
|
||||
"for i in range(0, __calls_when.len()):\n"
|
||||
" when = __assert_when[i]\n"
|
||||
" if when():\n"
|
||||
" todo = __calls_when[i]\n"
|
||||
" todo()\n";
|
||||
printf("%s", lines);
|
||||
char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines);
|
||||
printf("%s", pikaAsm);
|
||||
|
@ -874,13 +874,12 @@ TEST(pikaMain, dict_index) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
extern PikaObj* __pikaMain;
|
||||
TEST(pikaMain, task_run_once) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
/* run */
|
||||
__pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
obj_run(__pikaMain,(char*)
|
||||
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
obj_run(pikaMain,(char*)
|
||||
"def todo1():\n"
|
||||
" print('task 1 running...')\n"
|
||||
"def todo2():\n"
|
||||
@ -891,7 +890,6 @@ TEST(pikaMain, task_run_once) {
|
||||
"task.run_once()\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
PikaObj* pikaMain = __pikaMain;
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[0], (char*)"task 2 running...\r\n");
|
||||
EXPECT_STREQ(log_buff[1], (char*)"task 1 running...\r\n");
|
||||
@ -899,3 +897,33 @@ TEST(pikaMain, task_run_once) {
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, task_run_when) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
/* run */
|
||||
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
obj_run(pikaMain,(char*)
|
||||
"def todo1():\n"
|
||||
" print('task 1 running...')\n"
|
||||
"def todo2():\n"
|
||||
" print('task 2 running...')\n"
|
||||
"def todo3():\n"
|
||||
" print('task 3 running...')\n"
|
||||
"def when3():\n"
|
||||
" return True\n"
|
||||
"task = PikaStdTask.Task()\n"
|
||||
"task.call_always(todo1)\n"
|
||||
"task.call_always(todo2)\n"
|
||||
"task.call_when(todo3, when3)\n"
|
||||
"task.run_once()\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[0], (char*)"task 3 running...\r\n");
|
||||
EXPECT_STREQ(log_buff[1], (char*)"task 2 running...\r\n");
|
||||
EXPECT_STREQ(log_buff[2], (char*)"task 1 running...\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
0
port/linux/update-compiler.sh
Normal file → Executable file
0
port/linux/update-compiler.sh
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user