From 7f77407550cf4975db1c50ca60d5818af4cfbf16 Mon Sep 17 00:00:00 2001 From: pikastech Date: Thu, 4 Aug 2022 00:25:32 +0800 Subject: [PATCH] support del keyword, use v1.10 version name --- port/linux/make.sh | 1 - port/linux/only_make.sh | 1 + port/linux/run.sh | 2 ++ port/linux/test/VM-test.cpp | 19 +++++++++++++++++-- port/linux/test/parse-test.cpp | 14 ++++++++++++++ port/linux/version_config.py | 4 ++-- src/PikaParser.c | 19 +++++++++++++++++-- src/PikaVM.c | 14 +++++++++++--- src/PikaVersion.h | 6 +++--- 9 files changed, 67 insertions(+), 13 deletions(-) diff --git a/port/linux/make.sh b/port/linux/make.sh index 48320296e..4f86b8605 100644 --- a/port/linux/make.sh +++ b/port/linux/make.sh @@ -1,4 +1,3 @@ sh api-make.sh sh only_make.sh -cp ./build/boot/demo06-pikamain/pikascript_demo06-pikamain package/pikascript/pika cp config/pika_config_default.h config/pika_config.h diff --git a/port/linux/only_make.sh b/port/linux/only_make.sh index 6412947e2..eea5291d0 100644 --- a/port/linux/only_make.sh +++ b/port/linux/only_make.sh @@ -1 +1,2 @@ cd build && rm ./test/pikascript_test -f && ninja +cd .. && cp ./build/boot/demo06-pikamain/pikascript_demo06-pikamain package/pikascript/pika diff --git a/port/linux/run.sh b/port/linux/run.sh index b0214c556..917533cd1 100644 --- a/port/linux/run.sh +++ b/port/linux/run.sh @@ -1,2 +1,4 @@ +cp config/pika_config_void.h config/pika_config.h +sh only_make.sh cd package/pikascript && \ ./pika $1 diff --git a/port/linux/test/VM-test.cpp b/port/linux/test/VM-test.cpp index c5f09c9e6..df74508ab 100644 --- a/port/linux/test/VM-test.cpp +++ b/port/linux/test/VM-test.cpp @@ -1039,8 +1039,7 @@ TEST(VM, tuple_literal) { #endif TEST(VM, dvd_opt) { - char* line = - "a = 10%4\n"; + char* line = "a = 10%4\n"; PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj); obj_run(self, line); /* collect */ @@ -1051,3 +1050,19 @@ TEST(VM, dvd_opt) { obj_deinit(self); EXPECT_EQ(pikaMemNow(), 0); } + +TEST(VM, del_) { + char* line = + "a = 1\n" + "print(a)\n" + "del a\n" + "print(a)\n"; + PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj); + obj_run(self, line); + /* collect */ + /* assert */ + EXPECT_EQ(obj_isArgExist(self, "a"), 0); + /* deinit */ + obj_deinit(self); + EXPECT_EQ(pikaMemNow(), 0); +} diff --git a/port/linux/test/parse-test.cpp b/port/linux/test/parse-test.cpp index 95db9d7e2..0611cd85a 100644 --- a/port/linux/test/parse-test.cpp +++ b/port/linux/test/parse-test.cpp @@ -3554,3 +3554,17 @@ TEST(parser, tuple1) { args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } + +TEST(parser, _del) { + pikaMemInfo.heapUsedMax = 0; + Args* buffs = New_strBuff(); + char* lines = "del a\n"; + __platform_printf("%s\n", lines); + char* pikaAsm = Parser_multiLineToAsm(buffs, lines); + __platform_printf("%s", pikaAsm); + EXPECT_STREQ(pikaAsm, + "B0\n" + "0 DEL a\n"); + args_deinit(buffs); + EXPECT_EQ(pikaMemNow(), 0); +} diff --git a/port/linux/version_config.py b/port/linux/version_config.py index c9a02824e..b5480aa38 100644 --- a/port/linux/version_config.py +++ b/port/linux/version_config.py @@ -1,3 +1,3 @@ -MajorVersion = "2" -MinorVersion = "0" +MajorVersion = "1" +MinorVersion = "10" MicroVersion = "0" diff --git a/src/PikaParser.c b/src/PikaParser.c index 500862c2d..de1cadf19 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -943,8 +943,7 @@ void ParserState_beforeIter(struct ParserState* ps) { return; } Parser_popToken(ps->buffs_p, ps->tokens); - ps->last_token = - arg_newStr(Parser_popToken(ps->buffs_p, ps->tokens)); + ps->last_token = arg_newStr(Parser_popToken(ps->buffs_p, ps->tokens)); } #if PIKA_SYNTAX_SLICE_ENABLE @@ -1830,6 +1829,13 @@ AST* AST_parseLine(char* line, Stack* block_stack) { AST_setThisNode(ast, "global", global_list); goto block_matched; } + if (strIsStartWith(line_start, "del ")) { + stmt = ""; + char* del_dir = line_start + sizeof("del ") - 1; + del_dir = strsGetCleanCmd(&buffs, del_dir); + AST_setThisNode(ast, "del", del_dir); + goto block_matched; + } if (strIsStartWith(line_start, (char*)"def ")) { stmt = ""; char* declear = strsCut(&buffs, line_start, ' ', ':'); @@ -2476,6 +2482,15 @@ char* AST_toPikaASM(AST* ast, Args* outBuffs) { is_block_matched = 1; goto exit; } + if (obj_isArgExist(ast, "del")) { + /* parse stmt ast */ + pikaAsm = AST_appandPikaASM(ast, ast, &buffs, pikaAsm); + pikaAsm = strsAppend(&buffs, pikaAsm, "0 DEL "); + pikaAsm = strsAppend(&buffs, pikaAsm, obj_getStr(ast, "del")); + pikaAsm = strsAppend(&buffs, pikaAsm, "\n"); + is_block_matched = 1; + goto exit; + } if (obj_isArgExist(ast, "break")) { /* parse stmt ast */ pikaAsm = AST_appandPikaASM(ast, ast, &buffs, pikaAsm); diff --git a/src/PikaVM.c b/src/PikaVM.c index 61d1940fd..fa7d029e5 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -1133,8 +1133,7 @@ static Arg* VM_instruction_handler_JEZ(PikaObj* self, thisBlockDeepth = VMState_getBlockDeepthNow(vs); int jmp_expect = fast_atoi(data); arg_newStackBuff(pika_assertArg_stack, PIKA_ARG_BUFF_SIZE); - Arg* pika_assertArg = - stack_popArg(&(vs->stack), &pika_assertArg_stack); + Arg* pika_assertArg = stack_popArg(&(vs->stack), &pika_assertArg_stack); int pika_assert = arg_getInt(pika_assertArg); arg_deinit(pika_assertArg); vs->ireg[thisBlockDeepth] = !pika_assert; @@ -1585,7 +1584,16 @@ static Arg* VM_instruction_handler_DEL(PikaObj* self, VMState_delLReg(vs, reg_index); return NULL; } - obj_removeArg(vs->locals, data); + if (obj_isArgExist(vs->locals, data)) { + obj_removeArg(vs->locals, data); + return NULL; + } + if (obj_isArgExist(vs->globals, data)) { + obj_removeArg(vs->globals, data); + return NULL; + } + VMState_setErrorCode(vs, PIKA_RES_ERR_OPERATION_FAILED); + __platform_printf("NameError: name '%s' is not defined\n", data); return NULL; } diff --git a/src/PikaVersion.h b/src/PikaVersion.h index e7a0c033e..841c04e18 100644 --- a/src/PikaVersion.h +++ b/src/PikaVersion.h @@ -1,5 +1,5 @@ -#define PIKA_VERSION_MAJOR 2 -#define PIKA_VERSION_MINOR 0 +#define PIKA_VERSION_MAJOR 1 +#define PIKA_VERSION_MINOR 10 #define PIKA_VERSION_MICRO 0 -#define PIKA_EDIT_TIME "2022/08/01 10:06:47" +#define PIKA_EDIT_TIME "2022/08/04 00:10:34"