fix built-in function print

This commit is contained in:
lyon 2023-03-01 22:15:22 +08:00
parent f152db319c
commit 57a04ca87e
3 changed files with 25 additions and 2 deletions

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.getattr_native"
"--gtest_filter=vm.dir_print_arg"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -318,7 +318,11 @@ Arg* arg_toStrArg(Arg* arg) {
strEqu(method_store->name, "tuple")) {
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE,
"<class '%s'>", method_store->name);
return arg_newStr(buff);
}
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE,
"<built-in function %s>",
method_store->name);
return arg_newStr(buff);
}
if (argType_isConstructor(type)) {
@ -338,7 +342,7 @@ Arg* arg_toStrArg(Arg* arg) {
}
if (type == ARG_TYPE_OBJECT_META) {
pika_platform_snprintf(buff, PIKA_SPRINTF_BUFF_SIZE,
"<mate object at %p>", arg_getPtr(arg));
"<meta object at %p>", arg_getPtr(arg));
return arg_newStr(buff);
}
return NULL;

View File

@ -2711,6 +2711,25 @@ TEST(vm, type_fullfealure){
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(vm, dir_print_arg){
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
extern unsigned char pikaModules_py_a[];
obj_linkLibrary(pikaMain, pikaModules_py_a);
/* run */
__platform_printf("BEGIN\r\n");
obj_run(pikaMain, "print(dir)\r\n");
/* collect */
/* assert */
EXPECT_STREQ(log_buff[0], "<built-in function dir>\r\n");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
#endif
TEST_END