add filter for dir()

This commit is contained in:
lyon 2023-01-22 23:16:38 +08:00
parent bf63ac206a
commit d77e7f3f2d
6 changed files with 37 additions and 7 deletions

View File

@ -85,7 +85,7 @@ class SysObj:
@staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def dir(obj: object) -> list: ...
def dir(obj: any) -> list: ...
@staticmethod
@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")

View File

@ -569,7 +569,13 @@ int32_t __dir_each(Arg* argEach, Args* context) {
return 0;
}
PikaObj* PikaStdLib_SysObj_dir(PikaObj* self, PikaObj* obj) {
PikaObj* PikaStdLib_SysObj_dir(PikaObj* self, Arg* arg) {
if (!argType_isObject(arg_getType(arg))) {
obj_setErrorCode(self, 1);
__platform_printf("[Error] dir: arg is not object.\r\n");
return NULL;
}
PikaObj* obj = arg_getPtr(arg);
PikaObj* New_PikaStdData_List(Args * args);
PikaObj* list = newNormalObj(New_PikaStdData_List);
__vm_List___init__(list);
@ -683,6 +689,6 @@ void PikaStdLib_SysObj_help(PikaObj* self, char* name) {
}
}
void PikaStdLib_SysObj_reboot(PikaObj *self){
void PikaStdLib_SysObj_reboot(PikaObj* self) {
pika_platform_reboot();
}

View File

@ -11,7 +11,7 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
"--gtest_filter=VM._3_3"
"--gtest_filter=vm.dir_issue"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -85,7 +85,7 @@ class SysObj:
@staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def dir(obj: object) -> list: ...
def dir(obj: any) -> list: ...
@staticmethod
@PIKA_C_MACRO_IF("PIKA_EXEC_ENABLE")

View File

@ -569,7 +569,13 @@ int32_t __dir_each(Arg* argEach, Args* context) {
return 0;
}
PikaObj* PikaStdLib_SysObj_dir(PikaObj* self, PikaObj* obj) {
PikaObj* PikaStdLib_SysObj_dir(PikaObj* self, Arg* arg) {
if (!argType_isObject(arg_getType(arg))) {
obj_setErrorCode(self, 1);
__platform_printf("[Error] dir: arg is not object.\r\n");
return NULL;
}
PikaObj* obj = arg_getPtr(arg);
PikaObj* New_PikaStdData_List(Args * args);
PikaObj* list = newNormalObj(New_PikaStdData_List);
__vm_List___init__(list);
@ -683,6 +689,6 @@ void PikaStdLib_SysObj_help(PikaObj* self, char* name) {
}
}
void PikaStdLib_SysObj_reboot(PikaObj *self){
void PikaStdLib_SysObj_reboot(PikaObj* self) {
pika_platform_reboot();
}

View File

@ -2491,6 +2491,24 @@ TEST(vm, num_issue_lakj) {
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, dir_issue) {
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
/* run */
__platform_printf("BEGIN\r\n");
obj_run(pikaMain,
"class test:\n"
" pass\n"
"dir(test)\n"
);
/* collect */
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END