class_arg test no passed

This commit is contained in:
lyon 2022-02-25 18:21:27 +08:00
parent 483920213f
commit 3509d666d8
3 changed files with 48 additions and 12 deletions

View File

@ -2034,7 +2034,7 @@ TEST(parser, class_) {
pikaMemInfo.heapUsedMax = 0; pikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff(); Args* buffs = New_strBuff();
char* lines = (char*) char* lines = (char*)
"class Test( BaseObj ):\n" "class Test(PikaStdLib.PikaObj):\n"
" x = 1\n" " x = 1\n"
"\n" "\n"
; ;
@ -2042,15 +2042,19 @@ TEST(parser, class_) {
char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines); char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines);
printf("%s", pikaAsm); printf("%s", pikaAsm);
EXPECT_STREQ(pikaAsm, (char* ) EXPECT_STREQ(pikaAsm, (char* )
"B0\n" "B0\n"
"0 DEF Test()\n" "0 DEF Test()\n"
"B1\n" "0 JMP 1\n"
"0 RUN BaseObj\n" "B1\n"
"0 SLF\n" "0 RUN PikaStdLib.PikaObj\n"
"B1\n" "0 SLF\n"
"0 NUM 1\n" "B1\n"
"0 OUT x\n" "0 NUM 1\n"
"B0\n"); "0 OUT x\n"
"B1\n"
"0 RET\n"
"B0\n"
);
args_deinit(buffs); args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0); EXPECT_EQ(pikaMemNow(), 0);
} }

View File

@ -1,9 +1,12 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
extern "C" { extern "C" {
#include "PikaMain.h" #include "PikaMain.h"
#include "PikaParser.h"
#include "PikaStdLib_MemChecker.h" #include "PikaStdLib_MemChecker.h"
#include "PikaVM.h"
#include "dataArgs.h" #include "dataArgs.h"
#include "dataMemory.h" #include "dataMemory.h"
#include "dataStrs.h"
#include "pikaScript.h" #include "pikaScript.h"
#include "pika_config_gtest.h" #include "pika_config_gtest.h"
} }
@ -1053,3 +1056,25 @@ TEST(pikaMain, synac_err_1) {
obj_deinit(pikaMain); obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0); EXPECT_EQ(pikaMemNow(), 0);
} }
// TEST(pikaMain, class_arg) {
// /* init */
// pikaMemInfo.heapUsedMax = 0;
// /* run */
// PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
// __platform_printf((char*)"BEGIN\r\n");
// Args* buffs = New_strBuff();
// char * pikaAsm = Parser_multiLineToAsm(buffs, (char*)
// "class Test(PikaStdLib.PikaObj):\n"
// " x = 1\n"
// "\n"
// "test = Test()\n"
// "print(test.x)\n"
// );
// printf("%s", pikaAsm);
// pikaVM_runAsm(pikaMain, pikaAsm);
// /* assert */
// /* deinit */
// obj_deinit(pikaMain);
// EXPECT_EQ(pikaMemNow(), 0);
// }

View File

@ -1324,6 +1324,11 @@ char* AST_toPikaASM(AST* ast, Args* outBuffs) {
pikaAsm = ASM_addBlockDeepth(ast, outBuffs, pikaAsm, 1); pikaAsm = ASM_addBlockDeepth(ast, outBuffs, pikaAsm, 1);
pikaAsm = strsAppend(outBuffs, pikaAsm, (char*)"0 RET\n"); pikaAsm = strsAppend(outBuffs, pikaAsm, (char*)"0 RET\n");
} }
/* return when exit class */
if (strEqu(blockType, "class")) {
pikaAsm = ASM_addBlockDeepth(ast, outBuffs, pikaAsm, 1);
pikaAsm = strsAppend(outBuffs, pikaAsm, (char*)"0 RET\n");
}
} }
} }
/* add block deepth */ /* add block deepth */
@ -1433,8 +1438,10 @@ char* AST_toPikaASM(AST* ast, Args* outBuffs) {
char* thisClass = strsGetFirstToken(buffs, declear, '('); char* thisClass = strsGetFirstToken(buffs, declear, '(');
char* superClass = strsCut(buffs, declear, '(', ')'); char* superClass = strsCut(buffs, declear, '(', ')');
pikaAsm = strsAppend(buffs, pikaAsm, "0 DEF "); pikaAsm = strsAppend(buffs, pikaAsm, "0 DEF ");
pikaAsm = pikaAsm = strsAppend(buffs, pikaAsm,
strsAppend(buffs, pikaAsm, strsAppend(buffs, thisClass, "()\n")); strsAppend(buffs, thisClass,
"()\n"
"0 JMP 1\n"));
char block_deepth_str[] = "B0\n"; char block_deepth_str[] = "B0\n";
/* goto deeper block */ /* goto deeper block */
block_deepth_str[1] += obj_getInt(ast, "blockDeepth") + 1; block_deepth_str[1] += obj_getInt(ast, "blockDeepth") + 1;