use name hash and tested ok

This commit is contained in:
lyon 2021-11-13 18:48:47 +08:00
parent 5f0d7a9d31
commit ba938176c1
8 changed files with 40 additions and 85 deletions

View File

@ -11,9 +11,14 @@
"program": "${workspaceFolder}/build/test/pikascript_test",
// "program": "${workspaceFolder}/../build/src/boot/demo06-pikamain/pikascript_demo06-pikamain",
"args": [
// "--gtest_filter=queueObj.currentObj"
// "--gtest_filter=queue*"
// "--gtest_filter=parser*"
// "--gtest_filter=VM.RUN_local_b"
// "--gtest_filter=args*",
// "--gtest_filter=content*",
// "--gtest_filter=object_test.printa",
"--gtest_filter=object_test*",
// "--gtest_filter=stack*",
// "--gtest_filter=strs*",
// "--gtest_filter=block.ifrun2"
// "--gtest_filter=sysObj.print"
// "--gtest_filter=object_test.a_b"

View File

@ -15,8 +15,5 @@ class SysObj(BaseObj):
def type(argPath: str):
pass
def ls(objPath: str):
pass
def remove(argPath: str):
pass

View File

@ -1,56 +1,6 @@
#include "BaseObj.h"
#include "dataStrs.h"
static int32_t __foreach_listEachArg(Arg* argEach, Args* handleArgs) {
Args* buffs = handleArgs;
if (NULL == handleArgs) {
/* error: not handleArgs input */
return 1;
}
char* argName = strsCopy(buffs, arg_getNameHash(argEach));
if (strIsStartWith(argName, "[")) {
/* skip */
return 0;
}
char* stringOut = args_getStr(handleArgs, "stringOut");
if (NULL == stringOut) {
// stringOut no found
return 1;
}
stringOut = strsAppend(buffs, stringOut, argName);
stringOut = strsAppend(buffs, stringOut, " ");
args_setStr(handleArgs, "stringOut", stringOut);
return 0;
}
void PikaStdLib_SysObj_ls(PikaObj* self, char* objPath) {
obj_setErrorCode(self, 0);
Args* args = New_args(NULL);
args_setStr(args, "stringOut", "");
obj_setSysOut(self, "");
if (NULL == objPath) {
/* no input obj path, use current obj */
args_foreach(self->attributeList, __foreach_listEachArg, args);
obj_setSysOut(self, args_getStr(args, "stringOut"));
goto exit;
}
PikaObj* obj = obj_getObj(self, objPath, 0);
if (NULL == obj) {
/* do not find obj */
obj_setSysOut(self, "[error] list: object no found.");
obj_setErrorCode(self, 1);
goto exit;
}
/* list args */
args_foreach(obj->attributeList, __foreach_listEachArg, args);
obj_setSysOut(self, args_getStr(args, "stringOut"));
exit:
args_deinit(args);
}
void PikaStdLib_SysObj_remove(PikaObj* self, char* argPath) {
obj_setErrorCode(self, 0);
int32_t res = obj_removeArg(self, argPath);

View File

@ -73,7 +73,7 @@ TEST(content, set) {
ASSERT_EQ(content[3], 4);
ASSERT_EQ(totleSize, 24);
ASSERT_EQ(hash_time33("name"), nameHash);
ASSERT_EQ(hash_time33((char *)"name"), nameHash);
ASSERT_STREQ("type", type);
content_deinit(self);

View File

@ -416,7 +416,8 @@ int32_t obj_removeArg(PikaObj* self, char* argPath) {
goto exit;
}
char* argName = strsGetLastToken(buffs, argPath, '.');
int32_t res = args_removeArg(objHost->attributeList, argName);
int32_t res = args_removeArg(objHost->attributeList,
args_getArg(objHost->attributeList, argName));
if (1 == res) {
/*[error] not found arg*/
err = 2;

View File

@ -433,7 +433,8 @@ int32_t __clearInvokeQueues(Parameters* locals) {
Queue* queue = (Queue*)args_getPtr(locals->attributeList, deepth);
if (NULL != queue) {
args_deinit(queue);
args_removeArg(locals->attributeList, deepth);
args_removeArg(locals->attributeList,
args_getArg(locals->attributeList, deepth));
}
}
return 0;

View File

@ -11,25 +11,26 @@
#include "dataArgs.h"
static uint16_t const str100p[100] = {
0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730, 0x3830, 0x3930,
0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731, 0x3831, 0x3931,
0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632, 0x3732, 0x3832, 0x3932,
0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533, 0x3633, 0x3733, 0x3833, 0x3933,
0x3034, 0x3134, 0x3234, 0x3334, 0x3434, 0x3534, 0x3634, 0x3734, 0x3834, 0x3934,
0x3035, 0x3135, 0x3235, 0x3335, 0x3435, 0x3535, 0x3635, 0x3735, 0x3835, 0x3935,
0x3036, 0x3136, 0x3236, 0x3336, 0x3436, 0x3536, 0x3636, 0x3736, 0x3836, 0x3936,
0x3037, 0x3137, 0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737, 0x3837, 0x3937,
0x3038, 0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738, 0x3838, 0x3938,
0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739, 0x3839, 0x3939, };
0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730, 0x3830,
0x3930, 0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731,
0x3831, 0x3931, 0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632,
0x3732, 0x3832, 0x3932, 0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533,
0x3633, 0x3733, 0x3833, 0x3933, 0x3034, 0x3134, 0x3234, 0x3334, 0x3434,
0x3534, 0x3634, 0x3734, 0x3834, 0x3934, 0x3035, 0x3135, 0x3235, 0x3335,
0x3435, 0x3535, 0x3635, 0x3735, 0x3835, 0x3935, 0x3036, 0x3136, 0x3236,
0x3336, 0x3436, 0x3536, 0x3636, 0x3736, 0x3836, 0x3936, 0x3037, 0x3137,
0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737, 0x3837, 0x3937, 0x3038,
0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738, 0x3838, 0x3938,
0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739, 0x3839,
0x3939,
};
char *fast_itoa(char *buf, uint32_t val)
{
char *p = &buf[10];
char* fast_itoa(char* buf, uint32_t val) {
char* p = &buf[10];
*p = '\0';
while(val >= 100)
{
while (val >= 100) {
uint32_t const old = val;
p -= 2;
@ -61,7 +62,7 @@ int32_t queue_pushInt(Queue* queue, int val) {
Args* args = queue;
uint64_t top = args_getInt(args, "top");
char buff[11];
char *topStr = fast_itoa(buff, top);
char* topStr = fast_itoa(buff, top);
/* add top */
args_setInt(args, "top", top + 1);
return args_setInt(args, topStr, val);
@ -71,11 +72,11 @@ int64_t queue_popInt(Queue* queue) {
Args* args = queue;
uint64_t bottom = args_getInt(args, "bottom");
char buff[11];
char *bottomStr = fast_itoa(buff, bottom);
char* bottomStr = fast_itoa(buff, bottom);
/* add bottom */
args_setInt(args, "bottom", bottom + 1);
int64_t res = args_getInt(args, bottomStr);
args_removeArg(args, bottomStr);
args_removeArg(args, args_getArg(args, bottomStr));
return res;
}
@ -83,7 +84,7 @@ int32_t queue_pushFloat(Queue* queue, float val) {
Args* args = queue;
uint64_t top = args_getInt(args, "top");
char buff[11];
char *topStr = fast_itoa(buff, top);
char* topStr = fast_itoa(buff, top);
/* add top */
args_setInt(args, "top", top + 1);
return args_setFloat(args, topStr, val);
@ -93,11 +94,11 @@ float queue_popFloat(Queue* queue) {
Args* args = queue;
uint64_t bottom = args_getInt(args, "bottom");
char buff[11];
char *bottomStr = fast_itoa(buff, bottom);
char* bottomStr = fast_itoa(buff, bottom);
/* add bottom */
args_setInt(args, "bottom", bottom + 1);
float res = args_getFloat(args, bottomStr);
args_removeArg(args, bottomStr);
args_removeArg(args, args_getArg(args, bottomStr));
return res;
}
@ -106,7 +107,7 @@ int32_t queue_pushStr(Queue* queue, char* str) {
uint64_t top = args_getInt(args, "top");
char buff[11];
/* add top */
char *topStr = fast_itoa(buff, top);
char* topStr = fast_itoa(buff, top);
args_setInt(args, "top", top + 1);
return args_setStr(args, topStr, str);
}

View File

@ -29,6 +29,6 @@ char* stack_popStr(Stack* queue, char* outBuff) {
args_setInt(args, "top", top);
char* topStr = fast_itoa(buff, top);
strcpy(outBuff, args_getStr(args, topStr));
args_removeArg(args, topStr);
args_removeArg(args, args_getArg(args, topStr));
return outBuff;
}