rm port/linux/ src

This commit is contained in:
lyon 2022-04-27 18:02:24 +08:00
parent ea4776ae22
commit e4f1bbf7a6
41 changed files with 0 additions and 8494 deletions

View File

@ -1,100 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#define __PIKA_OBJ_CLASS_IMPLEMENT
#include "BaseObj.h"
#include "PikaObj.h"
#include "TinyObj.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr) {
Arg* argNew = New_arg(NULL);
/* m means mate-object */
argNew = arg_setPtr(argNew, objName, ARG_TYPE_MATE_OBJECT, (void*)objPtr);
return argNew;
}
int32_t obj_newObj(PikaObj* self,
char* objName,
char* className,
NewFun newFunPtr) {
/* add mate Obj, no inited */
Arg* newobj = arg_setMetaObj(objName, className, newFunPtr);
args_setArg(self->list, newobj);
return 0;
}
static void print_no_end(PikaObj* self, Args* args) {
obj_setErrorCode(self, 0);
char* res = args_print(args, "val");
if (NULL == res) {
obj_setSysOut(self, "[error] print: can not print val");
obj_setErrorCode(self, 1);
return;
}
/* not empty */
if (strIsContain(res, '\\')) {
res = strsReplace(args, res, "\\n", "\n");
res = strsReplace(args, res, "\\r", "\r");
res = strsReplace(args, res, "\\t", "\t");
}
__platform_printf("%s", res);
}
void baseobj_print(PikaObj* self, Args* args) {
obj_setErrorCode(self, 0);
Arg* print_arg = args_getArg(args, "val");
if (NULL != print_arg) {
if (arg_getType(print_arg) == ARG_TYPE_BYTES) {
arg_printBytes(print_arg);
return;
}
}
char* res = args_print(args, "val");
if (NULL == res) {
obj_setSysOut(self, "[error] print: can not print val");
obj_setErrorCode(self, 1);
return;
}
/* not empty */
if (strIsContain(res, '\\')) {
res = strsReplace(args, res, "\\n", "\n");
res = strsReplace(args, res, "\\r", "\r");
res = strsReplace(args, res, "\\t", "\t");
}
__platform_printf("%s\r\n", res);
}
PikaObj* New_BaseObj(Args* args) {
PikaObj* self = New_TinyObj(args);
class_defineMethod(self, "print(val:any)", baseobj_print);
class_defineMethod(self, "printNoEnd(val:any)", print_no_end);
return self;
}

View File

@ -1,46 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _PikaObj_baseObj__H
#define _PikaObj_baseObj__H
#include "PikaObj.h"
#include "PikaVM.h"
#include "TinyObj.h"
#include "dataMemory.h"
PikaObj* New_BaseObj(Args* args);
int32_t obj_newObjFromClassLoader(PikaObj* self,
char* objPath,
char* classPath);
int32_t obj_import(PikaObj* self, char* className, NewFun classPtr);
int32_t obj_newObj(PikaObj* self,
char* objName,
char* className,
NewFun newFunPtr);
Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr);
void baseobj_print(PikaObj* self, Args* args);
#endif

View File

@ -1,9 +0,0 @@
# BINARY IndexProject
set(BINARY ${CMAKE_PROJECT_NAME})
file(GLOB_RECURSE SOURCES LIST_DIRECTORIES true *.h *.c)
set(SOURCES ${SOURCES})
add_library(${BINARY}-core
STATIC
${SOURCES})

View File

