use pikaList, pikaDict, pikaTuple API

This commit is contained in:
lyon 2022-11-19 19:11:34 +08:00
parent bbba403980
commit b481c1c72b
21 changed files with 281 additions and 281 deletions

View File

@ -9,7 +9,7 @@
Arg* PikaStdData_Dict_get(PikaObj* self, char* key) {
PikaDict* dict = obj_getPtr(self, "dict");
Arg* res = dict_getArg(dict, key);
Arg* res = pikaDict_getArg(dict, key);
if (NULL == res) {
obj_setErrorCode(self, PIKA_RES_ERR_RUNTIME_ERROR);
__platform_printf("KeyError: %s\n", key);
@ -28,8 +28,8 @@ void PikaStdData_Dict_set(PikaObj* self, char* key, Arg* arg) {
void PikaStdData_Dict_remove(PikaObj* self, char* key) {
PikaDict* dict = obj_getPtr(self, "dict");
PikaDict* keys = obj_getPtr(self, "_keys");
dict_removeArg(dict, dict_getArg(dict, key));
dict_removeArg(keys, dict_getArg(keys, key));
pikaDict_removeArg(dict, pikaDict_getArg(dict, key));
pikaDict_removeArg(keys, pikaDict_getArg(keys, key));
}
Arg* PikaStdData_Dict___iter__(PikaObj* self) {
@ -60,9 +60,9 @@ Arg* PikaStdData_Dict___getitem__(PikaObj* self, Arg* __key) {
void PikaStdData_Dict___del__(PikaObj* self) {
PikaDict* dict = obj_getPtr(self, "dict");
PikaDict* keys = obj_getPtr(self, "_keys");
dict_deinit(dict);
pikaDict_deinit(dict);
if (NULL != keys) {
dict_deinit(keys);
pikaDict_deinit(keys);
}
}
@ -227,8 +227,8 @@ Arg* PikaStdData_dict_items___next__(PikaObj* self) {
PikaObj* tuple = newNormalObj(New_PikaStdData_Tuple);
PikaStdData_Tuple___init__(tuple);
PikaList* list = obj_getPtr(tuple, "list");
list_append(list, key);
list_append(list, val);
pikaList_append(list, key);
pikaList_append(list, val);
args_setInt(self->list, "__iter_i", __iter_i + 1);
return arg_newObj(tuple);
}

View File

@ -83,8 +83,8 @@ int PikaStdData_FILEIO_seek(PikaObj* self, int offset, PikaTuple* fromwhere) {
__platform_printf("Error: can't seek in file\n");
return -1;
}
if (tuple_getSize(fromwhere) == 1) {
int whence = tuple_getInt(fromwhere, 0);
if (pikaTuple_getSize(fromwhere) == 1) {
int whence = pikaTuple_getInt(fromwhere, 0);
__platform_fseek(f, offset, whence);
return __platform_ftell(f);
}
@ -167,8 +167,8 @@ void PikaStdData_FILEIO_writelines(PikaObj* self, PikaObj* lines) {
__platform_printf("Error: can't write lines to file\n");
return;
}
for (size_t i = 0; i < list_getSize(list); i++) {
char* line = list_getStr(list, i);
for (size_t i = 0; i < pikaList_getSize(list); i++) {
char* line = pikaList_getStr(list, i);
Arg* arg_str = arg_newStr(line);
PikaStdData_FILEIO_write(self, arg_str);
arg_deinit(arg_str);

View File

@ -10,7 +10,7 @@ void PikaStdData_List_append(PikaObj* self, Arg* arg) {
void PikaStdData_List_set(PikaObj* self, int i, Arg* arg) {
PikaList* list = obj_getPtr(self, "list");
if (PIKA_RES_OK != list_setArg(list, i, arg)) {
if (PIKA_RES_OK != pikaList_setArg(list, i, arg)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "Error: index exceeded lengh of list.");
}
@ -32,7 +32,7 @@ char* PikaStdData_List___str__(PikaObj* self) {
int i = 0;
while (PIKA_TRUE) {
Arg* item = list_getArg(list, i);
Arg* item = pikaList_getArg(list, i);
if (NULL == item) {
break;
}
@ -58,7 +58,7 @@ char* PikaStdData_List___str__(PikaObj* self) {
void PikaStdData_List_reverse(PikaObj* self) {
PikaList* list = obj_getPtr(self, "list");
list_reverse(list);
pikaList_reverse(list);
}
PikaObj* PikaStdData_List___add__(PikaObj* self, PikaObj* others) {
@ -67,20 +67,20 @@ PikaObj* PikaStdData_List___add__(PikaObj* self, PikaObj* others) {
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 < pikaList_getSize(list1); i++) {
Arg* arg = pikaList_getArg(list1, i);
pikaList_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);
for (size_t i = 0; i < pikaList_getSize(list2); i++) {
Arg* arg = pikaList_getArg(list2, i);
pikaList_append(list_res, arg);
}
return res;
}
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)) {
if (PIKA_RES_OK != pikaList_insert(list, i, arg)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "Error: index exceeded lengh of list.");
}
@ -88,11 +88,11 @@ void PikaStdData_List_insert(PikaObj *self, int i, Arg* arg){
Arg* PikaStdData_List_pop(PikaObj *self){
PikaList* list = obj_getPtr(self, "list");
return list_pop(list);
return pikaList_pop(list);
}
void PikaStdData_List_remove(PikaObj *self, Arg* val){
PikaList* list = obj_getPtr(self, "list");
list_remove(list, val);
pikaList_remove(list, val);
}

View File

@ -286,12 +286,12 @@ int PikaStdData_String___len__(PikaObj* self) {
char* PikaStdData_String_strip(PikaObj* self, PikaTuple* chrs) {
Args buffs = {0};
char to_strip = ' ';
if (tuple_getSize(chrs) > 1) {
if (pikaTuple_getSize(chrs) > 1) {
obj_setErrorCode(self, PIKA_RES_ERR_INVALID_PARAM);
obj_setSysOut(self, "Error. Invalid param");
}
if (tuple_getSize(chrs) == 1) {
char* ch_str = tuple_getStr(chrs, 0);
if (pikaTuple_getSize(chrs) == 1) {
char* ch_str = pikaTuple_getStr(chrs, 0);
to_strip = ch_str[0];
}
char* str = strsCopy(&buffs, obj_getStr(self, "str"));
@ -332,11 +332,11 @@ Arg* PikaStdData_String_encode(PikaObj* self, PikaTuple* encoding) {
#if PIKA_STRING_UTF8_ENABLE
char* to_code = NULL;
int argn = tuple_getSize(encoding);
int argn = pikaTuple_getSize(encoding);
if (argn < 1) {
return arg_newBytes((uint8_t*)str, strGetSize(str));
}
Arg* arg_i = tuple_getArg(encoding, 0);
Arg* arg_i = pikaTuple_getArg(encoding, 0);
if (arg_getType(arg_i) != ARG_TYPE_STRING) {
obj_setErrorCode(self, __LINE__);
__platform_printf("Error invaliad arguments\r\n");

View File

@ -4,12 +4,12 @@
int PikaStdData_Tuple_len(PikaObj* self) {
PikaList* list = obj_getPtr(self, "list");
return list_getSize(list);
return pikaList_getSize(list);
}
Arg* PikaStdData_Tuple_get(PikaObj* self, int i) {
PikaList* list = obj_getPtr(self, "list");
return arg_copy(list_getArg(list, i));
return arg_copy(pikaList_getArg(list, i));
}
void PikaStdData_Tuple___init__(PikaObj* self) {
@ -47,7 +47,7 @@ char* PikaStdData_Tuple___str__(PikaObj* self) {
int i = 0;
while (PIKA_TRUE) {
Arg* item = list_getArg(list, i);
Arg* item = pikaList_getArg(list, i);
if (NULL == item) {
break;
}
@ -77,8 +77,8 @@ int PikaStdData_Tuple___len__(PikaObj* self) {
int PikaStdData_Tuple___contains__(PikaObj* self, Arg* val) {
PikaList* list = obj_getPtr(self, "list");
for (size_t i = 0; i < list_getSize(list); i++) {
Arg* arg = list_getArg(list, i);
for (size_t i = 0; i < pikaList_getSize(list); i++) {
Arg* arg = pikaList_getArg(list, i);
if (arg_isEqual(arg, val)) {
return 1;
}

View File

@ -184,22 +184,22 @@ Arg* PikaStdLib_SysObj_range(PikaObj* self, PikaTuple* ax) {
Arg* obj_arg = arg_newDirectObj(New_PikaStdLib_RangeObj);
PikaObj* range_obj = arg_getPtr(obj_arg);
RangeData range_data = {0};
if (tuple_getSize(ax) == 1) {
if (pikaTuple_getSize(ax) == 1) {
int start = 0;
int end = arg_getInt(tuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 0));
range_data.start = start;
range_data.end = end;
range_data.step = 1;
} else if (tuple_getSize(ax) == 2) {
int start = arg_getInt(tuple_getArg(ax, 0));
int end = arg_getInt(tuple_getArg(ax, 1));
} else if (pikaTuple_getSize(ax) == 2) {
int start = arg_getInt(pikaTuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 1));
range_data.start = start;
range_data.end = end;
range_data.step = 1;
} else if (tuple_getSize(ax) == 3) {
int start = arg_getInt(tuple_getArg(ax, 0));
int end = arg_getInt(tuple_getArg(ax, 1));
int step = arg_getInt(tuple_getArg(ax, 2));
} else if (pikaTuple_getSize(ax) == 3) {
int start = arg_getInt(pikaTuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 1));
int step = arg_getInt(pikaTuple_getArg(ax, 2));
range_data.start = start;
range_data.end = end;
range_data.step = step;
@ -305,8 +305,8 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) {
Arg* PikaStdLib_SysObj_list(PikaObj* self, PikaTuple* val) {
#if PIKA_BUILTIN_STRUCT_ENABLE
if (1 == tuple_getSize(val)) {
Arg* in = tuple_getArg(val, 0);
if (1 == pikaTuple_getSize(val)) {
Arg* in = pikaTuple_getArg(val, 0);
obj_setArg(self, "__list", in);
/* clang-format off */
PIKA_PYTHON(
@ -408,10 +408,10 @@ Arg* PikaStdLib_SysObj_bytes(PikaObj* self, Arg* val) {
if (obj->constructor == New_PikaStdData_List ||
obj->constructor == New_PikaStdData_Tuple) {
PikaList* list = obj_getPtr(obj, "list");
Arg* bytes = arg_newBytes(NULL, list_getSize(list));
Arg* bytes = arg_newBytes(NULL, pikaList_getSize(list));
uint8_t* bytes_raw = arg_getBytes(bytes);
for (size_t i = 0; i < list_getSize(list); i++) {
bytes_raw[i] = (uint8_t)list_getInt(list, i);
for (size_t i = 0; i < pikaList_getSize(list); i++) {
bytes_raw[i] = (uint8_t)pikaList_getInt(list, i);
}
return bytes;
}
@ -474,20 +474,20 @@ __exit:
}
void PikaStdLib_SysObj_print(PikaObj* self, PikaTuple* val, PikaDict* ops) {
int arg_size = tuple_getSize(val);
char* end = dict_getStr(ops, "end");
int arg_size = pikaTuple_getSize(val);
char* end = pikaDict_getStr(ops, "end");
if (NULL == end) {
/* default */
end = "\r\n";
}
if (arg_size == 1) {
arg_singlePrint(tuple_getArg(val, 0), PIKA_FALSE, end);
arg_singlePrint(pikaTuple_getArg(val, 0), PIKA_FALSE, end);
return;
}
Arg* print_out_arg = NULL;
PIKA_BOOL is_get_print = PIKA_FALSE;
for (int i = 0; i < arg_size; i++) {
Arg* arg = tuple_getArg(val, i);
Arg* arg = pikaTuple_getArg(val, i);
char* item = __print_arg(self, arg);
if (NULL != item) {
is_get_print = PIKA_TRUE;
@ -663,8 +663,8 @@ char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
.handler = __obj_shellLineHandler_input,
.fn_getchar = __platform_getchar,
};
if (tuple_getSize(info) > 0) {
__platform_printf("%s", tuple_getStr(info, 0));
if (pikaTuple_getSize(info) > 0) {
__platform_printf("%s", pikaTuple_getStr(info, 0));
}
_temp__do_pikaScriptShell(self, &cfg);
char* res = obj_cacheStr(self, arg_getStr(cfg.context));

View File

@ -97,7 +97,7 @@ int *re_fullmatch2(pcre *re, const char *s, int len, int *out_vec_number, int op
if (!vec)
goto e_er;
opt &= ~PCRE_MULTILINE;
// opt &= ~PCRE_MULTILINE;
match:
rc = pcre_exec(re, NULL, s, len, start_offset, 0, vec, group_n);
if (rc == PCRE_ERROR_NOMATCH)

View File

@ -24,14 +24,14 @@
}
#define tu_getNew(name, obj_name) \
PikaTuple *name = New_tuple(); \
PikaTuple *name = New_pikaTuple(); \
Any obj_name = newNormalObj(New_PikaStdData_Tuple); \
obj_setPtr(obj_name, "list", name);
#define tu_append(tup, val, type) \
{ \
Arg *_arg = arg_new##type(val); \
list_append(&(tup)->super, _arg); \
pikaList_append(&(tup)->super, _arg); \
arg_deinit(_arg); \
}
#define li_append(list, val, type) \
@ -167,10 +167,10 @@ char *re_sub(PikaObj *self,
{
int flags = PCRE_UTF8;
int count = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -180,7 +180,7 @@ char *re_sub(PikaObj *self,
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -228,10 +228,10 @@ PikaObj *re_subn(PikaObj *self,
{
int flags = PCRE_UTF8;
int count = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -241,7 +241,7 @@ PikaObj *re_subn(PikaObj *self,
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -285,10 +285,10 @@ PikaObj *re_split(PikaObj *self, char *pattern, char *subject, PikaTuple *val)
{
int flags = PCRE_UTF8;
int max_split = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -298,7 +298,7 @@ PikaObj *re_split(PikaObj *self, char *pattern, char *subject, PikaTuple *val)
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -385,10 +385,10 @@ void re_Match___init__args(PikaObj *self, char *sub, int *vec, int ven)
char *re_Match_group(PikaObj *self, PikaTuple *val)
{
int n = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -452,7 +452,7 @@ PikaObj *re_Match_groups(PikaObj *self)
{
str_arg1 = arg_newStr("");
}
list_append(&(tup)->super, str_arg1);
pikaList_append(&(tup)->super, str_arg1);
arg_deinit(str_arg1);
}
return tup_obj;
@ -460,10 +460,10 @@ PikaObj *re_Match_groups(PikaObj *self)
PikaObj *re_Match_span(PikaObj *self, PikaTuple *val)
{
int group_n = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -599,10 +599,10 @@ char *re_Pattern_sub(PikaObj *self, char *repl, char *subjet, PikaTuple *val)
{
int flags = 0;
int count = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -612,7 +612,7 @@ char *re_Pattern_sub(PikaObj *self, char *repl, char *subjet, PikaTuple *val)
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -664,10 +664,10 @@ PikaObj *re_Pattern_subn(PikaObj *self, char *repl, char *subjet, PikaTuple *val
return NULL;
int flags = 0;
int count = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -677,7 +677,7 @@ PikaObj *re_Pattern_subn(PikaObj *self, char *repl, char *subjet, PikaTuple *val
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -702,10 +702,10 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
pcre *re = obj_getPtr(self, "_re");
int flags = PCRE_UTF8;
int max_split = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -715,7 +715,7 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -736,10 +736,10 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
int _get_flags(PikaTuple *val)
{
int flags = PCRE_UTF8;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
return -1;
@ -936,7 +936,7 @@ PikaObj *__findall(void *pattern__or__re,
b = malloc(length + 1);
if (!b)
goto e_er;
tu = New_tuple();
tu = New_pikaTuple();
for (int j = 1; j < brackets; j++)
{
@ -987,7 +987,7 @@ PikaObj *__subn(void *pattern__or__re,
}
if (s == subjet)
{
PikaTuple *yup = New_tuple();
PikaTuple *yup = New_pikaTuple();
tu_append(yup, s, Str);
tu_append(yup, 0, Int);
@ -996,7 +996,7 @@ PikaObj *__subn(void *pattern__or__re,
return tuple_obj;
}
PikaTuple *yup = New_tuple();
PikaTuple *yup = New_pikaTuple();
tu_append(yup, s, Str);
free(s);

View File

@ -5,7 +5,7 @@ import GTestTask, TempDevTest
import cb_test
import configparser
import test_module1, test_cmodule, test_module4, import_test
import hashlib
import hashlib, hmac
hashlib.sha256(b"123456")

View File

@ -9,7 +9,7 @@
Arg* PikaStdData_Dict_get(PikaObj* self, char* key) {
PikaDict* dict = obj_getPtr(self, "dict");
Arg* res = dict_getArg(dict, key);
Arg* res = pikaDict_getArg(dict, key);
if (NULL == res) {
obj_setErrorCode(self, PIKA_RES_ERR_RUNTIME_ERROR);
__platform_printf("KeyError: %s\n", key);
@ -28,8 +28,8 @@ void PikaStdData_Dict_set(PikaObj* self, char* key, Arg* arg) {
void PikaStdData_Dict_remove(PikaObj* self, char* key) {
PikaDict* dict = obj_getPtr(self, "dict");
PikaDict* keys = obj_getPtr(self, "_keys");
dict_removeArg(dict, dict_getArg(dict, key));
dict_removeArg(keys, dict_getArg(keys, key));
pikaDict_removeArg(dict, pikaDict_getArg(dict, key));
pikaDict_removeArg(keys, pikaDict_getArg(keys, key));
}
Arg* PikaStdData_Dict___iter__(PikaObj* self) {
@ -60,9 +60,9 @@ Arg* PikaStdData_Dict___getitem__(PikaObj* self, Arg* __key) {
void PikaStdData_Dict___del__(PikaObj* self) {
PikaDict* dict = obj_getPtr(self, "dict");
PikaDict* keys = obj_getPtr(self, "_keys");
dict_deinit(dict);
pikaDict_deinit(dict);
if (NULL != keys) {
dict_deinit(keys);
pikaDict_deinit(keys);
}
}
@ -227,8 +227,8 @@ Arg* PikaStdData_dict_items___next__(PikaObj* self) {
PikaObj* tuple = newNormalObj(New_PikaStdData_Tuple);
PikaStdData_Tuple___init__(tuple);
PikaList* list = obj_getPtr(tuple, "list");
list_append(list, key);
list_append(list, val);
pikaList_append(list, key);
pikaList_append(list, val);
args_setInt(self->list, "__iter_i", __iter_i + 1);
return arg_newObj(tuple);
}

View File

@ -83,8 +83,8 @@ int PikaStdData_FILEIO_seek(PikaObj* self, int offset, PikaTuple* fromwhere) {
__platform_printf("Error: can't seek in file\n");
return -1;
}
if (tuple_getSize(fromwhere) == 1) {
int whence = tuple_getInt(fromwhere, 0);
if (pikaTuple_getSize(fromwhere) == 1) {
int whence = pikaTuple_getInt(fromwhere, 0);
__platform_fseek(f, offset, whence);
return __platform_ftell(f);
}
@ -167,8 +167,8 @@ void PikaStdData_FILEIO_writelines(PikaObj* self, PikaObj* lines) {
__platform_printf("Error: can't write lines to file\n");
return;
}
for (size_t i = 0; i < list_getSize(list); i++) {
char* line = list_getStr(list, i);
for (size_t i = 0; i < pikaList_getSize(list); i++) {
char* line = pikaList_getStr(list, i);
Arg* arg_str = arg_newStr(line);
PikaStdData_FILEIO_write(self, arg_str);
arg_deinit(arg_str);

View File

@ -10,7 +10,7 @@ void PikaStdData_List_append(PikaObj* self, Arg* arg) {
void PikaStdData_List_set(PikaObj* self, int i, Arg* arg) {
PikaList* list = obj_getPtr(self, "list");
if (PIKA_RES_OK != list_setArg(list, i, arg)) {
if (PIKA_RES_OK != pikaList_setArg(list, i, arg)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "Error: index exceeded lengh of list.");
}
@ -32,7 +32,7 @@ char* PikaStdData_List___str__(PikaObj* self) {
int i = 0;
while (PIKA_TRUE) {
Arg* item = list_getArg(list, i);
Arg* item = pikaList_getArg(list, i);
if (NULL == item) {
break;
}
@ -58,7 +58,7 @@ char* PikaStdData_List___str__(PikaObj* self) {
void PikaStdData_List_reverse(PikaObj* self) {
PikaList* list = obj_getPtr(self, "list");
list_reverse(list);
pikaList_reverse(list);
}
PikaObj* PikaStdData_List___add__(PikaObj* self, PikaObj* others) {
@ -67,20 +67,20 @@ PikaObj* PikaStdData_List___add__(PikaObj* self, PikaObj* others) {
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 < pikaList_getSize(list1); i++) {
Arg* arg = pikaList_getArg(list1, i);
pikaList_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);
for (size_t i = 0; i < pikaList_getSize(list2); i++) {
Arg* arg = pikaList_getArg(list2, i);
pikaList_append(list_res, arg);
}
return res;
}
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)) {
if (PIKA_RES_OK != pikaList_insert(list, i, arg)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "Error: index exceeded lengh of list.");
}
@ -88,11 +88,11 @@ void PikaStdData_List_insert(PikaObj *self, int i, Arg* arg){
Arg* PikaStdData_List_pop(PikaObj *self){
PikaList* list = obj_getPtr(self, "list");
return list_pop(list);
return pikaList_pop(list);
}
void PikaStdData_List_remove(PikaObj *self, Arg* val){
PikaList* list = obj_getPtr(self, "list");
list_remove(list, val);
pikaList_remove(list, val);
}

View File

@ -286,12 +286,12 @@ int PikaStdData_String___len__(PikaObj* self) {
char* PikaStdData_String_strip(PikaObj* self, PikaTuple* chrs) {
Args buffs = {0};
char to_strip = ' ';
if (tuple_getSize(chrs) > 1) {
if (pikaTuple_getSize(chrs) > 1) {
obj_setErrorCode(self, PIKA_RES_ERR_INVALID_PARAM);
obj_setSysOut(self, "Error. Invalid param");
}
if (tuple_getSize(chrs) == 1) {
char* ch_str = tuple_getStr(chrs, 0);
if (pikaTuple_getSize(chrs) == 1) {
char* ch_str = pikaTuple_getStr(chrs, 0);
to_strip = ch_str[0];
}
char* str = strsCopy(&buffs, obj_getStr(self, "str"));
@ -332,11 +332,11 @@ Arg* PikaStdData_String_encode(PikaObj* self, PikaTuple* encoding) {
#if PIKA_STRING_UTF8_ENABLE
char* to_code = NULL;
int argn = tuple_getSize(encoding);
int argn = pikaTuple_getSize(encoding);
if (argn < 1) {
return arg_newBytes((uint8_t*)str, strGetSize(str));
}
Arg* arg_i = tuple_getArg(encoding, 0);
Arg* arg_i = pikaTuple_getArg(encoding, 0);
if (arg_getType(arg_i) != ARG_TYPE_STRING) {
obj_setErrorCode(self, __LINE__);
__platform_printf("Error invaliad arguments\r\n");

View File

@ -4,12 +4,12 @@
int PikaStdData_Tuple_len(PikaObj* self) {
PikaList* list = obj_getPtr(self, "list");
return list_getSize(list);
return pikaList_getSize(list);
}
Arg* PikaStdData_Tuple_get(PikaObj* self, int i) {
PikaList* list = obj_getPtr(self, "list");
return arg_copy(list_getArg(list, i));
return arg_copy(pikaList_getArg(list, i));
}
void PikaStdData_Tuple___init__(PikaObj* self) {
@ -47,7 +47,7 @@ char* PikaStdData_Tuple___str__(PikaObj* self) {
int i = 0;
while (PIKA_TRUE) {
Arg* item = list_getArg(list, i);
Arg* item = pikaList_getArg(list, i);
if (NULL == item) {
break;
}
@ -77,8 +77,8 @@ int PikaStdData_Tuple___len__(PikaObj* self) {
int PikaStdData_Tuple___contains__(PikaObj* self, Arg* val) {
PikaList* list = obj_getPtr(self, "list");
for (size_t i = 0; i < list_getSize(list); i++) {
Arg* arg = list_getArg(list, i);
for (size_t i = 0; i < pikaList_getSize(list); i++) {
Arg* arg = pikaList_getArg(list, i);
if (arg_isEqual(arg, val)) {
return 1;
}

View File

@ -184,22 +184,22 @@ Arg* PikaStdLib_SysObj_range(PikaObj* self, PikaTuple* ax) {
Arg* obj_arg = arg_newDirectObj(New_PikaStdLib_RangeObj);
PikaObj* range_obj = arg_getPtr(obj_arg);
RangeData range_data = {0};
if (tuple_getSize(ax) == 1) {
if (pikaTuple_getSize(ax) == 1) {
int start = 0;
int end = arg_getInt(tuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 0));
range_data.start = start;
range_data.end = end;
range_data.step = 1;
} else if (tuple_getSize(ax) == 2) {
int start = arg_getInt(tuple_getArg(ax, 0));
int end = arg_getInt(tuple_getArg(ax, 1));
} else if (pikaTuple_getSize(ax) == 2) {
int start = arg_getInt(pikaTuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 1));
range_data.start = start;
range_data.end = end;
range_data.step = 1;
} else if (tuple_getSize(ax) == 3) {
int start = arg_getInt(tuple_getArg(ax, 0));
int end = arg_getInt(tuple_getArg(ax, 1));
int step = arg_getInt(tuple_getArg(ax, 2));
} else if (pikaTuple_getSize(ax) == 3) {
int start = arg_getInt(pikaTuple_getArg(ax, 0));
int end = arg_getInt(pikaTuple_getArg(ax, 1));
int step = arg_getInt(pikaTuple_getArg(ax, 2));
range_data.start = start;
range_data.end = end;
range_data.step = step;
@ -305,8 +305,8 @@ int PikaStdLib_SysObj_len(PikaObj* self, Arg* arg) {
Arg* PikaStdLib_SysObj_list(PikaObj* self, PikaTuple* val) {
#if PIKA_BUILTIN_STRUCT_ENABLE
if (1 == tuple_getSize(val)) {
Arg* in = tuple_getArg(val, 0);
if (1 == pikaTuple_getSize(val)) {
Arg* in = pikaTuple_getArg(val, 0);
obj_setArg(self, "__list", in);
/* clang-format off */
PIKA_PYTHON(
@ -408,10 +408,10 @@ Arg* PikaStdLib_SysObj_bytes(PikaObj* self, Arg* val) {
if (obj->constructor == New_PikaStdData_List ||
obj->constructor == New_PikaStdData_Tuple) {
PikaList* list = obj_getPtr(obj, "list");
Arg* bytes = arg_newBytes(NULL, list_getSize(list));
Arg* bytes = arg_newBytes(NULL, pikaList_getSize(list));
uint8_t* bytes_raw = arg_getBytes(bytes);
for (size_t i = 0; i < list_getSize(list); i++) {
bytes_raw[i] = (uint8_t)list_getInt(list, i);
for (size_t i = 0; i < pikaList_getSize(list); i++) {
bytes_raw[i] = (uint8_t)pikaList_getInt(list, i);
}
return bytes;
}
@ -474,20 +474,20 @@ __exit:
}
void PikaStdLib_SysObj_print(PikaObj* self, PikaTuple* val, PikaDict* ops) {
int arg_size = tuple_getSize(val);
char* end = dict_getStr(ops, "end");
int arg_size = pikaTuple_getSize(val);
char* end = pikaDict_getStr(ops, "end");
if (NULL == end) {
/* default */
end = "\r\n";
}
if (arg_size == 1) {
arg_singlePrint(tuple_getArg(val, 0), PIKA_FALSE, end);
arg_singlePrint(pikaTuple_getArg(val, 0), PIKA_FALSE, end);
return;
}
Arg* print_out_arg = NULL;
PIKA_BOOL is_get_print = PIKA_FALSE;
for (int i = 0; i < arg_size; i++) {
Arg* arg = tuple_getArg(val, i);
Arg* arg = pikaTuple_getArg(val, i);
char* item = __print_arg(self, arg);
if (NULL != item) {
is_get_print = PIKA_TRUE;
@ -663,8 +663,8 @@ char* PikaStdLib_SysObj_input(PikaObj* self, PikaTuple* info) {
.handler = __obj_shellLineHandler_input,
.fn_getchar = __platform_getchar,
};
if (tuple_getSize(info) > 0) {
__platform_printf("%s", tuple_getStr(info, 0));
if (pikaTuple_getSize(info) > 0) {
__platform_printf("%s", pikaTuple_getStr(info, 0));
}
_temp__do_pikaScriptShell(self, &cfg);
char* res = obj_cacheStr(self, arg_getStr(cfg.context));

View File

@ -24,14 +24,14 @@
}
#define tu_getNew(name, obj_name) \
PikaTuple *name = New_tuple(); \
PikaTuple *name = New_pikaTuple(); \
Any obj_name = newNormalObj(New_PikaStdData_Tuple); \
obj_setPtr(obj_name, "list", name);
#define tu_append(tup, val, type) \
{ \
Arg *_arg = arg_new##type(val); \
list_append(&(tup)->super, _arg); \
pikaList_append(&(tup)->super, _arg); \
arg_deinit(_arg); \
}
#define li_append(list, val, type) \
@ -167,10 +167,10 @@ char *re_sub(PikaObj *self,
{
int flags = PCRE_UTF8;
int count = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -180,7 +180,7 @@ char *re_sub(PikaObj *self,
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -228,10 +228,10 @@ PikaObj *re_subn(PikaObj *self,
{
int flags = PCRE_UTF8;
int count = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -241,7 +241,7 @@ PikaObj *re_subn(PikaObj *self,
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -285,10 +285,10 @@ PikaObj *re_split(PikaObj *self, char *pattern, char *subject, PikaTuple *val)
{
int flags = PCRE_UTF8;
int max_split = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -298,7 +298,7 @@ PikaObj *re_split(PikaObj *self, char *pattern, char *subject, PikaTuple *val)
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -385,10 +385,10 @@ void re_Match___init__args(PikaObj *self, char *sub, int *vec, int ven)
char *re_Match_group(PikaObj *self, PikaTuple *val)
{
int n = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -452,7 +452,7 @@ PikaObj *re_Match_groups(PikaObj *self)
{
str_arg1 = arg_newStr("");
}
list_append(&(tup)->super, str_arg1);
pikaList_append(&(tup)->super, str_arg1);
arg_deinit(str_arg1);
}
return tup_obj;
@ -460,10 +460,10 @@ PikaObj *re_Match_groups(PikaObj *self)
PikaObj *re_Match_span(PikaObj *self, PikaTuple *val)
{
int group_n = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -599,10 +599,10 @@ char *re_Pattern_sub(PikaObj *self, char *repl, char *subjet, PikaTuple *val)
{
int flags = 0;
int count = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -612,7 +612,7 @@ char *re_Pattern_sub(PikaObj *self, char *repl, char *subjet, PikaTuple *val)
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -664,10 +664,10 @@ PikaObj *re_Pattern_subn(PikaObj *self, char *repl, char *subjet, PikaTuple *val
return NULL;
int flags = 0;
int count = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -677,7 +677,7 @@ PikaObj *re_Pattern_subn(PikaObj *self, char *repl, char *subjet, PikaTuple *val
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -702,10 +702,10 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
pcre *re = obj_getPtr(self, "_re");
int flags = PCRE_UTF8;
int max_split = 0;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -715,7 +715,7 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
}
if (argn >= 2)
{
Arg *arg_i = tuple_getArg(val, 1);
Arg *arg_i = pikaTuple_getArg(val, 1);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
obj_setErrorCode(self, -__LINE__);
@ -736,10 +736,10 @@ PikaObj *re_Pattern_split(PikaObj *self, char *subject, PikaTuple *val)
int _get_flags(PikaTuple *val)
{
int flags = PCRE_UTF8;
int argn = tuple_getSize(val);
int argn = pikaTuple_getSize(val);
if (argn >= 1)
{
Arg *arg_i = tuple_getArg(val, 0);
Arg *arg_i = pikaTuple_getArg(val, 0);
if (arg_getType(arg_i) != ARG_TYPE_INT)
{
return -1;
@ -936,7 +936,7 @@ PikaObj *__findall(void *pattern__or__re,
b = malloc(length + 1);
if (!b)
goto e_er;
tu = New_tuple();
tu = New_pikaTuple();
for (int j = 1; j < brackets; j++)
{
@ -987,7 +987,7 @@ PikaObj *__subn(void *pattern__or__re,
}
if (s == subjet)
{
PikaTuple *yup = New_tuple();
PikaTuple *yup = New_pikaTuple();
tu_append(yup, s, Str);
tu_append(yup, 0, Int);
@ -996,7 +996,7 @@ PikaObj *__subn(void *pattern__or__re,
return tuple_obj;
}
PikaTuple *yup = New_tuple();
PikaTuple *yup = New_pikaTuple();
tu_append(yup, s, Str);
free(s);

View File

@ -856,7 +856,7 @@ char* _keys_to_defult(char* type_list,
strPopLastToken(arg_name, '=');
/* load default arg from kws */
if (kws != NULL) {
Arg* default_arg = dict_getArg(kws, arg_name);
Arg* default_arg = pikaDict_getArg(kws, arg_name);
if (default_arg != NULL) {
argv[(*argc)++] = arg_copy(default_arg);
}
@ -920,16 +920,16 @@ static void _kw_push(PikaDict** kw_dict_p,
Arg* call_arg,
int i) {
if (NULL == *kw_dict_p) {
*kw_dict_p = New_dict();
*kw_dict_p = New_pikaDict();
}
if (NULL == *kw_keys_p) {
*kw_keys_p = New_dict();
*kw_keys_p = New_pikaDict();
}
arg_setIsKeyword(call_arg, PIKA_FALSE);
dict_setArg(*kw_dict_p, call_arg);
pikaDict_setArg(*kw_dict_p, call_arg);
char kw_keys_index_buff[11] = {0};
char* kw_keys_index = fast_itoa(kw_keys_index_buff, i);
dict_setArg(*kw_keys_p,
pikaDict_setArg(*kw_keys_p,
arg_setInt(NULL, kw_keys_index, arg_getNameHash(call_arg)));
}
@ -1040,7 +1040,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
var_tuple_name = arg_def + 1;
/* create tuple */
if (NULL == tuple) {
tuple = New_tuple();
tuple = New_pikaTuple();
/* remove the format arg */
strPopLastToken(type_list, ',');
}
@ -1049,8 +1049,8 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
if (arg_def[0] == '*' && arg_def[1] == '*') {
/* get keyword dict name */
kw_dict_name = arg_def + 2;
kw_dict = New_dict();
kw_keys = New_dict();
kw_dict = New_pikaDict();
kw_keys = New_pikaDict();
/* remove the format arg */
strPopLastToken(type_list, ',');
continue;
@ -1070,7 +1070,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
/* load variable arg */
if (arg_index > arg_num_pos) {
if (is_vars) {
list_append(&tuple->super, call_arg);
pikaList_append(&tuple->super, call_arg);
/* the append would copy the arg */
if (NULL != call_arg) {
arg_deinit(call_arg);
@ -1108,7 +1108,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
#endif
if (tuple != NULL) {
list_reverse(&tuple->super);
pikaList_reverse(&tuple->super);
/* load variable tuple */
PikaObj* New_PikaStdData_Tuple(Args * args);
PikaObj* tuple_obj = newNormalObj(New_PikaStdData_Tuple);
@ -1143,11 +1143,11 @@ exit:
void __vm_List_append(PikaObj* self, Arg* arg) {
PikaList* list = obj_getPtr(self, "list");
list_append(list, arg);
pikaList_append(list, arg);
}
void __vm_List___init__(PikaObj* self) {
PikaList* list = New_list();
PikaList* list = New_pikaList();
obj_setPtr(self, "list", list);
}
@ -1193,8 +1193,8 @@ static Arg* VM_instruction_handler_LST(PikaObj* self,
}
void __vm_Dict___init__(PikaObj* self) {
PikaDict* dict = New_dict();
PikaDict* keys = New_dict();
PikaDict* dict = New_pikaDict();
PikaDict* keys = New_pikaDict();
obj_setPtr(self, "dict", dict);
obj_setPtr(self, "_keys", keys);
}
@ -1205,8 +1205,8 @@ void __vm_Dict_set(PikaObj* self, Arg* arg, char* key) {
Arg* arg_key = arg_setStr(NULL, key, key);
Arg* arg_new = arg_copy(arg);
arg_setName(arg_new, key);
dict_setArg(dict, arg_new);
dict_setArg(keys, arg_key);
pikaDict_setArg(dict, arg_new);
pikaDict_setArg(keys, arg_key);
}
#if PIKA_BUILTIN_STRUCT_ENABLE

View File

@ -468,19 +468,19 @@ Args* New_args(Args* args) {
return self;
}
PikaDict* New_dict(void) {
PikaDict* New_pikaDict(void) {
PikaDict* self = (PikaDict*)New_args(NULL);
return self;
}
PikaList* New_list(void) {
PikaList* New_pikaList(void) {
PikaList* self = (PikaList*)New_args(NULL);
/* set top index for append */
args_pushArg_name(&self->super, "top", arg_newInt(0));
return self;
}
PIKA_RES list_setArg(PikaList* self, int index, Arg* arg) {
PIKA_RES pikaList_setArg(PikaList* self, int index, Arg* arg) {
char buff[11];
char* i_str = fast_itoa(buff, index);
int top = args_getInt(&self->super, "top");
@ -493,33 +493,33 @@ PIKA_RES list_setArg(PikaList* self, int index, Arg* arg) {
return PIKA_RES_OK;
}
Arg* list_getArg(PikaList* self, int index) {
Arg* pikaList_getArg(PikaList* self, int index) {
char buff[11];
char* i_str = fast_itoa(buff, index);
return args_getArg(&self->super, i_str);
}
int list_getInt(PikaList* self, int index) {
Arg* arg = list_getArg(self, index);
int pikaList_getInt(PikaList* self, int index) {
Arg* arg = pikaList_getArg(self, index);
return arg_getInt(arg);
}
pika_float list_getFloat(PikaList* self, int index) {
Arg* arg = list_getArg(self, index);
pika_float pikaList_getFloat(PikaList* self, int index) {
Arg* arg = pikaList_getArg(self, index);
return arg_getFloat(arg);
}
char* list_getStr(PikaList* self, int index) {
Arg* arg = list_getArg(self, index);
char* pikaList_getStr(PikaList* self, int index) {
Arg* arg = pikaList_getArg(self, index);
return arg_getStr(arg);
}
void* list_getPtr(PikaList* self, int index) {
Arg* arg = list_getArg(self, index);
void* pikaList_getPtr(PikaList* self, int index) {
Arg* arg = pikaList_getArg(self, index);
return arg_getPtr(arg);
}
PIKA_RES list_append(PikaList* self, Arg* arg) {
PIKA_RES pikaList_append(PikaList* self, Arg* arg) {
if (NULL == arg) {
return PIKA_RES_ERR_ARG_NO_FOUND;
}
@ -533,26 +533,26 @@ PIKA_RES list_append(PikaList* self, Arg* arg) {
return args_setInt(&self->super, "top", top + 1);
}
Arg* list_pop(PikaList* list) {
Arg* pikaList_pop(PikaList* list) {
int top = args_getInt(&list->super, "top");
if (top <= 0) {
return NULL;
}
Arg* arg = list_getArg(list, top - 1);
Arg* arg = pikaList_getArg(list, top - 1);
Arg* res = arg_copy(arg);
args_removeArg(&list->super, arg);
args_setInt(&list->super, "top", top - 1);
return res;
}
PIKA_RES list_remove(PikaList* list, Arg* arg) {
PIKA_RES pikaList_remove(PikaList* list, Arg* arg) {
int top = args_getInt(&list->super, "top");
int i_remove = 0;
if (top <= 0) {
return PIKA_RES_ERR_OUT_OF_RANGE;
}
for (int i = 0; i < top; i++) {
Arg* arg_now = list_getArg(list, i);
Arg* arg_now = pikaList_getArg(list, i);
if (arg_isEqual(arg_now, arg)) {
i_remove = i;
args_removeArg(&list->super, arg_now);
@ -563,14 +563,14 @@ PIKA_RES list_remove(PikaList* list, Arg* arg) {
for (int i = i_remove + 1; i < top; i++) {
char buff[11];
char* i_str = fast_itoa(buff, i - 1);
Arg* arg_now = list_getArg(list, i);
Arg* arg_now = pikaList_getArg(list, i);
arg_setName(arg_now, i_str);
}
args_setInt(&list->super, "top", top - 1);
return PIKA_RES_OK;
}
PIKA_RES list_insert(PikaList* self, int index, Arg* arg) {
PIKA_RES pikaList_insert(PikaList* self, int index, Arg* arg) {
int top = args_getInt(&self->super, "top");
if (index > top) {
return PIKA_RES_ERR_OUT_OF_RANGE;
@ -579,7 +579,7 @@ PIKA_RES list_insert(PikaList* self, int index, Arg* arg) {
for (int i = top - 1; i >= index; i--) {
char buff[11];
char* i_str = fast_itoa(buff, i + 1);
Arg* arg_now = list_getArg(self, i);
Arg* arg_now = pikaList_getArg(self, i);
arg_setName(arg_now, i_str);
}
char buff[11];
@ -591,26 +591,26 @@ PIKA_RES list_insert(PikaList* self, int index, Arg* arg) {
return PIKA_RES_OK;
}
size_t list_getSize(PikaList* self) {
size_t pikaList_getSize(PikaList* self) {
pika_assert(NULL != self);
return args_getInt(&self->super, "top");
}
void list_reverse(PikaList* self) {
void pikaList_reverse(PikaList* self) {
pika_assert(NULL != self);
int top = list_getSize(self);
int top = pikaList_getSize(self);
for (int i = 0; i < top / 2; i++) {
Arg* arg_i = arg_copy(list_getArg(self, i));
Arg* arg_top = arg_copy(list_getArg(self, top - i - 1));
list_setArg(self, i, arg_top);
list_setArg(self, top - i - 1, arg_i);
Arg* arg_i = arg_copy(pikaList_getArg(self, i));
Arg* arg_top = arg_copy(pikaList_getArg(self, top - i - 1));
pikaList_setArg(self, i, arg_top);
pikaList_setArg(self, top - i - 1, arg_i);
arg_deinit(arg_i);
arg_deinit(arg_top);
}
}
PikaTuple* New_tuple(void) {
PikaTuple* self = (PikaTuple*)New_list();
PikaTuple* New_pikaTuple(void) {
PikaTuple* self = (PikaTuple*)New_pikaList();
return self;
}
@ -674,9 +674,9 @@ char* strsFormatList(Args* out_buffs, char* fmt, PikaList* list) {
char* fmt_item = strsPopToken(&buffs, &fmt_buff, '%');
Arg* res_buff = arg_newStr(fmt_item);
for (size_t i = 0; i < list_getSize(list); i++) {
for (size_t i = 0; i < pikaList_getSize(list); i++) {
Args buffs_item = {0};
Arg* arg = list_getArg(list, i);
Arg* arg = pikaList_getArg(list, i);
char* fmt_item = strsPopToken(&buffs_item, &fmt_buff, '%');
fmt_item = strsAppend(&buffs_item, "%", fmt_item);
char* str_format = strsFormatArg(&buffs_item, fmt_item, arg);

View File

@ -136,131 +136,131 @@ struct PikaDict {
};
/* dict api */
PikaDict* New_dict(void);
PikaDict* New_pikaDict(void);
static inline PIKA_RES dict_setInt(PikaDict* self, char* name, int64_t val) {
static inline PIKA_RES pikaDict_setInt(PikaDict* self, char* name, int64_t val) {
return args_setInt((&((self)->super)), (name), (val));
}
static inline PIKA_RES dict_setFloat(PikaDict* self,
static inline PIKA_RES pikaDict_setFloat(PikaDict* self,
char* name,
pika_float val) {
return args_setFloat((&((self)->super)), (name), (val));
}
static inline PIKA_RES dict_setStr(PikaDict* self, char* name, char* val) {
static inline PIKA_RES pikaDict_setStr(PikaDict* self, char* name, char* val) {
return args_setStr((&((self)->super)), (name), (val));
}
static inline PIKA_RES dict_setPtr(PikaDict* self, char* name, void* val) {
static inline PIKA_RES pikaDict_setPtr(PikaDict* self, char* name, void* val) {
return args_setPtr((&((self)->super)), (name), (val));
}
static inline PIKA_RES dict_setArg(PikaDict* self, Arg* val) {
static inline PIKA_RES pikaDict_setArg(PikaDict* self, Arg* val) {
return args_setArg((&((self)->super)), (val));
}
static inline PIKA_RES dict_removeArg(PikaDict* self, Arg* val) {
static inline PIKA_RES pikaDict_removeArg(PikaDict* self, Arg* val) {
return args_removeArg((&((self)->super)), (val));
}
static inline PIKA_RES dict_setBytes(PikaDict* self,
static inline PIKA_RES pikaDict_setBytes(PikaDict* self,
char* name,
uint8_t* val,
size_t size) {
return args_setBytes((&((self)->super)), (name), (val), (size));
}
static inline int64_t dict_getInt(PikaDict* self, char* name) {
static inline int64_t pikaDict_getInt(PikaDict* self, char* name) {
return args_getInt((&((self)->super)), (name));
}
static inline pika_float dict_getFloat(PikaDict* self, char* name) {
static inline pika_float pikaDict_getFloat(PikaDict* self, char* name) {
return args_getFloat((&((self)->super)), (name));
}
static inline char* dict_getStr(PikaDict* self, char* name) {
static inline char* pikaDict_getStr(PikaDict* self, char* name) {
return args_getStr((&((self)->super)), (name));
}
static inline void* dict_getPtr(PikaDict* self, char* name) {
static inline void* pikaDict_getPtr(PikaDict* self, char* name) {
return args_getPtr((&((self)->super)), (name));
}
static inline Arg* dict_getArg(PikaDict* self, char* name) {
static inline Arg* pikaDict_getArg(PikaDict* self, char* name) {
return args_getArg((&((self)->super)), (name));
}
static inline uint8_t* dict_getBytes(PikaDict* self, char* name) {
static inline uint8_t* pikaDict_getBytes(PikaDict* self, char* name) {
return args_getBytes((&((self)->super)), (name));
}
static inline ArgType dict_getType(PikaDict* self, char* name) {
static inline ArgType pikaDict_getType(PikaDict* self, char* name) {
return args_getType((&((self)->super)), (name));
}
static inline size_t dict_getBytesSize(PikaDict* self, char* name) {
static inline size_t pikaDict_getBytesSize(PikaDict* self, char* name) {
return args_getBytesSize((&((self)->super)), (name));
}
static inline void dict_deinit(PikaDict* self) {
static inline void pikaDict_deinit(PikaDict* self) {
args_deinit((&((self)->super)));
}
/* list api */
PIKA_RES list_append(PikaList* self, Arg* arg);
PIKA_RES list_setArg(PikaList* self, int index, Arg* arg);
int list_getInt(PikaList* self, int index);
pika_float list_getFloat(PikaList* self, int index);
char* list_getStr(PikaList* self, int index);
void* list_getPtr(PikaList* self, int index);
Arg* list_getArg(PikaList* self, int index);
size_t list_getSize(PikaList* self);
void list_reverse(PikaList* self);
PIKA_RES list_insert(PikaList* self, int index, Arg* arg);
Arg* list_pop(PikaList* list);
PIKA_RES list_remove(PikaList* list, Arg* arg);
static inline void list_deinit(PikaList* self) {
PIKA_RES pikaList_append(PikaList* self, Arg* arg);
PIKA_RES pikaList_setArg(PikaList* self, int index, Arg* arg);
int pikaList_getInt(PikaList* self, int index);
pika_float pikaList_getFloat(PikaList* self, int index);
char* pikaList_getStr(PikaList* self, int index);
void* pikaList_getPtr(PikaList* self, int index);
Arg* pikaList_getArg(PikaList* self, int index);
size_t pikaList_getSize(PikaList* self);
void pikaList_reverse(PikaList* self);
PIKA_RES pikaList_insert(PikaList* self, int index, Arg* arg);
Arg* pikaList_pop(PikaList* list);
PIKA_RES pikaList_remove(PikaList* list, Arg* arg);
static inline void pikaList_deinit(PikaList* self) {
args_deinit((&((self)->super)));
}
static inline ArgType list_getType(PikaList* self, int index) {
Arg* arg = list_getArg(self, index);
static inline ArgType pikaList_getType(PikaList* self, int index) {
Arg* arg = pikaList_getArg(self, index);
return arg_getType(arg);
}
/* tuple api */
static inline void tuple_deinit(PikaTuple* self) {
list_deinit((&((self)->super)));
static inline void pikaTuple_deinit(PikaTuple* self) {
pikaList_deinit((&((self)->super)));
}
static inline Arg* tuple_getArg(PikaTuple* self, int index) {
return list_getArg((&((self)->super)), (index));
static inline Arg* pikaTuple_getArg(PikaTuple* self, int index) {
return pikaList_getArg((&((self)->super)), (index));
}
static inline size_t tuple_getSize(PikaTuple* self) {
return list_getSize((&((self)->super)));
static inline size_t pikaTuple_getSize(PikaTuple* self) {
return pikaList_getSize((&((self)->super)));
}
static inline int64_t tuple_getInt(PikaTuple* self, int index) {
return list_getInt((&((self)->super)), (index));
static inline int64_t pikaTuple_getInt(PikaTuple* self, int index) {
return pikaList_getInt((&((self)->super)), (index));
}
static inline pika_float tuple_getFloat(PikaTuple* self, int index) {
return list_getFloat((&((self)->super)), (index));
static inline pika_float pikaTuple_getFloat(PikaTuple* self, int index) {
return pikaList_getFloat((&((self)->super)), (index));
}
static inline char* tuple_getStr(PikaTuple* self, int index) {
return list_getStr((&((self)->super)), (index));
static inline char* pikaTuple_getStr(PikaTuple* self, int index) {
return pikaList_getStr((&((self)->super)), (index));
}
static inline void* tuple_getPtr(PikaTuple* self, int index) {
return list_getPtr((&((self)->super)), (index));
static inline void* pikaTuple_getPtr(PikaTuple* self, int index) {
return pikaList_getPtr((&((self)->super)), (index));
}
static inline ArgType tuple_getType(PikaTuple* self, int index) {
return list_getType((&((self)->super)), (index));
static inline ArgType pikaTuple_getType(PikaTuple* self, int index) {
return pikaList_getType((&((self)->super)), (index));
}
PikaList* New_list(void);
PikaTuple* New_tuple(void);
PikaList* New_pikaList(void);
PikaTuple* New_pikaTuple(void);
PikaTuple* args_getTuple(Args* self, char* name);
PikaDict* args_getDict(Args* self, char* name);

View File

@ -135,25 +135,25 @@ static inline char* mp_obj_str_get_data(Arg* self, size_t* len) {
static inline size_t pks_load_mp_args(PikaTuple* tuple,
mp_obj_t mp_self,
mp_obj_t* args) {
size_t len = tuple_getSize(tuple);
size_t len = pikaTuple_getSize(tuple);
size_t i = 0;
if (NULL != mp_self) {
args[0] = mp_self;
i = 1;
}
for (i = 0; i < len; i++) {
args[i] = tuple_getArg(tuple, i);
args[i] = pikaTuple_getArg(tuple, i);
}
return len;
}
static inline void pks_load_mp_map(PikaDict* kw, mp_map_t* map) {
size_t len = dict_getSize(kw);
size_t len = pikaDict_getSize(kw);
map->alloc = len;
map->used = len;
map->table = (mp_map_elem_t*)malloc(sizeof(mp_map_elem_t) * len);
for (int i = 0; i < len; i++) {
Arg* item = dict_getArgByidex(kw, i);
Arg* item = pikaDict_getArgByidex(kw, i);
map->table[i].key = arg_getNameHash(item);
map->table[i].value = item;
}
@ -202,7 +202,7 @@ static inline void mp_obj_get_array_fixed_n(mp_obj_t tuple,
size_t n,
mp_obj_t* arrray) {
for (int i = 0; i < n; i++) {
arrray[i] = tuple_getArg((PikaTuple*)arg_getPtr(tuple), i);
arrray[i] = pikaTuple_getArg((PikaTuple*)arg_getPtr(tuple), i);
}
}

View File

@ -257,25 +257,25 @@ TEST(args, args_mem) {
}
TEST(args, dict) {
PikaDict* dict = New_dict();
PikaDict* dict = New_pikaDict();
int64_t int64Out = 0;
void* pointer = NULL;
char* strOut = NULL;
dict_setInt(dict, "int64Test", (int64_t)22221);
dict_setPtr(dict, "pointerTest", (void*)2222322);
dict_setStr(dict, "strTest", "teeeds");
pikaDict_setInt(dict, "int64Test", (int64_t)22221);
pikaDict_setPtr(dict, "pointerTest", (void*)2222322);
pikaDict_setStr(dict, "strTest", "teeeds");
int64Out = dict_getInt(dict, "int64Test");
pointer = dict_getPtr(dict, "pointerTest");
strOut = dict_getStr(dict, "strTest");
int64Out = pikaDict_getInt(dict, "int64Test");
pointer = pikaDict_getPtr(dict, "pointerTest");
strOut = pikaDict_getStr(dict, "strTest");
EXPECT_EQ(int64Out, 22221);
EXPECT_EQ((uint64_t)pointer, 2222322);
EXPECT_EQ(1, strEqu("teeeds", strOut));
EXPECT_EQ(dict_getType(dict, "int64Test"), ARG_TYPE_INT);
EXPECT_EQ(dict_getType(dict, "pointerTest"), ARG_TYPE_POINTER);
EXPECT_EQ(dict_getType(dict, "strTest"), ARG_TYPE_STRING);
dict_deinit(dict);
EXPECT_EQ(pikaDict_getType(dict, "int64Test"), ARG_TYPE_INT);
EXPECT_EQ(pikaDict_getType(dict, "pointerTest"), ARG_TYPE_POINTER);
EXPECT_EQ(pikaDict_getType(dict, "strTest"), ARG_TYPE_STRING);
pikaDict_deinit(dict);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST_END