try to fix chain err

This commit is contained in:
lyon 2023-02-09 17:16:40 +08:00
parent ec51e2cc11
commit 612a8aa33d
5 changed files with 57 additions and 69 deletions

View File

@ -11,7 +11,7 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
// "--gtest_filter=vm.run_file"
// "--gtest_filter=vm.ui_page"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -7,6 +7,7 @@ import configparser, network
import test_module1, test_cmodule, test_module4, import_test
import hashlib, hmac, aes, base64, time
import _thread
import PikaUI as ui
mem = PikaStdLib.MemChecker()
print('hello pikascript!')

View File

@ -1306,7 +1306,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
}
if (vars_or_keys_or_default) {
f.n_arg = f.n_input;
f.n_arg = f.n_input - n_used;
} else {
f.n_arg = f.n_positional;
}
@ -3517,21 +3517,19 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState(
pika_assert(NULL != run_state);
int size = bytecode_frame->instruct_array.size;
/* locals is the local scope */
VMState vm = {
.bytecode_frame = bytecode_frame,
.locals = locals,
.globals = globals,
.jmp = 0,
.pc = pc,
.loop_deepth = 0,
.error_code = PIKA_RES_OK,
.line_error_code = PIKA_RES_OK,
.try_error_code = PIKA_RES_OK,
.run_state = run_state,
.ins_cnt = 0,
.in_super = PIKA_FALSE,
.super_invoke_deepth = 0,
};
VMState vm = {.bytecode_frame = bytecode_frame,
.locals = locals,
.globals = globals,
.jmp = 0,
.pc = pc,
.loop_deepth = 0,
.error_code = PIKA_RES_OK,
.line_error_code = PIKA_RES_OK,
.try_error_code = PIKA_RES_OK,
.run_state = run_state,
.ins_cnt = 0,
.in_super = PIKA_FALSE,
.super_invoke_deepth = 0};
stack_init(&(vm.stack));
VMState_initReg(&vm);
if (PikaVMSignal.vm_cnt == 0) {

View File

@ -2623,14 +2623,36 @@ TEST(vm, tuple_void) {
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, run_file){
TEST(vm, run_file) {
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
pikaVM_runFile(pikaMain, "package/pikascript/main.py");
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
// TEST(vm, ui_page) {
// /* init */
// pikaMemInfo.heapUsedMax = 0;
// PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
// extern unsigned char pikaModules_py_a[];
// obj_linkLibrary(pikaMain, pikaModules_py_a);
// /* run */
// __platform_printf("BEGIN\r\n");
// obj_run(pikaMain,
// "import PikaUI as ui\n"
// "ui.Page().add(\n"
// " ui.Widget(\n"
// " ).add(\n"
// " ui.Text()\n"
// " ),\n"
// ")\n");
// /* collect */
// /* assert */
// /* deinit */
// obj_deinit(pikaMain);
// EXPECT_EQ(pikaMemNow(), 0);
// }
#endif
TEST_END

View File

@ -5208,64 +5208,31 @@ TEST(parser, page_add) {
char* lines =
"PikaUI.Page().add(\n"
" ui.Widget(\n"
" pos=(0, 50),\n"
" width=300,\n"
" height=180,\n"
" ).add(\n"
" ui.Button(\n"
" width=120,\n"
" height=30,\n"
" align=ui.ALIGN.CENTER,\n"
" pos=(0, 40),\n"
" text='Hello PikaUI !'\n"
" ),\n"
" ui.Text(\n"
" text=\"Welcome to PikaUI !\",\n"
" width=200,\n"
" pos=(25, 20)\n"
" )\n"
" ui.Text()\n"
" ),\n"
").update()\n";
")\n"
"page.add(\n"
" ui.Widget(\n"
" ).add(\n"
" ui.Text()\n"
" ),\n"
")\n";
printf("%s\r\n", lines);
char* pikaAsm = Parser_linesToAsm(buffs, lines);
printf("%s", pikaAsm);
EXPECT_STREQ(pikaAsm,
"B0\n"
"2 RUN PikaUI.Page\n"
"5 NUM 0\n"
"5 NUM 50\n"
"4 RUN \n"
"4 OUT pos\n"
"4 NUM 300\n"
"4 OUT width\n"
"4 NUM 180\n"
"4 OUT height\n"
"3 RUN ui.Widget\n"
"4 NUM 120\n"
"4 OUT width\n"
"4 NUM 30\n"
"4 OUT height\n"
"4 REF ui.ALIGN.CENTER\n"
"4 OUT align\n"
"5 NUM 0\n"
"5 NUM 40\n"
"4 RUN \n"
"4 OUT pos\n"
"4 STR Hello PikaUI !\n"
"4 OUT text\n"
"3 RUN ui.Button\n"
"4 STR Welcome to PikaUI !\n"
"4 OUT text\n"
"4 NUM 200\n"
"4 OUT width\n"
"5 NUM 25\n"
"5 NUM 20\n"
"4 RUN \n"
"4 OUT pos\n"
"3 RUN ui.Text\n"
"2 RUN .add\n"
"1 RUN PikaUI.Page\n"
"2 RUN ui.Widget\n"
"2 RUN ui.Text\n"
"1 RUN .add\n"
"0 RUN .update\n"
"0 RUN .add\n"
"B0\n"
"2 RUN ui.Widget\n"
"2 RUN ui.Text\n"
"1 RUN .add\n"
"0 RUN page.add\n"
"B0\n");
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);