@ -1,883 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#define __PIKA_OBJ_CLASS_IMPLEMENT
#include "PikaObj.h"
#include "BaseObj.h"
#include "PikaPlatform.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
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},
};
uint16_t size = strGetSize(src);
p = p + size - 1;
if (*p) {
int s = 0;
const uint64_t* n = a[0];
while (p != src) {
s += n[(*p - '0')];
n += 10;
p--;
}
if (*p == '-') {
return -s;
}
return s + n[(*p - '0')];
}
return 0;
}
static uint16_t const str100p[100] = {
0x3030, 0x3130, 0x3230, 0x3330, 0x3430, 0x3530, 0x3630, 0x3730, 0x3830,
0x3930, 0x3031, 0x3131, 0x3231, 0x3331, 0x3431, 0x3531, 0x3631, 0x3731,
0x3831, 0x3931, 0x3032, 0x3132, 0x3232, 0x3332, 0x3432, 0x3532, 0x3632,
0x3732, 0x3832, 0x3932, 0x3033, 0x3133, 0x3233, 0x3333, 0x3433, 0x3533,
0x3633, 0x3733, 0x3833, 0x3933, 0x3034, 0x3134, 0x3234, 0x3334, 0x3434,
0x3534, 0x3634, 0x3734, 0x3834, 0x3934, 0x3035, 0x3135, 0x3235, 0x3335,
0x3435, 0x3535, 0x3635, 0x3735, 0x3835, 0x3935, 0x3036, 0x3136, 0x3236,
0x3336, 0x3436, 0x3536, 0x3636, 0x3736, 0x3836, 0x3936, 0x3037, 0x3137,
0x3237, 0x3337, 0x3437, 0x3537, 0x3637, 0x3737, 0x3837, 0x3937, 0x3038,
0x3138, 0x3238, 0x3338, 0x3438, 0x3538, 0x3638, 0x3738, 0x3838, 0x3938,
0x3039, 0x3139, 0x3239, 0x3339, 0x3439, 0x3539, 0x3639, 0x3739, 0x3839,
0x3939,
};
char* fast_itoa(char* buf, uint32_t val) {
char* p = &buf[10];
*p = '\0';
while (val >= 100) {
uint32_t const old = val;
p -= 2;
val /= 100;
__platform_memcpy(p, &str100p[old - (val * 100)], sizeof(uint16_t));
}
p -= 2;
__platform_memcpy(p, &str100p[val], sizeof(uint16_t));
return &p[val < 10];
}
int32_t obj_deinit(PikaObj* self) {
/* free the list */
args_deinit(self->list);
/* free the pointer */
pikaFree(self, sizeof(PikaObj));
self = NULL;
return 0;
}
int32_t obj_enable(PikaObj* self) {
obj_setInt(self, "isEnable", 1);
return 0;
}
int32_t obj_disable(PikaObj* self) {
obj_setInt(self, "isEnable", 0);
return 0;
}
int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
/* [error] object no found */
return 1;
}
char* name = strPointToLastToken(argPath, '.');
args_setInt(obj->list, name, val);
return 0;
}
int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return 1;
}
char* name = strPointToLastToken(argPath, '.');
args_setPtr(obj->list, name, pointer);
return 0;
}
int32_t obj_setRefObject(PikaObj* self, char* argPath, void* pointer) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return 1;
}
char* name = strPointToLastToken(argPath, '.');
args_setRefObj(obj->list, name, pointer);
return 0;
}
int32_t obj_setFloat(PikaObj* self, char* argPath, float value) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return 1;
}
char* name = strPointToLastToken(argPath, '.');
args_setFloat(obj->list, name, value);
return 0;
}
int32_t obj_setStr(PikaObj* self, char* argPath, char* str) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return 1;
}
char* name = strPointToLastToken(argPath, '.');
args_setStr(obj->list, name, str);
return 0;
}
int32_t obj_setBytes(PikaObj* self, char* argPath, uint8_t* src, size_t size) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return 1;
}
char* name = strPointToLastToken(argPath, '.');
args_setBytes(obj->list, name, src, size);
return 0;
}
int64_t obj_getInt(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return -999999999;
}
char* argName = strPointToLastToken(argPath, '.');
int res = args_getInt(obj->list, argName);
return res;
}
Arg* obj_getArg(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return NULL;
}
char* argName = strPointToLastToken(argPath, '.');
Arg* res = args_getArg(obj->list, argName);
return res;
}
uint8_t* obj_getBytes(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return NULL;
}
char* argName = strPointToLastToken(argPath, '.');
return args_getBytes(obj->list, argName);
}
size_t obj_getBytesSize(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return 0;
}
char* argName = strPointToLastToken(argPath, '.');
return args_getBytesSize(obj->list, argName);
}
size_t obj_loadMem(PikaObj* self, char* argPath, uint8_t* out_buff) {
size_t size_mem = obj_getBytesSize(self, argPath);
void* src = obj_getBytes(self, argPath);
if (0 == size_mem) {
return 0;
}
if (NULL == src) {
return 0;
}
__platform_memcpy(out_buff, src, size_mem);
return size_mem;
}
static int32_t __obj_setArg(PikaObj* self,
char* argPath,
Arg* arg,
uint8_t is_copy) {
/* setArg would copy arg */
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
/* object no found */
return 1;
}
char* argName = strPointToLastToken(argPath, '.');
Arg* newArg;
if (is_copy) {
newArg = arg_copy(arg);
} else {
newArg = arg;
}
newArg = arg_setName(newArg, argName);
args_setArg(obj->list, newArg);
return 0;
}
int32_t obj_setArg(PikaObj* self, char* argPath, Arg* arg) {
return __obj_setArg(self, argPath, arg, 1);
};
int32_t obj_setArg_noCopy(PikaObj* self, char* argPath, Arg* arg) {
return __obj_setArg(self, argPath, arg, 0);
}
void* obj_getPtr(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return NULL;
}
char* argName = strPointToLastToken(argPath, '.');
void* res = args_getPtr(obj->list, argName);
return res;
}
float obj_getFloat(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return -999.999;
}
char* argName = strPointToLastToken(argPath, '.');
float res = args_getFloat(obj->list, argName);
return res;
}
char* obj_getStr(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
if (NULL == obj) {
return NULL;
}
char* argName = strPointToLastToken(argPath, '.');
char* res = args_getStr(obj->list, argName);
return res;
}
int32_t obj_load(PikaObj* self, Args* args, char* name) {
args_copyArgByName(args, name, self->list);
return 0;
}
int32_t obj_freeObj(PikaObj* self, char* objPath) {
PikaObj* obj = obj_getPtr(self, objPath);
obj_deinit(obj);
return 0;
}
char* obj_print(PikaObj* self, char* name) {
if (NULL == self) {
return NULL;
}
return args_print(self->list, name);
}
PikaObj* obj_getClassObjByNewFun(PikaObj* context,
char* name,
NewFun newClassFun) {
Args* initArgs = New_args(NULL);
PikaObj* thisClass = newClassFun(initArgs);
obj_setPtr(thisClass, "_clsptr", (void*)newClassFun);
obj_setInt(thisClass, "_refcnt", 0);
args_deinit(initArgs);
return thisClass;
}
Arg* obj_getMethodArg(PikaObj* obj, char* methodPath) {
Arg* method = NULL;
char* methodName = strPointToLastToken(methodPath, '.');
method = obj_getArg(obj, methodName);
PikaObj* methodHostClass;
if (NULL != method) {
method = arg_copy(method);
goto exit;
}
methodHostClass = obj_getClassObj(obj);
method = arg_copy(obj_getArg(methodHostClass, methodName));
obj_deinit(methodHostClass);
exit:
return method;
}
PikaObj* obj_getClassObj(PikaObj* obj) {
NewFun classPtr = (NewFun)obj_getPtr(obj, "_clsptr");
PikaObj* classObj = obj_getClassObjByNewFun(obj, "", classPtr);
return classObj;
}
void* getNewClassObjFunByName(PikaObj* obj, char* name) {
char* classPath = name;
/* init the subprocess */
void* newClassObjFun = args_getPtr(obj->list, classPath);
return newClassObjFun;
}
int32_t __foreach_removeMethodInfo(Arg* argNow, Args* argList) {
if (arg_getType(argNow) == ARG_TYPE_NATIVE_METHOD) {
args_removeArg(argList, argNow);
return 0;
}
return 0;
}
PikaObj* removeMethodInfo(PikaObj* thisClass) {
#if PIKA_METHOD_CACHE_ENABLE
#else
args_foreach(thisClass->list, __foreach_removeMethodInfo, thisClass->list);
#endif
return thisClass;
}
PikaObj* obj_newObjDirect(NewFun newObjFun) {
PikaObj* thisClass = obj_getClassObjByNewFun(NULL, "", newObjFun);
obj_refcntInc(thisClass);
return removeMethodInfo(thisClass);
}
extern PikaObj* __pikaMain;
PikaObj* newRootObj(char* name, NewFun newObjFun) {
PikaObj* newObj = obj_newObjDirect(newObjFun);
__pikaMain = newObj;
return newObj;
}
Arg* obj_getRefArg(PikaObj* self) {
return arg_setPtr(NULL, "", ARG_TYPE_FREE_OBJECT, self);
}
Arg* obj_newObjArg(NewFun newObjFun) {
PikaObj* newObj = obj_newObjDirect(newObjFun);
Arg* objArg = arg_setPtr(NULL, "", ARG_TYPE_FREE_OBJECT, newObj);
return objArg;
}
Arg* obj_newObjInPackage(NewFun newObjFun) {
return obj_newObjArg(newObjFun);
}
static PikaObj* __initObj(PikaObj* obj, char* name) {
PikaObj* res = NULL;
NewFun constructor = (NewFun)getNewClassObjFunByName(obj, name);
Args buffs = {0};
PikaObj* thisClass;
PikaObj* new_obj;
if (NULL == constructor) {
/* no such object */
res = NULL;
goto exit;
}
thisClass = obj_getClassObjByNewFun(obj, name, constructor);
new_obj = removeMethodInfo(thisClass);
obj_refcntInc(new_obj);
args_setPtrWithType(obj->list, name, ARG_TYPE_OBJECT, new_obj);
res = obj_getPtr(obj, name);
goto exit;
exit:
strsDeinit(&buffs);
return res;
}
PikaObj* obj_getObjDirect(PikaObj* self, char* name) {
if (NULL == self) {
return NULL;
}
/* finded object, check type*/
ArgType type = args_getType(self->list, name);
/* found mate Object */
if (type == ARG_TYPE_MATE_OBJECT) {
return __initObj(self, name);
}
/* found Objcet */
if (type == ARG_TYPE_OBJECT) {
return args_getPtr(self->list, name);
}
return NULL;
}
PikaObj* obj_getObjWithKeepDeepth(PikaObj* self,
char* objPath,
int32_t keepDeepth) {
char objPath_buff[PIKA_PATH_BUFF_SIZE];
__platform_memcpy(objPath_buff, objPath, strGetSize(objPath) + 1);
char token_buff[PIKA_NAME_BUFF_SIZE] = {0};
int32_t token_num = strGetTokenNum(objPath, '.');
PikaObj* obj = self;
for (int32_t i = 0; i < token_num - keepDeepth; i++) {
char* token = strPopToken(token_buff, objPath_buff, '.');
obj = obj_getObjDirect(obj, token);
if (obj == NULL) {
goto exit;
}
}
goto exit;
exit:
return obj;
}
PikaObj* obj_getObj(PikaObj* self, char* objPath) {
return obj_getObjWithKeepDeepth(self, objPath, 0);
}
Method methodArg_getPtr(Arg* method_arg) {
uint32_t size_ptr = sizeof(void*);
void* info = arg_getContent(method_arg);
void* ptr = NULL;
__platform_memcpy(&ptr, info, size_ptr);
return (Method)ptr;
}
char* methodArg_getTypeList(Arg* method_arg, Args* buffs) {
char* method_dec = strsCopy(buffs, methodArg_getDec(method_arg));
return strsCut(buffs, method_dec, '(', ')');
}
Method obj_getNativeMethod(PikaObj* self, char* method_name) {
Arg* method_arg = obj_getMethodArg(self, method_name);
if (NULL == method_arg) {
return NULL;
}
Method res = methodArg_getPtr(method_arg);
arg_deinit(method_arg);
return res;
}
ByteCodeFrame* methodArg_getBytecodeFrame(Arg* method_arg) {
uint32_t size_ptr = sizeof(void*);
void* info = arg_getContent(method_arg) + size_ptr;
ByteCodeFrame* ptr = NULL;
__platform_memcpy(&ptr, info, size_ptr);
return ptr;
}
char* methodArg_getDec(Arg* method_arg) {
uint32_t size_ptr = sizeof(void*);
void* info = arg_getContent(method_arg);
return (char*)((uintptr_t)info + 2 * size_ptr);
}
static void obj_saveMethodInfo(PikaObj* self, MethodInfo* method_info) {
Args buffs = {0};
char* pars = strsRemovePrefix(&buffs, method_info->dec, method_info->name);
method_info->pars = pars;
Arg* arg = New_arg(NULL);
uint32_t size_pars = strGetSize(pars);
uintptr_t method_info_bytecode_frame =
(uintptr_t)method_info->bytecode_frame;
arg =
arg_setPtr(arg, method_info->name, method_info->type, method_info->ptr);
arg = arg_append(arg, &(method_info_bytecode_frame),
sizeof(method_info_bytecode_frame));
arg = arg_append(arg, method_info->pars, size_pars + 1);
args_setArg(self->list, arg);
strsDeinit(&buffs);
}
static int32_t __class_defineMethodWithType(PikaObj* self,
char* declearation,
Method methodPtr,
ArgType method_type,
ByteCodeFrame* bytecode_frame) {
int32_t size = strGetSize(declearation);
int32_t res = 0;
Args buffs = {0};
char* cleanDeclearation =
strDeleteChar(args_getBuff(&buffs, size), declearation, ' ');
char* methodPath =
strGetFirstToken(args_getBuff(&buffs, size), cleanDeclearation, '(');
PikaObj* methodHost = obj_getObjWithKeepDeepth(self, methodPath, 1);
MethodInfo method_info = {0};
char* methodName;
if (NULL == methodHost) {
/* no found method object */
res = 1;
goto exit;
}
methodName = strPointToLastToken(methodPath, '.');
method_info.dec = cleanDeclearation;
method_info.name = methodName;
method_info.ptr = (void*)methodPtr;
method_info.type = method_type;
method_info.bytecode_frame = bytecode_frame;
obj_saveMethodInfo(methodHost, &method_info);
res = 0;
goto exit;
exit:
strsDeinit(&buffs);
return res;
}
/* define a constructor method */
int32_t class_defineConstructor(PikaObj* self,
char* declearation,
Method methodPtr) {
return __class_defineMethodWithType(self, declearation, methodPtr,
ARG_TYPE_NATIVE_CONSTRUCTOR_METHOD,
NULL);
}
/* define a native method as default */
int32_t class_defineMethod(PikaObj* self,
char* declearation,
Method methodPtr) {
return __class_defineMethodWithType(self, declearation, methodPtr,
ARG_TYPE_NATIVE_METHOD, NULL);
}
/* define object method, object method is which startwith (self) */
int32_t class_defineRunTimeConstructor(PikaObj* self,
char* declearation,
Method methodPtr,
ByteCodeFrame* bytecode_frame) {
return __class_defineMethodWithType(self, declearation, methodPtr,
ARG_TYPE_CONSTRUCTOR_METHOD,
bytecode_frame);
}
/* define object method, object method is which startwith (self) */
int32_t class_defineObjectMethod(PikaObj* self,
char* declearation,
Method methodPtr,
ByteCodeFrame* bytecode_frame) {
return __class_defineMethodWithType(self, declearation, methodPtr,
ARG_TYPE_OBJECT_METHOD, bytecode_frame);
}
/* define a static method as default */
int32_t class_defineStaticMethod(PikaObj* self,
char* declearation,
Method methodPtr,
ByteCodeFrame* bytecode_frame) {
return __class_defineMethodWithType(self, declearation, methodPtr,
ARG_TYPE_STATIC_METHOD, bytecode_frame);
}
PIKA_WEAK int __runExtern_contral(PikaObj* self, char* cmd) {
return 0;
}
VMParameters* obj_runDirect(PikaObj* self, char* cmd) {
return pikaVM_run(self, cmd);
}
int32_t obj_removeArg(PikaObj* self, char* argPath) {
PikaObj* objHost = obj_getObjWithKeepDeepth(self, argPath, 1);
char* argName;
int32_t res;
int32_t err = 0;
if (NULL == objHost) {
/* [error] object no found */
err = 1;
goto exit;
}
argName = strPointToLastToken(argPath, '.');
res = args_removeArg(objHost->list, args_getArg(objHost->list, argName));
if (1 == res) {
/*[error] not found arg*/
err = 2;
goto exit;
}
goto exit;
exit:
return err;
}
int32_t obj_isArgExist(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getObjWithKeepDeepth(self, argPath, 1);
int32_t res = 0;
char* argName;
Arg* arg;
if (NULL == obj) {
/* [error] object no found */
res = 1;
goto exit;
}
argName = strPointToLastToken(argPath, '.');
arg = args_getArg(obj->list, argName);
if (NULL == arg) {
/* no found arg */
res = 0;
goto exit;
}
/* found arg */
res = 1;
goto exit;
exit:
return res;
}
void obj_runNoRes(PikaObj* slef, char* cmd) {
/* unsafe, nothing would happend when error occord */
obj_runDirect(slef, cmd);
}
void obj_run(PikaObj* self, char* cmd) {
obj_runDirect(self, cmd);
}
void obj_runNativeMethod(PikaObj* self, char* method_name, Args* args) {
Method native_method = obj_getNativeMethod(self, method_name);
if (NULL == native_method) {
return;
}
native_method(self, args);
}
static void __clearBuff(char* buff, int size) {
for (int i = 0; i < size; i++) {
buff[i] = 0;
}
}
void obj_shellLineProcess(PikaObj* self,
__obj_shellLineHandler_t __lineHandler_fun,
struct shell_config* cfg) {
Args buffs = {0};
char* rxBuff = args_getBuff(&buffs, PIKA_LINE_BUFF_SIZE);
char* input_line = NULL;
uint8_t is_in_block = 0;
__platform_printf(cfg->prefix);
while (1) {
char inputChar = __platform_getchar();
#ifndef __linux
__platform_printf("%c", inputChar);
#endif
if ((inputChar == '\b') || (inputChar == 127)) {
uint32_t size = strGetSize(rxBuff);
if (size == 0) {
__platform_printf(" ");
continue;
}
__platform_printf(" \b");
rxBuff[size - 1] = 0;
continue;
}
if (inputChar != '\r' && inputChar != '\n') {
strAppendWithSize(rxBuff, &inputChar, 1);
continue;
}
if ((inputChar == '\r') || (inputChar == '\n')) {
#ifndef __linux
__platform_printf("\r\n");
#endif
/* still in block */
if (is_in_block) {
/* load new line into buff */
Args buffs = {0};
char _n = '\n';
strAppendWithSize(rxBuff, &_n, 1);
char* shell_buff_new =
strsAppend(&buffs, obj_getStr(self, "shell_buff"), rxBuff);
obj_setStr(self, "shell_buff", shell_buff_new);
strsDeinit(&buffs);
/* go out from block */
if (rxBuff[0] != ' ') {
is_in_block = 0;
input_line = obj_getStr(self, "shell_buff");
if (SHELL_STATE_EXIT ==
__lineHandler_fun(self, input_line)) {
break;
}
__platform_printf(">>> ");
} else {
__platform_printf("... ");
}
__clearBuff(rxBuff, PIKA_LINE_BUFF_SIZE);
continue;
}
if (0 != strGetSize(rxBuff)) {
/* go in block */
if (rxBuff[strGetSize(rxBuff) - 1] == ':') {
is_in_block = 1;
char _n = '\n';
strAppendWithSize(rxBuff, &_n, 1);
obj_setStr(self, "shell_buff", rxBuff);
__clearBuff(rxBuff, PIKA_LINE_BUFF_SIZE);
__platform_printf("... ");
continue;
}
}
input_line = rxBuff;
if (SHELL_STATE_EXIT == __lineHandler_fun(self, input_line)) {
break;
}
__platform_printf(cfg->prefix);
__clearBuff(rxBuff, PIKA_LINE_BUFF_SIZE);
continue;
}
}
strsDeinit(&buffs);
}
static enum shell_state __obj_shellLineHandler_debuger(PikaObj* self,
char* input_line) {
/* exit */
if (strEqu("exit()", input_line)) {
/* exit pika shell */
return SHELL_STATE_EXIT;
}
/* run single line */
obj_run(self, input_line);
return SHELL_STATE_CONTINUE;
}
void pikaScriptShell(PikaObj* self) {
struct shell_config cfg = {
.prefix = ">>> ",
};
obj_shellLineProcess(self, __obj_shellLineHandler_debuger, &cfg);
}
void obj_setErrorCode(PikaObj* self, int32_t errCode) {
obj_setInt(self, "__errCode", errCode);
}
int32_t obj_getErrorCode(PikaObj* self) {
if (!obj_isArgExist(self, "__errCode")) {
return 0;
}
return obj_getInt(self, "__errCode");
}
void args_setErrorCode(Args* args, int32_t errCode) {
args_setInt(args, "__errCode", errCode);
}
int32_t args_getErrorCode(Args* args) {
if (!args_isArgExist(args, "__errCode")) {
return 0;
}
return args_getInt(args, "__errCode");
}
void obj_setSysOut(PikaObj* self, char* str) {
// obj_setStr(self, "__sysOut", str);
args_setSysOut(self->list, str);
}
char* obj_getSysOut(PikaObj* self) {
return obj_getStr(self, "__sysOut");
}
char* args_getSysOut(Args* args) {
return args_getStr(args, "__sysOut");
}
void args_setSysOut(Args* args, char* str) {
// args_setStr(args, "__sysOut", str);
if (NULL == str) {
return;
}
if (strEqu("", str)) {
return;
}
__platform_printf("%s\r\n", str);
}
void obj_sysPrintf(PikaObj* self, char* fmt, ...) {
va_list args;
va_start(args, fmt);
char sysOut[128] = {0};
__platform_vsprintf(sysOut, fmt, args);
obj_setSysOut(self, sysOut);
va_end(args);
}
void method_returnBytes(Args* args, uint8_t* val) {
args_setBytes(args, "return", val, PIKA_BYTES_DEFAULT_SIZE);
}
void method_returnStr(Args* args, char* val) {
args_setStr(args, "return", val);
}
void method_returnInt(Args* args, int32_t val) {
args_setInt(args, "return", val);
}
void method_returnFloat(Args* args, float val) {
args_setFloat(args, "return", val);
}
void method_returnPtr(Args* args, void* val) {
args_setPtr(args, "return", val);
}
void method_returnArg(Args* args, Arg* arg) {
arg = arg_setName(arg, "return");
args_setArg(args, arg);
}
int32_t method_getInt(Args* args, char* argName) {
return args_getInt(args, argName);
}
float method_getFloat(Args* args, char* argName) {
return args_getFloat(args, argName);
}
char* method_getStr(Args* args, char* argName) {
return args_getStr(args, argName);
}
PikaObj* New_PikaObj(void) {
PikaObj* self = pikaMalloc(sizeof(PikaObj));
/* List */
self->list = New_args(NULL);
return self;
}
void obj_refcntInc(PikaObj* self) {
obj_setInt(self, "_refcnt", obj_getInt(self, "_refcnt") + 1);
}
void obj_refcntDec(PikaObj* self) {
obj_setInt(self, "_refcnt", obj_getInt(self, "_refcnt") - 1);
}
int obj_refcntNow(PikaObj* self) {
return obj_getInt(self, "_refcnt");
}
Arg* arg_setRefObj(Arg* self, char* name, PikaObj* obj) {
obj_refcntInc(obj);
return arg_setPtr(self, name, ARG_TYPE_OBJECT, obj);
}
Arg* arg_setWeakRefObj(Arg* self, char* name, PikaObj* obj) {
return arg_setPtr(self, name, ARG_TYPE_OBJECT, obj);
}

View File

