mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add Warning flag and solve warnings
This commit is contained in:
parent
a2eed10693
commit
5316ede928
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -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*",
|
||||
|
3
port/linux/.vscode/settings.json
vendored
3
port/linux/.vscode/settings.json
vendored
@ -9,7 +9,8 @@
|
||||
"*.tcc": "c",
|
||||
"istream": "c",
|
||||
"cstring": "cpp",
|
||||
"variant": "cpp"
|
||||
"variant": "cpp",
|
||||
"pikaplatform.h": "c"
|
||||
},
|
||||
"python.formatting.provider": "yapf"
|
||||
}
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -3,7 +3,6 @@ extern "C" {
|
||||
#include "dataArg.h"
|
||||
#include "dataString.h"
|
||||
}
|
||||
static int mem;
|
||||
|
||||
TEST(arg_test, int_) {
|
||||
Arg* arg = New_arg(NULL);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -4,7 +4,6 @@ extern "C" {
|
||||
#include "dataMemory.h"
|
||||
#include "dataStack.h"
|
||||
}
|
||||
static int mem;
|
||||
|
||||
TEST(stack, NEW) {
|
||||
Stack* s = New_Stack();
|
||||
|
@ -22,6 +22,7 @@ TEST(strs, append) {
|
||||
TEST(strs, formatInt) {
|
||||
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);
|
||||
}
|
||||
@ -32,7 +33,8 @@ TEST(strs, analizeDef) {
|
||||
char currentClassName[] = "Compiler";
|
||||
char line[] = " def analizeFile(pythonApiPath: str):";
|
||||
printInfo("currentClassName", currentClassName);
|
||||
char* defSentenceWithBlock = strsRemovePrefix(buffs, line, (char*)" def ");
|
||||
char* defSentenceWithBlock =
|
||||
strsRemovePrefix(buffs, line, (char*)" def ");
|
||||
char* defSentence = strsDeleteChar(buffs, defSentenceWithBlock, ' ');
|
||||
printInfo("defSentence", defSentence);
|
||||
char* methodName = strsGetFirstToken(buffs, defSentence, '(');
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
33
src/PikaVM.c
33
src/PikaVM.c
@ -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, 5e0, 6e0, 7e0, 8e0, 9e0, 0, 1e1, 2e1,
|
||||
3e1, 4e1, 5e1, 6e1, 7e1, 8e1, 9e1, 0, 1e2, 2e2, 3e2, 4e2, 5e2,
|
||||
6e2, 7e2, 8e2, 9e2, 0, 1e3, 2e3, 3e3, 4e3, 5e3, 6e3, 7e3, 8e3,
|
||||
9e3, 0, 1e4, 2e4, 3e4, 4e4, 5e4, 6e4, 7e4, 8e4, 9e4, 0, 1e5,
|
||||
2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5, 0, 1e6, 2e6, 3e6, 4e6,
|
||||
5e6, 6e6, 7e6, 8e6, 9e6, 0, 1e7, 2e7, 3e7, 4e7, 5e7, 6e7, 7e7,
|
||||
8e7, 9e7, 0, 1e8, 2e8, 3e8, 4e8, 5e8, 6e8, 7e8, 8e8, 9e8, 0,
|
||||
1e9, 2e9, 3e9, 4e9, 5e9, 6e9, 7e9, 8e9, 9e9,
|
||||
{0, 1e0, 2e0, 3e0, 4e0, 5e0, 6e0, 7e0, 8e0, 9e0},
|
||||
{0, 1e1, 2e1, 3e1, 4e1, 5e1, 6e1, 7e1, 8e1, 9e1},
|
||||
{0, 1e2, 2e2, 3e2, 4e2, 5e2, 6e2, 7e2, 8e2, 9e2},
|
||||
{0, 1e3, 2e3, 3e3, 4e3, 5e3, 6e3, 7e3, 8e3, 9e3},
|
||||
{0, 1e4, 2e4, 3e4, 4e4, 5e4, 6e4, 7e4, 8e4, 9e4},
|
||||
{0, 1e5, 2e5, 3e5, 4e5, 5e5, 6e5, 7e5, 8e5, 9e5},
|
||||
{0, 1e6, 2e6, 3e6, 4e6, 5e6, 6e6, 7e6, 8e6, 9e6},
|
||||
{0, 1e7, 2e7, 3e7, 4e7, 5e7, 6e7, 7e7, 8e7, 9e7},
|
||||
{0, 1e8, 2e8, 3e8, 4e8, 5e8, 6e8, 7e8, 8e8, 9e8},
|
||||
{0, 1e9, 2e9, 3e9, 4e9, 5e9, 6e9, 7e9, 8e9, 9e9},
|
||||
};
|
||||
uint16_t size = strGetSize(src);
|
||||
p = p + size - 1;
|
||||
@ -180,12 +182,10 @@ Arg* pikaVM_runInstruct(PikaObj* self,
|
||||
}
|
||||
}
|
||||
if (instruct == 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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user