mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
use sys_malloc and fix a mem bug
This commit is contained in:
parent
db8094d9a5
commit
ac4247e5fd
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -25,7 +25,7 @@
|
||||
// "--gtest_filter=parser.add_a_b*",
|
||||
// "--gtest_filter=parser.method_void",
|
||||
// "--gtest_filter=parser.add_a_b",
|
||||
// "--gtest_filter=pikaMain.complex_str",
|
||||
"--gtest_filter=pikaMain.class_def",
|
||||
// "--gtest_filter=parser.mpy_demo_1",
|
||||
// "--gtest_filter=parser.__set__",
|
||||
// "--gtest_filter=parser.__get__",
|
||||
|
@ -1082,50 +1082,50 @@ TEST(pikaMain, class_arg) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
// TEST(pikaMain, class_def) {
|
||||
// /* init */
|
||||
// pikaMemInfo.heapUsedMax = 0;
|
||||
// /* run */
|
||||
// PikaObj* self = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
// __platform_printf((char*)"BEGIN\r\n");
|
||||
// obj_run(self, (char*)
|
||||
// "class Test():\n"
|
||||
// " x = 1\n"
|
||||
// " def hello(self, x):\n"
|
||||
// " return x + 2\n"
|
||||
// "test = Test()\n"
|
||||
// "x = test.hello(test.x)\n"
|
||||
// "print(x)\n"
|
||||
// );
|
||||
// /* assert */
|
||||
// EXPECT_STREQ(log_buff[0], (char*)"3\r\n");
|
||||
// EXPECT_STREQ(log_buff[1], (char*)"BEGIN\r\n");
|
||||
// /* deinit */
|
||||
// obj_deinit(self);
|
||||
// EXPECT_EQ(pikaMemNow(), 0);
|
||||
// }
|
||||
TEST(pikaMain, class_def) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
/* run */
|
||||
PikaObj* self = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
__platform_printf((char*)"BEGIN\r\n");
|
||||
obj_run(self, (char*)
|
||||
"class Test():\n"
|
||||
" x = 1\n"
|
||||
" def hello(self, x):\n"
|
||||
" return x + 2\n"
|
||||
"test = Test()\n"
|
||||
"x = test.hello(test.x)\n"
|
||||
"print(x)\n"
|
||||
);
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[0], (char*)"3\r\n");
|
||||
EXPECT_STREQ(log_buff[1], (char*)"BEGIN\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
// TEST(pikaMain, class_def_print) {
|
||||
// /* init */
|
||||
// pikaMemInfo.heapUsedMax = 0;
|
||||
// /* run */
|
||||
// PikaObj* self = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
// __platform_printf((char*)"BEGIN\r\n");
|
||||
// obj_run(self, (char*)
|
||||
// "class Test():\n"
|
||||
// " x = 1\n"
|
||||
// " def hi(self):\n"
|
||||
// " print('hi' + str(self.x))\n"
|
||||
// "test = Test()\n"
|
||||
// "test.hi()\n"
|
||||
// );
|
||||
// /* assert */
|
||||
// EXPECT_STREQ(log_buff[0], (char*)"hi1\r\n");
|
||||
// EXPECT_STREQ(log_buff[1], (char*)"BEGIN\r\n");
|
||||
// /* deinit */
|
||||
// obj_deinit(self);
|
||||
// EXPECT_EQ(pikaMemNow(), 0);
|
||||
// }
|
||||
TEST(pikaMain, class_def_print) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
/* run */
|
||||
PikaObj* self = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
__platform_printf((char*)"BEGIN\r\n");
|
||||
obj_run(self, (char*)
|
||||
"class Test():\n"
|
||||
" x = 1\n"
|
||||
" def hi(self):\n"
|
||||
" print('hi' + str(self.x))\n"
|
||||
"test = Test()\n"
|
||||
"test.hi()\n"
|
||||
);
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[0], (char*)"hi1\r\n");
|
||||
EXPECT_STREQ(log_buff[1], (char*)"BEGIN\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, class_demo_1) {
|
||||
/* init */
|
||||
@ -1153,29 +1153,29 @@ TEST(pikaMain, class_demo_1) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
// TEST(pikaMain, class_demo_2) {
|
||||
// /* init */
|
||||
// pikaMemInfo.heapUsedMax = 0;
|
||||
// /* run */
|
||||
// PikaObj* self = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
// __platform_printf((char*)"BEGIN\r\n");
|
||||
// obj_run(self, (char*)
|
||||
// "class Complex:\n"
|
||||
// " def __init__(self):\n"
|
||||
// " self.r = 3.0\n"
|
||||
// " self.i = -4.5\n"
|
||||
// "x = Complex()\n"
|
||||
// "print(x.r)\n"
|
||||
// "print(x.i)\n"
|
||||
// );
|
||||
// /* assert */
|
||||
// EXPECT_STREQ(log_buff[0], (char*)"-4.500000\r\n");
|
||||
// EXPECT_STREQ(log_buff[1], (char*)"3.000000\r\n");
|
||||
// EXPECT_STREQ(log_buff[2], (char*)"BEGIN\r\n");
|
||||
// /* deinit */
|
||||
// obj_deinit(self);
|
||||
// EXPECT_EQ(pikaMemNow(), 0);
|
||||
// }
|
||||
TEST(pikaMain, class_demo_2) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
/* run */
|
||||
PikaObj* self = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
__platform_printf((char*)"BEGIN\r\n");
|
||||
obj_run(self, (char*)
|
||||
"class Complex:\n"
|
||||
" def __init__(self):\n"
|
||||
" self.r = 3.0\n"
|
||||
" self.i = -4.5\n"
|
||||
"x = Complex()\n"
|
||||
"print(x.r)\n"
|
||||
"print(x.i)\n"
|
||||
);
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[0], (char*)"-4.500000\r\n");
|
||||
EXPECT_STREQ(log_buff[1], (char*)"3.000000\r\n");
|
||||
EXPECT_STREQ(log_buff[2], (char*)"BEGIN\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, class_demo_3) {
|
||||
/* init */
|
||||
|
@ -207,7 +207,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, VMState* vs, char* data) {
|
||||
PikaObj* method_host_obj;
|
||||
Arg* method_arg;
|
||||
Method method_ptr;
|
||||
ArgType method_type;
|
||||
ArgType method_type = ARG_TYPE_NONE;
|
||||
char* method_dec;
|
||||
char* type_list;
|
||||
char* method_code;
|
||||
@ -245,8 +245,8 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, VMState* vs, char* data) {
|
||||
method_ptr = (Method)methodArg_getPtr(method_arg);
|
||||
/* get method Decleartion */
|
||||
method_dec = strsCopy(&buffs, methodArg_getDec(method_arg));
|
||||
arg_deinit(method_arg);
|
||||
method_type = arg_getType(method_arg);
|
||||
arg_deinit(method_arg);
|
||||
|
||||
/* get type list */
|
||||
type_list = strsCut(&buffs, method_dec, '(', ')');
|
||||
|
Loading…
x
Reference in New Issue
Block a user