mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
support s[2] = 'q'
This commit is contained in:
parent
5b8a41f0d5
commit
8894e270f3
@ -43,7 +43,7 @@ class SysObj(BaseObj):
|
|||||||
def range(a1: int, a2: int, a3: int) -> any:
|
def range(a1: int, a2: int, a3: int) -> any:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __set__(obj: any, key: any, val: any):
|
def __set__(obj: any, key: any, val: any, obj_str: str):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __get__(obj: any, key: any) -> any:
|
def __get__(obj: any, key: any) -> any:
|
||||||
|
@ -160,13 +160,18 @@ Arg* PikaStdLib_SysObj___get__(PikaObj* self, Arg* key, Arg* obj) {
|
|||||||
return arg_setNull(NULL);
|
return arg_setNull(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PikaStdLib_SysObj___set__(PikaObj* self, Arg* key, Arg* obj, Arg* val) {
|
void PikaStdLib_SysObj___set__(PikaObj* self,
|
||||||
|
Arg* key,
|
||||||
|
Arg* obj,
|
||||||
|
char* obj_str,
|
||||||
|
Arg* val) {
|
||||||
ArgType obj_type = arg_getType(obj);
|
ArgType obj_type = arg_getType(obj);
|
||||||
if (TYPE_STRING == obj_type) {
|
if (TYPE_STRING == obj_type) {
|
||||||
int index = arg_getInt(key);
|
int index = arg_getInt(key);
|
||||||
char* str_val = arg_getStr(val);
|
char* str_val = arg_getStr(val);
|
||||||
char* str_pyload = arg_getStr(obj);
|
char* str_pyload = arg_getStr(obj);
|
||||||
str_pyload[index] = str_val[0];
|
str_pyload[index] = str_val[0];
|
||||||
|
obj_setStr(self, obj_str, str_pyload);
|
||||||
}
|
}
|
||||||
if ((TYPE_OBJECT == obj_type) || (TYPE_POINTER == obj_type)) {
|
if ((TYPE_OBJECT == obj_type) || (TYPE_POINTER == obj_type)) {
|
||||||
PikaObj* arg_obj = arg_getPtr(obj);
|
PikaObj* arg_obj = arg_getPtr(obj);
|
||||||
|
@ -1881,6 +1881,7 @@ TEST(parser, __set__) {
|
|||||||
"1 REF a\n"
|
"1 REF a\n"
|
||||||
"1 REF b\n"
|
"1 REF b\n"
|
||||||
"1 REF c\n"
|
"1 REF c\n"
|
||||||
|
"1 STR a\n"
|
||||||
"0 RUN __set__\n"
|
"0 RUN __set__\n"
|
||||||
);
|
);
|
||||||
args_deinit(buffs);
|
args_deinit(buffs);
|
||||||
|
@ -782,7 +782,7 @@ TEST(pikaMain, dict__set__get) {
|
|||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(pikaMain, str___get__) {
|
TEST(pikaMain, str___get____set__) {
|
||||||
/* init */
|
/* init */
|
||||||
pikaMemInfo.heapUsedMax = 0;
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||||
@ -791,7 +791,7 @@ TEST(pikaMain, str___get__) {
|
|||||||
obj_run(pikaMain, (char*)
|
obj_run(pikaMain, (char*)
|
||||||
"s = 'test'\n"
|
"s = 'test'\n"
|
||||||
"res = __get__(s, 2)\n"
|
"res = __get__(s, 2)\n"
|
||||||
"__set__(s, 2, 'q')\n"
|
"__set__(s, 2, 'q', 's')\n"
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
/* collect */
|
/* collect */
|
||||||
@ -799,7 +799,7 @@ TEST(pikaMain, str___get__) {
|
|||||||
char* s= obj_getStr(pikaMain, (char*)"s");
|
char* s= obj_getStr(pikaMain, (char*)"s");
|
||||||
/* assert */
|
/* assert */
|
||||||
EXPECT_STREQ(res, (char*)"s");
|
EXPECT_STREQ(res, (char*)"s");
|
||||||
// EXPECT_STREQ(s, (char*)"teqt");
|
EXPECT_STREQ(s, (char*)"teqt");
|
||||||
/* deinit */
|
/* deinit */
|
||||||
obj_deinit(pikaMain);
|
obj_deinit(pikaMain);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
@ -814,12 +814,18 @@ TEST(pikaMain, str__index__) {
|
|||||||
obj_run(pikaMain, (char*)
|
obj_run(pikaMain, (char*)
|
||||||
"s = 'test'\n"
|
"s = 'test'\n"
|
||||||
"res = s[2]\n"
|
"res = s[2]\n"
|
||||||
|
"res2 = 'eqrt'[2]\n"
|
||||||
|
"s[2] = 'q'\n"
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
/* collect */
|
/* collect */
|
||||||
char* res = obj_getStr(pikaMain, (char*)"res");
|
char* res = obj_getStr(pikaMain, (char*)"res");
|
||||||
|
char* res2 = obj_getStr(pikaMain, (char*)"res2");
|
||||||
|
char* s = obj_getStr(pikaMain, (char*)"s");
|
||||||
/* assert */
|
/* assert */
|
||||||
EXPECT_STREQ(res, (char*)"s");
|
EXPECT_STREQ(res, (char*)"s");
|
||||||
|
EXPECT_STREQ(res2, (char*)"r");
|
||||||
|
EXPECT_STREQ(s, (char*)"teqt");
|
||||||
// EXPECT_STREQ(s, (char*)"teqt");
|
// EXPECT_STREQ(s, (char*)"teqt");
|
||||||
/* deinit */
|
/* deinit */
|
||||||
obj_deinit(pikaMain);
|
obj_deinit(pikaMain);
|
||||||
|
@ -661,6 +661,11 @@ char* Parser_solveBranckets(Args* outBuffs,
|
|||||||
if (strEqu(mode, "left")) {
|
if (strEqu(mode, "left")) {
|
||||||
right_arg = arg_strAppend(right_arg, ",");
|
right_arg = arg_strAppend(right_arg, ",");
|
||||||
right_arg = arg_strAppend(right_arg, stmt);
|
right_arg = arg_strAppend(right_arg, stmt);
|
||||||
|
right_arg = arg_strAppend(right_arg, ",");
|
||||||
|
right_arg = arg_strAppend(right_arg, "'");
|
||||||
|
right_arg =
|
||||||
|
arg_strAppend(right_arg, args_getStr(buffs, "obj"));
|
||||||
|
right_arg = arg_strAppend(right_arg, "'");
|
||||||
}
|
}
|
||||||
right_arg = arg_strAppend(right_arg, ")");
|
right_arg = arg_strAppend(right_arg, ")");
|
||||||
args_setStr(buffs, "index", "");
|
args_setStr(buffs, "index", "");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user