dict/list to obj test not passed

This commit is contained in:
Lyon 2023-08-02 09:39:36 +08:00
parent 684d28ef20
commit 6c2903242f
10 changed files with 52 additions and 79 deletions

View File

@ -16,14 +16,14 @@ void PikaStdData_Dict___init__(PikaObj* self) {
}
void PikaStdData_Dict_set(PikaObj* self, char* key, Arg* arg) {
objDict_set(self, key, arg);
objDict_set(self, key, arg_copy(arg));
}
void PikaStdData_Dict_remove(PikaObj* self, char* key) {
PikaDict* dict = obj_getPtr(self, "dict");
PikaDict* keys = obj_getPtr(self, "_keys");
pikaDict_removeArg(dict, pikaDict_getArg(dict, key));
pikaDict_removeArg(keys, pikaDict_getArg(keys, key));
Args* dict = obj_getPtr(self, "dict");
Args* keys = obj_getPtr(self, "_keys");
args_removeArg(dict, args_getArg(dict, key));
args_removeArg(keys, args_getArg(keys, key));
}
Arg* PikaStdData_Dict___iter__(PikaObj* self) {
@ -43,8 +43,7 @@ Arg* PikaStdData_Dict___next__(PikaObj* self) {
}
void PikaStdData_Dict___setitem__(PikaObj* self, Arg* __key, Arg* __val) {
PikaStdData_Dict_set(self, obj_getStr(self, "__key"),
obj_getArg(self, "__val"));
PikaStdData_Dict_set(self, arg_getStr(__key), (__val));
}
Arg* PikaStdData_Dict___getitem__(PikaObj* self, Arg* __key) {
@ -53,7 +52,10 @@ Arg* PikaStdData_Dict___getitem__(PikaObj* self, Arg* __key) {
void PikaStdData_Dict___del__(PikaObj* self) {
Args* keys = obj_getPtr(self, "_keys");
pikaDict_deinit(self);
Args* dict = obj_getPtr(self, "dict");
if (NULL != dict) {
args_deinit(dict);
}
if (NULL != keys) {
args_deinit(keys);
}
@ -196,8 +198,7 @@ int dict_contains(PikaDict* dict, Arg* key) {
}
int PikaStdData_Dict___contains__(PikaObj* self, Arg* val) {
PikaDict* dict = obj_getPtr(self, "_keys");
return dict_contains(dict, val);
return dict_contains(self, val);
}
Arg* PikaStdData_dict_items___iter__(PikaObj* self) {

View File

@ -217,14 +217,8 @@ void PikaStdData_FILEIO_writelines(PikaObj* self, PikaObj* lines) {
__platform_printf("Error: can't write lines to file\n");
return;
}
PikaList* list = obj_getPtr(lines, "list");
if (list == NULL) {
obj_setErrorCode(self, PIKA_RES_ERR_IO);
__platform_printf("Error: can't write lines to file\n");
return;
}
for (size_t i = 0; i < pikaList_getSize(list); i++) {
char* line = pikaList_getStr(list, i);
for (size_t i = 0; i < pikaList_getSize(lines); i++) {
char* line = pikaList_getStr(lines, i);
Arg* arg_str = arg_newStr(line);
PikaStdData_FILEIO_write(self, arg_str);
arg_deinit(arg_str);

View File

@ -11,25 +11,7 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
// "--gtest_filter=builtin.write_fn"
// "--gtest_filter=builtin.base_type"
// "--gtest_filter=parser.multi_comprehension"
// "--gtest_filter=parser.comprehension_indent"
// "--gtest_filter=parser.*"
// "--gtest_filter=pikaMain.slice2"
// "--gtest_filter=re.match"
// "--gtest_filter=parser.for_indent"
// "--gtest_filter=VM.comprehension"
// "--gtest_filter=zlib.zlib1"
// "--gtest_filter=builtin.big_list"
// "--gtest_filter=VM.list_base"
// "--gtest_filter=vm.issue_dict_update"
// "--gtest_filter=builtin.tuple"
// "--gtest_filter=pikaMain.num_issue1"
// "--gtest_filter=parser.byte_issue"
// "--gtest_filter=VM.vars_runtime"
// "--gtest_filter=VM.list_add"
"--gtest_filter=PikaCV.test2"
"--gtest_filter=vm.issue_big_dict_update"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -16,14 +16,14 @@ void PikaStdData_Dict___init__(PikaObj* self) {
}
void PikaStdData_Dict_set(PikaObj* self, char* key, Arg* arg) {
objDict_set(self, key, arg);
objDict_set(self, key, arg_copy(arg));
}
void PikaStdData_Dict_remove(PikaObj* self, char* key) {
PikaDict* dict = obj_getPtr(self, "dict");
PikaDict* keys = obj_getPtr(self, "_keys");
pikaDict_removeArg(dict, pikaDict_getArg(dict, key));
pikaDict_removeArg(keys, pikaDict_getArg(keys, key));
Args* dict = obj_getPtr(self, "dict");
Args* keys = obj_getPtr(self, "_keys");
args_removeArg(dict, args_getArg(dict, key));
args_removeArg(keys, args_getArg(keys, key));
}
Arg* PikaStdData_Dict___iter__(PikaObj* self) {
@ -43,8 +43,7 @@ Arg* PikaStdData_Dict___next__(PikaObj* self) {
}
void PikaStdData_Dict___setitem__(PikaObj* self, Arg* __key, Arg* __val) {
PikaStdData_Dict_set(self, obj_getStr(self, "__key"),
obj_getArg(self, "__val"));
PikaStdData_Dict_set(self, arg_getStr(__key), (__val));
}
Arg* PikaStdData_Dict___getitem__(PikaObj* self, Arg* __key) {
@ -53,7 +52,10 @@ Arg* PikaStdData_Dict___getitem__(PikaObj* self, Arg* __key) {
void PikaStdData_Dict___del__(PikaObj* self) {
Args* keys = obj_getPtr(self, "_keys");
pikaDict_deinit(self);
Args* dict = obj_getPtr(self, "dict");
if (NULL != dict) {
args_deinit(dict);
}
if (NULL != keys) {
args_deinit(keys);
}
@ -196,8 +198,7 @@ int dict_contains(PikaDict* dict, Arg* key) {
}
int PikaStdData_Dict___contains__(PikaObj* self, Arg* val) {
PikaDict* dict = obj_getPtr(self, "_keys");
return dict_contains(dict, val);
return dict_contains(self, val);
}
Arg* PikaStdData_dict_items___iter__(PikaObj* self) {

View File

@ -217,14 +217,8 @@ void PikaStdData_FILEIO_writelines(PikaObj* self, PikaObj* lines) {
__platform_printf("Error: can't write lines to file\n");
return;
}
PikaList* list = obj_getPtr(lines, "list");
if (list == NULL) {
obj_setErrorCode(self, PIKA_RES_ERR_IO);
__platform_printf("Error: can't write lines to file\n");
return;
}
for (size_t i = 0; i < pikaList_getSize(list); i++) {
char* line = pikaList_getStr(list, i);
for (size_t i = 0; i < pikaList_getSize(lines); i++) {
char* line = pikaList_getStr(lines, i);
Arg* arg_str = arg_newStr(line);
PikaStdData_FILEIO_write(self, arg_str);
arg_deinit(arg_str);

View File

@ -3303,8 +3303,7 @@ Arg* builtins_list(PikaObj* self, PikaTuple* val) {
Arg* builtins_dict(PikaObj* self, PikaTuple* val) {
#if PIKA_BUILTIN_STRUCT_ENABLE
PikaObj* New_PikaStdData_Dict(Args * args);
return arg_newDirectObj(New_PikaStdData_Dict);
return arg_newObj(New_pikaDict());
#else
obj_setErrorCode(self, 1);
__platform_printf("[Error] built-in dist is not enabled.\r\n");
@ -3845,8 +3844,8 @@ Arg* _max_min(PikaObj* self, PikaTuple* val, uint8_t* bc) {
obj_setArg(self, "@list", pikaTuple_getArg(val, 0));
return pikaVM_runByteCodeReturn(self, (uint8_t*)bc, "@res_max");
}
PikaObj* oTuple = newNormalObj(New_PikaStdData_Tuple);
obj_setPtr(oTuple, "list", val);
PikaTuple* oTuple = newNormalObj(New_PikaStdData_Tuple);
obj_setPtr(oTuple, "list", obj_getPtr(val, "list"));
obj_setInt(oTuple, "needfree", 0);
Arg* aTuple = arg_newObj(oTuple);
obj_setArg(self, "@list", aTuple);
@ -3987,9 +3986,7 @@ Arg* objDict_get(PikaObj* self, char* key) {
}
void objDict_set(PikaObj* self, char* key, Arg* arg) {
Arg* arg_new = arg_copy(arg);
arg_setName(arg_new, key);
pikaDict_setArg(self, arg_new);
pikaDict_setArg(self, key, arg);
}
int32_t objDict_forEach(PikaObj* self,
@ -4006,7 +4003,7 @@ int32_t objDict_forEach(PikaObj* self,
while (1) {
Arg* item_key = args_getArgByIndex(keys, i);
Arg* item_val = args_getArgByIndex(dict, i);
if (NULL == item_key) {
if (NULL == item_val) {
break;
}
// Call the handle function on each key-value pair
@ -4067,8 +4064,7 @@ PikaList* New_pikaList(void) {
}
PikaDict* New_pikaDict(void) {
Args* dict = New_args(NULL);
PikaDict* self = newNormalObj(New_PikaStdData_Dict);
obj_setPtr(self, "dict", dict);
objDict_init(self);
return self;
}

View File

@ -790,33 +790,39 @@ PIKA_RES _transeBool(Arg* arg, pika_bool* res);
static inline PIKA_RES pikaDict_setInt(PikaDict* self,
char* name,
int64_t val) {
return args_setInt(_OBJ2LIST(self), (name), (val));
return args_setInt(_OBJ2DICT(self), (name), (val));
}
static inline PIKA_RES pikaDict_setFloat(PikaDict* self,
char* name,
pika_float val) {
return args_setFloat(_OBJ2LIST(self), (name), (val));
return args_setFloat(_OBJ2DICT(self), (name), (val));
}
static inline PIKA_RES pikaDict_setStr(PikaDict* self, char* name, char* val) {
return args_setStr(_OBJ2LIST(self), (name), (val));
return args_setStr(_OBJ2DICT(self), (name), (val));
}
static inline PIKA_RES pikaDict_setPtr(PikaDict* self, char* name, void* val) {
return args_setPtr(_OBJ2LIST(self), (name), (val));
return args_setPtr(_OBJ2DICT(self), (name), (val));
}
static inline PIKA_RES pikaDict_setArg(PikaDict* self, Arg* val) {
return args_setArg(_OBJ2LIST(self), (val));
static inline PIKA_RES _pikaDict_setVal(PikaDict* self, Arg* val) {
return args_setArg(_OBJ2DICT(self), (val));
}
static inline PIKA_RES pikaDict_setArg(PikaDict* self, char* name, Arg* val) {
arg_setName(val, name);
_pikaDict_setVal(self, val);
return args_setStr(_OBJ2KEYS(self), (name), (name));
}
static inline PIKA_RES pikaDict_removeArg(PikaDict* self, Arg* val) {
return args_removeArg(_OBJ2LIST(self), (val));
return args_removeArg(_OBJ2DICT(self), (val));
}
static inline PIKA_RES pikaDict_setBytes(PikaDict* self,
char* name,
uint8_t* val,
size_t size) {
return args_setBytes(_OBJ2LIST(self), (name), (val), (size));
return args_setBytes(_OBJ2DICT(self), (name), (val), (size));
}
static inline int64_t pikaDict_getInt(PikaDict* self, char* name) {
@ -864,7 +870,7 @@ static inline size_t pikaDict_getBytesSize(PikaDict* self, char* name) {
}
static inline void pikaDict_deinit(PikaDict* self) {
args_deinit(_OBJ2DICT(self));
obj_deinit(self);
}
/* list api */

View File

@ -1286,7 +1286,7 @@ static void _kw_push(FunctionArgsInfo* f, Arg* call_arg, int i) {
f->kw = New_pikaDict();
}
arg_setIsKeyword(call_arg, pika_false);
pikaDict_setArg(f->kw, call_arg);
_pikaDict_setVal(f->kw, call_arg);
}
static void _load_call_arg(VMState* vm,
@ -1707,8 +1707,7 @@ static Arg* VM_instruction_handler_DCT(PikaObj* self,
Arg* arg_ret_reg) {
#if PIKA_BUILTIN_STRUCT_ENABLE
uint32_t n_arg = VMState_getInputArgNum(vm);
PikaObj* dict = newNormalObj(New_PikaStdData_Dict);
objDict_init(dict);
PikaObj* dict = New_pikaDict();
Stack stack = {0};
stack_init(&stack);
/* load to local stack to change sort */
@ -1721,7 +1720,6 @@ static Arg* VM_instruction_handler_DCT(PikaObj* self,
Arg* val_arg = stack_popArg_alloc(&stack);
objDict_set(dict, arg_getStr(key_arg), val_arg);
arg_deinit(key_arg);
arg_deinit(val_arg);
}
stack_deinit(&stack);
return arg_newObj(dict);

View File

@ -2,4 +2,4 @@
#define PIKA_VERSION_MINOR 12
#define PIKA_VERSION_MICRO 4
#define PIKA_EDIT_TIME "2023/08/02 00:34:35"
#define PIKA_EDIT_TIME "2023/08/02 09:39:25"

View File

@ -85,6 +85,7 @@ PIKA_RES args_setRef(Args* self, char* name, void* argPointer) {
}
PIKA_RES args_setStr(Args* self, char* name, char* strIn) {
pika_assert(NULL != self);
PIKA_RES errCode = PIKA_RES_OK;
Arg* argNew = New_arg(NULL);
argNew = arg_setStr(argNew, name, strIn);