support del keyword, use v1.10 version name

This commit is contained in:
pikastech 2022-08-04 00:25:32 +08:00
parent 41a6d1c9f4
commit 7f77407550
9 changed files with 67 additions and 13 deletions

View File

@ -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

View File

@ -1 +1,2 @@
cd build && rm ./test/pikascript_test -f && ninja
cd .. && cp ./build/boot/demo06-pikamain/pikascript_demo06-pikamain package/pikascript/pika

View File

@ -1,2 +1,4 @@
cp config/pika_config_void.h config/pika_config.h
sh only_make.sh
cd package/pikascript && \
./pika $1

View File

@ -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);
}

View File

@ -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);
}

View File

@ -1,3 +1,3 @@
MajorVersion = "2"
MinorVersion = "0"
MajorVersion = "1"
MinorVersion = "10"
MicroVersion = "0"

View File

@ -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);

View File

@ -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;
}

View File

@ -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"