mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
use PIKA_PYTHON macro instead of comment
This commit is contained in:
parent
0fa29a0a14
commit
d384352c2c
@ -3,9 +3,11 @@
|
||||
|
||||
extern PikaObj* __pikaMain;
|
||||
void PikaStdTask_Task___init__(PikaObj* self) {
|
||||
// obj_run(self,
|
||||
// "calls.__init__()\n"
|
||||
// "is_period = 0\n");
|
||||
PIKA_PYTHON(
|
||||
calls.__init__()
|
||||
is_period = 0
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] = {
|
||||
0x0c, 0x00, /* instruct array size */
|
||||
0x00, 0x82, 0x01, 0x00, 0x00, 0x85, 0x10, 0x00, 0x00, 0x04, 0x12, 0x00,
|
||||
@ -15,15 +17,18 @@ void PikaStdTask_Task___init__(PikaObj* self) {
|
||||
0x74, 0x5f, 0x5f, 0x00, 0x30, 0x00, 0x69, 0x73, 0x5f, 0x70, 0x65, 0x72,
|
||||
0x69, 0x6f, 0x64, 0x00, /* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
obj_setPtr(__pikaMain, "__calls", obj_getPtr(self, "calls"));
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
||||
obj_setArg(self, "fun_todo", fun_todo);
|
||||
// obj_run(self,
|
||||
// "calls.append('always')\n"
|
||||
// "calls.append(fun_todo)\n");
|
||||
PIKA_PYTHON(
|
||||
calls.append('always')
|
||||
calls.append(fun_todo)
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] = {
|
||||
0x10, 0x00, /* instruct array size */
|
||||
0x10, 0x83, 0x01, 0x00, 0x00, 0x02, 0x08, 0x00, 0x10, 0x81, 0x15,
|
||||
@ -33,17 +38,19 @@ void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
||||
0x6c, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x00, 0x66,
|
||||
0x75, 0x6e, 0x5f, 0x74, 0x6f, 0x64, 0x6f, 0x00, /* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
}
|
||||
|
||||
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);
|
||||
/* obj_run(self,
|
||||
"calls.append('when')\n"
|
||||
"calls.append(fun_when)\n"
|
||||
"calls.append(fun_todo)\n");
|
||||
*/
|
||||
PIKA_PYTHON(
|
||||
calls.append('when')
|
||||
calls.append(fun_when)
|
||||
calls.append(fun_todo)
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] = {
|
||||
0x18, 0x00, /* instruct array size */
|
||||
0x10, 0x83, 0x01, 0x00, 0x00, 0x02, 0x06, 0x00, 0x10, 0x81, 0x13, 0x00,
|
||||
@ -56,6 +63,7 @@ void PikaStdTask_Task_call_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {
|
||||
0x00,
|
||||
/* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
}
|
||||
|
||||
@ -64,13 +72,14 @@ void PikaStdTask_Task_call_period_ms(PikaObj* self,
|
||||
int period_ms) {
|
||||
obj_setArg(self, "fun_todo", fun_todo);
|
||||
obj_setInt(self, "period_ms", period_ms);
|
||||
/* obj_run(self,
|
||||
"calls.append('period_ms')\n"
|
||||
"calls.append(period_ms)\n"
|
||||
"calls.append(fun_todo)\n"
|
||||
"calls.append(0)\n"
|
||||
"is_period = 1\n");
|
||||
*/
|
||||
PIKA_PYTHON(
|
||||
calls.append('period_ms')
|
||||
calls.append(period_ms)
|
||||
calls.append(fun_todo)
|
||||
calls.append(0)
|
||||
is_period = 1
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] =
|
||||
{
|
||||
0x28, 0x00, /* instruct array size */
|
||||
@ -85,50 +94,51 @@ void PikaStdTask_Task_call_period_ms(PikaObj* self,
|
||||
0x30, 0x00, 0x31, 0x00, 0x69, 0x73, 0x5f, 0x70, 0x65, 0x72, 0x69,
|
||||
0x6f, 0x64, 0x00, /* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_run_once(PikaObj* self) {
|
||||
/* transfer the tick to pikaMain */
|
||||
obj_setInt(__pikaMain, "__tick", obj_getInt(self, "tick"));
|
||||
/* obj_run(__pikaMain,
|
||||
"len = __calls.len()\n"
|
||||
"mode = 'none'\n"
|
||||
"info_index = 0\n"
|
||||
"for i in range(0, len):\n"
|
||||
" if len == 0:\n"
|
||||
" break\n"
|
||||
" if info_index == 0:\n"
|
||||
" mode = __calls[i]\n"
|
||||
" info_index = 1\n"
|
||||
" elif info_index == 1:\n"
|
||||
" if mode == 'always':\n"
|
||||
" todo = __calls[i]\n"
|
||||
" todo()\n"
|
||||
" info_index = 0\n"
|
||||
" elif mode == 'when':\n"
|
||||
" when = __calls[i]\n"
|
||||
" info_index = 2\n"
|
||||
" elif mode == 'period_ms':\n"
|
||||
" period_ms = __calls[i]\n"
|
||||
" info_index = 2\n"
|
||||
" elif info_index == 2:\n"
|
||||
" if mode == 'when':\n"
|
||||
" if when():\n"
|
||||
" todo = __calls[i]\n"
|
||||
" todo()\n"
|
||||
" info_index = 0\n"
|
||||
" elif mode == 'period_ms':\n"
|
||||
" todo = __calls[i]\n"
|
||||
" info_index = 3\n"
|
||||
" elif info_index == 3:\n"
|
||||
" if mode == 'period_ms':\n"
|
||||
" if __tick > __calls[i]:\n"
|
||||
" todo()\n"
|
||||
" __calls[i] = __tick + period_ms\n"
|
||||
" info_index = 0\n"
|
||||
"\n");
|
||||
*/
|
||||
PIKA_PYTHON(
|
||||
len = __calls.len()
|
||||
mode = 'none'
|
||||
info_index = 0
|
||||
for i in range(0, len):
|
||||
if len == 0:
|
||||
break
|
||||
if info_index == 0:
|
||||
mode = __calls[i]
|
||||
info_index = 1
|
||||
elif info_index == 1:
|
||||
if mode == 'always':
|
||||
todo = __calls[i]
|
||||
todo()
|
||||
info_index = 0
|
||||
elif mode == 'when':
|
||||
when = __calls[i]
|
||||
info_index = 2
|
||||
elif mode == 'period_ms':
|
||||
period_ms = __calls[i]
|
||||
info_index = 2
|
||||
elif info_index == 2:
|
||||
if mode == 'when':
|
||||
if when():
|
||||
todo = __calls[i]
|
||||
todo()
|
||||
info_index = 0
|
||||
elif mode == 'period_ms':
|
||||
todo = __calls[i]
|
||||
info_index = 3
|
||||
elif info_index == 3:
|
||||
if mode == 'period_ms':
|
||||
if __tick > __calls[i]:
|
||||
todo()
|
||||
__calls[i] = __tick + period_ms
|
||||
info_index = 0
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] = {
|
||||
0x08, 0x02, /* instruct array size */
|
||||
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x0d, 0x00, 0x00, 0x83, 0x11, 0x00,
|
||||
@ -192,6 +202,7 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
|
||||
0x5f, 0x74, 0x69, 0x63, 0x6b, 0x00, 0x3e, 0x00, 0x2b, 0x00, 0x5f, 0x5f,
|
||||
0x73, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(__pikaMain, (uint8_t*)bytes);
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,11 @@
|
||||
|
||||
extern PikaObj* __pikaMain;
|
||||
void PikaStdTask_Task___init__(PikaObj* self) {
|
||||
// obj_run(self,
|
||||
// "calls.__init__()\n"
|
||||
// "is_period = 0\n");
|
||||
PIKA_PYTHON(
|
||||
calls.__init__()
|
||||
is_period = 0
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] = {
|
||||
0x0c, 0x00, /* instruct array size */
|
||||
0x00, 0x82, 0x01, 0x00, 0x00, 0x85, 0x10, 0x00, 0x00, 0x04, 0x12, 0x00,
|
||||
@ -15,15 +17,18 @@ void PikaStdTask_Task___init__(PikaObj* self) {
|
||||
0x74, 0x5f, 0x5f, 0x00, 0x30, 0x00, 0x69, 0x73, 0x5f, 0x70, 0x65, 0x72,
|
||||
0x69, 0x6f, 0x64, 0x00, /* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
obj_setPtr(__pikaMain, "__calls", obj_getPtr(self, "calls"));
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
||||
obj_setArg(self, "fun_todo", fun_todo);
|
||||
// obj_run(self,
|
||||
// "calls.append('always')\n"
|
||||
// "calls.append(fun_todo)\n");
|
||||
PIKA_PYTHON(
|
||||
calls.append('always')
|
||||
calls.append(fun_todo)
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] = {
|
||||
0x10, 0x00, /* instruct array size */
|
||||
0x10, 0x83, 0x01, 0x00, 0x00, 0x02, 0x08, 0x00, 0x10, 0x81, 0x15,
|
||||
@ -33,17 +38,19 @@ void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
||||
0x6c, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x65, 0x6e, 0x64, 0x00, 0x66,
|
||||
0x75, 0x6e, 0x5f, 0x74, 0x6f, 0x64, 0x6f, 0x00, /* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
}
|
||||
|
||||
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);
|
||||
/* obj_run(self,
|
||||
"calls.append('when')\n"
|
||||
"calls.append(fun_when)\n"
|
||||
"calls.append(fun_todo)\n");
|
||||
*/
|
||||
PIKA_PYTHON(
|
||||
calls.append('when')
|
||||
calls.append(fun_when)
|
||||
calls.append(fun_todo)
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] = {
|
||||
0x18, 0x00, /* instruct array size */
|
||||
0x10, 0x83, 0x01, 0x00, 0x00, 0x02, 0x06, 0x00, 0x10, 0x81, 0x13, 0x00,
|
||||
@ -56,6 +63,7 @@ void PikaStdTask_Task_call_when(PikaObj* self, Arg* fun_todo, Arg* fun_when) {
|
||||
0x00,
|
||||
/* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
}
|
||||
|
||||
@ -64,13 +72,14 @@ void PikaStdTask_Task_call_period_ms(PikaObj* self,
|
||||
int period_ms) {
|
||||
obj_setArg(self, "fun_todo", fun_todo);
|
||||
obj_setInt(self, "period_ms", period_ms);
|
||||
/* obj_run(self,
|
||||
"calls.append('period_ms')\n"
|
||||
"calls.append(period_ms)\n"
|
||||
"calls.append(fun_todo)\n"
|
||||
"calls.append(0)\n"
|
||||
"is_period = 1\n");
|
||||
*/
|
||||
PIKA_PYTHON(
|
||||
calls.append('period_ms')
|
||||
calls.append(period_ms)
|
||||
calls.append(fun_todo)
|
||||
calls.append(0)
|
||||
is_period = 1
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] =
|
||||
{
|
||||
0x28, 0x00, /* instruct array size */
|
||||
@ -85,50 +94,51 @@ void PikaStdTask_Task_call_period_ms(PikaObj* self,
|
||||
0x30, 0x00, 0x31, 0x00, 0x69, 0x73, 0x5f, 0x70, 0x65, 0x72, 0x69,
|
||||
0x6f, 0x64, 0x00, /* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_run_once(PikaObj* self) {
|
||||
/* transfer the tick to pikaMain */
|
||||
obj_setInt(__pikaMain, "__tick", obj_getInt(self, "tick"));
|
||||
/* obj_run(__pikaMain,
|
||||
"len = __calls.len()\n"
|
||||
"mode = 'none'\n"
|
||||
"info_index = 0\n"
|
||||
"for i in range(0, len):\n"
|
||||
" if len == 0:\n"
|
||||
" break\n"
|
||||
" if info_index == 0:\n"
|
||||
" mode = __calls[i]\n"
|
||||
" info_index = 1\n"
|
||||
" elif info_index == 1:\n"
|
||||
" if mode == 'always':\n"
|
||||
" todo = __calls[i]\n"
|
||||
" todo()\n"
|
||||
" info_index = 0\n"
|
||||
" elif mode == 'when':\n"
|
||||
" when = __calls[i]\n"
|
||||
" info_index = 2\n"
|
||||
" elif mode == 'period_ms':\n"
|
||||
" period_ms = __calls[i]\n"
|
||||
" info_index = 2\n"
|
||||
" elif info_index == 2:\n"
|
||||
" if mode == 'when':\n"
|
||||
" if when():\n"
|
||||
" todo = __calls[i]\n"
|
||||
" todo()\n"
|
||||
" info_index = 0\n"
|
||||
" elif mode == 'period_ms':\n"
|
||||
" todo = __calls[i]\n"
|
||||
" info_index = 3\n"
|
||||
" elif info_index == 3:\n"
|
||||
" if mode == 'period_ms':\n"
|
||||
" if __tick > __calls[i]:\n"
|
||||
" todo()\n"
|
||||
" __calls[i] = __tick + period_ms\n"
|
||||
" info_index = 0\n"
|
||||
"\n");
|
||||
*/
|
||||
PIKA_PYTHON(
|
||||
len = __calls.len()
|
||||
mode = 'none'
|
||||
info_index = 0
|
||||
for i in range(0, len):
|
||||
if len == 0:
|
||||
break
|
||||
if info_index == 0:
|
||||
mode = __calls[i]
|
||||
info_index = 1
|
||||
elif info_index == 1:
|
||||
if mode == 'always':
|
||||
todo = __calls[i]
|
||||
todo()
|
||||
info_index = 0
|
||||
elif mode == 'when':
|
||||
when = __calls[i]
|
||||
info_index = 2
|
||||
elif mode == 'period_ms':
|
||||
period_ms = __calls[i]
|
||||
info_index = 2
|
||||
elif info_index == 2:
|
||||
if mode == 'when':
|
||||
if when():
|
||||
todo = __calls[i]
|
||||
todo()
|
||||
info_index = 0
|
||||
elif mode == 'period_ms':
|
||||
todo = __calls[i]
|
||||
info_index = 3
|
||||
elif info_index == 3:
|
||||
if mode == 'period_ms':
|
||||
if __tick > __calls[i]:
|
||||
todo()
|
||||
__calls[i] = __tick + period_ms
|
||||
info_index = 0
|
||||
)
|
||||
PIKA_BYTECODE_BEGIN
|
||||
const uint8_t bytes[] = {
|
||||
0x08, 0x02, /* instruct array size */
|
||||
0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x0d, 0x00, 0x00, 0x83, 0x11, 0x00,
|
||||
@ -192,6 +202,7 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
|
||||
0x5f, 0x74, 0x69, 0x63, 0x6b, 0x00, 0x3e, 0x00, 0x2b, 0x00, 0x5f, 0x5f,
|
||||
0x73, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const pool */
|
||||
};
|
||||
PIKA_BYTECODE_END
|
||||
pikaVM_runByteCode(__pikaMain, (uint8_t*)bytes);
|
||||
}
|
||||
|
||||
|
@ -41,4 +41,6 @@ int32_t obj_newObj(PikaObj* self,
|
||||
char* className,
|
||||
NewFun newFunPtr);
|
||||
Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -452,11 +452,11 @@ static int32_t __class_defineMethodWithType(PikaObj* self,
|
||||
goto exit;
|
||||
}
|
||||
methodName = strPointToLastToken(methodPath, '.');
|
||||
method_info.dec = cleanDeclearation;
|
||||
method_info.name = methodName;
|
||||
method_info.ptr = (void*)methodPtr;
|
||||
method_info.type = method_type;
|
||||
method_info.bytecode_frame = bytecode_frame;
|
||||
method_info.dec = cleanDeclearation;
|
||||
method_info.name = methodName;
|
||||
method_info.ptr = (void*)methodPtr;
|
||||
method_info.type = method_type;
|
||||
method_info.bytecode_frame = bytecode_frame;
|
||||
obj_saveMethodInfo(methodHost, &method_info);
|
||||
res = 0;
|
||||
goto exit;
|
||||
|
@ -220,4 +220,8 @@ int pikaCompile(char* output_file_name, char* py_lines);
|
||||
Method obj_getNativeMethod(PikaObj* self, char* method_name);
|
||||
void obj_runNativeMethod(PikaObj* self, char* method_name, Args* args);
|
||||
|
||||
#define PIKA_PYTHON(x)
|
||||
#define PIKA_BYTECODE_BEGIN
|
||||
#define PIKA_BYTECODE_END
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user