@ -1,241 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _Process__H
#define _Process__H
/*! \NOTE: Make sure #include "plooc_class.h" is close to the class definition
*/
//#define __PLOOC_CLASS_USE_STRICT_TEMPLATE__
#if defined(__PIKA_OBJ_CLASS_IMPLEMENT)
#define __PLOOC_CLASS_IMPLEMENT__
#elif defined(__PIKA_OBJ_CLASS_INHERIT__)
#define __PLOOC_CLASS_INHERIT__
#endif
#include "__pika_ooc.h"
#include "dataArgs.h"
#include "dataLink.h"
#include "dataMemory.h"
typedef struct InstructUnit_t {
uint8_t deepth;
uint8_t isNewLine_instruct;
uint16_t const_pool_index;
} InstructUnit;
typedef struct ConstPool_t ConstPool;
struct ConstPool_t {
Arg* arg_buff;
uint16_t content_offset_now;
uint16_t size;
void* content_start;
void (*output_redirect_fun)(ConstPool* self, char* content);
FILE* output_f;
};
typedef struct InstructArray_t InstructArray;
struct InstructArray_t {
Arg* arg_buff;
uint16_t content_offset_now;
uint16_t size;
void* content_start;
void (*output_redirect_fun)(InstructArray* self, InstructUnit* ins_unit);
FILE* output_f;
};
typedef struct ByteCodeFrame_t {
ConstPool const_pool;
InstructArray instruct_array;
} ByteCodeFrame;
typedef struct PikaObj_t {
/* list */
Args* list;
} PikaObj;
typedef PikaObj* (*NewFun)(Args* args);
typedef PikaObj* (*InitFun)(PikaObj* self, Args* args);
typedef PikaObj VMParameters;
typedef void (*Method)(PikaObj* self, Args* args);
typedef struct MethodInfo_t {
char* name;
char* dec;
char* ptr;
char* pars;
ArgType type;
ByteCodeFrame* bytecode_frame;
} MethodInfo;
/* operation */
int32_t obj_deinit(PikaObj* self);
int32_t obj_init(PikaObj* self, Args* args);
int32_t obj_update(PikaObj* self);
int32_t obj_enable(PikaObj* self);
int32_t obj_disable(PikaObj* self);
// arg type operations
int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val);
int32_t obj_setRefObject(PikaObj* self, char* argPath, void* pointer);
int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer);
int32_t obj_setFloat(PikaObj* self, char* argPath, float value);
int32_t obj_setStr(PikaObj* self, char* argPath, char* str);
int32_t obj_setArg(PikaObj* self, char* argPath, Arg* arg);
int32_t obj_setArg_noCopy(PikaObj* self, char* argPath, Arg* arg);
int32_t obj_setBytes(PikaObj* self, char* argPath, uint8_t* src, size_t size);
void* obj_getPtr(PikaObj* self, char* argPath);
float obj_getFloat(PikaObj* self, char* argPath);
char* obj_getStr(PikaObj* self, char* argPath);
int64_t obj_getInt(PikaObj* self, char* argPath);
Arg* obj_getArg(PikaObj* self, char* argPath);
uint8_t* obj_getBytes(PikaObj* self, char* argPath);
size_t obj_getBytesSize(PikaObj* self, char* argPath);
size_t obj_loadMem(PikaObj* self, char* argPath, uint8_t* out_buff);
char* obj_print(PikaObj* self, char* name);
// args operations
int32_t obj_load(PikaObj* self, Args* args, char* name);
// subObject
int32_t obj_addOther(PikaObj* self, char* subObjectName, void* new_projcetFun);
int32_t obj_setObjWithoutClass(PikaObj* self,
char* subObjectName,
void* new_projcetFun);
PikaObj* obj_getObjDirect(PikaObj* self, char* name);
PikaObj* obj_getObjWithKeepDeepth(PikaObj* self, char* objPath, int32_t deepth);
PikaObj* obj_getObj(PikaObj* self, char* objPath);
// subProcess
int32_t obj_freeObj(PikaObj* self, char* subObjectName);
/* method */
int32_t class_defineMethod(PikaObj* self, char* declearation, Method methodPtr);
int32_t class_defineObjectMethod(PikaObj* self,
char* declearation,
Method methodPtr,
ByteCodeFrame* bytecode_frame);
int32_t class_defineStaticMethod(PikaObj* self,
char* declearation,
Method methodPtr,
ByteCodeFrame* bytecode_frame);
int32_t class_defineConstructor(PikaObj* self,
char* declearation,
Method methodPtr);
int32_t class_defineRunTimeConstructor(PikaObj* self,
char* declearation,
Method methodPtr,
ByteCodeFrame* bytecode_frame);
int32_t obj_removeArg(PikaObj* self, char* argPath);
int32_t obj_isArgExist(PikaObj* self, char* argPath);
PikaObj* obj_getClassObjByNewFun(PikaObj* self, char* name, NewFun newClassFun);
PikaObj* newRootObj(char* name, NewFun newObjFun);
PikaObj* obj_getClassObj(PikaObj* obj);
Arg* obj_getMethodArg(PikaObj* obj, char* methodPath);
void obj_setErrorCode(PikaObj* self, int32_t errCode);
int32_t obj_getErrorCode(PikaObj* self);
void obj_setSysOut(PikaObj* self, char* str);
char* args_getSysOut(Args* args);
void args_setErrorCode(Args* args, int32_t errCode);
int32_t args_getErrorCode(Args* args);
void args_setSysOut(Args* args, char* str);
char* obj_getSysOut(PikaObj* self);
void obj_sysPrintf(PikaObj* self, char* fmt, ...);
uint8_t obj_getAnyArg(PikaObj* self,
char* targetArgName,
char* sourceArgPath,
Args* targetArgs);
void method_returnStr(Args* args, char* val);
void method_returnInt(Args* args, int32_t val);
void method_returnFloat(Args* args, float val);
void method_returnPtr(Args* args, void* val);
int32_t method_getInt(Args* args, char* argName);
float method_getFloat(Args* args, char* argName);
char* method_getStr(Args* args, char* argName);
void method_returnArg(Args* args, Arg* arg);
char* methodArg_getDec(Arg* method_arg);
char* methodArg_getTypeList(Arg* method_arg, Args* buffs);
ByteCodeFrame* methodArg_getBytecodeFrame(Arg* method_arg);
Method methodArg_getPtr(Arg* method_arg);
void obj_runNoRes(PikaObj* slef, char* cmd);
void obj_run(PikaObj* self, char* cmd);
VMParameters* obj_runDirect(PikaObj* self, char* cmd);
PikaObj* New_PikaObj(void);
/* tools */
int fast_atoi(char* src);
char* fast_itoa(char* buf, uint32_t val);
/* shell */
void pikaScriptShell(PikaObj* self);
enum shell_state { SHELL_STATE_CONTINUE, SHELL_STATE_EXIT };
typedef enum shell_state (*__obj_shellLineHandler_t)(PikaObj*, char*);
struct shell_config {
char* prefix;
};
void obj_shellLineProcess(PikaObj* self,
__obj_shellLineHandler_t __lineHandler_fun,
struct shell_config* cfg);
/*
need implament :
__platform_fopen()
__platform_fwrite()
__platform_fclose()
*/
int pikaCompile(char* output_file_name, char* py_lines);
Method obj_getNativeMethod(PikaObj* self, char* method_name);
void obj_runNativeMethod(PikaObj* self, char* method_name, Args* args);
Arg* obj_newObjArg(NewFun newObjFun);
Arg* obj_newObjInPackage(NewFun newObjFun);
void obj_refcntInc(PikaObj* self);
void obj_refcntDec(PikaObj* self);
int obj_refcntNow(PikaObj* self);
PikaObj* obj_newObjDirect(NewFun newObjFun);
Arg* arg_setRefObj(Arg* self, char* name, PikaObj* obj);
Arg* arg_setWeakRefObj(Arg* self, char* name, PikaObj* obj);
#define PIKA_PYTHON_BEGIN
#define PIKA_PYTHON(x)
#define PIKA_PYTHON_END
#endif

View File

@ -1,19 +0,0 @@
#api
class TinyObj:
pass
class BaseObj(TinyObj):
pass
class pointer:
pass
def print(val: any):
pass
def printNoEnd(val: any):
pass
def taskLoop(task: any):
pass

File diff suppressed because it is too large Load Diff

View File

@ -1,103 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __PIKA_PARSER__H
#define __PIKA_PARSER__H
#include "PikaVM.h"
#include "dataQueueObj.h"
#include "dataStack.h"
enum TokenType {
TOKEN_strEnd = 0,
TOKEN_symbol,
TOKEN_keyword,
TOKEN_operator,
TOKEN_devider,
TOKEN_literal,
};
enum StmtType {
STMT_reference,
STMT_string,
STMT_bytes,
STMT_number,
STMT_method,
STMT_operator,
STMT_list,
STMT_none,
};
typedef struct Asmer_t {
char* asm_code;
uint8_t block_deepth_now;
uint8_t is_new_line;
char* line_pointer;
} Asmer;
struct LexToken {
char* token;
enum TokenType type;
char* pyload;
};
struct ParserState {
char* tokens;
uint16_t length;
uint16_t iter_index;
uint8_t branket_deepth;
struct LexToken token1;
struct LexToken token2;
Arg* last_token;
Args* iter_buffs;
Args* buffs_p;
};
char* Parser_multiLineToAsm(Args* outBuffs, char* multiLine);
char* instructUnit_fromAsmLine(Args* outBuffs, char* pikaAsm);
char* Parser_byteCodeToAsm(Args* outBuffs, char* pikaByteCode);
ByteCodeFrame* byteCodeFrame_appendFromAsm(ByteCodeFrame* bf, char* pikaAsm);
int bytecodeFrame_fromMultiLine(ByteCodeFrame* bytecode_frame,
char* python_lines);
void Parser_compilePyToBytecodeArray(char* lines);
char* Parser_parsePyLines(Args* outBuffs,
ByteCodeFrame* bytecode_frame,
char* py_lines);
#define ParserState_forEach(parseState) \
ParserState_beforeIter(&parseState); \
for (int i = 0; i < parseState.length; i++)
#define ParserState_forEachTokenExistPs(parseState, tokens) \
/* init parserStage */ \
ParserState_init(&parseState); \
ParserState_parse(&parseState, tokens); \
ParserState_forEach(parseState)
#define ParserState_forEachToken(parseState, tokens) \
struct ParserState ps; \
ParserState_forEachTokenExistPs(parseState, tokens)
#endif

View File

@ -1,131 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "PikaPlatform.h"
#include <stdio.h>
#include <stdlib.h>
PIKA_WEAK void __platform_disable_irq_handle(void) {
/* disable irq to support thread */
}
PIKA_WEAK void __platform_enable_irq_handle(void) {
/* disable irq to support thread */
}
PIKA_WEAK void* __platform_malloc(size_t size) {
return malloc(size);
}
PIKA_WEAK void __platform_error_handle(){
return;
}
PIKA_WEAK void __platform_free(void* ptr) {
free(ptr);
}
PIKA_WEAK uint8_t __is_locked_pikaMemory(void) {
return 0;
}
#ifndef __platform_printf
PIKA_WEAK void __platform_printf(char* fmt, ...) {
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}
#endif
PIKA_WEAK int __platform_vsprintf(char* buff, char* fmt, va_list args) {
return vsprintf(buff, fmt, args);
}
PIKA_WEAK int __platform_vsnprintf(char* buff,
size_t size,
const char* fmt,
va_list args) {
return vsnprintf(buff, size, fmt, args);
}
PIKA_WEAK int __platform_sprintf(char* buff, char* fmt, ...) {
va_list args;
va_start(args, fmt);
int res = vsnprintf(buff, PIKA_SPRINTF_BUFF_SIZE, fmt, args);
va_end(args);
return res;
}
PIKA_WEAK void __platform_wait(void) {
while (1) {
};
}
PIKA_WEAK void* __platform_memset(void* mem, int ch, size_t size) {
return memset(mem, ch, size);
}
PIKA_WEAK void* __platform_memcpy(void* dir, const void* src, size_t size) {
return memcpy(dir, src, size);
}
PIKA_WEAK char __platform_getchar(void) {
#ifdef __linux
return getchar();
#else
__platform_printf("[error]: __platform_function need implementation!\r\n");
while (1) {
}
#endif
}
PIKA_WEAK FILE* __platform_fopen(const char* filename, const char* modes) {
#ifdef __linux
return fopen(filename, modes);
#else
__platform_printf("[error]: __platform_function need implementation!\r\n");
while (1) {
}
#endif
}
PIKA_WEAK int __platform_fclose(FILE* stream) {
#ifdef __linux
return fclose(stream);
#else
__platform_printf("[error]: __platform_function need implementation!\r\n");
while (1) {
}
#endif
}
PIKA_WEAK size_t __platform_fwrite(const void* ptr,
size_t size,
size_t n,
FILE* stream) {
#ifdef __linux
return fwrite(ptr, size, n, stream);
#else
__platform_printf("[error]: __platform_function need implementation!\r\n");
while (1) {
}
#endif
}

View File

@ -1,104 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* micro pika configuration */
#include "./pika_config_valid.h"
#ifndef __PIKA_PALTFORM__H
#define __PIKA_PALTFORM__H
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Compiler */
#if defined(__CC_ARM) || defined(__CLANG_ARM) /* ARM Compiler */
#define PIKA_WEAK __attribute__((weak))
#elif defined(__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
#define PIKA_WEAK __weak
#elif defined(__GNUC__) /* GNU GCC Compiler */
#define PIKA_WEAK __attribute__((weak))
#endif
/* default PIKA_WEAK */
#ifndef PIKA_WEAK
#define PIKA_WEAK
#endif
/* OS */
#ifdef __RTTHREAD__
#include <rtthread.h>
#define __platform_printf(...) rt_kprintf(__VA_ARGS__)
#endif
/*
[Note]:
Create a pika_config.c to override the following weak functions to config
PikaScript. [Example]:
1.
https://gitee.com/Lyon1998/pikascript/blob/master/package/STM32G030Booter/pika_config.c
2.
https://gitee.com/Lyon1998/pikascript/blob/master/package/pikaRTBooter/pika_config.c
*/
/* interrupt config */
void __platform_enable_irq_handle(void);
void __platform_disable_irq_handle(void);
/* printf family config */
#ifndef __platform_printf
void __platform_printf(char* fmt, ...);
#endif
int __platform_sprintf(char* buff, char* fmt, ...);
int __platform_vsprintf(char* buff, char* fmt, va_list args);
int __platform_vsnprintf(char* buff,
size_t size,
const char* fmt,
va_list args);
/* libc config */
void* __platform_malloc(size_t size);
void __platform_free(void* ptr);
void* __platform_memset(void* mem, int ch, size_t size);
void* __platform_memcpy(void* dir, const void* src, size_t size);
/* pika memory pool config */
void __platform_wait(void);
uint8_t __is_locked_pikaMemory(void);
/* support shell */
char __platform_getchar(void);
/* file API */
FILE* __platform_fopen(const char* filename, const char* modes);
int __platform_fclose(FILE* stream);
size_t __platform_fwrite(const void* ptr, size_t size, size_t n, FILE* stream);
/* error */
void __platform_error_handle(void);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,137 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __PIKA_VM__H
#define __PIKA_VM__H
#include "PikaObj.h"
#include "dataQueue.h"
#include "dataStack.h"
#include "dataQueueObj.h"
enum Instruct {
#define __INS_ENUM
#include "__instruction_table.cfg"
__INSTRCUTION_CNT,
};
typedef struct VMState_t {
VMParameters* locals;
VMParameters* globals;
Stack stack;
int32_t jmp;
int32_t pc;
ByteCodeFrame* bytecode_frame;
uint8_t error_code;
uint8_t line_error_code;
} VMState;
VMParameters* pikaVM_run(PikaObj* self, char* pyLine);
VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
VMParameters* pikaVM_runByteCodeFrame(PikaObj* self,
ByteCodeFrame* byteCode_frame);
#define instructUnit_getBlockDeepth(self) (((self)->deepth) & 0x0F)
#define instructUnit_getInvokeDeepth(self) (((self)->deepth) >> 4)
#define instructUnit_getInstruct(self) \
((enum Instruct)((self)->isNewLine_instruct & 0x7F))
#define instructUnit_getConstPoolIndex(self) ((self)->const_pool_index)
#define instructUnit_getIsNewLine(self) ((self)->isNewLine_instruct >> 7)
#define instructUnit_setBlockDeepth(self, val) \
do { \
((self)->deepth) |= (0x0F & (val)); \
} while (0)
#define instructUnit_setConstPoolIndex(self, val) \
do { \
((self)->const_pool_index = (val)); \
} while (0)
#define instructUnit_setInvokeDeepth(self, val) \
do { \
((self)->deepth) |= ((0x0F & (val)) << 4); \
} while (0)
#define instructUnit_setInstruct(self, val) \
do { \
((self)->isNewLine_instruct) |= (0x7F & (val)); \
} while (0)
#define instructUnit_setIsNewLine(self, val) \
do { \
((self)->isNewLine_instruct) |= ((0x01 & (val)) << 7); \
} while (0)
InstructUnit* New_instructUnit(uint8_t data_size);
void instructUnit_deinit(InstructUnit* self);
enum Instruct pikaVM_getInstructFromAsm(char* line);
void constPool_init(ConstPool* self);
void constPool_deinit(ConstPool* self);
void constPool_append(ConstPool* self, char* content);
char* constPool_getNow(ConstPool* self);
char* constPool_getNext(ConstPool* self);
char* constPool_getByIndex(ConstPool* self, uint16_t index);
char* constPool_getByOffset(ConstPool* self, uint16_t offset);
uint16_t constPool_getLastOffset(ConstPool* self);
void constPool_print(ConstPool* self);
void byteCodeFrame_init(ByteCodeFrame* bf);
void byteCodeFrame_deinit(ByteCodeFrame* bf);
size_t byteCodeFrame_getSize(ByteCodeFrame* bf);
void instructArray_init(InstructArray* ins_array);
void instructArray_deinit(InstructArray* ins_array);
void instructArray_append(InstructArray* ins_array, InstructUnit* ins_unit);
void instructUnit_init(InstructUnit* ins_unit);
void instructUnit_print(InstructUnit* self);
void instructArray_print(InstructArray* self);
void byteCodeFrame_print(ByteCodeFrame* self);
InstructUnit* instructArray_getByOffset(InstructArray* self, int32_t offset);
#define instructUnit_getSize(InstructUnit_p_self) ((size_t)sizeof(InstructUnit))
#define instructArray_getSize(InsturctArry_p_self) \
((size_t)(InsturctArry_p_self)->size)
VMParameters* pikaVM_runByteCodeWithState(PikaObj* self,
VMParameters* locals,
VMParameters* globals,
ByteCodeFrame* bytecode_frame,
uint16_t pc);
uint16_t constPool_getOffsetByData(ConstPool* self, char* data);
void instructArray_printWithConst(InstructArray* self, ConstPool* const_pool);
void constPool_update(ConstPool* self);
void instructArray_update(InstructArray* self);
void constPool_printAsArray(ConstPool* self);
void instructArray_printAsArray(InstructArray* self);
void byteCodeFrame_loadBytes(ByteCodeFrame* self, uint8_t* bytes);
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
VMParameters* pikaVM_runByteCode(PikaObj* self, uint8_t* bytecode);
#endif

