fix __cleanbuff err in _do_obj_runChar

This commit is contained in:
lyon 2022-10-22 11:25:13 +08:00
parent 8436c6623b
commit a344117bc3
13 changed files with 154 additions and 129 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=pikaMain.runchar_multiline"
// "--gtest_filter=parser.multi_import"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -60,7 +60,7 @@ int32_t main()
fgets(inputBuff, sizeof(inputBuff), stdin);
/* run PikaScript and get res */
PikaObj *globals = obj_runDirect(root, inputBuff);
PikaObj *globals = obj_run(root, inputBuff);
/* get system output of PikaScript*/
char *sysOut = args_getSysOut(globals->list);

View File

@ -57,7 +57,7 @@ int32_t main()
fgets(inputBuff, sizeof(inputBuff), stdin);
/* run PikaScript and get res */
PikaObj *globals = obj_runDirect(root, inputBuff);
PikaObj *globals = obj_run(root, inputBuff);
/* get system output of PikaScript*/
char *sysOut = args_getSysOut(globals->list);;

View File

@ -55,7 +55,7 @@ int32_t main()
fgets(inputBuff, sizeof(inputBuff), stdin);
/* run PikaScript and get res */
PikaObj *globals = obj_runDirect(root, inputBuff);
PikaObj *globals = obj_run(root, inputBuff);
/* get system output of PikaScript*/
char *sysOut = args_getSysOut(globals->list);;

View File

@ -110,7 +110,7 @@ int32_t main()
fgets(inputBuff, sizeof(inputBuff), stdin);
/* run PikaScript and get res */
PikaObj *globals = obj_runDirect(root, inputBuff);
PikaObj *globals = obj_run(root, inputBuff);
/* get system output of PikaScript*/
char *sysOut = args_getSysOut(globals->list);;

View File

@ -42,7 +42,7 @@ int main()
fgets(inputBuff, sizeof(inputBuff), stdin);
/* run PikaScript and get res */
PikaObj *globals = obj_runDirect(root, inputBuff);
PikaObj *globals = obj_run(root, inputBuff);
/* get system output of PikaScript*/
char *sysOut = args_getSysOut(globals->list);

View File

@ -507,22 +507,28 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
}
}
__platform_free(buff);
__platform_fclose(imp_file_pyo);
__platform_fclose(imp_file_pyo_api);
} else if (NULL != imp_file_py) {
/* found *.py, push to nocompiled list */
pikaMaker_setState(self, imp_module_name, "nocompiled");
__platform_fclose(imp_file_py);
} else if (NULL != imp_file_pyi) {
/* found *.py, push to nocompiled list */
pikaMaker_setState(self, imp_module_name, "cmodule");
__platform_fclose(imp_file_pyi);
} else {
__platform_printf(
" [warning]: file: '%s.pyi', '%s.py' or '%s.py.o' "
"no found\n",
imp_module_name, imp_module_name, imp_module_name);
}
if (NULL != imp_file_pyo) {
__platform_fclose(imp_file_pyo);
}
if (NULL != imp_file_pyi) {
__platform_fclose(imp_file_pyi);
}
if (NULL != imp_file_py) {
__platform_fclose(imp_file_py);
}
}
}
instructArray_getNext(ins_array);

View File

