mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
class_arg test no passed
This commit is contained in:
parent
483920213f
commit
3509d666d8
@ -2034,7 +2034,7 @@ TEST(parser, class_) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
Args* buffs = New_strBuff();
|
||||
char* lines = (char*)
|
||||
"class Test( BaseObj ):\n"
|
||||
"class Test(PikaStdLib.PikaObj):\n"
|
||||
" x = 1\n"
|
||||
"\n"
|
||||
;
|
||||
@ -2042,15 +2042,19 @@ TEST(parser, class_) {
|
||||
char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines);
|
||||
printf("%s", pikaAsm);
|
||||
EXPECT_STREQ(pikaAsm, (char* )
|
||||
"B0\n"
|
||||
"0 DEF Test()\n"
|
||||
"B1\n"
|
||||
"0 RUN BaseObj\n"
|
||||
"0 SLF\n"
|
||||
"B1\n"
|
||||
"0 NUM 1\n"
|
||||
"0 OUT x\n"
|
||||
"B0\n");
|
||||
"B0\n"
|
||||
"0 DEF Test()\n"
|
||||
"0 JMP 1\n"
|
||||
"B1\n"
|
||||
"0 RUN PikaStdLib.PikaObj\n"
|
||||
"0 SLF\n"
|
||||
"B1\n"
|
||||
"0 NUM 1\n"
|
||||
"0 OUT x\n"
|
||||
"B1\n"
|
||||
"0 RET\n"
|
||||
"B0\n"
|
||||
);
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include "gtest/gtest.h"
|
||||
extern "C" {
|
||||
#include "PikaMain.h"
|
||||
#include "PikaParser.h"
|
||||
#include "PikaStdLib_MemChecker.h"
|
||||
#include "PikaVM.h"
|
||||
#include "dataArgs.h"
|
||||
#include "dataMemory.h"
|
||||
#include "dataStrs.h"
|
||||
#include "pikaScript.h"
|
||||
#include "pika_config_gtest.h"
|
||||
}
|
||||
@ -1053,3 +1056,25 @@ TEST(pikaMain, synac_err_1) {
|
||||
obj_deinit(pikaMain);
|
||||
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);
|
||||
// }
|
||||
|
@ -1324,6 +1324,11 @@ char* AST_toPikaASM(AST* ast, Args* outBuffs) {
|
||||
pikaAsm = ASM_addBlockDeepth(ast, outBuffs, pikaAsm, 1);
|
||||
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 */
|
||||
@ -1433,8 +1438,10 @@ char* AST_toPikaASM(AST* ast, Args* outBuffs) {
|
||||
char* thisClass = strsGetFirstToken(buffs, declear, '(');
|
||||
char* superClass = strsCut(buffs, declear, '(', ')');
|
||||
pikaAsm = strsAppend(buffs, pikaAsm, "0 DEF ");
|
||||
pikaAsm =
|
||||
strsAppend(buffs, pikaAsm, strsAppend(buffs, thisClass, "()\n"));
|
||||
pikaAsm = strsAppend(buffs, pikaAsm,
|
||||
strsAppend(buffs, thisClass,
|
||||
"()\n"
|
||||
"0 JMP 1\n"));
|
||||
char block_deepth_str[] = "B0\n";
|
||||
/* goto deeper block */
|
||||
block_deepth_str[1] += obj_getInt(ast, "blockDeepth") + 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user