View File

@ -1 +0,0 @@
# PikaScript 运行时内核

View File

@ -1,41 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "PikaObj.h"
void _UpdateHandle(PikaObj* self) {
// override the handle function here
}
void _beforDinit(PikaObj* self) {
/* override in user code */
}
PikaObj* New_TinyObj(Args* args) {
PikaObj* self = New_PikaObj();
return self;
}

View File

@ -1,32 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __TYNYOBJ__H
#define __TYNYOBJ__H
#include "PikaObj.h"
PikaObj* New_TinyObj(Args* args);
#endif

View File

@ -1,54 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 GorgonMeducer ?? embedded_zhuoran@hotmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#undef def_ins
#if defined(__INS_ENUM)
#define def_ins(__INS_NAME) __INS_NAME,
#endif
#if defined(__INS_TABLE)
#define def_ins(__INS_NAME) [__INS_NAME] = &VM_instruction_handler_##__INS_NAME,
#endif
#if defined(__INS_COMPIRE)
#define def_ins(__INS_NAME) \
if (0 == strncmp(line + 2, "" #__INS_NAME "", 3)) { \
return __INS_NAME; \
}
#endif
#if defined(__INS_GET_INS_STR)
#define def_ins(__INS_NAME) \
if (__INS_NAME == instructUnit_getInstruct(self)){ \
return ""#__INS_NAME""; \
}
#endif
#undef __INS_ENUM
#undef __INS_TABLE
#undef __INS_COMPIRE

View File

@ -1,56 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 GorgonMeducer ?? embedded_zhuoran@hotmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "__instruction_def.h"
//! just append ins to the end, insert ins would brake the pre-compiled
//! bytecode.
def_ins(NON)
def_ins(REF)
def_ins(RUN)
def_ins(STR)
def_ins(OUT)
def_ins(NUM)
def_ins(JMP)
def_ins(JEZ)
def_ins(OPT)
def_ins(DEF)
def_ins(RET)
def_ins(NEL)
def_ins(DEL)
def_ins(EST)
def_ins(BRK)
def_ins(CTN)
def_ins(GLB)
def_ins(RAS)
def_ins(NEW)
def_ins(CLS)
def_ins(BYT)
#if PIKA_BUILTIN_LIST_ENABLE
def_ins(LST)
#endif

View File

@ -1,34 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon ?? liang6516@outlook.com
* Copyright (c) 2021 Gorgon Meducer ?? embedded_zhuoran@hotmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __PIKA_OOC_H__
#define __PIKA_OOC_H__
// #include "./3rd-party/PLOOC/plooc_class.h"
#endif

View File

@ -1,369 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataArg.h"
#include "PikaObj.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "dataString.h"
#include "stdlib.h"
uint16_t arg_getTotleSize(Arg* self) {
return content_totleSize(self);
}
/**
* time33 hash
*/
Hash hash_time33(char* str) {
Hash hash = 5381;
while (*str) {
hash += (hash << 5) + (*str++);
}
return (hash & 0x7FFFFFFF);
}
static uint8_t* content_init_hash(Hash nameHash,
ArgType type,
uint8_t* content,
uint32_t size,
uint8_t* next) {
__arg* self = (__arg*)pikaMalloc(sizeof(__arg) + size);
self->next = (__arg*)next;
self->size = size;
self->name_hash = nameHash;
self->type = type;
if (NULL != content) {
__platform_memcpy(self->content, content, size);
} else {
__platform_memset(self->content, 0, size);
}
return (uint8_t*)self;
}
static uint8_t* content_init(char* name,
ArgType type,
uint8_t* content,
uint16_t size,
uint8_t* next) {
Hash nameHash = hash_time33(name);
return content_init_hash(nameHash, type, content, size, next);
}
uint16_t content_totleSize(uint8_t* self) {
return ((__arg*)self)->size + sizeof(__arg);
}
void arg_freeContent(Arg* self) {
if (NULL != self) {
content_deinit(self);
}
}
uint8_t* content_deinit(uint8_t* self) {
uint16_t totleSize = content_totleSize(self);
pikaFree(self, totleSize);
return 0;
}
uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size) {
if (NULL == self) {
/* malloc */
return content_init("", ARG_TYPE_VOID, content, size, NULL);
}
/* only copy */
if (content_getSize(self) == size) {
__platform_memcpy(((__arg*)self)->content, content, size);
return self;
}
/* realloc */
Hash nameHash = content_getNameHash(self);
ArgType type = content_getType(self);
uint8_t* next = content_getNext(self);
uint8_t* newContent =
content_init_hash(nameHash, type, content, size, next);
content_deinit(self);
return newContent;
}
uint8_t* content_setNameHash(uint8_t* self, Hash nameHash) {
if (NULL == self) {
return content_init_hash(nameHash, ARG_TYPE_VOID, NULL, 0, NULL);
}
__arg* arg = (__arg*)self;
arg->name_hash = nameHash;
return self;
}
uint8_t* content_setName(uint8_t* self, char* name) {
return content_setNameHash(self, hash_time33(name));
}
uint8_t* content_setType(uint8_t* self, ArgType type) {
if (NULL == self) {
return content_init("", type, NULL, 0, NULL);
}
__arg* arg = (__arg*)self;
arg->type = type;
return self;
}
ArgType content_getType(uint8_t* self) {
__arg* arg = (__arg*)self;
return (ArgType)arg->type;
}
Arg* arg_setBytes(Arg* self, char* name, uint8_t* src, size_t size) {
self = arg_newContent(self, size + sizeof(size_t));
self = arg_setName(self, name);
self = arg_setType(self, ARG_TYPE_BYTES);
void* dir = arg_getContent(self);
__platform_memcpy(dir, &size, sizeof(size_t));
__platform_memcpy((void*)((uintptr_t)dir + sizeof(size_t)), src, size);
return self;
}
Arg* arg_newContent(Arg* self, uint32_t size) {
uint8_t* newContent = content_init("", ARG_TYPE_VOID, NULL, size, NULL);
arg_freeContent(self);
return newContent;
}
Arg* arg_setContent(Arg* self, uint8_t* content, uint32_t size) {
return content_setContent(self, content, size);
}
uint8_t* arg_getBytes(Arg* self) {
return content_getContent(self) + sizeof(size_t);
}
void arg_printBytes(Arg* self) {
size_t bytes_size = arg_getBytesSize(self);
uint8_t* bytes = arg_getBytes(self);
__platform_printf("b\'");
for (size_t i = 0; i < bytes_size; i++) {
__platform_printf("\\x%02x", bytes[i]);
}
__platform_printf("\'\r\n");
}
size_t arg_getBytesSize(Arg* self) {
size_t mem_size = 0;
void* content = (void*)arg_getContent(self);
if (NULL == content) {
return 0;
}
__platform_memcpy(&mem_size, content, sizeof(size_t));
return mem_size;
}
Arg* arg_setStruct(Arg* self,
char* name,
void* struct_ptr,
uint32_t struct_size) {
if (NULL == struct_ptr) {
return NULL;
}
Arg* struct_arg = arg_setContent(NULL, (uint8_t*)struct_ptr, struct_size);
struct_arg = arg_setType(struct_arg, ARG_TYPE_STRUCT);
struct_arg = arg_setName(struct_arg, name);
return struct_arg;
}
Arg* arg_setHeapStruct(Arg* self,
char* name,
void* struct_ptr,
uint32_t struct_size,
void* struct_deinit_fun) {
if (NULL == struct_ptr) {
return NULL;
}
Arg* struct_arg =
arg_setContent(NULL, (uint8_t*)&struct_deinit_fun, sizeof(void*));
struct_arg = arg_append(struct_arg, (uint8_t*)struct_ptr, struct_size);
struct_arg = arg_setType(struct_arg, ARG_TYPE_HEAP_STRUCT);
struct_arg = arg_setName(struct_arg, name);
return struct_arg;
}
void* arg_getHeapStructDeinitFun(Arg* self) {
void* deinit_fun = NULL;
__platform_memcpy(&deinit_fun, arg_getContent(self), sizeof(void*));
return deinit_fun;
}
Arg* arg_setName(Arg* self, char* name) {
return content_setName(self, name);
}
Arg* arg_setNameHash(Arg* self, Hash nameHash) {
return content_setNameHash(self, nameHash);
}
Arg* arg_setType(Arg* self, ArgType type) {
return content_setType(self, type);
}
Arg* arg_setInt(Arg* self, char* name, int64_t val) {
return content_init(name, ARG_TYPE_INT, (uint8_t*)&val, sizeof(val), NULL);
}
Arg* arg_setNull(Arg* self) {
return content_init("", ARG_TYPE_NULL, NULL, 0, NULL);
}
Arg* arg_setFloat(Arg* self, char* name, float val) {
return content_init(name, ARG_TYPE_FLOAT, (uint8_t*)&val, sizeof(val),
NULL);
}
float arg_getFloat(Arg* self) {
if (NULL == arg_getContent(self)) {
return -999.999;
}
return *(float*)(((__arg*)self)->content);
}
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer) {
return content_init(name, type, (uint8_t*)&pointer, sizeof(uintptr_t),
NULL);
}
Arg* arg_setStr(Arg* self, char* name, char* string) {
return content_init(name, ARG_TYPE_STRING, (uint8_t*)string,
strGetSize(string) + 1, NULL);
}
int64_t arg_getInt(Arg* self) {
if (NULL == arg_getContent(self)) {
return -999999;
}
return *(int64_t*)(((__arg*)self)->content);
}
void* arg_getPtr(Arg* self) {
if (NULL == arg_getContent(self)) {
return NULL;
}
return *(void**)(((__arg*)self)->content);
}
char* arg_getStr(Arg* self) {
return (char*)arg_getContent(self);
}
Hash arg_getNameHash(Arg* self) {
if (NULL == self) {
return 999999;
}
return content_getNameHash(self);
}
ArgType arg_getType(Arg* self) {
if (NULL == self) {
return ARG_TYPE_NULL;
}
return content_getType(self);
}
uint16_t arg_getContentSize(Arg* self) {
return content_getSize(self);
}
Arg* New_arg(void* voidPointer) {
return NULL;
}
Arg* arg_copy(Arg* argToBeCopy) {
if (NULL == argToBeCopy) {
return NULL;
}
ArgType arg_type = arg_getType(argToBeCopy);
if (ARG_TYPE_OBJECT == arg_type) {
obj_refcntInc(arg_getPtr(argToBeCopy));
}
Arg* argCopied = New_arg(NULL);
argCopied = arg_setContent(argCopied, arg_getContent(argToBeCopy),
arg_getContentSize(argToBeCopy));
argCopied = arg_setNameHash(argCopied, arg_getNameHash(argToBeCopy));
argCopied = arg_setType(argCopied, arg_getType(argToBeCopy));
return argCopied;
}
Arg* arg_append(Arg* arg_in, void* new_content, size_t new_size) {
uint8_t* old_content = arg_getContent(arg_in);
size_t old_size = arg_getContentSize(arg_in);
/* create arg_out */
Arg* arg_out = arg_setContent(NULL, NULL, old_size + new_size);
arg_setType(arg_out, arg_getType(arg_in));
arg_setNameHash(arg_out, arg_getNameHash(arg_in));
/* copy old content */
__platform_memcpy(arg_getContent(arg_out), old_content, old_size);
/* copy new content */
__platform_memcpy(arg_getContent(arg_out) + old_size, new_content,
new_size);
arg_deinit(arg_in);
return arg_out;
}
void* arg_getHeapStruct(Arg* self) {
return arg_getContent(self) + sizeof(void*);
}
void arg_deinitHeap(Arg* self) {
ArgType type = arg_getType(self);
/* deinit heap struct */
if (type == ARG_TYPE_HEAP_STRUCT) {
/* deinit heap strcut */
StructDeinitFun struct_deinit_fun =
(StructDeinitFun)arg_getHeapStructDeinitFun(self);
struct_deinit_fun(arg_getHeapStruct(self));
}
/* deinit sub object */
if (type == ARG_TYPE_OBJECT) {
PikaObj* subObj = arg_getPtr(self);
obj_refcntDec(subObj);
int ref_cnt = obj_refcntNow(subObj);
if (ref_cnt <= 0) {
obj_deinit(subObj);
}
}
}
void arg_deinit(Arg* self) {
/* deinit arg pointed heap */
arg_deinitHeap(self);
/* free the ref */
arg_freeContent(self);
}

View File

@ -1,142 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _arg__H
#define _arg__H
#include "dataLink.h"
#include "dataMemory.h"
typedef uint32_t Hash;
typedef enum {
ARG_TYPE_UNDEF = 0,
ARG_TYPE_NONE,
ARG_TYPE_VOID,
ARG_TYPE_BYTES,
ARG_TYPE_NULL,
ARG_TYPE_INT,
ARG_TYPE_FLOAT,
ARG_TYPE_STRING,
ARG_TYPE_MATE_OBJECT,
ARG_TYPE_FREE_OBJECT,
ARG_TYPE_OBJECT,
ARG_TYPE_POINTER,
ARG_TYPE_NATIVE_METHOD,
ARG_TYPE_NATIVE_CONSTRUCTOR_METHOD,
ARG_TYPE_CONSTRUCTOR_METHOD,
ARG_TYPE_OBJECT_METHOD,
ARG_TYPE_STATIC_METHOD,
ARG_TYPE_STRUCT,
ARG_TYPE_HEAP_STRUCT,
} ArgType;
typedef void (*StructDeinitFun)(void* struct_);
typedef struct __arg __arg;
struct __arg {
__arg* next;
uint16_t size;
uint8_t type;
uint8_t ref_cnt;
Hash name_hash;
uint8_t content[];
};
typedef uint8_t Arg;
// uint32_t content_getNameHash(uint8_t* content);
#define content_getNameHash(__addr) (((__arg*)(__addr))->name_hash)
ArgType content_getType(uint8_t* self);
#define content_getNext(__addr) ((uint8_t*)(((__arg*)(__addr))->next))
#define content_getSize(__addr) ((uint16_t)(((__arg*)(__addr))->size))
#define content_getContent(__addr) (((__arg*)(__addr))->content)
uint16_t content_totleSize(uint8_t* self);
uint8_t* content_deinit(uint8_t* self);
uint8_t* content_setName(uint8_t* self, char* name);
uint8_t* content_setType(uint8_t* self, ArgType type);
uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size);
// void content_setNext(uint8_t* self, uint8_t* next);
#define content_setNext(__addr, __next) \
do { \
(((__arg*)(__addr))->next) = (__arg*)(__next); \
} while (0)
uint16_t arg_getTotleSize(Arg* self);
void arg_freeContent(Arg* self);
Arg* arg_setName(Arg* self, char* name);
Arg* arg_setContent(Arg* self, uint8_t* content, uint32_t size);
Arg* arg_newContent(Arg* self, uint32_t size);
Arg* arg_setType(Arg* self, ArgType type);
Hash arg_getNameHash(Arg* self);
ArgType arg_getType(Arg* self);
uint16_t arg_getContentSize(Arg* self);
Hash hash_time33(char* str);
Arg* arg_setInt(Arg* self, char* name, int64_t val);
Arg* arg_setFloat(Arg* self, char* name, float val);
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer);
Arg* arg_setStr(Arg* self, char* name, char* string);
Arg* arg_setNull(Arg* self);
int64_t arg_getInt(Arg* self);
float arg_getFloat(Arg* self);
void* arg_getPtr(Arg* self);
char* arg_getStr(Arg* self);
uint8_t* arg_getBytes(Arg* self);
size_t arg_getBytesSize(Arg* self);
Arg* arg_copy(Arg* argToBeCopy);
#define arg_getContent(self) ((uint8_t*)content_getContent((self)))
Arg* arg_init(Arg* self, void* voidPointer);
void arg_deinit(Arg* self);
Arg* New_arg(void* voidPointer);
Arg* arg_append(Arg* arg_in, void* new_content, size_t new_size);
Arg* arg_setStruct(Arg* self,
char* name,
void* struct_ptr,
uint32_t struct_size);
Arg* arg_setHeapStruct(Arg* self,
char* name,
void* struct_ptr,
uint32_t struct_size,
void* struct_deinit_fun);
void* arg_getHeapStruct(Arg* self);
void arg_deinitHeap(Arg* self);
Arg* arg_setBytes(Arg* self, char* name, uint8_t* src, size_t size);
void arg_printBytes(Arg* self);
#endif

