mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
fix __cleanbuff err in _do_obj_runChar
This commit is contained in:
parent
8436c6623b
commit
a344117bc3
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -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}",
|
||||
|
@ -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);
|
||||
|
@ -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);;
|
||||
|
@ -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);;
|
||||
|
@ -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);;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -10,9 +10,9 @@ TEST(pikaMain, init) {
|
||||
TEST(pikaMain, new_mem) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
VMParameters* globals = obj_runDirect(pikaMain,
|
||||
"mem = PikaStdLib.MemChecker()\n"
|
||||
"mem.max()\n");
|
||||
VMParameters* globals = obj_run(pikaMain,
|
||||
"mem = PikaStdLib.MemChecker()\n"
|
||||
"mem.max()\n");
|
||||
PikaObj* mem = (PikaObj*)args_getPtr(globals->list, "mem");
|
||||
PikaObj* memClassPtr = (PikaObj*)mem->constructor;
|
||||
EXPECT_EQ((void*)memClassPtr, (void*)New_PikaStdLib_MemChecker);
|
||||
@ -41,13 +41,13 @@ TEST(pikaMain, list_new) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
VMParameters* globals = obj_runDirect(pikaMain,
|
||||
"list = PikaStdData.List()\n"
|
||||
"list.append(7)\n"
|
||||
"list.append('eee')\n"
|
||||
"len = list.len()\n"
|
||||
"a1 = list.get(0)\n"
|
||||
"a2 = list.get(1)\n");
|
||||
VMParameters* globals = obj_run(pikaMain,
|
||||
"list = PikaStdData.List()\n"
|
||||
"list.append(7)\n"
|
||||
"list.append('eee')\n"
|
||||
"len = list.len()\n"
|
||||
"a1 = list.get(0)\n"
|
||||
"a2 = list.get(1)\n");
|
||||
/* collect */
|
||||
int len = obj_getInt(globals, "len");
|
||||
int a1 = obj_getInt(globals, "a1");
|
||||
@ -69,11 +69,11 @@ TEST(pikaMain, int_float_convert) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
VMParameters* globals = obj_runDirect(pikaMain,
|
||||
"a = 1\n"
|
||||
"a_f = float(a)\n"
|
||||
"b = 1.3\n"
|
||||
"b_i = int(b)\n");
|
||||
VMParameters* globals = obj_run(pikaMain,
|
||||
"a = 1\n"
|
||||
"a_f = float(a)\n"
|
||||
"b = 1.3\n"
|
||||
"b_i = int(b)\n");
|
||||
/* collect */
|
||||
int a = obj_getInt(globals, "a");
|
||||
float a_f = obj_getFloat(globals, "a_f");
|
||||
@ -97,10 +97,10 @@ TEST(pikaMain, type_) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"type(1)\n"
|
||||
"b = 1.4\n"
|
||||
"type(b)\n");
|
||||
obj_run(pikaMain,
|
||||
"type(1)\n"
|
||||
"b = 1.4\n"
|
||||
"type(b)\n");
|
||||
/* collect */
|
||||
|
||||
/* assert */
|
||||
@ -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,11 +184,11 @@ TEST(pikaMain, less_equ) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"a = 0\n"
|
||||
"while a <= 10:\n"
|
||||
" a += 1\n"
|
||||
"\n");
|
||||
obj_run(pikaMain,
|
||||
"a = 0\n"
|
||||
"while a <= 10:\n"
|
||||
" a += 1\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
int a = obj_getInt(pikaMain, "a");
|
||||
|
||||
@ -205,24 +205,24 @@ TEST(pikaMain, and_or_not) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"a = 0\n"
|
||||
"b = 0\n"
|
||||
"c = 0\n"
|
||||
"d = 0\n"
|
||||
"if (1>2) or (2>1):\n"
|
||||
" a = 1\n"
|
||||
"\n"
|
||||
"if (1>2) and (2>1):\n"
|
||||
" b = 1\n"
|
||||
"\n"
|
||||
"if not (1>2):\n"
|
||||
" c = 1\n"
|
||||
"\n"
|
||||
"if not (2>1):\n"
|
||||
" d = 1\n"
|
||||
"\n"
|
||||
"e = ~1\n");
|
||||
obj_run(pikaMain,
|
||||
"a = 0\n"
|
||||
"b = 0\n"
|
||||
"c = 0\n"
|
||||
"d = 0\n"
|
||||
"if (1>2) or (2>1):\n"
|
||||
" a = 1\n"
|
||||
"\n"
|
||||
"if (1>2) and (2>1):\n"
|
||||
" b = 1\n"
|
||||
"\n"
|
||||
"if not (1>2):\n"
|
||||
" c = 1\n"
|
||||
"\n"
|
||||
"if not (2>1):\n"
|
||||
" d = 1\n"
|
||||
"\n"
|
||||
"e = ~1\n");
|
||||
/* collect */
|
||||
int a = obj_getInt(pikaMain, "a");
|
||||
int b = obj_getInt(pikaMain, "b");
|
||||
@ -285,14 +285,14 @@ TEST(pikaMain, list_method) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"list = PikaStdData.List()\n"
|
||||
"list.append(7)\n"
|
||||
"list.append('eee')\n"
|
||||
"len = list.len()\n"
|
||||
"a1 = list.get(0)\n"
|
||||
"a2 = list.get(1)\n"
|
||||
"\n");
|
||||
obj_run(pikaMain,
|
||||
"list = PikaStdData.List()\n"
|
||||
"list.append(7)\n"
|
||||
"list.append('eee')\n"
|
||||
"len = list.len()\n"
|
||||
"a1 = list.get(0)\n"
|
||||
"a2 = list.get(1)\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
/* deinit */
|
||||
@ -306,10 +306,10 @@ TEST(pikaMain, list_iter) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"list = PikaStdData.List()\n"
|
||||
"res = iter(list)\n"
|
||||
"\n");
|
||||
obj_run(pikaMain,
|
||||
"list = PikaStdData.List()\n"
|
||||
"res = iter(list)\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
PikaObj* res = (PikaObj*)obj_getPtr(pikaMain, "res");
|
||||
PikaObj* list = (PikaObj*)obj_getPtr(pikaMain, "list");
|
||||
@ -328,15 +328,15 @@ TEST(pikaMain, list_for_loop) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"list = PikaStdData.List()\n"
|
||||
"list.append(7)\n"
|
||||
"list.append('eee')\n"
|
||||
"len = list.len()\n"
|
||||
"for item in list:\n"
|
||||
" print(item)\n"
|
||||
" a = item\n"
|
||||
"\n");
|
||||
obj_run(pikaMain,
|
||||
"list = PikaStdData.List()\n"
|
||||
"list.append(7)\n"
|
||||
"list.append('eee')\n"
|
||||
"len = list.len()\n"
|
||||
"for item in list:\n"
|
||||
" print(item)\n"
|
||||
" a = item\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
char* a = obj_getStr(pikaMain, "a");
|
||||
/* assert */
|
||||
@ -352,10 +352,10 @@ TEST(pikaMain, range) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"r = range(10, 0)\n"
|
||||
"r\n"
|
||||
"\n");
|
||||
obj_run(pikaMain,
|
||||
"r = range(10, 0)\n"
|
||||
"r\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
obj_deinit(pikaMain);
|
||||
@ -368,12 +368,12 @@ TEST(pikaMain, for_in_range) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"a = 0\n"
|
||||
"for i in range(0, 10):\n"
|
||||
" print(i)\n"
|
||||
" a = a + i\n"
|
||||
"\n");
|
||||
obj_run(pikaMain,
|
||||
"a = 0\n"
|
||||
"for i in range(0, 10):\n"
|
||||
" print(i)\n"
|
||||
" a = a + i\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
int a = obj_getInt(pikaMain, "a");
|
||||
/* assert */
|
||||
@ -389,13 +389,13 @@ TEST(pikaMain, for_for_in_range) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"a = 0\n"
|
||||
"for i in range(0, 10):\n"
|
||||
" for k in range(0, 3):\n"
|
||||
" print(k)\n"
|
||||
" a = a + k\n"
|
||||
"\n");
|
||||
obj_run(pikaMain,
|
||||
"a = 0\n"
|
||||
"for i in range(0, 10):\n"
|
||||
" for k in range(0, 3):\n"
|
||||
" print(k)\n"
|
||||
" a = a + k\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
int a = obj_getInt(pikaMain, "a");
|
||||
/* assert */
|
||||
@ -411,13 +411,13 @@ TEST(pikaMain, for_if_break) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
obj_runDirect(pikaMain,
|
||||
"a = 0\n"
|
||||
"for i in range(0, 10):\n"
|
||||
" if i == 5:\n"
|
||||
" break\n"
|
||||
" a = a + i\n"
|
||||
"\n");
|
||||
obj_run(pikaMain,
|
||||
"a = 0\n"
|
||||
"for i in range(0, 10):\n"
|
||||
" if i == 5:\n"
|
||||
" break\n"
|
||||
" a = a + i\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
int a = obj_getInt(pikaMain, "a");
|
||||
/* assert */
|
||||
@ -460,10 +460,10 @@ 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,
|
||||
"def test_print():\n"
|
||||
" print('test')\n"
|
||||
"test_print()\n");
|
||||
obj_run(pikaMain,
|
||||
"def test_print():\n"
|
||||
" print('test')\n"
|
||||
"test_print()\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
/* should only print once, so the second log (log_buff[1]) shuold be '\0' */
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user