mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
pass class demo 1, run.sh not pass
This commit is contained in:
parent
a966d43ad0
commit
ee91552bbb
@ -1126,3 +1126,29 @@ TEST(pikaMain, class_def_print) {
|
|||||||
obj_deinit(self);
|
obj_deinit(self);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(pikaMain, class_demo_1) {
|
||||||
|
/* init */
|
||||||
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
|
/* run */
|
||||||
|
PikaObj* self = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||||
|
__platform_printf((char*)"BEGIN\r\n");
|
||||||
|
obj_run(self, (char*)
|
||||||
|
"class MyClass:\n"
|
||||||
|
" i = 12345\n"
|
||||||
|
" def f(self):\n"
|
||||||
|
" return 'hello world'\n"
|
||||||
|
" \n"
|
||||||
|
"x = MyClass()\n"
|
||||||
|
" \n"
|
||||||
|
"print(x.i)\n"
|
||||||
|
"print(x.f())\n"
|
||||||
|
);
|
||||||
|
/* assert */
|
||||||
|
EXPECT_STREQ(log_buff[0], (char*)"hello world\r\n");
|
||||||
|
EXPECT_STREQ(log_buff[1], (char*)"12345\r\n");
|
||||||
|
EXPECT_STREQ(log_buff[2], (char*)"BEGIN\r\n");
|
||||||
|
/* deinit */
|
||||||
|
obj_deinit(self);
|
||||||
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
|
}
|
||||||
|
@ -1441,8 +1441,15 @@ char* AST_toPikaASM(AST* ast, Args* outBuffs) {
|
|||||||
if (strEqu(obj_getStr(ast, "block"), "class")) {
|
if (strEqu(obj_getStr(ast, "block"), "class")) {
|
||||||
Args* buffs = New_strBuff();
|
Args* buffs = New_strBuff();
|
||||||
char* declear = obj_getStr(ast, "declear");
|
char* declear = obj_getStr(ast, "declear");
|
||||||
char* thisClass = strsGetFirstToken(buffs, declear, '(');
|
char* thisClass = NULL;
|
||||||
char* superClass = strsCut(buffs, declear, '(', ')');
|
char* superClass = NULL;
|
||||||
|
if (strIsContain(declear, '(')) {
|
||||||
|
thisClass = strsGetFirstToken(buffs, declear, '(');
|
||||||
|
superClass = strsCut(buffs, declear, '(', ')');
|
||||||
|
} else {
|
||||||
|
thisClass = declear;
|
||||||
|
superClass = "";
|
||||||
|
}
|
||||||
if (strEqu("", superClass)) {
|
if (strEqu("", superClass)) {
|
||||||
/* default superClass */
|
/* default superClass */
|
||||||
superClass = "PikaStdLib.PikaObj";
|
superClass = "PikaStdLib.PikaObj";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user