View File

@ -1,519 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataArgs.h"
#include "PikaObj.h"
#include "PikaPlatform.h"
#include "dataLink.h"
#include "dataMemory.h"
#include "dataString.h"
#include "dataStrs.h"
void args_deinit(Args* self) {
link_deinit(self);
}
void args_deinit_stack(Args* self) {
link_deinit_stack(self);
}
int32_t args_setFloat(Args* self, char* name, float argFloat) {
Arg* argNew = New_arg(NULL);
argNew = arg_setFloat(argNew, name, argFloat);
args_setArg(self, argNew);
return 0;
}
void* args_getPtr(Args* self, char* name) {
void* pointer = NULL;
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return NULL;
}
pointer = arg_getPtr(arg);
return pointer;
}
int32_t args_setPtr(Args* self, char* name, void* argPointer) {
int32_t errCode = 0;
Arg* argNew = New_arg(NULL);
argNew = arg_setPtr(argNew, name, ARG_TYPE_POINTER, argPointer);
args_setArg(self, argNew);
return errCode;
}
int32_t args_setRefObj(Args* self, char* name, void* argPointer) {
int32_t errCode = 0;
Arg* argNew = New_arg(NULL);
argNew = arg_setRefObj(argNew, name, argPointer);
args_setArg(self, argNew);
return errCode;
}
int32_t args_setStr(Args* self, char* name, char* strIn) {
int32_t errCode = 0;
Arg* argNew = New_arg(NULL);
argNew = arg_setStr(argNew, name, strIn);
args_setArg(self, argNew);
return errCode;
}
int args_pushArg(Args* self, Arg* arg) {
link_addNode(self, arg);
return 0;
}
void args_setBytes(Args* self, char* name, uint8_t* src, size_t size) {
Arg* argNew = arg_setBytes(NULL, name, src, size);
args_setArg(self, argNew);
}
char* args_getBuff(Args* self, int32_t size) {
Arg* argNew = New_arg(NULL);
argNew = arg_newContent(argNew, size + 1);
args_pushArg(self, argNew);
return (char*)arg_getContent(argNew);
}
char* args_getStr(Args* self, char* name) {
if (NULL == self) {
return NULL;
}
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return NULL;
}
if (NULL == arg_getContent(arg)) {
return NULL;
}
return (char*)arg_getContent(arg);
}
uint8_t* args_getBytes(Args* self, char* name) {
if (NULL == self) {
return NULL;
}
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return NULL;
}
if (NULL == arg_getContent(arg)) {
return NULL;
}
return arg_getBytes(arg);
}
size_t args_getBytesSize(Args* self, char* name) {
if (NULL == self) {
return 0;
}
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return 0;
}
if (NULL == arg_getContent(arg)) {
return 0;
}
return arg_getBytesSize(arg);
}
int32_t args_setInt(Args* self, char* name, int64_t int64In) {
Arg* argNew = New_arg(NULL);
argNew = arg_setInt(argNew, name, int64In);
args_setArg(self, argNew);
return 0;
}
int64_t args_getInt(Args* self, char* name) {
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return -999999999;
}
ArgType arg_type = arg_getType(arg);
if (arg_type == ARG_TYPE_INT) {
return arg_getInt(arg);
} else if (arg_type == ARG_TYPE_FLOAT) {
return (int)arg_getFloat(arg);
}
return -999999999;
}
int32_t args_getSize(Args* self) {
return link_getSize(self);
}
ArgType args_getType(Args* self, char* name) {
Arg* arg = NULL;
arg = args_getArg(self, name);
if (NULL == arg) {
return ARG_TYPE_NULL;
}
return arg_getType(arg);
}
float args_getFloat(Args* self, char* name) {
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return -999999999.0;
}
ArgType arg_type = arg_getType(arg);
if (arg_type == ARG_TYPE_FLOAT) {
return arg_getFloat(arg);
} else if (arg_type == ARG_TYPE_INT) {
return (float)arg_getInt(arg);
}
return -999999999.0;
}
int32_t args_copyArg(Args* self, Arg* argToBeCopy) {
if (NULL == argToBeCopy) {
return 1;
}
Arg* argCopied = arg_copy(argToBeCopy);
args_setArg(self, argCopied);
return 0;
}
int32_t args_setStructWithSize(Args* self,
char* name,
void* struct_ptr,
uint32_t struct_size) {
Arg* struct_arg = arg_setStruct(NULL, name, struct_ptr, struct_size);
if (NULL == struct_arg) {
/* faild */
return 1;
}
args_setArg(self, struct_arg);
return 0;
}
void* args_getStruct(Args* self, char* name) {
Arg* struct_arg = args_getArg(self, name);
return arg_getContent(struct_arg);
}
void* args_getHeapStruct(Args* self, char* name) {
Arg* struct_arg = args_getArg(self, name);
return arg_getHeapStruct(struct_arg);
}
int32_t args_setHeapStructWithSize(Args* self,
char* name,
void* struct_ptr,
uint32_t struct_size,
void* struct_deinit_fun) {
Arg* struct_arg = arg_setHeapStruct(NULL, name, struct_ptr, struct_size,
struct_deinit_fun);
if (NULL == struct_arg) {
/* faild */
return 1;
}
args_setArg(self, struct_arg);
return 0;
}
int32_t args_copyArgByName(Args* self, char* name, Args* directArgs) {
Arg* argToBeCopy = args_getArg(self, name);
args_copyArg(directArgs, argToBeCopy);
return 0;
}
int32_t args_isArgExist_hash(Args* self, Hash nameHash) {
if (NULL != args_getArg_hash(self, nameHash)) {
return 1;
}
return 0;
}
int32_t args_isArgExist(Args* self, char* name) {
if (NULL != args_getArg(self, name)) {
return 1;
}
return 0;
}
int32_t __updateArg(Args* self, Arg* argNew) {
LinkNode* nodeToUpdate = NULL;
LinkNode* nodeNow = self->firstNode;
LinkNode* priorNode = NULL;
Hash nameHash = arg_getNameHash(argNew);
while (1) {
if (content_getNameHash(nodeNow) == nameHash) {
nodeToUpdate = nodeNow;
break;
}
if (content_getNext(nodeNow) == NULL) {
// error, node no found
goto exit;
}
priorNode = nodeNow;
nodeNow = content_getNext(nodeNow);
}
arg_deinitHeap(nodeToUpdate);
nodeToUpdate = arg_setContent(nodeToUpdate, arg_getContent(argNew),
arg_getContentSize(argNew));
nodeToUpdate = arg_setType(nodeToUpdate, arg_getType(argNew));
// update privior link, because arg_getContent would free origin pointer
if (NULL == priorNode) {
self->firstNode = nodeToUpdate;
goto exit;
}
content_setNext(priorNode, nodeToUpdate);
goto exit;
exit:
arg_freeContent(argNew);
return 0;
}
int32_t args_setArg(Args* self, Arg* arg) {
Hash nameHash = arg_getNameHash(arg);
if (!args_isArgExist_hash(self, nameHash)) {
args_pushArg(self, arg);
return 0;
}
__updateArg(self, arg);
return 0;
}
#ifndef __PIKA_CFG_HASH_LIST_CACHE_SIZE
#define __PIKA_CFG_HASH_LIST_CACHE_SIZE 4
#endif
LinkNode* args_getNode_hash(Args* self, Hash nameHash) {
LinkNode** ppnode = (LinkNode**)&(self->firstNode);
int_fast8_t n = 0;
while (NULL != (*ppnode)) {
Arg* arg = (*ppnode);
Hash thisNameHash = arg_getNameHash(arg);
if (thisNameHash == nameHash) {
__arg* tmp = (__arg*)(*ppnode);
if (n > __PIKA_CFG_HASH_LIST_CACHE_SIZE) {
/* the first __PIKA_CFG_HASH_LIST_CACHE_SIZE items in the list
* is considered as a cache.
* Don't make __PIKA_CFG_HASH_LIST_CACHE_SIZE too big, otherwise
* this optimisation is useless.
*/
/*! remove current node from the list */
(*ppnode) = (LinkNode*)(tmp->next);
/*! move the node to the cache */
tmp->next = (__arg*)(self->firstNode);
self->firstNode = (LinkNode*)tmp;
}
return (LinkNode*)tmp;
}
n++;
ppnode = (LinkNode**)&(((__arg*)(*ppnode))->next);
}
return NULL;
}
LinkNode* args_getNode(Args* self, char* name) {
return args_getNode_hash(self, hash_time33(name));
}
Arg* args_getArg_hash(Args* self, Hash nameHash) {
LinkNode* node = args_getNode_hash(self, nameHash);
if (NULL == node) {
return NULL;
}
return node;
}
Arg* args_getArg(Args* self, char* name) {
LinkNode* node = args_getNode(self, name);
if (NULL == node) {
return NULL;
}
return node;
}
Arg* args_getArg_index(Args* self, int index) {
LinkNode* nodeNow = self->firstNode;
if (NULL == nodeNow) {
return NULL;
}
for (int i = 0; i < index; i++) {
nodeNow = content_getNext(nodeNow);
}
return nodeNow;
}
char* getPrintSring(Args* self, char* name, char* valString) {
Args buffs = {0};
char* printName = strsFormat(&buffs, 128, "[printBuff]%s", name);
char* printString = strsCopy(&buffs, valString);
args_setStr(self, printName, printString);
char* res = args_getStr(self, printName);
strsDeinit(&buffs);
return res;
}
char* getPrintStringFromInt(Args* self, char* name, int32_t val) {
Args buffs = {0};
char* res = NULL;
char* valString = strsFormat(&buffs, 32, "%d", val);
res = getPrintSring(self, name, valString);
strsDeinit(&buffs);
return res;
}
char* getPrintStringFromFloat(Args* self, char* name, float val) {
Args buffs = {0};
char* res = NULL;
char* valString = strsFormat(&buffs, 32, "%f", val);
res = getPrintSring(self, name, valString);
strsDeinit(&buffs);
return res;
}
char* getPrintStringFromPtr(Args* self, char* name, void* val) {
Args buffs = {0};
char* res = NULL;
uint64_t intVal = (uintptr_t)val;
char* valString = strsFormat(&buffs, 32, "0x%llx", intVal);
res = getPrintSring(self, name, valString);
strsDeinit(&buffs);
return res;
}
char* args_print(Args* self, char* name) {
char* res = NULL;
ArgType type = args_getType(self, name);
Args buffs = {0};
if (ARG_TYPE_NONE == type) {
/* can not get arg */
res = NULL;
goto exit;
}
if (type == ARG_TYPE_INT) {
int32_t val = args_getInt(self, name);
res = getPrintStringFromInt(self, name, val);
goto exit;
}
if (type == ARG_TYPE_FLOAT) {
float val = args_getFloat(self, name);
res = getPrintStringFromFloat(self, name, val);
goto exit;
}
if (type == ARG_TYPE_STRING) {
res = args_getStr(self, name);
goto exit;
}
if (type == ARG_TYPE_OBJECT) {
void* val = args_getPtr(self, name);
res = getPrintStringFromPtr(self, name, val);
goto exit;
}
/* can not match type */
res = NULL;
goto exit;
exit:
strsDeinit(&buffs);
return res;
}
int32_t args_setPtrWithType(Args* self,
char* name,
ArgType type,
void* objPtr) {
Arg* argNew = New_arg(NULL);
argNew = arg_setPtr(argNew, name, type, objPtr);
args_setArg(self, argNew);
return 0;
}
int32_t args_foreach(Args* self,
int32_t (*eachHandle)(Arg* argEach, Args* handleArgs),
Args* handleArgs) {
if (NULL == self->firstNode) {
return 0;
}
LinkNode* nodeNow = self->firstNode;
while (1) {
Arg* argNow = nodeNow;
if (NULL == argNow) {
continue;
}
LinkNode* nextNode = content_getNext(nodeNow);
eachHandle(argNow, handleArgs);
if (NULL == nextNode) {
break;
}
nodeNow = nextNode;
}
return 0;
}
int32_t args_removeArg(Args* self, Arg* argNow) {
if (NULL == argNow) {
/* can not found arg */
return 1;
}
link_removeNode(self, argNow);
return 0;
}
int32_t args_removeArg_notDeinitArg(Args* self, Arg* argNow) {
if (NULL == argNow) {
/* can not found arg */
return 1;
}
link_removeNode_notDeinitNode(self, argNow);
return 0;
}
int args_moveArg(Args* self, Args* dict, Arg* argNow) {
if (NULL == argNow) {
/* can not found arg */
return 1;
}
link_removeNode_notDeinitNode(self, argNow);
args_pushArg(dict, argNow);
return 0;
}
Args* New_args(Args* args) {
Args* self = New_link(NULL);
return self;
}

View File

