mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-02-05 17:28:23 +08:00
use more warning and debug maybe use uninited
This commit is contained in:
parent
71e87600f9
commit
20b228e3aa
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.0.0)
|
cmake_minimum_required(VERSION 3.0.0)
|
||||||
add_compile_options(-Wall)
|
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Werror)
|
||||||
|
|
||||||
project(pikascript VERSION 0.1.0)
|
project(pikascript VERSION 0.1.0)
|
||||||
|
|
||||||
|
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/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/make.sh
Normal file → Executable file
0
port/linux/make.sh
Normal file → Executable file
0
port/linux/package/pikascript/rust-msc-latest-linux
Normal file → Executable file
0
port/linux/package/pikascript/rust-msc-latest-linux
Normal file → Executable file
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/test-banchmark.sh
Normal file → Executable file
0
port/linux/test-banchmark.sh
Normal file → Executable file
0
port/linux/update-compiler.sh
Normal file → Executable file
0
port/linux/update-compiler.sh
Normal file → Executable file
@ -221,7 +221,7 @@ exit:
|
|||||||
uint8_t Parser_checkIsDirect(char* str) {
|
uint8_t Parser_checkIsDirect(char* str) {
|
||||||
/* include '0' */
|
/* include '0' */
|
||||||
uint32_t size = strGetSize(str) + 1;
|
uint32_t size = strGetSize(str) + 1;
|
||||||
for (int i = 1; i + 1 < size; i++) {
|
for (uint32_t i = 1; i + 1 < size; i++) {
|
||||||
if ((str[i - 1] != '%') && (str[i - 1] != '!') && (str[i - 1] != '<') &&
|
if ((str[i - 1] != '%') && (str[i - 1] != '!') && (str[i - 1] != '<') &&
|
||||||
(str[i - 1] != '>') && (str[i - 1] != '=') && (str[i - 1] != '+') &&
|
(str[i - 1] != '>') && (str[i - 1] != '=') && (str[i - 1] != '+') &&
|
||||||
(str[i - 1] != '-') && (str[i - 1] != '*') && (str[i - 1] != '/') &&
|
(str[i - 1] != '-') && (str[i - 1] != '*') && (str[i - 1] != '/') &&
|
||||||
@ -239,7 +239,7 @@ char* Lexer_printTokens(Args* outBuffs, char* tokens) {
|
|||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
uint16_t tokenSize = strCountSign(tokens, 0x1F) + 1;
|
uint16_t tokenSize = strCountSign(tokens, 0x1F) + 1;
|
||||||
for (int i = 0; i < tokenSize; i++) {
|
for (uint16_t i = 0; i < tokenSize; i++) {
|
||||||
char* token = strsPopToken(buffs, tokens, 0x1F);
|
char* token = strsPopToken(buffs, tokens, 0x1F);
|
||||||
if (token[0] == TOKEN_operator) {
|
if (token[0] == TOKEN_operator) {
|
||||||
printOut = strsAppend(buffs, printOut, "{opt}");
|
printOut = strsAppend(buffs, printOut, "{opt}");
|
||||||
@ -283,8 +283,8 @@ Arg* Lexer_setToken(Arg* tokens_arg,
|
|||||||
|
|
||||||
Arg* Lexer_setSymbel(Arg* tokens_arg,
|
Arg* Lexer_setSymbel(Arg* tokens_arg,
|
||||||
char* stmt,
|
char* stmt,
|
||||||
uint32_t i,
|
int32_t i,
|
||||||
int* symbol_start_index) {
|
int32_t* symbol_start_index) {
|
||||||
Args* buffs = New_strBuff();
|
Args* buffs = New_strBuff();
|
||||||
char* symbol_buff = NULL;
|
char* symbol_buff = NULL;
|
||||||
/* nothing to add symbel */
|
/* nothing to add symbel */
|
||||||
@ -316,18 +316,18 @@ char* Lexer_getTokens(Args* outBuffs, char* stmt) {
|
|||||||
/* init */
|
/* init */
|
||||||
Arg* tokens_arg = New_arg(NULL);
|
Arg* tokens_arg = New_arg(NULL);
|
||||||
tokens_arg = arg_setStr(tokens_arg, "", "");
|
tokens_arg = arg_setStr(tokens_arg, "", "");
|
||||||
uint32_t size = strGetSize(stmt);
|
int32_t size = strGetSize(stmt);
|
||||||
uint8_t bracket_deepth = 0;
|
uint8_t bracket_deepth = 0;
|
||||||
uint8_t c0 = 0;
|
uint8_t c0 = 0;
|
||||||
uint8_t c1 = 0;
|
uint8_t c1 = 0;
|
||||||
uint8_t c2 = 0;
|
uint8_t c2 = 0;
|
||||||
uint8_t c3 = 0;
|
uint8_t c3 = 0;
|
||||||
int symbol_start_index = -1;
|
int32_t symbol_start_index = -1;
|
||||||
int is_in_string = 0;
|
int is_in_string = 0;
|
||||||
char* tokens;
|
char* tokens;
|
||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
for (int i = 0; i < size; i++) {
|
for (int32_t i = 0; i < size; i++) {
|
||||||
/* update char */
|
/* update char */
|
||||||
c0 = stmt[i];
|
c0 = stmt[i];
|
||||||
if (i + 1 < size) {
|
if (i + 1 < size) {
|
||||||
@ -564,7 +564,7 @@ char* Lexer_getOperator(Args* outBuffs, char* stmt) {
|
|||||||
"**", "~", "*", "/", "%", "//", "+", "-", ">>", "<<",
|
"**", "~", "*", "/", "%", "//", "+", "-", ">>", "<<",
|
||||||
"&", "^", "|", "<", "<=", ">", ">=", "!=", "==", "%=",
|
"&", "^", "|", "<", "<=", ">", ">=", "!=", "==", "%=",
|
||||||
"/=", "//=", "-=", "+=", "*=", "**=", " not ", " and ", " or "};
|
"/=", "//=", "-=", "+=", "*=", "**=", " not ", " and ", " or "};
|
||||||
for (int 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, (char*)operators[i])) {
|
||||||
operator= strsCopy(buffs, (char*)operators[i]);
|
operator= strsCopy(buffs, (char*)operators[i]);
|
||||||
}
|
}
|
||||||
@ -658,7 +658,7 @@ exit:
|
|||||||
|
|
||||||
static int32_t Parser_getPyLineBlockDeepth(char* line) {
|
static int32_t Parser_getPyLineBlockDeepth(char* line) {
|
||||||
uint32_t size = strGetSize(line);
|
uint32_t size = strGetSize(line);
|
||||||
for (int i = 0; i < size; i++) {
|
for (uint32_t i = 0; i < size; i++) {
|
||||||
if (line[i] != ' ') {
|
if (line[i] != ' ') {
|
||||||
uint32_t spaceNum = i;
|
uint32_t spaceNum = i;
|
||||||
if (0 == spaceNum % 4) {
|
if (0 == spaceNum % 4) {
|
||||||
@ -673,7 +673,7 @@ static int32_t Parser_getPyLineBlockDeepth(char* line) {
|
|||||||
|
|
||||||
char* Parser_removeAnnotation(char* line) {
|
char* Parser_removeAnnotation(char* line) {
|
||||||
uint8_t is_annotation_exit = 0;
|
uint8_t is_annotation_exit = 0;
|
||||||
for (int i = 0; i < strGetSize(line); i++) {
|
for (uint32_t i = 0; i < strGetSize(line); i++) {
|
||||||
if ('#' == line[i]) {
|
if ('#' == line[i]) {
|
||||||
/* end the line */
|
/* end the line */
|
||||||
line[i] = 0;
|
line[i] = 0;
|
||||||
@ -686,7 +686,7 @@ char* Parser_removeAnnotation(char* line) {
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
/* check empty line */
|
/* check empty line */
|
||||||
for (int i = 0; i < strGetSize(line); i++) {
|
for (uint32_t i = 0; i < strGetSize(line); i++) {
|
||||||
if (' ' != line[i]) {
|
if (' ' != line[i]) {
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
37
src/PikaVM.c
37
src/PikaVM.c
@ -109,7 +109,6 @@ Arg* pikaVM_runInstruct(PikaObj* self,
|
|||||||
Queue* invokeQuene0,
|
Queue* invokeQuene0,
|
||||||
Queue* invokeQuene1,
|
Queue* invokeQuene1,
|
||||||
int32_t* jmp,
|
int32_t* jmp,
|
||||||
int32_t* jmp_block,
|
|
||||||
char* programConter,
|
char* programConter,
|
||||||
char* asmStart) {
|
char* asmStart) {
|
||||||
if (instruct == NUM) {
|
if (instruct == NUM) {
|
||||||
@ -204,10 +203,10 @@ Arg* pikaVM_runInstruct(PikaObj* self,
|
|||||||
Arg* arg2 = arg_copy(queue_popArg(invokeQuene1));
|
Arg* arg2 = arg_copy(queue_popArg(invokeQuene1));
|
||||||
ArgType type_arg1 = arg_getType(arg1);
|
ArgType type_arg1 = arg_getType(arg1);
|
||||||
ArgType type_arg2 = arg_getType(arg2);
|
ArgType type_arg2 = arg_getType(arg2);
|
||||||
int num1_i;
|
int num1_i = 0;
|
||||||
int num2_i;
|
int num2_i = 0;
|
||||||
float num1_f;
|
float num1_f = 0.0;
|
||||||
float num2_f;
|
float num2_f = 0.0;
|
||||||
/* get int and float num */
|
/* get int and float num */
|
||||||
if (type_arg1 == TYPE_INT) {
|
if (type_arg1 == TYPE_INT) {
|
||||||
num1_i = arg_getInt(arg1);
|
num1_i = arg_getInt(arg1);
|
||||||
@ -492,11 +491,9 @@ int getThisBlockDeepth(char* start, char* code, int* offset) {
|
|||||||
return thisBlockDeepth;
|
return thisBlockDeepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VM_getAddrOffsetFromJmp(char* start,
|
int32_t getAddrOffsetFromJmp(char* start, char* code, int32_t jmp) {
|
||||||
char* code,
|
int offset = 0;
|
||||||
int32_t jmp,
|
int thisBlockDeepth = getThisBlockDeepth(start, code, &offset);
|
||||||
int32_t offset,
|
|
||||||
int thisBlockDeepth) {
|
|
||||||
char* codeNow = code + offset;
|
char* codeNow = code + offset;
|
||||||
int8_t blockNum = 0;
|
int8_t blockNum = 0;
|
||||||
if (jmp > 0) {
|
if (jmp > 0) {
|
||||||
@ -534,14 +531,6 @@ int32_t VM_getAddrOffsetFromJmp(char* start,
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t VM_getAddrOffsetFromJmpByThisBlockDeepth(char* start,
|
|
||||||
char* code,
|
|
||||||
int32_t jmp) {
|
|
||||||
int offset = 0;
|
|
||||||
int thisBlockDeepth = getThisBlockDeepth(start, code, &offset);
|
|
||||||
return VM_getAddrOffsetFromJmp(start, code, jmp, offset, thisBlockDeepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t pikaVM_runAsmLine(PikaObj* self,
|
int32_t pikaVM_runAsmLine(PikaObj* self,
|
||||||
Parameters* locals,
|
Parameters* locals,
|
||||||
Parameters* globals,
|
Parameters* globals,
|
||||||
@ -552,7 +541,6 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
|||||||
char* line = strs_getLine(buffs, programCounter);
|
char* line = strs_getLine(buffs, programCounter);
|
||||||
int32_t nextAddr = lineAddr + strGetSize(line) + 1;
|
int32_t nextAddr = lineAddr + strGetSize(line) + 1;
|
||||||
int32_t jmp = 0;
|
int32_t jmp = 0;
|
||||||
int32_t jmp_block = -1;
|
|
||||||
enum Instruct instruct;
|
enum Instruct instruct;
|
||||||
char invokeDeepth0[2] = {0}, invokeDeepth1[2] = {0};
|
char invokeDeepth0[2] = {0}, invokeDeepth1[2] = {0};
|
||||||
char* data;
|
char* data;
|
||||||
@ -581,9 +569,9 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
|||||||
invokeQuene1 = New_queue();
|
invokeQuene1 = New_queue();
|
||||||
args_setPtr(locals->list, invokeDeepth1, invokeQuene1);
|
args_setPtr(locals->list, invokeDeepth1, invokeQuene1);
|
||||||
}
|
}
|
||||||
resArg = pikaVM_runInstruct(self, locals, globals, instruct, data,
|
resArg =
|
||||||
invokeQuene0, invokeQuene1, &jmp, &jmp_block,
|
pikaVM_runInstruct(self, locals, globals, instruct, data, invokeQuene0,
|
||||||
programCounter, pikaAsm);
|
invokeQuene1, &jmp, programCounter, pikaAsm);
|
||||||
if (NULL != resArg) {
|
if (NULL != resArg) {
|
||||||
queue_pushArg(invokeQuene0, resArg);
|
queue_pushArg(invokeQuene0, resArg);
|
||||||
}
|
}
|
||||||
@ -594,10 +582,7 @@ nextLine:
|
|||||||
return -99999;
|
return -99999;
|
||||||
}
|
}
|
||||||
if (jmp != 0) {
|
if (jmp != 0) {
|
||||||
if (-1 == jmp_block) {
|
return lineAddr + getAddrOffsetFromJmp(pikaAsm, programCounter, jmp);
|
||||||
return lineAddr + VM_getAddrOffsetFromJmpByThisBlockDeepth(
|
|
||||||
pikaAsm, programCounter, jmp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nextAddr;
|
return nextAddr;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ char* strCut(char* strOut, char* strIn, char startSign, char endSign) {
|
|||||||
|
|
||||||
char* strDeleteChar(char* strOut, char* strIn, char ch) {
|
char* strDeleteChar(char* strOut, char* strIn, char ch) {
|
||||||
int32_t iOut = 0;
|
int32_t iOut = 0;
|
||||||
for (int32_t i = 0; i < strGetSize(strIn); i++) {
|
for (uint32_t i = 0; i < strGetSize(strIn); i++) {
|
||||||
if (ch == strIn[i]) {
|
if (ch == strIn[i]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ char* strAppendWithSize(char* strOut, char* pData, int32_t Size) {
|
|||||||
|
|
||||||
int32_t strCountSign(char* strIn, char sign) {
|
int32_t strCountSign(char* strIn, char sign) {
|
||||||
int32_t count = 0;
|
int32_t count = 0;
|
||||||
for (int32_t i = 0; i < strGetSize(strIn); i++) {
|
for (uint32_t i = 0; i < strGetSize(strIn); i++) {
|
||||||
if (sign == strIn[i]) {
|
if (sign == strIn[i]) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@ -210,12 +210,12 @@ char* strGetFirstToken(char* strOut, char* strIn, char sign) {
|
|||||||
|
|
||||||
int32_t strGetToken(char* string, char** argv, char sign) {
|
int32_t strGetToken(char* string, char** argv, char sign) {
|
||||||
int32_t argc = 0;
|
int32_t argc = 0;
|
||||||
int32_t i = 0;
|
uint32_t i = 0;
|
||||||
// arg_i point32_t to the arg operated now
|
// arg_i point32_t to the arg operated now
|
||||||
int32_t arg_i = 0;
|
int32_t arg_i = 0;
|
||||||
// if not found ' ', then put chars from CMD to argv_tem
|
// if not found ' ', then put chars from CMD to argv_tem
|
||||||
int32_t char_i = 0;
|
int32_t char_i = 0;
|
||||||
for (i = 0; (i < strGetSize(string)); i++) {
|
for (i = 0; i < strGetSize(string); i++) {
|
||||||
if (string[i] != sign) {
|
if (string[i] != sign) {
|
||||||
argv[arg_i][char_i] = string[i];
|
argv[arg_i][char_i] = string[i];
|
||||||
char_i++;
|
char_i++;
|
||||||
@ -246,7 +246,7 @@ int32_t strIsStartWith(char* str, char* strStart) {
|
|||||||
}
|
}
|
||||||
uint32_t size = strGetSize(strStart);
|
uint32_t size = strGetSize(strStart);
|
||||||
uint32_t CMDName_get = 1;
|
uint32_t CMDName_get = 1;
|
||||||
for (int32_t i = 0; i < size; i++) {
|
for (uint32_t i = 0; i < size; i++) {
|
||||||
if (str[i] != strStart[i]) {
|
if (str[i] != strStart[i]) {
|
||||||
CMDName_get = 0;
|
CMDName_get = 0;
|
||||||
}
|
}
|
||||||
@ -266,21 +266,21 @@ char* strRemovePrefix(char* inputStr, char* prefix, char* outputStr) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = strGetSize(prefix); i < strGetSize(inputStr); i++) {
|
for (uint32_t i = strGetSize(prefix); i < strGetSize(inputStr); i++) {
|
||||||
outputStr[i - strGetSize(prefix)] = inputStr[i];
|
outputStr[i - strGetSize(prefix)] = inputStr[i];
|
||||||
}
|
}
|
||||||
return outputStr;
|
return outputStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* strClear(char* str) {
|
char* strClear(char* str) {
|
||||||
for (int32_t i = 0; i < sizeof(str); i++) {
|
for (uint32_t i = 0; i < sizeof(str); i++) {
|
||||||
str[i] = 0;
|
str[i] = 0;
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t strIsContain(char* str, char ch) {
|
int32_t strIsContain(char* str, char ch) {
|
||||||
for (int32_t i = 0; i < strGetSize(str); i++) {
|
for (uint32_t i = 0; i < strGetSize(str); i++) {
|
||||||
if (str[i] == ch) {
|
if (str[i] == ch) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user