add dict in stddata

This commit is contained in:
lyon 2021-12-13 22:01:42 +08:00
parent 078eab2bfb
commit adaff1bd43
4 changed files with 43 additions and 4 deletions

View File

@ -18,7 +18,8 @@
"stdint.h": "c",
"cstdio": "c",
"cstdlib": "c",
"pikastddevice_gpio.h": "c"
"pikastddevice_gpio.h": "c",
"pikastddata_dict.h": "c"
},
"python.formatting.provider": "autopep8"
}

View File

@ -1,5 +1,6 @@
from PikaObj import *
class List(TinyObj):
def __init__():
pass
@ -12,10 +13,27 @@ class List(TinyObj):
def get(i: int) -> any:
pass
# set an arg by the index
# set an arg by the index
def set(i: int, arg: any):
pass
# get the length of list
def len() -> int:
pass
pass
class Dict(TinyObj):
def __init__():
pass
# get an arg by the key
def get(key: str) -> any:
pass
# set an arg by the key
def set(key: str, arg: any):
pass
# remove an arg by the key
def remove(key: str):
pass

View File

@ -1,4 +1,4 @@
#include "PikaStdData_List.h"
#include "PikaObj.h"
void PikaStdData_List_append(PikaObj* self, Arg* arg) {
int top = obj_getInt(self, "top");

View File

@ -266,6 +266,26 @@ TEST(pikaMain, __init__) {
/* assert */
EXPECT_STREQ(a, "PA0");
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(pikaMain, PikaStdData){
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
/* run */
obj_run(pikaMain, (char*)
"dict = PikaStdData.Dict()\n"
"dict.set('a', 1)\n"
"a = dict.get('a')\n"
);
/* collect */
int a = obj_getInt(pikaMain, (char *)"a");
/* assert */
EXPECT_EQ(a, 1);
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);