2022-07-14 08:36:02 +00:00
|
|
|
#include "PikaStdData_List.h"
|
2021-12-28 01:21:47 +08:00
|
|
|
#include "BaseObj.h"
|
2021-12-13 22:14:59 +08:00
|
|
|
#include "PikaObj.h"
|
2022-07-14 08:36:02 +00:00
|
|
|
#include "PikaStdData_Tuple.h"
|
2022-06-24 03:30:56 +00:00
|
|
|
#include "dataStrs.h"
|
2021-12-13 21:32:45 +08:00
|
|
|
|
|
|
|
void PikaStdData_List_append(PikaObj* self, Arg* arg) {
|
2022-07-11 23:17:25 +08:00
|
|
|
__vm_List_append(self, arg);
|
2021-12-13 21:32:45 +08:00
|
|
|
}
|
|
|
|
|
2022-07-30 18:26:58 +08:00
|
|
|
void PikaStdData_List_set(PikaObj* self, int i, Arg* arg) {
|
2022-06-11 14:56:51 +00:00
|
|
|
PikaList* list = obj_getPtr(self, "list");
|
|
|
|
if (PIKA_RES_OK != list_setArg(list, i, arg)) {
|
2021-12-13 21:32:45 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
2022-08-16 11:05:19 +08:00
|
|
|
obj_setSysOut(self, "Error: index exceeded lengh of list.");
|
2021-12-13 21:32:45 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-28 01:21:47 +08:00
|
|
|
|
2022-07-29 23:40:16 +08:00
|
|
|
void PikaStdData_List___setitem__(PikaObj* self, Arg* __key, Arg* __val) {
|
2022-07-30 18:26:58 +08:00
|
|
|
PikaStdData_List_set(self, obj_getInt(self, "__key"),
|
|
|
|
obj_getArg(self, "__val"));
|
2022-01-30 17:37:21 +08:00
|
|
|
}
|
2022-03-25 21:18:54 +08:00
|
|
|
|
2022-07-14 08:36:02 +00:00
|
|
|
void PikaStdData_List___init__(PikaObj* self) {
|
|
|
|
__vm_List___init__(self);
|
2022-06-11 14:56:51 +00:00
|
|
|
}
|
2022-06-24 03:30:56 +00:00
|
|
|
|
|
|
|
char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg);
|
|
|
|
char* PikaStdData_List___str__(PikaObj* self) {
|
2022-07-20 10:32:01 +08:00
|
|
|
Arg* str_arg = arg_newStr("[");
|
2022-06-24 03:30:56 +00:00
|
|
|
PikaList* list = obj_getPtr(self, "list");
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
while (PIKA_TRUE) {
|
|
|
|
Arg* item = list_getArg(list, i);
|
|
|
|
if (NULL == item) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i != 0) {
|
|
|
|
str_arg = arg_strAppend(str_arg, ", ");
|
|
|
|
}
|
|
|
|
char* item_str = PikaStdLib_SysObj_str(self, item);
|
2022-08-10 11:49:54 +08:00
|
|
|
if (arg_getType(item) == ARG_TYPE_STRING) {
|
|
|
|
str_arg = arg_strAppend(str_arg, "'");
|
|
|
|
}
|
2022-06-24 03:30:56 +00:00
|
|
|
str_arg = arg_strAppend(str_arg, item_str);
|
2022-08-10 11:49:54 +08:00
|
|
|
if (arg_getType(item) == ARG_TYPE_STRING) {
|
|
|
|
str_arg = arg_strAppend(str_arg, "'");
|
|
|
|
}
|
2022-06-24 03:30:56 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
str_arg = arg_strAppend(str_arg, "]");
|
|
|
|
obj_setStr(self, "_buf", arg_getStr(str_arg));
|
|
|
|
arg_deinit(str_arg);
|
|
|
|
return obj_getStr(self, "_buf");
|
|
|
|
}
|
2022-08-16 12:21:11 +08:00
|
|
|
|
|
|
|
void PikaStdData_List_reverse(PikaObj* self) {
|
|
|
|
PikaList* list = obj_getPtr(self, "list");
|
|
|
|
list_reverse(list);
|
|
|
|
}
|
2022-08-16 17:40:11 +08:00
|
|
|
|
|
|
|
PikaObj* PikaStdData_List___add__(PikaObj* self, PikaObj* others) {
|
|
|
|
PikaObj* res = newNormalObj(New_PikaStdData_List);
|
|
|
|
PikaStdData_List___init__(res);
|
|
|
|
PikaList* list_res = obj_getPtr(res, "list");
|
|
|
|
PikaList* list1 = obj_getPtr(self, "list");
|
|
|
|
PikaList* list2 = obj_getPtr(others, "list");
|
|
|
|
for (size_t i = 0; i < list_getSize(list1); i++) {
|
|
|
|
Arg* arg = list_getArg(list1, i);
|
|
|
|
list_append(list_res, arg);
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < list_getSize(list2); i++) {
|
|
|
|
Arg* arg = list_getArg(list2, i);
|
|
|
|
list_append(list_res, arg);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2022-09-23 11:35:54 +08:00
|
|
|
|
|
|
|
void PikaStdData_List_insert(PikaObj *self, int i, Arg* arg){
|
|
|
|
PikaList* list = obj_getPtr(self, "list");
|
|
|
|
if (PIKA_RES_OK != list_insert(list, i, arg)) {
|
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "Error: index exceeded lengh of list.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Arg* PikaStdData_List_pop(PikaObj *self){
|
|
|
|
PikaList* list = obj_getPtr(self, "list");
|
|
|
|
return list_pop(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdData_List_remove(PikaObj *self, Arg* val){
|
|
|
|
PikaList* list = obj_getPtr(self, "list");
|
|
|
|
list_remove(list, val);
|
|
|
|
}
|
|
|
|
|