mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
use PikaAsm in Task_Run_Once
This commit is contained in:
parent
fc7028c158
commit
56069510c3
@ -2,14 +2,15 @@ from PikaObj import *
|
||||
import PikaStdData
|
||||
|
||||
class Task(TinyObj):
|
||||
task_list = PikaStdData.List()
|
||||
task_list_always = PikaStdData.List()
|
||||
task_list_when = PikaStdData.List()
|
||||
def __init__():
|
||||
pass
|
||||
|
||||
def call_always(fun_todo: any):
|
||||
pass
|
||||
|
||||
def do_when(fun_todo: any, fun_when: any):
|
||||
def call_when(fun_todo: any, fun_when: any):
|
||||
pass
|
||||
|
||||
def run_once():
|
||||
|
@ -1,29 +1,45 @@
|
||||
#include "PikaStdTask_Task.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaVM.h"
|
||||
|
||||
extern PikaObj* __pikaMain;
|
||||
void PikaStdTask_Task___init__(PikaObj* self) {
|
||||
obj_run(self, "task_list.__init__()");
|
||||
obj_run(self, "task_list_always.__init__()");
|
||||
obj_run(self, "task_list_when.__init__()");
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
||||
obj_setArg(self, "fun_todo", fun_todo);
|
||||
obj_run(self, "task_list.append(fun_todo)");
|
||||
// pikaVM_runAsm(__pikaMain, fun_todo_ptr);
|
||||
obj_run(self, "task_list_always.append(fun_todo)");
|
||||
}
|
||||
void PikaStdTask_Task_do_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {}
|
||||
|
||||
void PikaStdTask_Task_call_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {}
|
||||
|
||||
void PikaStdTask_Task_run_once(PikaObj* self) {
|
||||
/* reference the task_list in __pikaMain */
|
||||
obj_setPtr(__pikaMain, "__task_list", obj_getPtr(self, "task_list"));
|
||||
obj_run(__pikaMain,
|
||||
"for fun_todo in __task_list :\n"
|
||||
" fun_todo()\n"
|
||||
"\n"
|
||||
);
|
||||
/* reference the task_list_always in __pikaMain */
|
||||
obj_setPtr(__pikaMain, "__task_list_always",
|
||||
obj_getPtr(self, "task_list_always"));
|
||||
pikaVM_runAsm(__pikaMain,
|
||||
"B0\n"
|
||||
"1 REF __task_list_always\n"
|
||||
"0 RUN iter\n"
|
||||
"0 OUT _l0\n"
|
||||
"B0\n"
|
||||
"0 RUN _l0.__next__\n"
|
||||
"0 OUT fun_todo\n"
|
||||
"0 EST fun_todo\n"
|
||||
"0 JEZ 2\n"
|
||||
"B1\n"
|
||||
"0 RUN fun_todo\n"
|
||||
"B0\n"
|
||||
"0 JMP -1\n"
|
||||
"B0\n"
|
||||
"0 DEL _l0\n"
|
||||
"B0\n");
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_run_always(PikaObj *self){
|
||||
while (1){
|
||||
void PikaStdTask_Task_run_always(PikaObj* self) {
|
||||
while (1) {
|
||||
PikaStdTask_Task_run_once(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
@ -2,14 +2,15 @@ from PikaObj import *
|
||||
import PikaStdData
|
||||
|
||||
class Task(TinyObj):
|
||||
task_list = PikaStdData.List()
|
||||
task_list_always = PikaStdData.List()
|
||||
task_list_when = PikaStdData.List()
|
||||
def __init__():
|
||||
pass
|
||||
|
||||
def call_always(fun_todo: any):
|
||||
pass
|
||||
|
||||
def do_when(fun_todo: any, fun_when: any):
|
||||
def call_when(fun_todo: any, fun_when: any):
|
||||
pass
|
||||
|
||||
def run_once():
|
||||
|
@ -1,29 +1,45 @@
|
||||
#include "PikaStdTask_Task.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaVM.h"
|
||||
|
||||
extern PikaObj* __pikaMain;
|
||||
void PikaStdTask_Task___init__(PikaObj* self) {
|
||||
obj_run(self, "task_list.__init__()");
|
||||
obj_run(self, "task_list_always.__init__()");
|
||||
obj_run(self, "task_list_when.__init__()");
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
||||
obj_setArg(self, "fun_todo", fun_todo);
|
||||
obj_run(self, "task_list.append(fun_todo)");
|
||||
// pikaVM_runAsm(__pikaMain, fun_todo_ptr);
|
||||
obj_run(self, "task_list_always.append(fun_todo)");
|
||||
}
|
||||
void PikaStdTask_Task_do_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {}
|
||||
|
||||
void PikaStdTask_Task_call_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {}
|
||||
|
||||
void PikaStdTask_Task_run_once(PikaObj* self) {
|
||||
/* reference the task_list in __pikaMain */
|
||||
obj_setPtr(__pikaMain, "__task_list", obj_getPtr(self, "task_list"));
|
||||
obj_run(__pikaMain,
|
||||
"for fun_todo in __task_list :\n"
|
||||
" fun_todo()\n"
|
||||
"\n"
|
||||
);
|
||||
/* reference the task_list_always in __pikaMain */
|
||||
obj_setPtr(__pikaMain, "__task_list_always",
|
||||
obj_getPtr(self, "task_list_always"));
|
||||
pikaVM_runAsm(__pikaMain,
|
||||
"B0\n"
|
||||
"1 REF __task_list_always\n"
|
||||
"0 RUN iter\n"
|
||||
"0 OUT _l0\n"
|
||||
"B0\n"
|
||||
"0 RUN _l0.__next__\n"
|
||||
"0 OUT fun_todo\n"
|
||||
"0 EST fun_todo\n"
|
||||
"0 JEZ 2\n"
|
||||
"B1\n"
|
||||
"0 RUN fun_todo\n"
|
||||
"B0\n"
|
||||
"0 JMP -1\n"
|
||||
"B0\n"
|
||||
"0 DEL _l0\n"
|
||||
"B0\n");
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_run_always(PikaObj *self){
|
||||
while (1){
|
||||
void PikaStdTask_Task_run_always(PikaObj* self) {
|
||||
while (1) {
|
||||
PikaStdTask_Task_run_once(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
@ -1887,3 +1887,36 @@ TEST(parser, __set__) {
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
|
||||
TEST(parser, test__) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
Args* buffs = New_strBuff();
|
||||
char* lines = (char*)
|
||||
"for fun_todo in __task_list_always :\n"
|
||||
" fun_todo()\n"
|
||||
"\n";
|
||||
printf("%s", lines);
|
||||
char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines);
|
||||
printf("%s", pikaAsm);
|
||||
EXPECT_STREQ(pikaAsm,
|
||||
"B0\n"
|
||||
"1 REF __task_list_always\n"
|
||||
"0 RUN iter\n"
|
||||
"0 OUT _l0\n"
|
||||
"B0\n"
|
||||
"0 RUN _l0.__next__\n"
|
||||
"0 OUT fun_todo\n"
|
||||
"0 EST fun_todo\n"
|
||||
"0 JEZ 2\n"
|
||||
"B1\n"
|
||||
"0 RUN fun_todo\n"
|
||||
"B0\n"
|
||||
"0 JMP -1\n"
|
||||
"B0\n"
|
||||
"0 DEL _l0\n"
|
||||
"B0\n"
|
||||
);
|
||||
args_deinit(buffs);
|
||||
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