mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
literal is ok
This commit is contained in:
parent
769eee97e4
commit
bbe6845cde
4
src/.vscode/launch.json
vendored
4
src/.vscode/launch.json
vendored
@ -10,8 +10,8 @@
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/../build/src/test/pikascript_test",
|
||||
"args": [
|
||||
"--gtest_filter=object_test.test2"
|
||||
// "--gtest_filter=block.assert1"
|
||||
// "--gtest_filter=object_test.test2"
|
||||
"--gtest_filter=block.assert1"
|
||||
// "--gtest_filter=sysObj.print"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
|
@ -234,31 +234,7 @@ static void *getMethodPtr(PikaObj *methodHost, char *methodName)
|
||||
return res;
|
||||
}
|
||||
|
||||
static char *getCleanCmd(Args *buffs, char *cmd)
|
||||
{
|
||||
int32_t size = strGetSize(cmd);
|
||||
char *strOut = args_getBuff(buffs, size);
|
||||
int32_t iOut = 0;
|
||||
char delChar = ' ';
|
||||
int32_t isInStr = 0;
|
||||
for (int32_t i = 0; i < strGetSize(cmd); i++)
|
||||
{
|
||||
if ('\'' == cmd[i] || '\"' == cmd[i])
|
||||
{
|
||||
isInStr = !isInStr;
|
||||
}
|
||||
if ((delChar == cmd[i]) && (!isInStr))
|
||||
{
|
||||
/* do not load char */
|
||||
continue;
|
||||
}
|
||||
strOut[iOut] = cmd[i];
|
||||
iOut++;
|
||||
}
|
||||
/* add \0 */
|
||||
strOut[iOut] = 0;
|
||||
return strOut;
|
||||
}
|
||||
|
||||
|
||||
Args *obj_invoke(PikaObj *self, char *cmd)
|
||||
{
|
||||
@ -266,7 +242,7 @@ Args *obj_invoke(PikaObj *self, char *cmd)
|
||||
Args *res = New_args(NULL);
|
||||
args_setErrorCode(res, 0);
|
||||
Args *buffs = New_strBuff();
|
||||
char *cleanCmd = getCleanCmd(buffs, cmd);
|
||||
char *cleanCmd = strsGetCleanCmd(buffs, cmd);
|
||||
char *methodToken = strsGetFirstToken(buffs, cleanCmd, '(');
|
||||
char *methodPath = methodToken;
|
||||
Args *args = NULL;
|
||||
|
@ -505,14 +505,6 @@ static void transferReturnVal(PikaObj *self, char *returnType, char *returnName,
|
||||
}
|
||||
}
|
||||
|
||||
Args *getRightRes(PikaObj *self, char *cmd)
|
||||
{
|
||||
if (strIsContain(cmd, '(') && strIsContain(cmd, ')'))
|
||||
{
|
||||
return obj_invoke(self, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
char *getRightCmd(Args *buffs, char *cmd)
|
||||
{
|
||||
char *right = NULL;
|
||||
@ -534,6 +526,26 @@ char *getRightCmd(Args *buffs, char *cmd)
|
||||
return right;
|
||||
}
|
||||
|
||||
Args *getRightRes(PikaObj *self, char *cmd)
|
||||
{
|
||||
Args *buffs = New_strBuff();
|
||||
Args *res = NULL;
|
||||
if (strIsContain(cmd, '(') && strIsContain(cmd, ')'))
|
||||
{
|
||||
res = obj_invoke(self, cmd);
|
||||
goto exit;
|
||||
}
|
||||
res = New_args(NULL);
|
||||
args_setLiteral(res, "return", cmd);
|
||||
char *returnType = strsAppend(buffs, "->", args_getType(res, "return"));
|
||||
args_setStr(res, "returnType", returnType);
|
||||
goto exit;
|
||||
|
||||
exit:
|
||||
args_deinit(buffs);
|
||||
return res;
|
||||
}
|
||||
|
||||
Args *obj_runDirect(PikaObj *self, char *cmd)
|
||||
{
|
||||
Args *buffs = New_strBuff();
|
||||
@ -632,17 +644,17 @@ void obj_runNoRes(PikaObj *slef, char *cmd)
|
||||
args_deinit(obj_runDirect(slef, cmd));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void obj_run(PikaObj *self, char *cmd)
|
||||
{
|
||||
/* safe, stop when error occord and error info would be print32_t */
|
||||
Args *res = obj_runDirect(self, cmd);
|
||||
char *sysOut = args_getSysOut(res);
|
||||
if (!strEqu("", sysOut))
|
||||
if (NULL != sysOut)
|
||||
{
|
||||
printf("%s\r\n", sysOut);
|
||||
if (!strEqu("", sysOut))
|
||||
{
|
||||
printf("%s\r\n", sysOut);
|
||||
}
|
||||
}
|
||||
if (0 != args_getErrorCode(res))
|
||||
{
|
||||
|
@ -386,13 +386,17 @@ exit:
|
||||
|
||||
uint8_t args_setLiteral(Args *self, char *name, char *literal)
|
||||
{
|
||||
Args *buffs = New_strBuff();
|
||||
literal = strsGetCleanCmd(buffs, literal);
|
||||
uint8_t err = 0;
|
||||
char *directStr = strsGetDirectStr(self, literal);
|
||||
if (NULL != directStr)
|
||||
{
|
||||
/* direct string value */
|
||||
args_setStr(self, name, directStr);
|
||||
/* ok */
|
||||
return 0;
|
||||
err = 0;
|
||||
goto exit;
|
||||
}
|
||||
if ((literal[0] >= '0') && (literal[0] <= '9'))
|
||||
{
|
||||
@ -402,14 +406,20 @@ uint8_t args_setLiteral(Args *self, char *name, char *literal)
|
||||
args_setFloat(self, name, 0);
|
||||
args_set(self, name, literal);
|
||||
/* succeed */
|
||||
return 0;
|
||||
err = 0;
|
||||
goto exit;
|
||||
}
|
||||
args_setInt(self, name, 0);
|
||||
args_set(self, name, literal);
|
||||
/* succeed */
|
||||
return 0;
|
||||
err = 0;
|
||||
goto exit;
|
||||
}
|
||||
return 1;
|
||||
err = 1;
|
||||
goto exit;
|
||||
exit:
|
||||
args_deinit(buffs);
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t args_set(Args *self, char *name, char *valStr)
|
||||
|
@ -90,3 +90,29 @@ char *strsFormat(Args *buffs, uint16_t buffSize, const char *fmt, ...)
|
||||
va_end(args);
|
||||
return res;
|
||||
}
|
||||
|
||||
char *strsGetCleanCmd(Args *buffs, char *cmd)
|
||||
{
|
||||
int32_t size = strGetSize(cmd);
|
||||
char *strOut = args_getBuff(buffs, size);
|
||||
int32_t iOut = 0;
|
||||
char delChar = ' ';
|
||||
int32_t isInStr = 0;
|
||||
for (int32_t i = 0; i < strGetSize(cmd); i++)
|
||||
{
|
||||
if ('\'' == cmd[i] || '\"' == cmd[i])
|
||||
{
|
||||
isInStr = !isInStr;
|
||||
}
|
||||
if ((delChar == cmd[i]) && (!isInStr))
|
||||
{
|
||||
/* do not load char */
|
||||
continue;
|
||||
}
|
||||
strOut[iOut] = cmd[i];
|
||||
iOut++;
|
||||
}
|
||||
/* add \0 */
|
||||
strOut[iOut] = 0;
|
||||
return strOut;
|
||||
}
|
||||
|
@ -12,4 +12,5 @@ char *strsRemovePrefix(Args *buffs, char *inputStr, char *prefix);
|
||||
char *strsAppend(Args *buffs, char *strOrigin, char *strAppend);
|
||||
char *strsFormat(Args *buffs, uint16_t buffSize, const char *fmt, ...);
|
||||
char *strsGetDirectStr(Args *buffs, char *argPath);
|
||||
char *strsGetCleanCmd(Args *buffs, char *cmd);
|
||||
#endif
|
||||
|
@ -36,13 +36,13 @@ TEST(block, pop)
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
// TEST(block, assert1)
|
||||
// {
|
||||
// PikaObj *block = block_init();
|
||||
// block_setAssert(block, (char *)"1");
|
||||
// int res = block_checkAssert(block);
|
||||
// ASSERT_EQ(1, res);
|
||||
// block_deinit(block);
|
||||
// }
|
||||
TEST(block, assert1)
|
||||
{
|
||||
PikaObj *block = block_init();
|
||||
block_setAssert(block, (char *)"1");
|
||||
int res = block_checkAssert(block);
|
||||
ASSERT_EQ(1, res);
|
||||
block_deinit(block);
|
||||
}
|
||||
|
||||
void block_pushLine(PikaObj *self, char *line);
|
||||
|
@ -13,7 +13,7 @@ TEST(sysObj, print)
|
||||
char *sysOut = args_getSysOut(res);
|
||||
int errCode = args_getErrorCode(res);
|
||||
printf("sysout = %s\r\n", sysOut);
|
||||
ASSERT_EQ(1, strEqu((char *)"hello world", sysOut));
|
||||
ASSERT_STREQ((char *)"hello world", sysOut);
|
||||
ASSERT_EQ(0, errCode);
|
||||
args_deinit(res);
|
||||
obj_deinit(obj);
|
||||
|
Loading…
x
Reference in New Issue
Block a user