add Warning flag and solve warnings

This commit is contained in:
lyon 2021-11-14 18:39:08 +08:00
parent a2eed10693
commit 5316ede928
27 changed files with 90 additions and 117 deletions

View File

@ -14,7 +14,7 @@
// "--gtest_filter=queue*"
// "--gtest_filter=parser*"
// "--gtest_filter=args*",
"--gtest_filter=content*",
// "--gtest_filter=content*",
// "--gtest_filter=object_test.printa",
// "--gtest_filter=object_test*",
// "--gtest_filter=stack*",

View File

@ -9,7 +9,8 @@
"*.tcc": "c",
"istream": "c",
"cstring": "cpp",
"variant": "cpp"
"variant": "cpp",
"pikaplatform.h": "c"
},
"python.formatting.provider": "yapf"
}

View File

@ -1,4 +1,6 @@
cmake_minimum_required(VERSION 3.0.0)
add_compile_options(-Wall)
project(pikascript VERSION 0.1.0)
include_directories(package/pikascript/pikascript-core)

View File

@ -161,7 +161,6 @@ TEST(VM, JEZ) {
"B0\n";
PikaObj* self = New_TinyObj(NULL);
int lineAddr = 0;
int size = strGetSize(pikaAsm);
Args* sysRes = New_args(NULL);
args_setErrorCode(sysRes, 0);
args_setSysOut(sysRes, (char*)"");
@ -185,7 +184,6 @@ TEST(VM, JMP) {
"B0\n";
PikaObj* self = New_TinyObj(NULL);
int lineAddr = 0;
int size = strGetSize(pikaAsm);
Args* sysRes = New_args(NULL);
args_setErrorCode(sysRes, 0);
args_setSysOut(sysRes, (char*)"");
@ -209,7 +207,6 @@ TEST(VM, JMP_back1) {
"B0\n";
PikaObj* self = New_TinyObj(NULL);
int lineAddr = 0;
int size = strGetSize(pikaAsm);
Args* sysRes = New_args(NULL);
args_setErrorCode(sysRes, 0);
args_setSysOut(sysRes, (char*)"");
@ -334,6 +331,7 @@ TEST(VM, mem_x) {
Parameters* globals = pikaVM_runAsm(self, pikaAsm);
int res = obj_getInt(globals, (char*)"mem.x");
EXPECT_EQ(2, res);
obj_deinit(self);
obj_deinit(globals);
args_deinit(buffs);
@ -355,8 +353,6 @@ TEST(VM, DEF_instruct) {
"0 RET\n"
"B0\n";
PikaObj* self = New_TinyObj(NULL);
int lineAddr = 0;
int size = strGetSize(pikaAsm);
Parameters* globals = pikaVM_runAsm(self, pikaAsm);
char* methodPtr = (char*)obj_getPtr(self, (char*)"test");
EXPECT_STREQ(methodCode, methodPtr);
@ -374,8 +370,6 @@ TEST(VM, RET_instruct) {
"0 RET\n"
"B0\n";
PikaObj* self = New_TinyObj(NULL);
int lineAddr = 0;
int size = strGetSize(pikaAsm);
Parameters* globals = pikaVM_runAsm(self, pikaAsm);
Arg* returnArg = args_getArg(globals->list, (char*)"return");
int num = arg_getInt(returnArg);

View File

@ -3,7 +3,6 @@ extern "C" {
#include "dataArg.h"
#include "dataString.h"
}
static int mem;
TEST(arg_test, int_) {
Arg* arg = New_arg(NULL);

View File

@ -25,7 +25,6 @@ TEST(args, test4) {
TEST(args, test2) {
Args* args = New_args(NULL);
float floatOut = 0;
int64_t int64Out = 0;
void* pointer = NULL;
char* strOut = NULL;
@ -64,7 +63,7 @@ TEST(args, test3) {
TEST(args, buff) {
Args* buffs = New_args(NULL);
char* buff = args_getBuff(buffs, 256);
args_getBuff(buffs, 256);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -3,7 +3,6 @@ extern "C" {
#include "dataArg.h"
#include "dataString.h"
}
static int mem;
TEST(content, init) {
uint8_t contentIn[4] = {0};
@ -11,7 +10,6 @@ TEST(content, init) {
contentIn[1] = 2;
contentIn[2] = 3;
contentIn[3] = 4;
uint16_t sizeIn = 4;
uint8_t* self =
content_init((char*)"name", (char*)"type", contentIn, 4, NULL);

View File

@ -87,9 +87,6 @@ PikaObj* New_MYROOT1(Args* args) {
TEST(object_test, test10) {
PikaObj* root = newRootObj((char*)"root", New_MYROOT1);
PikaObj* usart = obj_getObj(root, (char*)"usart", 0);
// PikaObj* context = obj_getContext(usart);
// EXPECT_EQ(context, root);
obj_run(root, (char*)"usart.send('hello world')");
obj_deinit(root);
EXPECT_EQ(pikaMemNow(), 0);

View File

@ -5,7 +5,6 @@ extern "C" {
#include "dataQueue.h"
#include "dataQueueObj.h"
}
static int mem;
TEST(queue, NEW) {
Queue* q = New_queue();
@ -134,7 +133,9 @@ TEST(queueObj, currentObj) {
queueObj_pushObj(q, (char*)"type1");
PikaObj* currentObj = queueObj_getCurrentObj(q);
EXPECT_TRUE(currentObj != NULL);
char* type = args_getType(q->list, (char*)"0");
EXPECT_STREQ((char*)"c", type);
obj_setInt(queueObj_getCurrentObj(q), (char*)"test", 1);
queueObj_pushObj(q, (char*)"type2");
@ -156,4 +157,4 @@ TEST(queueObj, currentObj) {
EXPECT_EQ(obj_getInt(obj3, (char*)"test"), 3);
obj_deinit(q);
EXPECT_EQ(pikaMemNow(), 0);
}
}

View File

@ -4,7 +4,6 @@ extern "C" {
#include "dataMemory.h"
#include "dataStack.h"
}
static int mem;
TEST(stack, NEW) {
Stack* s = New_Stack();

View File

@ -7,67 +7,69 @@ extern "C" {
}
static void printInfo(const char* argName, char* argVal) {
printf("\t\t[info] %s: \"%s\"\r\n", argName, argVal);
printf("\t\t[info] %s: \"%s\"\r\n", argName, argVal);
}
static int mem;
TEST(strs, append) {
Args* buffs = New_strBuff();
char* res = strsAppend(buffs, (char*)"a", (char*)"b");
EXPECT_STREQ((char*)"ab", res);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
Args* buffs = New_strBuff();
char* res = strsAppend(buffs, (char*)"a", (char*)"b");
EXPECT_STREQ((char*)"ab", res);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(strs, formatInt) {
Args* buffs = New_strBuff();
char* res = strsFormat(buffs, 32, "test: %d", 3);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
Args* buffs = New_strBuff();
char* res = strsFormat(buffs, 32, "test: %d", 3);
EXPECT_STREQ((char*)"test: 3", res);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(strs, analizeDef) {
mem = pikaMemNow();
Args* buffs = New_args(NULL);
char currentClassName[] = "Compiler";
char line[] = " def analizeFile(pythonApiPath: str):";
printInfo("currentClassName", currentClassName);
char* defSentenceWithBlock = strsRemovePrefix(buffs, line, (char*)" def ");
char* defSentence = strsDeleteChar(buffs, defSentenceWithBlock, ' ');
printInfo("defSentence", defSentence);
char* methodName = strsGetFirstToken(buffs, defSentence, '(');
printInfo("methodName", methodName);
char* methodObjPath = strsAppend(
buffs, strsAppend(buffs, currentClassName, (char*)"."), methodName);
printInfo("methodObjPath", methodObjPath);
char* returnType = strsCut(buffs, defSentence, '>', ':');
printInfo("returnType", returnType);
mem = pikaMemNow();
Args* buffs = New_args(NULL);
char currentClassName[] = "Compiler";
char line[] = " def analizeFile(pythonApiPath: str):";
printInfo("currentClassName", currentClassName);
char* defSentenceWithBlock =
strsRemovePrefix(buffs, line, (char*)" def ");
char* defSentence = strsDeleteChar(buffs, defSentenceWithBlock, ' ');
printInfo("defSentence", defSentence);
char* methodName = strsGetFirstToken(buffs, defSentence, '(');
printInfo("methodName", methodName);
char* methodObjPath = strsAppend(
buffs, strsAppend(buffs, currentClassName, (char*)"."), methodName);
printInfo("methodObjPath", methodObjPath);
char* returnType = strsCut(buffs, defSentence, '>', ':');
printInfo("returnType", returnType);
char* typeList = strsCut(buffs, defSentence, '(', ')');
printInfo("typeList", typeList);
if (0 != strGetSize(typeList)) {
int argNum = strCountSign(typeList, ',') + 1;
char* typeListBuff = strsCopy(buffs, typeList);
for (int i = 0; i < argNum; i++) {
char* typeDeclearation = strsPopToken(buffs, typeListBuff, ',');
printInfo("typeDeclearation", typeDeclearation);
char* argName = strsGetFirstToken(buffs, typeDeclearation, ':');
printInfo("argName", argName);
char* argType = strsGetLastToken(buffs, typeDeclearation, ':');
printInfo("argType", argType);
char* typeList = strsCut(buffs, defSentence, '(', ')');
printInfo("typeList", typeList);
if (0 != strGetSize(typeList)) {
int argNum = strCountSign(typeList, ',') + 1;
char* typeListBuff = strsCopy(buffs, typeList);
for (int i = 0; i < argNum; i++) {
char* typeDeclearation = strsPopToken(buffs, typeListBuff, ',');
printInfo("typeDeclearation", typeDeclearation);
char* argName = strsGetFirstToken(buffs, typeDeclearation, ':');
printInfo("argName", argName);
char* argType = strsGetLastToken(buffs, typeDeclearation, ':');
printInfo("argType", argType);
}
}
}
args_deinit(buffs);
return;
args_deinit(buffs);
return;
}
TEST(strs, format) {
Args* buffs = New_args(NULL);
char* fmt = strsFormat(buffs, 128, "test int: %d, float %f", 1, 34.2);
EXPECT_TRUE(strEqu((char*)"test int: 1, float 34.200000", fmt));
args_deinit(buffs);
Args* buffs = New_args(NULL);
char* fmt = strsFormat(buffs, 128, "test int: %d, float %f", 1, 34.2);
EXPECT_TRUE(strEqu((char*)"test int: 1, float 34.200000", fmt));
args_deinit(buffs);
}
TEST(strs, mem) {
EXPECT_EQ(pikaMemNow(), mem);
EXPECT_EQ(pikaMemNow(), mem);
}

View File

@ -10,11 +10,6 @@
#include "dataString.h"
#include "dataStrs.h"
static void* getClassPtr(PikaObj* classObj, char* classPath) {
char* ptrPath = classPath;
return obj_getPtr(classObj, ptrPath);
}
Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr) {
Args* buffs = New_strBuff();
Arg* argNew = New_arg(NULL);

View File

@ -292,9 +292,6 @@ PikaObj* initObj(PikaObj* obj, char* name) {
PikaObj* thisClass = obj_getClassObjByNewFun(obj, name, newObjFun);
PikaObj* newObj = removeMethodInfo(thisClass);
char* mateObjType = args_getType(obj->list, name);
char* pureType = strsGetLastToken(buffs, mateObjType, ']');
char* objType = strsAppend(buffs, "c", pureType);
args_setPtrWithType(obj->list, name, "c", newObj);
res = obj_getPtr(obj, name);
goto exit;
@ -557,4 +554,4 @@ PikaObj* New_PikaObj(void) {
/* List */
self->list = New_args(NULL);
return self;
}
}

View File

@ -16,7 +16,6 @@ char* strsPopTokenWithSkip(Args* buffs,
return NULL;
}
char* strOut = args_getBuff(buffs, size);
int32_t iOut = 0;
int32_t stmtEnd = 0;
uint8_t isGetSign = 0;
int32_t parentheseDeepth = 0;
@ -500,4 +499,4 @@ char* AST_toPikaAsm(AST* ast, Args* buffs) {
int32_t AST_deinit(AST* ast) {
return obj_deinit(ast);
}
}

View File

@ -10,4 +10,4 @@ int32_t AST_deinit(AST* ast);
char* AST_toPikaAsm(AST* ast, Args* buffs);
char* pikaParseMultiLineToAsm(Args* outBuffs, char* multiLine);
#endif
#endif

View File

@ -4,11 +4,11 @@
#include <stdio.h>
#include <stdlib.h>
PIKA_WEAK void __platformDisableIrqHandle() {
PIKA_WEAK void __platformDisableIrqHandle(void) {
/* disable irq to support thread */
}
PIKA_WEAK void __platformEnableIrqHandle() {
PIKA_WEAK void __platformEnableIrqHandle(void) {
/* disable irq to support thread */
}
@ -23,12 +23,11 @@ PIKA_WEAK void __platformFree(void* ptr) {
PIKA_WEAK void __platformPrintf(char* fmt, ...) {
va_list args;
va_start(args, fmt);
char sysOut[128] = {0};
vprintf(fmt, args);
va_end(args);
}
PIKA_WEAK char* __platformLoadPikaAsm() {
PIKA_WEAK char* __platformLoadPikaAsm(void) {
/* faild */
return NULL;
}
@ -43,6 +42,6 @@ PIKA_WEAK uint8_t __platformAsmIsToFlash(char* pyMultiLine) {
return 0;
}
PIKA_WEAK int32_t __platformSavePikaAsmEOF() {
PIKA_WEAK int32_t __platformSavePikaAsmEOF(void) {
return 1;
}

View File

@ -14,12 +14,12 @@
void __platformPrintf(char* fmt, ...);
void* __platformMalloc(size_t size);
void __platformFree(void* ptr);
void __platformEnableIrqHandle();
void __platformDisableIrqHandle();
void __platformEnableIrqHandle(void);
void __platformDisableIrqHandle(void);
char* __platformLoadPikaAsm();
char* __platformLoadPikaAsm(void);
int32_t __platformSavePikaAsm(char *PikaAsm);
uint8_t __platformAsmIsToFlash(char *pyMultiLine);
int32_t __platformSavePikaAsmEOF();
int32_t __platformSavePikaAsmEOF(void);
#endif
#endif

View File

@ -73,14 +73,16 @@ static enum Instruct getInstruct(char* line) {
int fast_atoi(char* src) {
const char* p = src;
static const uint64_t a[][10] = {
0, 1e0, 2e0, 3e0, 4e0,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ct == OPT) {
char* operator= data;
Arg* outArg = NULL;
Arg* arg1 = arg_copy(queue_popArg(invokeQuene1));
Arg* arg2 = arg_copy(queue_popArg(invokeQuene1));
if (strEqu(arg_getType(arg1), "i") &&
strEqu(arg_getType(arg2), "i")) {
if (strEqu(arg_getType(arg1), "i") && strEqu(arg_getType(arg2), "i")) {
int num1 = arg_getInt(arg1);
int num2 = arg_getInt(arg2);
if (strEqu("+", data)) {
@ -217,8 +217,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
goto OPT_exit;
}
}
if (strEqu(arg_getType(arg1), "f") &&
strEqu(arg_getType(arg2), "i")) {
if (strEqu(arg_getType(arg1), "f") && strEqu(arg_getType(arg2), "i")) {
float num1 = arg_getFloat(arg1);
int num2 = arg_getInt(arg2);
if (strEqu("+", data)) {
@ -250,8 +249,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
goto OPT_exit;
}
}
if (strEqu(arg_getType(arg1), "i") &&
strEqu(arg_getType(arg2), "f")) {
if (strEqu(arg_getType(arg1), "i") && strEqu(arg_getType(arg2), "f")) {
int num1 = arg_getInt(arg1);
float num2 = arg_getFloat(arg2);
if (strEqu("+", data)) {
@ -283,8 +281,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
goto OPT_exit;
}
}
if (strEqu(arg_getType(arg1), "f") &&
strEqu(arg_getType(arg2), "f")) {
if (strEqu(arg_getType(arg1), "f") && strEqu(arg_getType(arg2), "f")) {
float num1 = arg_getFloat(arg1);
float num2 = arg_getFloat(arg2);
if (strEqu("+", data)) {
@ -531,7 +528,6 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
args_setErrorCode(locals->list, 0);
args_setSysOut(locals->list, (char*)"");
__clearInvokeQueues(locals);
uint8_t blockDeepth = line[1] - '0';
goto nextLine;
}
@ -627,7 +623,6 @@ Parameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm) {
Parameters* pikaVM_run(PikaObj* self, char* multiLine) {
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseMultiLineToAsm(buffs, multiLine);
uint32_t asm_size = strGetSize(pikaAsm);
Parameters* globals = pikaVM_runAsm(self, pikaAsm);
if (NULL != buffs) {
args_deinit(buffs);

View File

@ -20,4 +20,4 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
char* pikaAsm,
int32_t lineAddr);
#endif
#endif

View File

@ -103,7 +103,6 @@ uint8_t* content_init(char* name,
}
uint16_t content_totleSize(uint8_t* self) {
Hash nameHash = content_getNameHash(self);
char* type = content_getType(self);
const uint8_t sizeLenth = 2;
const uint8_t nextLength = sizeof(uint8_t*);
@ -219,7 +218,6 @@ char* content_getType(uint8_t* self) {
uint16_t content_contentOffset(uint8_t* self) {
const uint8_t nextLength = sizeof(uint8_t*);
const uint8_t sizeLength = 2;
Hash nameHash = content_getNameHash(self);
return nextLength + sizeLength + sizeof(Hash);
}

View File

@ -139,4 +139,4 @@ Arg* queue_popArg(Queue* queue) {
char buff[11];
Arg* res = args_getArg(args, fast_itoa(buff, bottom));
return res;
}
}

View File

@ -21,4 +21,4 @@ int64_t queue_popInt(Queue* queue);
float queue_popFloat(Queue* queue);
char* queue_popStr(Queue* queue);
Arg* queue_popArg(Queue* queue);
#endif
#endif

View File

@ -95,4 +95,4 @@ char* queueObj_popStr(QueueObj* self) {
/* add bottom */
obj_setInt(self, "bottom", bottom + 1);
return obj_getStr(self, bottomStr);
}
}

View File

@ -18,4 +18,4 @@ PikaObj* queueObj_popObj(QueueObj* self);
PikaObj* queueObj_getCurrentObj(QueueObj* self);
#endif
#endif

View File

@ -31,4 +31,4 @@ char* stack_popStr(Stack* queue, char* outBuff) {
strcpy(outBuff, args_getStr(args, topStr));
args_removeArg(args, args_getArg(args, topStr));
return outBuff;
}
}

View File

@ -13,4 +13,4 @@ int32_t stack_deinit(Stack* stack);
int32_t stack_pushStr(Stack* stack, char* str);
char* stack_popStr(Stack* queue, char* outBuff);
#endif
#endif

View File

@ -130,7 +130,6 @@ char* strGetLastLine(char* strOut, char* strIn) {
char* strGetLastToken(char* strOut, char* strIn, char sign) {
int32_t size = strGetSize(strIn);
int32_t isGetSign = 0;
int32_t buffSize = 0;
for (int32_t i = size - 1; i > -1; i--) {
if (strIn[i] != sign) {
@ -138,7 +137,6 @@ char* strGetLastToken(char* strOut, char* strIn, char sign) {
buffSize++;
}
if (strIn[i] == sign) {
isGetSign = 1;
break;
}
}