mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
remove pikascriptcore
This commit is contained in:
parent
bcf40725e8
commit
c08a077f27
@ -1,89 +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 "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "TinyObj.h"
|
||||
#include "dataMemory.h"
|
||||
#include "dataString.h"
|
||||
#include "dataStrs.h"
|
||||
|
||||
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* arg = args_getArg(args, "val");
|
||||
ArgType arg_type = arg_getType(arg);
|
||||
if (NULL != arg) {
|
||||
if (arg_getType(arg) == ARG_TYPE_BYTES) {
|
||||
arg_printBytes(arg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ARG_TYPE_OBJECT == arg_type) {
|
||||
char* to_str = obj_toStr(arg_getPtr(arg));
|
||||
if (NULL != to_str) {
|
||||
__platform_printf("%s\r\n", to_str);
|
||||
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;
|
||||
}
|
@ -1,38 +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);
|
||||
void Baseobj_print(PikaObj* self, Args* args);
|
||||
|
||||
#endif
|
@ -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})
|
@ -1,582 +0,0 @@
|
||||
|
||||
#include "PikaCompiler.h"
|
||||
#include "BaseObj.h"
|
||||
#include "PikaObj.h"
|
||||
#include "PikaParser.h"
|
||||
#include "dataQueue.h"
|
||||
#include "dataQueueObj.h"
|
||||
#include "dataStack.h"
|
||||
#include "dataStrs.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, "wb+");
|
||||
/* 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;
|
||||
};
|
||||
|
||||
/*
|
||||
need implament :
|
||||
__platform_fopen()
|
||||
__platform_fread()
|
||||
__platform_fwrite()
|
||||
__platform_fclose()
|
||||
*/
|
||||
int pikaCompileFileWithOutputName(char* output_file_name,
|
||||
char* input_file_name) {
|
||||
Args buffs = {0};
|
||||
Arg* input_file_arg = arg_loadFile(NULL, input_file_name);
|
||||
if (NULL == input_file_arg) {
|
||||
return 1;
|
||||
}
|
||||
char* lines = (char*)arg_getBytes(input_file_arg);
|
||||
/* replace the "\r\n" to "\n" */
|
||||
lines = strsReplace(&buffs, lines, "\r\n", "\n");
|
||||
/* clear the void line */
|
||||
lines = strsReplace(&buffs, lines, "\n\n", "\n");
|
||||
/* add '\n' at the end */
|
||||
lines = strsAppend(&buffs, lines, "\n\n");
|
||||
pikaCompile(output_file_name, lines);
|
||||
arg_deinit(input_file_arg);
|
||||
strsDeinit(&buffs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pikaCompileFile(char* input_file_name) {
|
||||
Args buffs = {0};
|
||||
char* output_file_name = strsGetFirstToken(&buffs, input_file_name, '.');
|
||||
output_file_name = strsAppend(&buffs, input_file_name, ".o");
|
||||
pikaCompileFileWithOutputName(output_file_name, input_file_name);
|
||||
strsDeinit(&buffs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LibObj* New_LibObj(Args* args) {
|
||||
LibObj* self = New_TinyObj(NULL);
|
||||
return self;
|
||||
}
|
||||
|
||||
void LibObj_deinit(LibObj* self) {
|
||||
obj_deinit(self);
|
||||
}
|
||||
|
||||
/* add bytecode to lib, not copy the bytecode */
|
||||
void LibObj_dynamicLink(LibObj* self, char* module_name, uint8_t* bytecode) {
|
||||
if (!obj_isArgExist(self, module_name)) {
|
||||
obj_newObj(self, module_name, "", New_TinyObj);
|
||||
}
|
||||
PikaObj* module_obj = obj_getObj(self, module_name);
|
||||
obj_setStr(module_obj, "name", module_name);
|
||||
obj_setPtr(module_obj, "bytecode", bytecode);
|
||||
}
|
||||
|
||||
/* add bytecode to lib, and copy the bytecode to the buff in the lib */
|
||||
int LibObj_staticLink(LibObj* self,
|
||||
char* module_name,
|
||||
uint8_t* bytecode,
|
||||
size_t size) {
|
||||
if (!obj_isArgExist(self, module_name)) {
|
||||
obj_newObj(self, module_name, "", New_TinyObj);
|
||||
}
|
||||
PikaObj* module_obj = obj_getObj(self, module_name);
|
||||
/* copy bytecode to buff */
|
||||
obj_setBytes(module_obj, "buff", bytecode, size);
|
||||
/* link to buff */
|
||||
LibObj_dynamicLink(self, module_name, obj_getBytes(module_obj, "buff"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LibObj_staticLinkFile(LibObj* self, char* input_file_name) {
|
||||
Args buffs = {0};
|
||||
/* read file */
|
||||
Arg* input_file_arg = arg_loadFile(NULL, input_file_name);
|
||||
char* module_name = strsGetLastToken(&buffs, input_file_name, '/');
|
||||
|
||||
/* cut off '.py.o' */
|
||||
module_name[strlen(module_name) - (sizeof(".py.o") - 1)] = 0;
|
||||
|
||||
/* push bytecode */
|
||||
LibObj_staticLink(self, module_name, arg_getBytes(input_file_arg),
|
||||
arg_getBytesSize(input_file_arg));
|
||||
|
||||
/* deinit */
|
||||
strsDeinit(&buffs);
|
||||
arg_deinit(input_file_arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t __foreach_handler_listModules(Arg* argEach, Args* context) {
|
||||
if (arg_getType(argEach) == ARG_TYPE_OBJECT) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
__platform_printf("%s\r\n", obj_getStr(module_obj, "name"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LibObj_listModules(LibObj* self) {
|
||||
args_foreach(self->list, __foreach_handler_listModules, NULL);
|
||||
}
|
||||
|
||||
static int32_t __foreach_handler_writeBytecode(Arg* argEach, Args* context) {
|
||||
FILE* out_file = args_getPtr(context, "out_file");
|
||||
if (arg_getType(argEach) == ARG_TYPE_OBJECT) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
char* bytecode = obj_getPtr(module_obj, "bytecode");
|
||||
size_t bytecode_size = obj_getBytesSize(module_obj, "buff");
|
||||
size_t aline_size =
|
||||
aline_by(bytecode_size, sizeof(uint32_t)) - bytecode_size;
|
||||
char aline_buff[sizeof(uint32_t)] = {0};
|
||||
__platform_fwrite(bytecode, 1, bytecode_size, out_file);
|
||||
__platform_fwrite(aline_buff, 1, aline_size, out_file);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t __foreach_handler_writeIndex(Arg* argEach, Args* context) {
|
||||
FILE* out_file = args_getPtr(context, "out_file");
|
||||
if (arg_getType(argEach) == ARG_TYPE_OBJECT) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
uint32_t bytecode_size = obj_getBytesSize(module_obj, "buff");
|
||||
char buff[LIB_INFO_BLOCK_SIZE - sizeof(uint32_t)] = {0};
|
||||
bytecode_size = aline_by(bytecode_size, sizeof(uint32_t));
|
||||
char* module_name = obj_getStr(module_obj, "name");
|
||||
__platform_memcpy(buff, module_name, strGetSize(module_name));
|
||||
__platform_fwrite(buff, 1, LIB_INFO_BLOCK_SIZE - sizeof(bytecode_size),
|
||||
out_file);
|
||||
__platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size), out_file);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t __foreach_handler_getModuleNum(Arg* argEach, Args* context) {
|
||||
if (arg_getType(argEach) == ARG_TYPE_OBJECT) {
|
||||
args_setInt(context, "module_num",
|
||||
args_getInt(context, "module_num") + 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LibObj_saveLibraryFile(LibObj* self, char* output_file_name) {
|
||||
FILE* out_file = __platform_fopen(output_file_name, "wb+");
|
||||
|
||||
Args context = {0};
|
||||
args_setPtr(&context, "out_file", out_file);
|
||||
args_setInt(&context, "module_num", 0);
|
||||
|
||||
/* write meta information */
|
||||
char buff[LIB_INFO_BLOCK_SIZE] = {0};
|
||||
args_foreach(self->list, __foreach_handler_getModuleNum, &context);
|
||||
|
||||
/* meta info */
|
||||
char magic_code[] = {0x7f, 'p', 'y', 'a'};
|
||||
uint32_t version_num = 1;
|
||||
uint32_t module_num = args_getInt(&context, "module_num");
|
||||
|
||||
/* write meta info */
|
||||
const uint32_t magic_code_offset = sizeof(uint32_t) * 0;
|
||||
const uint32_t version_offset = sizeof(uint32_t) * 1;
|
||||
const uint32_t module_num_offset = sizeof(uint32_t) * 2;
|
||||
|
||||
__platform_memcpy(buff + magic_code_offset, &magic_code, sizeof(uint32_t));
|
||||
__platform_memcpy(buff + version_offset, &version_num, sizeof(uint32_t));
|
||||
/* write module_num to the file */
|
||||
__platform_memcpy(buff + module_num_offset, &module_num, sizeof(uint32_t));
|
||||
/* aline to 32 bytes */
|
||||
__platform_fwrite(buff, 1, LIB_INFO_BLOCK_SIZE, out_file);
|
||||
/* write module index to file */
|
||||
args_foreach(self->list, __foreach_handler_writeIndex, &context);
|
||||
/* write module bytecode to file */
|
||||
args_foreach(self->list, __foreach_handler_writeBytecode, &context);
|
||||
args_deinit_stack(&context);
|
||||
/* main process */
|
||||
/* deinit */
|
||||
__platform_fclose(out_file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes) {
|
||||
if (0 != ((intptr_t)library_bytes & 0x03)) {
|
||||
return PIKA_ERR_UNALIGNED_PTR;
|
||||
}
|
||||
|
||||
char* magic_code = (char*)library_bytes;
|
||||
|
||||
uint32_t* library_info = (uint32_t*)library_bytes;
|
||||
uint32_t version_num = library_info[1];
|
||||
uint32_t module_num = library_info[2];
|
||||
|
||||
/* check magic_code */
|
||||
if (!((magic_code[0] == 0x7f) && (magic_code[1] == 'p') &&
|
||||
(magic_code[2] == 'y') && (magic_code[3] == 'a'))) {
|
||||
__platform_printf("Error: invalid magic code.\r\n");
|
||||
return PIKA_ERR_ILLEGAL_MAGIC_CODE;
|
||||
}
|
||||
/* check version num */
|
||||
if (version_num != LIB_VERSION_NUMBER) {
|
||||
__platform_printf(
|
||||
"Error: invalid version number. Expected %, got %\r\n",
|
||||
LIB_VERSION_NUMBER, version_num);
|
||||
return PIKA_ERR_INVALID_VERSION_NUMBER;
|
||||
}
|
||||
uint8_t* bytecode_addr =
|
||||
library_bytes + LIB_INFO_BLOCK_SIZE * (module_num + 1);
|
||||
for (uint32_t i = 0; i < module_num; i++) {
|
||||
char* module_name =
|
||||
(char*)(library_bytes + LIB_INFO_BLOCK_SIZE * (i + 1));
|
||||
LibObj_dynamicLink(self, module_name, bytecode_addr);
|
||||
uint32_t module_size =
|
||||
*(uint32_t*)(module_name + LIB_INFO_BLOCK_SIZE - sizeof(uint32_t));
|
||||
bytecode_addr += module_size;
|
||||
}
|
||||
return PIKA_OK;
|
||||
}
|
||||
|
||||
int LibObj_loadLibraryFile(LibObj* self, char* lib_file_name) {
|
||||
Arg* file_arg = arg_loadFile(NULL, lib_file_name);
|
||||
if (NULL == file_arg) {
|
||||
__platform_printf("Error: Could not load library file '%s'\n",
|
||||
lib_file_name);
|
||||
return PIKA_ERR_IO_ERROR;
|
||||
}
|
||||
/* save file_arg as __lib_buf to libObj */
|
||||
obj_setArg_noCopy(self, "__lib_buf", file_arg);
|
||||
if (0 != LibObj_loadLibrary(self, arg_getBytes(file_arg))) {
|
||||
__platform_printf("Error: Could not load library from '%s'\n",
|
||||
lib_file_name);
|
||||
return PIKA_ERR_OPERATION_FAILED;
|
||||
}
|
||||
return PIKA_OK;
|
||||
}
|
||||
|
||||
size_t pika_fputs(char* str, FILE* fp) {
|
||||
size_t size = strGetSize(str);
|
||||
return __platform_fwrite(str, 1, size, fp);
|
||||
}
|
||||
|
||||
int Lib_loadLibraryFileToArray(char* origin_file_name, char* out_folder) {
|
||||
Args buffs = {0};
|
||||
Arg* file_arg = arg_loadFile(NULL, origin_file_name);
|
||||
int res = 0;
|
||||
if (NULL == file_arg) {
|
||||
__platform_printf("Error: Could not load file '%s'\n",
|
||||
origin_file_name);
|
||||
return 1;
|
||||
}
|
||||
char* output_file_name = NULL;
|
||||
output_file_name = strsGetLastToken(&buffs, origin_file_name, '/');
|
||||
output_file_name = strsAppend(&buffs, "__asset_", output_file_name);
|
||||
output_file_name = strsReplace(&buffs, output_file_name, ".", "_");
|
||||
output_file_name = strsAppend(&buffs, output_file_name, ".c");
|
||||
|
||||
char* output_file_path = strsAppend(&buffs, out_folder, "/");
|
||||
output_file_path = strsAppend(&buffs, output_file_path, output_file_name);
|
||||
|
||||
FILE* fp = __platform_fopen(output_file_path, "wb+");
|
||||
char* array_name = strsGetLastToken(&buffs, origin_file_name, '/');
|
||||
array_name = strsReplace(&buffs, array_name, ".", "_");
|
||||
__platform_printf(" loading %s[]...\n", array_name);
|
||||
pika_fputs("#include \"PikaPlatform.h\"\n",
|
||||
fp);
|
||||
pika_fputs("/* warning: auto generated file, please do not modify */\n",
|
||||
fp);
|
||||
pika_fputs("PIKA_BYTECODE_ALIGN const unsigned char ", fp);
|
||||
pika_fputs(array_name, fp);
|
||||
pika_fputs("[] = {", fp);
|
||||
char byte_buff[32] = {0};
|
||||
uint8_t* array = arg_getBytes(file_arg);
|
||||
for (size_t i = 0; i < arg_getBytesSize(file_arg); i++) {
|
||||
if (i % 12 == 0) {
|
||||
pika_fputs("\n ", fp);
|
||||
}
|
||||
__platform_sprintf(byte_buff, "0x%02x, ", array[i]);
|
||||
pika_fputs(byte_buff, fp);
|
||||
}
|
||||
|
||||
pika_fputs("\n};\n", fp);
|
||||
res = 0;
|
||||
goto exit;
|
||||
|
||||
exit:
|
||||
__platform_fclose(fp);
|
||||
strsDeinit(&buffs);
|
||||
arg_deinit(file_arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
static void __Maker_compileModuleWithInfo(PikaMaker* self, char* module_name) {
|
||||
Args buffs = {0};
|
||||
char* input_file_name = strsAppend(&buffs, module_name, ".py");
|
||||
char* input_file_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), input_file_name);
|
||||
__platform_printf(" compiling %s...\r\n", input_file_name);
|
||||
char* output_file_name = strsAppend(&buffs, module_name, ".py.o");
|
||||
char* output_file_path = NULL;
|
||||
output_file_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), "pikascript-api/");
|
||||
output_file_path = strsAppend(&buffs, output_file_path, output_file_name);
|
||||
pikaCompileFileWithOutputName(output_file_path, input_file_path);
|
||||
strsDeinit(&buffs);
|
||||
}
|
||||
|
||||
PikaMaker* New_PikaMaker(void) {
|
||||
PikaMaker* self = New_TinyObj(NULL);
|
||||
obj_setStr(self, "pwd", "");
|
||||
return self;
|
||||
}
|
||||
|
||||
void pikaMaker_setPWD(PikaMaker* self, char* pwd) {
|
||||
obj_setStr(self, "pwd", pwd);
|
||||
}
|
||||
|
||||
void pikaMaker_setState(PikaMaker* self, char* module_name, char* state) {
|
||||
obj_newMetaObj(self, module_name, New_TinyObj);
|
||||
PikaObj* module_obj = obj_getObj(self, module_name);
|
||||
obj_setStr(module_obj, "name", module_name);
|
||||
obj_setStr(module_obj, "state", state);
|
||||
}
|
||||
|
||||
void pikaMaker_compileModule(PikaMaker* self, char* module_name) {
|
||||
__Maker_compileModuleWithInfo(self, module_name);
|
||||
/* update compile info */
|
||||
pikaMaker_setState(self, module_name, "compiled");
|
||||
}
|
||||
|
||||
int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
|
||||
int res = 0;
|
||||
ByteCodeFrame bf = {0};
|
||||
Args buffs = {0};
|
||||
byteCodeFrame_init(&bf);
|
||||
ConstPool* const_pool = NULL;
|
||||
InstructArray* ins_array = NULL;
|
||||
char* module_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), "pikascript-api/");
|
||||
module_path = strsAppend(&buffs, module_path, module_name);
|
||||
char* file_path = strsAppend(&buffs, module_path, ".py.o");
|
||||
Arg* file_arg = arg_loadFile(NULL, file_path);
|
||||
uint8_t offset_befor = 0;
|
||||
if (NULL == file_arg) {
|
||||
res = 1;
|
||||
goto exit;
|
||||
}
|
||||
byteCodeFrame_loadByteCode(&bf, arg_getBytes(file_arg));
|
||||
const_pool = &bf.const_pool;
|
||||
ins_array = &bf.instruct_array;
|
||||
|
||||
offset_befor = ins_array->content_offset_now;
|
||||
ins_array->content_offset_now = 0;
|
||||
while (1) {
|
||||
InstructUnit* ins_unit = instructArray_getNow(ins_array);
|
||||
if (NULL == ins_unit) {
|
||||
goto exit;
|
||||
}
|
||||
if (instructUnit_getInstruct(ins_unit) == IMP) {
|
||||
char* imp_module_name =
|
||||
constPool_getByOffset(const_pool, ins_unit->const_pool_index);
|
||||
char* imp_module_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), imp_module_name);
|
||||
/* check if compiled the module */
|
||||
if (obj_isArgExist(self, imp_module_name)) {
|
||||
/* module info is exist, do nothing */
|
||||
} else {
|
||||
/* module info is not exist */
|
||||
/* set module to be compile */
|
||||
FILE* imp_file_py = __platform_fopen(
|
||||
strsAppend(&buffs, imp_module_path, ".py"), "rb");
|
||||
FILE* imp_file_pyi = __platform_fopen(
|
||||
strsAppend(&buffs, imp_module_path, ".pyi"), "rb");
|
||||
if (NULL != imp_file_py) {
|
||||
/* found *.py, push to nocompiled list */
|
||||
pikaMaker_setState(self, imp_module_name, "nocompiled");
|
||||
__platform_fclose(imp_file_py);
|
||||
} else if (NULL != imp_file_pyi) {
|
||||
/* found *.py, push to nocompiled list */
|
||||
pikaMaker_setState(self, imp_module_name, "cmodule");
|
||||
__platform_fclose(imp_file_pyi);
|
||||
} else {
|
||||
__platform_printf(
|
||||
" [warning]: file: '%s.pyi' or '%s.py' no found\n",
|
||||
imp_module_name, imp_module_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
instructArray_getNext(ins_array);
|
||||
}
|
||||
|
||||
exit:
|
||||
ins_array->content_offset_now = offset_befor;
|
||||
if (NULL != file_arg) {
|
||||
arg_deinit(file_arg);
|
||||
}
|
||||
strsDeinit(&buffs);
|
||||
byteCodeFrame_deinit(&bf);
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t __foreach_handler_printStates(Arg* argEach, Args* context) {
|
||||
if (arg_getType(argEach) == ARG_TYPE_OBJECT) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
__platform_printf("%s: %s\r\n", obj_getStr(module_obj, "name"),
|
||||
obj_getStr(module_obj, "state"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pikaMaker_printStates(PikaMaker* self) {
|
||||
args_foreach(self->list, __foreach_handler_printStates, NULL);
|
||||
}
|
||||
|
||||
int32_t __foreach_handler_getFirstNocompiled(Arg* argEach, Args* context) {
|
||||
if (arg_getType(argEach) == ARG_TYPE_OBJECT) {
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
char* state = obj_getStr(module_obj, "state");
|
||||
if (args_isArgExist(context, "res")) {
|
||||
/* already get method */
|
||||
return 0;
|
||||
}
|
||||
if (strEqu("nocompiled", state)) {
|
||||
/* push module */
|
||||
args_setStr(context, "res", obj_getStr(module_obj, "name"));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* pikaMaker_getFirstNocompiled(PikaMaker* self) {
|
||||
Args context = {0};
|
||||
args_foreach(self->list, __foreach_handler_getFirstNocompiled, &context);
|
||||
char* res = args_getStr(&context, "res");
|
||||
if (NULL == res) {
|
||||
/* remove res in maker */
|
||||
obj_removeArg(self, "res");
|
||||
} else {
|
||||
obj_setStr(self, "res", res);
|
||||
}
|
||||
args_deinit_stack(&context);
|
||||
return obj_getStr(self, "res");
|
||||
}
|
||||
|
||||
void pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name) {
|
||||
pikaMaker_compileModule(self, module_name);
|
||||
pikaMaker_getDependencies(self, module_name);
|
||||
while (1) {
|
||||
char* uncompiled = pikaMaker_getFirstNocompiled(self);
|
||||
/* compiled all modules */
|
||||
if (NULL == uncompiled) {
|
||||
break;
|
||||
}
|
||||
pikaMaker_compileModule(self, uncompiled);
|
||||
pikaMaker_getDependencies(self, uncompiled);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t __foreach_handler_linkCompiledModules(Arg* argEach, Args* context) {
|
||||
Args buffs = {0};
|
||||
if (arg_getType(argEach) == ARG_TYPE_OBJECT) {
|
||||
LibObj* lib = args_getPtr(context, "__lib");
|
||||
PikaMaker* maker = args_getPtr(context, "__maker");
|
||||
PikaObj* module_obj = arg_getPtr(argEach);
|
||||
char* module_name = obj_getStr(module_obj, "name");
|
||||
char* state = obj_getStr(module_obj, "state");
|
||||
if (strEqu(state, "compiled")) {
|
||||
char* pwd = obj_getStr(maker, "pwd");
|
||||
char* folder_path = strsAppend(&buffs, pwd, "pikascript-api/");
|
||||
char* module_file_name = strsAppend(&buffs, module_name, ".py.o");
|
||||
char* module_file_path =
|
||||
strsAppend(&buffs, folder_path, module_file_name);
|
||||
LibObj_staticLinkFile(lib, module_file_path);
|
||||
}
|
||||
}
|
||||
strsDeinit(&buffs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name) {
|
||||
Args context = {0};
|
||||
LibObj* lib = New_LibObj(NULL);
|
||||
Args buffs = {0};
|
||||
__platform_printf(" linking %s...\n", lib_name);
|
||||
args_setPtr(&context, "__lib", lib);
|
||||
args_setPtr(&context, "__maker", self);
|
||||
args_foreach(self->list, __foreach_handler_linkCompiledModules, &context);
|
||||
args_deinit_stack(&context);
|
||||
char* pwd = obj_getStr(self, "pwd");
|
||||
char* folder_path = strsAppend(&buffs, pwd, "pikascript-api/");
|
||||
char* lib_file_path = strsAppend(&buffs, folder_path, lib_name);
|
||||
LibObj_saveLibraryFile(lib, lib_file_path);
|
||||
Lib_loadLibraryFileToArray(lib_file_path, folder_path);
|
||||
LibObj_deinit(lib);
|
||||
strsDeinit(&buffs);
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
#ifndef __PIKA_COMPILER__H
|
||||
#define __PIKA_COMPILER__H
|
||||
#include "PikaObj.h"
|
||||
#include "stdint.h"
|
||||
|
||||
int pikaCompileFile(char* input_file_name);
|
||||
int pikaCompileFileWithOutputName(char* output_file_name,
|
||||
char* input_file_name);
|
||||
int pikaCompile(char* output_file_name, char* py_lines);
|
||||
|
||||
LibObj* New_LibObj(Args* args);
|
||||
void LibObj_deinit(LibObj* self);
|
||||
void LibObj_dynamicLink(LibObj* self, char* module_name, uint8_t* bytecode);
|
||||
int LibObj_staticLink(LibObj* self,
|
||||
char* module_name,
|
||||
uint8_t* bytecode,
|
||||
size_t size);
|
||||
int LibObj_staticLinkFile(LibObj* self, char* input_file_name);
|
||||
void LibObj_listModules(LibObj* self);
|
||||
int LibObj_saveLibraryFile(LibObj* self, char* output_file_name);
|
||||
int LibObj_loadLibraryFile(LibObj* self, char* input_file_name);
|
||||
int Lib_loadLibraryFileToArray(char* origin_file_name, char* pikascript_root);
|
||||
PikaMaker* New_PikaMaker(void);
|
||||
void pikaMaker_setPWD(PikaMaker* self, char* pwd);
|
||||
void pikaMaker_compileModule(PikaMaker* self, char* module_name);
|
||||
int pikaMaker_getDependencies(PikaMaker* self, char* module_name);
|
||||
void pikaMaker_printStates(PikaMaker* self);
|
||||
char* pikaMaker_getFirstNocompiled(PikaMaker* self);
|
||||
void pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name);
|
||||
void pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
|
||||
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes);
|
||||
|
||||
#define LIB_VERSION_NUMBER 1
|
||||
#define LIB_INFO_BLOCK_SIZE 32
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,253 +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
|
||||
|
||||
#include "dataArgs.h"
|
||||
#include "dataLink.h"
|
||||
#include "dataMemory.h"
|
||||
|
||||
typedef struct InstructUnit InstructUnit;
|
||||
struct InstructUnit {
|
||||
uint8_t deepth;
|
||||
uint8_t isNewLine_instruct;
|
||||
uint16_t const_pool_index;
|
||||
};
|
||||
|
||||
typedef struct ConstPool ConstPool;
|
||||
struct ConstPool {
|
||||
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 InstructArray;
|
||||
struct InstructArray {
|
||||
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 ByteCodeFrame;
|
||||
struct ByteCodeFrame {
|
||||
ConstPool const_pool;
|
||||
InstructArray instruct_array;
|
||||
};
|
||||
|
||||
typedef struct PikaObj PikaObj;
|
||||
struct PikaObj {
|
||||
Args* list;
|
||||
};
|
||||
|
||||
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 MethodInfo;
|
||||
struct MethodInfo {
|
||||
char* name;
|
||||
char* dec;
|
||||
char* ptr;
|
||||
char* pars;
|
||||
ArgType type;
|
||||
ByteCodeFrame* bytecode_frame;
|
||||
};
|
||||
|
||||
typedef PikaObj LibObj;
|
||||
typedef PikaObj PikaMaker;
|
||||
|
||||
/* 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_setRef(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_loadBytes(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);
|
||||
PikaObj* obj_getObj(PikaObj* self, char* objPath);
|
||||
PikaObj* obj_getHostObj(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_newObjInPackage(NewFun newObjFun);
|
||||
|
||||
void obj_refcntInc(PikaObj* self);
|
||||
void obj_refcntDec(PikaObj* self);
|
||||
int obj_refcntNow(PikaObj* self);
|
||||
PikaObj* NewObjDirect(NewFun newObjFun);
|
||||
Arg* arg_setRef(Arg* self, char* name, PikaObj* obj);
|
||||
Arg* arg_setWeakRef(Arg* self, char* name, PikaObj* obj);
|
||||
|
||||
PikaObj* obj_importModuleWithByteCodeFrame(PikaObj* self,
|
||||
char* name,
|
||||
ByteCodeFrame* bytecode_frame);
|
||||
PikaObj* obj_importModuleWithByteCode(PikaObj* self,
|
||||
char* name,
|
||||
uint8_t* byteCode);
|
||||
|
||||
int32_t obj_newObj(PikaObj* self,
|
||||
char* objName,
|
||||
char* className,
|
||||
NewFun newFunPtr);
|
||||
|
||||
Arg* arg_newMetaObj(NewFun objPtr);
|
||||
PikaObj* obj_linkLibObj(PikaObj* self, LibObj* library);
|
||||
PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes);
|
||||
int obj_importModule(PikaObj* self, char* module_name);
|
||||
int32_t obj_newMetaObj(PikaObj* self, char* objName, NewFun newFunPtr);
|
||||
int32_t obj_newDirectObj(PikaObj* self, char* objName, NewFun newFunPtr);
|
||||
int obj_runModule(PikaObj* self, char* module_name);
|
||||
char* obj_toStr(PikaObj* self);
|
||||
void obj_runCharInit(PikaObj* self);
|
||||
enum shell_state obj_runChar(PikaObj* self, char inputChar);
|
||||
|
||||
#define PIKA_PYTHON_BEGIN
|
||||
#define PIKA_PYTHON(x)
|
||||
#define PIKA_PYTHON_END
|
||||
|
||||
#endif
|
@ -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
@ -1,109 +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_import,
|
||||
STMT_list,
|
||||
STMT_none,
|
||||
};
|
||||
|
||||
typedef struct Asmer Asmer;
|
||||
struct Asmer {
|
||||
char* asm_code;
|
||||
uint8_t block_deepth_now;
|
||||
uint8_t is_new_line;
|
||||
char* line_pointer;
|
||||
};
|
||||
|
||||
typedef struct LexToken LexToken;
|
||||
struct LexToken {
|
||||
char* token;
|
||||
enum TokenType type;
|
||||
char* pyload;
|
||||
};
|
||||
|
||||
typedef struct ParserState ParsetState;
|
||||
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)
|
||||
|
||||
uint16_t Tokens_getSize(char* tokens);
|
||||
|
||||
#endif
|
@ -1,156 +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_free(void* ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
PIKA_WEAK void* __user_malloc(size_t size) {
|
||||
return __platform_malloc(size);
|
||||
}
|
||||
|
||||
PIKA_WEAK void __user_free(void* ptr, size_t size) {
|
||||
__platform_free(ptr);
|
||||
}
|
||||
|
||||
PIKA_WEAK void __platform_error_handle() {
|
||||
return;
|
||||
}
|
||||
|
||||
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) {
|
||||
#if defined(__linux)||defined(_WIN32)
|
||||
return getchar();
|
||||
#else
|
||||
__platform_printf("[error]: __platform_getchar need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK FILE* __platform_fopen(const char* filename, const char* modes) {
|
||||
#if defined(__linux)||defined(_WIN32)
|
||||
return fopen(filename, modes);
|
||||
#else
|
||||
__platform_printf("[error]: __platform_fopen need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK int __platform_fclose(FILE* stream) {
|
||||
#if defined(__linux)||defined(_WIN32)
|
||||
return fclose(stream);
|
||||
#else
|
||||
__platform_printf("[error]: __platform_fclose need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK size_t __platform_fwrite(const void* ptr,
|
||||
size_t size,
|
||||
size_t n,
|
||||
FILE* stream) {
|
||||
#if defined(__linux)||defined(_WIN32)
|
||||
return fwrite(ptr, size, n, stream);
|
||||
#else
|
||||
__platform_printf("[error]: __platform_fwrite need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PIKA_WEAK size_t __platform_fread(void* ptr,
|
||||
size_t size,
|
||||
size_t n,
|
||||
FILE* stream) {
|
||||
#if defined(__linux)||defined(_WIN32)
|
||||
return fread(ptr, size, n, stream);
|
||||
#else
|
||||
__platform_printf("[error]: __platform_fread need implementation!\r\n");
|
||||
while (1) {
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,136 +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(__ARMCC_VERSION) && (__ARMCC_VERSION >= 5000000) /* ARM Compiler */
|
||||
#define PIKA_WEAK __attribute__((weak))
|
||||
#elif defined(__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
|
||||
#define PIKA_WEAK __weak
|
||||
#elif defined(__MINGW32__) /* MINGW32 Compiler */
|
||||
#define PIKA_WEAK
|
||||
#elif defined(__GNUC__) /* GNU GCC Compiler */
|
||||
#define PIKA_WEAK __attribute__((weak))
|
||||
#endif
|
||||
/* default PIKA_WEAK */
|
||||
#ifndef PIKA_WEAK
|
||||
#define PIKA_WEAK
|
||||
#endif
|
||||
|
||||
/* align for bytecode */
|
||||
#if defined(_WIN32)
|
||||
#define PIKA_BYTECODE_ALIGN
|
||||
#else
|
||||
#define PIKA_BYTECODE_ALIGN __attribute__((aligned(4)))
|
||||
#endif
|
||||
|
||||
/* OS */
|
||||
#ifdef __RTTHREAD__
|
||||
#include <rtthread.h>
|
||||
#define __platform_printf(...) rt_kprintf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
typedef enum {
|
||||
|
||||
PIKA_ERR_UNKNOWN_INSTRUCTION = -11,
|
||||
PIKA_ERR_OUT_OF_RANGE = -10,
|
||||
PIKA_ERR_IO_ERROR = -9,
|
||||
PIKA_ERR_INSUFFICIENT_RESOURCE = -8,
|
||||
PIKA_ERR_INVALID_PARAM = -7,
|
||||
PIKA_ERR_INVALID_PTR = -6,
|
||||
PIKA_ERR_UNALIGNED_PTR = -5,
|
||||
PIKA_ERR_INVALID_VERSION_NUMBER = -4,
|
||||
PIKA_ERR_ILLEGAL_MAGIC_CODE = -3,
|
||||
PIKA_ERR_OPERATION_FAILED = -2,
|
||||
PIKA_ERR_UNKNOWN = -1,
|
||||
PIKA_OK = 0,
|
||||
|
||||
} PikaErr;
|
||||
/* clang-format on*/
|
||||
|
||||
/*
|
||||
[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);
|
||||
|
||||
void* __user_malloc(size_t size);
|
||||
void __user_free(void* ptr, 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);
|
||||
size_t __platform_fread(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
@ -1,135 +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 "dataQueueObj.h"
|
||||
#include "dataStack.h"
|
||||
|
||||
enum Instruct {
|
||||
#define __INS_ENUM
|
||||
#include "__instruction_table.cfg"
|
||||
__INSTRCUTION_CNT,
|
||||
};
|
||||
|
||||
typedef struct VMState VMState;
|
||||
struct VMState {
|
||||
VMParameters* locals;
|
||||
VMParameters* globals;
|
||||
Stack stack;
|
||||
int32_t jmp;
|
||||
int32_t pc;
|
||||
ByteCodeFrame* bytecode_frame;
|
||||
uint8_t error_code;
|
||||
uint8_t line_error_code;
|
||||
};
|
||||
|
||||
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)
|
||||
|
||||
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_loadByteCode(ByteCodeFrame* self, uint8_t* bytes);
|
||||
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
|
||||
void byteCodeFrame_init(ByteCodeFrame* self);
|
||||
VMParameters* pikaVM_runByteCode(PikaObj* self, uint8_t* bytecode);
|
||||
InstructUnit* instructArray_getNow(InstructArray* self);
|
||||
InstructUnit* instructArray_getNext(InstructArray* self);
|
||||
|
||||
#endif
|
@ -1 +0,0 @@
|
||||
# PikaScript 运行时内核
|
@ -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;
|
||||
}
|
@ -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
|
@ -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
|
@ -1,55 +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)
|
||||
def_ins(LST)
|
||||
def_ins(IMP)
|
@ -1,36 +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__
|
||||
#if PIKA_PLOOC_ENABLE
|
||||
#include "../pikascript-lib/PLOOC/plooc_class.h"
|
||||
#else
|
||||
#define private_member(X) X
|
||||
#endif
|
||||
#endif
|
@ -1,387 +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 arg_totleSize(self);
|
||||
}
|
||||
|
||||
/**
|
||||
* time33 hash
|
||||
*/
|
||||
Hash hash_time33(char* str) {
|
||||
Hash hash = 5381;
|
||||
while (*str) {
|
||||
hash += (hash << 5) + (*str++);
|
||||
}
|
||||
return (hash & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
static Arg* arg_init_hash(Hash nameHash,
|
||||
ArgType type,
|
||||
uint8_t* content,
|
||||
uint32_t size,
|
||||
Arg* next) {
|
||||
Arg* self = (Arg*)pikaMalloc(sizeof(Arg) + size);
|
||||
self->next = next;
|
||||
self->size = size;
|
||||
self->name_hash = nameHash;
|
||||
self->type = type;
|
||||
__platform_memset(self->content, 0, aline_by(size, sizeof(uint32_t)));
|
||||
if (NULL != content) {
|
||||
__platform_memcpy(self->content, content, size);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static Arg* arg_init(char* name,
|
||||
ArgType type,
|
||||
uint8_t* content,
|
||||
uint16_t size,
|
||||
Arg* next) {
|
||||
Hash nameHash = hash_time33(name);
|
||||
return arg_init_hash(nameHash, type, content, size, next);
|
||||
}
|
||||
|
||||
uint16_t arg_totleSize(Arg* self) {
|
||||
return ((Arg*)self)->size + sizeof(Arg);
|
||||
}
|
||||
|
||||
void arg_freeContent(Arg* self) {
|
||||
if (NULL != self) {
|
||||
uint16_t totleSize = arg_totleSize(self);
|
||||
pikaFree(self, totleSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Arg* arg_setContent(Arg* self, uint8_t* content, uint16_t size) {
|
||||
if (NULL == self) {
|
||||
/* malloc */
|
||||
return arg_init("", ARG_TYPE_VOID, content, size, NULL);
|
||||
}
|
||||
|
||||
/* only copy */
|
||||
if (arg_getSize(self) == size) {
|
||||
__platform_memcpy(((Arg*)self)->content, content, size);
|
||||
return self;
|
||||
}
|
||||
|
||||
/* realloc */
|
||||
Hash nameHash = arg_getNameHash(self);
|
||||
ArgType type = arg_getType(self);
|
||||
Arg* next = arg_getNext(self);
|
||||
Arg* newContent = arg_init_hash(nameHash, type, content, size, next);
|
||||
arg_freeContent(self);
|
||||
return newContent;
|
||||
}
|
||||
|
||||
Arg* arg_setNameHash(Arg* self, Hash nameHash) {
|
||||
if (NULL == self) {
|
||||
return arg_init_hash(nameHash, ARG_TYPE_VOID, NULL, 0, NULL);
|
||||
}
|
||||
Arg* arg = (Arg*)self;
|
||||
arg->name_hash = nameHash;
|
||||
return self;
|
||||
}
|
||||
|
||||
Arg* arg_setName(Arg* self, char* name) {
|
||||
return arg_setNameHash(self, hash_time33(name));
|
||||
}
|
||||
|
||||
Arg* arg_setType(Arg* self, ArgType type) {
|
||||
if (NULL == self) {
|
||||
return arg_init("", type, NULL, 0, NULL);
|
||||
}
|
||||
self->type = type;
|
||||
return self;
|
||||
}
|
||||
|
||||
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);
|
||||
/* set content all to 0 */
|
||||
__platform_memset(dir, 0, size + sizeof(size_t));
|
||||
__platform_memcpy(dir, &size, sizeof(size_t));
|
||||
|
||||
/* set init value */
|
||||
if (NULL != src) {
|
||||
__platform_memcpy((void*)((uintptr_t)dir + sizeof(size_t)), src, size);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
Arg* arg_newContent(Arg* self, uint32_t size) {
|
||||
Arg* newContent = arg_init("", ARG_TYPE_VOID, NULL, size, NULL);
|
||||
arg_freeContent(self);
|
||||
return newContent;
|
||||
}
|
||||
|
||||
uint8_t* arg_getBytes(Arg* self) {
|
||||
return arg_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_STRUCT_HEAP);
|
||||
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_setInt(Arg* self, char* name, int64_t val) {
|
||||
return arg_init(name, ARG_TYPE_INT, (uint8_t*)&val, sizeof(val), NULL);
|
||||
}
|
||||
|
||||
Arg* arg_setNull(Arg* self) {
|
||||
return arg_init("", ARG_TYPE_NULL, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
Arg* arg_setFloat(Arg* self, char* name, float val) {
|
||||
return arg_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*)self->content;
|
||||
}
|
||||
|
||||
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer) {
|
||||
return arg_init(name, type, (uint8_t*)&pointer, sizeof(uintptr_t), NULL);
|
||||
}
|
||||
|
||||
Arg* arg_setStr(Arg* self, char* name, char* string) {
|
||||
return arg_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*)self->content;
|
||||
}
|
||||
|
||||
void* arg_getPtr(Arg* self) {
|
||||
if (NULL == arg_getContent(self)) {
|
||||
return NULL;
|
||||
}
|
||||
return *(void**)self->content;
|
||||
}
|
||||
char* arg_getStr(Arg* self) {
|
||||
return (char*)arg_getContent(self);
|
||||
}
|
||||
|
||||
Hash arg_getNameHash(Arg* self) {
|
||||
if (NULL == self) {
|
||||
return 999999;
|
||||
}
|
||||
return self->name_hash;
|
||||
}
|
||||
|
||||
ArgType arg_getType(Arg* self) {
|
||||
if (NULL == self) {
|
||||
return ARG_TYPE_NULL;
|
||||
}
|
||||
return self->type;
|
||||
}
|
||||
|
||||
uint16_t arg_getContentSize(Arg* self) {
|
||||
return arg_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* self, void* new_content, size_t new_size) {
|
||||
uint8_t* old_content = arg_getContent(self);
|
||||
size_t old_size = arg_getContentSize(self);
|
||||
/* create arg_out */
|
||||
Arg* arg_out = arg_setContent(NULL, NULL, old_size + new_size);
|
||||
arg_setType(arg_out, arg_getType(self));
|
||||
arg_setNameHash(arg_out, arg_getNameHash(self));
|
||||
/* 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(self);
|
||||
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_STRUCT_HEAP) {
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* load file as byte array */
|
||||
Arg* arg_loadFile(Arg* self, char* filename) {
|
||||
size_t file_size = 0;
|
||||
char* file_buff = __platform_malloc(PIKA_READ_FILE_BUFF_SIZE);
|
||||
Arg* res = New_arg(NULL);
|
||||
__platform_memset(file_buff, 0, PIKA_READ_FILE_BUFF_SIZE);
|
||||
FILE* input_file = __platform_fopen(filename, "rb");
|
||||
if (NULL == input_file) {
|
||||
__platform_printf("Error: Couldn't open file '%s'\n", filename);
|
||||
res = NULL;
|
||||
goto exit;
|
||||
}
|
||||
file_size =
|
||||
__platform_fread(file_buff, 1, PIKA_READ_FILE_BUFF_SIZE, input_file);
|
||||
|
||||
if (file_size >= PIKA_READ_FILE_BUFF_SIZE) {
|
||||
__platform_printf("Error: Not enough buff for input file.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
/* add '\0' to the end of the string */
|
||||
res = arg_setBytes(res, "", (uint8_t*)file_buff, file_size + 1);
|
||||
|
||||
exit:
|
||||
__platform_free(file_buff);
|
||||
if (NULL != input_file) {
|
||||
__platform_fclose(input_file);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void arg_deinit(Arg* self) {
|
||||
/* deinit arg pointed heap */
|
||||
arg_deinitHeap(self);
|
||||
/* free the ref */
|
||||
arg_freeContent(self);
|
||||
}
|
||||
|
||||
Arg* arg_getNext(Arg* self) {
|
||||
return self->next;
|
||||
}
|
||||
|
||||
uint16_t arg_getSize(Arg* self) {
|
||||
return self->size;
|
||||
}
|
||||
|
||||
uint8_t* arg_getContent(Arg* self) {
|
||||
return self->content;
|
||||
}
|
||||
|
||||
void arg_setNext(Arg* self, Arg* next) {
|
||||
self->next = next;
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
||||
#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_NULL,
|
||||
ARG_TYPE_VOID,
|
||||
ARG_TYPE_INT,
|
||||
ARG_TYPE_FLOAT,
|
||||
ARG_TYPE_STRING,
|
||||
ARG_TYPE_BYTES,
|
||||
ARG_TYPE_POINTER,
|
||||
ARG_TYPE_OBJECT,
|
||||
ARG_TYPE_OBJECT_META,
|
||||
ARG_TYPE_OBJECT_NEW,
|
||||
ARG_TYPE_METHOD_NATIVE,
|
||||
ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR,
|
||||
ARG_TYPE_METHOD_CONSTRUCTOR,
|
||||
ARG_TYPE_METHOD_OBJECT,
|
||||
ARG_TYPE_METHOD_STATIC,
|
||||
ARG_TYPE_STRUCT,
|
||||
ARG_TYPE_STRUCT_HEAP,
|
||||
} 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[];
|
||||
};
|
||||
|
||||
Arg* arg_getNext(Arg* self);
|
||||
uint16_t arg_getSize(Arg* self);
|
||||
uint8_t* arg_getContent(Arg* self);
|
||||
uint16_t arg_totleSize(Arg* self);
|
||||
void arg_setNext(Arg* self, Arg* next);
|
||||
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, uint16_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);
|
||||
|
||||
uint8_t* arg_getContent(Arg* self);
|
||||
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);
|
||||
Arg* arg_loadFile(Arg* self, char* filename);
|
||||
|
||||
#endif
|
@ -1,516 +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_setRef(Args* self, char* name, void* argPointer) {
|
||||
int32_t errCode = 0;
|
||||
Arg* argNew = New_arg(NULL);
|
||||
argNew = arg_setRef(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 (arg_getNameHash((Arg*)nodeNow) == nameHash) {
|
||||
nodeToUpdate = nodeNow;
|
||||
break;
|
||||
}
|
||||
if (arg_getNext((Arg*)nodeNow) == NULL) {
|
||||
// error, node no found
|
||||
goto exit;
|
||||
}
|
||||
priorNode = nodeNow;
|
||||
nodeNow = (LinkNode*)arg_getNext((Arg*)nodeNow);
|
||||
}
|
||||
|
||||
arg_deinitHeap((Arg*)nodeToUpdate);
|
||||
|
||||
nodeToUpdate = (LinkNode*)arg_setContent(
|
||||
(Arg*)nodeToUpdate, arg_getContent(argNew), arg_getContentSize(argNew));
|
||||
|
||||
nodeToUpdate =
|
||||
(LinkNode*)arg_setType((Arg*)nodeToUpdate, arg_getType(argNew));
|
||||
// update privior link, because arg_getContent would free origin pointer
|
||||
if (NULL == priorNode) {
|
||||
self->firstNode = nodeToUpdate;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
arg_setNext((Arg*)priorNode, (Arg*)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* node = self->firstNode;
|
||||
int_fast8_t n = 0;
|
||||
while (NULL != node) {
|
||||
Arg* arg = (Arg*)node;
|
||||
Hash thisNameHash = arg_getNameHash(arg);
|
||||
if (thisNameHash == nameHash) {
|
||||
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 */
|
||||
node = (LinkNode*)arg_getNext((Arg*)arg);
|
||||
|
||||
/*! move the node to the cache */
|
||||
arg_setNext(arg, (Arg*)(self->firstNode));
|
||||
self->firstNode = (LinkNode*)arg;
|
||||
}
|
||||
return (LinkNode*)arg;
|
||||
}
|
||||
node = (LinkNode*)arg_getNext((Arg*)node);
|
||||
}
|
||||
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 (Arg*)node;
|
||||
}
|
||||
|
||||
Arg* args_getArg(Args* self, char* name) {
|
||||
LinkNode* node = args_getNode(self, name);
|
||||
if (NULL == node) {
|
||||
return NULL;
|
||||
}
|
||||
return (Arg*)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 = (LinkNode*)arg_getNext((Arg*)nodeNow);
|
||||
}
|
||||
return (Arg*)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* context),
|
||||
Args* context) {
|
||||
if (NULL == self->firstNode) {
|
||||
return 0;
|
||||
}
|
||||
LinkNode* nodeNow = self->firstNode;
|
||||
while (1) {
|
||||
Arg* argNow = (Arg*)nodeNow;
|
||||
if (NULL == argNow) {
|
||||
continue;
|
||||
}
|
||||
LinkNode* nextNode = (LinkNode*)arg_getNext((Arg*)nodeNow);
|
||||
eachHandle(argNow, context);
|
||||
|
||||
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;
|
||||
}
|
@ -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_setRef(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
|
@ -1,127 +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 = (LinkNode*)arg_getNext((Arg*)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
|
||||
arg_setNext(content, (Arg*)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 = (LinkNode*)arg_getNext((Arg*)nodeNow);
|
||||
}
|
||||
|
||||
nextNode = (LinkNode*)arg_getNext((Arg*)nodeToDelete);
|
||||
if (nodeToDelete == self->firstNode) {
|
||||
self->firstNode = (LinkNode*)arg_getNext((Arg*)nodeToDelete);
|
||||
}
|
||||
if (NULL == priorNode) {
|
||||
self->firstNode = nextNode;
|
||||
goto exit;
|
||||
}
|
||||
arg_setNext((Arg*)priorNode, (Arg*)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 = (LinkNode*)arg_getNext((Arg*)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;
|
||||
}
|
@ -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 Link Link;
|
||||
struct 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
|
@ -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((Arg*)self);
|
||||
}
|
||||
|
||||
void linkNode_init(LinkNode* self, void* args) {
|
||||
/* attribute */
|
||||
}
|
||||
|
||||
LinkNode* New_linkNode(void* args) {
|
||||
return NULL;
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
||||
#ifndef _linkNode__H
|
||||
#define _linkNode__H
|
||||
|
||||
#include "dataMemory.h"
|
||||
|
||||
typedef struct LinkNode LinkNode;
|
||||
struct LinkNode {
|
||||
void* __rsvd;
|
||||
};
|
||||
|
||||
void linkNode_deinit(LinkNode* self);
|
||||
void linkNode_init(LinkNode* self, void* args);
|
||||
|
||||
LinkNode* New_linkNode(void* args);
|
||||
#endif
|
@ -1,297 +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 __DATA_MEMORY_CLASS_IMPLEMENT__
|
||||
#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 = __user_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();
|
||||
__user_free(mem, size);
|
||||
__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);
|
||||
}
|
@ -1,82 +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"
|
||||
|
||||
/*! \NOTE: Make sure #include "plooc_class.h" is close to the class definition
|
||||
*/
|
||||
#if defined(__DATA_MEMORY_CLASS_IMPLEMENT__)
|
||||
#define __PLOOC_CLASS_IMPLEMENT__
|
||||
#endif
|
||||
#include "__pika_ooc.h"
|
||||
|
||||
typedef struct {
|
||||
uint32_t heapUsed;
|
||||
uint32_t heapUsedMax;
|
||||
} PikaMemInfo;
|
||||
|
||||
typedef uint8_t* BitMap;
|
||||
|
||||
/* clang-format off */
|
||||
typedef struct Pool Pool;
|
||||
struct Pool{
|
||||
private_member(
|
||||
BitMap bitmap;
|
||||
uint8_t* mem;
|
||||
uint8_t aline;
|
||||
uint32_t size;
|
||||
uint32_t first_free_block;
|
||||
uint32_t purl_free_block_start;
|
||||
)
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
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);
|
||||
|
||||
#undef __DATA_MEMORY_CLASS_IMPLEMENT__
|
||||
#endif
|
@ -1,123 +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_noRmoveArg(Queue* queue) {
|
||||
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));
|
||||
/* not deinit arg to keep str buff */
|
||||
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_noRmoveArg(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_noRmoveArg(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_noRmoveArg(queue));
|
||||
}
|
@ -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
|
@ -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_getObj(self, currentStr);
|
||||
}
|
||||
|
||||
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_getObj(self, bottomStr);
|
||||
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);
|
||||
}
|
@ -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
|
@ -1,133 +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);
|
||||
stack->stack_totle_size = PIKA_STACK_BUFF_SIZE;
|
||||
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, Arg* content, size_t size) {
|
||||
size_t stack_size_after_push =
|
||||
size + (stack->sp - arg_getContent(stack->stack_pyload));
|
||||
if (stack_size_after_push > stack->stack_totle_size) {
|
||||
__platform_printf(
|
||||
"OverflowError: pika VM stack overflow, please use bigger "
|
||||
"PIKA_STACK_BUFF_SIZE\r\n");
|
||||
__platform_printf("Info: stack size request: %d\r\n",
|
||||
stack_size_after_push);
|
||||
__platform_printf("Info: stack size now: %d\r\n",
|
||||
stack->stack_totle_size);
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
__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;
|
||||
}
|
@ -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 __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;
|
||||
size_t stack_totle_size;
|
||||
} 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
|
@ -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;
|
||||
}
|
||||
|
||||
size_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;
|
||||
}
|
@ -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 */
|
||||
size_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
|
@ -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);
|
||||
}
|
@ -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
|
@ -1,92 +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
|
||||
#define PIKA_READ_FILE_BUFF_SIZE 0x10000
|
||||
#define PIKA_INIT_STRING_ENABLE 0
|
||||
#define PIKA_SYNTEX_ITEM_SLICE_ENABLE 1
|
||||
#define PIKA_PLOOC_ENABLE 0
|
||||
|
||||
/* optimize options */
|
||||
#define PIKA_OPTIMIZE_SIZE 0
|
||||
#define PIKA_OPTIMIZE_SPEED 1
|
||||
|
||||
/* syntax support level */
|
||||
#define PIKA_SYNTAX_LEVEL_MINIMAL 0
|
||||
#define PIKA_SYNTAX_LEVEL_MAXIMAL 1
|
||||
|
||||
/* default optimize */
|
||||
#define PIKA_OPTIMIZE PIKA_OPTIMIZE_SIZE
|
||||
/* default syntax support level */
|
||||
#define PIKA_SYNTAX_LEVEL PIKA_SYNTAX_LEVEL_MAXIMAL
|
||||
|
||||
/* 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
|
||||
|
||||
/* config for syntax level */
|
||||
#if PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MINIMAL
|
||||
#undef PIKA_SYNTEX_ITEM_SLICE_ENABLE
|
||||
#define PIKA_SYNTEX_ITEM_SLICE_ENABLE 0
|
||||
#elif PIKA_SYNTAX_LEVEL == PIKA_SYNTAX_LEVEL_MAXIMAL
|
||||
#undef PIKA_INIT_STRING_ENABLE
|
||||
#define PIKA_INIT_STRING_ENABLE 1
|
||||
#undef PIKA_SYNTEX_ITEM_SLICE_ENABLE
|
||||
#define PIKA_SYNTEX_ITEM_SLICE_ENABLE 1
|
||||
#undef PIKA_BUILTIN_LIST_ENABLE
|
||||
#define PIKA_BUILTIN_LIST_ENABLE 1
|
||||
#undef PIKA_BUILTIN_DICT_ENABLE
|
||||
#define PIKA_BUILTIN_DICT_ENABLE 1
|
||||
#endif
|
||||
|
||||
/* configuration validation */
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user