update PikaStdTask to bytecode based

This commit is contained in:
lyon1998 2022-03-17 16:47:03 +08:00
parent 494f61a562
commit ff1c71322b
4 changed files with 149 additions and 360 deletions

View File

@ -45,7 +45,7 @@ void PikaStdLib_SysObj_type(PikaObj* self, Arg* arg) {
obj_setSysOut(self, "mate_object"); obj_setSysOut(self, "mate_object");
return; return;
} }
if (ARG_TYPE_STATIC_METHOD == type) { if (ARG_TYPE_NATIVE_METHOD == type) {
obj_setSysOut(self, "method"); obj_setSysOut(self, "method");
return; return;
} }
@ -79,22 +79,22 @@ int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg) {
char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) { char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
ArgType type = arg_getType(arg); ArgType type = arg_getType(arg);
Args* buffs = New_strBuff(); Args buffs = {0};
char* res = NULL; char* res = NULL;
do { do {
if (ARG_TYPE_INT == type) { if (ARG_TYPE_INT == type) {
int val = arg_getInt(arg); int val = arg_getInt(arg);
res = strsFormat(buffs, 11, "%d", val); res = strsFormat(&buffs, 11, "%d", val);
break; break;
} }
if (ARG_TYPE_FLOAT == type) { if (ARG_TYPE_FLOAT == type) {
float val = arg_getFloat(arg); float val = arg_getFloat(arg);
res = strsFormat(buffs, 11, "%f", val); res = strsFormat(&buffs, 11, "%f", val);
break; break;
} }
} while (0); } while (0);
obj_setStr(self, "__strtmp", res); obj_setStr(self, "__strtmp", res);
args_deinit(buffs); strsDeinit(&buffs);
return obj_getStr(self, "__strtmp"); return obj_getStr(self, "__strtmp");
} }

View File

