This commit is contained in:
lyon 2021-11-14 22:22:04 +08:00
commit 08a6708cb6
36 changed files with 76 additions and 58 deletions

View File

@ -92,4 +92,4 @@ void PikaPiZero_RGB_flow(PikaObj* self) {
exit:
obj_setInt(self, "flowState", (flowState + 1) % 4);
}
}

View File

@ -1,3 +1,3 @@
#include <stdint.h>
void RGB_set(uint32_t G8R8B8);
void RGB_set(uint32_t G8R8B8);

View File

@ -103,4 +103,4 @@ void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
void PikaStdDevice_GPIO_platformRead(PikaObj *self){
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
}

View File

@ -26,4 +26,4 @@ void PikaStdDevice_ADC_platformEnable(PikaObj* self) {
void PikaStdDevice_ADC_platformRead(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
}

View File

@ -8,4 +8,4 @@ void PikaStdDevice_Time_sleep_ms(PikaObj* self, int ms) {
void PikaStdDevice_Time_sleep_s(PikaObj* self, int s) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
}

View File

@ -36,4 +36,4 @@ void PikaStdDevice_UART_platformRead(PikaObj* self) {
void PikaStdDevice_UART_platformWrite(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
}

View File

@ -169,4 +169,4 @@ int STM32_lowLevel_readPin(PikaObj* self, char* pin) {
obj_setSysOut(self, "[error] not match gpio pin.");
}
return LL_GPIO_IsInputPinSet(gpioPort, gpioPin);
}
}

View File

@ -11,4 +11,4 @@ void STM32_Time_sleep_s(PikaObj* self, int s) {
for (int i = 0; i < s; i++) {
HAL_Delay(1000);
}
}
}

View File

@ -166,7 +166,6 @@ void STM32_UART_platformRead(PikaObj* self) {
memcpy(rx_buff, rx_buff + length, *rx_offset - length);
*rx_offset -= length;
rx_buff[*rx_offset] = 0;
exit:
args_deinit(buffs);
obj_setStr(self, "readData", readBuff);
}

View File

@ -165,4 +165,4 @@ uint8_t GPIO_enable_clock(char* pin) {
return 0;
}
return 1;
}
}

View File

@ -90,4 +90,4 @@ uint8_t GPIO_enable_clock(char* pin);
void delay_us(uint32_t delay);
void delay_unit(uint32_t delay);
#endif
#endif

View File

