From db928b1ec1e3ccfd05916058d176579218b062a9 Mon Sep 17 00:00:00 2001 From: lyon1998 <645275593@qq.com> Date: Thu, 14 Oct 2021 10:05:55 +0800 Subject: [PATCH] free ram after parse --- port/linux/test/parse-test.cpp | 7 ------- src/PikaParser.c | 9 +++++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/port/linux/test/parse-test.cpp b/port/linux/test/parse-test.cpp index 9d5d16f76..d8a206eb1 100644 --- a/port/linux/test/parse-test.cpp +++ b/port/linux/test/parse-test.cpp @@ -11,7 +11,6 @@ TEST(parser, NEW) { Args* buffs = New_strBuff(); char* pikaAsm = AST_toPikaAsm(ast, buffs); printf("%s", pikaAsm); - AST_deinit(ast); args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } @@ -22,7 +21,6 @@ TEST(parser, add_a_b) { char* pikaAsm = AST_toPikaAsm(ast, buffs); printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, "1 REF a\n1 REF b\n0 RUN add\n"); - AST_deinit(ast); args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } @@ -33,7 +31,6 @@ TEST(parser, add_a_b_c) { char* pikaAsm = AST_toPikaAsm(ast, buffs); printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, "2 REF a\n2 REF b\n1 RUN add\n1 REF c\n0 RUN add\n0 OUT d\n"); - AST_deinit(ast); args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } @@ -45,7 +42,6 @@ TEST(parser, method1) { printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, "2 REF a\n2 REF se.b\n1 RUN b.add\n1 REF pmw.c\n0 RUN a.add\n0 OUT d.p\n"); - AST_deinit(ast); args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } @@ -58,7 +54,6 @@ TEST(parser, method2) { printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, "2 REF a\n2 REF se.b\n3 REF pp\n2 RUN diek\n1 RUN b.add\n1 RUN pmw.c\n0 RUN a.add\n0 OUT d.p\n"); - AST_deinit(ast); args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } @@ -71,7 +66,6 @@ TEST(parser, str1) { printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, "1 STR 2.322\n0 RUN literal\n"); - AST_deinit(ast); args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } @@ -84,7 +78,6 @@ TEST(parser, str2) { printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, "1 REF a\n2 STR 1\n1 RUN literal\n0 RUN add\n0 OUT b\n"); - AST_deinit(ast); args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } \ No newline at end of file diff --git a/src/PikaParser.c b/src/PikaParser.c index c230bba43..59c6fee72 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -164,9 +164,14 @@ char* AST_appandPikaAsm(AST* ast, AST* subAst, Args* buffs, char* pikaAsm) { } char* AST_toPikaAsm(AST* ast, Args* buffs) { - char* pikaAsm = strsCopy(buffs, ""); + Args* runBuffs = New_strBuff(); + char* pikaAsm = strsCopy(runBuffs, ""); obj_setInt(ast, "deepth", 0); - return AST_appandPikaAsm(ast, ast, buffs, pikaAsm); + pikaAsm = AST_appandPikaAsm(ast, ast, runBuffs, pikaAsm); + pikaAsm = strsCopy(buffs, pikaAsm); + AST_deinit(ast); + args_deinit(runBuffs); + return pikaAsm; } int32_t AST_deinit(AST* ast) {