update parse-test

This commit is contained in:
lyon 2021-12-27 21:27:07 +08:00
parent 5b888744b4
commit 280ca09539
14 changed files with 45 additions and 54 deletions

0
port/linux/api-make-linux.sh Normal file → Executable file
View File

0
port/linux/api-make-win10.sh Normal file → Executable file
View File

0
port/linux/api-make.sh Normal file → Executable file
View File

0
port/linux/gtest.sh Normal file → Executable file
View File

0
port/linux/init.sh Normal file → Executable file
View File

0
port/linux/make.sh Normal file → Executable file
View File

0
port/linux/package/pikascript/rust-msc-latest-linux Normal file → Executable file
View File

0
port/linux/pkg-push.sh Normal file → Executable file
View File

0
port/linux/pull-core.sh Normal file → Executable file
View File

0
port/linux/push-core.sh Normal file → Executable file
View File

0
port/linux/test-banchmark.sh Normal file → Executable file
View File

View File

@ -1373,21 +1373,38 @@ TEST(parser, if_elif_else) {
EXPECT_EQ(pikaMemNow(), 0);
}
// TEST(parser, for_range) {
// Args* bf = New_strBuff();
// Stack* bs = New_Stack();
// char* s = strsCopy(bf, (char*)"");
// s = parse("for i in range(0,10):", bf, s, bs);
// s = parse(" print(i)", bf, s, bs);
// s = parse("", bf, s, bs);
// printf("%s", s);
// EXPECT_STREQ(s,
// ""
// );
// stack_deinit(bs);
// args_deinit(bf);
// EXPECT_EQ(pikaMemNow(), 0);
// }
TEST(parser, for_range) {
Args* bf = New_strBuff();
Stack* bs = New_Stack();
char* s = strsCopy(bf, (char*)"");
s = parse("for i in range(0,10):", bf, s, bs);
s = parse(" print(i)", bf, s, bs);
s = parse("", bf, s, bs);
printf("%s", s);
EXPECT_STREQ(s,
"B0\n"
"2 NUM 0\n"
"2 NUM 10\n"
"1 RUN range\n"
"0 RUN iter\n"
"0 OUT __list0\n"
"B0\n"
"1 REF __list0\n"
"0 RUN next\n"
"0 OUT i\n"
"0 EST i\n"
"0 JEZ 2\n"
"B1\n"
"1 REF i\n"
"0 RUN print\n"
"B0\n"
"0 JMP -1\n"
"B0\n"
);
stack_deinit(bs);
args_deinit(bf);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(parser, for_list) {
Args* bf = New_strBuff();

0
port/linux/update-compiler.sh Normal file → Executable file
View File

View File

@ -759,43 +759,22 @@ AST* AST_parseLine(char* line, Stack* blockStack) {
char* list_in = strsCopy(list_buffs, "");
uint8_t isRange = 0;
token = Lexer_popToken(list_buffs, tokens) + 1;
if (strEqu("range", token)) {
isRange = 1;
/* not push 'range' to list_int */
while (!strEqu(token, ":")) {
if (!strEqu("range", token)) {
list_in = strsAppend(list_buffs, list_in, token);
}
token = Lexer_popToken(list_buffs, tokens) + 1;
}
list_in = strsCut(list_buffs, list_in, '(', ')');
if (NULL != blockStack) {
stack_pushStr(blockStack, "for_range");
}
obj_setStr(ast, "block", "for_range");
obj_setStr(ast, "range_args", list_in);
stmt = "";
args_deinit(list_buffs);
goto block_matched;
while (!strEqu(token, ":")) {
list_in = strsAppend(list_buffs, list_in, token);
token = Lexer_popToken(list_buffs, tokens) + 1;
}
if (!isRange) {
while (!strEqu(token, ":")) {
list_in = strsAppend(list_buffs, list_in, token);
token = Lexer_popToken(list_buffs, tokens) + 1;
}
list_in = strsAppend(list_buffs, "iter(", list_in);
list_in = strsAppend(list_buffs, list_in, ")");
list_in = strsCopy(buffs, list_in);
args_deinit(list_buffs);
list_in = strsAppend(list_buffs, "iter(", list_in);
list_in = strsAppend(list_buffs, list_in, ")");
list_in = strsCopy(buffs, list_in);
args_deinit(list_buffs);
obj_setStr(ast, "block", "for");
obj_setStr(ast, "list_in", list_in);
if (NULL != blockStack) {
stack_pushStr(blockStack, "for");
}
stmt = list_in;
goto block_matched;
obj_setStr(ast, "block", "for");
obj_setStr(ast, "list_in", list_in);
if (NULL != blockStack) {
stack_pushStr(blockStack, "for");
}
stmt = list_in;
goto block_matched;
}
if (0 == strncmp(lineStart, (char*)"if ", 3)) {
stmt = strsCut(buffs, lineStart, ' ', ':');
@ -1091,11 +1070,6 @@ char* AST_toPikaAsm(AST* ast, Args* buffs) {
is_block_matched = 1;
goto exit;
}
if (strEqu(obj_getStr(ast, "block"), "for_range")) {
char* arg_in = obj_getStr(ast, "arg_in");
char* range_args = obj_getStr(ast, "range_args");
goto exit;
}
if (strEqu(obj_getStr(ast, "block"), "while")) {
/* parse stmt ast */
pikaAsm = AST_appandPikaAsm(ast, ast, runBuffs, pikaAsm);