@ -80,176 +80,70 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
" info_index = 0\n" " info_index = 0\n"
"\n"); "\n");
*/ */
pikaVM_runAsm(__pikaMain, const uint8_t bytes[] = {
"B0\n" 0x08, 0x02, /* instruct array size */
"0 RUN __calls.len\n" 0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x0d, 0x00, 0x00, 0x83, 0x11, 0x00,
"0 OUT len\n" 0x00, 0x04, 0x16, 0x00, 0x00, 0x85, 0x1b, 0x00, 0x00, 0x04, 0x1d, 0x00,
"B0\n" 0x20, 0x85, 0x1b, 0x00, 0x20, 0x01, 0x0d, 0x00, 0x10, 0x02, 0x28, 0x00,
"0 STR none\n" 0x00, 0x02, 0x2e, 0x00, 0x00, 0x04, 0x33, 0x00, 0x00, 0x01, 0x37, 0x00,
"0 OUT mode\n" 0x00, 0x01, 0x3b, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x00, 0x04, 0x43, 0x00,
"B0\n" 0x00, 0x04, 0x4a, 0x00, 0x00, 0x04, 0x51, 0x00, 0x00, 0x82, 0x58, 0x00,
"0 NUM 0\n" 0x00, 0x04, 0x65, 0x00, 0x00, 0x0d, 0x65, 0x00, 0x00, 0x07, 0x67, 0x00,
"0 OUT info_index\n" 0x11, 0x81, 0x0d, 0x00, 0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x69, 0x00,
"B0\n" 0x01, 0x07, 0x6c, 0x00, 0x02, 0x8e, 0x6c, 0x00, 0x11, 0x81, 0x1d, 0x00,
"2 NUM 0\n" 0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00,
"2 REF len\n" 0x12, 0x81, 0x6e, 0x00, 0x12, 0x01, 0x65, 0x00, 0x02, 0x02, 0x76, 0x00,
"1 RUN range\n" 0x02, 0x04, 0x16, 0x00, 0x02, 0x85, 0x6c, 0x00, 0x02, 0x04, 0x1d, 0x00,
"0 RUN iter\n" 0x01, 0x8b, 0x6c, 0x00, 0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x6c, 0x00,
"0 OUT _l0\n" 0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00, 0x12, 0x81, 0x16, 0x00,
"0 REF _r1\n" 0x12, 0x03, 0x7e, 0x00, 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00,
"0 REF _r2\n" 0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00,
"0 REF _r3\n" 0x03, 0x04, 0x85, 0x00, 0x03, 0x82, 0x85, 0x00, 0x03, 0x85, 0x1b, 0x00,
"0 OUT _l0.a1\n" 0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x6c, 0x00, 0x12, 0x01, 0x16, 0x00,
"0 OUT _l0.a2\n" 0x12, 0x03, 0x8a, 0x00, 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00,
"0 OUT _l0.a3\n" 0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00,
"B0\n" 0x03, 0x04, 0x8a, 0x00, 0x03, 0x85, 0x67, 0x00, 0x03, 0x04, 0x1d, 0x00,
"0 RUN _l0.__next__\n" 0x02, 0x8b, 0x6c, 0x00, 0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00,
"0 OUT i\n" 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x6e, 0x00,
"0 EST i\n" 0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00, 0x03, 0x04, 0x8f, 0x00,
"0 JEZ 2\n" 0x03, 0x85, 0x67, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x6c, 0x00,
"B1\n" 0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x67, 0x00, 0x01, 0x08, 0x69, 0x00,
"1 REF len\n" 0x01, 0x07, 0x6c, 0x00, 0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x8a, 0x00,
"1 NUM 0\n" 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00, 0x03, 0x82, 0x8a, 0x00,
"0 OPT ==\n" 0x03, 0x07, 0x6c, 0x00, 0x14, 0x81, 0x6e, 0x00, 0x14, 0x01, 0x65, 0x00,
"0 JEZ 1\n" 0x04, 0x02, 0x76, 0x00, 0x04, 0x04, 0x85, 0x00, 0x04, 0x82, 0x85, 0x00,
"B2\n" 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x6c, 0x00,
"0 BRK\n" 0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00, 0x02, 0x08, 0x69, 0x00,
"B1\n" 0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00,
"1 REF info_index\n" 0x03, 0x02, 0x76, 0x00, 0x03, 0x04, 0x85, 0x00, 0x03, 0x85, 0x99, 0x00,
"1 NUM 0\n" 0x03, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x6c, 0x00, 0x11, 0x01, 0x1d, 0x00,
"0 OPT ==\n" 0x11, 0x05, 0x99, 0x00, 0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00,
"0 JEZ 1\n" 0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00, 0x02, 0x08, 0x69, 0x00,
"B2\n" 0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x9b, 0x00, 0x23, 0x01, 0x6e, 0x00,
"1 REF __calls\n" 0x23, 0x01, 0x65, 0x00, 0x13, 0x02, 0x76, 0x00, 0x03, 0x08, 0xa2, 0x00,
"1 REF i\n" 0x03, 0x07, 0x6c, 0x00, 0x04, 0x82, 0x85, 0x00, 0x14, 0x81, 0x6e, 0x00,
"0 RUN __get__\n" 0x14, 0x01, 0x65, 0x00, 0x24, 0x01, 0x9b, 0x00, 0x24, 0x01, 0x8f, 0x00,
"0 OUT mode\n" 0x14, 0x08, 0xa4, 0x00, 0x14, 0x03, 0x6e, 0x00, 0x04, 0x02, 0xa6, 0x00,
"B2\n" 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x00, 0x86, 0xae, 0x00,
"0 NUM 1\n" 0x00, 0x8c, 0x33, 0x00, /* instruct array */
"0 OUT info_index\n" 0xb1, 0x00, /* const pool size */
"B1\n" 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x2e, 0x6c, 0x65, 0x6e,
"0 NEL 1\n" 0x00, 0x6c, 0x65, 0x6e, 0x00, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x6d, 0x6f,
"1 REF info_index\n" 0x64, 0x65, 0x00, 0x30, 0x00, 0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x69, 0x6e,
"1 NUM 1\n" 0x64, 0x65, 0x78, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74,
"0 OPT ==\n" 0x65, 0x72, 0x00, 0x5f, 0x6c, 0x30, 0x00, 0x5f, 0x72, 0x31, 0x00, 0x5f,
"0 JEZ 1\n" 0x72, 0x32, 0x00, 0x5f, 0x72, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61,
"B2\n" 0x31, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61, 0x32, 0x00, 0x5f, 0x6c, 0x30,
"1 REF mode\n" 0x2e, 0x61, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65,
"1 STR always\n" 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00, 0x3d, 0x3d, 0x00,
"0 OPT ==\n" 0x31, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x00, 0x5f, 0x5f,
"0 JEZ 1\n" 0x67, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x61, 0x6c, 0x77, 0x61, 0x79, 0x73,
"B3\n" 0x00, 0x74, 0x6f, 0x64, 0x6f, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x00, 0x70,
"1 REF __calls\n" 0x65, 0x72, 0x69, 0x6f, 0x64, 0x5f, 0x6d, 0x73, 0x00, 0x33, 0x00, 0x5f,
"1 REF i\n" 0x5f, 0x74, 0x69, 0x63, 0x6b, 0x00, 0x3e, 0x00, 0x2b, 0x00, 0x5f, 0x5f,
"0 RUN __get__\n" 0x73, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const pool */
"0 OUT todo\n" };
"B3\n" pikaVM_runByteCode(__pikaMain, (uint8_t*)bytes);
"0 RUN todo\n"
"B3\n"
"0 NUM 0\n"
"0 OUT info_index\n"
"B2\n"
"0 NEL 1\n"
"1 REF mode\n"
"1 STR when\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"1 REF __calls\n"
"1 REF i\n"
"0 RUN __get__\n"
"0 OUT when\n"
"B3\n"
"0 NUM 2\n"
"0 OUT info_index\n"
"B2\n"
"0 NEL 1\n"
"1 REF mode\n"
"1 STR period_ms\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"1 REF __calls\n"
"1 REF i\n"
"0 RUN __get__\n"
"0 OUT period_ms\n"
"B3\n"
"0 NUM 2\n"
"0 OUT info_index\n"
"B1\n"
"0 NEL 1\n"
"1 REF info_index\n"
"1 NUM 2\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B2\n"
"1 REF mode\n"
"1 STR when\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"0 RUN when\n"
"0 JEZ 1\n"
"B4\n"
"1 REF __calls\n"
"1 REF i\n"
"0 RUN __get__\n"
"0 OUT todo\n"
"B4\n"
"0 RUN todo\n"
"B3\n"
"0 NUM 0\n"
"0 OUT info_index\n"
"B2\n"
"0 NEL 1\n"
"1 REF mode\n"
"1 STR period_ms\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"1 REF __calls\n"
"1 REF i\n"
"0 RUN __get__\n"
"0 OUT todo\n"
"B3\n"
"0 NUM 3\n"
"0 OUT info_index\n"
"B1\n"
"0 NEL 1\n"
"1 REF info_index\n"
"1 NUM 3\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B2\n"
"1 REF mode\n"
"1 STR period_ms\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"1 REF __tick\n"
"2 REF __calls\n"
"2 REF i\n"
"1 RUN __get__\n"
"0 OPT >\n"
"0 JEZ 1\n"
"B4\n"
"0 RUN todo\n"
"B4\n"
"1 REF __calls\n"
"1 REF i\n"
"2 REF __tick\n"
"2 REF period_ms\n"
"1 OPT +\n"
"1 STR __calls\n"
"0 RUN __set__\n"
"B3\n"
"0 NUM 0\n"
"0 OUT info_index\n"
"B0\n"
"0 JMP -1\n"
"B0\n"
"0 DEL _l0\n"
"B0\n");
} }
void __Task_update_tick(PikaObj* self) { void __Task_update_tick(PikaObj* self) {

View File

@ -80,176 +80,70 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
" info_index = 0\n" " info_index = 0\n"
"\n"); "\n");
*/ */
pikaVM_runAsm(__pikaMain, const uint8_t bytes[] = {
"B0\n" 0x08, 0x02, /* instruct array size */
"0 RUN __calls.len\n" 0x00, 0x82, 0x01, 0x00, 0x00, 0x04, 0x0d, 0x00, 0x00, 0x83, 0x11, 0x00,
"0 OUT len\n" 0x00, 0x04, 0x16, 0x00, 0x00, 0x85, 0x1b, 0x00, 0x00, 0x04, 0x1d, 0x00,
"B0\n" 0x20, 0x85, 0x1b, 0x00, 0x20, 0x01, 0x0d, 0x00, 0x10, 0x02, 0x28, 0x00,
"0 STR none\n" 0x00, 0x02, 0x2e, 0x00, 0x00, 0x04, 0x33, 0x00, 0x00, 0x01, 0x37, 0x00,
"0 OUT mode\n" 0x00, 0x01, 0x3b, 0x00, 0x00, 0x01, 0x3f, 0x00, 0x00, 0x04, 0x43, 0x00,
"B0\n" 0x00, 0x04, 0x4a, 0x00, 0x00, 0x04, 0x51, 0x00, 0x00, 0x82, 0x58, 0x00,
"0 NUM 0\n" 0x00, 0x04, 0x65, 0x00, 0x00, 0x0d, 0x65, 0x00, 0x00, 0x07, 0x67, 0x00,
"0 OUT info_index\n" 0x11, 0x81, 0x0d, 0x00, 0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x69, 0x00,
"B0\n" 0x01, 0x07, 0x6c, 0x00, 0x02, 0x8e, 0x6c, 0x00, 0x11, 0x81, 0x1d, 0x00,
"2 NUM 0\n" 0x11, 0x05, 0x1b, 0x00, 0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00,
"2 REF len\n" 0x12, 0x81, 0x6e, 0x00, 0x12, 0x01, 0x65, 0x00, 0x02, 0x02, 0x76, 0x00,
"1 RUN range\n" 0x02, 0x04, 0x16, 0x00, 0x02, 0x85, 0x6c, 0x00, 0x02, 0x04, 0x1d, 0x00,
"0 RUN iter\n" 0x01, 0x8b, 0x6c, 0x00, 0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x6c, 0x00,
"0 OUT _l0\n" 0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00, 0x12, 0x81, 0x16, 0x00,
"0 REF _r1\n" 0x12, 0x03, 0x7e, 0x00, 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00,
"0 REF _r2\n" 0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00,
"0 REF _r3\n" 0x03, 0x04, 0x85, 0x00, 0x03, 0x82, 0x85, 0x00, 0x03, 0x85, 0x1b, 0x00,
"0 OUT _l0.a1\n" 0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x6c, 0x00, 0x12, 0x01, 0x16, 0x00,
"0 OUT _l0.a2\n" 0x12, 0x03, 0x8a, 0x00, 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00,
"0 OUT _l0.a3\n" 0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00,
"B0\n" 0x03, 0x04, 0x8a, 0x00, 0x03, 0x85, 0x67, 0x00, 0x03, 0x04, 0x1d, 0x00,
"0 RUN _l0.__next__\n" 0x02, 0x8b, 0x6c, 0x00, 0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00,
"0 OUT i\n" 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x6e, 0x00,
"0 EST i\n" 0x13, 0x01, 0x65, 0x00, 0x03, 0x02, 0x76, 0x00, 0x03, 0x04, 0x8f, 0x00,
"0 JEZ 2\n" 0x03, 0x85, 0x67, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x6c, 0x00,
"B1\n" 0x11, 0x01, 0x1d, 0x00, 0x11, 0x05, 0x67, 0x00, 0x01, 0x08, 0x69, 0x00,
"1 REF len\n" 0x01, 0x07, 0x6c, 0x00, 0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x8a, 0x00,
"1 NUM 0\n" 0x02, 0x08, 0x69, 0x00, 0x02, 0x07, 0x6c, 0x00, 0x03, 0x82, 0x8a, 0x00,
"0 OPT ==\n" 0x03, 0x07, 0x6c, 0x00, 0x14, 0x81, 0x6e, 0x00, 0x14, 0x01, 0x65, 0x00,
"0 JEZ 1\n" 0x04, 0x02, 0x76, 0x00, 0x04, 0x04, 0x85, 0x00, 0x04, 0x82, 0x85, 0x00,
"B2\n" 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x02, 0x8b, 0x6c, 0x00,
"0 BRK\n" 0x12, 0x01, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00, 0x02, 0x08, 0x69, 0x00,
"B1\n" 0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x6e, 0x00, 0x13, 0x01, 0x65, 0x00,
"1 REF info_index\n" 0x03, 0x02, 0x76, 0x00, 0x03, 0x04, 0x85, 0x00, 0x03, 0x85, 0x99, 0x00,
"1 NUM 0\n" 0x03, 0x04, 0x1d, 0x00, 0x01, 0x8b, 0x6c, 0x00, 0x11, 0x01, 0x1d, 0x00,
"0 OPT ==\n" 0x11, 0x05, 0x99, 0x00, 0x01, 0x08, 0x69, 0x00, 0x01, 0x07, 0x6c, 0x00,
"0 JEZ 1\n" 0x12, 0x81, 0x16, 0x00, 0x12, 0x03, 0x8f, 0x00, 0x02, 0x08, 0x69, 0x00,
"B2\n" 0x02, 0x07, 0x6c, 0x00, 0x13, 0x81, 0x9b, 0x00, 0x23, 0x01, 0x6e, 0x00,
"1 REF __calls\n" 0x23, 0x01, 0x65, 0x00, 0x13, 0x02, 0x76, 0x00, 0x03, 0x08, 0xa2, 0x00,
"1 REF i\n" 0x03, 0x07, 0x6c, 0x00, 0x04, 0x82, 0x85, 0x00, 0x14, 0x81, 0x6e, 0x00,
"0 RUN __get__\n" 0x14, 0x01, 0x65, 0x00, 0x24, 0x01, 0x9b, 0x00, 0x24, 0x01, 0x8f, 0x00,
"0 OUT mode\n" 0x14, 0x08, 0xa4, 0x00, 0x14, 0x03, 0x6e, 0x00, 0x04, 0x02, 0xa6, 0x00,
"B2\n" 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x00, 0x86, 0xae, 0x00,
"0 NUM 1\n" 0x00, 0x8c, 0x33, 0x00, /* instruct array */
"0 OUT info_index\n" 0xb1, 0x00, /* const pool size */
"B1\n" 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x2e, 0x6c, 0x65, 0x6e,
"0 NEL 1\n" 0x00, 0x6c, 0x65, 0x6e, 0x00, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x6d, 0x6f,
"1 REF info_index\n" 0x64, 0x65, 0x00, 0x30, 0x00, 0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x69, 0x6e,
"1 NUM 1\n" 0x64, 0x65, 0x78, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74,
"0 OPT ==\n" 0x65, 0x72, 0x00, 0x5f, 0x6c, 0x30, 0x00, 0x5f, 0x72, 0x31, 0x00, 0x5f,
"0 JEZ 1\n" 0x72, 0x32, 0x00, 0x5f, 0x72, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61,
"B2\n" 0x31, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61, 0x32, 0x00, 0x5f, 0x6c, 0x30,
"1 REF mode\n" 0x2e, 0x61, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65,
"1 STR always\n" 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00, 0x3d, 0x3d, 0x00,
"0 OPT ==\n" 0x31, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x00, 0x5f, 0x5f,
"0 JEZ 1\n" 0x67, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x61, 0x6c, 0x77, 0x61, 0x79, 0x73,
"B3\n" 0x00, 0x74, 0x6f, 0x64, 0x6f, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x00, 0x70,
"1 REF __calls\n" 0x65, 0x72, 0x69, 0x6f, 0x64, 0x5f, 0x6d, 0x73, 0x00, 0x33, 0x00, 0x5f,
"1 REF i\n" 0x5f, 0x74, 0x69, 0x63, 0x6b, 0x00, 0x3e, 0x00, 0x2b, 0x00, 0x5f, 0x5f,
"0 RUN __get__\n" 0x73, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const pool */
"0 OUT todo\n" };
"B3\n" pikaVM_runByteCode(__pikaMain, (uint8_t*)bytes);
"0 RUN todo\n"
"B3\n"
"0 NUM 0\n"
"0 OUT info_index\n"
"B2\n"
"0 NEL 1\n"
"1 REF mode\n"
"1 STR when\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"1 REF __calls\n"
"1 REF i\n"
"0 RUN __get__\n"
"0 OUT when\n"
"B3\n"
"0 NUM 2\n"
"0 OUT info_index\n"
"B2\n"
"0 NEL 1\n"
"1 REF mode\n"
"1 STR period_ms\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"1 REF __calls\n"
"1 REF i\n"
"0 RUN __get__\n"
"0 OUT period_ms\n"
"B3\n"
"0 NUM 2\n"
"0 OUT info_index\n"
"B1\n"
"0 NEL 1\n"
"1 REF info_index\n"
"1 NUM 2\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B2\n"
"1 REF mode\n"
"1 STR when\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"0 RUN when\n"
"0 JEZ 1\n"
"B4\n"
"1 REF __calls\n"
"1 REF i\n"
"0 RUN __get__\n"
"0 OUT todo\n"
"B4\n"
"0 RUN todo\n"
"B3\n"
"0 NUM 0\n"
"0 OUT info_index\n"
"B2\n"
"0 NEL 1\n"
"1 REF mode\n"
"1 STR period_ms\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"1 REF __calls\n"
"1 REF i\n"
"0 RUN __get__\n"
"0 OUT todo\n"
"B3\n"
"0 NUM 3\n"
"0 OUT info_index\n"
"B1\n"
"0 NEL 1\n"
"1 REF info_index\n"
"1 NUM 3\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B2\n"
"1 REF mode\n"
"1 STR period_ms\n"
"0 OPT ==\n"
"0 JEZ 1\n"
"B3\n"
"1 REF __tick\n"
"2 REF __calls\n"
"2 REF i\n"
"1 RUN __get__\n"
"0 OPT >\n"
"0 JEZ 1\n"
"B4\n"
"0 RUN todo\n"
"B4\n"
"1 REF __calls\n"
"1 REF i\n"
"2 REF __tick\n"
"2 REF period_ms\n"
"1 OPT +\n"
"1 STR __calls\n"
"0 RUN __set__\n"
"B3\n"
"0 NUM 0\n"
"0 OUT info_index\n"
"B0\n"
"0 JMP -1\n"
"B0\n"
"0 DEL _l0\n"
"B0\n");
} }
void __Task_update_tick(PikaObj* self) { void __Task_update_tick(PikaObj* self) {

View File

@ -863,21 +863,21 @@ TEST(VM, load_static_bytes) {
0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x00, 0x86, 0xae, 0x00, 0x03, 0x85, 0x1b, 0x00, 0x03, 0x04, 0x1d, 0x00, 0x00, 0x86, 0xae, 0x00,
0x00, 0x8c, 0x33, 0x00, /* instruct array */ 0x00, 0x8c, 0x33, 0x00, /* instruct array */
0xb1, 0x00, /* const pool size */ 0xb1, 0x00, /* const pool size */
0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x2e, 0x6c, 0x65, 0x6e, 0x00, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x2e, 0x6c, 0x65, 0x6e,
0x6c, 0x65, 0x6e, 0x00, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x6d, 0x6f, 0x64, 0x00, 0x6c, 0x65, 0x6e, 0x00, 0x6e, 0x6f, 0x6e, 0x65, 0x00, 0x6d, 0x6f,
0x65, 0x00, 0x30, 0x00, 0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x69, 0x6e, 0x64, 0x64, 0x65, 0x00, 0x30, 0x00, 0x69, 0x6e, 0x66, 0x6f, 0x5f, 0x69, 0x6e,
0x65, 0x78, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74, 0x65, 0x64, 0x65, 0x78, 0x00, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x00, 0x69, 0x74,
0x72, 0x00, 0x5f, 0x6c, 0x30, 0x00, 0x5f, 0x72, 0x31, 0x00, 0x5f, 0x72, 0x65, 0x72, 0x00, 0x5f, 0x6c, 0x30, 0x00, 0x5f, 0x72, 0x31, 0x00, 0x5f,
0x32, 0x00, 0x5f, 0x72, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61, 0x31, 0x72, 0x32, 0x00, 0x5f, 0x72, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61,
0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61, 0x32, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x31, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x61, 0x32, 0x00, 0x5f, 0x6c, 0x30,
0x61, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x2e, 0x61, 0x33, 0x00, 0x5f, 0x6c, 0x30, 0x2e, 0x5f, 0x5f, 0x6e, 0x65,
0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00, 0x3d, 0x3d, 0x00, 0x31, 0x78, 0x74, 0x5f, 0x5f, 0x00, 0x69, 0x00, 0x32, 0x00, 0x3d, 0x3d, 0x00,
0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x00, 0x5f, 0x5f, 0x67, 0x31, 0x00, 0x5f, 0x5f, 0x63, 0x61, 0x6c, 0x6c, 0x73, 0x00, 0x5f, 0x5f,
0x65, 0x74, 0x5f, 0x5f, 0x00, 0x61, 0x6c, 0x77, 0x61, 0x79, 0x73, 0x00, 0x67, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x61, 0x6c, 0x77, 0x61, 0x79, 0x73,
0x74, 0x6f, 0x64, 0x6f, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x00, 0x70, 0x65, 0x00, 0x74, 0x6f, 0x64, 0x6f, 0x00, 0x77, 0x68, 0x65, 0x6e, 0x00, 0x70,
0x72, 0x69, 0x6f, 0x64, 0x5f, 0x6d, 0x73, 0x00, 0x33, 0x00, 0x5f, 0x5f, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x5f, 0x6d, 0x73, 0x00, 0x33, 0x00, 0x5f,
0x74, 0x69, 0x63, 0x6b, 0x00, 0x3e, 0x00, 0x2b, 0x00, 0x5f, 0x5f, 0x73, 0x5f, 0x74, 0x69, 0x63, 0x6b, 0x00, 0x3e, 0x00, 0x2b, 0x00, 0x5f, 0x5f,
0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const pool */ 0x73, 0x65, 0x74, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const pool */
}; };
ByteCodeFrame bytecode_frame = {.const_pool = ByteCodeFrame bytecode_frame = {.const_pool =
{ {
@ -894,6 +894,7 @@ TEST(VM, load_static_bytes) {
}}; }};
byteCodeFrame_loadBytes(&bytecode_frame, (uint8_t*)bytes); byteCodeFrame_loadBytes(&bytecode_frame, (uint8_t*)bytes);
byteCodeFrame_print(&bytecode_frame);
EXPECT_EQ(instructArray_getSize(&(bytecode_frame.instruct_array)), 520); EXPECT_EQ(instructArray_getSize(&(bytecode_frame.instruct_array)), 520);
EXPECT_EQ(bytecode_frame.const_pool.size, 177); EXPECT_EQ(bytecode_frame.const_pool.size, 177);