mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
Merge branch 'master' of https://gitee.com/lyon1998/pikascript
This commit is contained in:
commit
141274dc1c
1
port/linux/.vscode/launch.json
vendored
1
port/linux/.vscode/launch.json
vendored
@ -18,6 +18,7 @@
|
|||||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||||
// "program": "${workspaceFolder}/../build/src/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
// "program": "${workspaceFolder}/../build/src/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||||
"args": [
|
"args": [
|
||||||
|
// "--gtest_filter=parser.__get__",
|
||||||
// "--gtest_filter=pikaMain.print_with_enter",
|
// "--gtest_filter=pikaMain.print_with_enter",
|
||||||
// "--gtest_filter=pikaMain.str_add",
|
// "--gtest_filter=pikaMain.str_add",
|
||||||
// "--gtest_filter=content*",
|
// "--gtest_filter=content*",
|
||||||
|
0
port/linux/api-make-linux.sh
Normal file → Executable file
0
port/linux/api-make-linux.sh
Normal file → Executable file
0
port/linux/api-make-win10.sh
Normal file → Executable file
0
port/linux/api-make-win10.sh
Normal file → Executable file
0
port/linux/api-make.sh
Normal file → Executable file
0
port/linux/api-make.sh
Normal file → Executable file
0
port/linux/ci_benchmark.sh
Normal file → Executable file
0
port/linux/ci_benchmark.sh
Normal file → Executable file
0
port/linux/gtest.sh
Normal file → Executable file
0
port/linux/gtest.sh
Normal file → Executable file
0
port/linux/init.sh
Normal file → Executable file
0
port/linux/init.sh
Normal file → Executable file
0
port/linux/install_dependency.sh
Normal file → Executable file
0
port/linux/install_dependency.sh
Normal file → Executable file
0
port/linux/make.sh
Normal file → Executable file
0
port/linux/make.sh
Normal file → Executable file
@ -138,13 +138,6 @@ Arg* PikaStdLib_SysObj_range(PikaObj* self, int a1, int a2, int a3) {
|
|||||||
return arg_setMetaObj("", "PikaStdLib_RangeObj", New_PikaStdLib_RangeObj);
|
return arg_setMetaObj("", "PikaStdLib_RangeObj", New_PikaStdLib_RangeObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __Sys_initObj(PikaObj* self, Arg* mate_obj) {
|
|
||||||
if (TYPE_MATE_OBJECT != arg_getType(mate_obj)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Hash arg_hash = arg_getNameHash(mate_obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
Arg* PikaStdLib_SysObj___get__(PikaObj* self, Arg* key, Arg* obj) {
|
Arg* PikaStdLib_SysObj___get__(PikaObj* self, Arg* key, Arg* obj) {
|
||||||
ArgType obj_type = arg_getType(obj);
|
ArgType obj_type = arg_getType(obj);
|
||||||
if ((TYPE_OBJECT == obj_type) || (TYPE_POINTER == obj_type)) {
|
if ((TYPE_OBJECT == obj_type) || (TYPE_POINTER == obj_type)) {
|
||||||
@ -162,7 +155,6 @@ Arg* PikaStdLib_SysObj___get__(PikaObj* self, Arg* key, Arg* obj) {
|
|||||||
|
|
||||||
void PikaStdLib_SysObj___set__(PikaObj* self, Arg* key, Arg* obj, Arg* val) {
|
void PikaStdLib_SysObj___set__(PikaObj* self, Arg* key, Arg* obj, Arg* val) {
|
||||||
ArgType obj_type = arg_getType(obj);
|
ArgType obj_type = arg_getType(obj);
|
||||||
__Sys_initObj(self, obj);
|
|
||||||
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);
|
||||||
obj_setArg(arg_obj, "__key", key);
|
obj_setArg(arg_obj, "__key", key);
|
||||||
|
0
port/linux/pkg-push.sh
Normal file → Executable file
0
port/linux/pkg-push.sh
Normal file → Executable file
0
port/linux/pull-core.sh
Normal file → Executable file
0
port/linux/pull-core.sh
Normal file → Executable file
0
port/linux/push-core.sh
Normal file → Executable file
0
port/linux/push-core.sh
Normal file → Executable file
0
port/linux/run.sh
Normal file → Executable file
0
port/linux/run.sh
Normal file → Executable file
0
port/linux/test-banchmark.sh
Normal file → Executable file
0
port/linux/test-banchmark.sh
Normal file → Executable file
@ -1798,3 +1798,20 @@ TEST(parser, print_ddd) {
|
|||||||
args_deinit(buffs);
|
args_deinit(buffs);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(parser, __get__) {
|
||||||
|
pikaMemInfo.heapUsedMax = 0;
|
||||||
|
Args* buffs = New_strBuff();
|
||||||
|
char* lines = (char*)
|
||||||
|
"a = b[c]\n";
|
||||||
|
printf("%s", lines);
|
||||||
|
char* pikaAsm = Parser_multiLineToAsm(buffs, (char*)lines);
|
||||||
|
printf("%s", pikaAsm);
|
||||||
|
// EXPECT_STREQ(pikaAsm,
|
||||||
|
// "B0\n"
|
||||||
|
// "1 STR [Info]: in Python config...\n"
|
||||||
|
// "0 RUN print\n"
|
||||||
|
// );
|
||||||
|
args_deinit(buffs);
|
||||||
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
|
}
|
||||||
|
0
port/linux/update-compiler.sh
Normal file → Executable file
0
port/linux/update-compiler.sh
Normal file → Executable file
@ -542,15 +542,27 @@ char* Lexer_popToken(Args* buffs, char* tokens_buff) {
|
|||||||
return strsPopToken(buffs, tokens_buff, 0x1F);
|
return strsPopToken(buffs, tokens_buff, 0x1F);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Lexer_isContain(char* tokens, char* operator) {
|
uint16_t Lexer_getTokenSize(char* tokens) {
|
||||||
|
return strCountSign(tokens, 0x1F) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum TokenType Lexer_getTokenType(char* token) {
|
||||||
|
return token[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
char* Lexer_getTokenPyload(char* token) {
|
||||||
|
return (char*)((uintptr_t)token + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Lexer_isContain(char* tokens, enum TokenType token_type, char* pyload) {
|
||||||
Args* buffs = New_strBuff();
|
Args* buffs = New_strBuff();
|
||||||
char* tokens_buff = strsCopy(buffs, tokens);
|
char* tokens_buff = strsCopy(buffs, tokens);
|
||||||
uint8_t res = 0;
|
uint8_t res = 0;
|
||||||
uint16_t token_size = strCountSign(tokens, 0x1F) + 1;
|
uint16_t token_size = Lexer_getTokenSize(tokens);
|
||||||
for (int i = 0; i < token_size; i++) {
|
for (int i = 0; i < token_size; i++) {
|
||||||
char* token = Lexer_popToken(buffs, tokens_buff);
|
char* token = Lexer_popToken(buffs, tokens_buff);
|
||||||
if (TOKEN_operator == token[0]) {
|
if (token_type == Lexer_getTokenType(token)) {
|
||||||
if (strEqu(token + 1, operator)) {
|
if (strEqu(Lexer_getTokenPyload(token), pyload)) {
|
||||||
res = 1;
|
res = 1;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -570,7 +582,7 @@ char* Lexer_getOperator(Args* outBuffs, char* stmt) {
|
|||||||
"&", "^", "|", "<", "<=", ">", ">=", "!=", "==", "%=",
|
"&", "^", "|", "<", "<=", ">", ">=", "!=", "==", "%=",
|
||||||
"/=", "//=", "-=", "+=", "*=", "**=", " not ", " and ", " or "};
|
"/=", "//=", "-=", "+=", "*=", "**=", " not ", " and ", " or "};
|
||||||
for (uint32_t i = 0; i < sizeof(operators) / 6; i++) {
|
for (uint32_t i = 0; i < sizeof(operators) / 6; i++) {
|
||||||
if (Lexer_isContain(tokens, (char*)operators[i])) {
|
if (Lexer_isContain(tokens, TOKEN_operator, (char*)operators[i])) {
|
||||||
operator= strsCopy(buffs, (char*)operators[i]);
|
operator= strsCopy(buffs, (char*)operators[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -580,6 +592,55 @@ char* Lexer_getOperator(Args* outBuffs, char* stmt) {
|
|||||||
return operator;
|
return operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* Parser_solveRightBranckets(Args* outBuffs, char* right) {
|
||||||
|
Args* buffs = New_args(NULL);
|
||||||
|
char* tokens = NULL;
|
||||||
|
char *token1, *token2 = NULL;
|
||||||
|
char *pyload1, *pyload2 = NULL;
|
||||||
|
Arg* right_arg = arg_setStr(NULL, "", "");
|
||||||
|
Arg* token1_arg = NULL;
|
||||||
|
enum TokenType token_type1, token_type2;
|
||||||
|
do {
|
||||||
|
tokens = Lexer_getTokens(buffs, right);
|
||||||
|
if (!Lexer_isContain(tokens, TOKEN_devider, "[")) {
|
||||||
|
/* not contain '[', return origin */
|
||||||
|
arg_deinit(right_arg);
|
||||||
|
right_arg = arg_setStr(right_arg, "", right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
uint16_t len = Lexer_getTokenSize(tokens);
|
||||||
|
Lexer_popToken(buffs, tokens);
|
||||||
|
token1_arg = arg_setStr(NULL, "", Lexer_popToken(buffs, tokens));
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
char* token_buffs = New_strBuff();
|
||||||
|
token1 = strsCopy(token_buffs, arg_getStr(token1_arg));
|
||||||
|
arg_deinit(token1_arg);
|
||||||
|
token2 = Lexer_popToken(token_buffs, tokens);
|
||||||
|
token1_arg = arg_setStr(NULL, "", token2);
|
||||||
|
token_type1 = Lexer_getTokenType(token1);
|
||||||
|
token_type2 = Lexer_getTokenType(token2);
|
||||||
|
pyload1 = Lexer_getTokenPyload(token1);
|
||||||
|
pyload2 = Lexer_getTokenPyload(token2);
|
||||||
|
|
||||||
|
/* matched [] */
|
||||||
|
if ((TOKEN_devider == token_type1) && (strEqu(pyload1, "["))) {
|
||||||
|
} else if ((TOKEN_devider == token_type1) &&
|
||||||
|
(strEqu(pyload1, "]"))) {
|
||||||
|
} else {
|
||||||
|
right_arg = arg_strAppend(right_arg, pyload1);
|
||||||
|
}
|
||||||
|
args_deinit(token_buffs);
|
||||||
|
}
|
||||||
|
arg_deinit(token1_arg);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
/* clean and retur */
|
||||||
|
right = strsCopy(outBuffs, arg_getStr(right_arg));
|
||||||
|
arg_deinit(right_arg);
|
||||||
|
args_deinit(buffs);
|
||||||
|
return right;
|
||||||
|
}
|
||||||
|
|
||||||
AST* AST_parseStmt(AST* ast, char* stmt) {
|
AST* AST_parseStmt(AST* ast, char* stmt) {
|
||||||
Args* buffs = New_strBuff();
|
Args* buffs = New_strBuff();
|
||||||
char* assignment = strsGetFirstToken(buffs, stmt, '(');
|
char* assignment = strsGetFirstToken(buffs, stmt, '(');
|
||||||
@ -604,6 +665,10 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
|
|||||||
} else {
|
} else {
|
||||||
right = stmt;
|
right = stmt;
|
||||||
}
|
}
|
||||||
|
/* solve the [] stmt */
|
||||||
|
right = Parser_solveRightBranckets(buffs, right);
|
||||||
|
|
||||||
|
/* match statment type */
|
||||||
enum StmtType stmtType = Lexer_matchStmtType(right);
|
enum StmtType stmtType = Lexer_matchStmtType(right);
|
||||||
/* solve operator stmt */
|
/* solve operator stmt */
|
||||||
if (STMT_operator == stmtType) {
|
if (STMT_operator == stmtType) {
|
||||||
|
25
src/PikaVM.c
25
src/PikaVM.c
@ -60,7 +60,6 @@ enum Instruct {
|
|||||||
|
|
||||||
#define __INS_ENUM
|
#define __INS_ENUM
|
||||||
#include "__instruction_table.cfg"
|
#include "__instruction_table.cfg"
|
||||||
|
|
||||||
__INSTRCUTION_CNT,
|
__INSTRCUTION_CNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -370,27 +369,29 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
|
|||||||
goto OPT_exit;
|
goto OPT_exit;
|
||||||
}
|
}
|
||||||
/* default: int and float */
|
/* default: int and float */
|
||||||
outArg = arg_setInt(outArg, "",
|
outArg =
|
||||||
(num1_f - num2_f) * (num1_f - num2_f) < 0.000001);
|
arg_setInt(outArg, "",
|
||||||
|
(num1_f - num2_f) * (num1_f - num2_f) < (float)0.000001);
|
||||||
goto OPT_exit;
|
goto OPT_exit;
|
||||||
}
|
}
|
||||||
if (strEqu("!=", data)) {
|
if (strEqu("!=", data)) {
|
||||||
outArg = arg_setInt(
|
outArg = arg_setInt(
|
||||||
outArg, "", !((num1_f - num2_f) * (num1_f - num2_f) < 0.000001));
|
outArg, "",
|
||||||
|
!((num1_f - num2_f) * (num1_f - num2_f) < (float)0.000001));
|
||||||
goto OPT_exit;
|
goto OPT_exit;
|
||||||
}
|
}
|
||||||
if (strEqu(">=", data)) {
|
if (strEqu(">=", data)) {
|
||||||
outArg =
|
outArg = arg_setInt(
|
||||||
arg_setInt(outArg, "",
|
outArg, "",
|
||||||
(num1_f > num2_f) ||
|
(num1_f > num2_f) ||
|
||||||
((num1_f - num2_f) * (num1_f - num2_f) < 0.000001));
|
((num1_f - num2_f) * (num1_f - num2_f) < (float)0.000001));
|
||||||
goto OPT_exit;
|
goto OPT_exit;
|
||||||
}
|
}
|
||||||
if (strEqu("<=", data)) {
|
if (strEqu("<=", data)) {
|
||||||
outArg =
|
outArg = arg_setInt(
|
||||||
arg_setInt(outArg, "",
|
outArg, "",
|
||||||
(num1_f < num2_f) ||
|
(num1_f < num2_f) ||
|
||||||
((num1_f - num2_f) * (num1_f - num2_f) < 0.000001));
|
((num1_f - num2_f) * (num1_f - num2_f) < (float)0.000001));
|
||||||
goto OPT_exit;
|
goto OPT_exit;
|
||||||
}
|
}
|
||||||
if (strEqu("&", data)) {
|
if (strEqu("&", data)) {
|
||||||
|
@ -142,8 +142,12 @@ char* strsReplace(Args* buffs, char* orig, char* rep, char* with) {
|
|||||||
len_with = strlen(with);
|
len_with = strlen(with);
|
||||||
// count the number of replacements needed
|
// count the number of replacements needed
|
||||||
ins = orig;
|
ins = orig;
|
||||||
for (count = 0; (tmp = strstr(ins, rep)); ++count) {
|
tmp = strstr(ins, rep);
|
||||||
|
count = 0;
|
||||||
|
while (tmp) {
|
||||||
|
count++;
|
||||||
ins = tmp + len_rep;
|
ins = tmp + len_rep;
|
||||||
|
tmp = strstr(ins, rep);
|
||||||
}
|
}
|
||||||
tmp = args_getBuff(buffs, strlen(orig) + (len_with - len_rep) * count + 1);
|
tmp = args_getBuff(buffs, strlen(orig) + (len_with - len_rep) * count + 1);
|
||||||
result = tmp;
|
result = tmp;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user