diff --git a/port/linux/.vscode/settings.json b/port/linux/.vscode/settings.json index b1d41c3bf..fec2376a4 100644 --- a/port/linux/.vscode/settings.json +++ b/port/linux/.vscode/settings.json @@ -103,7 +103,8 @@ "pikastddevice_pwm.h": "c", "pikastddevice_spi.h": "c", "pikastddevice_uart.h": "c", - "datamemory.h": "c" + "datamemory.h": "c", + "pika_adapter_old_api.h": "c" }, "python.formatting.provider": "autopep8", } \ No newline at end of file diff --git a/port/linux/package/pikascript/pikascript-lib/pika_libc/pika_vsnprintf.c b/port/linux/package/pikascript/pikascript-lib/pika_libc/pika_vsnprintf.c index 0e02438a4..575ada1e2 100644 --- a/port/linux/package/pikascript/pikascript-lib/pika_libc/pika_vsnprintf.c +++ b/port/linux/package/pikascript/pikascript-lib/pika_libc/pika_vsnprintf.c @@ -51,8 +51,13 @@ #include #include #include +#include "PikaObj.h" #include "pika_adapter_rtt.h" +#if !PIKASCRIPT_VERSION_REQUIRE_MINIMUN(1, 12, 0) +#error "pika_vsnprintf.c requires at least PikaScript 1.12.0" +#endif + // 'ntoa' conversion buffer size, this must be big enough to hold one converted // numeric number including padded zeros (dynamically created on stack) #ifndef PRINTF_INTEGER_BUFFER_SIZE @@ -1256,13 +1261,10 @@ static int __vsnprintf(out_fct_type out, * * @return The number of characters actually written to buffer. */ -int pika_vsnprintf(char* buf, rt_size_t size, const char* fmt, va_list args) { - return __vsnprintf(out_buffer, buf, size, fmt, args); -} -int __platform_vsnprintf(char* buff, - size_t size, - const char* fmt, - va_list args) { - return pika_vsnprintf(buff, size, fmt, args); +int pika_platform_vsnprintf(char* buff, + size_t size, + const char* fmt, + va_list args) { + return __vsnprintf(out_buffer, buff, size, fmt, args); } diff --git a/port/linux/version_config.py b/port/linux/version_config.py index 53936634a..d053dae6e 100644 --- a/port/linux/version_config.py +++ b/port/linux/version_config.py @@ -1,3 +1,3 @@ MajorVersion = "1" -MinorVersion = "11" -MicroVersion = "9" +MinorVersion = "12" +MicroVersion = "0" diff --git a/src/PikaCompiler.c b/src/PikaCompiler.c index 7f8f5f7c3..19df647c5 100644 --- a/src/PikaCompiler.c +++ b/src/PikaCompiler.c @@ -67,7 +67,7 @@ static void __handler_constPool_output_file(ConstPool* self, char* content) { 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); + pika_platform_fwrite(content, 1, size, self->output_f); } /* instruct array output redirect */ @@ -79,23 +79,23 @@ static void __handler_instructArray_output_none(InstructArray* self, static void __handler_instructArray_output_file(InstructArray* self, InstructUnit* ins_unit) { /* to flash */ - __platform_fwrite(ins_unit, 1, instructUnit_getSize(), self->output_f); + pika_platform_fwrite(ins_unit, 1, instructUnit_getSize(), self->output_f); } /* need implament : - __platform_fopen() - __platform_fwrite() - __platform_fclose() + pika_platform_fopen() + pika_platform_fwrite() + pika_platform_fclose() */ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) { PIKA_RES res = PIKA_RES_OK; ByteCodeFrame bytecode_frame = {0}; - FILE* bytecode_f = __platform_fopen(output_file_name, "wb+"); + FILE* bytecode_f = pika_platform_fopen(output_file_name, "wb+"); if (NULL == bytecode_f) { - __platform_printf("Error: open file %s failed.\r\n", output_file_name); + pika_platform_printf("Error: open file %s failed.\r\n", output_file_name); res = PIKA_RES_ERR_IO_ERROR; goto exit; } @@ -109,7 +109,7 @@ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) { __handler_instructArray_output_none; res = Parser_linesToBytes(&bytecode_frame, py_lines); if (PIKA_RES_OK != res) { - __platform_printf(" Error: Syntax error.\r\n"); + pika_platform_printf(" Error: Syntax error.\r\n"); goto exit; } uint32_t const_pool_size = bytecode_frame.const_pool.size; @@ -121,11 +121,11 @@ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) { /* step 2, write instruct array to file */ /* write magic code */ - __platform_fwrite(magic_code_pyo, 1, sizeof(magic_code_pyo), bytecode_f); + pika_platform_fwrite(magic_code_pyo, 1, sizeof(magic_code_pyo), bytecode_f); /* write bytecode size */ - __platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size), bytecode_f); + pika_platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size), bytecode_f); /* write ins array size */ - __platform_fwrite(&instruct_array_size, 1, sizeof(instruct_array_size), + pika_platform_fwrite(&instruct_array_size, 1, sizeof(instruct_array_size), bytecode_f); byteCodeFrame_init(&bytecode_frame); bytecode_frame.const_pool.output_f = bytecode_f; @@ -137,10 +137,10 @@ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) { byteCodeFrame_deinit(&bytecode_frame); /* step 3, write const pool to file */ - __platform_fwrite(&const_pool_size, 1, sizeof(const_pool_size), bytecode_f); + pika_platform_fwrite(&const_pool_size, 1, sizeof(const_pool_size), bytecode_f); char void_ = 0; /* add \0 at the start */ - __platform_fwrite(&void_, 1, 1, bytecode_f); + pika_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; @@ -156,7 +156,7 @@ PIKA_RES pikaCompile(char* output_file_name, char* py_lines) { exit: byteCodeFrame_deinit(&bytecode_frame); if (NULL != bytecode_f) { - __platform_fclose(bytecode_f); + pika_platform_fclose(bytecode_f); } /* succeed */ return res; @@ -164,10 +164,10 @@ exit: /* need implament : - __platform_fopen() - __platform_fread() - __platform_fwrite() - __platform_fclose() + pika_platform_fopen() + pika_platform_fread() + pika_platform_fwrite() + pika_platform_fclose() */ PIKA_RES pikaCompileFileWithOutputName(char* output_file_name, char* input_file_name) { @@ -243,7 +243,7 @@ int LibObj_staticLinkFile(LibObj* self, char* input_file_name) { /* read file */ Arg* input_file_arg = arg_loadFile(NULL, input_file_name); if (NULL == input_file_arg) { - __platform_printf("error: can't open file %s\r\n", input_file_name); + pika_platform_printf("error: can't open file %s\r\n", input_file_name); return -1; } char* module_name = strsGetLastToken(&buffs, input_file_name, '/'); @@ -258,7 +258,7 @@ int LibObj_staticLinkFile(LibObj* self, char* input_file_name) { module_name[module_name_len - 5] == '.') { module_name[module_name_len - 5] = 0; } else { - // __platform_printf("linking raw %s:%s:%ld\r\n", input_file_name, + // pika_platform_printf("linking raw %s:%s:%ld\r\n", input_file_name, // module_name, arg_getBytecodeSize(input_file_arg)); /* replace . to | */ module_name = strsReplace(&buffs, module_name, ".", "|"); @@ -277,7 +277,7 @@ int LibObj_staticLinkFile(LibObj* self, char* input_file_name) { static int32_t __foreach_handler_listModules(Arg* argEach, Args* context) { if (argType_isObject(arg_getType(argEach))) { PikaObj* module_obj = arg_getPtr(argEach); - __platform_printf("%s\r\n", obj_getStr(module_obj, "name")); + pika_platform_printf("%s\r\n", obj_getStr(module_obj, "name")); } return 0; } @@ -295,8 +295,8 @@ static int32_t __foreach_handler_libWriteBytecode(Arg* argEach, Args* context) { 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); + pika_platform_fwrite(bytecode, 1, bytecode_size, out_file); + pika_platform_fwrite(aline_buff, 1, aline_size, out_file); } return 0; } @@ -311,11 +311,11 @@ static int32_t __foreach_handler_libWriteIndex(Arg* argEach, Args* context) { bytecode_size = aline_by(bytecode_size, sizeof(uint32_t)); char* module_name = obj_getStr(module_obj, "name"); module_name = strsReplace(&buffs, module_name, "|", "."); - // __platform_printf(" %s:%d\r\n", module_name, bytecode_size); - __platform_memcpy(buff, module_name, strGetSize(module_name)); - __platform_fwrite(buff, 1, LIB_INFO_BLOCK_SIZE - sizeof(bytecode_size), + // pika_platform_printf(" %s:%d\r\n", module_name, bytecode_size); + pika_platform_memcpy(buff, module_name, strGetSize(module_name)); + pika_platform_fwrite(buff, 1, LIB_INFO_BLOCK_SIZE - sizeof(bytecode_size), out_file); - __platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size), out_file); + pika_platform_fwrite(&bytecode_size, 1, sizeof(bytecode_size), out_file); } strsDeinit(&buffs); return 0; @@ -330,7 +330,7 @@ static int32_t __foreach_handler_getModuleNum(Arg* argEach, Args* context) { } int LibObj_saveLibraryFile(LibObj* self, char* output_file_name) { - FILE* out_file = __platform_fopen(output_file_name, "wb+"); + FILE* out_file = pika_platform_fopen(output_file_name, "wb+"); Args context = {0}; args_setPtr(&context, "out_file", out_file); @@ -350,12 +350,12 @@ int LibObj_saveLibraryFile(LibObj* self, char* output_file_name) { 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)); + pika_platform_memcpy(buff + magic_code_offset, &magic_code, sizeof(uint32_t)); + pika_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)); + pika_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); + pika_platform_fwrite(buff, 1, LIB_INFO_BLOCK_SIZE, out_file); /* write module index to file */ args_foreach(self->list, __foreach_handler_libWriteIndex, &context); /* write module bytecode to file */ @@ -363,7 +363,7 @@ int LibObj_saveLibraryFile(LibObj* self, char* output_file_name) { args_deinit_stack(&context); /* main process */ /* deinit */ - __platform_fclose(out_file); + pika_platform_fclose(out_file); return 0; } @@ -381,12 +381,12 @@ static int _getModuleNum(uint8_t* library_bytes) { /* 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"); + pika_platform_printf("Error: invalid magic code.\r\n"); return PIKA_RES_ERR_ILLEGAL_MAGIC_CODE; } /* check version num */ if (version_num != LIB_VERSION_NUMBER) { - __platform_printf( + pika_platform_printf( "Error: invalid version number. Expected %d, got %d\r\n", LIB_VERSION_NUMBER, version_num); return PIKA_RES_ERR_INVALID_VERSION_NUMBER; @@ -405,7 +405,7 @@ static PIKA_RES _loadModuleDataWithIndex(uint8_t* library_bytes, for (uint32_t i = 0; i < module_index + 1; i++) { char* module_name = (char*)(library_bytes + LIB_INFO_BLOCK_SIZE * (i + 1)); - // __platform_printf("loading module: %s\r\n", module_name); + // pika_platform_printf("loading module: %s\r\n", module_name); *name_p = module_name; *addr_p = bytecode_addr; uint32_t module_size = @@ -461,8 +461,8 @@ int32_t __foreach_handler_printModule(Arg* argEach, Args* context) { PikaObj* module_obj = arg_getPtr(argEach); char* module_name = obj_getStr(module_obj, "name"); if (NULL != module_name) { - __platform_printf(module_name); - __platform_printf("\r\n"); + pika_platform_printf(module_name); + pika_platform_printf("\r\n"); } } return 0; @@ -475,14 +475,14 @@ void LibObj_printModules(LibObj* self) { 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", + pika_platform_printf("Error: Could not load library file '%s'\n", lib_file_name); return PIKA_RES_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", + pika_platform_printf("Error: Could not load library from '%s'\n", lib_file_name); return PIKA_RES_ERR_OPERATION_FAILED; } @@ -491,7 +491,7 @@ int LibObj_loadLibraryFile(LibObj* self, char* lib_file_name) { size_t pika_fputs(char* str, FILE* fp) { size_t size = strGetSize(str); - return __platform_fwrite(str, 1, size, fp); + return pika_platform_fwrite(str, 1, size, fp); } int Lib_loadLibraryFileToArray(char* origin_file_name, char* out_folder) { @@ -499,7 +499,7 @@ int Lib_loadLibraryFileToArray(char* origin_file_name, char* out_folder) { 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", + pika_platform_printf("Error: Could not load file '%s'\n", origin_file_name); return 1; } @@ -512,10 +512,10 @@ int Lib_loadLibraryFileToArray(char* origin_file_name, char* out_folder) { 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+"); + FILE* fp = pika_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_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); @@ -528,7 +528,7 @@ int Lib_loadLibraryFileToArray(char* origin_file_name, char* out_folder) { if (i % 12 == 0) { pika_fputs("\n ", fp); } - __platform_sprintf(byte_buff, "0x%02x, ", array[i]); + pika_platform_sprintf(byte_buff, "0x%02x, ", array[i]); pika_fputs(byte_buff, fp); } @@ -537,7 +537,7 @@ int Lib_loadLibraryFileToArray(char* origin_file_name, char* out_folder) { goto exit; exit: - __platform_fclose(fp); + pika_platform_fclose(fp); strsDeinit(&buffs); arg_deinit(file_arg); return res; @@ -549,7 +549,7 @@ static PIKA_RES __Maker_compileModuleWithInfo(PikaMaker* self, 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); + pika_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 = @@ -637,14 +637,14 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) { } else { /* module info is not exist */ /* set module to be compile */ - FILE* imp_file_py = __platform_fopen( + FILE* imp_file_py = pika_platform_fopen( strsAppend(&buffs, imp_module_path, ".py"), "rb"); - FILE* imp_file_pyi = __platform_fopen( + FILE* imp_file_pyi = pika_platform_fopen( strsAppend(&buffs, imp_module_path, ".pyi"), "rb"); - FILE* imp_file_pyo = __platform_fopen( + FILE* imp_file_pyo = pika_platform_fopen( strsAppend(&buffs, imp_module_path, ".py.o"), "rb"); if (NULL != imp_file_pyo) { - __platform_printf(" loading %s.py.o...\r\n", + pika_platform_printf(" loading %s.py.o...\r\n", imp_module_path); /* found *.py.o, push to compiled list */ pikaMaker_setState(self, imp_module_name, "compiled"); @@ -652,23 +652,23 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) { &buffs, obj_getStr(self, "pwd"), "pikascript-api/"); imp_api_path = strsAppend(&buffs, imp_api_path, imp_module_name); - FILE* imp_file_pyo_api = __platform_fopen( + FILE* imp_file_pyo_api = pika_platform_fopen( strsAppend(&buffs, imp_api_path, ".py.o"), "wb+"); /* copy imp_file_pyo to imp_api_path */ - uint8_t* buff = (uint8_t*)__platform_malloc(128); + uint8_t* buff = (uint8_t*)pika_platform_malloc(128); size_t read_size = 0; while (1) { read_size = - __platform_fread(buff, 1, 128, imp_file_pyo); + pika_platform_fread(buff, 1, 128, imp_file_pyo); if (read_size > 0) { - __platform_fwrite(buff, 1, read_size, + pika_platform_fwrite(buff, 1, read_size, imp_file_pyo_api); } else { break; } } - __platform_free(buff); - __platform_fclose(imp_file_pyo_api); + pika_platform_free(buff); + pika_platform_fclose(imp_file_pyo_api); } else if (NULL != imp_file_py) { /* found *.py, push to nocompiled list */ pikaMaker_setState(self, imp_module_name, "nocompiled"); @@ -676,19 +676,19 @@ int pikaMaker_getDependencies(PikaMaker* self, char* module_name) { /* found *.py, push to nocompiled list */ pikaMaker_setState(self, imp_module_name, "cmodule"); } else { - __platform_printf( + pika_platform_printf( " [warning]: file: '%s.pyi', '%s.py' or '%s.py.o' " "no found\n", imp_module_name, imp_module_name, imp_module_name); } if (NULL != imp_file_pyo) { - __platform_fclose(imp_file_pyo); + pika_platform_fclose(imp_file_pyo); } if (NULL != imp_file_pyi) { - __platform_fclose(imp_file_pyi); + pika_platform_fclose(imp_file_pyi); } if (NULL != imp_file_py) { - __platform_fclose(imp_file_py); + pika_platform_fclose(imp_file_py); } } } @@ -708,7 +708,7 @@ exit: int32_t __foreach_handler_printStates(Arg* argEach, Args* context) { if (argType_isObject(arg_getType(argEach))) { PikaObj* module_obj = arg_getPtr(argEach); - __platform_printf("%s: %s\r\n", obj_getStr(module_obj, "name"), + pika_platform_printf("%s: %s\r\n", obj_getStr(module_obj, "name"), obj_getStr(module_obj, "state")); } return 0; @@ -799,12 +799,12 @@ PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path) { PIKA_RES compile_err = obj_getInt(self, "err"); if (PIKA_RES_OK != compile_err) { - __platform_printf(" Error: compile failed, link aborted.\r\n"); + pika_platform_printf(" Error: compile failed, link aborted.\r\n"); return compile_err; } Args context = {0}; Args buffs = {0}; - __platform_printf(" linking %s...\n", lib_path); + pika_platform_printf(" linking %s...\n", lib_path); LibObj* lib = obj_getPtr(self, "lib"); args_setPtr(&context, "@lib", lib); args_setPtr(&context, "__maker", self); diff --git a/src/PikaObj.c b/src/PikaObj.c index 5aec3b4c4..2b6f3265f 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -97,10 +97,10 @@ char* fast_itoa(char* buf, uint32_t val) { uint32_t const old = val; p -= 2; val /= 100; - __platform_memcpy(p, &str100p[old - (val * 100)], sizeof(uint16_t)); + pika_platform_memcpy(p, &str100p[old - (val * 100)], sizeof(uint16_t)); } p -= 2; - __platform_memcpy(p, &str100p[val], sizeof(uint16_t)); + pika_platform_memcpy(p, &str100p[val], sizeof(uint16_t)); return &p[val < 10]; } @@ -270,7 +270,7 @@ size_t obj_loadBytes(PikaObj* self, char* argPath, uint8_t* out_buff) { if (NULL == src) { return 0; } - __platform_memcpy(out_buff, src, size_mem); + pika_platform_memcpy(out_buff, src, size_mem); return size_mem; } @@ -508,10 +508,10 @@ PikaObj* newRootObj(char* name, NewFun newObjFun) { PikaObj* newObj = newNormalObj(newObjFun); if (!logo_printed) { logo_printed = 1; - __platform_printf("\r\n"); - __platform_printf("~~~/ POWERED BY \\~~~\r\n"); - __platform_printf("~ pikascript.com ~\r\n"); - __platform_printf("~~~~~~~~~~~~~~~~~~~~\r\n"); + pika_platform_printf("\r\n"); + pika_platform_printf("~~~/ POWERED BY \\~~~\r\n"); + pika_platform_printf("~ pikascript.com ~\r\n"); + pika_platform_printf("~~~~~~~~~~~~~~~~~~~~\r\n"); } __pikaMain = newObj; in_root_obj = PIKA_FALSE; @@ -682,7 +682,7 @@ char* methodArg_getTypeList(Arg* method_arg, char* buffs, size_t size) { char* method_dec = methodArg_getDec(method_arg); pika_assert(strGetSize(method_dec) <= size); if (strGetSize(method_dec) > size) { - __platform_printf( + pika_platform_printf( "OverFlowError: please use bigger PIKA_LINE_BUFF_SIZE\r\n"); while (1) { } @@ -941,13 +941,13 @@ static void _obj_runChar_beforeRun(PikaObj* self, ShellConfig* shell) { shell->line_position = 0; shell->line_curpos = 0; __clearBuff(shell); - __platform_printf("%s", shell->prefix); + pika_platform_printf("%s", shell->prefix); } static void _putc_cmd(char KEY_POS, int pos) { const char cmd[] = {0x1b, 0x5b, KEY_POS, 0x00}; for (int i = 0; i < pos; i++) { - __platform_printf((char*)cmd); + pika_platform_printf((char*)cmd); } } @@ -957,7 +957,7 @@ enum shellCTRL _do_obj_runChar(PikaObj* self, char* input_line = NULL; enum shellCTRL ctrl = SHELL_CTRL_CONTINUE; #if !(defined(__linux) || defined(_WIN32)) - __platform_printf("%c", inputChar); + pika_platform_printf("%c", inputChar); #endif if (inputChar == '\n' && shell->lastChar == '\r') { ctrl = SHELL_CTRL_CONTINUE; @@ -981,17 +981,17 @@ enum shellCTRL _do_obj_runChar(PikaObj* self, if (shell->line_curpos) { shell->line_curpos--; } else { - __platform_printf(" "); + pika_platform_printf(" "); } ctrl = SHELL_CTRL_CONTINUE; goto exit; } if (inputChar == KEY_RIGHT) { if (shell->line_curpos < shell->line_position) { - // __platform_printf("%c", shell->lineBuff[shell->line_curpos]); + // pika_platform_printf("%c", shell->lineBuff[shell->line_curpos]); shell->line_curpos++; } else { - __platform_printf("\b"); + pika_platform_printf("\b"); } ctrl = SHELL_CTRL_CONTINUE; goto exit; @@ -1008,21 +1008,21 @@ enum shellCTRL _do_obj_runChar(PikaObj* self, } if ((inputChar == '\b') || (inputChar == 127)) { if (shell->line_position == 0) { - __platform_printf(" "); + pika_platform_printf(" "); ctrl = SHELL_CTRL_CONTINUE; goto exit; } - __platform_printf(" \b"); + pika_platform_printf(" \b"); shell->line_position--; shell->line_curpos--; - __platform_memmove(shell->lineBuff + shell->line_curpos, + pika_platform_memmove(shell->lineBuff + shell->line_curpos, shell->lineBuff + shell->line_curpos + 1, shell->line_position - shell->line_curpos); shell->lineBuff[shell->line_position] = 0; if (shell->line_curpos != shell->line_position) { /* update screen */ - __platform_printf(shell->lineBuff + shell->line_curpos); - __platform_printf(" "); + pika_platform_printf(shell->lineBuff + shell->line_curpos); + pika_platform_printf(" "); _putc_cmd(KEY_LEFT, shell->line_position - shell->line_curpos + 1); } ctrl = SHELL_CTRL_CONTINUE; @@ -1030,7 +1030,7 @@ enum shellCTRL _do_obj_runChar(PikaObj* self, } if ((inputChar != '\r') && (inputChar != '\n')) { if (shell->line_position + 1 >= PIKA_LINE_BUFF_SIZE) { - __platform_printf( + pika_platform_printf( "\r\nError: line buff overflow, please use bigger " "'PIKA_LINE_BUFF_SIZE'\r\n"); ctrl = SHELL_CTRL_EXIT; @@ -1038,12 +1038,12 @@ enum shellCTRL _do_obj_runChar(PikaObj* self, goto exit; } if ('\0' != inputChar) { - __platform_memmove(shell->lineBuff + shell->line_curpos + 1, + pika_platform_memmove(shell->lineBuff + shell->line_curpos + 1, shell->lineBuff + shell->line_curpos, shell->line_position - shell->line_curpos); shell->lineBuff[shell->line_position + 1] = 0; if (shell->line_curpos != shell->line_position) { - __platform_printf(shell->lineBuff + shell->line_curpos + 1); + pika_platform_printf(shell->lineBuff + shell->line_curpos + 1); _putc_cmd(KEY_LEFT, shell->line_position - shell->line_curpos); } shell->lineBuff[shell->line_curpos] = inputChar; @@ -1055,7 +1055,7 @@ enum shellCTRL _do_obj_runChar(PikaObj* self, } if ((inputChar == '\r') || (inputChar == '\n')) { #if !(defined(__linux) || defined(_WIN32)) - __platform_printf("\r\n"); + pika_platform_printf("\r\n"); #endif /* still in block */ if (shell->blockBuffName != NULL && shell->inBlock) { @@ -1074,10 +1074,10 @@ enum shellCTRL _do_obj_runChar(PikaObj* self, input_line = obj_getStr(self, shell->blockBuffName); ctrl = shell->handler(self, input_line, shell); __clearBuff(shell); - __platform_printf(">>> "); + pika_platform_printf(">>> "); goto exit; } else { - __platform_printf("... "); + pika_platform_printf("... "); } __clearBuff(shell); ctrl = SHELL_CTRL_CONTINUE; @@ -1091,14 +1091,14 @@ enum shellCTRL _do_obj_runChar(PikaObj* self, strAppendWithSize(shell->lineBuff, &_n, 1); obj_setStr(self, shell->blockBuffName, shell->lineBuff); __clearBuff(shell); - __platform_printf("... "); + pika_platform_printf("... "); ctrl = SHELL_CTRL_CONTINUE; goto exit; } } shell->lineBuff[shell->line_position] = '\0'; ctrl = shell->handler(self, shell->lineBuff, shell); - __platform_printf("%s", shell->prefix); + pika_platform_printf("%s", shell->prefix); __clearBuff(shell); goto exit; } @@ -1165,42 +1165,42 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) { buff[buff_i++] = input[0]; } /* end */ - __platform_printf("\r\n=============== [Code] ===============\r\n"); + pika_platform_printf("\r\n=============== [Code] ===============\r\n"); size_t len = strGetSize(buff); for (size_t i = 0; i < len; i++) { if (buff[i] == '\r') { continue; } if (buff[i] == '\n') { - __platform_printf("\r\n"); + pika_platform_printf("\r\n"); continue; } - __platform_printf("%c", buff[i]); + pika_platform_printf("%c", buff[i]); } - __platform_printf("\r\n"); - __platform_printf("=============== [File] ===============\r\n"); - __platform_printf("[ Info] File buff used: %d/%d (%0.2f%%)\r\n", + pika_platform_printf("\r\n"); + pika_platform_printf("=============== [File] ===============\r\n"); + pika_platform_printf("[ Info] File buff used: %d/%d (%0.2f%%)\r\n", (int)len, (int)PIKA_READ_FILE_BUFF_SIZE, ((float)len / (float)PIKA_READ_FILE_BUFF_SIZE)); #if PIKA_SHELL_SAVE_FILE_ENABLE char* file_name = PIKA_SHELL_SAVE_FILE_NAME; - __platform_printf("[ Info] Saving file to '%s'...\r\n", + pika_platform_printf("[ Info] Saving file to '%s'...\r\n", file_name); - FILE* fp = __platform_fopen(file_name, "w+"); + FILE* fp = pika_platform_fopen(file_name, "w+"); if (NULL == fp) { - __platform_printf("[ Error] Open file '%s' error!\r\n", + pika_platform_printf("[ Error] Open file '%s' error!\r\n", file_name); - __platform_fclose(fp); + pika_platform_fclose(fp); } else { - __platform_fwrite(buff, 1, len, fp); - __platform_printf("[ Info] Writing %d bytes to '%s'...\r\n", + pika_platform_fwrite(buff, 1, len, fp); + pika_platform_printf("[ Info] Writing %d bytes to '%s'...\r\n", (int)(len), file_name); - __platform_fclose(fp); - __platform_printf("[ OK ] Writing to '%s' succeed!\r\n", + pika_platform_fclose(fp); + pika_platform_printf("[ OK ] Writing to '%s' succeed!\r\n", file_name); } #endif - __platform_printf("=============== [ Run] ===============\r\n"); + pika_platform_printf("=============== [ Run] ===============\r\n"); obj_run(self, (char*)buff); if (NULL != strstr(buff, "exit()")) { is_exit = PIKA_TRUE; @@ -1209,7 +1209,7 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) { if (is_exit) { return; } - __platform_printf("%s", cfg->prefix); + pika_platform_printf("%s", cfg->prefix); continue; } @@ -1228,9 +1228,9 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) { for (uint32_t i = 0; i < size; i++) { buff[i] = cfg->fn_getchar(); } - __platform_printf("\r\n=============== [Code] ===============\r\n"); - __platform_printf("[ Info] Bytecode size: %d\r\n", size); - __platform_printf("=============== [ RUN] ===============\r\n"); + pika_platform_printf("\r\n=============== [Code] ===============\r\n"); + pika_platform_printf("[ Info] Bytecode size: %d\r\n", size); + pika_platform_printf("=============== [ RUN] ===============\r\n"); pikaVM_runByteCodeInconstant(self, buff); pikaFree(buff, size); return; @@ -1280,7 +1280,7 @@ void pikaScriptShell_withGetchar(PikaObj* self, sh_getchar getchar_fn) { } void pikaScriptShell(PikaObj* self) { - pikaScriptShell_withGetchar(self, __platform_getchar); + pikaScriptShell_withGetchar(self, pika_platform_getchar); } void obj_setErrorCode(PikaObj* self, int32_t errCode) { @@ -1317,7 +1317,7 @@ void args_setSysOut(Args* args, char* str) { if (strEqu("", str)) { return; } - __platform_printf("%s\r\n", str); + pika_platform_printf("%s\r\n", str); } void method_returnBytes(Args* args, uint8_t* val) { @@ -1458,7 +1458,7 @@ PikaObj* obj_importModuleWithByteCodeFrame(PikaObj* self, return self; } -PikaObj* Obj_linkLibraryFile(PikaObj* self, char* input_file_name) { +PikaObj* obj_linkLibraryFile(PikaObj* self, char* input_file_name) { obj_newMetaObj(self, "@lib", New_LibObj); LibObj* lib = obj_getObj(self, "@lib"); LibObj_loadLibraryFile(lib, input_file_name); @@ -1475,7 +1475,7 @@ PikaObj* obj_linkLibrary(PikaObj* self, uint8_t* library_bytes) { void obj_printModules(PikaObj* self) { LibObj* lib = obj_getObj(self, "@lib"); - __platform_printf(arg_getStr((Arg*)_help_modules_cmodule)); + pika_platform_printf(arg_getStr((Arg*)_help_modules_cmodule)); LibObj_printModules(lib); } @@ -1599,7 +1599,7 @@ Arg* __eventListener_runEvent(PikaEventListener* lisener, Arg* eventData) { PikaObj* handler = pks_eventListener_getEventHandleObj(lisener, eventId); if (NULL == handler) { - __platform_printf( + pika_platform_printf( "Error: can not find event handler by id: [0x%02x]\r\n", eventId); return NULL; } @@ -1636,7 +1636,7 @@ void _do_pks_eventListener_send(PikaEventListener* self, Arg* eventData, PIKA_BOOL pickupWhenNoVM) { #if !PIKA_EVENT_ENABLE - __platform_printf("PIKA_EVENT_ENABLE is not enable"); + pika_platform_printf("PIKA_EVENT_ENABLE is not enable"); while (1) { }; #else @@ -1669,9 +1669,9 @@ Arg* pks_eventListener_sendSignalAwaitResult(PikaEventListener* self, int eventSignal) { /* * Await result from event. - * need implement `__platform_thread_delay()` to support thread switch */ + * need implement `pika_platform_thread_delay()` to support thread switch */ #if !PIKA_EVENT_ENABLE - __platform_printf("PIKA_EVENT_ENABLE is not enable"); + pika_platform_printf("PIKA_EVENT_ENABLE is not enable"); while (1) { }; #else @@ -1680,7 +1680,7 @@ Arg* pks_eventListener_sendSignalAwaitResult(PikaEventListener* self, pks_eventListener_sendSignal(self, eventId, eventSignal); while (1) { Arg* res = PikaVMSignal.cq.res[tail]; - __platform_thread_delay(); + pika_platform_thread_delay(); if (NULL != res) { return res; } @@ -1690,12 +1690,12 @@ Arg* pks_eventListener_sendSignalAwaitResult(PikaEventListener* self, /* print major version info */ void pks_printVersion(void) { - __platform_printf("pikascript-core==v%d.%d.%d (%s)\r\n", PIKA_VERSION_MAJOR, + pika_platform_printf("pikascript-core==v%d.%d.%d (%s)\r\n", PIKA_VERSION_MAJOR, PIKA_VERSION_MINOR, PIKA_VERSION_MICRO, PIKA_EDIT_TIME); } void pks_getVersion(char* buff) { - __platform_sprintf(buff, "%d.%d.%d", PIKA_VERSION_MAJOR, PIKA_VERSION_MINOR, + pika_platform_sprintf(buff, "%d.%d.%d", PIKA_VERSION_MAJOR, PIKA_VERSION_MINOR, PIKA_VERSION_MICRO); } diff --git a/src/PikaObj.h b/src/PikaObj.h index dba43350a..2a694a8ec 100644 --- a/src/PikaObj.h +++ b/src/PikaObj.h @@ -293,9 +293,9 @@ void _temp__do_pikaScriptShell(PikaObj* self, ShellConfig* cfg); /* need implament : - __platform_fopen() - __platform_fwrite() - __platform_fclose() + pika_platform_fopen() + pika_platform_fwrite() + pika_platform_fclose() */ Method obj_getNativeMethod(PikaObj* self, char* method_name); PIKA_RES obj_runNativeMethod(PikaObj* self, char* method_name, Args* args); @@ -367,7 +367,7 @@ PikaObj* pks_eventListener_getEventHandleObj(PikaEventListener* self, void pks_eventListener_init(PikaEventListener** p_self); void pks_eventListener_deinit(PikaEventListener** p_self); PikaObj* methodArg_getDefContext(Arg* method_arg); -PikaObj* Obj_linkLibraryFile(PikaObj* self, char* input_file_name); +PikaObj* obj_linkLibraryFile(PikaObj* self, char* input_file_name); NewFun obj_getClass(PikaObj* obj); void pks_printVersion(void); @@ -391,13 +391,13 @@ static inline uint8_t obj_refcntNow(PikaObj* self) { #define ABSTRACT_METHOD_NEED_OVERRIDE_ERROR(_) \ obj_setErrorCode(self, 1); \ - __platform_printf("Error: abstract method `%s()` need override.\r\n", \ + pika_platform_printf("Error: abstract method `%s()` need override.\r\n", \ __FUNCTION__) #define WEAK_FUNCTION_NEED_OVERRIDE_ERROR(_) \ - __platform_printf("Error: weak function `%s()` need override.\r\n", \ + pika_platform_printf("Error: weak function `%s()` need override.\r\n", \ __FUNCTION__); \ - __platform_panic_handle(); + pika_platform_panic_handle(); char* obj_cacheStr(PikaObj* self, char* str); PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp); diff --git a/src/PikaParser.c b/src/PikaParser.c index 3149e032c..b23042941 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -97,7 +97,7 @@ char* strsPopTokenWithSkip_byStr(Args* outBuffs, Cursor_deinit(&cs); char* keeped = arg_getStr(keeped_arg); char* poped = strsCopy(outBuffs, arg_getStr(poped_arg)); - __platform_memcpy(stmts, keeped, strGetSize(keeped) + 1); + pika_platform_memcpy(stmts, keeped, strGetSize(keeped) + 1); arg_deinit(poped_arg); arg_deinit(keeped_arg); return poped; @@ -413,7 +413,7 @@ Arg* Lexer_setSymbel(Arg* tokenStream_arg, goto exit; } symbol_buff = args_getBuff(&buffs, i - *symbol_start_index); - __platform_memcpy(symbol_buff, stmt + *symbol_start_index, + pika_platform_memcpy(symbol_buff, stmt + *symbol_start_index, i - *symbol_start_index); /* literal */ if ((symbol_buff[0] == '\'') || (symbol_buff[0] == '"')) { @@ -1877,7 +1877,7 @@ AST* AST_parseLine_withBlockStack_withBlockDeepth(char* line, /* set block deepth */ if (block_deepth_now == -1) { /* get block_deepth error */ - __platform_printf( + pika_platform_printf( "IndentationError: unexpected indent, only support 4 " "spaces\r\n"); obj_deinit(ast); @@ -2580,9 +2580,9 @@ exit: PIKA_RES Parser_linesToBytes(ByteCodeFrame* bf, char* py_lines) { #if PIKA_BYTECODE_ONLY_ENABLE - __platform_printf( + pika_platform_printf( "Error: In bytecode-only mode, can not parse python script.\r\n"); - __platform_printf( + pika_platform_printf( " Note: Please check PIKA_BYTECODE_ONLY_ENABLE config.\r\n"); return PIKA_RES_ERR_SYNTAX_ERROR; #else @@ -2653,7 +2653,7 @@ char* AST_genAsm_sub(AST* ast, AST* subAst, Args* outBuffs, char* pikaAsm) { char* astNodeVal = obj_getStr(subAst, rule.ast); if (NULL != astNodeVal) { /* e.g. "0 RUN print \n" */ - __platform_sprintf(buff, "%d %s ", deepth, rule.ins); + pika_platform_sprintf(buff, "%d %s ", deepth, rule.ins); Arg* abuff = arg_newStr(buff); if (rule.type == VAL_DYNAMIC) { abuff = arg_strAppend(abuff, astNodeVal); @@ -2694,7 +2694,7 @@ char* GenRule_toAsm(GenRule rule, /* parse stmt ast */ pikaAsm = AST_genAsm_sub(ast, ast, buffs, pikaAsm); /* e.g. "0 CTN \n" */ - __platform_sprintf(buff, "%d %s ", deepth, rule.ins); + pika_platform_sprintf(buff, "%d %s ", deepth, rule.ins); Arg* abuff = arg_newStr(buff); if (rule.type == VAL_DYNAMIC) { abuff = arg_strAppend(abuff, obj_getStr(ast, rule.ast)); @@ -3112,14 +3112,14 @@ char* Parser_linesToArray(char* lines) { /* do something */ byteCodeFrame_print(&bytecode_frame); - __platform_printf("\n\n/* clang-format off */\n"); - __platform_printf("PIKA_PYTHON(\n"); - __platform_printf("%s\n", lines); - __platform_printf(")\n"); - __platform_printf("/* clang-format on */\n"); + pika_platform_printf("\n\n/* clang-format off */\n"); + pika_platform_printf("PIKA_PYTHON(\n"); + pika_platform_printf("%s\n", lines); + pika_platform_printf(")\n"); + pika_platform_printf("/* clang-format on */\n"); byteCodeFrame_printAsArray(&bytecode_frame); /* deinit */ byteCodeFrame_deinit(&bytecode_frame); - __platform_printf("\n\n"); + pika_platform_printf("\n\n"); return NULL; } diff --git a/src/PikaPlatform.c b/src/PikaPlatform.c index 535eebb70..872f56141 100644 --- a/src/PikaPlatform.c +++ b/src/PikaPlatform.c @@ -29,125 +29,125 @@ #include #include -PIKA_WEAK void __platform_disable_irq_handle(void) { +PIKA_WEAK void pika_platform_disable_irq_handle(void) { /* disable irq to support thread */ } -PIKA_WEAK void __platform_enable_irq_handle(void) { +PIKA_WEAK void pika_platform_enable_irq_handle(void) { /* disable irq to support thread */ } -PIKA_WEAK void* __platform_malloc(size_t size) { +PIKA_WEAK void* pika_platform_malloc(size_t size) { return malloc(size); } -PIKA_WEAK void* __platform_realloc(void* ptr, size_t size) { +PIKA_WEAK void* pika_platform_realloc(void* ptr, size_t size) { return realloc(ptr, size); } -PIKA_WEAK void* __platform_calloc(size_t num, size_t size) { +PIKA_WEAK void* pika_platform_calloc(size_t num, size_t size) { return calloc(num, size); } -PIKA_WEAK void __platform_free(void* ptr) { +PIKA_WEAK void pika_platform_free(void* ptr) { free(ptr); } -PIKA_WEAK void* __user_malloc(size_t size) { - return __platform_malloc(size); +PIKA_WEAK void* pika_user_malloc(size_t size) { + return pika_platform_malloc(size); } -PIKA_WEAK void __user_free(void* ptr, size_t size) { - __platform_free(ptr); +PIKA_WEAK void pika_user_free(void* ptr, size_t size) { + pika_platform_free(ptr); } -PIKA_WEAK void __platform_error_handle() { +PIKA_WEAK void pika_platform_error_handle() { return; } -PIKA_WEAK void __platform_panic_handle() { +PIKA_WEAK void pika_platform_panic_handle() { while (1) { }; } -PIKA_WEAK uint8_t __is_locked_pikaMemory(void) { +PIKA_WEAK uint8_t pika_is_locked_pikaMemory(void) { return 0; } -PIKA_WEAK int64_t __platform_getTick(void) { +PIKA_WEAK int64_t pika_platform_getTick(void) { return -1; } -PIKA_WEAK int __platform_vsprintf(char* buff, char* fmt, va_list args) { +PIKA_WEAK int pika_platform_vsprintf(char* buff, char* fmt, va_list args) { /* vsnprintf */ - return __platform_vsnprintf(buff, PIKA_SPRINTF_BUFF_SIZE, fmt, args); + return pika_platform_vsnprintf(buff, PIKA_SPRINTF_BUFF_SIZE, fmt, args); } -PIKA_WEAK int __platform_snprintf(char* buff, +PIKA_WEAK int pika_platform_snprintf(char* buff, size_t size, const char* fmt, ...) { va_list args; va_start(args, fmt); - int ret = __platform_vsnprintf(buff, size, fmt, args); + int ret = pika_platform_vsnprintf(buff, size, fmt, args); va_end(args); return ret; } -PIKA_WEAK int __platform_putchar(char ch) { +PIKA_WEAK int pika_platform_putchar(char ch) { return putchar(ch); } -PIKA_WEAK int __platform_vprintf(char* fmt, va_list args) { +PIKA_WEAK int pika_platform_vprintf(char* fmt, va_list args) { /* vsprintf to vprintf */ char buff[PIKA_SPRINTF_BUFF_SIZE]; - __platform_vsprintf(buff, fmt, args); + pika_platform_vsprintf(buff, fmt, args); /* putchar */ for (int i = 0; i < strlen(buff); i++) { - __platform_putchar(buff[i]); + pika_platform_putchar(buff[i]); } return 0; } -#ifndef __platform_printf -PIKA_WEAK void __platform_printf(char* fmt, ...) { +#ifndef pika_platform_printf +PIKA_WEAK void pika_platform_printf(char* fmt, ...) { va_list args; va_start(args, fmt); - __platform_vprintf(fmt, args); + pika_platform_vprintf(fmt, args); va_end(args); } #endif -PIKA_WEAK char* __platform_strdup(const char* src) { - char* dst = (char*)__platform_malloc(strlen(src) + 1); +PIKA_WEAK char* pika_platform_strdup(const char* src) { + char* dst = (char*)pika_platform_malloc(strlen(src) + 1); if (dst) { strcpy(dst, src); } return dst; } -PIKA_WEAK size_t __platform_tick_from_millisecond(size_t ms) { +PIKA_WEAK size_t pika_platform_tick_from_millisecond(size_t ms) { return ms; } -PIKA_WEAK int __platform_vsnprintf(char* buff, +PIKA_WEAK int pika_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, ...) { +PIKA_WEAK int pika_platform_sprintf(char* buff, char* fmt, ...) { va_list args; va_start(args, fmt); - int res = __platform_vsnprintf(buff, PIKA_SPRINTF_BUFF_SIZE, fmt, args); + int res = pika_platform_vsnprintf(buff, PIKA_SPRINTF_BUFF_SIZE, fmt, args); va_end(args); if (res >= PIKA_SPRINTF_BUFF_SIZE) { - __platform_printf( + pika_platform_printf( "OverflowError: sprintf buff size overflow, please use bigger " "PIKA_SPRINTF_BUFF_SIZE\r\n"); - __platform_printf("Info: buff size request: %d\r\n", res); - __platform_printf("Info: buff size now: %d\r\n", + pika_platform_printf("Info: buff size request: %d\r\n", res); + pika_platform_printf("Info: buff size now: %d\r\n", PIKA_SPRINTF_BUFF_SIZE); while (1) ; @@ -155,129 +155,129 @@ PIKA_WEAK int __platform_sprintf(char* buff, char* fmt, ...) { return res; } -PIKA_WEAK void __platform_wait(void) { +PIKA_WEAK void pika_platform_wait(void) { while (1) { }; } -PIKA_WEAK void* __platform_memset(void* mem, int ch, size_t size) { +PIKA_WEAK void* pika_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) { +PIKA_WEAK void* pika_platform_memcpy(void* dir, const void* src, size_t size) { return memcpy(dir, src, size); } -PIKA_WEAK int __platform_memcmp(const void* s1, const void* s2, size_t n) { +PIKA_WEAK int pika_platform_memcmp(const void* s1, const void* s2, size_t n) { return memcmp(s1, s2, n); } -PIKA_WEAK void* __platform_memmove(void* s1, void* s2, size_t n) { +PIKA_WEAK void* pika_platform_memmove(void* s1, void* s2, size_t n) { return memmove(s1, s2, n); } -PIKA_WEAK char __platform_getchar(void) { +PIKA_WEAK char pika_platform_getchar(void) { #if defined(__linux) || defined(_WIN32) return getchar(); #else - __platform_printf("Error: __platform_getchar need implementation!\r\n"); + pika_platform_printf("Error: pika_platform_getchar need implementation!\r\n"); while (1) { } #endif } /* fopen */ -PIKA_WEAK FILE* __platform_fopen(const char* filename, const char* modes) { +PIKA_WEAK FILE* pika_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"); + pika_platform_printf("Error: pika_platform_fopen need implementation!\r\n"); while (1) { } #endif } /* fclose */ -PIKA_WEAK int __platform_fclose(FILE* stream) { +PIKA_WEAK int pika_platform_fclose(FILE* stream) { #if defined(__linux) || defined(_WIN32) return fclose(stream); #else - __platform_printf("Error: __platform_fclose need implementation!\r\n"); + pika_platform_printf("Error: pika_platform_fclose need implementation!\r\n"); while (1) { } #endif } /* fwrite */ -PIKA_WEAK size_t __platform_fwrite(const void* ptr, +PIKA_WEAK size_t pika_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"); + pika_platform_printf("Error: pika_platform_fwrite need implementation!\r\n"); while (1) { } #endif } /* fread */ -PIKA_WEAK size_t __platform_fread(void* ptr, +PIKA_WEAK size_t pika_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"); + pika_platform_printf("Error: pika_platform_fread need implementation!\r\n"); while (1) { } #endif } /* fseek */ -PIKA_WEAK int __platform_fseek(FILE* stream, long offset, int whence) { +PIKA_WEAK int pika_platform_fseek(FILE* stream, long offset, int whence) { #if defined(__linux) || defined(_WIN32) return fseek(stream, offset, whence); #else - __platform_printf("Error: __platform_fseek need implementation!\r\n"); + pika_platform_printf("Error: pika_platform_fseek need implementation!\r\n"); while (1) { } #endif } /* ftell */ -PIKA_WEAK long __platform_ftell(FILE* stream) { +PIKA_WEAK long pika_platform_ftell(FILE* stream) { #if defined(__linux) || defined(_WIN32) return ftell(stream); #else - __platform_printf("Error: __platform_ftell need implementation!\r\n"); + pika_platform_printf("Error: pika_platform_ftell need implementation!\r\n"); while (1) { } #endif } -PIKA_WEAK void __pks_hook_instruct(void) { +PIKA_WEAK void pika_hook_instruct(void) { return; } -PIKA_WEAK PIKA_BOOL __pks_hook_arg_cache_filter(void* self) { +PIKA_WEAK PIKA_BOOL pika_hook_arg_cache_filter(void* self) { return PIKA_TRUE; } -PIKA_WEAK void __platform_thread_delay(void) { +PIKA_WEAK void pika_platform_thread_delay(void) { return; } -PIKA_WEAK void __platform_sleep_ms(uint32_t ms) { - __platform_printf("Error: __platform_sleep_ms need implementation!\r\n"); +PIKA_WEAK void pika_platform_sleep_ms(uint32_t ms) { + pika_platform_printf("Error: pika_platform_sleep_ms need implementation!\r\n"); while (1) { } } -PIKA_WEAK void __platform_sleep_s(uint32_t s) { - __platform_printf("Error: __platform_sleep_s need implementation!\r\n"); +PIKA_WEAK void pika_platform_sleep_s(uint32_t s) { + pika_platform_printf("Error: pika_platform_sleep_s need implementation!\r\n"); while (1) { } } @@ -296,11 +296,11 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init( void* (*thread_entry)(void*); thread_entry = (void* (*)(void*))entry; - thread = __platform_malloc(sizeof(pika_platform_thread_t)); + thread = pika_platform_malloc(sizeof(pika_platform_thread_t)); res = pthread_create(&thread->thread, NULL, thread_entry, param); if (res != 0) { - __platform_free(thread); + pika_platform_free(thread); } thread->mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; @@ -311,14 +311,14 @@ PIKA_WEAK pika_platform_thread_t* pika_platform_thread_init( BaseType_t err; pika_platform_thread_t* thread; - thread = __platform_malloc(sizeof(pika_platform_thread_t)); + thread = pika_platform_malloc(sizeof(pika_platform_thread_t)); (void)tick; err = xTaskCreate(entry, name, stack_size, param, priority, thread->thread); if (pdPASS != err) { - __platform_free(thread); + pika_platform_free(thread); return NULL; } @@ -360,13 +360,13 @@ PIKA_WEAK void pika_platform_thread_destroy(pika_platform_thread_t* thread) { #ifdef __linux if (NULL != thread) { pthread_detach(thread->thread); - __platform_free(thread); + pika_platform_free(thread); thread = NULL; } #elif PIKA_FREERTOS_ENABLE if (NULL != thread) vTaskDelete(thread->thread); - __platform_memory_free(thread); + pika_platform_memory_free(thread); #else WEAK_FUNCTION_NEED_OVERRIDE_ERROR(); #endif diff --git a/src/PikaPlatform.h b/src/PikaPlatform.h index 5022eb068..2ea232d95 100644 --- a/src/PikaPlatform.h +++ b/src/PikaPlatform.h @@ -25,6 +25,9 @@ * SOFTWARE. */ +/* adapter for old api */ +#include "./pika_adapter_old_api.h" + /* micro pika configuration */ #include "./pika_config_valid.h" @@ -40,7 +43,7 @@ #if PIKA_ASSERT_ENABLE #define pika_assert(expr) \ if(!(expr)) { \ - __platform_printf("Assertion \"%s\" failed, in function: %s(). \r\n (at %s:%d)\n", #expr, __FUNCTION__, __FILE__, __LINE__); \ + pika_platform_printf("Assertion \"%s\" failed, in function: %s(). \r\n (at %s:%d)\n", #expr, __FUNCTION__, __FILE__, __LINE__); \ abort(); \ } #else @@ -74,7 +77,7 @@ /* OS */ #ifdef __RTTHREAD__ #include -#define __platform_printf(...) rt_kprintf(__VA_ARGS__) +#define pika_platform_printf(...) rt_kprintf(__VA_ARGS__) #endif typedef enum { @@ -120,65 +123,69 @@ typedef enum { */ /* interrupt config */ -void __platform_enable_irq_handle(void); -void __platform_disable_irq_handle(void); +void pika_platform_enable_irq_handle(void); +void pika_platform_disable_irq_handle(void); /* printf family config */ -#ifndef __platform_printf -void __platform_printf(char* fmt, ...); +#ifndef pika_platform_printf +void pika_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); -int __platform_snprintf(char* buff, size_t size, const char* fmt, ...); -char* __platform_strdup(const char* src); -size_t __platform_tick_from_millisecond(size_t ms); +int pika_platform_sprintf(char* buff, char* fmt, ...); +int pika_platform_vsprintf(char* buff, char* fmt, va_list args); +int pika_platform_vsnprintf(char* buff, + size_t size, + const char* fmt, + va_list args); +int pika_platform_snprintf(char* buff, size_t size, const char* fmt, ...); +char* pika_platform_strdup(const char* src); +size_t pika_platform_tick_from_millisecond(size_t ms); /* libc config */ -void* __platform_malloc(size_t size); -void* __platform_realloc(void* ptr, size_t size); -void* __platform_calloc(size_t num, 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); -int __platform_memcmp(const void* s1, const void* s2, size_t n); -void* __platform_memmove(void* s1, void* s2, size_t n); +void* pika_platform_malloc(size_t size); +void* pika_platform_realloc(void* ptr, size_t size); +void* pika_platform_calloc(size_t num, size_t size); +void pika_platform_free(void* ptr); +void* pika_platform_memset(void* mem, int ch, size_t size); +void* pika_platform_memcpy(void* dir, const void* src, size_t size); +int pika_platform_memcmp(const void* s1, const void* s2, size_t n); +void* pika_platform_memmove(void* s1, void* s2, size_t n); -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); +void pika_platform_wait(void); /* support shell */ -char __platform_getchar(void); -int __platform_putchar(char ch); +char pika_platform_getchar(void); +int pika_platform_putchar(char ch); /* 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); -int __platform_fseek(FILE* stream, long offset, int whence); -long __platform_ftell(FILE* stream); +FILE* pika_platform_fopen(const char* filename, const char* modes); +int pika_platform_fclose(FILE* stream); +size_t pika_platform_fwrite(const void* ptr, + size_t size, + size_t n, + FILE* stream); +size_t pika_platform_fread(void* ptr, size_t size, size_t n, FILE* stream); +int pika_platform_fseek(FILE* stream, long offset, int whence); +long pika_platform_ftell(FILE* stream); /* error */ -void __platform_error_handle(void); +void pika_platform_error_handle(void); /* panic */ -void __platform_panic_handle(void); +void pika_platform_panic_handle(void); -void __pks_hook_instruct(void); -PIKA_BOOL __pks_hook_arg_cache_filter(void* self); -void __platform_thread_delay(void); -int64_t __platform_getTick(void); +void pika_platform_thread_delay(void); +int64_t pika_platform_getTick(void); -void __platform_sleep_ms(uint32_t ms); -void __platform_sleep_s(uint32_t s); +void pika_platform_sleep_ms(uint32_t ms); +void pika_platform_sleep_s(uint32_t s); + +void pika_hook_instruct(void); +PIKA_BOOL pika_hook_arg_cache_filter(void* self); +void* pika_user_malloc(size_t size); +void pika_user_free(void* ptr, size_t size); +uint8_t pika_is_locked_pikaMemory(void); #if PIKA_FLOAT_TYPE_DOUBLE #define pika_float double @@ -206,11 +213,11 @@ typedef struct pika_platform_thread { } pika_platform_thread_t; #else /* - You need to create the __platform_thread.h for your platform. + You need to create the pika_platform_thread.h for your platform. For example: - You can #include in the __platform_thread.h + You can #include in the pika_platform_thread.h */ -#include "__platform_thread.h" +#include "pika_platform_thread.h" #endif pika_platform_thread_t* pika_platform_thread_init(const char* name, diff --git a/src/PikaVM.c b/src/PikaVM.c index 88836a8f3..28654013f 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -64,8 +64,8 @@ static PIKA_BOOL _cq_isFull(volatile EventCQ* cq) { void _VMEvent_deinit(void) { #if !PIKA_EVENT_ENABLE - __platform_printf("PIKA_EVENT_ENABLE is not enable"); - __platform_panic_handle(); + pika_platform_printf("PIKA_EVENT_ENABLE is not enable"); + pika_platform_panic_handle(); #else for (int i = 0; i < PIKA_EVENT_LIST_SIZE; i++) { if (NULL != PikaVMSignal.cq.res[i]) { @@ -84,8 +84,8 @@ PIKA_RES __eventListener_pushEvent(PikaEventListener* lisener, uint32_t eventId, Arg* eventData) { #if !PIKA_EVENT_ENABLE - __platform_printf("PIKA_EVENT_ENABLE is not enable"); - __platform_panic_handle(); + pika_platform_printf("PIKA_EVENT_ENABLE is not enable"); + pika_platform_panic_handle(); #else /* push to event_cq_buff */ if (_cq_isFull(&PikaVMSignal.cq)) { @@ -116,8 +116,8 @@ PIKA_RES __eventListener_popEvent(PikaEventListener** lisener_p, Arg** data, int* head) { #if !PIKA_EVENT_ENABLE - __platform_printf("PIKA_EVENT_ENABLE is not enable"); - __platform_panic_handle(); + pika_platform_printf("PIKA_EVENT_ENABLE is not enable"); + pika_platform_panic_handle(); #else /* pop from event_cq_buff */ if (_cq_isEmpty(&PikaVMSignal.cq)) { @@ -134,8 +134,8 @@ PIKA_RES __eventListener_popEvent(PikaEventListener** lisener_p, void _VMEvent_pickupEvent(void) { #if !PIKA_EVENT_ENABLE - __platform_printf("PIKA_EVENT_ENABLE is not enable"); - __platform_panic_handle(); + pika_platform_printf("PIKA_EVENT_ENABLE is not enable"); + pika_platform_panic_handle(); #else PikaObj* event_lisener; uint32_t event_id; @@ -500,9 +500,9 @@ Arg* _vm_slice(VMState* vm, uint8_t* bytes_origin = arg_getBytes(sliced_arg); size_t size_origin = arg_getBytesSize(sliced_arg); Arg* sliced_arg_new = arg_newBytes(NULL, size_origin + 1); - __platform_memcpy(arg_getBytes(sliced_arg_new), bytes_origin, + pika_platform_memcpy(arg_getBytes(sliced_arg_new), bytes_origin, size_origin); - __platform_memcpy(arg_getBytes(sliced_arg_new) + size_origin, + pika_platform_memcpy(arg_getBytes(sliced_arg_new) + size_origin, arg_getBytes(item_arg), 1); arg_deinit(sliced_arg); sliced_arg = sliced_arg_new; @@ -754,7 +754,7 @@ static Arg* VM_instruction_handler_REF(PikaObj* self, exit: if (NULL == res) { VMState_setErrorCode(vm, PIKA_RES_ERR_ARG_NO_FOUND); - __platform_printf("NameError: name '%s' is not defined\r\n", arg_path); + pika_platform_printf("NameError: name '%s' is not defined\r\n", arg_path); } else { res = arg_copy_noalloc(res, arg_ret_reg); } @@ -1149,10 +1149,10 @@ static int VMState_loadArgsFromMethodArg(VMState* vm, /* get method type list */ f.type_list = methodArg_getTypeList(method_arg, buffs1, sizeof(_buffs1)); if (NULL == f.type_list) { - __platform_printf( + pika_platform_printf( "OverflowError: type list is too long, please use bigger " "PIKA_LINE_BUFF_SIZE\r\n"); - __platform_panic_handle(); + pika_platform_panic_handle(); } f.method_type = arg_getType(method_arg); @@ -1177,7 +1177,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm, if (!vars_or_keys_or_default) { if (f.n_positional != f.n_input) { VMState_setErrorCode(vm, PIKA_RES_ERR_INVALID_PARAM); - __platform_printf( + pika_platform_printf( "TypeError: %s() takes %d positional argument but %d were " "given\r\n", method_name, f.n_positional, f.n_input); @@ -1190,7 +1190,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm, int8_t n_max = f.n_positional + f.n_default; if (f.n_input < n_min || f.n_input > n_max) { VMState_setErrorCode(vm, PIKA_RES_ERR_INVALID_PARAM); - __platform_printf( + pika_platform_printf( "TypeError: %s() takes from %d to %d positional arguments " "but %d were given\r\n", method_name, n_min, n_max, f.n_input); @@ -1209,7 +1209,7 @@ static int VMState_loadArgsFromMethodArg(VMState* vm, /* create tuple/dict for vars/keys */ if (vars_or_keys_or_default) { if (strGetSize(f.type_list) > sizeof(_buffs2)) { - __platform_printf( + pika_platform_printf( "OverFlowError: please use bigger PIKA_LINE_BUFF_SIZE\r\n"); while (1) { } @@ -1537,10 +1537,10 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, Arg* stack_tmp[PIKA_ARG_NUM_MAX] = {0}; int n_arg = VMState_getInputArgNum(vm); if (n_arg > PIKA_ARG_NUM_MAX) { - __platform_printf( + pika_platform_printf( "[ERROR] Too many args in RUN instruction, please use bigger " "#define PIKA_ARG_NUM_MAX\n"); - __platform_panic_handle(); + pika_platform_panic_handle(); } for (int i = 0; i < n_arg; i++) { stack_tmp[i] = stack_popArg_alloc(&(vm->stack)); @@ -1571,7 +1571,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, if (NULL == method_host) { /* error, not found object */ VMState_setErrorCode(vm, PIKA_RES_ERR_ARG_NO_FOUND); - __platform_printf("Error: method '%s' no found.\r\n", run_path); + pika_platform_printf("Error: method '%s' no found.\r\n", run_path); goto exit; } @@ -1607,7 +1607,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, if (NULL == method || ARG_TYPE_NONE == arg_getType(method)) { /* error, method no found */ VMState_setErrorCode(vm, PIKA_RES_ERR_ARG_NO_FOUND); - __platform_printf("NameError: name '%s' is not defined\r\n", run_path); + pika_platform_printf("NameError: name '%s' is not defined\r\n", run_path); goto exit; } @@ -1615,7 +1615,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, if (!argType_isCallable(arg_getType(method))) { /* error, method no found */ VMState_setErrorCode(vm, PIKA_RES_ERR_ARG_NO_FOUND); - __platform_printf("TypeError: '%s' object is not callable\r\n", + pika_platform_printf("TypeError: '%s' object is not callable\r\n", run_path); goto exit; } @@ -1943,12 +1943,12 @@ static Arg* VM_instruction_handler_NUM(PikaObj* self, if (data[1] == 'o' || data[1] == 'O') { char strtoll_buff[10] = {0}; strtoll_buff[0] = '0'; - __platform_memcpy(strtoll_buff + 1, data + 2, strGetSize(data) - 2); + pika_platform_memcpy(strtoll_buff + 1, data + 2, strGetSize(data) - 2); return arg_setInt(arg_ret_reg, "", strtoll(strtoll_buff, NULL, 0)); } if (data[1] == 'b' || data[1] == 'B') { char strtoll_buff[10] = {0}; - __platform_memcpy(strtoll_buff, data + 2, strGetSize(data) - 2); + pika_platform_memcpy(strtoll_buff, data + 2, strGetSize(data) - 2); return arg_setInt(arg_ret_reg, "", strtoll(strtoll_buff, NULL, 2)); } /* float */ @@ -2086,7 +2086,7 @@ static void _OPT_ADD(OperatorInfo* op) { if (argType_isObject(op->t1)) { if (!argType_isObject(op->t2)) { VMState_setErrorCode(op->vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf("TypeError: unsupported operand +\n"); + pika_platform_printf("TypeError: unsupported operand +\n"); op->res = NULL; return; } @@ -2094,7 +2094,7 @@ static void _OPT_ADD(OperatorInfo* op) { Arg* method_add = obj_getMethodArg(obj1, "__add__"); if (NULL == method_add) { VMState_setErrorCode(op->vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf("TypeError: unsupported operand +\n"); + pika_platform_printf("TypeError: unsupported operand +\n"); op->res = NULL; return; } @@ -2144,8 +2144,8 @@ static void _OPT_ADD(OperatorInfo* op) { size_t size2 = arg_getBytesSize(op->a2); op->res = arg_setBytes(op->res, "", NULL, size1 + size2); uint8_t* bytes_out = arg_getBytes(op->res); - __platform_memcpy(bytes_out, bytes1, size1); - __platform_memcpy(bytes_out + size1, bytes2, size2); + pika_platform_memcpy(bytes_out, bytes1, size1); + pika_platform_memcpy(bytes_out + size1, bytes2, size2); return; } #endif @@ -2164,7 +2164,7 @@ static void _OPT_SUB(OperatorInfo* op) { if (argType_isObject(op->t1)) { if (!argType_isObject(op->t2)) { VMState_setErrorCode(op->vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf("TypeError: unsupported operand +\n"); + pika_platform_printf("TypeError: unsupported operand +\n"); op->res = NULL; return; } @@ -2172,7 +2172,7 @@ static void _OPT_SUB(OperatorInfo* op) { Arg* method_sub = obj_getMethodArg(obj1, "__sub__"); if (NULL == method_sub) { VMState_setErrorCode(op->vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf("TypeError: unsupported operand +\n"); + pika_platform_printf("TypeError: unsupported operand +\n"); op->res = NULL; return; } @@ -2297,7 +2297,7 @@ static void _OPT_POW(OperatorInfo* op) { return; #else VMState_setErrorCode(op->vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf( + pika_platform_printf( "Operation float ** float is not enabled, please set " "PIKA_MATH_ENABLE\n"); #endif @@ -2333,7 +2333,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, goto exit; } VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf( + pika_platform_printf( "TypeError: unsupported operand type(s) for %%: 'float'\n"); op.res = NULL; goto exit; @@ -2368,7 +2368,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, goto exit; } VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf( + pika_platform_printf( "TypeError: unsupported operand type(s) for &: 'float'\n"); op.res = NULL; goto exit; @@ -2378,7 +2378,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, goto exit; } VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf( + pika_platform_printf( "TypeError: unsupported operand type(s) for |: 'float'\n"); op.res = NULL; goto exit; @@ -2388,7 +2388,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, goto exit; } VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf( + pika_platform_printf( "TypeError: unsupported operand type(s) for ~: 'float'\n"); op.res = NULL; goto exit; @@ -2463,7 +2463,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, goto exit; } VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf( + pika_platform_printf( "TypeError: unsupported operand type(s) for //: 'float'\n"); op.res = NULL; goto exit; @@ -2503,7 +2503,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, goto exit; } VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf( + pika_platform_printf( "TypeError: unsupported operand type(s) for >>: 'float'\n"); op.res = NULL; goto exit; @@ -2514,7 +2514,7 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self, goto exit; } VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf( + pika_platform_printf( "TypeError: unsupported operand type(s) for <<: 'float'\n"); op.res = NULL; goto exit; @@ -2646,10 +2646,10 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self, res = VM_instruction_handler_RIS(self, vm, data, arg_ret_reg); if (vm->run_state->try_state == TRY_STATE_NONE) { if (n_arg == 1) { - __platform_printf("AssertionError\n"); + pika_platform_printf("AssertionError\n"); } if (n_arg == 2) { - __platform_printf("AssertionError: %s\n", arg_getStr(arg2)); + pika_platform_printf("AssertionError: %s\n", arg_getStr(arg2)); } } goto exit; @@ -2692,7 +2692,7 @@ static Arg* VM_instruction_handler_DEL(PikaObj* self, return NULL; } VMState_setErrorCode(vm, PIKA_RES_ERR_OPERATION_FAILED); - __platform_printf("NameError: name '%s' is not defined\n", data); + pika_platform_printf("NameError: name '%s' is not defined\n", data); return NULL; } @@ -2772,7 +2772,7 @@ static Arg* VM_instruction_handler_IMP(PikaObj* self, return NULL; } VMState_setErrorCode(vm, PIKA_RES_ERR_ARG_NO_FOUND); - __platform_printf("ModuleNotFoundError: No module named '%s'\r\n", data); + pika_platform_printf("ModuleNotFoundError: No module named '%s'\r\n", data); return NULL; } @@ -2970,7 +2970,7 @@ static VMParameters* __pikaVM_runPyLines(PikaObj* self, char* py_lines) { /* generate byte code */ byteCodeFrame_init(bytecode_frame_p); if (PIKA_RES_OK != Parser_linesToBytes(bytecode_frame_p, py_lines)) { - __platform_printf("Error: Syntax error.\r\n"); + pika_platform_printf("Error: Syntax error.\r\n"); globals = NULL; goto exit; } @@ -3163,7 +3163,7 @@ void constPool_print(ConstPool* self) { goto exit; } uint16_t offset = self->content_offset_now; - __platform_printf("%d: %s\r\n", offset, constPool_getNow(self)); + pika_platform_printf("%d: %s\r\n", offset, constPool_getNow(self)); } exit: /* retore ptr_now */ @@ -3285,9 +3285,9 @@ static char* instructUnit_getInstructStr(InstructUnit* self) { void instructUnit_print(InstructUnit* self) { if (instructUnit_getIsNewLine(self)) { - __platform_printf("B%d\r\n", instructUnit_getBlockDeepth(self)); + pika_platform_printf("B%d\r\n", instructUnit_getBlockDeepth(self)); } - __platform_printf("%d %s #%d\r\n", instructUnit_getInvokeDeepth(self), + pika_platform_printf("%d %s #%d\r\n", instructUnit_getInvokeDeepth(self), instructUnit_getInstructStr(self), self->const_pool_index); } @@ -3295,9 +3295,9 @@ void instructUnit_print(InstructUnit* self) { static void instructUnit_printWithConst(InstructUnit* self, ConstPool* const_pool) { // if (instructUnit_getIsNewLine(self)) { - // __platform_printf("B%d\r\n", instructUnit_getBlockDeepth(self)); + // pika_platform_printf("B%d\r\n", instructUnit_getBlockDeepth(self)); // } - __platform_printf("%s %s \t\t(#%d)\r\n", instructUnit_getInstructStr(self), + pika_platform_printf("%s %s \t\t(#%d)\r\n", instructUnit_getInstructStr(self), constPool_getByOffset(const_pool, self->const_pool_index), self->const_pool_index); } @@ -3340,11 +3340,11 @@ void instructArray_printAsArray(InstructArray* self) { uint8_t line_num = 12; uint16_t g_i = 0; uint8_t* ins_size_p = (uint8_t*)&self->size; - __platform_printf("0x%02x, ", *(ins_size_p)); - __platform_printf("0x%02x, ", *(ins_size_p + (uintptr_t)1)); - __platform_printf("0x%02x, ", *(ins_size_p + (uintptr_t)2)); - __platform_printf("0x%02x, ", *(ins_size_p + (uintptr_t)3)); - __platform_printf("/* instruct array size */\n"); + pika_platform_printf("0x%02x, ", *(ins_size_p)); + pika_platform_printf("0x%02x, ", *(ins_size_p + (uintptr_t)1)); + pika_platform_printf("0x%02x, ", *(ins_size_p + (uintptr_t)2)); + pika_platform_printf("0x%02x, ", *(ins_size_p + (uintptr_t)3)); + pika_platform_printf("/* instruct array size */\n"); while (1) { InstructUnit* ins_unit = instructArray_getNow(self); if (NULL == ins_unit) { @@ -3352,15 +3352,15 @@ void instructArray_printAsArray(InstructArray* self) { } for (int i = 0; i < (int)instructUnit_getSize(); i++) { g_i++; - __platform_printf("0x%02x, ", *((uint8_t*)ins_unit + (uintptr_t)i)); + pika_platform_printf("0x%02x, ", *((uint8_t*)ins_unit + (uintptr_t)i)); if (g_i % line_num == 0) { - __platform_printf("\n"); + pika_platform_printf("\n"); } } instructArray_getNext(self); } exit: - __platform_printf("/* instruct array */\n"); + pika_platform_printf("/* instruct array */\n"); self->content_offset_now = offset_befor; return; } @@ -3372,8 +3372,8 @@ size_t byteCodeFrame_getSize(ByteCodeFrame* bf) { void byteCodeFrame_print(ByteCodeFrame* self) { constPool_print(&(self->const_pool)); instructArray_printWithConst(&(self->instruct_array), &(self->const_pool)); - __platform_printf("---------------\r\n"); - __platform_printf("byte code size: %d\r\n", + pika_platform_printf("---------------\r\n"); + pika_platform_printf("byte code size: %d\r\n", self->const_pool.size + self->instruct_array.size); } @@ -3442,7 +3442,7 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState( vm.ins_cnt++; #if PIKA_INSTRUCT_HOOK_ENABLE if (vm.ins_cnt % PIKA_INSTRUCT_HOOK_PERIOD == 0) { - __pks_hook_instruct(); + pika_hook_instruct(); } #endif #if PIKA_EVENT_ENABLE @@ -3465,9 +3465,9 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState( if (!vm.run_state->try_state) { while (1) { if (head_ins_unit != this_ins_unit) { - __platform_printf(" "); + pika_platform_printf(" "); } else { - __platform_printf(" -> "); + pika_platform_printf(" -> "); } instructUnit_printWithConst(head_ins_unit, &(bytecode_frame->const_pool)); @@ -3477,7 +3477,7 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState( } } } - __platform_error_handle(); + pika_platform_error_handle(); vm.error_code = 0; } } @@ -3497,17 +3497,17 @@ VMParameters* pikaVM_runByteCodeFrame(PikaObj* self, void constPool_printAsArray(ConstPool* self) { uint8_t* const_size_str = (uint8_t*)&(self->size); - __platform_printf("0x%02x, ", *(const_size_str)); - __platform_printf("0x%02x, ", *(const_size_str + (uintptr_t)1)); - __platform_printf("0x%02x, ", *(const_size_str + (uintptr_t)2)); - __platform_printf("0x%02x, ", *(const_size_str + (uintptr_t)3)); - __platform_printf("/* const pool size */\n"); + pika_platform_printf("0x%02x, ", *(const_size_str)); + pika_platform_printf("0x%02x, ", *(const_size_str + (uintptr_t)1)); + pika_platform_printf("0x%02x, ", *(const_size_str + (uintptr_t)2)); + pika_platform_printf("0x%02x, ", *(const_size_str + (uintptr_t)3)); + pika_platform_printf("/* const pool size */\n"); uint16_t ptr_befor = self->content_offset_now; uint8_t line_num = 12; uint16_t g_i = 0; /* set ptr_now to begin */ self->content_offset_now = 0; - __platform_printf("0x00, "); + pika_platform_printf("0x00, "); while (1) { if (NULL == constPool_getNext(self)) { goto exit; @@ -3516,27 +3516,27 @@ void constPool_printAsArray(ConstPool* self) { /* todo start */ size_t len = strlen(data_each); for (uint32_t i = 0; i < len + 1; i++) { - __platform_printf("0x%02x, ", *(data_each + (uintptr_t)i)); + pika_platform_printf("0x%02x, ", *(data_each + (uintptr_t)i)); g_i++; if (g_i % line_num == 0) { - __platform_printf("\n"); + pika_platform_printf("\n"); } } /* todo end */ } exit: /* retore ptr_now */ - __platform_printf("/* const pool */\n"); + pika_platform_printf("/* const pool */\n"); self->content_offset_now = ptr_befor; return; } void byteCodeFrame_printAsArray(ByteCodeFrame* self) { - __platform_printf("const uint8_t bytes[] = {\n"); + pika_platform_printf("const uint8_t bytes[] = {\n"); instructArray_printAsArray(&(self->instruct_array)); constPool_printAsArray(&(self->const_pool)); - __platform_printf("};\n"); - __platform_printf("pikaVM_runByteCode(self, (uint8_t*)bytes);\n"); + pika_platform_printf("};\n"); + pika_platform_printf("pikaVM_runByteCode(self, (uint8_t*)bytes);\n"); } PikaObj* pikaVM_runFile(PikaObj* self, char* file_name) { @@ -3544,15 +3544,15 @@ PikaObj* pikaVM_runFile(PikaObj* self, char* file_name) { char* module_name = strsCopy(&buffs, file_name); strPopLastToken(module_name, '.'); - __platform_printf("(pikascript) pika compiler:\r\n"); + pika_platform_printf("(pikascript) pika compiler:\r\n"); PikaMaker* maker = New_PikaMaker(); pikaMaker_compileModuleWithDepends(maker, module_name); pikaMaker_linkCompiledModules(maker, "pikaModules_cache.py.a"); pikaMaker_deinit(maker); - __platform_printf("(pikascript) all succeed.\r\n\r\n"); + pika_platform_printf("(pikascript) all succeed.\r\n\r\n"); pikaMemMaxReset(); - Obj_linkLibraryFile(self, "pikascript-api/pikaModules_cache.py.a"); + obj_linkLibraryFile(self, "pikascript-api/pikaModules_cache.py.a"); self = pikaVM_runSingleFile(self, file_name); strsDeinit(&buffs); return self; diff --git a/src/PikaVersion.h b/src/PikaVersion.h index dc2a686c9..0a961d533 100644 --- a/src/PikaVersion.h +++ b/src/PikaVersion.h @@ -1,5 +1,5 @@ #define PIKA_VERSION_MAJOR 1 -#define PIKA_VERSION_MINOR 11 -#define PIKA_VERSION_MICRO 9 +#define PIKA_VERSION_MINOR 12 +#define PIKA_VERSION_MICRO 0 -#define PIKA_EDIT_TIME "2022/12/22 15:33:13" +#define PIKA_EDIT_TIME "2022/12/29 18:05:17" diff --git a/src/dataArg.c b/src/dataArg.c index c249ad8f0..35a0dcc7a 100644 --- a/src/dataArg.c +++ b/src/dataArg.c @@ -36,7 +36,7 @@ static PIKA_BOOL _arg_cache_push(Arg* self, uint32_t size) { #if !PIKA_ARG_CACHE_ENABLE return PIKA_FALSE; #else - if (PIKA_FALSE == __pks_hook_arg_cache_filter(self)) { + if (PIKA_FALSE == pika_hook_arg_cache_filter(self)) { return PIKA_FALSE; } extern PikaMemInfo pikaMemInfo; @@ -139,9 +139,9 @@ static Arg* _arg_set_hash(Arg* self, self->name_hash = nameHash; self->type = type; if (NULL != content) { - __platform_memcpy(arg_getContent(self), content, size); + pika_platform_memcpy(arg_getContent(self), content, size); } else { - __platform_memset(arg_getContent(self), 0, + pika_platform_memset(arg_getContent(self), 0, aline_by(size, sizeof(uint32_t))); } pika_assert(self->flag < ARG_FLAG_MAX); @@ -200,7 +200,7 @@ Arg* arg_setContent(Arg* self, uint8_t* content, uint32_t size) { /* only copy */ if (arg_getSize(self) >= size) { - __platform_memcpy(arg_getContent((Arg*)self), content, size); + pika_platform_memcpy(arg_getContent((Arg*)self), content, size); return self; } @@ -237,13 +237,13 @@ Arg* arg_setBytes(Arg* self, char* name, uint8_t* src, size_t size) { arg_setType(self, ARG_TYPE_BYTES); void* dir = arg_getContent(self); /* set content all to 0 */ - __platform_memset(dir, 0, size + sizeof(size_t) + 1); + pika_platform_memset(dir, 0, size + sizeof(size_t) + 1); /* setsize */ - __platform_memcpy(dir, &size, sizeof(size_t)); + pika_platform_memcpy(dir, &size, sizeof(size_t)); /* set init value */ if (NULL != src) { - __platform_memcpy((void*)((uintptr_t)dir + sizeof(size_t)), src, size); + pika_platform_memcpy((void*)((uintptr_t)dir + sizeof(size_t)), src, size); } pika_assert(self->flag < ARG_FLAG_MAX); return self; @@ -276,39 +276,39 @@ char* __printBytes(PikaObj* self, Arg* arg) { void arg_printBytes(Arg* self, char* end) { PikaObj* obj = New_PikaObj(); - __platform_printf("%s%s", __printBytes(obj, self), end); + pika_platform_printf("%s%s", __printBytes(obj, self), end); obj_deinit(obj); } void arg_singlePrint(Arg* self, PIKA_BOOL in_REPL, char* end) { ArgType type = arg_getType(self); if (ARG_TYPE_NONE == type) { - __platform_printf("None%s", end); + pika_platform_printf("None%s", end); return; } if (argType_isObject(type)) { char* res = obj_toStr(arg_getPtr(self)); - __platform_printf("%s%s", res, end); + pika_platform_printf("%s%s", res, end); return; } if (type == ARG_TYPE_INT) { #if PIKA_PRINT_LLD_ENABLE - __platform_printf("%lld%s", (long long int)arg_getInt(self), end); + pika_platform_printf("%lld%s", (long long int)arg_getInt(self), end); #else - __platform_printf("%d%s", (int)arg_getInt(self), end); + pika_platform_printf("%d%s", (int)arg_getInt(self), end); #endif return; } if (type == ARG_TYPE_FLOAT) { - __platform_printf("%f%s", arg_getFloat(self), end); + pika_platform_printf("%f%s", arg_getFloat(self), end); return; } if (type == ARG_TYPE_STRING) { if (in_REPL) { - __platform_printf("'%s'%s", arg_getStr(self), end); + pika_platform_printf("'%s'%s", arg_getStr(self), end); return; } - __platform_printf("%s%s", arg_getStr(self), end); + pika_platform_printf("%s%s", arg_getStr(self), end); return; } if (type == ARG_TYPE_BYTES) { @@ -316,7 +316,7 @@ void arg_singlePrint(Arg* self, PIKA_BOOL in_REPL, char* end) { return; } if (ARG_TYPE_POINTER == type || ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR) { - __platform_printf("%p%s", arg_getPtr(self), end); + pika_platform_printf("%p%s", arg_getPtr(self), end); return; } return; @@ -328,7 +328,7 @@ size_t arg_getBytesSize(Arg* self) { if (NULL == content) { return 0; } - __platform_memcpy(&mem_size, content, sizeof(size_t)); + pika_platform_memcpy(&mem_size, content, sizeof(size_t)); return mem_size; } @@ -362,7 +362,7 @@ Arg* arg_setHeapStruct(Arg* self, void* arg_getHeapStructDeinitFun(Arg* self) { void* deinit_fun = NULL; - __platform_memcpy(&deinit_fun, arg_getContent(self), sizeof(void*)); + pika_platform_memcpy(&deinit_fun, arg_getContent(self), sizeof(void*)); return deinit_fun; } @@ -493,10 +493,10 @@ Arg* arg_append(Arg* self, void* new_content, size_t new_size) { arg_setNameHash(new_arg, arg_getNameHash(self)); if (self != new_arg) { /* copy old content */ - __platform_memcpy(arg_getContent(new_arg), old_content, old_size); + pika_platform_memcpy(arg_getContent(new_arg), old_content, old_size); } /* copy new content */ - __platform_memcpy(arg_getContent(new_arg) + old_size, new_content, + pika_platform_memcpy(arg_getContent(new_arg) + old_size, new_content, new_size); if (self != new_arg) { arg_deinit(self); @@ -536,29 +536,29 @@ void arg_deinitHeap(Arg* self) { /* 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); + char* file_buff = pika_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"); + pika_platform_memset(file_buff, 0, PIKA_READ_FILE_BUFF_SIZE); + FILE* input_file = pika_platform_fopen(filename, "rb"); if (NULL == input_file) { - __platform_printf("Error: Couldn't open file '%s'\n", filename); + pika_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); + pika_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"); + pika_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); + pika_platform_free(file_buff); if (NULL != input_file) { - __platform_fclose(input_file); + pika_platform_fclose(input_file); } return res; } @@ -591,7 +591,7 @@ PIKA_BOOL arg_isEqual(Arg* self, Arg* other) { return PIKA_TRUE; } } - if (0 != __platform_memcmp(arg_getContent(self), arg_getContent(other), + if (0 != pika_platform_memcmp(arg_getContent(self), arg_getContent(other), arg_getContentSize(self))) { return PIKA_FALSE; } diff --git a/src/dataMemory.c b/src/dataMemory.c index 130db13d5..c4af07503 100644 --- a/src/dataMemory.c +++ b/src/dataMemory.c @@ -33,8 +33,8 @@ volatile PikaMemInfo pikaMemInfo = {0}; void* pikaMalloc(uint32_t size) { /* pika memory lock */ - if (0 != __is_locked_pikaMemory()) { - __platform_wait(); + if (0 != pika_is_locked_pikaMemory()) { + pika_platform_wait(); } //! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment @@ -47,11 +47,11 @@ void* pikaMalloc(uint32_t size) { if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) { pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed; } - __platform_disable_irq_handle(); - void* mem = __user_malloc(size); - __platform_enable_irq_handle(); + pika_platform_disable_irq_handle(); + void* mem = pika_user_malloc(size); + pika_platform_enable_irq_handle(); if (NULL == mem) { - __platform_printf("Error: No heap space! Please reset the device.\r\n"); + pika_platform_printf("Error: No heap space! Please reset the device.\r\n"); while (1) { } } @@ -59,8 +59,8 @@ void* pikaMalloc(uint32_t size) { } void pikaFree(void* mem, uint32_t size) { - if (0 != __is_locked_pikaMemory()) { - __platform_wait(); + if (0 != pika_is_locked_pikaMemory()) { + pika_platform_wait(); } //! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment @@ -69,9 +69,9 @@ void pikaFree(void* mem, uint32_t size) { size = mem_align(size); #endif - __platform_disable_irq_handle(); - __user_free(mem, size); - __platform_enable_irq_handle(); + pika_platform_disable_irq_handle(); + pika_user_free(mem, size); + pika_platform_enable_irq_handle(); pikaMemInfo.heapUsed -= size; } @@ -105,7 +105,7 @@ Pool pool_init(uint32_t size, uint8_t 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.mem = pika_platform_malloc(pool_aline(&pool, pool.size)); pool.first_free_block = 0; pool.purl_free_block_start = 0; pool.inited = PIKA_TRUE; @@ -113,7 +113,7 @@ Pool pool_init(uint32_t size, uint8_t aline) { } void pool_deinit(Pool* pool) { - __platform_free(pool->mem); + pika_platform_free(pool->mem); pool->mem = NULL; bitmap_deinit(pool->bitmap); } @@ -130,13 +130,13 @@ uint32_t pool_getBlockIndex_byMem(Pool* pool, void* mem) { 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"); + pika_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: 0x%d", i * pool->aline, + pika_platform_printf("0x%x\t: 0x%d", i * pool->aline, (i + 15) * pool->aline); for (uint32_t j = i; j < i + 16; j += 4) { if (is_end) { @@ -147,11 +147,11 @@ void pool_printBlocks(Pool* pool, uint32_t size_min, uint32_t size_max) { is_end = 1; break; } - __platform_printf("%d", bitmap_get(pool->bitmap, k)); + pika_platform_printf("%d", bitmap_get(pool->bitmap, k)); } - __platform_printf(" "); + pika_platform_printf(" "); } - __platform_printf("\r\n"); + pika_platform_printf("\r\n"); } } @@ -244,12 +244,12 @@ void pool_free(Pool* pool, void* mem, uint32_t size) { BitMap bitmap_init(uint32_t size) { BitMap mem_bit_map = - (BitMap)__platform_malloc(((size - 1) / 8 + 1) * sizeof(char)); + (BitMap)pika_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); + pika_platform_memset(mem_bit_map, 0x0, size_mem_bit_map); return mem_bit_map; } @@ -284,15 +284,15 @@ uint8_t bitmap_get(BitMap bitmap, uint32_t index) { } void bitmap_deinit(BitMap bitmap) { - __platform_free(bitmap); + pika_platform_free(bitmap); } #if PIKA_POOL_ENABLE Pool pikaPool = {0}; -void* __user_malloc(size_t size) { +void* pika_user_malloc(size_t size) { return pool_malloc(&pikaPool, size); } -void __user_free(void* ptrm, size_t size) { +void pika_user_free(void* ptrm, size_t size) { pool_free(&pikaPool, ptrm, size); } #endif @@ -308,7 +308,7 @@ void mem_pool_init(void) { void _mem_cache_deinit(void) { #if PIKA_ARG_CACHE_ENABLE while (pikaMemInfo.cache_pool_top) { - __user_free(pikaMemInfo.cache_pool[pikaMemInfo.cache_pool_top - 1], 0); + pika_user_free(pikaMemInfo.cache_pool[pikaMemInfo.cache_pool_top - 1], 0); pikaMemInfo.cache_pool_top--; } #endif diff --git a/src/dataStack.c b/src/dataStack.c index 87bdb67c4..bef2389e8 100644 --- a/src/dataStack.c +++ b/src/dataStack.c @@ -97,22 +97,22 @@ void stack_pushPyload(Stack* stack, 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( + pika_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", + pika_platform_printf("Info: stack size request: %d\r\n", (int)stack_size_after_push); - __platform_printf("Info: stack size now: %d\r\n", + pika_platform_printf("Info: stack size now: %d\r\n", (int)stack->stack_totle_size); while (1) { } } Arg* top = (Arg*)stack->sp; if (is_sample_copy) { - __platform_memcpy(top, in, size); + pika_platform_memcpy(top, in, size); } else { - __platform_memcpy(top, in, sizeof(Arg)); - __platform_memcpy(top->content, ((Arg*)in)->_.buffer, + pika_platform_memcpy(top, in, sizeof(Arg)); + pika_platform_memcpy(top->content, ((Arg*)in)->_.buffer, size - sizeof(Arg)); /* transfer to serialized form */ arg_setSerialized(top, PIKA_TRUE); diff --git a/src/dataString.c b/src/dataString.c index 56a58890c..206e2bce9 100644 --- a/src/dataString.c +++ b/src/dataString.c @@ -242,7 +242,7 @@ int32_t strIsContain(char* str, char ch) { } char* strCopy(char* strBuff, char* strIn) { - __platform_memcpy(strBuff, strIn, strGetSize(strIn) + 1); + pika_platform_memcpy(strBuff, strIn, strGetSize(strIn) + 1); return strBuff; } @@ -258,7 +258,7 @@ int32_t strGetLineSize(char* str) { char* strGetLine(char* strOut, char* strIn) { int32_t lineSize = strGetLineSize(strIn); - __platform_memcpy(strOut, strIn, lineSize); + pika_platform_memcpy(strOut, strIn, lineSize); strOut[lineSize] = 0; return strOut; } @@ -276,7 +276,7 @@ char* strGetLastLine(char* strOut, char* strIn) { } } - __platform_memcpy(strOut, strIn + beginIndex, size - beginIndex); + pika_platform_memcpy(strOut, strIn + beginIndex, size - beginIndex); strOut[size - beginIndex + 1] = 0; return strOut; } diff --git a/src/dataStrs.c b/src/dataStrs.c index 1d1e2f9b2..3f9403801 100644 --- a/src/dataStrs.c +++ b/src/dataStrs.c @@ -122,7 +122,7 @@ 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); + pika_platform_vsnprintf(res, buffSize, fmt, args); va_end(args); return res; } diff --git a/src/pika_adapter_mpy.h b/src/pika_adapter_mpy.h index d82d22759..c60449a7f 100644 --- a/src/pika_adapter_mpy.h +++ b/src/pika_adapter_mpy.h @@ -47,7 +47,7 @@ #define MP_ENOMEM "out of memory" #define MP_BUFFER_READ "read" #define MP_ERROR_TEXT(_s) _s -#define mp_raise_msg_varg(_, ...) __platform_printf(__VA_ARGS__) +#define mp_raise_msg_varg(_, ...) pika_platform_printf(__VA_ARGS__) #define mp_raise_msg(_, _s) mp_raise_msg_varg(_, _s) #define mp_raise_TpyeXXX(_s) mp_raise_msg(NULL, _s) #define mp_raise_ValueError mp_raise_TpyeXXX diff --git a/src/pika_adapter_rtt.h b/src/pika_adapter_rtt.h index 03adbd2cb..a8c824c85 100644 --- a/src/pika_adapter_rtt.h +++ b/src/pika_adapter_rtt.h @@ -8,18 +8,18 @@ #define RT_TRUE 1 /**< boolean true */ #define RT_FALSE 0 /**< boolean fails */ -#define rt_malloc __platform_malloc -#define rt_calloc __platform_calloc -#define rt_realloc __platform_realloc -#define rt_free __platform_free -#define rt_memset __platform_memset -#define rt_memcpy __platform_memcpy -#define rt_memcmp __platform_memcmp -#define rt_kprintf __platform_printf -#define rt_snprintf __platform_snprintf -#define rt_vsnprintf __platform_vsnprintf -#define rt_strdup __platform_strdup -#define rt_tick_from_millisecond __platform_tick_from_millisecond +#define rt_malloc pika_platform_malloc +#define rt_calloc pika_platform_calloc +#define rt_realloc pika_platform_realloc +#define rt_free pika_platform_free +#define rt_memset pika_platform_memset +#define rt_memcpy pika_platform_memcpy +#define rt_memcmp pika_platform_memcmp +#define rt_kprintf pika_platform_printf +#define rt_snprintf pika_platform_snprintf +#define rt_vsnprintf pika_platform_vsnprintf +#define rt_strdup pika_platform_strdup +#define rt_tick_from_millisecond pika_platform_tick_from_millisecond #define rt_int32_t int32_t #define rt_uint32_t uint32_t @@ -45,7 +45,7 @@ #define RT_EINTR 9 /**< Interrupted system call */ #define RT_EINVAL 10 /**< Invalid argument */ -#define LOG_E(fmt, ...) __platform_printf(fmt "\r\n", ##__VA_ARGS__) +#define LOG_E(fmt, ...) pika_platform_printf(fmt "\r\n", ##__VA_ARGS__) #define LOG_W(...) #define LOG_D(...) diff --git a/test/pika_config_gtest.c b/test/pika_config_gtest.c index 7e0f6bb75..46c28bc85 100644 --- a/test/pika_config_gtest.c +++ b/test/pika_config_gtest.c @@ -6,9 +6,8 @@ char log_buff[LOG_BUFF_MAX][LOG_SIZE] = {0}; uint32_t log_index = 0; -#ifndef __platform_printf /* save printf content to log_buff */ -void __platform_printf(char* fmt, ...) { +void pika_platform_printf(char* fmt, ...) { va_list args; for (int i = LOG_BUFF_MAX - 2; i >= 0; i--) { memcpy(log_buff[i + 1], log_buff[i], LOG_SIZE); @@ -21,7 +20,6 @@ void __platform_printf(char* fmt, ...) { __platform_putchar(log_buff[0][i]); } } -#endif /* quick_malloc is always open */ uint8_t __is_quick_malloc(void) {