support isinstance() for simple type

This commit is contained in:
lyon 2023-05-21 01:19:13 +08:00
parent 977d844d2c
commit c823ad0879
33 changed files with 483 additions and 410 deletions

View File

@ -197,7 +197,7 @@ int dict_contains(PikaDict* dict, Arg* key) {
}
i++;
}
return PIKA_FALSE;
return pika_false;
}
int PikaStdData_Dict___contains__(PikaObj* self, Arg* val) {

View File

@ -47,6 +47,10 @@ class SysObj:
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def type(arg: any) -> any: ...
@staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def isinstance(object: any, classinfo: any) -> bool: ...
@staticmethod
def len(arg: any) -> int: ...

View File

@ -154,10 +154,10 @@ int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg, PikaTuple* base) {
return _PIKA_INT_ERR;
}
PIKA_BOOL PikaStdLib_SysObj_bool(PikaObj* self, Arg* arg) {
pika_bool PikaStdLib_SysObj_bool(PikaObj* self, Arg* arg) {
int64_t res = 0;
if (_transeInt(arg, 10, &res) == PIKA_RES_OK) {
return res ? PIKA_TRUE : PIKA_FALSE;
return res ? PIKA_TRUE : pika_false;
}
obj_setSysOut(self, "ValueError: invalid literal for bool()");
obj_setErrorCode(self, 1);
@ -181,7 +181,7 @@ char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
/* object */
PIKA_BOOL bIsTemp = PIKA_FALSE;
pika_bool bIsTemp = pika_false;
PikaObj* oArg = _arg_to_obj(arg, &bIsTemp);
NewFun _clsptr = (NewFun)oArg->constructor;
if (_clsptr == New_PikaStdLib_RangeObj) {
@ -470,11 +470,11 @@ void PikaStdLib_SysObj_print(PikaObj* self, PikaTuple* val, PikaDict* ops) {
end = "\r\n";
}
if (arg_size == 1) {
arg_print(pikaTuple_getArg(val, 0), PIKA_FALSE, end);
arg_print(pikaTuple_getArg(val, 0), pika_false, end);
return;
}
Arg* print_out_arg = NULL;
PIKA_BOOL is_get_print = PIKA_FALSE;
pika_bool is_get_print = pika_false;
for (int i = 0; i < arg_size; i++) {
Arg* arg = pikaTuple_getArg(val, i);
Arg* item_arg_str = arg_toStrArg(arg);
@ -795,3 +795,27 @@ Arg* PikaStdLib_SysObj_max(PikaObj* self, PikaTuple* val) {
Arg* PikaStdLib_SysObj_min(PikaObj* self, PikaTuple* val) {
return _max_min(self, val, (uint8_t*)bc_min);
}
pika_bool PikaStdLib_SysObj_isinstance(PikaObj* self,
Arg* object,
Arg* classinfo) {
pika_bool res = pika_false;
Arg* aObjType = NULL;
if (!argType_isConstructor(arg_getType(classinfo)) &&
!argType_isCallable(arg_getType(classinfo))) {
obj_setErrorCode(self, 1);
__platform_printf("TypeError: isinstance() arg 2 must be a type\r\n");
res = pika_false;
goto __exit;
}
aObjType = PikaStdLib_SysObj_type(self, object);
if (arg_getPtr(aObjType) == arg_getPtr(classinfo)) {
res = pika_true;
goto __exit;
}
__exit:
if (NULL != aObjType) {
arg_deinit(aObjType);
}
return res;
}

View File

@ -24,9 +24,9 @@
// "--gtest_filter=lua.eval"
// "--gtest_filter=eventloop.once1"
// "--gtest_filter=parser.fn_fn"
// "--gtest_filter=vm.fn_fn"
"--gtest_filter=vm.isinstance"
// "--gtest_filter=VM.run_def_add"
"--gtest_filter=parser.slice_fn"
// "--gtest_filter=parser.slice_fn"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",

View File

@ -47,6 +47,10 @@ class SysObj:
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def type(arg: any) -> any: ...
@staticmethod
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
def isinstance(object: any, classinfo: any) -> bool: ...
@staticmethod
def len(arg: any) -> int: ...

View File

@ -197,7 +197,7 @@ int dict_contains(PikaDict* dict, Arg* key) {
}
i++;
}
return PIKA_FALSE;
return pika_false;
}
int PikaStdData_Dict___contains__(PikaObj* self, Arg* val) {

View File

@ -154,10 +154,10 @@ int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg, PikaTuple* base) {
return _PIKA_INT_ERR;
}
PIKA_BOOL PikaStdLib_SysObj_bool(PikaObj* self, Arg* arg) {
pika_bool PikaStdLib_SysObj_bool(PikaObj* self, Arg* arg) {
int64_t res = 0;
if (_transeInt(arg, 10, &res) == PIKA_RES_OK) {
return res ? PIKA_TRUE : PIKA_FALSE;
return res ? PIKA_TRUE : pika_false;
}
obj_setSysOut(self, "ValueError: invalid literal for bool()");
obj_setErrorCode(self, 1);
@ -181,7 +181,7 @@ char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
/* object */
PIKA_BOOL bIsTemp = PIKA_FALSE;
pika_bool bIsTemp = pika_false;
PikaObj* oArg = _arg_to_obj(arg, &bIsTemp);
NewFun _clsptr = (NewFun)oArg->constructor;
if (_clsptr == New_PikaStdLib_RangeObj) {
@ -470,11 +470,11 @@ void PikaStdLib_SysObj_print(PikaObj* self, PikaTuple* val, PikaDict* ops) {
end = "\r\n";
}
if (arg_size == 1) {
arg_print(pikaTuple_getArg(val, 0), PIKA_FALSE, end);
arg_print(pikaTuple_getArg(val, 0), pika_false, end);
return;
}
Arg* print_out_arg = NULL;
PIKA_BOOL is_get_print = PIKA_FALSE;
pika_bool is_get_print = pika_false;
for (int i = 0; i < arg_size; i++) {
Arg* arg = pikaTuple_getArg(val, i);
Arg* item_arg_str = arg_toStrArg(arg);
@ -795,3 +795,27 @@ Arg* PikaStdLib_SysObj_max(PikaObj* self, PikaTuple* val) {
Arg* PikaStdLib_SysObj_min(PikaObj* self, PikaTuple* val) {
return _max_min(self, val, (uint8_t*)bc_min);
}
pika_bool PikaStdLib_SysObj_isinstance(PikaObj* self,
Arg* object,
Arg* classinfo) {
pika_bool res = pika_false;
Arg* aObjType = NULL;
if (!argType_isConstructor(arg_getType(classinfo)) &&
!argType_isCallable(arg_getType(classinfo))) {
obj_setErrorCode(self, 1);
__platform_printf("TypeError: isinstance() arg 2 must be a type\r\n");
res = pika_false;
goto __exit;
}
aObjType = PikaStdLib_SysObj_type(self, object);
if (arg_getPtr(aObjType) == arg_getPtr(classinfo)) {
res = pika_true;
goto __exit;
}
__exit:
if (NULL != aObjType) {
arg_deinit(aObjType);
}
return res;
}

View File

@ -38,15 +38,15 @@ const char magic_code_pyo[] = {0x0f, 'p', 'y', 'o'};
/*
* @brief check magic code of pyo file
* @param bytecode
* @return PIKA_TRUE or PIKA_FALSE
* @return pika_true or pika_false
*/
static PIKA_BOOL _check_magic_code_pyo(uint8_t* bytecode) {
static pika_bool _check_magic_code_pyo(uint8_t* bytecode) {
char* data = (char*)bytecode;
if (data[0] == magic_code_pyo[0] && data[1] == magic_code_pyo[1] &&
data[2] == magic_code_pyo[2] && data[3] == magic_code_pyo[3]) {
return PIKA_TRUE;
return pika_true;
}
return PIKA_FALSE;
return pika_false;
}
/*
@ -468,10 +468,10 @@ static PIKA_RES _loadModuleDataWithIndex(uint8_t* library_bytes,
*(uint32_t*)(module_name + LIB_INFO_BLOCK_SIZE - sizeof(uint32_t));
*size = module_size;
/* fix size for string */
PIKA_BOOL bIsString = PIKA_TRUE;
pika_bool bIsString = pika_true;
for (size_t i = 0; i < *size - 1; ++i) {
if (bytecode_addr[i] == 0) {
bIsString = PIKA_FALSE;
bIsString = pika_false;
break;
}
}
@ -1014,7 +1014,7 @@ int32_t __foreach_handler_linkCompiledModules(Arg* argEach, void* context) {
PIKA_RES _do_pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
char* lib_path,
PIKA_BOOL gen_c_array) {
pika_bool gen_c_array) {
PIKA_RES compile_err = (PIKA_RES)obj_getInt(self, "err");
if (PIKA_RES_OK != compile_err) {
pika_platform_printf(" Error: compile failed, link aborted.\r\n");
@ -1042,12 +1042,12 @@ PIKA_RES _do_pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
char* lib_path) {
return _do_pikaMaker_linkCompiledModulesFullPath(self, lib_path, PIKA_TRUE);
return _do_pikaMaker_linkCompiledModulesFullPath(self, lib_path, pika_true);
}
PIKA_RES _do_pikaMaker_linkCompiledModules(PikaMaker* self,
char* lib_name,
PIKA_BOOL gen_c_array) {
pika_bool gen_c_array) {
Args buffs = {0};
char* lib_file_path = strsPathJoin(&buffs, "pikascript-api/", lib_name);
PIKA_RES res = _do_pikaMaker_linkCompiledModulesFullPath(
@ -1057,7 +1057,7 @@ PIKA_RES _do_pikaMaker_linkCompiledModules(PikaMaker* self,
}
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name) {
return _do_pikaMaker_linkCompiledModules(self, lib_name, PIKA_TRUE);
return _do_pikaMaker_linkCompiledModules(self, lib_name, pika_true);
}
/*
@ -1112,7 +1112,7 @@ pikafs_FILE* pikafs_fopen_pack(char* pack_name, char* file_name) {
f->addr = (uint8_t*)pikaMalloc(f->size);
pika_platform_memcpy(f->addr, arg_getBytes(file_arg), f->size);
f->need_free = PIKA_TRUE;
f->need_free = pika_true;
arg_deinit(file_arg);
return f;

View File

@ -35,7 +35,7 @@ PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path);
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
PIKA_RES _do_pikaMaker_linkCompiledModules(PikaMaker* self,
char* lib_name,
PIKA_BOOL gen_c_array);
pika_bool gen_c_array);
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes);
void LibObj_printModules(LibObj* self);
void pikaMaker_deinit(PikaMaker* self);
@ -56,7 +56,7 @@ typedef struct {
uint8_t* addr;
size_t size;
size_t pos;
PIKA_BOOL need_free;
pika_bool need_free;
} pikafs_FILE;
pikafs_FILE* pikafs_fopen(char* file_name, char* mode);

View File

@ -46,7 +46,7 @@
extern volatile VMSignal g_PikaVMSignal;
volatile PikaObjState g_PikaObjState = {
.helpModulesCmodule = NULL,
.inRootObj = PIKA_FALSE,
.inRootObj = pika_false,
#if PIKA_GC_MARK_SWEEP_ENABLE
.objCnt = 0,
.objCntMax = 0,
@ -175,9 +175,9 @@ int obj_GC(PikaObj* self) {
int32_t obj_deinit(PikaObj* self) {
pikaGC_lock();
PIKA_BOOL bisRoot = PIKA_FALSE;
pika_bool bisRoot = pika_false;
#if PIKA_KERNAL_DEBUG_ENABLE
self->isAlive = PIKA_FALSE;
self->isAlive = pika_false;
#endif
Arg* del = obj_getMethodArgWithFullPath(self, "__del__");
if (NULL != del) {
@ -193,7 +193,7 @@ int32_t obj_deinit(PikaObj* self) {
}
extern volatile PikaObj* __pikaMain;
if (self == (PikaObj*)__pikaMain) {
bisRoot = PIKA_TRUE;
bisRoot = pika_true;
_mem_cache_deinit();
#if PIKA_EVENT_ENABLE
_VMEvent_deinit();
@ -298,19 +298,19 @@ int64_t obj_getInt(PikaObj* self, char* argPath) {
return res;
}
PIKA_BOOL obj_getBool(PikaObj* self, char* argPath) {
pika_bool obj_getBool(PikaObj* self, char* argPath) {
PikaObj* obj = obj_getHostObj(self, argPath);
if (NULL == obj) {
return PIKA_FALSE;
return pika_false;
}
char* argName = strPointToLastToken(argPath, '.');
PIKA_BOOL res = args_getBool(obj->list, argName);
pika_bool res = args_getBool(obj->list, argName);
return res;
}
Arg* obj_getArg(PikaObj* self, char* argPath) {
pika_assert(obj_checkAlive(self));
PIKA_BOOL is_temp = PIKA_FALSE;
pika_bool is_temp = pika_false;
PikaObj* obj = obj_getHostObjWithIsTemp(self, argPath, &is_temp);
if (NULL == obj) {
return NULL;
@ -384,7 +384,7 @@ static PIKA_RES _obj_setArg(PikaObj* self,
/* setArg would copy arg */
PikaObj* host = obj_getHostObj(self, argPath);
PikaObj* oNew = NULL;
PIKA_BOOL bNew = PIKA_FALSE;
pika_bool bNew = pika_false;
if (NULL == host) {
/* object no found */
return PIKA_RES_ERR_ARG_NO_FOUND;
@ -399,7 +399,7 @@ static PIKA_RES _obj_setArg(PikaObj* self,
aNew = arg_setName(aNew, sArgName);
if (arg_isObject(aNew)) {
oNew = arg_getPtr(aNew);
bNew = PIKA_TRUE;
bNew = pika_true;
pika_assert(obj_checkAlive(oNew));
#if PIKA_KERNAL_DEBUG_ENABLE
if (host != oNew) {
@ -732,7 +732,7 @@ static void signal_handler(int sig) {
extern volatile PikaObj* __pikaMain;
PikaObj* newRootObj(char* name, NewFun newObjFun) {
g_PikaObjState.inRootObj = PIKA_TRUE;
g_PikaObjState.inRootObj = pika_true;
#if PIKA_POOL_ENABLE
mem_pool_init();
#endif
@ -763,7 +763,7 @@ PikaObj* newRootObj(char* name, NewFun newObjFun) {
}
__pikaMain = newObj;
obj_setName(newObj, name);
g_PikaObjState.inRootObj = PIKA_FALSE;
g_PikaObjState.inRootObj = pika_false;
return newObj;
}
@ -808,7 +808,7 @@ exit:
return res;
}
PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
PikaObj* _arg_to_obj(Arg* self, pika_bool* pIsTemp) {
if (NULL == self) {
return NULL;
}
@ -821,7 +821,7 @@ PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
PikaObj* obj = newNormalObj(New_PikaStdData_String);
obj_setStr(obj, "str", arg_getStr(self));
if (NULL != pIsTemp) {
*pIsTemp = PIKA_TRUE;
*pIsTemp = pika_true;
}
return obj;
}
@ -830,7 +830,7 @@ PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
PikaObj* obj = newNormalObj(New_PikaStdData_ByteArray);
obj_setArg(obj, "raw", self);
if (NULL != pIsTemp) {
*pIsTemp = PIKA_TRUE;
*pIsTemp = pika_true;
}
return obj;
}
@ -840,8 +840,8 @@ PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
static PikaObj* _obj_getObjDirect(PikaObj* self,
char* name,
PIKA_BOOL* pIsTemp) {
*pIsTemp = PIKA_FALSE;
pika_bool* pIsTemp) {
*pIsTemp = pika_false;
if (NULL == self) {
return NULL;
}
@ -867,7 +867,7 @@ static PikaObj* _obj_getObjDirect(PikaObj* self,
/* found class */
if (type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
type == ARG_TYPE_METHOD_CONSTRUCTOR) {
*pIsTemp = PIKA_TRUE;
*pIsTemp = pika_true;
PikaObj* method_args_obj = New_TinyObj(NULL);
Arg* cls_obj_arg = obj_runMethodArg(self, method_args_obj, arg_obj);
obj_deinit(method_args_obj);
@ -884,7 +884,7 @@ static PikaObj* _obj_getObjDirect(PikaObj* self,
static PikaObj* _obj_getObjWithKeepDeepth(PikaObj* self,
char* objPath,
PIKA_BOOL* pIsTemp,
pika_bool* pIsTemp,
int32_t keepDeepth) {
char objPath_buff[PIKA_PATH_BUFF_SIZE];
char* objPath_ptr = objPath_buff;
@ -912,19 +912,19 @@ exit:
PikaObj* obj_getObj(PikaObj* self, char* objPath) {
pika_assert(NULL != objPath);
PIKA_BOOL is_temp = PIKA_FALSE;
pika_bool is_temp = pika_false;
return _obj_getObjWithKeepDeepth(self, objPath, &is_temp, 0);
}
PikaObj* obj_getHostObj(PikaObj* self, char* objPath) {
pika_assert(NULL != objPath);
PIKA_BOOL is_temp = PIKA_FALSE;
pika_bool is_temp = pika_false;
return _obj_getObjWithKeepDeepth(self, objPath, &is_temp, 1);
}
PikaObj* obj_getHostObjWithIsTemp(PikaObj* self,
char* objPath,
PIKA_BOOL* pIsTemp) {
pika_bool* pIsTemp) {
return _obj_getObjWithKeepDeepth(self, objPath, pIsTemp, 1);
}
@ -1223,7 +1223,7 @@ enum PIKA_SHELL_STATE {
static void _obj_runChar_beforeRun(PikaObj* self, ShellConfig* shell) {
/* create the line buff for the first time */
shell->inBlock = PIKA_FALSE;
shell->inBlock = pika_false;
shell->stat = PIKA_SHELL_STATE_NORMAL;
shell->line_position = 0;
shell->line_curpos = 0;
@ -1246,18 +1246,18 @@ typedef enum {
__FILTER_SUCCESS_DROP_ALL_PEEKED
} FilterReturn;
PIKA_BOOL _filter_msg_hi_pika_handler(FilterItem* msg,
pika_bool _filter_msg_hi_pika_handler(FilterItem* msg,
PikaObj* self,
ShellConfig* shell) {
pika_platform_printf("Yes, I am here\r\n");
return PIKA_TRUE;
return pika_true;
}
PIKA_BOOL _filter_msg_bye_pika_handler(FilterItem* msg,
pika_bool _filter_msg_bye_pika_handler(FilterItem* msg,
PikaObj* self,
ShellConfig* shell) {
pika_platform_printf("OK, see you\r\n");
return PIKA_TRUE;
return pika_true;
}
#define __MSG_DECLARE
@ -1485,7 +1485,7 @@ char* shHistory_getNext(ShellHistory* self) {
static void handle_history_navigation(char inputChar,
ShellConfig* shell,
PIKA_BOOL bIsUp) {
pika_bool bIsUp) {
#if PIKA_SHELL_HISTORY_ENABLE
if (NULL == shell->history) {
shell->history = shHistory_create(PIKA_SHELL_HISTORY_NUM);
@ -1569,12 +1569,12 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
if (inputChar == PIKA_KEY_UP) {
_putc_cmd(PIKA_KEY_DOWN, 1);
ctrl = SHELL_CTRL_CONTINUE;
handle_history_navigation(inputChar, shell, PIKA_TRUE);
handle_history_navigation(inputChar, shell, pika_true);
goto __exit;
}
if (inputChar == PIKA_KEY_DOWN) {
ctrl = SHELL_CTRL_CONTINUE;
handle_history_navigation(inputChar, shell, PIKA_FALSE);
handle_history_navigation(inputChar, shell, pika_false);
goto __exit;
}
}
@ -1658,7 +1658,7 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
strsDeinit(&buffs);
/* go out from block */
if ((shell->lineBuff[0] != ' ') && (shell->lineBuff[0] != '\t')) {
shell->inBlock = PIKA_FALSE;
shell->inBlock = pika_false;
input_line = obj_getStr(self, shell->blockBuffName);
ctrl = shell->handler(self, input_line, shell);
__clearBuff(shell);
@ -1674,7 +1674,7 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
/* go in block */
if (shell->blockBuffName != NULL && 0 != strGetSize(shell->lineBuff)) {
if (shell->lineBuff[strGetSize(shell->lineBuff) - 1] == ':') {
shell->inBlock = PIKA_TRUE;
shell->inBlock = pika_true;
char _n = '\n';
strAppendWithSize(shell->lineBuff, &_n, 1);
obj_setStr(self, shell->blockBuffName, shell->lineBuff);
@ -1706,11 +1706,11 @@ enum shellCTRL _do_obj_runChar(PikaObj* self,
if (NULL == queue->buffer) {
/* need initialize first */
byteQueue_init(queue, &shell->filter_fifo.buffer,
sizeof(shell->filter_fifo.buffer), PIKA_FALSE);
sizeof(shell->filter_fifo.buffer), pika_false);
}
PIKA_BOOL result = byteQueue_writeOne(queue, inputChar);
pika_assert(result != PIKA_FALSE);
pika_bool result = byteQueue_writeOne(queue, inputChar);
pika_assert(result != pika_false);
int16_t byte_count;
do {
@ -1722,7 +1722,7 @@ enum shellCTRL _do_obj_runChar(PikaObj* self,
while (n--) {
result = byteQueue_readOne(queue, (uint8_t*)&inputChar);
pika_assert(PIKA_FALSE != result);
pika_assert(pika_false != result);
if (SHELL_CTRL_EXIT ==
_inner_do_obj_runChar(self, inputChar, shell)) {
@ -1792,8 +1792,8 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
char* buff = pikaMalloc(PIKA_READ_FILE_BUFF_SIZE);
char input[2] = {0};
int buff_i = 0;
PIKA_BOOL is_exit = PIKA_FALSE;
PIKA_BOOL is_first_line = PIKA_TRUE;
pika_bool is_exit = pika_false;
pika_bool is_first_line = pika_true;
while (1) {
input[1] = input[0];
input[0] = cfg->fn_getchar();
@ -1810,7 +1810,7 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
}
if (is_first_line) {
if ('\n' == input[0]) {
is_first_line = PIKA_FALSE;
is_first_line = pika_false;
}
continue;
}
@ -1842,7 +1842,7 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
pika_platform_printf("=============== [ Run] ===============\r\n");
obj_run(self, (char*)buff);
if (NULL != strstr(buff, "exit()")) {
is_exit = PIKA_TRUE;
is_exit = pika_true;
}
pikaFree(buff, PIKA_READ_FILE_BUFF_SIZE);
if (is_exit) {
@ -2004,7 +2004,7 @@ void method_returnInt(Args* args, int64_t val) {
args_pushArg_name(args, "@rt", arg_newInt(val));
}
void method_returnBool(Args* args, PIKA_BOOL val) {
void method_returnBool(Args* args, pika_bool val) {
if (val == _PIKA_BOOL_ERR) {
return;
}
@ -2225,26 +2225,26 @@ int _pikaGC_markDumpHandler(PikaGC* gc) {
#endif
PIKA_BOOL obj_checkAlive(PikaObj* self) {
pika_bool obj_checkAlive(PikaObj* self) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return PIKA_TRUE;
return pika_true;
#else
PIKA_BOOL ret = PIKA_FALSE;
pika_bool ret = pika_false;
if (NULL == g_PikaObjState.gcChain) {
ret = PIKA_FALSE;
ret = pika_false;
goto __exit;
}
PikaObj* obj = g_PikaObjState.gcChain;
while (NULL != obj) {
if (obj == self) {
ret = PIKA_TRUE;
ret = pika_true;
goto __exit;
}
obj = obj->gcNext;
}
__exit:
#if PIKA_KERNAL_DEBUG_ENABLE
if (ret == PIKA_TRUE) {
if (ret == pika_true) {
self->isAlive = ret;
}
#endif
@ -2358,9 +2358,9 @@ void pikaGC_unlock(void) {
#endif
}
PIKA_BOOL pikaGC_islock(void) {
pika_bool pikaGC_islock(void) {
#if !PIKA_GC_MARK_SWEEP_ENABLE
return PIKA_FALSE;
return pika_false;
#else
return g_PikaObjState.markSweepBusy > 0;
#endif
@ -2381,7 +2381,7 @@ PikaObj* New_PikaObj(void) {
self->aName = NULL;
self->name = "PikaObj";
self->parent = NULL;
self->isAlive = PIKA_TRUE;
self->isAlive = pika_true;
#endif
#if PIKA_GC_MARK_SWEEP_ENABLE && PIKA_KERNAL_DEBUG_ENABLE
self->gcRoot = NULL;
@ -2456,7 +2456,7 @@ PikaObj* obj_importModuleWithByteCode(PikaObj* self,
Arg* aModule = obj_getArg((PikaObj*)__pikaMain, name);
PikaObj* oModule = arg_getPtr(aModule);
obj_setArg(self, name, aModule);
arg_setIsWeakRef(obj_getArg(self, name), PIKA_TRUE);
arg_setIsWeakRef(obj_getArg(self, name), pika_true);
pika_assert(arg_isObject(aModule));
/* decrase refcnt to avoid circle reference */
obj_refcntDec(oModule);
@ -2668,7 +2668,7 @@ static void _thread_event(void* arg) {
void _do_pks_eventListener_send(PikaEventListener* self,
uint32_t eventId,
Arg* eventData,
PIKA_BOOL pickupWhenNoVM) {
pika_bool pickupWhenNoVM) {
#if !PIKA_EVENT_ENABLE
pika_platform_printf("PIKA_EVENT_ENABLE is not enable");
while (1) {
@ -2704,7 +2704,7 @@ void _do_pks_eventListener_send(PikaEventListener* self,
void pks_eventListener_send(PikaEventListener* self,
uint32_t eventId,
Arg* eventData) {
_do_pks_eventListener_send(self, eventId, eventData, PIKA_TRUE);
_do_pks_eventListener_send(self, eventId, eventData, pika_true);
}
void pks_eventListener_sendSignal(PikaEventListener* self,

View File

@ -89,8 +89,8 @@ struct PikaObj {
char* name;
Arg* aName;
PikaObj* parent;
PIKA_BOOL isAlive;
PIKA_BOOL isGCRoot;
pika_bool isAlive;
pika_bool isGCRoot;
#endif
#if PIKA_GC_MARK_SWEEP_ENABLE && PIKA_KERNAL_DEBUG_ENABLE
PikaObj* gcRoot;
@ -118,7 +118,7 @@ struct RangeData {
typedef struct PikaObjState PikaObjState;
struct PikaObjState {
Arg* helpModulesCmodule;
PIKA_BOOL inRootObj;
pika_bool inRootObj;
#if PIKA_GC_MARK_SWEEP_ENABLE
PikaObj* gcChain;
uint32_t objCnt;
@ -153,7 +153,7 @@ static inline void obj_setFlag(PikaObj* self, uint16_t flag) {
self->flag |= flag;
#if PIKA_KERNAL_DEBUG_ENABLE
if (flag == OBJ_FLAG_GC_ROOT) {
self->isGCRoot = PIKA_TRUE;
self->isGCRoot = pika_true;
}
#endif
}
@ -162,7 +162,7 @@ static inline void obj_clearFlag(PikaObj* self, uint16_t flag) {
self->flag &= ~flag;
#if PIKA_KERNAL_DEBUG_ENABLE
if (flag == OBJ_FLAG_GC_ROOT) {
self->isGCRoot = PIKA_FALSE;
self->isGCRoot = pika_false;
}
#endif
}
@ -227,7 +227,7 @@ void* obj_getPtr(PikaObj* self, char* argPath);
pika_float obj_getFloat(PikaObj* self, char* argPath);
char* obj_getStr(PikaObj* self, char* argPath);
int64_t obj_getInt(PikaObj* self, char* argPath);
PIKA_BOOL obj_getBool(PikaObj* self, char* argPath);
pika_bool obj_getBool(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);
@ -244,7 +244,7 @@ PikaObj* obj_getObj(PikaObj* self, char* objPath);
PikaObj* obj_getHostObj(PikaObj* self, char* objPath);
PikaObj* obj_getHostObjWithIsTemp(PikaObj* self,
char* objPath,
PIKA_BOOL* pIsClass);
pika_bool* pIsClass);
// subProcess
int32_t obj_freeObj(PikaObj* self, char* subObjectName);
@ -308,7 +308,7 @@ uint8_t obj_getAnyArg(PikaObj* self,
void method_returnStr(Args* args, char* val);
void method_returnInt(Args* args, int64_t val);
void method_returnBool(Args* args, PIKA_BOOL val);
void method_returnBool(Args* args, pika_bool val);
void method_returnFloat(Args* args, pika_float val);
void method_returnPtr(Args* args, void* val);
void method_returnObj(Args* args, void* val);
@ -351,7 +351,7 @@ typedef struct FilterFIFO {
typedef struct FilterItem FilterItem;
typedef PIKA_BOOL FilterMessageHandler(FilterItem* msg,
typedef pika_bool FilterMessageHandler(FilterItem* msg,
PikaObj* self,
ShellConfig* shell);
@ -391,7 +391,7 @@ struct ShellConfig {
size_t line_position;
size_t line_curpos;
char* blockBuffName;
PIKA_BOOL inBlock;
pika_bool inBlock;
char lastChar;
sh_getchar fn_getchar;
uint8_t stat;
@ -514,7 +514,7 @@ void pks_eventListener_removeEvent(PikaEventListener* self, uint32_t eventId);
void _do_pks_eventListener_send(PikaEventListener* self,
uint32_t eventId,
Arg* eventData,
PIKA_BOOL pickupWhenNoVM);
pika_bool pickupWhenNoVM);
void pks_eventListener_sendSignal(PikaEventListener* self,
uint32_t eventId,
@ -560,7 +560,7 @@ static inline uint8_t obj_refcntNow(PikaObj* self) {
__FUNCTION__)
char* obj_cacheStr(PikaObj* self, char* str);
PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp);
PikaObj* _arg_to_obj(Arg* self, pika_bool* pIsTemp);
Arg* arg_toStrArg(Arg* arg);
#define PIKASCRIPT_VERSION_TO_NUM(majer, minor, micro) \
@ -716,14 +716,14 @@ void obj_printModules(PikaObj* self);
void obj_appendGcChain(PikaObj* self);
void obj_removeGcChain(PikaObj* self);
void obj_enableGC(PikaObj* self);
PIKA_BOOL obj_checkAlive(PikaObj* self);
pika_bool obj_checkAlive(PikaObj* self);
void obj_setName(PikaObj* self, char* name);
void pikaGC_mark(void);
void pikaGC_markDump(void);
void pikaGC_lock(void);
void pikaGC_unlock(void);
PIKA_BOOL pikaGC_islock(void);
pika_bool pikaGC_islock(void);
uint32_t pikaGC_count(void);
uint32_t pikaGC_countMarked(void);
uint32_t pikaGC_markSweep(void);

View File

@ -55,7 +55,7 @@ void Cursor_deinit(struct Cursor* cs);
/* Cursor high level api */
char* Cursor_popToken(Args* buffs, char** pStmt, char* devide);
PIKA_BOOL Cursor_isContain(char* stmt, TokenType type, char* pyload);
pika_bool Cursor_isContain(char* stmt, TokenType type, char* pyload);
char* Cursor_splitCollect(Args* buffs, char* stmt, char* devide, int index);
char* pika_lines2Asm(Args* outBuffs, char* multiLine);
@ -179,22 +179,22 @@ static enum StmtType Lexer_matchStmtType(char* right) {
enum StmtType stmtType = STMT_none;
char* rightWithoutSubStmt = _remove_sub_stmt(&buffs, right);
PIKA_BOOL is_get_operator = PIKA_FALSE;
PIKA_BOOL is_get_method = PIKA_FALSE;
PIKA_BOOL is_get_string = PIKA_FALSE;
PIKA_BOOL is_get_bytes = PIKA_FALSE;
PIKA_BOOL is_get_number = PIKA_FALSE;
PIKA_BOOL is_get_symbol = PIKA_FALSE;
PIKA_BOOL is_get_list = PIKA_FALSE;
PIKA_BOOL is_get_slice = PIKA_FALSE;
PIKA_BOOL is_get_dict = PIKA_FALSE;
PIKA_BOOL is_get_import = PIKA_FALSE;
PIKA_BOOL is_get_chain = PIKA_FALSE;
pika_bool is_get_operator = pika_false;
pika_bool is_get_method = pika_false;
pika_bool is_get_string = pika_false;
pika_bool is_get_bytes = pika_false;
pika_bool is_get_number = pika_false;
pika_bool is_get_symbol = pika_false;
pika_bool is_get_list = pika_false;
pika_bool is_get_slice = pika_false;
pika_bool is_get_dict = pika_false;
pika_bool is_get_import = pika_false;
pika_bool is_get_chain = pika_false;
Cursor_forEach(cs, rightWithoutSubStmt) {
Cursor_iterStart(&cs);
/* collect type */
if (strEqu(cs.token1.pyload, " import ")) {
is_get_import = PIKA_TRUE;
is_get_import = pika_true;
goto iter_continue;
}
if (strEqu(cs.token2.pyload, "[")) {
@ -204,17 +204,17 @@ static enum StmtType Lexer_matchStmtType(char* right) {
strEqu(cs.token1.pyload, "]") ||
strEqu(cs.token1.pyload, ")")) {
/* keep the last one of the chain or slice */
is_get_slice = PIKA_TRUE;
is_get_chain = PIKA_FALSE;
is_get_slice = pika_true;
is_get_chain = pika_false;
goto iter_continue;
}
/* ( <,> | <=> ) + <[> */
is_get_list = PIKA_TRUE;
is_get_list = pika_true;
}
if (strEqu(cs.token1.pyload, "[") && cs.iter_index == 1) {
/* VOID + <[> */
is_get_list = PIKA_TRUE;
is_get_method = PIKA_FALSE;
is_get_list = pika_true;
is_get_method = pika_false;
goto iter_continue;
}
if (strEqu(cs.token1.pyload, "...")) {
@ -228,41 +228,41 @@ static enum StmtType Lexer_matchStmtType(char* right) {
if (strIsStartWith(cs.token1.pyload, ".")) {
if (cs.iter_index != 1) {
/* keep the last one of the chain or slice */
is_get_chain = PIKA_TRUE;
is_get_slice = PIKA_FALSE;
is_get_chain = pika_true;
is_get_slice = pika_false;
goto iter_continue;
}
}
if (strEqu(cs.token1.pyload, "{")) {
is_get_dict = PIKA_TRUE;
is_get_dict = pika_true;
goto iter_continue;
}
if (cs.token1.type == TOKEN_operator) {
is_get_operator = PIKA_TRUE;
is_get_operator = pika_true;
goto iter_continue;
}
/* <(> */
if (strEqu(cs.token1.pyload, "(")) {
is_get_method = PIKA_TRUE;
is_get_slice = PIKA_FALSE;
is_get_method = pika_true;
is_get_slice = pika_false;
goto iter_continue;
}
if (cs.token1.type == TOKEN_literal) {
if (cs.token1.pyload[0] == '\'' || cs.token1.pyload[0] == '"') {
is_get_string = PIKA_TRUE;
is_get_string = pika_true;
goto iter_continue;
}
if (cs.token1.pyload[1] == '\'' || cs.token1.pyload[1] == '"') {
if (cs.token1.pyload[0] == 'b') {
is_get_bytes = PIKA_TRUE;
is_get_bytes = pika_true;
goto iter_continue;
}
}
is_get_number = PIKA_TRUE;
is_get_number = pika_true;
goto iter_continue;
}
if (cs.token1.type == TOKEN_symbol) {
is_get_symbol = PIKA_TRUE;
is_get_symbol = pika_true;
goto iter_continue;
}
iter_continue:
@ -978,24 +978,24 @@ void _Cursor_beforeIter(struct Cursor* cs) {
uint8_t Token_isBranketStart(LexToken* token) {
if (token->type != TOKEN_devider) {
return PIKA_FALSE;
return pika_false;
}
if (strEqu(token->pyload, "(") || strEqu(token->pyload, "[") ||
strEqu(token->pyload, "{")) {
return PIKA_TRUE;
return pika_true;
}
return PIKA_FALSE;
return pika_false;
}
uint8_t Token_isBranketEnd(LexToken* token) {
if (token->type != TOKEN_devider) {
return PIKA_FALSE;
return pika_false;
}
if (strEqu(token->pyload, ")") || strEqu(token->pyload, "]") ||
strEqu(token->pyload, "}")) {
return PIKA_TRUE;
return pika_true;
}
return PIKA_FALSE;
return pika_false;
}
uint8_t Token_isBranket(LexToken* token) {
@ -1005,10 +1005,10 @@ uint8_t Token_isBranket(LexToken* token) {
uint8_t _Cursor_count(char* stmt,
TokenType type,
char* pyload,
PIKA_BOOL bSkipbracket) {
pika_bool bSkipbracket) {
/* fast return */
if (!strstr(stmt, pyload)) {
return PIKA_FALSE;
return pika_false;
}
Args buffs = {0};
uint8_t res = 0;
@ -1036,26 +1036,26 @@ uint8_t _Cursor_count(char* stmt,
}
uint8_t Cursor_count(char* stmt, TokenType type, char* pyload) {
return _Cursor_count(stmt, type, pyload, PIKA_FALSE);
return _Cursor_count(stmt, type, pyload, pika_false);
}
PIKA_BOOL Cursor_isContain(char* stmt, TokenType type, char* pyload) {
pika_bool Cursor_isContain(char* stmt, TokenType type, char* pyload) {
if (Cursor_count(stmt, type, pyload) > 0) {
return PIKA_TRUE;
return pika_true;
}
return PIKA_FALSE;
return pika_false;
}
char* Cursor_popToken(Args* buffs, char** pStmt, char* devide) {
Arg* out_item = arg_newStr("");
Arg* tokenStream_after = arg_newStr("");
PIKA_BOOL is_find_devide = PIKA_FALSE;
pika_bool is_find_devide = pika_false;
Cursor_forEach(cs, *pStmt) {
Cursor_iterStart(&cs);
if (!is_find_devide) {
if ((cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, devide)) ||
cs.iter_index == cs.length) {
is_find_devide = PIKA_TRUE;
is_find_devide = pika_true;
Cursor_iterEnd(&cs);
continue;
}
@ -1282,31 +1282,31 @@ char* Suger_format(Args* outBuffs, char* right) {
return right;
}
PIKA_BOOL is_format = PIKA_FALSE;
pika_bool is_format = pika_false;
Cursor_forEach(ps1, right) {
Cursor_iterStart(&ps1);
if (ps1.bracket_deepth == 0 && strEqu(ps1.token1.pyload, "%")) {
is_format = PIKA_TRUE;
is_format = pika_true;
}
Cursor_iterEnd(&ps1);
}
Cursor_deinit(&ps1);
if (PIKA_FALSE == is_format) {
if (pika_false == is_format) {
return right;
}
char* res = right;
Arg* str_buf = arg_newStr("");
Arg* var_buf = arg_newStr("");
PIKA_BOOL is_in_format = PIKA_FALSE;
PIKA_BOOL is_tuple = PIKA_FALSE;
PIKA_BOOL is_out_vars = PIKA_FALSE;
pika_bool is_in_format = pika_false;
pika_bool is_tuple = pika_false;
pika_bool is_out_vars = pika_false;
Args buffs = {0};
char* fmt = NULL;
Cursor_forEach(cs, right) {
char* item = "";
Cursor_iterStart(&cs);
if (PIKA_FALSE == is_in_format) {
if (pika_false == is_in_format) {
if (cs.token1.type != TOKEN_literal) {
item = cs.token1.pyload;
goto iter_continue;
@ -1320,16 +1320,16 @@ char* Suger_format(Args* outBuffs, char* right) {
goto iter_continue;
}
/* found the format stmt */
is_in_format = PIKA_TRUE;
is_in_format = pika_true;
fmt = strsCopy(&buffs, cs.token1.pyload);
goto iter_continue;
}
if (PIKA_TRUE == is_in_format) {
if (pika_true == is_in_format) {
/* check the format vars */
if (strEqu(cs.token1.pyload, "%")) {
/* is a tuple */
if (strEqu(cs.token2.pyload, "(")) {
is_tuple = PIKA_TRUE;
is_tuple = pika_true;
} else {
var_buf = arg_strAppend(var_buf, cs.token2.pyload);
}
@ -1337,8 +1337,8 @@ char* Suger_format(Args* outBuffs, char* right) {
}
/* found the end of tuple */
if (cs.iter_index == cs.length) {
is_out_vars = PIKA_TRUE;
is_in_format = PIKA_FALSE;
is_out_vars = pika_true;
is_in_format = pika_false;
} else {
/* push the vars inner the tuple */
var_buf = arg_strAppend(var_buf, cs.token2.pyload);
@ -1476,7 +1476,7 @@ char* Parser_popSubStmt(Args* outbuffs, char** psStmt, char* delimiter) {
Arg* aSubstmt = arg_newStr("");
Arg* aNewStmt = arg_newStr("");
char* sStmt = *psStmt;
PIKA_BOOL bIsGetSubstmt = PIKA_FALSE;
pika_bool bIsGetSubstmt = pika_false;
Args buffs = {0};
Cursor_forEach(cs, sStmt) {
Cursor_iterStart(&cs);
@ -1494,7 +1494,7 @@ char* Parser_popSubStmt(Args* outbuffs, char** psStmt, char* delimiter) {
}
if (strEqu(cs.token1.pyload, delimiter)) {
/* found delimiter */
bIsGetSubstmt = PIKA_TRUE;
bIsGetSubstmt = pika_true;
Cursor_iterEnd(&cs);
continue;
}
@ -1516,13 +1516,13 @@ int Parser_getSubStmtNum(char* subStmts, char* delimiter) {
if (strEqu(subStmts, ",")) {
return 0;
}
return _Cursor_count(subStmts, TOKEN_devider, delimiter, PIKA_TRUE);
return _Cursor_count(subStmts, TOKEN_devider, delimiter, pika_true);
}
char* _Parser_popLastSubStmt(Args* outbuffs,
char** stmt_p,
char* delimiter,
PIKA_BOOL bSkipBracket) {
pika_bool bSkipBracket) {
uint8_t last_stmt_i = 0;
char* stmt = *stmt_p;
Cursor_forEach(cs, stmt) {
@ -1570,7 +1570,7 @@ char* _Parser_popLastSubStmt(Args* outbuffs,
}
char* Parser_popLastSubStmt(Args* outbuffs, char** stmt_p, char* delimiter) {
return _Parser_popLastSubStmt(outbuffs, stmt_p, delimiter, PIKA_TRUE);
return _Parser_popLastSubStmt(outbuffs, stmt_p, delimiter, pika_true);
}
static void _AST_parse_list(AST* ast, Args* buffs, char* stmt) {
@ -1615,7 +1615,7 @@ static void _AST_parse_slice(AST* ast, Args* buffs, char* stmt) {
#endif
AST_setNodeAttr(ast, (char*)"slice", "slice");
stmt = strsCopy(buffs, stmt);
char* laststmt = _Parser_popLastSubStmt(buffs, &stmt, "[", PIKA_FALSE);
char* laststmt = _Parser_popLastSubStmt(buffs, &stmt, "[", pika_false);
AST_parseSubStmt(ast, stmt);
char* slice_list = strsCut(buffs, laststmt, '[', ']');
pika_assert(slice_list != NULL);
@ -1645,8 +1645,8 @@ char* _Suger_process(Args* out_buffs,
char* ret = line;
char* stmt1 = "";
char* stmt2 = "";
PIKA_BOOL got_tokens = PIKA_FALSE;
PIKA_BOOL skip = PIKA_FALSE;
pika_bool got_tokens = pika_false;
pika_bool skip = pika_false;
Args buffs = {0};
if (1 != Cursor_count(line, TOKEN_operator, token1)) {
@ -1663,14 +1663,14 @@ char* _Suger_process(Args* out_buffs,
if (!got_tokens) {
if (strEqu(cs.token1.pyload, token1) &&
strEqu(cs.token2.pyload, token2)) {
got_tokens = PIKA_TRUE;
got_tokens = pika_true;
Cursor_iterEnd(&cs);
continue;
}
stmt1 = strsAppend(&buffs, stmt1, cs.token1.pyload);
} else {
if (!skip) {
skip = PIKA_TRUE;
skip = pika_true;
Cursor_iterEnd(&cs);
continue;
}
@ -1821,13 +1821,13 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
char* laststmt = methodstmt;
/* for method()() */
int iBracketNum =
_Cursor_count(methodstmt, TOKEN_devider, "(", PIKA_TRUE) +
_Cursor_count(methodstmt, TOKEN_devider, "[", PIKA_TRUE);
_Cursor_count(methodstmt, TOKEN_devider, "(", pika_true) +
_Cursor_count(methodstmt, TOKEN_devider, "[", pika_true);
if (iBracketNum > 1) {
laststmt =
_Parser_popLastSubStmt(&buffs, &methodstmt, "(", PIKA_FALSE);
_Parser_popLastSubStmt(&buffs, &methodstmt, "(", pika_false);
/* for (...) */
if (_Cursor_count(laststmt, TOKEN_devider, "(", PIKA_FALSE) == 1) {
if (_Cursor_count(laststmt, TOKEN_devider, "(", pika_false) == 1) {
char* sMethodCheck = strsGetFirstToken(&buffs, laststmt, '(');
if (strEqu(sMethodCheck, "")) {
laststmt = strsAppend(&buffs, ".", laststmt);
@ -1993,7 +1993,7 @@ char* _defGetDefault(Args* outBuffs, char** psDeclearOut) {
char* sArgList = strsCut(&buffs, sDeclear, '(', ')');
char* sDefaultOut = NULL;
pika_assert(NULL != sArgList);
int iArgNum = _Cursor_count(sArgList, TOKEN_devider, ",", PIKA_TRUE) + 1;
int iArgNum = _Cursor_count(sArgList, TOKEN_devider, ",", pika_true) + 1;
for (int i = 0; i < iArgNum; i++) {
char* sItem = Cursor_popToken(&buffs, &sArgList, ",");
char* sDefaultVal = NULL;
@ -2360,15 +2360,15 @@ exit:
return strsReturnOut(&buffs, out_buffs, line_out);
}
static PIKA_BOOL _check_is_multi_assign(char* arg_list) {
static pika_bool _check_is_multi_assign(char* arg_list) {
#if PIKA_NANO_ENABLE
return PIKA_FALSE;
return pika_false;
#endif
PIKA_BOOL res = PIKA_FALSE;
pika_bool res = pika_false;
Cursor_forEach(cs, arg_list) {
Cursor_iterStart(&cs);
if ((cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, ","))) {
res = PIKA_TRUE;
res = pika_true;
}
Cursor_iterEnd(&cs);
}
@ -2383,7 +2383,7 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) {
Args buffs = {0};
char* line_out = line;
int space_num = _getSpaceNum(line);
PIKA_BOOL is_assign = PIKA_FALSE;
pika_bool is_assign = pika_false;
Arg* stmt = arg_newStr("");
Arg* out_list = arg_newStr("");
Arg* out_item = arg_newStr("");
@ -2394,7 +2394,7 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) {
Cursor_forEach(cs, line) {
Cursor_iterStart(&cs);
if (cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, "=")) {
is_assign = PIKA_TRUE;
is_assign = pika_true;
Cursor_iterEnd(&cs);
continue;
}
@ -2874,7 +2874,7 @@ PIKA_RES pika_lines2Bytes(ByteCodeFrame* bf, char* py_lines) {
return PIKA_RES_ERR_SYNTAX_ERROR;
#else
Parser* parser = New_parser();
parser->isGenBytecode = PIKA_TRUE;
parser->isGenBytecode = pika_true;
parser->bytecode_frame = bf;
if (1 == (uintptr_t)parser_lines2BackendCode(parser, py_lines)) {
parser_deinit(parser);
@ -2887,7 +2887,7 @@ PIKA_RES pika_lines2Bytes(ByteCodeFrame* bf, char* py_lines) {
char* pika_lines2Asm(Args* outBuffs, char* multi_line) {
Parser* parser = New_parser();
parser->isGenBytecode = PIKA_FALSE;
parser->isGenBytecode = pika_false;
char* sAsm = parser_lines2BackendCode(parser, multi_line);
if (NULL == sAsm) {
parser_deinit(parser);
@ -3245,7 +3245,7 @@ char* AST_genAsm(AST* oAST, Args* outBuffs) {
#if !PIKA_NANO_ENABLE
if (NULL != sDefaultStmts) {
int iStmtNum =
_Cursor_count(sDefaultStmts, TOKEN_devider, ",", PIKA_TRUE) + 1;
_Cursor_count(sDefaultStmts, TOKEN_devider, ",", pika_true) + 1;
for (int i = 0; i < iStmtNum; i++) {
char* sStmt = Cursor_popToken(&buffs, &sDefaultStmts, ",");
char* sArgName = strsGetFirstToken(&buffs, sStmt, '=');
@ -3341,8 +3341,8 @@ exit:
}
#define IS_SPACE_OR_TAB(ch) ((ch) == ' ' || (ch) == '\t')
static PIKA_BOOL _strCheckCodeBlockFlag(char* sLine) {
PIKA_BOOL bStart = PIKA_FALSE, bEnd = PIKA_FALSE;
static pika_bool _strCheckCodeBlockFlag(char* sLine) {
pika_bool bStart = pika_false, bEnd = pika_false;
char *pStart = sLine, *pEnd = sLine + strlen(sLine) - 1;
while (pStart <= pEnd && IS_SPACE_OR_TAB(*pStart)) {
pStart++;
@ -3351,21 +3351,21 @@ static PIKA_BOOL _strCheckCodeBlockFlag(char* sLine) {
pEnd--;
}
if (pEnd - pStart < 2) {
return PIKA_FALSE;
return pika_false;
}
if (strncmp(pStart, "```", 3) == 0) {
bStart = PIKA_TRUE;
bStart = pika_true;
}
if (pEnd - pStart >= 5 && strncmp(pEnd - 2, "```", 3) == 0) {
bEnd = PIKA_TRUE;
bEnd = pika_true;
}
if (bStart && bEnd) {
return PIKA_FALSE;
return pika_false;
}
if (bStart || bEnd) {
return PIKA_TRUE;
return pika_true;
}
return PIKA_FALSE;
return pika_false;
}
static char* _parser_fixDocStringIndent(Parser* self,
@ -3376,7 +3376,7 @@ static char* _parser_fixDocStringIndent(Parser* self,
Arg* aOut = arg_newStr("");
char* sOut = NULL;
uint32_t iLineNum = strCountSign(sBuff, '\n');
PIKA_BOOL bInCodeBlock = PIKA_FALSE;
pika_bool bInCodeBlock = pika_false;
int iIndentCodeBlock = 0;
for (int i = 0; i < iLineNum; i++) {
char* sLine = strsPopToken(&buffs, &sBuff, '\n');
@ -3385,7 +3385,7 @@ static char* _parser_fixDocStringIndent(Parser* self,
}
int iIndentThis = strGetIndent(sLine);
int iIndentStrip = iIndentThis;
PIKA_BOOL bCodeBlockFlag = _strCheckCodeBlockFlag(sLine);
pika_bool bCodeBlockFlag = _strCheckCodeBlockFlag(sLine);
if (bCodeBlockFlag) {
bInCodeBlock = !bInCodeBlock;
iIndentCodeBlock = iIndentStrip;

View File

@ -95,7 +95,7 @@ struct Parser {
Args genBuffs;
BlockState blockState;
fn_parser_Ast2BeckendCode fn_ast2BeckendCode;
PIKA_BOOL isGenBytecode;
pika_bool isGenBytecode;
ByteCodeFrame* bytecode_frame;
uint8_t thisBlockDeepth;
};
@ -148,7 +148,7 @@ uint8_t Cursor_count(char* stmt, TokenType type, char* pyload);
uint8_t _Cursor_count(char* stmt,
TokenType type,
char* pyload,
PIKA_BOOL bSkipbracket);
pika_bool bSkipbracket);
AST* AST_parseStmt(AST* ast, char* stmt);
char* AST_genAsm(AST* oAST, Args* outBuffs);

View File

@ -159,17 +159,17 @@ int pika_pvsprintf(char** buff, const char* fmt, va_list args) {
return required_size;
}
static PIKA_BOOL _check_no_buff_format(char* format) {
static pika_bool _check_no_buff_format(char* format) {
while (*format) {
if (*format == '%') {
++format;
if (*format != 's' && *format != '%') {
return PIKA_FALSE;
return pika_false;
}
}
++format;
}
return PIKA_TRUE;
return pika_true;
}
static int _no_buff_vprintf(char* fmt, va_list args) {
@ -379,8 +379,8 @@ PIKA_WEAK void pika_hook_instruct(void) {
return;
}
PIKA_WEAK PIKA_BOOL pika_hook_arg_cache_filter(void* self) {
return PIKA_TRUE;
PIKA_WEAK pika_bool pika_hook_arg_cache_filter(void* self) {
return pika_true;
}
PIKA_WEAK void pika_platform_thread_delay(void) {

View File

@ -111,9 +111,10 @@ typedef enum {
/* clang-format off */
/* pikascript bool type */
#define PIKA_BOOL int64_t
#define PIKA_TRUE 1
#define PIKA_FALSE 0
#define pika_bool int64_t
#define pika_true 1
#define pika_false 0
#define _PIKA_BOOL_ERR -1
#define _PIKA_INT_ERR (-999999999)
@ -190,7 +191,7 @@ int64_t pika_platform_get_tick(void);
void pika_platform_sleep_ms(uint32_t ms);
void pika_hook_instruct(void);
PIKA_BOOL pika_hook_arg_cache_filter(void* self);
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);

View File

@ -41,6 +41,7 @@ static pika_platform_thread_mutex_t g_pikaGIL = {0};
volatile VMSignal g_PikaVMSignal = {.signal_ctrl = VM_SIGNAL_CTRL_NONE,
.vm_cnt = 0,
.vm_now = NULL,
#if PIKA_EVENT_ENABLE
.cq =
{
@ -56,7 +57,7 @@ volatile VMSignal g_PikaVMSignal = {.signal_ctrl = VM_SIGNAL_CTRL_NONE,
extern volatile PikaObjState g_PikaObjState;
/* private */
static PIKA_BOOL _checkLReg(char* data);
static pika_bool _checkLReg(char* data);
static uint8_t _getLRegIndex(char* data);
static PikaObj* New_Locals(Args* args);
char* string_slice(Args* outBuffs, char* str, int start, int end);
@ -124,23 +125,23 @@ int _VMEvent_getEventPickupCnt(void) {
}
#if PIKA_EVENT_ENABLE
static PIKA_BOOL _ecq_isEmpty(volatile EventCQ* cq) {
return (PIKA_BOOL)(cq->head == cq->tail);
static pika_bool _ecq_isEmpty(volatile EventCQ* cq) {
return (pika_bool)(cq->head == cq->tail);
}
static PIKA_BOOL _ecq_isFull(volatile EventCQ* cq) {
return (PIKA_BOOL)((cq->tail + 1) % PIKA_EVENT_LIST_SIZE == cq->head);
static pika_bool _ecq_isFull(volatile EventCQ* cq) {
return (pika_bool)((cq->tail + 1) % PIKA_EVENT_LIST_SIZE == cq->head);
}
#endif
#if PIKA_SETJMP_ENABLE
static PIKA_BOOL _jcq_isEmpty(volatile JmpBufCQ* cq) {
return (PIKA_BOOL)(cq->head == cq->tail);
static pika_bool _jcq_isEmpty(volatile JmpBufCQ* cq) {
return (pika_bool)(cq->head == cq->tail);
}
static PIKA_BOOL _jcq_isFull(volatile JmpBufCQ* cq) {
return (PIKA_BOOL)((cq->tail + 1) % PIKA_JMP_BUF_LIST_SIZE == cq->head);
static pika_bool _jcq_isFull(volatile JmpBufCQ* cq) {
return (pika_bool)((cq->tail + 1) % PIKA_JMP_BUF_LIST_SIZE == cq->head);
}
static jmp_buf* _jcq_pop(volatile JmpBufCQ* cq) {
@ -296,7 +297,7 @@ void pks_vm_exit(void) {
g_PikaVMSignal.signal_ctrl = VM_SIGNAL_CTRL_EXIT;
}
void pks_vmSignal_setCtrlElear(void) {
void pks_vmSignal_setCtrlClear(void) {
g_PikaVMSignal.signal_ctrl = VM_SIGNAL_CTRL_NONE;
}
@ -554,16 +555,16 @@ static int arg_getLen(Arg* self) {
static void VMState_initReg(VMState* self) {
for (uint8_t i = 0; i < PIKA_REGIST_SIZE; i++) {
self->ireg[i] = PIKA_FALSE;
self->ireg[i] = pika_false;
}
}
static PIKA_BOOL _checkLReg(char* data) {
static pika_bool _checkLReg(char* data) {
if ((data[0] == '$') && (data[1] == 'l') && (data[2] >= '0') &&
(data[2] <= '9')) {
return PIKA_TRUE;
return pika_true;
}
return PIKA_FALSE;
return pika_false;
}
static uint8_t _getLRegIndex(char* data) {
@ -621,7 +622,7 @@ Arg* _vm_get(VMState* vm, PikaObj* self, Arg* aKey, Arg* aObj) {
if (ARG_TYPE_STRING == eType) {
#if PIKA_STRING_UTF8_ENABLE
PIKA_BOOL bIsTemp = PIKA_FALSE;
pika_bool bIsTemp = pika_false;
aObjNew = arg_newObj(_arg_to_obj(aObj, &bIsTemp));
eType = arg_getType(aObjNew);
#else
@ -667,7 +668,7 @@ Arg* _vm_get(VMState* vm, PikaObj* self, Arg* aKey, Arg* aObj) {
if (NULL != vm) {
aRes = _do_pikaVM_runByteCodeReturn(oArg, oArg, oArg,
(uint8_t*)bytes, vm->run_state,
PIKA_TRUE, "@res_item");
pika_true, "@res_item");
} else {
aRes = pikaVM_runByteCodeReturn(oArg, (uint8_t*)bytes, "@res_item");
}
@ -929,17 +930,17 @@ static Arg* VM_instruction_handler_REF(PikaObj* self,
PikaObj* oHost = NULL;
char* arg_path = data;
char* arg_name = strPointToLastToken(arg_path, '.');
PIKA_BOOL is_temp = PIKA_FALSE;
pika_bool is_temp = pika_false;
switch (data[0]) {
case 'T':
if (strEqu(arg_path, (char*)"True")) {
return arg_setBool(aRetReg, "", PIKA_TRUE);
return arg_setBool(aRetReg, "", pika_true);
}
break;
case 'F':
if (strEqu(arg_path, (char*)"False")) {
return arg_setBool(aRetReg, "", PIKA_FALSE);
return arg_setBool(aRetReg, "", pika_false);
}
break;
case 'N':
@ -1232,25 +1233,25 @@ static void _type_list_parse(FunctionArgsInfo* f) {
/* default */
if (iAssign > 0) {
iArgc -= iAssign;
f->is_default = PIKA_TRUE;
f->is_default = pika_true;
f->n_default = iAssign;
}
/* vars */
if (iStar == 1) {
f->is_vars = PIKA_TRUE;
f->is_vars = pika_true;
f->n_positional = iArgc - 1;
return;
}
/* kw */
if (iStar == 2) {
f->is_keys = PIKA_TRUE;
f->is_keys = pika_true;
f->n_positional = iArgc - 1;
return;
}
/* vars and kw */
if (iStar == 3) {
f->is_vars = PIKA_TRUE;
f->is_keys = PIKA_TRUE;
f->is_vars = pika_true;
f->is_keys = pika_true;
f->n_positional = iArgc - 2;
return;
}
@ -1265,7 +1266,7 @@ static void _kw_push(FunctionArgsInfo* f, Arg* call_arg, int i) {
if (NULL == f->kw_keys) {
f->kw_keys = New_pikaDict();
}
arg_setIsKeyword(call_arg, PIKA_FALSE);
arg_setIsKeyword(call_arg, pika_false);
pikaDict_setArg(f->kw, call_arg);
char kw_keys_index_buff[11] = {0};
char* kw_keys_index = fast_itoa(kw_keys_index_buff, i);
@ -1383,13 +1384,13 @@ static int _get_n_input_with_unpack(VMState* vm, int n_used) {
pika_assert(obj->constructor == New_PikaStdData_Dict);
PikaDict* dict = obj_getPtr(obj, "dict");
int i_item = 0;
while (PIKA_TRUE) {
while (pika_true) {
Arg* item_val = args_getArgByIndex(&dict->super, i_item);
if (NULL == item_val) {
break;
}
/* unpack as keyword arg */
arg_setIsKeyword(item_val, PIKA_TRUE);
arg_setIsKeyword(item_val, pika_true);
stack_pushArg(&stack_tmp, arg_copy(item_val));
i_item++;
}
@ -1629,7 +1630,7 @@ PikaObj* New_PikaStdData_Tuple(Args* args);
static Arg* _vm_create_list_or_tuple(PikaObj* self,
VMState* vm,
PIKA_BOOL is_list) {
pika_bool is_list) {
#if PIKA_BUILTIN_STRUCT_ENABLE
NewFun constructor = is_list ? New_PikaStdData_List : New_PikaStdData_Tuple;
uint8_t n_arg = VMState_getInputArgNum(vm);
@ -1660,14 +1661,14 @@ static Arg* VM_instruction_handler_LST(PikaObj* self,
VMState* vm,
char* data,
Arg* arg_ret_reg) {
return _vm_create_list_or_tuple(self, vm, PIKA_TRUE);
return _vm_create_list_or_tuple(self, vm, pika_true);
}
static Arg* VM_instruction_handler_TPL(PikaObj* self,
VMState* vm,
char* data,
Arg* arg_ret_reg) {
return _vm_create_list_or_tuple(self, vm, PIKA_FALSE);
return _vm_create_list_or_tuple(self, vm, pika_false);
}
void __vm_Dict___init__(PikaObj* self) {
@ -1734,40 +1735,40 @@ static Arg* VM_instruction_handler_RET(PikaObj* self,
}
static InstructUnit* _find_instruct_unit(ByteCodeFrame* bcframe,
int32_t pc_start,
int32_t iPcStart,
enum InstructIndex index,
int32_t* p_offset,
PIKA_BOOL search_upwards) {
int32_t* iOffset_p,
pika_bool bIsForward) {
/* find instruct unit */
int instructArray_size = instructArray_getSize(&(bcframe->instruct_array));
while (1) {
*p_offset += (search_upwards ? -1 : 1) * instructUnit_getSize();
if (pc_start + *p_offset >= instructArray_size) {
*iOffset_p += (bIsForward ? -1 : 1) * instructUnit_getSize();
if (iPcStart + *iOffset_p >= instructArray_size) {
return NULL;
}
if (pc_start + *p_offset < 0) {
if (iPcStart + *iOffset_p < 0) {
return NULL;
}
InstructUnit* unit = instructArray_getByOffset(
&(bcframe->instruct_array), pc_start + *p_offset);
&(bcframe->instruct_array), iPcStart + *iOffset_p);
if (index == instructUnit_getInstructIndex(unit)) {
return unit;
}
}
}
static InstructUnit* _find_ins_unit_up(ByteCodeFrame* bcframe,
static InstructUnit* _find_ins_unit_forward(ByteCodeFrame* bcframe,
int32_t pc_start,
enum InstructIndex index,
int32_t* p_offset) {
return _find_instruct_unit(bcframe, pc_start, index, p_offset, PIKA_TRUE);
return _find_instruct_unit(bcframe, pc_start, index, p_offset, pika_true);
}
static InstructUnit* _find_ins_unit_down(ByteCodeFrame* bcframe,
static InstructUnit* _find_ins_unit_backward(ByteCodeFrame* bcframe,
int32_t pc_start,
enum InstructIndex index,
int32_t* p_offset) {
return _find_instruct_unit(bcframe, pc_start, index, p_offset, PIKA_FALSE);
return _find_instruct_unit(bcframe, pc_start, index, p_offset, pika_false);
}
#if !PIKA_NANO_ENABLE
@ -1775,9 +1776,9 @@ static char* _find_super_class_name(ByteCodeFrame* bcframe, int32_t pc_start) {
/* find super class */
int offset = 0;
char* super_class_name = NULL;
_find_ins_unit_up(bcframe, pc_start, CLS, &offset);
_find_ins_unit_forward(bcframe, pc_start, CLS, &offset);
InstructUnit* unit_run =
_find_ins_unit_down(bcframe, pc_start, RUN, &offset);
_find_ins_unit_backward(bcframe, pc_start, RUN, &offset);
super_class_name = constPool_getByOffset(
&(bcframe->const_pool), instructUnit_getConstPoolIndex(unit_run));
return super_class_name;
@ -1827,8 +1828,8 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
PikaObj* oThis = NULL;
Arg* aMethod = NULL;
Arg* aStack = NULL;
PIKA_BOOL bIsTemp = PIKA_FALSE;
PIKA_BOOL bSkipInit = PIKA_FALSE;
pika_bool bIsTemp = pika_false;
pika_bool bSkipInit = pika_false;
char* sSysOut;
int iNumUsed = 0;
arg_newReg(arg_reg1, 32);
@ -1844,7 +1845,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
if (vm->pc - 2 * (int)instructUnit_getSize() >= 0) {
if (CLS == VMstate_getInstructWithOffset(
vm, -2 * (int)instructUnit_getSize())) {
bSkipInit = PIKA_TRUE;
bSkipInit = pika_true;
}
}
@ -1856,7 +1857,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
goto exit;
}
/* create a tuple */
aReturn = _vm_create_list_or_tuple(self, vm, PIKA_FALSE);
aReturn = _vm_create_list_or_tuple(self, vm, pika_false);
goto exit;
}
@ -1865,9 +1866,9 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
if (strEqu(sRunPath, "super")) {
sRunPath = _find_super_class_name(vm->bytecode_frame, vm->pc);
sArgName = strPointToLastToken(sRunPath, '.');
vm->in_super = PIKA_TRUE;
vm->in_super = pika_true;
vm->super_invoke_deepth = VMState_getInvokeDeepthNow(vm);
bSkipInit = PIKA_TRUE;
bSkipInit = pika_true;
}
#endif
@ -1951,7 +1952,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
#if !PIKA_NANO_ENABLE
if (!bSkipInit && vm->in_super &&
VMState_getInvokeDeepthNow(vm) == vm->super_invoke_deepth - 1) {
vm->in_super = PIKA_FALSE;
vm->in_super = pika_false;
oThis = obj_getPtr(vm->locals, _find_self_name(vm));
}
#endif
@ -2196,9 +2197,9 @@ static Arg* VM_instruction_handler_BYT(PikaObj* self,
return arg_newBytes((uint8_t*)data, strGetSize(data));
}
static PIKA_BOOL _proxy_setattr(PikaObj* self, char* name, Arg* arg) {
static pika_bool _proxy_setattr(PikaObj* self, char* name, Arg* arg) {
#if PIKA_NANO_ENABLE
return PIKA_FALSE;
return pika_false;
#endif
if (obj_getFlag(self, OBJ_FLAG_PROXY_SETATTR)) {
obj_setStr(self, "@name", name);
@ -2219,9 +2220,9 @@ static PIKA_BOOL _proxy_setattr(PikaObj* self, char* name, Arg* arg) {
0x72, 0x5f, 0x5f, 0x00, /* const pool */
};
pikaVM_runByteCode(self, (uint8_t*)bytes);
return PIKA_TRUE;
return pika_true;
}
return PIKA_FALSE;
return pika_false;
}
static Arg* VM_instruction_handler_OUT(PikaObj* self,
@ -2232,7 +2233,7 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self,
pika_assert(sArgPath != NULL);
char* sArgName = strPointToLastToken(sArgPath, '.');
PikaObj* oHost = NULL;
PIKA_BOOL bIsTemp = PIKA_FALSE;
pika_bool bIsTemp = pika_false;
arg_newReg(aOutReg, PIKA_ARG_BUFF_SIZE);
Arg* aOut = stack_popArg(&vm->stack, &aOutReg);
if (NULL == aOut) {
@ -2241,7 +2242,7 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self,
ArgType eOutArgType = arg_getType(aOut);
if (VMState_getInvokeDeepthNow(vm) > 0) {
/* in block, is a kw arg */
arg_setIsKeyword(aOut, PIKA_TRUE);
arg_setIsKeyword(aOut, pika_true);
arg_setName(aOut, sArgPath);
Arg* res = arg_copy_noalloc(aOut, aRetReg);
arg_deinit(aOut);
@ -2381,7 +2382,7 @@ static Arg* _VM_JEZ(PikaObj* self,
int pika_assert) {
int thisBlockDeepth = VMState_getBlockDeepthNow(vm);
int jmp_expect = fast_atoi(data);
vm->ireg[thisBlockDeepth] = (PIKA_BOOL)!pika_assert;
vm->ireg[thisBlockDeepth] = (pika_bool)!pika_assert;
if (0 == pika_assert) {
/* jump */
@ -2835,9 +2836,9 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
if (data[1] == 'i' && data[2] == 'n') {
if (op.t1 == ARG_TYPE_STRING && op.t2 == ARG_TYPE_STRING) {
if (strstr(arg_getStr(op.a2), arg_getStr(op.a1))) {
op.res = arg_setBool(op.res, "", PIKA_TRUE);
op.res = arg_setBool(op.res, "", pika_true);
} else {
op.res = arg_setBool(op.res, "", PIKA_FALSE);
op.res = arg_setBool(op.res, "", pika_false);
}
goto exit;
}
@ -3076,7 +3077,7 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self,
/* assert failed */
if ((arg_getType(arg1) == ARG_TYPE_INT && arg_getInt(arg1) == 0) ||
(arg_getType(arg1) == ARG_TYPE_BOOL &&
arg_getBool(arg1) == PIKA_FALSE)) {
arg_getBool(arg1) == pika_false)) {
stack_pushArg(&vm->stack, arg_newInt(PIKA_RES_ERR_ASSERT));
res = VM_instruction_handler_RIS(self, vm, data, arg_ret_reg);
// if (vm->run_state->try_state == TRY_STATE_NONE) {
@ -3243,42 +3244,43 @@ static struct {
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
const uint16_t signature_dict[PIKA_INSTRUCT_SIGNATURE_DICT_COUNT];
#endif
} VM = {
} g_PikaVMInsSet = {
.default_ins_set =
{
.ins_set = &VM_default_instruction_set,
.next = NULL,
},
.list = (VMInstructionSetItem*)&VM.default_ins_set,
.recent = (VMInstructionSetItem*)&VM.default_ins_set,
.list = (VMInstructionSetItem*)&g_PikaVMInsSet.default_ins_set,
.recent = (VMInstructionSetItem*)&g_PikaVMInsSet.default_ins_set,
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
.signature_dict = {PIKA_INSTRUCT_SIGNATURE_DICT},
#endif
};
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
pika_bool pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
pika_assert(NULL != ins_set);
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
uint16_t signature = ins_set->signature;
PIKA_BOOL ins_set_valid = PIKA_FALSE;
for (int n = 0; n < sizeof(VM.signature_dict) / sizeof(uint16_t); n++) {
if (VM.signature_dict[n] == signature) {
ins_set_valid = PIKA_TRUE;
pika_bool ins_set_valid = pika_false;
for (int n = 0;
n < sizeof(g_PikaVMInsSet.signature_dict) / sizeof(uint16_t); n++) {
if (g_PikaVMInsSet.signature_dict[n] == signature) {
ins_set_valid = pika_true;
break;
}
}
if (!ins_set_valid) {
return PIKA_FALSE;
return pika_false;
}
#endif
/* check whether the target instruction set exists or not */
VMInstructionSetItem* list_item = VM.list;
VMInstructionSetItem* list_item = g_PikaVMInsSet.list;
do {
if (list_item->ins_set->signature == signature) {
return PIKA_TRUE; /* already exist */
return pika_true; /* already exist */
}
list_item = list_item->next;
@ -3287,7 +3289,7 @@ PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
VMInstructionSetItem* item =
pika_platform_malloc(sizeof(VMInstructionSetItem));
if (NULL == item) {
return PIKA_FALSE;
return pika_false;
}
item->ins_set = ins_set;
item->next = NULL;
@ -3295,12 +3297,12 @@ PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
/* add item to the tail of VM.list */
list_item->next = item;
return PIKA_TRUE;
return pika_true;
}
static const VMInstruction* instructUnit_getInstruct(
enum InstructIndex ins_idx) {
VMInstructionSetItem* item = VM.recent;
VMInstructionSetItem* item = g_PikaVMInsSet.recent;
if ((ins_idx >= item->ins_set->op_idx_start) &&
(ins_idx <= item->ins_set->op_idx_end)) {
@ -3309,11 +3311,11 @@ static const VMInstruction* instructUnit_getInstruct(
}
/* search list */
item = VM.list;
item = g_PikaVMInsSet.list;
do {
if ((ins_idx >= item->ins_set->op_idx_start) &&
(ins_idx <= item->ins_set->op_idx_end)) {
VM.recent = item;
g_PikaVMInsSet.recent = item;
return &(item->ins_set
->instructions[ins_idx - item->ins_set->op_idx_start]);
}
@ -3340,15 +3342,15 @@ static enum InstructIndex __find_ins_idx_in_ins_set(
enum InstructIndex pikaVM_getInstructFromAsm(char* ins_str) {
enum InstructIndex ins_idx =
__find_ins_idx_in_ins_set(ins_str, VM.recent->ins_set);
__find_ins_idx_in_ins_set(ins_str, g_PikaVMInsSet.recent->ins_set);
if (__INSTRUCTION_UNKNOWN == ins_idx) {
VMInstructionSetItem* item = VM.list;
VMInstructionSetItem* item = g_PikaVMInsSet.list;
do {
ins_idx = __find_ins_idx_in_ins_set(ins_str, item->ins_set);
if (__INSTRUCTION_UNKNOWN != ins_idx) {
VM.recent = item;
g_PikaVMInsSet.recent = item;
return ins_idx;
}
item = item->next;
@ -3362,8 +3364,8 @@ enum InstructIndex pikaVM_getInstructFromAsm(char* ins_str) {
#else
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
return PIKA_FALSE;
pika_bool pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
return pika_false;
}
enum InstructIndex pikaVM_getInstructFromAsm(char* ins_str) {
@ -3592,7 +3594,7 @@ VMParameters* _do_pikaVM_runByteCode(PikaObj* self,
VMParameters* globals,
uint8_t* bytecode,
RunState* run_state,
PIKA_BOOL is_const_bytecode) {
pika_bool is_const_bytecode) {
ByteCodeFrame bytecode_frame_stack = {0};
ByteCodeFrame* bytecode_frame_p = NULL;
uint8_t is_use_heap_bytecode = 1;
@ -3606,7 +3608,7 @@ VMParameters* _do_pikaVM_runByteCode(PikaObj* self,
/* get bytecode_ptr from stack */
bytecode_frame_p = &bytecode_frame_stack;
/* no def/class ins, no need cache bytecode */
is_const_bytecode = PIKA_TRUE;
is_const_bytecode = pika_true;
}
/* load or generate byte code frame */
@ -3664,7 +3666,11 @@ VMParameters* pikaVM_runByteCode(PikaObj* self, const uint8_t* bytecode) {
RunState run_state = {.try_state = TRY_STATE_NONE,
.try_result = TRY_RESULT_NONE};
return _do_pikaVM_runByteCode(self, self, self, (uint8_t*)bytecode,
&run_state, PIKA_TRUE);
&run_state, pika_true);
}
VMState* pikaVM_getCurrent(void) {
return g_PikaVMSignal.vm_now;
}
Arg* pikaVM_runByteCodeReturn(PikaObj* self,
@ -3687,7 +3693,7 @@ Arg* _do_pikaVM_runByteCodeReturn(PikaObj* self,
VMParameters* globals,
uint8_t* bytecode,
RunState* run_state,
PIKA_BOOL is_const_bytecode,
pika_bool is_const_bytecode,
char* return_name) {
_do_pikaVM_runByteCode(self, locals, globals, bytecode, run_state,
is_const_bytecode);
@ -3706,7 +3712,7 @@ VMParameters* pikaVM_runByteCodeInconstant(PikaObj* self, uint8_t* bytecode) {
RunState run_state = {.try_state = TRY_STATE_NONE,
.try_result = TRY_RESULT_NONE};
return _do_pikaVM_runByteCode(self, self, self, (uint8_t*)bytecode,
&run_state, PIKA_FALSE);
&run_state, pika_false);
}
void constPool_update(ConstPool* self) {
@ -3820,7 +3826,7 @@ void byteCodeFrame_init(ByteCodeFrame* self) {
extern const char magic_code_pyo[4];
void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
uint8_t* bytes,
PIKA_BOOL is_const) {
pika_bool is_const) {
if (bytes[0] == magic_code_pyo[0] && bytes[1] == magic_code_pyo[1] &&
bytes[2] == magic_code_pyo[2] && bytes[3] == magic_code_pyo[3]) {
/* load from file, found magic code, skip head */
@ -3850,7 +3856,7 @@ void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
}
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes) {
_do_byteCodeFrame_loadByteCode(self, bytes, PIKA_TRUE);
_do_byteCodeFrame_loadByteCode(self, bytes, pika_true);
}
void byteCodeFrame_deinit(ByteCodeFrame* self) {
@ -3930,15 +3936,16 @@ static const char* __find_ins_str_in_ins_set(enum InstructIndex op_idx,
static char* instructUnit_getInstructStr(InstructUnit* self) {
enum InstructIndex op_idx = instructUnit_getInstructIndex(self);
const char* ins_str = __find_ins_str_in_ins_set(op_idx, VM.recent->ins_set);
const char* ins_str =
__find_ins_str_in_ins_set(op_idx, g_PikaVMInsSet.recent->ins_set);
if (NULL != ins_str) {
return (char*)ins_str;
}
VMInstructionSetItem* item = VM.list;
VMInstructionSetItem* item = g_PikaVMInsSet.list;
do {
ins_str = __find_ins_str_in_ins_set(op_idx, item->ins_set);
if (NULL != ins_str) {
VM.recent = item;
g_PikaVMInsSet.recent = item;
return (char*)ins_str;
}
item = item->next;
@ -4062,7 +4069,7 @@ void VMState_solveUnusedStack(VMState* vm) {
arg_deinit(arg);
continue;
}
arg_print(arg, PIKA_TRUE, "\r\n");
arg_print(arg, pika_true, "\r\n");
arg_deinit(arg);
}
}
@ -4078,50 +4085,51 @@ static VMParameters* _pikaVM_runByteCodeFrameWithState(
int size = bytecode_frame->instruct_array.size;
/* locals is the local scope */
VMState* vm_ptr = (VMState*)pikaMalloc(sizeof(VMState));
vm_ptr->bytecode_frame = bytecode_frame;
vm_ptr->locals = locals;
vm_ptr->globals = globals;
vm_ptr->jmp = 0;
vm_ptr->pc = pc;
vm_ptr->loop_deepth = 0;
vm_ptr->error_code = PIKA_RES_OK;
vm_ptr->line_error_code = PIKA_RES_OK;
vm_ptr->try_error_code = PIKA_RES_OK;
vm_ptr->run_state = run_state;
vm_ptr->ins_cnt = 0;
vm_ptr->in_super = PIKA_FALSE;
vm_ptr->super_invoke_deepth = 0;
stack_init(&(vm_ptr->stack));
VMState_initReg(vm_ptr);
VMState* vm = (VMState*)pikaMalloc(sizeof(VMState));
vm->bytecode_frame = bytecode_frame;
vm->locals = locals;
vm->globals = globals;
vm->jmp = 0;
vm->pc = pc;
vm->loop_deepth = 0;
vm->error_code = PIKA_RES_OK;
vm->line_error_code = PIKA_RES_OK;
vm->try_error_code = PIKA_RES_OK;
vm->run_state = run_state;
vm->ins_cnt = 0;
vm->in_super = pika_false;
vm->super_invoke_deepth = 0;
stack_init(&(vm->stack));
VMState_initReg(vm);
if (g_PikaVMSignal.vm_cnt == 0) {
pks_vmSignal_setCtrlElear();
pks_vmSignal_setCtrlClear();
}
g_PikaVMSignal.vm_cnt++;
while (vm_ptr->pc < size) {
if (vm_ptr->pc == VM_PC_EXIT) {
g_PikaVMSignal.vm_now = vm;
while (vm->pc < size) {
if (vm->pc == VM_PC_EXIT) {
break;
}
InstructUnit* this_ins_unit = VMState_getInstructNow(vm_ptr);
InstructUnit* this_ins_unit = VMState_getInstructNow(vm);
uint8_t is_new_line = instructUnit_getIsNewLine(this_ins_unit);
if (is_new_line) {
VMState_solveUnusedStack(vm_ptr);
stack_reset(&(vm_ptr->stack));
vm_ptr->error_code = 0;
vm_ptr->line_error_code = 0;
VMState_solveUnusedStack(vm);
stack_reset(&(vm->stack));
vm->error_code = 0;
vm->line_error_code = 0;
}
vm_ptr->pc = pikaVM_runInstructUnit(self, vm_ptr, this_ins_unit);
vm_ptr->ins_cnt++;
vm->pc = pikaVM_runInstructUnit(self, vm, this_ins_unit);
vm->ins_cnt++;
#if PIKA_INSTRUCT_HOOK_ENABLE
if (vm_ptr->ins_cnt % PIKA_INSTRUCT_HOOK_PERIOD == 0) {
if (vm->ins_cnt % PIKA_INSTRUCT_HOOK_PERIOD == 0) {
pika_hook_instruct();
}
#endif
if (vm_ptr->ins_cnt % PIKA_INSTRUCT_YIELD_PERIOD == 0) {
if (vm->ins_cnt % PIKA_INSTRUCT_YIELD_PERIOD == 0) {
_pikaVM_yield();
}
if (0 != vm_ptr->error_code) {
vm_ptr->line_error_code = vm_ptr->error_code;
if (0 != vm->error_code) {
vm->line_error_code = vm->error_code;
InstructUnit* head_ins_unit = this_ins_unit;
/* get first ins of a line */
while (1) {
@ -4130,11 +4138,11 @@ static VMParameters* _pikaVM_runByteCodeFrameWithState(
}
head_ins_unit--;
}
if (vm_ptr->run_state->try_state) {
vm_ptr->try_error_code = vm_ptr->error_code;
if (vm->run_state->try_state) {
vm->try_error_code = vm->error_code;
}
/* print inses of a line */
if (!vm_ptr->run_state->try_state) {
if (!vm->run_state->try_state) {
while (1) {
if (head_ins_unit != this_ins_unit) {
pika_platform_printf(" ");
@ -4150,15 +4158,15 @@ static VMParameters* _pikaVM_runByteCodeFrameWithState(
}
}
pika_platform_error_handle();
vm_ptr->error_code = 0;
vm->error_code = 0;
}
}
VMState_solveUnusedStack(vm_ptr);
stack_deinit(&(vm_ptr->stack));
VMState_solveUnusedStack(vm);
stack_deinit(&(vm->stack));
g_PikaVMSignal.vm_cnt--;
VMParameters* result = locals;
pikaFree(vm_ptr, sizeof(VMState));
pikaFree(vm, sizeof(VMState));
return result;
}
@ -4224,7 +4232,7 @@ PikaObj* pikaVM_runFile(PikaObj* self, char* file_name) {
pikaMaker_setPWD(maker, pwd);
pikaMaker_compileModuleWithDepends(maker, module_name);
_do_pikaMaker_linkCompiledModules(maker, "pikaModules_cache.py.a",
PIKA_FALSE);
pika_false);
pikaMaker_deinit(maker);
pika_platform_printf("(pikascript) all succeed.\r\n\r\n");

View File

@ -84,10 +84,10 @@ struct VMState {
uint8_t line_error_code;
uint8_t try_error_code;
uint32_t ins_cnt;
PIKA_BOOL in_super;
pika_bool in_super;
uint8_t super_invoke_deepth;
RunState* run_state;
PIKA_BOOL ireg[PIKA_REGIST_SIZE];
pika_bool ireg[PIKA_REGIST_SIZE];
};
typedef struct {
@ -97,9 +97,9 @@ typedef struct {
int8_t n_arg;
int8_t i_arg;
int8_t n_input;
PIKA_BOOL is_vars;
PIKA_BOOL is_keys;
PIKA_BOOL is_default;
pika_bool is_vars;
pika_bool is_keys;
pika_bool is_default;
ArgType method_type;
PikaTuple* tuple;
PikaDict* kw;
@ -151,6 +151,7 @@ typedef struct VMSignal VMSignal;
struct VMSignal {
VM_SIGNAL_CTRL signal_ctrl;
int vm_cnt;
VMState* vm_now;
#if PIKA_EVENT_ENABLE
EventCQ cq;
int event_pickup_cnt;
@ -181,6 +182,7 @@ struct VMInstructionSet {
uint16_t op_idx_end;
};
VMState* pikaVM_getCurrent(void);
VMParameters* pikaVM_run(PikaObj* self, char* pyLine);
VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
VMParameters* pikaVM_runByteCodeFrame(PikaObj* self,
@ -314,7 +316,7 @@ void instructArray_printAsArray(InstructArray* self);
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes);
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
void byteCodeFrame_init(ByteCodeFrame* self);
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set);
pika_bool pikaVM_registerInstructionSet(VMInstructionSet* ins_set);
VMParameters* pikaVM_runByteCode(PikaObj* self, const uint8_t* bytecode);
VMParameters* pikaVM_runByteCodeInconstant(PikaObj* self, uint8_t* bytecode);
Arg* pikaVM_runByteCodeReturn(PikaObj* self,
@ -325,7 +327,7 @@ Arg* _do_pikaVM_runByteCodeReturn(PikaObj* self,
VMParameters* globals,
uint8_t* bytecode,
RunState* run_state,
PIKA_BOOL is_const_bytecode,
pika_bool is_const_bytecode,
char* return_name);
InstructUnit* instructArray_getNow(InstructArray* self);
InstructUnit* instructArray_getNext(InstructArray* self);
@ -344,10 +346,10 @@ VMParameters* _do_pikaVM_runByteCode(PikaObj* self,
VMParameters* globals,
uint8_t* bytecode,
RunState* run_state,
PIKA_BOOL is_const_bytecode);
pika_bool is_const_bytecode);
void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
uint8_t* bytes,
PIKA_BOOL is_const);
pika_bool is_const);
Arg* _vm_get(VMState* vm, PikaObj* self, Arg* key, Arg* obj);
void __vm_List_append(PikaObj* self, Arg* arg);
void __vm_List___init__(PikaObj* self);
@ -355,7 +357,7 @@ void __vm_Dict_set(PikaObj* self, Arg* arg, char* key);
void __vm_Dict___init__(PikaObj* self);
VM_SIGNAL_CTRL VMSignal_getCtrl(void);
void pks_vm_exit(void);
void pks_vmSignal_setCtrlElear(void);
void pks_vmSignal_setCtrlClear(void);
PIKA_RES __eventListener_popEvent(PikaEventListener** lisener_p,
uint32_t* id,
Arg** signal,

View File

@ -48,11 +48,11 @@
#if defined(__MSG_DECLARE)
#define __add_filter_msg(__name, __msg, ...) \
PIKA_BOOL _filter_msg_##__name##_handler( FilterItem *msg, \
pika_bool _filter_msg_##__name##_handler( FilterItem *msg, \
PikaObj* self, \
ShellConfig* shell);
#define __add_filter_item(__name, ...) \
PIKA_BOOL _filter_msg_##__name##_handler( FilterItem *msg, \
pika_bool _filter_msg_##__name##_handler( FilterItem *msg, \
PikaObj* self, \
ShellConfig* shell);
#endif

View File

@ -37,15 +37,15 @@
* add_filter_msg(
* <name>,
* <string>,
* [.is_visible = PIKA_TRUE,]
* [.is_case_insensitive = PIKA_TRUE,]
* [.is_visible = pika_true,]
* [.is_case_insensitive = pika_true,]
* [.ignore_mask = mask value,]
* [.target = your own object address/value,]
* )
*/
add_filter_msg(hi_pika, "###Hi Pika")
add_filter_msg(bye_pika, "###bye pika", .is_case_insensitive = PIKA_TRUE)
add_filter_msg(bye_pika, "###bye pika", .is_case_insensitive = pika_true)
/* add your own message item here with syntax:
*
@ -53,8 +53,8 @@ add_filter_msg(bye_pika, "###bye pika", .is_case_insensitive = PIKA_TRUE)
* <name>,
* .message = (const uint8_t []){< num0, num1, ... >},
* .size = <array size>,
* [.is_visible = PIKA_TRUE,]
* [.is_case_insensitive = PIKA_TRUE,]
* [.is_visible = pika_true,]
* [.is_case_insensitive = pika_true,]
* [.ignore_mask = mask value,]
* [.target = your own object address/value,]
* )

View File

@ -32,24 +32,24 @@
#include "dataString.h"
#include "stdlib.h"
static PIKA_BOOL _arg_cache_push(Arg* self, uint32_t size) {
static pika_bool _arg_cache_push(Arg* self, uint32_t size) {
#if !PIKA_ARG_CACHE_ENABLE
return PIKA_FALSE;
return pika_false;
#else
if (PIKA_FALSE == pika_hook_arg_cache_filter(self)) {
return PIKA_FALSE;
if (pika_false == pika_hook_arg_cache_filter(self)) {
return pika_false;
}
extern PikaMemInfo g_PikaMemInfo;
if (self->heap_size < PIKA_ARG_CACHE_SIZE ||
self->heap_size > 2 * PIKA_ARG_CACHE_SIZE) {
return PIKA_FALSE;
return pika_false;
}
if (PIKA_ARG_CACHE_POOL_SIZE <= g_PikaMemInfo.cache_pool_top) {
return PIKA_FALSE;
return pika_false;
}
g_PikaMemInfo.cache_pool[g_PikaMemInfo.cache_pool_top++] = (uint8_t*)self;
g_PikaMemInfo.heapUsed -= mem_align(sizeof(Arg) + size);
return PIKA_TRUE;
return pika_true;
#endif
}
@ -132,8 +132,8 @@ static Arg* _arg_set_hash(Arg* self,
}
self->size = size;
self->flag = 0;
arg_setSerialized(self, PIKA_TRUE);
// arg_setIsKeyword(self, PIKA_FALSE);
arg_setSerialized(self, pika_true);
// arg_setIsKeyword(self, pika_false);
arg_setNext(self, next);
}
self->name_hash = nameHash;
@ -365,7 +365,7 @@ __exit:
return result;
}
void arg_print(Arg* self, PIKA_BOOL in_REPL, char* end) {
void arg_print(Arg* self, pika_bool in_REPL, char* end) {
/* use arg_toStrArg() */
Arg* str_arg = arg_toStrArg(self);
if (NULL == str_arg) {
@ -428,7 +428,7 @@ Arg* arg_setInt(Arg* self, char* name, int64_t val) {
return arg_set(self, name, ARG_TYPE_INT, (uint8_t*)&val, sizeof(val));
}
Arg* arg_setBool(Arg* self, char* name, PIKA_BOOL val) {
Arg* arg_setBool(Arg* self, char* name, pika_bool val) {
return arg_set(self, name, ARG_TYPE_BOOL, (uint8_t*)&val, sizeof(val));
}
@ -468,12 +468,12 @@ int64_t arg_getInt(Arg* self) {
return *(int64_t*)arg_getContent(self);
}
PIKA_BOOL arg_getBool(Arg* self) {
pika_bool arg_getBool(Arg* self) {
pika_assert(NULL != self);
if (NULL == arg_getContent(self)) {
return _PIKA_BOOL_ERR;
}
return *(PIKA_BOOL*)arg_getContent(self);
return *(pika_bool*)arg_getContent(self);
}
void* arg_getPtr(Arg* self) {
@ -553,7 +553,7 @@ Arg* arg_copy_noalloc(Arg* arg_src, Arg* arg_dict) {
return arg_copy(arg_src);
}
arg_refcntInc(arg_src);
arg_setSerialized(arg_dict, PIKA_FALSE);
arg_setSerialized(arg_dict, pika_false);
arg_dict = arg_copy_content(arg_dict, arg_src);
return arg_dict;
}
@ -663,26 +663,26 @@ void arg_deinit(Arg* self) {
arg_freeContent(self);
}
PIKA_BOOL arg_isEqual(Arg* self, Arg* other) {
pika_bool arg_isEqual(Arg* self, Arg* other) {
if (NULL == self || NULL == other) {
return PIKA_FALSE;
return pika_false;
}
if (arg_getType(self) != arg_getType(other)) {
return PIKA_FALSE;
return pika_false;
}
if (arg_getType(self) == ARG_TYPE_OBJECT) {
if (arg_getPtr(self) != arg_getPtr(other)) {
return PIKA_FALSE;
return pika_false;
}
}
if (arg_getType(self) == ARG_TYPE_STRING) {
if (strEqu(arg_getStr(self), arg_getStr(other))) {
return PIKA_TRUE;
return pika_true;
}
}
if (0 != pika_platform_memcmp(arg_getContent(self), arg_getContent(other),
arg_getContentSize(self))) {
return PIKA_FALSE;
return pika_false;
}
return PIKA_TRUE;
return pika_true;
}

View File

@ -120,7 +120,7 @@ uint32_t arg_getContentSize(Arg* self);
Hash hash_time33(char* str);
Arg* arg_setInt(Arg* self, char* name, int64_t val);
Arg* arg_setBool(Arg* self, char* name, PIKA_BOOL val);
Arg* arg_setBool(Arg* self, char* name, pika_bool val);
Arg* arg_setFloat(Arg* self, char* name, pika_float val);
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer);
Arg* arg_setStr(Arg* self, char* name, char* string);
@ -131,7 +131,7 @@ static inline Arg* arg_newInt(int64_t val) {
return arg_setInt(NULL, (char*)"", (val));
}
static inline Arg* arg_newBool(PIKA_BOOL val) {
static inline Arg* arg_newBool(pika_bool val) {
return arg_setBool(NULL, (char*)"", (val));
}
@ -156,7 +156,7 @@ static inline Arg* arg_newBytes(uint8_t* src, size_t size) {
}
int64_t arg_getInt(Arg* self);
PIKA_BOOL arg_getBool(Arg* self);
pika_bool arg_getBool(Arg* self);
pika_float arg_getFloat(Arg* self);
void* arg_getPtr(Arg* self);
char* arg_getStr(Arg* self);
@ -182,7 +182,7 @@ Arg* arg_setHeapStruct(Arg* self,
void* arg_getHeapStruct(Arg* self);
void arg_deinitHeap(Arg* self);
Arg* arg_toStrArg(Arg* arg);
void arg_print(Arg* self, PIKA_BOOL in_REPL, char* end);
void arg_print(Arg* self, pika_bool in_REPL, char* end);
Arg* arg_loadFile(Arg* self, char* filename);
#define ARG_FLAG_SERIALIZED 0x01
@ -301,7 +301,7 @@ static inline uint8_t argType_isNative(ArgType type) {
arg_init_stack(&__name, __##__name##_buff, __size)
void arg_init_stack(Arg* self, uint8_t* buffer, uint32_t size);
PIKA_BOOL arg_isEqual(Arg* self, Arg* other);
pika_bool arg_isEqual(Arg* self, Arg* other);
Hash hash_time33EndWith(char* str, char end);
#endif

View File

@ -202,7 +202,7 @@ int64_t args_getInt(Args* self, char* name) {
return _PIKA_INT_ERR;
}
PIKA_BOOL args_getBool(Args* self, char* name) {
pika_bool args_getBool(Args* self, char* name) {
Arg* arg = args_getArg(self, name);
if (NULL == arg) {
return _PIKA_BOOL_ERR;

View File

@ -75,7 +75,7 @@ void* args_getPtr(Args* self, char* name);
PIKA_RES args_setInt(Args* self, char* name, int64_t int64In);
int64_t args_getInt(Args* self, char* name);
PIKA_BOOL args_getBool(Args* self, char* name);
pika_bool args_getBool(Args* self, char* name);
char* args_print(Args* self, char* name);

View File

@ -109,7 +109,7 @@ Pool pool_init(uint32_t size, uint8_t aline) {
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;
pool.inited = pika_true;
return pool;
}

View File

@ -63,7 +63,7 @@ struct Pool{
uint32_t size;
uint32_t first_free_block;
uint32_t purl_free_block_start;
PIKA_BOOL inited;
pika_bool inited;
)
};
/* clang-format on */

View File

@ -99,7 +99,7 @@ char* queue_popStr(Queue* queue) {
ByteQueue* byteQueue_init(ByteQueue* queue,
void* buffer,
uint_fast16_t size,
PIKA_BOOL is_queue_full) {
pika_bool is_queue_full) {
pika_assert(NULL != queue);
pika_assert(NULL != buffer);
pika_assert(size > 0);
@ -116,10 +116,10 @@ ByteQueue* byteQueue_init(ByteQueue* queue,
return queue;
}
PIKA_BOOL byteQueue_readOne(ByteQueue* queue, uint8_t* byte_ptr) {
pika_bool byteQueue_readOne(ByteQueue* queue, uint8_t* byte_ptr) {
pika_assert(NULL != queue);
uint8_t byte;
PIKA_BOOL result = PIKA_FALSE;
pika_bool result = pika_false;
/* ------------------atomicity sensitive start---------------- */
do {
@ -141,17 +141,17 @@ PIKA_BOOL byteQueue_readOne(ByteQueue* queue, uint8_t* byte_ptr) {
if (NULL != byte_ptr) {
*byte_ptr = byte;
}
result = PIKA_TRUE;
result = pika_true;
} while (0);
/* ------------------atomicity sensitive end ---------------- */
return result;
}
PIKA_BOOL byteQueue_peekOne(ByteQueue* queue, uint8_t* byte_ptr) {
pika_bool byteQueue_peekOne(ByteQueue* queue, uint8_t* byte_ptr) {
pika_assert(NULL != queue);
uint8_t byte;
PIKA_BOOL result = PIKA_FALSE;
pika_bool result = pika_false;
/* ------------------atomicity sensitive start---------------- */
do {
@ -169,7 +169,7 @@ PIKA_BOOL byteQueue_peekOne(ByteQueue* queue, uint8_t* byte_ptr) {
if (NULL != byte_ptr) {
*byte_ptr = byte;
}
result = PIKA_TRUE;
result = pika_true;
} while (0);
/* ------------------atomicity sensitive end ---------------- */
@ -200,9 +200,9 @@ void byteQueue_dropAllPeeked(ByteQueue* queue) {
/* ------------------atomicity sensitive end ---------------- */
}
PIKA_BOOL byteQueue_writeOne(ByteQueue* queue, uint8_t byte) {
pika_bool byteQueue_writeOne(ByteQueue* queue, uint8_t byte) {
pika_assert(NULL != queue);
PIKA_BOOL result = PIKA_FALSE;
pika_bool result = pika_false;
/* ------------------atomicity sensitive start---------------- */
do {
@ -218,7 +218,7 @@ PIKA_BOOL byteQueue_writeOne(ByteQueue* queue, uint8_t byte) {
queue->tail = 0;
}
result = PIKA_TRUE;
result = pika_true;
} while (0);
/* ------------------atomicity sensitive end ---------------- */

View File

@ -76,14 +76,14 @@ void queue_init(Queue* queue);
ByteQueue *byteQueue_init( ByteQueue *queue,
void *buffer,
uint_fast16_t size,
PIKA_BOOL is_queue_full);
PIKA_BOOL byteQueue_readOne(ByteQueue *queue, uint8_t *byte_ptr);
PIKA_BOOL byteQueue_peekOne(ByteQueue *queue, uint8_t *byte_ptr);
pika_bool is_queue_full);
pika_bool byteQueue_readOne(ByteQueue *queue, uint8_t *byte_ptr);
pika_bool byteQueue_peekOne(ByteQueue *queue, uint8_t *byte_ptr);
void byteQueue_resetPeek(ByteQueue *queue);
void byteQueue_dropAllPeeked(ByteQueue *queue);
uint_fast16_t byteQueue_getPeekedNumber(ByteQueue *queue);
uint_fast16_t byteQueue_peekAvailableCount(ByteQueue *queue);
PIKA_BOOL byteQueue_writeOne(ByteQueue *queue, uint8_t byte);
pika_bool byteQueue_writeOne(ByteQueue *queue, uint8_t byte);
#endif
#ifdef __cplusplus

View File

@ -93,7 +93,7 @@ int32_t stack_deinit(Stack* stack) {
void stack_pushPyload(Stack* stack,
uint8_t* in,
size_t size,
PIKA_BOOL is_sample_copy) {
pika_bool is_sample_copy) {
size_t stack_size_after_push =
size + (stack->sp - arg_getContent(stack->stack_pyload));
if (stack_size_after_push > stack->stack_totle_size) {
@ -115,7 +115,7 @@ void stack_pushPyload(Stack* stack,
pika_platform_memcpy(top->content, ((Arg*)in)->_.buffer,
size - sizeof(Arg));
/* transfer to serialized form */
arg_setSerialized(top, PIKA_TRUE);
arg_setSerialized(top, pika_true);
}
stack->sp += size;
}
@ -128,8 +128,8 @@ uint8_t* stack_popPyload(Stack* stack, int32_t size) {
return stack->sp;
}
static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
PIKA_BOOL is_big_arg = PIKA_FALSE;
static int32_t _stack_pushArg(Stack* stack, Arg* arg, pika_bool is_alloc) {
pika_bool is_big_arg = pika_false;
stack->top++;
size_t size = arg_getTotleSize(arg);
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
@ -141,17 +141,17 @@ static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
arg_refcntInc(arg);
if (arg_isSerialized(arg)) {
is_big_arg = PIKA_TRUE;
is_big_arg = pika_true;
}
if (is_big_arg) {
/* push a pointer to this arg */
stack_pushSize(stack, -1);
stack_pushPyload(stack, (uint8_t*)&arg, sizeof(Arg*), PIKA_TRUE);
stack_pushPyload(stack, (uint8_t*)&arg, sizeof(Arg*), pika_true);
} else {
stack_pushSize(stack, size);
stack_pushPyload(stack, (uint8_t*)arg, size,
(PIKA_BOOL)arg_isSerialized(arg));
(pika_bool)arg_isSerialized(arg));
}
if (is_big_arg) {
@ -171,9 +171,9 @@ int32_t stack_pushArg(Stack* stack, Arg* arg) {
pika_assert(obj_checkAlive(arg_getPtr(arg)));
}
if (arg_isSerialized(arg)) {
return _stack_pushArg(stack, arg, PIKA_TRUE);
return _stack_pushArg(stack, arg, pika_true);
}
return _stack_pushArg(stack, arg, PIKA_FALSE);
return _stack_pushArg(stack, arg, pika_false);
}
int32_t stack_pushStr(Stack* stack, char* str) {
@ -181,15 +181,15 @@ int32_t stack_pushStr(Stack* stack, char* str) {
return stack_pushArg(stack, newArg);
}
Arg* _stack_popArg(Stack* stack, Arg* arg_dict, PIKA_BOOL is_alloc) {
PIKA_BOOL is_big_arg = PIKA_FALSE;
Arg* _stack_popArg(Stack* stack, Arg* arg_dict, pika_bool is_alloc) {
pika_bool is_big_arg = pika_false;
if (stack->top == 0) {
return NULL;
}
stack->top--;
int32_t size = stack_popSize(stack);
if (size == -1) {
is_big_arg = PIKA_TRUE;
is_big_arg = pika_true;
size = sizeof(Arg*);
}
Arg* arg = NULL;
@ -211,11 +211,11 @@ Arg* _stack_popArg(Stack* stack, Arg* arg_dict, PIKA_BOOL is_alloc) {
}
Arg* stack_popArg_alloc(Stack* stack) {
return _stack_popArg(stack, NULL, PIKA_TRUE);
return _stack_popArg(stack, NULL, pika_true);
}
Arg* stack_popArg(Stack* stack, Arg* arg_dict) {
return _stack_popArg(stack, arg_dict, PIKA_FALSE);
return _stack_popArg(stack, arg_dict, pika_false);
}
char* stack_popStr(Stack* stack, char* outBuff) {

View File

@ -94,10 +94,10 @@ const char bracketStart[] = {'(', '[', '{', '\'', '\"'};
const char bracketEnd[] = {')', ']', '}', '\'', '\"'};
#define BRACKET_TYPE_NUM (sizeof(bracketStart) / sizeof(char))
int _strCountSign(char* strIn, char sign, PIKA_BOOL bracketDepth0) {
int _strCountSign(char* strIn, char sign, pika_bool bracketDepth0) {
int32_t iCount = 0;
int32_t iTotalDepth = 0;
PIKA_BOOL bEscaped = PIKA_FALSE;
pika_bool bEscaped = pika_false;
for (size_t i = 0; strIn[i] != '\0'; i++) {
if (!bracketDepth0) {
if (strIn[i] == sign) {
@ -122,7 +122,7 @@ int _strCountSign(char* strIn, char sign, PIKA_BOOL bracketDepth0) {
if (cCurrentChar == sign && iTotalDepth == 0) {
iCount++;
}
bEscaped = PIKA_FALSE;
bEscaped = pika_false;
}
return iCount;
}

View File

@ -72,7 +72,7 @@ int strPathGetFileName(char* input, char* output);
int strGetIndent(char* string);
int strIsBlank(char* string);
int strOnly(char* string, char ch);
int _strCountSign(char* strIn, char sign, PIKA_BOOL bracketDepth0);
int _strCountSign(char* strIn, char sign, pika_bool bracketDepth0);
#endif
#ifdef __cplusplus

View File

@ -85,6 +85,10 @@ extern "C" {
#define arg_newNull arg_newNone
#define arg_setNull arg_setNone
#define PIKA_BOOL pika_bool
#define PIKA_TRUE pika_true
#define PIKA_FALSE pika_false
#endif
#endif

View File

@ -2871,6 +2871,8 @@ TEST_RUN_LINES(vm, import_void, "import \n")
TEST_RUN_SINGLE_FILE_PASS(vm, fn_fn, "test/python/builtin/fn_fn.py")
TEST_RUN_LINES_EXCEPT_OUTPUT(vm, isinstance, "isinstance(1, int)\n", "True\r\n")
#endif
TEST_END

View File

@ -30,7 +30,7 @@ impl PyType {
return "Arg*".to_string();
}
if self.type_name == "bool"{
return "PIKA_BOOL".to_string();
return "pika_bool".to_string();
}
if self.type_name == "@tupleVarPar" {
return "PikaTuple*".to_string();
@ -49,7 +49,7 @@ impl PyType {
return "int64_t".to_string();
}
if self.type_name == "bool" {
return "PIKA_BOOL".to_string();
return "pika_bool".to_string();
}
if self.type_name == "float" {
return "pika_float".to_string();