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
@ -19,3 +20,20 @@ class List(TinyObj):
# get the length of list
def len() -> int:
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

@ -270,3 +270,23 @@ TEST(pikaMain, __init__) {
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);
}