mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
fix parse err for kw def
fix VM typelist overflow
This commit is contained in:
parent
244d196ef3
commit
7d90370d4c
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=network.get"
|
||||
"--gtest_filter=vm.class_keyword_mqtt"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -653,6 +653,12 @@ char* methodArg_getTypeList(Arg* method_arg, char* buffs, size_t size) {
|
||||
}
|
||||
char* method_dec = methodArg_getDec(method_arg);
|
||||
pika_assert(strGetSize(method_dec) <= size);
|
||||
if (strGetSize(method_dec) > size) {
|
||||
__platform_printf(
|
||||
"OverFlowError: please use bigger PIKA_LINE_BUFF_SIZE\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
char* res = strCut(buffs, method_dec, '(', ')');
|
||||
pika_assert(NULL != res);
|
||||
return res;
|
||||
|
@ -384,6 +384,11 @@ static inline uint8_t obj_refcntNow(PikaObj* self) {
|
||||
__platform_printf("Error: abstract method `%s()` need override.\r\n", \
|
||||
__FUNCTION__)
|
||||
|
||||
#define WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_) \
|
||||
__platform_printf("Error: weak function `%s()` need override.\r\n", \
|
||||
__FUNCTION__); \
|
||||
while (1)
|
||||
|
||||
char* obj_cacheStr(PikaObj* self, char* str);
|
||||
PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp);
|
||||
char* __printBytes(PikaObj* self, Arg* arg);
|
||||
|
@ -1556,7 +1556,7 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
|
||||
uint8_t is_meet_equ = 0;
|
||||
Cursor_forEachToken(cs, stmt) {
|
||||
Cursor_iterStart(&cs);
|
||||
if (strEqu(cs.token1.pyload, "=") &&
|
||||
if (!is_meet_equ && strEqu(cs.token1.pyload, "=") &&
|
||||
cs.token1.type == TOKEN_operator) {
|
||||
is_meet_equ = 1;
|
||||
Cursor_iterEnd(&cs);
|
||||
|
@ -159,7 +159,9 @@ PIKA_WEAK char __platform_getchar(void) {
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return getchar();
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
__platform_printf("Error: __platform_getchar need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -168,7 +170,9 @@ PIKA_WEAK FILE* __platform_fopen(const char* filename, const char* modes) {
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return fopen(filename, modes);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
__platform_printf("Error: __platform_fopen need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -177,7 +181,9 @@ PIKA_WEAK int __platform_fclose(FILE* stream) {
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return fclose(stream);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
__platform_printf("Error: __platform_fclose need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -189,7 +195,9 @@ PIKA_WEAK size_t __platform_fwrite(const void* ptr,
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return fwrite(ptr, size, n, stream);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
__platform_printf("Error: __platform_fwrite need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -201,7 +209,9 @@ PIKA_WEAK size_t __platform_fread(void* ptr,
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return fread(ptr, size, n, stream);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
__platform_printf("Error: __platform_fread need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -210,7 +220,9 @@ PIKA_WEAK int __platform_fseek(FILE* stream, long offset, int whence) {
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return fseek(stream, offset, whence);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
__platform_printf("Error: __platform_fseek need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -219,7 +231,9 @@ PIKA_WEAK long __platform_ftell(FILE* stream) {
|
||||
#if defined(__linux) || defined(_WIN32)
|
||||
return ftell(stream);
|
||||
#else
|
||||
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
|
||||
__platform_printf("Error: __platform_ftell need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ uint8_t __is_locked_pikaMemory(void);
|
||||
/* support shell */
|
||||
char __platform_getchar(void);
|
||||
|
||||
/* libc file API */
|
||||
/* file API */
|
||||
FILE* __platform_fopen(const char* filename, const char* modes);
|
||||
int __platform_fclose(FILE* stream);
|
||||
size_t __platform_fwrite(const void* ptr, size_t size, size_t n, FILE* stream);
|
||||
@ -172,11 +172,6 @@ void __pks_hook_instruct(void);
|
||||
PIKA_BOOL __pks_hook_arg_cache_filter(void* self);
|
||||
PIKA_WEAK void __platform_thread_delay(void);
|
||||
|
||||
#define WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_) \
|
||||
__platform_printf("Error: weak function `%s()` need override.\r\n", \
|
||||
__FUNCTION__); \
|
||||
while (1)
|
||||
|
||||
#if PIKA_FLOAT_TYPE_DOUBLE
|
||||
#define pika_float double
|
||||
#else
|
||||
|
@ -867,7 +867,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
|
||||
int argc = 0;
|
||||
char _buffs1[PIKA_LINE_BUFF_SIZE] = {0};
|
||||
char* buffs1 = (char*)_buffs1;
|
||||
char _buffs2[PIKA_LINE_BUFF_SIZE / 2] = {0};
|
||||
char _buffs2[PIKA_LINE_BUFF_SIZE] = {0};
|
||||
char* buffs2 = (char*)_buffs2;
|
||||
uint8_t arg_num_dec = 0;
|
||||
PIKA_BOOL vars_or_keys_or_default = PIKA_FALSE;
|
||||
@ -936,6 +936,12 @@ static int VMState_loadArgsFromMethodArg(VMState* vm,
|
||||
}
|
||||
|
||||
if (vars_or_keys_or_default) {
|
||||
if (strGetSize(type_list) > sizeof(_buffs2)) {
|
||||
__platform_printf(
|
||||
"OverFlowError: please use bigger PIKA_LINE_BUFF_SIZE\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
type_list_buff = strCopy(buffs2, type_list);
|
||||
int default_num = strCountSign(type_list_buff, '=');
|
||||
variable_arg_start = 0;
|
||||
|
@ -336,14 +336,6 @@
|
||||
#define PIKA_EVENT_LIST_SIZE 16
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_LWIP_ENABLE
|
||||
#define PIKA_LWIP_ENABLE 0
|
||||
#endif
|
||||
|
||||
#ifndef PIKA_FREERTOS_ENABLE
|
||||
#define PIKA_FREERTOS_ENABLE 0
|
||||
#endif
|
||||
|
||||
/* configuration validation */
|
||||
|
||||
#endif
|
||||
|
@ -1265,6 +1265,48 @@ TEST(vm, keyword_4) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(vm, class_keyword) {
|
||||
char* line =
|
||||
"class Test:\n"
|
||||
" def __init__(self, a, b = 1, c =2):\n"
|
||||
" print(a, b, c)\n"
|
||||
"t = Test(0, b = 3)\n";
|
||||
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
|
||||
obj_run(self, line);
|
||||
/* collect */
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[0], "0 3 2\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(vm, class_keyword_mqtt) {
|
||||
char* line =
|
||||
"class MQTT:\n"
|
||||
" def __init__(self,\n"
|
||||
" ip: str,\n"
|
||||
" port=1883,\n"
|
||||
" clinetID='mac',\n"
|
||||
" username='',\n"
|
||||
" password='',\n"
|
||||
" version='3.1.1',\n"
|
||||
" ca='',\n"
|
||||
" keepalive=60):\n"
|
||||
" print('ip:', ip)\n"
|
||||
" print('port:', port)\n"
|
||||
"c = MQTT('test')\n";
|
||||
PikaObj* self = newRootObj("root", New_PikaStdLib_SysObj);
|
||||
obj_run(self, line);
|
||||
/* collect */
|
||||
/* assert */
|
||||
EXPECT_STREQ(log_buff[1], "ip: test\r\n");
|
||||
EXPECT_STREQ(log_buff[0], "port: 1883\r\n");
|
||||
/* deinit */
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(vm, vars_keyward) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
|
@ -4032,6 +4032,50 @@ TEST(parser, keyword1) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(parser, keyword_class) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
Args* buffs = New_strBuff();
|
||||
char* lines = "t = Test(0, b = 3)\n";
|
||||
__platform_printf("%s\n", lines);
|
||||
char* pikaAsm = Parser_linesToAsm(buffs, lines);
|
||||
__platform_printf("%s", pikaAsm);
|
||||
EXPECT_STREQ(pikaAsm,
|
||||
"B0\n"
|
||||
"1 NUM 0\n"
|
||||
"1 NUM 3\n"
|
||||
"1 OUT b\n"
|
||||
"0 RUN Test\n"
|
||||
"0 OUT t\n"
|
||||
"B0\n");
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(parser, keyword_class_mqtt) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
Args* buffs = New_strBuff();
|
||||
char* lines =
|
||||
"class MQTT:\n"
|
||||
" def __init__(self,\n"
|
||||
" ip: str,\n"
|
||||
" port=1883,\n"
|
||||
" clinetID='mac',\n"
|
||||
" username='',\n"
|
||||
" password='',\n"
|
||||
" version='3.1.1',\n"
|
||||
" ca='',\n"
|
||||
" keepalive=60):\n"
|
||||
" print('MQTT init')\n"
|
||||
" print(port)\n"
|
||||
" print('ip:', ip)\n"
|
||||
"c = MQTT('test')\n";
|
||||
__platform_printf("%s\n", lines);
|
||||
char* pikaAsm = Parser_linesToAsm(buffs, lines);
|
||||
__platform_printf("%s", pikaAsm);
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
#if !PIKA_NANO_ENABLE
|
||||
TEST(parser, except_dict) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user