2022-07-14 08:36:02 +00:00
|
|
|
#include "PikaStdData_Tuple.h"
|
|
|
|
#include "PikaVM.h"
|
|
|
|
#include "dataStrs.h"
|
|
|
|
|
|
|
|
int PikaStdData_Tuple_len(PikaObj* self) {
|
|
|
|
PikaList* list = obj_getPtr(self, "list");
|
|
|
|
return list_getSize(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
Arg* PikaStdData_Tuple_get(PikaObj* self, int i) {
|
|
|
|
PikaList* list = obj_getPtr(self, "list");
|
|
|
|
return arg_copy(list_getArg(list, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdData_Tuple___init__(PikaObj* self) {
|
|
|
|
__vm_List___init__(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
Arg* PikaStdData_Tuple___iter__(PikaObj* self) {
|
|
|
|
obj_setInt(self, "__iter_i", 0);
|
2022-07-20 10:32:01 +08:00
|
|
|
return arg_newRef(self);
|
2022-07-14 08:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Arg* PikaStdData_Tuple___next__(PikaObj* self) {
|
|
|
|
int __iter_i = args_getInt(self->list, "__iter_i");
|
|
|
|
Arg* res = PikaStdData_Tuple_get(self, __iter_i);
|
|
|
|
if (NULL == res) {
|
2022-07-20 10:32:01 +08:00
|
|
|
return arg_newNull();
|
2022-07-14 08:36:02 +00:00
|
|
|
}
|
|
|
|
args_setInt(self->list, "__iter_i", __iter_i + 1);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-07-29 23:40:16 +08:00
|
|
|
Arg* PikaStdData_Tuple___getitem__(PikaObj* self, Arg* __key) {
|
2022-07-14 08:36:02 +00:00
|
|
|
return PikaStdData_Tuple_get(self, obj_getInt(self, "__key"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PikaStdData_Tuple___del__(PikaObj* self) {
|
|
|
|
Args* list = obj_getPtr(self, "list");
|
|
|
|
args_deinit(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg);
|
|
|
|
char* PikaStdData_Tuple___str__(PikaObj* self) {
|
2022-07-20 10:32:01 +08:00
|
|
|
Arg* str_arg = arg_newStr("(");
|
2022-07-14 08:36:02 +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-07-14 08:36:02 +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-07-14 08:36:02 +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");
|
|
|
|
}
|
|
|
|
|
|
|
|
int PikaStdData_Tuple___len__(PikaObj* self) {
|
|
|
|
return PikaStdData_Tuple_len(self);
|
|
|
|
}
|