@ -790,10 +790,6 @@ int32_t class_defineStaticMethod(PikaObj* self,
def_context, bytecode_frame);
}
VMParameters* obj_runDirect(PikaObj* self, char* cmd) {
return pikaVM_run(self, cmd);
}
int32_t obj_removeArg(PikaObj* self, char* argPath) {
PikaObj* objHost = obj_getHostObj(self, argPath);
char* argName;
@ -841,13 +837,8 @@ exit:
return res;
}
void obj_runNoRes(PikaObj* slef, char* cmd) {
/* unsafe, nothing would happend when error occord */
obj_runDirect(slef, cmd);
}
void obj_run(PikaObj* self, char* cmd) {
obj_runDirect(self, cmd);
VMParameters* obj_run(PikaObj* self, char* cmd) {
return pikaVM_run(self, cmd);
}
PIKA_RES obj_runNativeMethod(PikaObj* self, char* method_name, Args* args) {
@ -921,6 +912,7 @@ enum shell_state _do_obj_runChar(PikaObj* self,
cfg->inBlock = PIKA_FALSE;
input_line = obj_getStr(self, cfg->blockBuffName);
state = cfg->handler(self, input_line, cfg);
__clearBuff(rxBuff, PIKA_LINE_BUFF_SIZE);
__platform_printf(">>> ");
goto exit;
} else {

View File

@ -236,9 +236,7 @@ char* methodArg_getName(Arg* method_arg, char* buffs, size_t size);
ByteCodeFrame* methodArg_getBytecodeFrame(Arg* method_arg);
Method methodArg_getPtr(Arg* method_arg);
void obj_runNoRes(PikaObj* slef, char* cmd);
void obj_run(PikaObj* self, char* cmd);
VMParameters* obj_runDirect(PikaObj* self, char* cmd);
VMParameters* obj_run(PikaObj* self, char* cmd);
PikaObj* New_PikaObj(void);
/* tools */

View File

@ -2478,13 +2478,13 @@ static VMParameters* __pikaVM_runPyLines_or_byteCode(PikaObj* self,
/*
* the first obj_run, cache bytecode to heap, to support 'def' and 'class'
*/
if (!args_isArgExist(self->list, "__first_bytecode")) {
if (!args_isArgExist(self->list, "@bc0")) {
is_use_heap_bytecode = 1;
/* load bytecode to heap */
args_setHeapStruct(self->list, "__first_bytecode", bytecode_frame_stack,
args_setHeapStruct(self->list, "@bc0", bytecode_frame_stack,
byteCodeFrame_deinit);
/* get bytecode_ptr from heap */
bytecode_frame_p = args_getHeapStruct(self->list, "__first_bytecode");
bytecode_frame_p = args_getHeapStruct(self->list, "@bc0");
} else {
/* not the first obj_run */
/* save 'def' and 'class' to heap */

View File

@ -114,7 +114,7 @@ TEST(object_test, test3) {
TEST(object_test, test6) {
PikaObj* obj = newRootObj("test", New_PikaObj_test);
VMParameters* globals = obj_runDirect(obj, "res = add(1, 2)");
VMParameters* globals = obj_run(obj, "res = add(1, 2)");
int32_t res = obj_getInt(globals, "res");
EXPECT_EQ(3, res);
obj_deinit(obj);
@ -141,15 +141,15 @@ TEST(object_test, test9) {
TEST(object_test, noMethod) {
PikaObj* root = newRootObj("root", New_MYROOT1);
obj_runNoRes(root, "noDefindMethod()");
obj_run(root, "noDefindMethod()");
obj_deinit(root);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(object_test, a_b) {
PikaObj* root = newRootObj("root", New_MYROOT1);
obj_runNoRes(root, "b=1");
obj_runNoRes(root, "a=b");
obj_run(root, "b=1");
obj_run(root, "a=b");
obj_deinit(root);
EXPECT_EQ(pikaMemNow(), 0);
}
@ -165,7 +165,7 @@ TEST(object_test, voidRun) {
extern char log_buff[LOG_BUFF_MAX][LOG_SIZE];
TEST(object_test, printa) {
PikaObj* root = newRootObj("root", New_PikaStdLib_SysObj);
obj_runDirect(root,
obj_run(root,
"a = 2\n"
"print(a)\n");
@ -199,7 +199,7 @@ TEST(object_test, obj_run_while) {
" b = 1\n"
" a = 0\n"
"\n";
VMParameters* globals = obj_runDirect(root, lines);
VMParameters* globals = obj_run(root, lines);
EXPECT_EQ(obj_getInt(globals, "a"), 0);
EXPECT_EQ(obj_getInt(globals, "b"), 1);
obj_deinit(root);

View File

@ -10,7 +10,7 @@ TEST(pikaMain, init) {
TEST(pikaMain, new_mem) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
VMParameters* globals = obj_runDirect(pikaMain,
VMParameters* globals = obj_run(pikaMain,
"mem = PikaStdLib.MemChecker()\n"
"mem.max()\n");
PikaObj* mem = (PikaObj*)args_getPtr(globals->list, "mem");
@ -41,7 +41,7 @@ TEST(pikaMain, list_new) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
VMParameters* globals = obj_runDirect(pikaMain,
VMParameters* globals = obj_run(pikaMain,
"list = PikaStdData.List()\n"
"list.append(7)\n"
"list.append('eee')\n"
@ -69,7 +69,7 @@ TEST(pikaMain, int_float_convert) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
VMParameters* globals = obj_runDirect(pikaMain,
VMParameters* globals = obj_run(pikaMain,
"a = 1\n"
"a_f = float(a)\n"
"b = 1.3\n"
@ -97,7 +97,7 @@ TEST(pikaMain, type_) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"type(1)\n"
"b = 1.4\n"
"type(b)\n");
@ -116,7 +116,7 @@ TEST(pikaMain, a_signed) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain, "a = -1\n");
obj_run(pikaMain, "a = -1\n");
/* collect */
int a = obj_getInt(pikaMain, "a");
@ -133,7 +133,7 @@ TEST(pikaMain, a_mm) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain, "a = -1.1 ** 3\n");
obj_run(pikaMain, "a = -1.1 ** 3\n");
/* collect */
float a = obj_getFloat(pikaMain, "a");
@ -150,7 +150,7 @@ TEST(pikaMain, a_n1) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain, "a = -2\n");
obj_run(pikaMain, "a = -2\n");
/* collect */
int a = obj_getInt(pikaMain, "a");
@ -167,7 +167,7 @@ TEST(pikaMain, a_l4) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain, "a = 1<<4\n");
obj_run(pikaMain, "a = 1<<4\n");
/* collect */
int a = obj_getInt(pikaMain, "a");
@ -184,7 +184,7 @@ TEST(pikaMain, less_equ) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"a = 0\n"
"while a <= 10:\n"
" a += 1\n"
@ -205,7 +205,7 @@ TEST(pikaMain, and_or_not) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"a = 0\n"
"b = 0\n"
"c = 0\n"
@ -285,7 +285,7 @@ TEST(pikaMain, list_method) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"list = PikaStdData.List()\n"
"list.append(7)\n"
"list.append('eee')\n"
@ -306,7 +306,7 @@ TEST(pikaMain, list_iter) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"list = PikaStdData.List()\n"
"res = iter(list)\n"
"\n");
@ -328,7 +328,7 @@ TEST(pikaMain, list_for_loop) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"list = PikaStdData.List()\n"
"list.append(7)\n"
"list.append('eee')\n"
@ -352,7 +352,7 @@ TEST(pikaMain, range) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"r = range(10, 0)\n"
"r\n"
"\n");
@ -368,7 +368,7 @@ TEST(pikaMain, for_in_range) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"a = 0\n"
"for i in range(0, 10):\n"
" print(i)\n"
@ -389,7 +389,7 @@ TEST(pikaMain, for_for_in_range) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"a = 0\n"
"for i in range(0, 10):\n"
" for k in range(0, 3):\n"
@ -411,7 +411,7 @@ TEST(pikaMain, for_if_break) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
obj_runDirect(pikaMain,
obj_run(pikaMain,
"a = 0\n"
"for i in range(0, 10):\n"
" if i == 5:\n"
@ -460,7 +460,7 @@ TEST(pikaMain, print_in_def) {
/* the test is used to fix too many print in def */
/* clear the log_buff */
memset(log_buff, 0, LOG_BUFF_MAX * LOG_SIZE);
obj_runDirect(pikaMain,
obj_run(pikaMain,
"def test_print():\n"
" print('test')\n"
"test_print()\n");
@ -2688,3 +2688,32 @@ TEST(pikaMain, runchar_multiline) {
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(pikaMain, callback_run_char) {
char* lines =
"def test2():\r\n"
" print('hello')\r\n"
"\r\n"
"def test():\r\n"
" print('hello')\r\n"
" print('in test')\r\n"
"\r\n"
"def test3():\r\n"
" print('hello3')\r\n"
"\r\n"
"test()\r\n";
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
for (size_t i = 0; i < strGetSize(lines); i++) {
obj_runChar(pikaMain, lines[i]);
}
/* collect */
/* assert */
EXPECT_STREQ(log_buff[1], "in test\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -2,7 +2,7 @@
TEST(sysObj, print) {
PikaObj* obj = newRootObj("test", New_PikaStdLib_SysObj);
VMParameters* globals = obj_runDirect(obj, "print('hello world')");
VMParameters* globals = obj_run(obj, "print('hello world')");
// char* sysOut = args_getSysOut(globals->list);
int errCode = args_getErrorCode(globals->list);
// printf("sysout = %s\r\n", sysOut);
@ -17,7 +17,7 @@ TEST(sysObj, print) {
TEST(sysObj, noMethod) {
PikaObj* obj = newRootObj("test", New_PikaStdLib_SysObj);
__platform_printf("BEGIN\r\n");
obj_runDirect(obj, "printttt('hello world')");
obj_run(obj, "printttt('hello world')");
// char* sysOut = args_getSysOut(globals->list);
// int errCode = args_getErrorCode(globals->list);
// printf("sysout = %s\r\n", sysOut);