@ -1,124 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _dataArgs__H
#define _dataArgs__H
#include "dataArg.h"
#include "dataLink.h"
#include "dataMemory.h"
#include "dataString.h"
typedef Link Args;
/* operation */
void args_deinit(Args* self);
void args_deinit_stack(Args* self);
void args_init(Args* self, Args* args);
int32_t args_getSize(Args* self);
LinkNode* args_getNode(Args* self, char* name);
Arg* args_getArgByIndex(Args* self, int32_t index);
Arg* args_getArg(Args* self, char* name);
int32_t args_removeArg(Args* self, Arg* argNow);
int args_moveArg(Args* self, Args* dict, Arg* arg);
Arg* args_getArg_hash(Args* self, Hash nameHash);
int32_t args_setArg(Args* self, Arg* arg);
int32_t args_copyArgByName(Args* self, char* name, Args* directList);
int32_t args_copyArg(Args* self, Arg* argToBeCopy);
ArgType args_getType(Args* self, char* name);
int32_t args_isArgExist_hash(Args* self, Hash nameHash);
int32_t args_isArgExist(Args* self, char* name);
int32_t args_setStr(Args* self, char* name, char* strIn);
int32_t args_setStrWithDefaultName(Args* self, char* strIn);
char* args_getStr(Args* self, char* name);
int32_t args_setFloatWithDefaultName(Args* self, float argFloat);
int32_t args_setFloat(Args* self, char* name, float argFloat);
float args_getFloat(Args* self, char* name);
int32_t args_setRefObj(Args* self, char* name, void* argPointer);
int32_t args_setPtr(Args* self, char* name, void* argPointer);
void* args_getPtr(Args* self, char* name);
int32_t args_setInt(Args* self, char* name, int64_t int64In);
int64_t args_getInt(Args* self, char* name);
void args_bindInt(Args* self, char* name, int32_t* intPtr);
void args_bindFloat(Args* self, char* name, float* floatPtr);
void args_bindStr(Args* self, char* name, char** stringPtr);
/* arg general opeartion */
void args_bind(Args* self, char* type, char* name, void* pointer);
char* args_print(Args* self, char* name);
int32_t args_setStructWithSize(Args* self,
char* name,
void* struct_ptr,
uint32_t struct_size);
int32_t args_setHeapStructWithSize(Args* self,
char* name,
void* struct_ptr,
uint32_t struct_size,
void* struct_deinit_fun);
#define args_setStruct(Args_p_self, char_p_name, struct_) \
args_setStructWithSize((Args_p_self), (char_p_name), &(struct_), \
sizeof(struct_))
#define args_setHeapStruct(Args_p_self, char_p_name, struct_, \
struct_deinit_fun) \
args_setHeapStructWithSize((Args_p_self), (char_p_name), &(struct_), \
sizeof(struct_), (void*)struct_deinit_fun)
void* args_getStruct(Args* self, char* name);
int32_t args_set(Args* self, char* name, char* valueStr);
int32_t args_setObjectWithClass(Args* self,
char* objectName,
char* className,
void* objectPtr);
int32_t args_setPtrWithType(Args* self, char* name, ArgType type, void* objPtr);
int32_t args_foreach(Args* self,
int32_t (*eachHandle)(Arg* argEach, Args* handleArgs),
Args* handleArgs);
char* args_getBuff(Args* self, int32_t size);
uint8_t args_setLiteral(Args* self, char* targetArgName, char* literal);
int args_pushArg(Args* self, Arg* arg);
Arg* args_getArg_index(Args* self, int index);
void* args_getHeapStruct(Args* self, char* name);
int32_t args_removeArg_notDeinitArg(Args* self, Arg* argNow);
uint8_t* args_getBytes(Args* self, char* name);
void args_setBytes(Args* self, char* name, uint8_t* src, size_t size);
size_t args_getBytesSize(Args* self, char* name);
Args* New_args(Args* args);
#endif

View File

@ -1,129 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataLink.h"
#include "dataArg.h"
#include "dataLinkNode.h"
#include "dataMemory.h"
void __link_deinit_pyload(Link* self) {
LinkNode* nowNode = self->firstNode;
while (NULL != nowNode) {
LinkNode* nodeNext = content_getNext(nowNode);
linkNode_deinit(nowNode);
nowNode = nodeNext;
}
self = NULL;
}
void link_deinit(Link* self) {
__link_deinit_pyload(self);
pikaFree(self, sizeof(Link));
}
void link_deinit_stack(Link* self) {
__link_deinit_pyload(self);
}
void link_addNode(Link* self, void* content) {
// old first node become new second node
LinkNode* secondNode = self->firstNode;
self->firstNode = content;
// change the first node to new node
content_setNext(content, secondNode);
}
static void __link_removeNode(Link* self,
void* content,
uint8_t is_deinit_node) {
LinkNode* nodeToDelete = NULL;
LinkNode* nodeNow = self->firstNode;
LinkNode* priorNode = NULL;
LinkNode* nextNode;
while (1) {
if (nodeNow == content) {
nodeToDelete = nodeNow;
break;
}
if (nodeNow == NULL) {
// error, node no found
goto exit;
}
priorNode = nodeNow;
nodeNow = content_getNext(nodeNow);
}
nextNode = content_getNext(nodeToDelete);
if (nodeToDelete == self->firstNode) {
self->firstNode = content_getNext(nodeToDelete);
}
if (NULL == priorNode) {
self->firstNode = nextNode;
goto exit;
}
content_setNext(priorNode, nextNode);
goto exit;
// deinit the node
exit:
if (is_deinit_node) {
linkNode_deinit(nodeToDelete);
}
return;
}
void link_removeNode(Link* self, void* content) {
__link_removeNode(self, content, 1);
}
void link_removeNode_notDeinitNode(Link* self, void* content) {
__link_removeNode(self, content, 0);
}
int32_t link_getSize(Link* self) {
LinkNode* NowNode;
int32_t size = 0;
NowNode = self->firstNode;
while (NULL != NowNode) {
size++;
NowNode = content_getNext(NowNode);
}
return size;
}
void link_init(Link* self, void* args) {
self->firstNode = NULL;
}
Link* New_link(void* args) {
Link* self = pikaMalloc(sizeof(Link));
link_init(self, args);
return self;
}

View File

@ -1,52 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _link2__H
#define _link2__H
#include "dataLinkNode.h"
#include "dataMemory.h"
enum LINK_IS_DEINIT_SELF {
LINK_IS_DEINIT_SELF_ENABLE,
LINK_IS_DEINIT_SELF_DISABLE,
};
typedef struct Class_link Link;
struct Class_link {
LinkNode* firstNode;
};
void link_deinit(Link* self);
void link_deinit_stack(Link* self);
void link_init(Link* self, void* args);
void link_addNode(Link* self, void* content);
void link_removeNode(Link* self, void* content);
void link_removeNode_notDeinitNode(Link* self, void* content);
LinkNode* link_getNode(Link* self, int64_t id);
int32_t link_getSize(Link* self);
Link* New_link(void* args);
#endif

View File

@ -1,42 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataLinkNode.h"
#include "dataArg.h"
#include "dataMemory.h"
void linkNode_deinit(LinkNode* self) {
arg_deinit(self);
}
void linkNode_init(LinkNode* self, void* args) {
/* attribute */
}
LinkNode* New_linkNode(void* args) {
return NULL;
}

View File

@ -1,37 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef _linkNode__H
#define _linkNode__H
#include "dataMemory.h"
typedef uint8_t LinkNode;
void linkNode_deinit(LinkNode* self);
void linkNode_init(LinkNode* self, void* args);
LinkNode* New_linkNode(void* args);
#endif

View File

@ -1,296 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataMemory.h"
#include "PikaPlatform.h"
PikaMemInfo pikaMemInfo = {0};
void* pikaMalloc(uint32_t size) {
/* pika memory lock */
if (0 != __is_locked_pikaMemory()) {
__platform_wait();
}
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
#if PIKA_ARG_ALIGN_ENABLE
/* force alignment to avoid unaligned access */
size = (size + 4 - 1) & ~(4 - 1);
#endif
pikaMemInfo.heapUsed += size;
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
}
__platform_disable_irq_handle();
void* mem = __platform_malloc(size);
__platform_enable_irq_handle();
if (NULL == mem) {
__platform_printf(
"[error]: No heap space! Please reset the device.\r\n");
while (1) {
}
}
return mem;
}
void pikaFree(void* mem, uint32_t size) {
if (0 != __is_locked_pikaMemory()) {
__platform_wait();
}
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
#if PIKA_ARG_ALIGN_ENABLE
/* force alignment to avoid unaligned access */
size = (size + 4 - 1) & ~(4 - 1);
#endif
__platform_disable_irq_handle();
__platform_free(mem);
__platform_enable_irq_handle();
pikaMemInfo.heapUsed -= size;
}
uint16_t pikaMemNow(void) {
return pikaMemInfo.heapUsed;
// return 0;
}
uint16_t pikaMemMax(void) {
return pikaMemInfo.heapUsedMax;
}
void pikaMemMaxReset(void) {
pikaMemInfo.heapUsedMax = 0;
}
uint32_t pool_getBlockIndex_byMemSize(Pool* pool, uint32_t size) {
if (0 == size) {
return 0;
}
return (size - 1) / pool->aline + 1;
}
uint32_t pool_aline(Pool* pool, uint32_t size) {
return pool_getBlockIndex_byMemSize(pool, size) * pool->aline;
}
Pool pool_init(uint32_t size, uint8_t aline) {
Pool pool;
pool.aline = aline;
uint32_t block_size = pool_getBlockIndex_byMemSize(&pool, size);
pool.size = pool_aline(&pool, size);
pool.bitmap = bitmap_init(block_size);
pool.mem = __platform_malloc(pool_aline(&pool, pool.size));
pool.first_free_block = 0;
pool.purl_free_block_start = 0;
return pool;
}
void pool_deinit(Pool* pool) {
__platform_free(pool->mem);
pool->mem = NULL;
bitmap_deinit(pool->bitmap);
}
void* pool_getBytes_byBlockIndex(Pool* pool, uint32_t block_index) {
return pool->mem + block_index * pool->aline;
}
uint32_t pool_getBlockIndex_byMem(Pool* pool, void* mem) {
uint32_t mem_size = (uintptr_t)mem - (uintptr_t)pool->mem;
return pool_getBlockIndex_byMemSize(pool, mem_size);
}
void pool_printBlocks(Pool* pool, uint32_t size_min, uint32_t size_max) {
uint32_t block_index_min = pool_getBlockIndex_byMemSize(pool, size_min);
uint32_t block_index_max = pool_getBlockIndex_byMemSize(pool, size_max);
__platform_printf("[bitmap]\r\n");
uint8_t is_end = 0;
for (uint32_t i = block_index_min; i < block_index_max; i += 16) {
if (is_end) {
break;
}
__platform_printf("0x%x\t: ", i * pool->aline, (i + 15) * pool->aline);
for (uint32_t j = i; j < i + 16; j += 4) {
if (is_end) {
break;
}
for (uint32_t k = j; k < j + 4; k++) {
if (k >= block_index_max) {
is_end = 1;
break;
}
__platform_printf("%d", bitmap_get(pool->bitmap, k));
}
__platform_printf(" ");
}
__platform_printf("\r\n");
}
}
void* pool_malloc(Pool* pool, uint32_t size) {
uint32_t block_index_max = pool_getBlockIndex_byMemSize(pool, pool->size);
uint32_t block_num_need = pool_getBlockIndex_byMemSize(pool, size);
uint32_t block_num_found = 0;
uint8_t found_first_free = 0;
uint32_t block_index;
// if (__is_quick_malloc()) {
// /* high speed malloc */
// block_index = pool->purl_free_block_start + block_num_need - 1;
// if (block_index < block_index_max) {
// goto found;
// }
// }
/* low speed malloc */
for (block_index = pool->first_free_block;
block_index < pool->purl_free_block_start; block_index++) {
/* 8 bit is not free */
uint8_t bitmap_byte = bitmap_getByte(pool->bitmap, block_index);
if (0xFF == bitmap_byte) {
block_index = 8 * (block_index / 8) + 7;
block_num_found = 0;
continue;
}
/* found a free block */
if (0 == bitmap_get(pool->bitmap, block_index)) {
/* save the first free */
if (!found_first_free) {
pool->first_free_block = block_index;
found_first_free = 1;
}
block_num_found++;
} else {
/* a used block appeared, find again */
block_num_found = 0;
}
/* found all request blocks */
if (block_num_found >= block_num_need) {
goto found;
}
}
/* malloc for purl free blocks */
block_index = pool->purl_free_block_start + block_num_need - 1;
if (block_index < block_index_max) {
goto found;
}
/* no found */
return NULL;
found:
/* set 1 for found blocks */
for (uint32_t i = 0; i < block_num_need; i++) {
bitmap_set(pool->bitmap, block_index - i, 1);
}
/* save last used block */
if (block_index >= pool->purl_free_block_start) {
pool->purl_free_block_start = block_index + 1;
}
/* return mem by block index */
return pool_getBytes_byBlockIndex(pool, block_index - block_num_need + 1);
}
void pool_free(Pool* pool, void* mem, uint32_t size) {
uint32_t block_num = pool_getBlockIndex_byMemSize(pool, size);
uint32_t block_index = pool_getBlockIndex_byMem(pool, mem);
for (uint32_t i = 0; i < block_num; i++) {
bitmap_set(pool->bitmap, block_index + i, 0);
}
/* save min free block index to add speed */
if (block_index < pool->first_free_block) {
pool->first_free_block = block_index;
}
/* save last free block index to add speed */
uint32_t block_end = block_index + block_num - 1;
if (block_end == pool->purl_free_block_start - 1) {
uint32_t first_pure_free_block = block_index;
/* back to first used block */
if (0 != first_pure_free_block) {
while (0 == bitmap_get(pool->bitmap, first_pure_free_block - 1)) {
first_pure_free_block--;
if (0 == first_pure_free_block) {
break;
}
}
}
pool->purl_free_block_start = first_pure_free_block;
}
return;
}
uint32_t aline_by(uint32_t size, uint32_t aline) {
if (size == 0) {
return 0;
}
return ((size - 1) / aline + 1) * aline;
}
BitMap bitmap_init(uint32_t size) {
BitMap mem_bit_map =
(BitMap)__platform_malloc(((size - 1) / 8 + 1) * sizeof(char));
if (mem_bit_map == NULL) {
return NULL;
}
uint32_t size_mem_bit_map = (size - 1) / 8 + 1;
__platform_memset(mem_bit_map, 0x0, size_mem_bit_map);
return mem_bit_map;
}
void bitmap_set(BitMap bitmap, uint32_t index, uint8_t bit) {
uint32_t index_byte = index / 8;
uint8_t index_bit = index % 8;
uint8_t x = (0x1 << index_bit);
/* set 1 */
if (bit) {
bitmap[index_byte] |= x;
return;
}
/* set 0 */
bitmap[index_byte] &= ~x;
return;
}
uint8_t bitmap_getByte(BitMap bitmap, uint32_t index) {
uint32_t index_byte = (index) / 8;
uint8_t byte;
byte = bitmap[index_byte];
return byte;
}
uint8_t bitmap_get(BitMap bitmap, uint32_t index) {
uint32_t index_byte = (index) / 8;
uint8_t index_bit = (index) % 8;
uint8_t x = (0x1 << index_bit);
uint8_t bit;
bit = bitmap[index_byte] & x;
return bit > 0 ? 1 : 0;
}
void bitmap_deinit(BitMap bitmap) {
__platform_free(bitmap);
}

View File

@ -1,68 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __MEMORY_H__
#define __MEMORY_H__
#include "PikaPlatform.h"
typedef struct {
uint32_t heapUsed;
uint32_t heapUsedMax;
} PikaMemInfo;
typedef uint8_t* BitMap;
typedef struct {
BitMap bitmap;
uint8_t* mem;
uint8_t aline;
uint32_t size;
uint32_t first_free_block;
uint32_t purl_free_block_start;
} Pool;
void pikaFree(void* mem, uint32_t size);
void* pikaMalloc(uint32_t size);
uint16_t pikaMemNow(void);
uint16_t pikaMemMax(void);
void pikaMemMaxReset(void);
uint32_t aline_by(uint32_t size, uint32_t aline);
BitMap bitmap_init(uint32_t size);
void bitmap_set(BitMap bitmap, uint32_t index, uint8_t bit);
uint8_t bitmap_get(BitMap bitmap, uint32_t index);
uint8_t bitmap_getByte(BitMap bitmap, uint32_t index);
void bitmap_deinit(BitMap bitmap);
Pool pool_init(uint32_t size, uint8_t aline);
void* pool_malloc(Pool* pool, uint32_t size);
void pool_free(Pool* pool, void* mem, uint32_t size);
void pool_deinit(Pool* pool);
void pool_printBlocks(Pool* pool, uint32_t block_min, uint32_t block_max);
#endif

