mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add mem check
add big_dict_update test
This commit is contained in:
parent
b067caa7e0
commit
efd9abbf17
@ -58,19 +58,26 @@ class List(Tuple):
|
||||
|
||||
|
||||
class Dict:
|
||||
def __init__(self): ...
|
||||
# get an arg by the key
|
||||
def __init__(self):
|
||||
""" get an arg by the key """
|
||||
|
||||
def get(self, key: str) -> any: ...
|
||||
# set an arg by the key
|
||||
def set(self, key: str, arg: any): ...
|
||||
# remove an arg by the key
|
||||
def remove(self, key: str): ...
|
||||
|
||||
def set(self, key: str, arg: any):
|
||||
""" set an arg by the key """
|
||||
|
||||
def remove(self, key: str):
|
||||
""" remove an arg by the key """
|
||||
|
||||
def __iter__(self) -> any: ...
|
||||
def __next__(self) -> any: ...
|
||||
# support dict[] = val
|
||||
def __setitem__(self, __key: any, __val: any): ...
|
||||
# support val = dict[]
|
||||
def __getitem__(self, __key: any) -> any: ...
|
||||
|
||||
def __setitem__(self, __key: any, __val: any):
|
||||
""" support dict[] = val """
|
||||
|
||||
def __getitem__(self, __key: any) -> any:
|
||||
""" support val = dict[] """
|
||||
|
||||
def __del__(self): ...
|
||||
def __str__(self) -> str: ...
|
||||
def keys(self) -> dict_keys: ...
|
||||
@ -80,6 +87,9 @@ class Dict:
|
||||
def __contains__(self, val: any) -> int:
|
||||
""" support val in dict """
|
||||
|
||||
def update(self, other: Dict):
|
||||
""" update dict """
|
||||
|
||||
|
||||
class dict_keys:
|
||||
def __iter__(self) -> any: ...
|
||||
@ -101,12 +111,16 @@ class String:
|
||||
def get(self) -> str: ...
|
||||
def __iter__(self) -> any: ...
|
||||
def __next__(self) -> any: ...
|
||||
# support string[] = val
|
||||
def __setitem__(self, __key: any, __val: any): ...
|
||||
# support val = string[]
|
||||
def __getitem__(self, __key: any) -> any: ...
|
||||
# support str()
|
||||
def __str__(self) -> str: ...
|
||||
|
||||
def __setitem__(self, __key: any, __val: any):
|
||||
""" support string[] = val """
|
||||
|
||||
def __getitem__(self, __key: any) -> any:
|
||||
""" support val = string[] """
|
||||
|
||||
def __str__(self) -> str:
|
||||
""" support str() """
|
||||
|
||||
def __len__(self) -> int: ...
|
||||
def encode(self, *encoding) -> bytes: ...
|
||||
def startswith(self, prefix: str) -> int: ...
|
||||
@ -122,14 +136,18 @@ class String:
|
||||
|
||||
|
||||
class ByteArray:
|
||||
# convert a string to ByteArray
|
||||
def __init__(self, bytes: any): ...
|
||||
# support for loop
|
||||
def __iter__(self) -> any: ...
|
||||
# support for loop
|
||||
def __next__(self) -> any: ...
|
||||
# support [] index
|
||||
def __getitem__(self, __key: int) -> int: ...
|
||||
def __init__(self, bytes: any):
|
||||
""" convert a bytes to ByteArray """
|
||||
|
||||
def __iter__(self) -> any:
|
||||
""" support for loop """
|
||||
|
||||
def __next__(self) -> any:
|
||||
""" support for loop """
|
||||
|
||||
def __getitem__(self, __key: int) -> int:
|
||||
""" support [] index """
|
||||
|
||||
def __setitem__(self, __key: int, __val: int): ...
|
||||
def __str__(self) -> str: ...
|
||||
def decode(self) -> str: ...
|
||||
@ -148,5 +166,5 @@ class FILEIO:
|
||||
|
||||
|
||||
class Utils:
|
||||
# convert a int to bytes
|
||||
def int_to_bytes(self, val: int) -> bytes: ...
|
||||
def int_to_bytes(self, val: int) -> bytes:
|
||||
""" convert a int to bytes """
|
||||
|
@ -254,3 +254,38 @@ char* PikaStdData_dict_items___str__(PikaObj* self) {
|
||||
arg_deinit(str_arg);
|
||||
return obj_getStr(self, "_buf");
|
||||
}
|
||||
|
||||
void PikaStdData_Dict_update(PikaObj* self, PikaObj* other) {
|
||||
PikaObj* context = newNormalObj(New_PikaStdLib_SysObj);
|
||||
obj_setRef(context, "@other", other);
|
||||
obj_setRef(context, "@self", self);
|
||||
/* clang-format off */
|
||||
PIKA_PYTHON(
|
||||
for @item in @other:
|
||||
@self[@item] = @other[@item]
|
||||
|
||||
)
|
||||
/* clang-format on */
|
||||
const uint8_t
|
||||
bytes[] =
|
||||
{
|
||||
0x40, 0x00, /* instruct array size */
|
||||
0x10, 0x81, 0x01, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x04,
|
||||
0x0d, 0x00, 0x00, 0x82, 0x11, 0x00, 0x00, 0x04, 0x1e, 0x00,
|
||||
0x00, 0x0d, 0x1e, 0x00, 0x00, 0x07, 0x24, 0x00, 0x11, 0x81,
|
||||
0x26, 0x00, 0x11, 0x01, 0x1e, 0x00, 0x21, 0x01, 0x01, 0x00,
|
||||
0x21, 0x01, 0x1e, 0x00, 0x11, 0x1d, 0x00, 0x00, 0x01, 0x02,
|
||||
0x2c, 0x00, 0x01, 0x04, 0x26, 0x00, 0x00, 0x86, 0x38, 0x00,
|
||||
0x00, 0x8c, 0x0d, 0x00, /* instruct array */
|
||||
0x3b, 0x00, /* const pool size */
|
||||
0x00, 0x40, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x00, 0x69, 0x74,
|
||||
0x65, 0x72, 0x00, 0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30,
|
||||
0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00,
|
||||
0x40, 0x69, 0x74, 0x65, 0x6d, 0x00, 0x32, 0x00, 0x40, 0x73,
|
||||
0x65, 0x6c, 0x66, 0x00, 0x5f, 0x5f, 0x73, 0x65, 0x74, 0x69,
|
||||
0x74, 0x65, 0x6d, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const
|
||||
pool */
|
||||
};
|
||||
pikaVM_runByteCode(context, (uint8_t*)bytes);
|
||||
obj_deinit(context);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class SysObj:
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
|
||||
def dict() -> any: ...
|
||||
def dict(*val) -> any: ...
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
|
@ -341,7 +341,7 @@ Arg* PikaStdLib_SysObj_list(PikaObj* self, PikaTuple* val) {
|
||||
return arg_newNull();
|
||||
}
|
||||
|
||||
Arg* PikaStdLib_SysObj_dict(PikaObj* self) {
|
||||
Arg* PikaStdLib_SysObj_dict(PikaObj *self, PikaTuple* val){
|
||||
#if PIKA_BUILTIN_STRUCT_ENABLE
|
||||
PikaObj* New_PikaStdData_Dict(Args * args);
|
||||
return arg_newDirectObj(New_PikaStdData_Dict);
|
||||
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
// "--gtest_filter=proxy.test1"
|
||||
// "--gtest_filter=stddata.dict_update"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -1,4 +1,4 @@
|
||||
#define PIKA_STACK_BUFF_SIZE 1024 * 10
|
||||
#define PIKA_POOL_ENABLE 1
|
||||
#define PIKA_POOL_SIZE 1024 * 1024
|
||||
#define PIKA_POOL_SIZE 1024 * 1024 * 10
|
||||
#define PIKA_ASSERT_ENABLE 1
|
@ -58,19 +58,26 @@ class List(Tuple):
|
||||
|
||||
|
||||
class Dict:
|
||||
def __init__(self): ...
|
||||
# get an arg by the key
|
||||
def __init__(self):
|
||||
""" get an arg by the key """
|
||||
|
||||
def get(self, key: str) -> any: ...
|
||||
# set an arg by the key
|
||||
def set(self, key: str, arg: any): ...
|
||||
# remove an arg by the key
|
||||
def remove(self, key: str): ...
|
||||
|
||||
def set(self, key: str, arg: any):
|
||||
""" set an arg by the key """
|
||||
|
||||
def remove(self, key: str):
|
||||
""" remove an arg by the key """
|
||||
|
||||
def __iter__(self) -> any: ...
|
||||
def __next__(self) -> any: ...
|
||||
# support dict[] = val
|
||||
def __setitem__(self, __key: any, __val: any): ...
|
||||
# support val = dict[]
|
||||
def __getitem__(self, __key: any) -> any: ...
|
||||
|
||||
def __setitem__(self, __key: any, __val: any):
|
||||
""" support dict[] = val """
|
||||
|
||||
def __getitem__(self, __key: any) -> any:
|
||||
""" support val = dict[] """
|
||||
|
||||
def __del__(self): ...
|
||||
def __str__(self) -> str: ...
|
||||
def keys(self) -> dict_keys: ...
|
||||
@ -80,6 +87,9 @@ class Dict:
|
||||
def __contains__(self, val: any) -> int:
|
||||
""" support val in dict """
|
||||
|
||||
def update(self, other: Dict):
|
||||
""" update dict """
|
||||
|
||||
|
||||
class dict_keys:
|
||||
def __iter__(self) -> any: ...
|
||||
@ -101,12 +111,16 @@ class String:
|
||||
def get(self) -> str: ...
|
||||
def __iter__(self) -> any: ...
|
||||
def __next__(self) -> any: ...
|
||||
# support string[] = val
|
||||
def __setitem__(self, __key: any, __val: any): ...
|
||||
# support val = string[]
|
||||
def __getitem__(self, __key: any) -> any: ...
|
||||
# support str()
|
||||
def __str__(self) -> str: ...
|
||||
|
||||
def __setitem__(self, __key: any, __val: any):
|
||||
""" support string[] = val """
|
||||
|
||||
def __getitem__(self, __key: any) -> any:
|
||||
""" support val = string[] """
|
||||
|
||||
def __str__(self) -> str:
|
||||
""" support str() """
|
||||
|
||||
def __len__(self) -> int: ...
|
||||
def encode(self, *encoding) -> bytes: ...
|
||||
def startswith(self, prefix: str) -> int: ...
|
||||
@ -122,14 +136,18 @@ class String:
|
||||
|
||||
|
||||
class ByteArray:
|
||||
# convert a string to ByteArray
|
||||
def __init__(self, bytes: any): ...
|
||||
# support for loop
|
||||
def __iter__(self) -> any: ...
|
||||
# support for loop
|
||||
def __next__(self) -> any: ...
|
||||
# support [] index
|
||||
def __getitem__(self, __key: int) -> int: ...
|
||||
def __init__(self, bytes: any):
|
||||
""" convert a bytes to ByteArray """
|
||||
|
||||
def __iter__(self) -> any:
|
||||
""" support for loop """
|
||||
|
||||
def __next__(self) -> any:
|
||||
""" support for loop """
|
||||
|
||||
def __getitem__(self, __key: int) -> int:
|
||||
""" support [] index """
|
||||
|
||||
def __setitem__(self, __key: int, __val: int): ...
|
||||
def __str__(self) -> str: ...
|
||||
def decode(self) -> str: ...
|
||||
@ -148,5 +166,5 @@ class FILEIO:
|
||||
|
||||
|
||||
class Utils:
|
||||
# convert a int to bytes
|
||||
def int_to_bytes(self, val: int) -> bytes: ...
|
||||
def int_to_bytes(self, val: int) -> bytes:
|
||||
""" convert a int to bytes """
|
||||
|
@ -57,7 +57,7 @@ class SysObj:
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("PIKA_BUILTIN_STRUCT_ENABLE")
|
||||
def dict() -> any: ...
|
||||
def dict(*val) -> any: ...
|
||||
|
||||
@staticmethod
|
||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||
|
@ -254,3 +254,38 @@ char* PikaStdData_dict_items___str__(PikaObj* self) {
|
||||
arg_deinit(str_arg);
|
||||
return obj_getStr(self, "_buf");
|
||||
}
|
||||
|
||||
void PikaStdData_Dict_update(PikaObj* self, PikaObj* other) {
|
||||
PikaObj* context = newNormalObj(New_PikaStdLib_SysObj);
|
||||
obj_setRef(context, "@other", other);
|
||||
obj_setRef(context, "@self", self);
|
||||
/* clang-format off */
|
||||
PIKA_PYTHON(
|
||||
for @item in @other:
|
||||
@self[@item] = @other[@item]
|
||||
|
||||
)
|
||||
/* clang-format on */
|
||||
const uint8_t
|
||||
bytes[] =
|
||||
{
|
||||
0x40, 0x00, /* instruct array size */
|
||||
0x10, 0x81, 0x01, 0x00, 0x00, 0x02, 0x08, 0x00, 0x00, 0x04,
|
||||
0x0d, 0x00, 0x00, 0x82, 0x11, 0x00, 0x00, 0x04, 0x1e, 0x00,
|
||||
0x00, 0x0d, 0x1e, 0x00, 0x00, 0x07, 0x24, 0x00, 0x11, 0x81,
|
||||
0x26, 0x00, 0x11, 0x01, 0x1e, 0x00, 0x21, 0x01, 0x01, 0x00,
|
||||
0x21, 0x01, 0x1e, 0x00, 0x11, 0x1d, 0x00, 0x00, 0x01, 0x02,
|
||||
0x2c, 0x00, 0x01, 0x04, 0x26, 0x00, 0x00, 0x86, 0x38, 0x00,
|
||||
0x00, 0x8c, 0x0d, 0x00, /* instruct array */
|
||||
0x3b, 0x00, /* const pool size */
|
||||
0x00, 0x40, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x00, 0x69, 0x74,
|
||||
0x65, 0x72, 0x00, 0x24, 0x6c, 0x30, 0x00, 0x24, 0x6c, 0x30,
|
||||
0x2e, 0x5f, 0x5f, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x5f, 0x00,
|
||||
0x40, 0x69, 0x74, 0x65, 0x6d, 0x00, 0x32, 0x00, 0x40, 0x73,
|
||||
0x65, 0x6c, 0x66, 0x00, 0x5f, 0x5f, 0x73, 0x65, 0x74, 0x69,
|
||||
0x74, 0x65, 0x6d, 0x5f, 0x5f, 0x00, 0x2d, 0x31, 0x00, /* const
|
||||
pool */
|
||||
};
|
||||
pikaVM_runByteCode(context, (uint8_t*)bytes);
|
||||
obj_deinit(context);
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ Arg* PikaStdLib_SysObj_list(PikaObj* self, PikaTuple* val) {
|
||||
return arg_newNull();
|
||||
}
|
||||
|
||||
Arg* PikaStdLib_SysObj_dict(PikaObj* self) {
|
||||
Arg* PikaStdLib_SysObj_dict(PikaObj *self, PikaTuple* val){
|
||||
#if PIKA_BUILTIN_STRUCT_ENABLE
|
||||
PikaObj* New_PikaStdData_Dict(Args * args);
|
||||
return arg_newDirectObj(New_PikaStdData_Dict);
|
||||
|
@ -5,7 +5,7 @@ FLAG_NOTE="\033[35m[Note]\033[0m"
|
||||
|
||||
cp package/pikascript/pikascript-core/* ../../src -r
|
||||
cp package/pikascript/PikaObj.pyi ../../src
|
||||
git add ../../test/python/*.py
|
||||
git add $(find ../../test/python -name '*.py')
|
||||
sh std_push.sh PikaStdLib
|
||||
sh std_push.sh PikaStdData
|
||||
sh std_push.sh PikaDebug
|
||||
|
@ -1938,4 +1938,21 @@ TEST(vm, issue_dict_update) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(vm, issue_big_dict_update) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
extern unsigned char pikaModules_py_a[];
|
||||
obj_linkLibrary(pikaMain, pikaModules_py_a);
|
||||
/* run */
|
||||
__platform_printf("BEGIN\r\n");
|
||||
pikaVM_runSingleFile(pikaMain,
|
||||
"test/python/issue/issue_big_dict_update.py");
|
||||
/* collect */
|
||||
/* assert */
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -640,3 +640,12 @@ TEST(compiler, setattr) {
|
||||
Parser_linesToArray(lines);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(compiler, dict_update) {
|
||||
char* lines =
|
||||
"for @item in @other:\n"
|
||||
" @self[@item] = @other[@item]\n"
|
||||
;
|
||||
Parser_linesToArray(lines);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
12
test/python/issue/issue_big_dict_update.py
Normal file
12
test/python/issue/issue_big_dict_update.py
Normal file
@ -0,0 +1,12 @@
|
||||
nodes = dict({})
|
||||
nodes.update({'widget0':{"type":"div","attributes":{"class":"container","style":{"width":240,"height":240,"margin":0,"padding":0,"border-radius":0,"border-width":0,"border-color":"red","background-color":37864}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"result-text","style":{"top":5,"left":5,"width":220,"text-align":"right","height":30,"color":"white","text-overflow":"longbreak","border-width":0,"border-color":"red","background-color":"transparent"}},"nodes":[],"bindings":[{"attrName":"text","key":"result","isText":True}],"events":[],"value":"0","widgetName":"widget1"},{"type":"div","attributes":{"class":"key-wrapper","onclick":"onclick","style":{"width":60,"height":50,"border-width":0,"border-color":"red","background-color":"transparent","top":40,"left":10}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"1","widgetName":"widget3"}],"bindings":[],"events":[{"onclick":"onclick"}],"widgetName":"widget2"},{"type":"div","attributes":{"class":"key-wrapper","onclick":"onclick","style":{"width":60,"height":50,"border-width":0,"border-color":"red","background-color":"transparent","top":40,"left":60}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"2","widgetName":"widget5"}],"bindings":[],"events":[{"onclick":"onclick"}],"widgetName":"widget4"},{"type":"div","attributes":{"class":"key-wrapper","onclick":"onclick","style":{"width":60,"height":50,"border-width":0,"border-color":"red","background-color":"transparent","top":40,"left":110}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"3","widgetName":"widget7"}],"bindings":[],"events":[{"onclick":"onclick"}],"widgetName":"widget6"},{"type":"div","attributes":{"class":"key-wrapper","onclick":"onclick","style":{"width":60,"height":50,"border-width":0,"border-color":"red","background-color":"transparent","top":40,"left":160}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"+","widgetName":"widget9"}],"bindings":[],"events":[{"onclick":"onclick"}],"widgetName":"widget8"}],"bindings":[],"events":[],"widgetName":"widget0"}})
|
||||
nodes.update({'widget1':{"type":"text","attributes":{"font-size":"30","class":"result-text","style":{"top":5,"left":5,"width":220,"text-align":"right","height":30,"color":"white","text-overflow":"longbreak","border-width":0,"border-color":"red","background-color":"transparent"}},"nodes":[],"bindings":[{"attrName":"text","key":"result","isText":True}],"events":[],"value":"0","widgetName":"widget1"}})
|
||||
nodes.update({'widget2':{"type":"div","attributes":{"class":"key-wrapper","onclick":"onclick","style":{"width":60,"height":50,"border-width":0,"border-color":"red","background-color":"transparent","top":40,"left":10}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"1","widgetName":"widget3"}],"bindings":[],"events":[{"onclick":"onclick"}],"widgetName":"widget2"}})
|
||||
nodes.update({'widget3':{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"1","widgetName":"widget3"}})
|
||||
nodes.update({'widget4':{"type":"div","attributes":{"class":"key-wrapper","onclick":"onclick","style":{"width":60,"height":50,"border-width":0,"border-color":"red","background-color":"transparent","top":40,"left":60}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"2","widgetName":"widget5"}],"bindings":[],"events":[{"onclick":"onclick"}],"widgetName":"widget4"}})
|
||||
nodes.update({'widget5':{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"2","widgetName":"widget5"}})
|
||||
nodes.update({'widget6':{"type":"div","attributes":{"class":"key-wrapper","onclick":"onclick","style":{"width":60,"height":50,"border-width":0,"border-color":"red","background-color":"transparent","top":40,"left":110}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"3","widgetName":"widget7"}],"bindings":[],"events":[{"onclick":"onclick"}],"widgetName":"widget6"}})
|
||||
nodes.update({'widget7':{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"3","widgetName":"widget7"}})
|
||||
nodes.update({'widget8':{"type":"div","attributes":{"class":"key-wrapper","onclick":"onclick","style":{"width":60,"height":50,"border-width":0,"border-color":"red","background-color":"transparent","top":40,"left":160}},"nodes":[{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"+","widgetName":"widget9"}],"bindings":[],"events":[{"onclick":"onclick"}],"widgetName":"widget8"}})
|
||||
nodes.update({'widget9':{"type":"text","attributes":{"font-size":"30","class":"key","style":{"left":0,"top":0,"width":50,"height":40,"margin":0,"padding":0,"color":"white","font-size":30,"text-align":"center","background-color":"transparent"}},"nodes":[],"bindings":[],"events":[],"value":"+","widgetName":"widget9"}})
|
||||
print(nodes)
|
@ -1,4 +1,6 @@
|
||||
import PikaStdLib
|
||||
nodes = {"type": "div", "attributes": {"class": "container", "style": {"width": 240, "height": 240, "margin": 0, "padding": 0, "border-radius": 0, "border-width": 0, "border-color": "red", "background-color": 37864}}, "nodes": [{"type": "text", "attributes": {"font-size": "30", "class": "result-text", "style": {"top": 5, "left": 5, "width": 220, "text-align": "right", "height": 30, "color": "white", "text-overflow": "longbreak", "border-width": 0, "border-color": "red", "background-color": "transparent"}}, "nodes": [], "bindings":[{"attrName": "text", "key": "result", "isText": True}], "events": [], "value":"0", "widgetName":"widget1"}, {"type": "div", "attributes": {"class": "key-wrapper", "onclick": "onclick", "style": {"width": 60, "height": 50, "border-width": 0, "border-color": "red", "background-color": "transparent", "top": 40, "left": 10}}, "nodes": [{"type": "text", "attributes": {"font-size": "30", "class": "key", "style": {"left": 0, "top": 0, "width": 50, "height": 40, "margin": 0, "padding": 0, "color": "white", "font-size": 30, "text-align": "center", "background-color": "transparent"}}, "nodes": [], "bindings":[], "events":[], "value":"1", "widgetName":"widget3"}], "bindings":[], "events":[{"onclick": "onclick"}], "widgetName": "widget2"}, {"type": "div", "attributes": {"class": "key-wrapper", "onclick": "onclick", "style": {"width": 60, "height": 50, "border-width": 0, "border-color": "red", "background-color": "transparent", "top": 40, "left": 60}}, "nodes": [{"type": "text", "attributes": {"font-size": "30", "class": "key", "style": {
|
||||
"left": 0, "top": 0, "width": 50, "height": 40, "margin": 0, "padding": 0, "color": "white", "font-size": 30, "text-align": "center", "background-color": "transparent"}}, "nodes": [], "bindings":[], "events":[], "value":"2", "widgetName":"widget5"}], "bindings":[], "events":[{"onclick": "onclick"}], "widgetName": "widget4"}, {"type": "div", "attributes": {"class": "key-wrapper", "onclick": "onclick", "style": {"width": 60, "height": 50, "border-width": 0, "border-color": "red", "background-color": "transparent", "top": 40, "left": 110}}, "nodes": [{"type": "text", "attributes": {"font-size": "30", "class": "key", "style": {"left": 0, "top": 0, "width": 50, "height": 40, "margin": 0, "padding": 0, "color": "white", "font-size": 30, "text-align": "center", "background-color": "transparent"}}, "nodes": [], "bindings":[], "events":[], "value":"3", "widgetName":"widget7"}], "bindings":[], "events":[{"onclick": "onclick"}], "widgetName": "widget6"}, {"type": "div", "attributes": {"class": "key-wrapper", "onclick": "onclick", "style": {"width": 60, "height": 50, "border-width": 0, "border-color": "red", "background-color": "transparent", "top": 40, "left": 160}}, "nodes": [{"type": "text", "attributes": {"font-size": "30", "class": "key", "style": {"left": 0, "top": 0, "width": 50, "height": 40, "margin": 0, "padding": 0, "color": "white", "font-size": 30, "text-align": "center", "background-color": "transparent"}}, "nodes": [], "bindings":[], "events":[], "value":"+", "widgetName":"widget9"}], "bindings":[], "events":[{"onclick": "onclick"}], "widgetName": "widget8"}], "bindings": [], "events": [], "widgetName": "widget0"}
|
||||
print(nodes)
|
||||
inner = nodes['nodes'][2]['nodes'][0]['widgetName']
|
||||
PikaStdLib.MemChecker().max()
|
||||
|
@ -373,4 +373,25 @@ TEST(stddata, list_insert_) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(stddata, dict_update) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
/* run */
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(pikaMain,
|
||||
"d = {'a':1, 'b':2, 'c':3}\n"
|
||||
"d.update({'b':4, 'd':5})\n"
|
||||
"res1 = d['b']\n"
|
||||
"res2 = d['a']\n"
|
||||
"print(d)\n");
|
||||
/* collect */
|
||||
/* assert */
|
||||
EXPECT_EQ(obj_getInt(pikaMain, "res1"), 4);
|
||||
EXPECT_EQ(obj_getInt(pikaMain, "res2"), 1);
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user