From 74426e4bd3e97060f06b2cb451a38042b5634abc Mon Sep 17 00:00:00 2001 From: lyon Date: Mon, 13 Dec 2021 21:32:45 +0800 Subject: [PATCH] add PikaStdData --- package/PikaStdData/PikaStdData.py | 17 +++++++++++++ package/PikaStdData/PikaStdData_List.c | 35 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 package/PikaStdData/PikaStdData.py create mode 100644 package/PikaStdData/PikaStdData_List.c diff --git a/package/PikaStdData/PikaStdData.py b/package/PikaStdData/PikaStdData.py new file mode 100644 index 000000000..8f227d9c1 --- /dev/null +++ b/package/PikaStdData/PikaStdData.py @@ -0,0 +1,17 @@ +from PikaObj import * + +class List(TinyObj): + def init(): + pass + + def append(arg: any): + pass + + def get(i: int) -> any: + pass + + def set(i: int, arg: any): + pass + + def len() -> int: + pass \ No newline at end of file diff --git a/package/PikaStdData/PikaStdData_List.c b/package/PikaStdData/PikaStdData_List.c new file mode 100644 index 000000000..407594dea --- /dev/null +++ b/package/PikaStdData/PikaStdData_List.c @@ -0,0 +1,35 @@ +#include "PikaStdData_List.h" + +void PikaStdData_List_append(PikaObj* self, Arg* arg) { + int top = obj_getInt(self, "top"); + char buff[11]; + char* topStr = fast_itoa(buff, top); + obj_setArg(self, topStr, arg); + /* top++ */ + obj_setInt(self, "top", top + 1); +} + +int PikaStdData_List_len(PikaObj* self) { + return obj_getInt(self, "top"); +} + +Arg* PikaStdData_List_get(PikaObj* self, int i) { + char buff[11]; + char* index = fast_itoa(buff, i); + return arg_copy(obj_getArg(self, index)); +} +void PikaStdData_List___init__(PikaObj* self) { + /* set top index for append */ + obj_setInt(self, "top", 0); +} + +void PikaStdData_List_set(PikaObj* self, Arg* arg, int i) { + char buff[11]; + char* i_str = fast_itoa(buff, i); + int top = obj_getInt(self, "top"); + if (i > top) { + obj_setErrorCode(self, 1); + obj_setSysOut(self, "[error]: index exceeded lengh of list."); + } + obj_setArg(self, i_str, arg); +}