View File

@ -1,108 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataQueue.h"
#include "PikaPlatform.h"
#include "dataArgs.h"
void queue_init(Queue* queue) {
args_setInt(queue, "__t", 0);
args_setInt(queue, "__b", 0);
}
Queue* New_queue(void) {
Args* args = New_args(NULL);
queue_init(args);
return (Queue*)args;
}
int32_t queue_deinit(Queue* queue) {
Args* args = queue;
args_deinit(args);
return 0;
}
int32_t queue_pushArg(Queue* queue, Arg* arg) {
Args* args = queue;
uint64_t top = args_getInt(args, "__t");
/* add top */
args_setInt(args, "__t", top + 1);
char buff[11];
arg = arg_setName(arg, fast_itoa(buff, top));
return args_setArg(args, arg);
}
Arg* __queue_popArg(Queue* queue, uint8_t is_deinit_arg) {
Args* args = queue;
uint64_t top = args_getInt(args, "__t");
uint64_t bottom = args_getInt(args, "__b");
if (top - bottom < 1) {
return NULL;
}
/* add bottom */
args_setInt(args, "__b", bottom + 1);
char buff[11];
Arg* res = args_getArg(args, fast_itoa(buff, bottom));
if (is_deinit_arg) {
args_removeArg(args, res);
} else {
args_removeArg_notDeinitArg(args, res);
}
return res;
}
Arg* queue_popArg(Queue* queue) {
return __queue_popArg(queue, 1);
}
Arg* queue_popArg_notDeinitArg(Queue* queue) {
return __queue_popArg(queue, 0);
}
int32_t queue_pushInt(Queue* queue, int val) {
return queue_pushArg(queue, arg_setInt(NULL, "", val));
}
int64_t queue_popInt(Queue* queue) {
return arg_getInt(queue_popArg(queue));
}
int32_t queue_pushFloat(Queue* queue, float val) {
return queue_pushArg(queue, arg_setFloat(NULL, "", val));
}
float queue_popFloat(Queue* queue) {
return arg_getFloat(queue_popArg(queue));
}
int32_t queue_pushStr(Queue* queue, char* str) {
return queue_pushArg(queue, arg_setStr(NULL, "", str));
}
char* queue_popStr(Queue* queue) {
return arg_getStr(queue_popArg(queue));
}

View File

@ -1,49 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __DATA_QUEUE__H
#define __DATA_QUEUE__H
#include "dataArgs.h"
typedef Args Queue;
Queue* New_queue(void);
int32_t queue_deinit(Queue* queue);
int32_t queue_pushInt(Queue* queue, int val);
int32_t queue_pushFloat(Queue* queue, float val);
int32_t queue_pushStr(Queue* queue, char* str);
int32_t queue_pushArg(Queue* queue, Arg* arg);
char* fast_itoa(char* buf, uint32_t val);
int64_t queue_popInt(Queue* queue);
float queue_popFloat(Queue* queue);
char* queue_popStr(Queue* queue);
Arg* queue_popArg(Queue* queue);
Arg* queue_popArg_notDeinitArg(Queue* queue);
int32_t queue_deinit_stack(Queue* queue);
void queue_init(Queue* queue);
#endif

View File

@ -1,125 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataQueueObj.h"
#include "BaseObj.h"
#include "dataQueue.h"
QueueObj* New_queueObj(void) {
PikaObj* self = New_PikaObj();
queueObj_init(self);
return self;
}
int32_t queueObj_init(QueueObj* self) {
obj_setInt(self, "top", 0);
obj_setInt(self, "bottom", 0);
return 0;
}
int32_t queueObj_pushObj(QueueObj* self, char* className) {
uint64_t top = obj_getInt(self, "top");
char buff[11];
char* topStr = fast_itoa(buff, top);
/* add top */
obj_setInt(self, "top", top + 1);
return obj_newObj(self, topStr, className, New_TinyObj);
}
PikaObj* queueObj_getCurrentObj(QueueObj* self) {
uint64_t current = obj_getInt(self, "top") - 1;
char buff[11];
char* currentStr = fast_itoa(buff, current);
return obj_getObjWithKeepDeepth(self, currentStr, 0);
}
PikaObj* queueObj_popObj(QueueObj* self) {
uint64_t bottom = obj_getInt(self, "bottom");
char buff[11];
char* bottomStr = fast_itoa(buff, bottom);
/* add bottom */
obj_setInt(self, "bottom", bottom + 1);
PikaObj* res = obj_getObjWithKeepDeepth(self, bottomStr, 0);
return res;
}
int32_t queueObj_pushInt(QueueObj* self, int val) {
uint64_t top = obj_getInt(self, "top");
char buff[11];
char* topStr = fast_itoa(buff, top);
/* add top */
obj_setInt(self, "top", top + 1);
return obj_setInt(self, topStr, val);
}
int64_t queueObj_popInt(QueueObj* self) {
uint64_t bottom = obj_getInt(self, "bottom");
char buff[11];
char* bottomStr = fast_itoa(buff, bottom);
/* add bottom */
obj_setInt(self, "bottom", bottom + 1);
int64_t res = obj_getInt(self, bottomStr);
obj_removeArg(self, bottomStr);
return res;
}
int32_t queueObj_pushFloat(QueueObj* self, float val) {
uint64_t top = obj_getInt(self, "top");
char buff[11];
char* topStr = fast_itoa(buff, top);
/* add top */
obj_setInt(self, "top", top + 1);
return obj_setFloat(self, topStr, val);
}
float queueObj_popFloat(QueueObj* self) {
uint64_t bottom = obj_getInt(self, "bottom");
char buff[11];
char* bottomStr = fast_itoa(buff, bottom);
/* add bottom */
obj_setInt(self, "bottom", bottom + 1);
float res = obj_getFloat(self, bottomStr);
obj_removeArg(self, bottomStr);
return res;
}
int32_t queueObj_pushStr(QueueObj* self, char* str) {
uint64_t top = obj_getInt(self, "top");
char buff[11];
char* topStr = fast_itoa(buff, top);
/* add top */
obj_setInt(self, "top", top + 1);
return obj_setStr(self, topStr, str);
}
char* queueObj_popStr(QueueObj* self) {
uint64_t bottom = obj_getInt(self, "bottom");
char buff[11];
char* bottomStr = fast_itoa(buff, bottom);
/* add bottom */
obj_setInt(self, "bottom", bottom + 1);
return obj_getStr(self, bottomStr);
}

View File

@ -1,48 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __DATA_QUEUE_OBJ__H
#define __DATA_QUEUE_OBJ__H
#include "PikaObj.h"
typedef PikaObj QueueObj;
QueueObj* New_queueObj(void);
int32_t queueObj_init(QueueObj* self);
int32_t queueObj_pushInt(QueueObj* self, int val);
int32_t queueObj_pushFloat(QueueObj* self, float val);
int32_t queueObj_pushStr(QueueObj* self, char* str);
int32_t queueObj_pushObj(QueueObj* self, char* className);
int64_t queueObj_popInt(QueueObj* self);
float queueObj_popFloat(QueueObj* self);
char* queueObj_popStr(QueueObj* self);
PikaObj* queueObj_popObj(QueueObj* self);
PikaObj* queueObj_getCurrentObj(QueueObj* self);
#endif

View File

@ -1,120 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataStack.h"
#include "PikaObj.h"
#include "dataQueue.h"
void stack_reset(Stack* stack) {
stack->sp = (uint8_t*)arg_getContent(stack->stack_pyload);
stack->sp_size = (int16_t*)arg_getContent(stack->stack_size_array);
stack->top = 0;
}
int32_t stack_init(Stack* stack) {
stack->stack_pyload = arg_setContent(NULL, NULL, PIKA_STACK_BUFF_SIZE);
stack->stack_size_array =
arg_setContent(NULL, NULL, PIKA_STACK_BUFF_SIZE / 4);
stack_reset(stack);
return 0;
};
void stack_pushSize(Stack* stack, int16_t size) {
*(stack->sp_size) = size;
stack->sp_size++;
}
int16_t stack_popSize(Stack* stack) {
stack->sp_size--;
return *(stack->sp_size);
}
int32_t stack_deinit(Stack* stack) {
arg_deinit(stack->stack_pyload);
arg_deinit(stack->stack_size_array);
return 0;
}
void stack_pushPyload(Stack* stack, uint8_t* content, size_t size) {
__platform_memcpy(stack->sp, content, size);
stack->sp += size;
}
uint8_t* stack_popPyload(Stack* stack, size_t size) {
stack->sp -= size;
return stack->sp;
}
int32_t stack_pushArg(Stack* stack, Arg* arg) {
stack->top++;
size_t size = arg_getTotleSize(arg);
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
#if PIKA_ARG_ALIGN_ENABLE
/* force alignment to avoid unaligned access */
size = (size + 4 - 1) & ~(4 - 1);
#endif
/* add ref_cnt to keep object in stack */
if (arg_getType(arg) == ARG_TYPE_OBJECT) {
obj_refcntInc(arg_getPtr(arg));
}
stack_pushSize(stack, size);
stack_pushPyload(stack, arg, size);
arg_deinit(arg);
return 0;
}
int32_t stack_pushStr(Stack* stack, char* str) {
Arg* newArg = arg_setStr(NULL, "", str);
return stack_pushArg(stack, newArg);
}
Arg* stack_popArg(Stack* stack) {
if (stack->top == 0) {
return NULL;
}
stack->top--;
int16_t size = stack_popSize(stack);
Arg* arg = arg_copy((Arg*)stack_popPyload(stack, size));
/* decrase ref_cnt */
if (arg_getType(arg) == ARG_TYPE_OBJECT) {
obj_refcntDec(arg_getPtr(arg));
}
return arg;
}
char* stack_popStr(Stack* stack, char* outBuff) {
Arg* arg = stack_popArg(stack);
strcpy(outBuff, arg_getStr(arg));
arg_deinit(arg);
return outBuff;
}
int8_t stack_getTop(Stack* stack) {
return stack->top;
}

View File

@ -1,51 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __DATA_STACK__H
#define __DATA_STACK__H
#include "dataArgs.h"
typedef struct Stack_t {
Arg* stack_pyload;
Arg* stack_size_array;
uint8_t* sp;
int16_t* sp_size;
int16_t top;
} Stack;
int32_t stack_deinit(Stack* stack);
int32_t stack_pushStr(Stack* stack, char* str);
char* stack_popStr(Stack* stack, char* outBuff);
Arg* stack_popArg(Stack* stack);
int32_t stack_pushArg(Stack* stack, Arg* arg);
int8_t stack_getTop(Stack* stack);
int32_t stack_init(Stack* stack);
int16_t stack_popSize(Stack* stack);
void stack_pushSize(Stack* stack, int16_t size);
void stack_reset(Stack* stack);
#endif

View File

@ -1,326 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataString.h"
#include "PikaPlatform.h"
char* strAppendWithSize_unlimited(char* strOut, char* pData, int32_t Size) {
int32_t strOut_i = strGetSize(strOut);
for (int32_t i = 0; i < Size; i++) {
strOut[strOut_i + i] = pData[i];
}
strOut_i += Size;
// add \0 to the end of strOut
strOut[strOut_i] = 0;
return strOut;
}
char* strCut(char* strOut, char* strIn, char startSign, char endSign) {
int32_t Size = strGetSize(strIn);
int32_t iStart = 0;
int32_t iEnd = Size;
uint8_t isStart = 0;
uint8_t isEnd = 0;
for (int32_t i = 0; i < Size; i++) {
if (strIn[i] == startSign) {
iStart = i;
isStart = 1;
break;
}
}
for (int32_t i = Size - 1; i >= 0; i--) {
if (strIn[i] == endSign) {
iEnd = i;
isEnd = 1;
break;
}
}
int outi = 0;
for (int32_t i = iStart + 1; i < iEnd; i++) {
strOut[outi] = strIn[i];
outi++;
}
/* add \0 */
strOut[outi] = 0;
if (isStart && isEnd) {
/* succeed */
return strOut;
}
/* faild */
return NULL;
}
char* strDeleteChar(char* strOut, char* strIn, char ch) {
int32_t iOut = 0;
for (uint32_t i = 0; i < strGetSize(strIn); i++) {
if (ch == strIn[i]) {
continue;
}
strOut[iOut] = strIn[i];
iOut++;
}
/* add \0 */
strOut[iOut] = 0;
return strOut;
}
char* strDeleteEnter(char* str) {
return strDeleteChar(str, str, '\n');
}
char* strAppendWithSize(char* strOut, char* pData, int32_t Size) {
int32_t strOut_i = strGetSize(strOut);
for (int32_t i = 0; i < Size; i++) {
strOut[strOut_i + i] = pData[i];
}
strOut_i += Size;
// add \0 to the end of strOut
strOut[strOut_i] = 0;
return strOut;
}
int32_t strCountSign(char* strIn, char sign) {
int32_t count = 0;
for (uint32_t i = 0; i < strGetSize(strIn); i++) {
if (sign == strIn[i]) {
count++;
}
}
return count;
}
int32_t strGetTokenNum(char* strIn, char sign) {
return strCountSign(strIn, sign) + 1;
}
uint32_t strGetSize(char* pData) {
return strlen(pData);
}
char* strAppend_unlimited(char* strOut, char* pData) {
uint32_t Size = 0;
Size = strGetSize(pData);
return strAppendWithSize_unlimited(strOut, pData, Size);
}
char* strGetLastLine(char* strOut, char* strIn) {
int32_t size = strGetSize(strIn);
char sign = '\n';
uint32_t beginIndex = 0;
/* skip the latest '\n' */
for (int32_t i = size - 2; i > -1; i--) {
if (strIn[i] == sign) {
beginIndex = i + 1;
break;
}
}
__platform_memcpy(strOut, strIn + beginIndex, size - beginIndex);
strOut[size - beginIndex + 1] = 0;
return strOut;
}
char* strPointToLastToken(char* strIn, char sign) {
int32_t size = strGetSize(strIn);
for (int32_t i = size - 1; i > -1; i--) {
if (strIn[i] == sign) {
return strIn + i + 1;
}
}
return strIn;
}
char* strPopLastToken(char* strIn, char sign) {
char* last_token = strPointToLastToken(strIn, sign);
if (last_token != strIn) {
*(last_token - 1) = 0;
}
return last_token;
}
char* strGetLastToken(char* strOut, char* strIn, char sign) {
int32_t size = strGetSize(strIn);
int32_t buffSize = 0;
for (int32_t i = size - 1; i > -1; i--) {
if (strIn[i] != sign) {
strOut[size - i - 1] = strIn[i];
buffSize++;
}
if (strIn[i] == sign) {
break;
}
}
int32_t i = 0;
for (i = 0; i < buffSize / 2; i++) {
char buff = strOut[i];
strOut[i] = strOut[buffSize - i - 1];
strOut[buffSize - i - 1] = buff;
}
strOut[buffSize] = 0;
return strOut;
}
char* strPopToken(char* strOut, char* strIn, char sign) {
int32_t getSign = 0;
int32_t iPoped = 0;
int32_t iOut = 0;
int32_t size = strGetSize(strIn);
int32_t i = 0;
for (i = 0; i < size; i++) {
if (getSign) {
strIn[iPoped] = strIn[i];
iPoped++;
continue;
}
if (strIn[i] != sign) {
strOut[iOut++] = strIn[i];
continue;
}
if (strIn[i] == sign) {
getSign = 1;
continue;
}
}
strOut[iOut] = 0;
strIn[iPoped] = 0;
return strOut;
}
char* strGetFirstToken(char* strOut, char* strIn, char sign) {
int32_t size = strGetSize(strIn);
for (int32_t i = 0; i < size; i++) {
if (strIn[i] != sign) {
strOut[i] = strIn[i];
}
if (strIn[i] == sign) {
break;
}
}
return strOut;
}
int32_t strGetToken(char* string, char** argv, char sign) {
int32_t argc = 0;
uint32_t i = 0;
// arg_i point32_t to the arg operated now
int32_t arg_i = 0;
// if not found ' ', then put chars from CMD to argv_tem
int32_t char_i = 0;
for (i = 0; i < strGetSize(string); i++) {
if (string[i] != sign) {
argv[arg_i][char_i] = string[i];
char_i++;
}
if (string[i] == sign) {
// write '\0' to the end of argv
argv[arg_i][char_i] = 0;
arg_i++;
char_i = 0;
}
// write '\0' to the end of last argv
argv[arg_i][char_i] = 0;
}
argc = arg_i + 1;
return argc;
}
char* strAppend(char* strOut, char* pData) {
uint32_t Size = 0;
Size = strGetSize(pData);
return strAppendWithSize(strOut, pData, Size);
}
int32_t strIsStartWith(char* str, char* strStart) {
if (NULL == str || NULL == strStart) {
/* input is null */
return 0;
}
uint32_t size = strGetSize(strStart);
if (0 == strncmp(str, strStart, size)) {
return 1;
}
return 0;
}
int32_t strEqu(char* str1, char* str2) {
if (NULL == str1 || NULL == str2) {
return 0;
}
return !strcmp(str1, str2);
}
char* strRemovePrefix(char* inputStr, char* prefix, char* outputStr) {
if (!strIsStartWith(inputStr, prefix)) {
return NULL;
}
for (uint32_t i = strGetSize(prefix); i < strGetSize(inputStr); i++) {
outputStr[i - strGetSize(prefix)] = inputStr[i];
}
return outputStr;
}
char* strClear(char* str) {
for (uint32_t i = 0; i < sizeof(str); i++) {
str[i] = 0;
}
return str;
}
int32_t strIsContain(char* str, char ch) {
for (uint32_t i = 0; i < strGetSize(str); i++) {
if (str[i] == ch) {
return 1;
}
}
return 0;
}
char* strCopy(char* strBuff, char* strIn) {
__platform_memcpy(strBuff, strIn, strGetSize(strIn));
return strBuff;
}
int32_t strGetLineSize(char* str) {
int i = 0;
while (1) {
if (str[i] == '\n') {
return i;
}
i++;
}
}
char* strGetLine(char* strOut, char* strIn) {
int32_t lineSize = strGetLineSize(strIn);
__platform_memcpy(strOut, strIn, lineSize);
strOut[lineSize] = 0;
return strOut;
}

