From ffe05656381317b6275ed72ceef98efb6bde321f Mon Sep 17 00:00:00 2001 From: pikastech Date: Thu, 20 Oct 2022 13:57:28 +0800 Subject: [PATCH] multiy module import ok, cmodule not ok --- port/linux/.vscode/launch.json | 2 +- port/linux/package/pikascript/main.py | 3 +-- src/PikaParser.c | 37 ++++++++++++++++++++++++--- src/pika_config_valid.h | 2 +- test/parse-test.cpp | 12 +++++++-- 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/port/linux/.vscode/launch.json b/port/linux/.vscode/launch.json index ba22109e3..59baaf7fc 100644 --- a/port/linux/.vscode/launch.json +++ b/port/linux/.vscode/launch.json @@ -11,7 +11,7 @@ "program": "${workspaceFolder}/build/test/pikascript_test", // "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain", "args": [ - "--gtest_filter=parser.multi_from_import_as" + "--gtest_filter=parser.multi_import" ], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/port/linux/package/pikascript/main.py b/port/linux/package/pikascript/main.py index cf1fbe176..f152e64ec 100644 --- a/port/linux/package/pikascript/main.py +++ b/port/linux/package/pikascript/main.py @@ -4,8 +4,7 @@ import PikaStdDevice import ctypes import GTestTask import PikaMath -import test_module1 -import test_cmodule +import test_module1, test_cmodule import TempDevTest import cjson_test import test_module4 diff --git a/src/PikaParser.c b/src/PikaParser.c index 093fa4c48..39fe7cc02 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -2229,10 +2229,39 @@ exit: return line_out; } -static char* Suger_import(Args* buffs_p, char* line) { - line = Suger_import_as(buffs_p, line); - line = Suger_from_import_as(buffs_p, line); - return line; +static char* Suger_import(Args* outbuffs, char* line) { + line = Suger_import_as(outbuffs, line); + line = Suger_from_import_as(outbuffs, line); + Arg* line_buff = arg_newStr(""); + while (1) { + char* single_line = strPopFirstToken(&line, '\n'); + if (single_line[0] == '\0') { + break; + } + if (strIsStartWith(single_line, "import ")) { + if (strIsContain(single_line, ',')) { + single_line = single_line + 7; + while (1) { + char* single_import = strPopFirstToken(&single_line, ','); + if (single_import[0] == '\0') { + break; + } + line_buff = arg_strAppend(line_buff, "import "); + line_buff = arg_strAppend(line_buff, single_import); + line_buff = arg_strAppend(line_buff, "\n"); + } + char* line_after = arg_getStr(line_buff); + line_after[strlen(line_after) - 1] = '\0'; + } + } + line_buff = arg_strAppend(line_buff, single_line); + line_buff = arg_strAppend(line_buff, "\n"); + } + char* line_after = arg_getStr(line_buff); + line_after[strlen(line_after) - 1] = '\0'; + line_after = strsCopy(outbuffs, line_after); + arg_deinit(line_buff); + return line_after; } static char* Parser_linePreProcess(Args* outbuffs, char* line) { diff --git a/src/pika_config_valid.h b/src/pika_config_valid.h index f250b5ae4..9d59faf94 100644 --- a/src/pika_config_valid.h +++ b/src/pika_config_valid.h @@ -321,7 +321,7 @@ #endif #ifndef PIKA_ARG_CACHE_SIZE - #define PIKA_ARG_CACHE_SIZE sizeof(Arg) + 8 + #define PIKA_ARG_CACHE_SIZE sizeof(Arg) + 16 #endif /* configuration validation */ diff --git a/test/parse-test.cpp b/test/parse-test.cpp index 1e0718073..e4ddb6eea 100644 --- a/test/parse-test.cpp +++ b/test/parse-test.cpp @@ -4848,9 +4848,17 @@ TEST(parser, multi_import) { printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, "B0\n" - "0 IMP a,b,c\n" + "0 IMP a\n" "B0\n" - "0 IMP a,b,c\n" + "0 IMP b\n" + "B0\n" + "0 IMP c\n" + "B0\n" + "0 IMP a\n" + "B0\n" + "0 IMP b\n" + "B0\n" + "0 IMP c\n" "B0\n" "1 REF a\n" "1 REF b\n"