@ -83,7 +83,6 @@ int main(void) {
/* boot pikaScript */
char* code = (char*)FLASH_SCRIPT_START_ADDR;
uint16_t codeOffset = 0;
if (code[0] != 0xFF) {
/* boot from flash */
pikaMain = newRootObj("pikaMain", New_PikaMain);
@ -207,4 +206,5 @@ void assert_failed(uint8_t* file, uint32_t line) {
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -29,7 +29,7 @@
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
Stack_Size EQU 0x340
Stack_Size EQU 0x300
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size

View File

@ -165,7 +165,7 @@ int32_t __platformSavePikaAsmEOF() {
/* support download python script by uart1 */
CodeHeap codeHeap;
void STM32_Code_Init() {
void STM32_Code_Init(void) {
codeHeap.size = 0;
codeHeap.content = pikaMalloc(codeHeap.size + 1);
codeHeap.ena = 0;
@ -195,7 +195,7 @@ uint8_t STM32_Code_reciveHandler(char* data, uint32_t rxSize) {
return 0;
}
void STM32_Code_flashHandler() {
void STM32_Code_flashHandler(void) {
if (!codeHeap.ena) {
/* recive not activate */
return;

View File

@ -51,9 +51,9 @@ void HARDWARE_PRINTF_Init(void);
/* support download python script by uart1 */
uint8_t STM32_Code_reciveHandler(char* data, uint32_t rxSize);
void STM32_Code_Init();
void STM32_Code_flashHandler();
void STM32_Code_Init(void);
void STM32_Code_flashHandler(void);
/* handler for usart1 */
void __PIKA_USART1_IRQHandler(char rx_char);
#endif
#endif

0
port/linux/api-make-linux.sh Executable file → Normal file
View File

0
port/linux/api-make-win10.sh Executable file → Normal file
View File

0
port/linux/api-make.sh Executable file → Normal file
View File

0
port/linux/gtest.sh Executable file → Normal file
View File

0
port/linux/init.sh Executable file → Normal file
View File

0
port/linux/make.sh Executable file → Normal file
View File

0
port/linux/package/pikascript/rust-msc-latest-linux Executable file → Normal file
View File

0
port/linux/pull-core.sh Executable file → Normal file
View File

0
port/linux/push-core.sh Executable file → Normal file
View File

0
port/linux/test-banchmark.sh Executable file → Normal file
View File

0
port/linux/update-compiler.sh Executable file → Normal file
View File

View File

@ -232,11 +232,12 @@ Arg* obj_getMethod(PikaObj* obj, char* methodPath) {
Args* buffs = New_strBuff();
char* methodName = strsGetLastToken(buffs, methodPath, '.');
method = obj_getArg(obj, methodName);
PikaObj* methodHostClass;
if (NULL != method) {
method = arg_copy(method);
goto exit;
}
PikaObj* methodHostClass = obj_getClassObj(obj);
methodHostClass = obj_getClassObj(obj);
method = arg_copy(obj_getArg(methodHostClass, methodName));
obj_deinit(methodHostClass);
exit:
@ -246,7 +247,7 @@ exit:
PikaObj* obj_getClassObj(PikaObj* obj) {
Args* buffs = New_strBuff();
void* classPtr = obj_getPtr(obj, "_clsptr");
NewFun classPtr = (NewFun)obj_getPtr(obj, "_clsptr");
char* classObjName = strsAppend(buffs, "_cls-", "");
PikaObj* classObj = obj_getClassObjByNewFun(obj, classObjName, classPtr);
args_deinit(buffs);
@ -256,7 +257,7 @@ PikaObj* obj_getClassObj(PikaObj* obj) {
void* getNewClassObjFunByName(PikaObj* obj, char* name) {
char* classPath = name;
/* init the subprocess */
void* (*newClassObjFun)(Args * initArgs) =
void * newClassObjFun=
args_getPtr(obj->list, classPath);
return newClassObjFun;
}
@ -282,15 +283,17 @@ PikaObj* newRootObj(char* name, NewFun newObjFun) {
PikaObj* initObj(PikaObj* obj, char* name) {
PikaObj* res = NULL;
NewFun newObjFun = getNewClassObjFunByName(obj, name);
NewFun newObjFun = (NewFun) getNewClassObjFunByName(obj, name);
Args* buffs = New_args(NULL);
PikaObj* thisClass;
PikaObj* newObj;
if (NULL == newObjFun) {
/* no such object */
res = NULL;
goto exit;
}
PikaObj* thisClass = obj_getClassObjByNewFun(obj, name, newObjFun);
PikaObj* newObj = removeMethodInfo(thisClass);
thisClass = obj_getClassObjByNewFun(obj, name, newObjFun);
newObj = removeMethodInfo(thisClass);
args_setPtrWithType(obj->list, name, "c", newObj);
res = obj_getPtr(obj, name);
@ -346,7 +349,7 @@ void* methodArg_getPtr(Arg* method_arg) {
char* methodArg_getDec(Arg* method_arg) {
uint32_t size_ptr = sizeof(void*);
void* info = arg_getContent(method_arg);
return info + size_ptr;
return (char *)((uint64_t)info + size_ptr);
}
void obj_saveMethodInfo(PikaObj* self,
@ -362,7 +365,7 @@ void obj_saveMethodInfo(PikaObj* self,
void* info = args_getBuff(buffs, size_info);
memcpy(info, &method_ptr, size_ptr);
/* +1 to add \0 */
memcpy(info + size_ptr, pars, size_pars + 1);
memcpy((void *)((uint64_t)info + size_ptr), pars, size_pars + 1);
arg = arg_setName(arg, method_name);
arg = arg_setType(arg, "M");
arg = arg_setContent(arg, info, size_info);
@ -373,7 +376,7 @@ void obj_saveMethodInfo(PikaObj* self,
int32_t class_defineMethod(PikaObj* self,
char* declearation,
void (*methodPtr)(PikaObj* self, Args* args)) {
Method methodPtr) {
int32_t size = strGetSize(declearation);
int32_t res = 0;
Args* buffs = New_strBuff();
@ -383,12 +386,13 @@ int32_t class_defineMethod(PikaObj* self,
strGetFirstToken(args_getBuff(buffs, size), cleanDeclearation, '(');
PikaObj* methodHost = obj_getObj(self, methodPath, 1);
char* methodName;
if (NULL == methodHost) {
/* no found method object */
res = 1;
goto exit;
}
char* methodName = strsGetLastToken(buffs, methodPath, '.');
methodName = strsGetLastToken(buffs, methodPath, '.');
obj_saveMethodInfo(methodHost, methodName, cleanDeclearation, methodPtr);
res = 0;
@ -416,6 +420,8 @@ int32_t obj_removeArg(PikaObj* self, char* argPath) {
PikaObj* objHost = obj_getObj(self, argPath, 1);
PikaObj* obj = obj_getObj(self, argPath, 0);
Args* buffs = New_strBuff();
char* argName;
int32_t res;
if (NULL != obj) {
obj_deinit(obj);
}
@ -425,8 +431,8 @@ int32_t obj_removeArg(PikaObj* self, char* argPath) {
err = 1;
goto exit;
}
char* argName = strsGetLastToken(buffs, argPath, '.');
int32_t res =
argName = strsGetLastToken(buffs, argPath, '.');
res =
args_removeArg(objHost->list, args_getArg(objHost->list, argName));
if (1 == res) {
/*[error] not found arg*/
@ -443,13 +449,15 @@ int32_t obj_isArgExist(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObj(self, argPath, 1);
Args* buffs = New_strBuff();
int32_t res = 0;
char* argName;
Arg* arg;
if (NULL == obj) {
/* [error] object no found */
res = 1;
goto exit;
}
char* argName = strsGetLastToken(buffs, argPath, '.');
Arg* arg = args_getArg(obj->list, argName);
argName = strsGetLastToken(buffs, argPath, '.');
arg = args_getArg(obj->list, argName);
if (NULL == arg) {
/* no found arg */
res = 0;

View File

@ -12,7 +12,7 @@ typedef struct PikaObj_t PikaObj;
typedef PikaObj* (*NewFun)(Args* args);
typedef PikaObj* (*InitFun)(PikaObj* self, Args* args);
typedef PikaObj Parameters;
typedef void (*Method)(PikaObj* self, Args* args);
struct PikaObj_t {
/* list */
Args* list;
@ -65,7 +65,7 @@ int32_t obj_freeObj(PikaObj* self, char* subObjectName);
/* method */
int32_t class_defineMethod(PikaObj* self,
char* declearation,
void (*methodPtr)(PikaObj* self, Args* args));
Method methodPtr);
int32_t obj_removeArg(PikaObj* self, char* argPath);
int32_t obj_isArgExist(PikaObj* self, char* argPath);

View File

@ -165,7 +165,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
while (1) {
if ((methodPtr[0] == 'B') &&
(methodPtr[1] - '0' == thisBlockDeepth + 1)) {
class_defineMethod(self, data, (void*)methodPtr);
class_defineMethod(self, data, (Method)methodPtr);
break;
}
offset += gotoNextLine(methodPtr);
@ -325,13 +325,20 @@ Arg* pikaVM_runInstruct(PikaObj* self,
Arg* returnArg = NULL;
Parameters* subLocals = NULL;
char* methodPath = data;
PikaObj* methodHostObj;
Arg* method_arg;
Method methodPtr;
char* methodDec;
char* typeList;
char* methodCode;
char* sysOut;
/* return arg directly */
if (strEqu(data, "")) {
returnArg = arg_copy(queue_popArg(invokeQuene1));
goto RUN_exit;
}
/* get method host obj */
PikaObj* methodHostObj = obj_getObj(self, methodPath, 1);
methodHostObj = obj_getObj(self, methodPath, 1);
if (NULL == methodHostObj) {
methodHostObj = obj_getObj(locals, methodPath, 1);
}
@ -342,7 +349,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
goto RUN_exit;
}
/* get method */
Arg* method_arg = obj_getMethod(methodHostObj, methodPath);
method_arg = obj_getMethod(methodHostObj, methodPath);
/* assert method*/
if (NULL == method_arg) {
/* error, method no found */
@ -351,14 +358,13 @@ Arg* pikaVM_runInstruct(PikaObj* self,
goto RUN_exit;
}
/* get method Ptr */
void (*methodPtr)(PikaObj * self, Args * args) =
methodArg_getPtr(method_arg);
methodPtr = (Method) methodArg_getPtr(method_arg);
/* get method Decleartion */
char* methodDec = strsCopy(buffs, methodArg_getDec(method_arg));
methodDec = strsCopy(buffs, methodArg_getDec(method_arg));
arg_deinit(method_arg);
/* get type list */
char* typeList = strsCut(buffs, methodDec, '(', ')');
typeList = strsCut(buffs, methodDec, '(', ')');
if (typeList == NULL) {
/* typeList no found */
@ -383,7 +389,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
obj_setSysOut(methodHostObj, "");
/* run method */
char* methodCode = (char*)methodPtr;
methodCode = (char*)methodPtr;
if (methodCode[0] == 'B' && methodCode[2] == '\n') {
/* VM method */
subLocals = pikaVM_runAsmWithPars(methodHostObj, subLocals, globals,
@ -398,7 +404,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
}
/* transfer sysOut */
char* sysOut = obj_getSysOut(methodHostObj);
sysOut = obj_getSysOut(methodHostObj);
if (NULL != sysOut) {
args_setSysOut(locals->list, sysOut);
}
@ -523,6 +529,12 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
char* line = strs_getLine(buffs, programCounter);
int32_t nextAddr = lineAddr + strGetSize(line) + 1;
int32_t jmp = 0;
enum Instruct instruct;
char invokeDeepth0[2] = {0}, invokeDeepth1[2] = {0};
char* data;
Queue* invokeQuene0;
Queue* invokeQuene1;
Arg* resArg;
/* Found new script Line, clear the queues*/
if ('B' == line[0]) {
args_setErrorCode(locals->list, 0);
@ -530,15 +542,13 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
__clearInvokeQueues(locals);
goto nextLine;
}
char invokeDeepth0[2] = {0}, invokeDeepth1[2] = {0};
invokeDeepth0[0] = line[0];
invokeDeepth1[0] = line[0] + 1;
enum Instruct instruct = getInstruct(line);
char* data = line + 6;
instruct = getInstruct(line);
data = line + 6;
Queue* invokeQuene0 = args_getPtr(locals->list, invokeDeepth0);
Queue* invokeQuene1 = args_getPtr(locals->list, invokeDeepth1);
invokeQuene0 = args_getPtr(locals->list, invokeDeepth0);
invokeQuene1 = args_getPtr(locals->list, invokeDeepth1);
if (NULL == invokeQuene0) {
invokeQuene0 = New_queue();
args_setPtr(locals->list, invokeDeepth0, invokeQuene0);
@ -548,7 +558,7 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
args_setPtr(locals->list, invokeDeepth1, invokeQuene1);
}
Arg* resArg =
resArg =
pikaVM_runInstruct(self, locals, globals, instruct, data, invokeQuene0,
invokeQuene1, &jmp, programCounter);
if (NULL != resArg) {

View File

@ -33,6 +33,7 @@ void link_removeNode(Link* self, void* content) {
LinkNode* nodeToDelete = NULL;
LinkNode* nodeNow = self->firstNode;
LinkNode* priorNode = NULL;
LinkNode* nextNode;
while (1) {
if (nodeNow == content) {
nodeToDelete = nodeNow;
@ -46,7 +47,7 @@ void link_removeNode(Link* self, void* content) {
nodeNow = content_getNext(nodeNow);
}
LinkNode* nextNode = content_getNext(nodeToDelete);
nextNode = content_getNext(nodeToDelete);
if (nodeToDelete == self->firstNode) {
self->firstNode = content_getNext(nodeToDelete);
}

View File

@ -44,7 +44,7 @@ char* fast_itoa(char* buf, uint32_t val) {
return &p[val < 10];
}
Queue* New_queue() {
Queue* New_queue(void) {
Args* args = New_args(NULL);
args_setInt(args, "top", 0);
args_setInt(args, "bottom", 0);

View File

@ -8,7 +8,7 @@
#include "dataArgs.h"
typedef Args Queue;
Queue* New_queue();
Queue* New_queue(void);
int32_t queue_deinit(Queue* queue);
int32_t queue_pushInt(Queue* queue, int val);

View File

@ -1,7 +1,7 @@
#include "dataQueueObj.h"
#include "BaseObj.h"
#include "dataQueue.h"
QueueObj* New_queueObj() {
QueueObj* New_queueObj(void) {
PikaObj* self = New_PikaObj();
queueObj_init(self);
return self;

View File

@ -3,7 +3,7 @@
#include "PikaObj.h"
typedef PikaObj QueueObj;
QueueObj* New_queueObj();
QueueObj* New_queueObj(void);
int32_t queueObj_init(QueueObj* self);
int32_t queueObj_pushInt(QueueObj* self, int val);

View File

@ -1,7 +1,7 @@
#include "dataStack.h"
#include "dataQueue.h"
Stack* New_Stack() {
Stack* New_Stack(void) {
Args* args = New_args(NULL);
args_setInt(args, "top", 0);
Stack* stack = args;

View File

@ -8,7 +8,7 @@
#include "dataArgs.h"
typedef Args Stack;
Stack* New_Stack();
Stack* New_Stack(void);
int32_t stack_deinit(Stack* stack);
int32_t stack_pushStr(Stack* stack, char* str);