View File

@ -1,64 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __MY_TEST_TOOLS_H
#define __MY_TEST_TOOLS_H
#include "PikaPlatform.h"
/* size */
uint32_t strGetSize(char* pData);
/* append */
char* strAppend(char* strOut, char* pData);
char* strAppend_unlimited(char* strOut, char* pData);
char* strAppendWithSize(char* strOut, char* pData, int32_t Size);
/* cut */
char* strCut(char* strOut, char* strIn, char startSign, char endSign);
/* assert */
int32_t strIsStartWith(char* str, char* strStart);
int32_t strEqu(char* str1, char* str2);
/* delete */
char* strDeleteEnter(char* str);
char* strDeleteChar(char* strOut, char* strIn, char ch);
/* prefix */
char* strRemovePrefix(char* inputStr, char* prefix, char* outputStr);
/* token */
int32_t strGetToken(char* string, char** argv, char sign);
char* strPopToken(char* strOut, char* strIn, char sign);
int32_t strCountSign(char* strIn, char sign);
int32_t strGetTokenNum(char* strIn, char sign);
char* strGetFirstToken(char* strOut, char* strIn, char sign);
char* strGetLastToken(char* strOut, char* strIn, char sign);
char* strClear(char* str);
int32_t strIsContain(char* str, char ch);
char* strCopy(char* strBuff, char* strIn);
char* strGetLastLine(char* strOut, char* strIn);
char* strPointToLastToken(char* strIn, char sign);
char* strGetLine(char* strOut, char* strIn);
int32_t strGetLineSize(char* str);
char* strPopLastToken(char* strIn, char sign);
#endif

View File

@ -1,182 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "dataStrs.h"
#include "PikaPlatform.h"
#include "dataString.h"
Args* New_strBuff(void) {
return New_args(NULL);
}
char* strsRemovePrefix(Args* buffs_p, char* inputStr, char* prefix) {
int32_t size = strGetSize(inputStr);
char* buff = args_getBuff(buffs_p, size);
return strRemovePrefix(inputStr, prefix, buff);
}
char* strsGetDirectStr(Args* buffs_p, char* argPath) {
char* directStr = NULL;
directStr = strsCut(buffs_p, argPath, '"', '"');
if (NULL != directStr) {
return directStr;
}
directStr = strsCut(buffs_p, argPath, '\'', '\'');
if (NULL != directStr) {
return directStr;
}
return NULL;
}
char* strsAppend(Args* buffs_p, char* strOrigin, char* strToAppend) {
int32_t size = strGetSize(strOrigin) + strGetSize(strToAppend);
char* buff = args_getBuff(buffs_p, size);
char* strOut = strCopy(buff, strOrigin);
strAppend(strOut, strToAppend);
return strOut;
}
char* strsGetLastToken(Args* buffs_p, char* argPath, char sign) {
int32_t size = strGetSize(argPath);
char* buff = args_getBuff(buffs_p, size);
return strGetLastToken(buff, argPath, sign);
}
char* strsCut(Args* buffs_p, char* strIn, char startSign, char endSign) {
int32_t size = strGetSize(strIn);
char* buff = args_getBuff(buffs_p, size);
return strCut(buff, strIn, startSign, endSign);
}
char* strsDeleteChar(Args* buffs_p, char* strIn, char ch) {
int32_t size = strGetSize(strIn);
return strDeleteChar(args_getBuff(buffs_p, size), strIn, ch);
}
static uint32_t getSizeOfFirstToken(char* str, char sign) {
uint32_t size = strGetSize(str);
for (uint32_t i = 0; i < size; i++) {
if (str[i] == sign) {
return i;
}
}
return size;
}
char* strsGetFirstToken(Args* buffs_p, char* strIn, char sign) {
int32_t size = getSizeOfFirstToken(strIn, sign);
return strGetFirstToken(args_getBuff(buffs_p, size), strIn, sign);
}
char* strsPopToken(Args* buffs_p, char* tokens, char sign) {
int32_t size = strGetSize(tokens);
char* buff = args_getBuff(buffs_p, size);
return strPopToken(buff, tokens, sign);
}
char* strsCopy(Args* buffs_p, char* source) {
int32_t size = strGetSize(source);
char* buff = args_getBuff(buffs_p, size);
return strCopy(buff, source);
}
char* strsFormat(Args* buffs_p, uint16_t buffSize, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
char* res = args_getBuff(buffs_p, buffSize);
__platform_vsnprintf(res, buffSize, fmt, args);
va_end(args);
return res;
}
Arg* arg_strAppend(Arg* arg_in, char* str_to_append) {
Args buffs = {0};
char* str_out = strsAppend(&buffs, arg_getStr(arg_in), str_to_append);
Arg* arg_out = arg_setStr(arg_in, "", str_out);
arg_deinit(arg_in);
strsDeinit(&buffs);
return arg_out;
}
char* strsReplace(Args* buffs_p, char* orig, char* rep, char* with) {
char* result; // the return string
char* ins; // the next insert point
char* tmp; // varies
int len_rep; // length of rep (the string to remove)
int len_with; // length of with (the string to replace rep with)
int len_front; // distance between rep and end of last rep
int count; // number of replacements
// sanity checks and initialization
if (!orig || !rep)
return NULL;
len_rep = strlen(rep);
if (len_rep == 0)
return NULL; // empty rep causes infinite loop during count
if (!with)
with = "";
len_with = strlen(with);
// count the number of replacements needed
ins = orig;
tmp = strstr(ins, rep);
count = 0;
while (tmp) {
count++;
ins = tmp + len_rep;
tmp = strstr(ins, rep);
}
tmp =
args_getBuff(buffs_p, strlen(orig) + (len_with - len_rep) * count + 1);
result = tmp;
if (NULL == result) {
return NULL;
}
// first time through the loop, all the variable are set correctly
// from here on,
// tmp points to the end of the result string
// ins points to the next occurrence of rep in orig
// orig points to the remainder of orig after "end of rep"
while (count--) {
ins = strstr(orig, rep);
len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; // move to next "end of rep"
}
strcpy(tmp, orig);
return result;
}
char* strsGetLine(Args* buffs_p, char* code) {
int32_t lineSize = strGetLineSize(code);
char* line_buff = args_getBuff(buffs_p, lineSize + 1);
return strGetLine(line_buff, code);
}
void strsDeinit(Args* buffs_p) {
link_deinit_stack(buffs_p);
}

View File

@ -1,46 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __STR_ARGS__H
#define __STR_ARGS__H
#include "dataArgs.h"
Args* New_strBuff(void);
char* strsGetFirstToken(Args* buffs, char* strIn, char sign);
char* strsGetLastToken(Args* buffs, char* arg_Path, char sign);
char* strsPopToken(Args* buffs, char* tokens, char sign);
char* strsCopy(Args* buffs, char* source);
char* strsDeleteChar(Args* buff, char* strIn, char ch);
char* strsCut(Args* buffs, char* strIn, char startSign, char endSign);
char* strsRemovePrefix(Args* buffs, char* inputStr, char* prefix);
char* strsAppend(Args* buffs, char* strOrigin, char* strAppend);
char* strsFormat(Args* buffs, uint16_t buffSize, const char* fmt, ...);
char* strsGetDirectStr(Args* buffs, char* argPath);
Arg* arg_strAppend(Arg* arg_in, char* str_to_append);
char* strsReplace(Args* buffs, char* orig, char* rep, char* with);
char* strsGetLine(Args* buffs, char* code);
void strsDeinit(Args* buffs);
#endif

View File

@ -1,87 +0,0 @@
#include "PikaParser.h"
#include "BaseObj.h"
#include "PikaObj.h"
#include "dataQueue.h"
#include "dataQueueObj.h"
#include "dataStack.h"
#include "dataStrs.h"
#include "pikaCompiler.h"
/* const Pool output redirect */
static void __handler_constPool_output_file(ConstPool* self, char* content) {
/* to ram */
uint16_t size = strGetSize(content) + 1;
self->arg_buff = arg_append(self->arg_buff, content, size);
/* to flash */
__platform_fwrite(content, 1, size, self->output_f);
}
/* instruct array output redirect */
static void __handler_instructArray_output_none(InstructArray* self,
InstructUnit* ins_unit) {
/* none */
}
static void __handler_instructArray_output_file(InstructArray* self,
InstructUnit* ins_unit) {
/* to flash */
__platform_fwrite(ins_unit, 1, instructUnit_getSize(), self->output_f);
}
/*
need implament :
__platform_fopen()
__platform_fwrite()
__platform_fclose()
*/
int pikaCompile(char* output_file_name, char* py_lines) {
ByteCodeFrame bytecode_frame = {0};
FILE* bytecode_f = __platform_fopen(output_file_name, "w+");
/* main process */
/* step 1, get size of const pool and instruct array */
byteCodeFrame_init(&bytecode_frame);
bytecode_frame.const_pool.output_f = bytecode_f;
bytecode_frame.instruct_array.output_f = bytecode_f;
bytecode_frame.instruct_array.output_redirect_fun =
__handler_instructArray_output_none;
Parser_parsePyLines(NULL, &bytecode_frame, py_lines);
uint16_t const_pool_size = bytecode_frame.const_pool.size;
uint16_t instruct_array_size = bytecode_frame.instruct_array.size;
byteCodeFrame_deinit(&bytecode_frame);
/* step 2, write instruct array to file */
__platform_fwrite(&instruct_array_size, 1, 2, bytecode_f);
byteCodeFrame_init(&bytecode_frame);
bytecode_frame.const_pool.output_f = bytecode_f;
bytecode_frame.instruct_array.output_f = bytecode_f;
/* instruct array to file */
bytecode_frame.instruct_array.output_redirect_fun =
__handler_instructArray_output_file;
Parser_parsePyLines(NULL, &bytecode_frame, py_lines);
byteCodeFrame_deinit(&bytecode_frame);
/* step 3, write const pool to file */
__platform_fwrite(&const_pool_size, 1, 2, bytecode_f);
char void_ = 0;
/* add \0 at the start */
__platform_fwrite(&void_, 1, 1, bytecode_f);
byteCodeFrame_init(&bytecode_frame);
bytecode_frame.const_pool.output_f = bytecode_f;
bytecode_frame.instruct_array.output_f = bytecode_f;
/* const pool to file */
bytecode_frame.const_pool.output_redirect_fun =
__handler_constPool_output_file;
/* instruct array to none */
bytecode_frame.instruct_array.output_redirect_fun =
__handler_instructArray_output_none;
Parser_parsePyLines(NULL, &bytecode_frame, py_lines);
byteCodeFrame_deinit(&bytecode_frame);
/* deinit */
__platform_fclose(bytecode_f);
/* succeed */
return 0;
};

View File

@ -1,5 +0,0 @@
#ifndef __PIKA_COMPILER__H
#define __PIKA_COMPILER__H
#endif

View File

@ -1,67 +0,0 @@
/*
* This file is part of the PikaScript project.
* http://github.com/pikastech/pikascript
*
* MIT License
*
* Copyright (c) 2021 lyon liang6516@outlook.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __PIKA_CFG_VALID_H__
#define __PIKA_CFG_VALID_H__
/* default configuration */
#define PIKA_LINE_BUFF_SIZE 128
#define PIKA_SPRINTF_BUFF_SIZE 128
#define PIKA_STACK_BUFF_SIZE 256
#define PIKA_NAME_BUFF_SIZE 32
#define PIKA_PATH_BUFF_SIZE 64
#define PIKA_BYTES_DEFAULT_SIZE 64
#define PIKA_ARG_ALIGN_ENABLE 1
#define PIKA_METHOD_CACHE_ENABLE 0
#define PIKA_BUILTIN_LIST_ENABLE 0
#define PIKA_BUILTIN_DICT_ENABLE 0
/* optimize options */
#define PIKA_OPTIMIZE_SIZE 0
#define PIKA_OPTIMIZE_SPEED 1
/* default optimize */
#define PIKA_OPTIMIZE PIKA_OPTIMIZE_SIZE
/* use user config */
#ifdef PIKA_CONFIG_ENABLE
#include "pika_config.h"
#endif
/* config for size optimize */
#if PIKA_OPTIMIZE == PIKA_OPTIMIZE_SIZE
#undef PIKA_METHOD_CACHE_ENABLE
#define PIKA_METHOD_CACHE_ENABLE 0
/* config for speed optimize */
#elif PIKA_OPTIMIZE == PIKA_OPTIMIZE_SPEED
#undef PIKA_METHOD_CACHE_ENABLE
#define PIKA_METHOD_CACHE_ENABLE 1
#endif
/* configuration validation */
#endif