mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
support isinstance() for simple type
This commit is contained in:
parent
977d844d2c
commit
c823ad0879
@ -197,7 +197,7 @@ int dict_contains(PikaDict* dict, Arg* key) {
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PikaStdData_Dict___contains__(PikaObj* self, Arg* val) {
|
int PikaStdData_Dict___contains__(PikaObj* self, Arg* val) {
|
||||||
|
@ -47,6 +47,10 @@ class SysObj:
|
|||||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||||
def type(arg: any) -> any: ...
|
def type(arg: any) -> any: ...
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||||
|
def isinstance(object: any, classinfo: any) -> bool: ...
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def len(arg: any) -> int: ...
|
def len(arg: any) -> int: ...
|
||||||
|
|
||||||
|
@ -154,10 +154,10 @@ int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg, PikaTuple* base) {
|
|||||||
return _PIKA_INT_ERR;
|
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;
|
int64_t res = 0;
|
||||||
if (_transeInt(arg, 10, &res) == PIKA_RES_OK) {
|
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_setSysOut(self, "ValueError: invalid literal for bool()");
|
||||||
obj_setErrorCode(self, 1);
|
obj_setErrorCode(self, 1);
|
||||||
@ -181,7 +181,7 @@ char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
|
|||||||
|
|
||||||
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
|
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
|
||||||
/* object */
|
/* object */
|
||||||
PIKA_BOOL bIsTemp = PIKA_FALSE;
|
pika_bool bIsTemp = pika_false;
|
||||||
PikaObj* oArg = _arg_to_obj(arg, &bIsTemp);
|
PikaObj* oArg = _arg_to_obj(arg, &bIsTemp);
|
||||||
NewFun _clsptr = (NewFun)oArg->constructor;
|
NewFun _clsptr = (NewFun)oArg->constructor;
|
||||||
if (_clsptr == New_PikaStdLib_RangeObj) {
|
if (_clsptr == New_PikaStdLib_RangeObj) {
|
||||||
@ -470,11 +470,11 @@ void PikaStdLib_SysObj_print(PikaObj* self, PikaTuple* val, PikaDict* ops) {
|
|||||||
end = "\r\n";
|
end = "\r\n";
|
||||||
}
|
}
|
||||||
if (arg_size == 1) {
|
if (arg_size == 1) {
|
||||||
arg_print(pikaTuple_getArg(val, 0), PIKA_FALSE, end);
|
arg_print(pikaTuple_getArg(val, 0), pika_false, end);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Arg* print_out_arg = NULL;
|
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++) {
|
for (int i = 0; i < arg_size; i++) {
|
||||||
Arg* arg = pikaTuple_getArg(val, i);
|
Arg* arg = pikaTuple_getArg(val, i);
|
||||||
Arg* item_arg_str = arg_toStrArg(arg);
|
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) {
|
Arg* PikaStdLib_SysObj_min(PikaObj* self, PikaTuple* val) {
|
||||||
return _max_min(self, val, (uint8_t*)bc_min);
|
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;
|
||||||
|
}
|
||||||
|
4
port/linux/.vscode/launch.json
vendored
4
port/linux/.vscode/launch.json
vendored
@ -24,9 +24,9 @@
|
|||||||
// "--gtest_filter=lua.eval"
|
// "--gtest_filter=lua.eval"
|
||||||
// "--gtest_filter=eventloop.once1"
|
// "--gtest_filter=eventloop.once1"
|
||||||
// "--gtest_filter=parser.fn_fn"
|
// "--gtest_filter=parser.fn_fn"
|
||||||
// "--gtest_filter=vm.fn_fn"
|
"--gtest_filter=vm.isinstance"
|
||||||
// "--gtest_filter=VM.run_def_add"
|
// "--gtest_filter=VM.run_def_add"
|
||||||
"--gtest_filter=parser.slice_fn"
|
// "--gtest_filter=parser.slice_fn"
|
||||||
],
|
],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
|
@ -47,6 +47,10 @@ class SysObj:
|
|||||||
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||||
def type(arg: any) -> any: ...
|
def type(arg: any) -> any: ...
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@PIKA_C_MACRO_IF("!PIKA_NANO_ENABLE")
|
||||||
|
def isinstance(object: any, classinfo: any) -> bool: ...
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def len(arg: any) -> int: ...
|
def len(arg: any) -> int: ...
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ int dict_contains(PikaDict* dict, Arg* key) {
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PikaStdData_Dict___contains__(PikaObj* self, Arg* val) {
|
int PikaStdData_Dict___contains__(PikaObj* self, Arg* val) {
|
||||||
|
@ -154,10 +154,10 @@ int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg, PikaTuple* base) {
|
|||||||
return _PIKA_INT_ERR;
|
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;
|
int64_t res = 0;
|
||||||
if (_transeInt(arg, 10, &res) == PIKA_RES_OK) {
|
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_setSysOut(self, "ValueError: invalid literal for bool()");
|
||||||
obj_setErrorCode(self, 1);
|
obj_setErrorCode(self, 1);
|
||||||
@ -181,7 +181,7 @@ char* PikaStdLib_SysObj_str(PikaObj* self, Arg* arg) {
|
|||||||
|
|
||||||
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
|
Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
|
||||||
/* object */
|
/* object */
|
||||||
PIKA_BOOL bIsTemp = PIKA_FALSE;
|
pika_bool bIsTemp = pika_false;
|
||||||
PikaObj* oArg = _arg_to_obj(arg, &bIsTemp);
|
PikaObj* oArg = _arg_to_obj(arg, &bIsTemp);
|
||||||
NewFun _clsptr = (NewFun)oArg->constructor;
|
NewFun _clsptr = (NewFun)oArg->constructor;
|
||||||
if (_clsptr == New_PikaStdLib_RangeObj) {
|
if (_clsptr == New_PikaStdLib_RangeObj) {
|
||||||
@ -470,11 +470,11 @@ void PikaStdLib_SysObj_print(PikaObj* self, PikaTuple* val, PikaDict* ops) {
|
|||||||
end = "\r\n";
|
end = "\r\n";
|
||||||
}
|
}
|
||||||
if (arg_size == 1) {
|
if (arg_size == 1) {
|
||||||
arg_print(pikaTuple_getArg(val, 0), PIKA_FALSE, end);
|
arg_print(pikaTuple_getArg(val, 0), pika_false, end);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Arg* print_out_arg = NULL;
|
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++) {
|
for (int i = 0; i < arg_size; i++) {
|
||||||
Arg* arg = pikaTuple_getArg(val, i);
|
Arg* arg = pikaTuple_getArg(val, i);
|
||||||
Arg* item_arg_str = arg_toStrArg(arg);
|
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) {
|
Arg* PikaStdLib_SysObj_min(PikaObj* self, PikaTuple* val) {
|
||||||
return _max_min(self, val, (uint8_t*)bc_min);
|
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;
|
||||||
|
}
|
||||||
|
@ -38,15 +38,15 @@ const char magic_code_pyo[] = {0x0f, 'p', 'y', 'o'};
|
|||||||
/*
|
/*
|
||||||
* @brief check magic code of pyo file
|
* @brief check magic code of pyo file
|
||||||
* @param bytecode
|
* @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;
|
char* data = (char*)bytecode;
|
||||||
if (data[0] == magic_code_pyo[0] && data[1] == magic_code_pyo[1] &&
|
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]) {
|
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));
|
*(uint32_t*)(module_name + LIB_INFO_BLOCK_SIZE - sizeof(uint32_t));
|
||||||
*size = module_size;
|
*size = module_size;
|
||||||
/* fix size for string */
|
/* fix size for string */
|
||||||
PIKA_BOOL bIsString = PIKA_TRUE;
|
pika_bool bIsString = pika_true;
|
||||||
for (size_t i = 0; i < *size - 1; ++i) {
|
for (size_t i = 0; i < *size - 1; ++i) {
|
||||||
if (bytecode_addr[i] == 0) {
|
if (bytecode_addr[i] == 0) {
|
||||||
bIsString = PIKA_FALSE;
|
bIsString = pika_false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1014,7 +1014,7 @@ int32_t __foreach_handler_linkCompiledModules(Arg* argEach, void* context) {
|
|||||||
|
|
||||||
PIKA_RES _do_pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
PIKA_RES _do_pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
||||||
char* lib_path,
|
char* lib_path,
|
||||||
PIKA_BOOL gen_c_array) {
|
pika_bool gen_c_array) {
|
||||||
PIKA_RES compile_err = (PIKA_RES)obj_getInt(self, "err");
|
PIKA_RES compile_err = (PIKA_RES)obj_getInt(self, "err");
|
||||||
if (PIKA_RES_OK != compile_err) {
|
if (PIKA_RES_OK != compile_err) {
|
||||||
pika_platform_printf(" Error: compile failed, link aborted.\r\n");
|
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,
|
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
||||||
char* lib_path) {
|
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,
|
PIKA_RES _do_pikaMaker_linkCompiledModules(PikaMaker* self,
|
||||||
char* lib_name,
|
char* lib_name,
|
||||||
PIKA_BOOL gen_c_array) {
|
pika_bool gen_c_array) {
|
||||||
Args buffs = {0};
|
Args buffs = {0};
|
||||||
char* lib_file_path = strsPathJoin(&buffs, "pikascript-api/", lib_name);
|
char* lib_file_path = strsPathJoin(&buffs, "pikascript-api/", lib_name);
|
||||||
PIKA_RES res = _do_pikaMaker_linkCompiledModulesFullPath(
|
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) {
|
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);
|
f->addr = (uint8_t*)pikaMalloc(f->size);
|
||||||
pika_platform_memcpy(f->addr, arg_getBytes(file_arg), 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);
|
arg_deinit(file_arg);
|
||||||
return f;
|
return f;
|
||||||
|
@ -35,7 +35,7 @@ PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path);
|
|||||||
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
|
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
|
||||||
PIKA_RES _do_pikaMaker_linkCompiledModules(PikaMaker* self,
|
PIKA_RES _do_pikaMaker_linkCompiledModules(PikaMaker* self,
|
||||||
char* lib_name,
|
char* lib_name,
|
||||||
PIKA_BOOL gen_c_array);
|
pika_bool gen_c_array);
|
||||||
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes);
|
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes);
|
||||||
void LibObj_printModules(LibObj* self);
|
void LibObj_printModules(LibObj* self);
|
||||||
void pikaMaker_deinit(PikaMaker* self);
|
void pikaMaker_deinit(PikaMaker* self);
|
||||||
@ -56,7 +56,7 @@ typedef struct {
|
|||||||
uint8_t* addr;
|
uint8_t* addr;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
PIKA_BOOL need_free;
|
pika_bool need_free;
|
||||||
} pikafs_FILE;
|
} pikafs_FILE;
|
||||||
|
|
||||||
pikafs_FILE* pikafs_fopen(char* file_name, char* mode);
|
pikafs_FILE* pikafs_fopen(char* file_name, char* mode);
|
||||||
|
106
src/PikaObj.c
106
src/PikaObj.c
@ -46,7 +46,7 @@
|
|||||||
extern volatile VMSignal g_PikaVMSignal;
|
extern volatile VMSignal g_PikaVMSignal;
|
||||||
volatile PikaObjState g_PikaObjState = {
|
volatile PikaObjState g_PikaObjState = {
|
||||||
.helpModulesCmodule = NULL,
|
.helpModulesCmodule = NULL,
|
||||||
.inRootObj = PIKA_FALSE,
|
.inRootObj = pika_false,
|
||||||
#if PIKA_GC_MARK_SWEEP_ENABLE
|
#if PIKA_GC_MARK_SWEEP_ENABLE
|
||||||
.objCnt = 0,
|
.objCnt = 0,
|
||||||
.objCntMax = 0,
|
.objCntMax = 0,
|
||||||
@ -175,9 +175,9 @@ int obj_GC(PikaObj* self) {
|
|||||||
|
|
||||||
int32_t obj_deinit(PikaObj* self) {
|
int32_t obj_deinit(PikaObj* self) {
|
||||||
pikaGC_lock();
|
pikaGC_lock();
|
||||||
PIKA_BOOL bisRoot = PIKA_FALSE;
|
pika_bool bisRoot = pika_false;
|
||||||
#if PIKA_KERNAL_DEBUG_ENABLE
|
#if PIKA_KERNAL_DEBUG_ENABLE
|
||||||
self->isAlive = PIKA_FALSE;
|
self->isAlive = pika_false;
|
||||||
#endif
|
#endif
|
||||||
Arg* del = obj_getMethodArgWithFullPath(self, "__del__");
|
Arg* del = obj_getMethodArgWithFullPath(self, "__del__");
|
||||||
if (NULL != del) {
|
if (NULL != del) {
|
||||||
@ -193,7 +193,7 @@ int32_t obj_deinit(PikaObj* self) {
|
|||||||
}
|
}
|
||||||
extern volatile PikaObj* __pikaMain;
|
extern volatile PikaObj* __pikaMain;
|
||||||
if (self == (PikaObj*)__pikaMain) {
|
if (self == (PikaObj*)__pikaMain) {
|
||||||
bisRoot = PIKA_TRUE;
|
bisRoot = pika_true;
|
||||||
_mem_cache_deinit();
|
_mem_cache_deinit();
|
||||||
#if PIKA_EVENT_ENABLE
|
#if PIKA_EVENT_ENABLE
|
||||||
_VMEvent_deinit();
|
_VMEvent_deinit();
|
||||||
@ -298,19 +298,19 @@ int64_t obj_getInt(PikaObj* self, char* argPath) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
PIKA_BOOL obj_getBool(PikaObj* self, char* argPath) {
|
pika_bool obj_getBool(PikaObj* self, char* argPath) {
|
||||||
PikaObj* obj = obj_getHostObj(self, argPath);
|
PikaObj* obj = obj_getHostObj(self, argPath);
|
||||||
if (NULL == obj) {
|
if (NULL == obj) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
char* argName = strPointToLastToken(argPath, '.');
|
char* argName = strPointToLastToken(argPath, '.');
|
||||||
PIKA_BOOL res = args_getBool(obj->list, argName);
|
pika_bool res = args_getBool(obj->list, argName);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* obj_getArg(PikaObj* self, char* argPath) {
|
Arg* obj_getArg(PikaObj* self, char* argPath) {
|
||||||
pika_assert(obj_checkAlive(self));
|
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);
|
PikaObj* obj = obj_getHostObjWithIsTemp(self, argPath, &is_temp);
|
||||||
if (NULL == obj) {
|
if (NULL == obj) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -384,7 +384,7 @@ static PIKA_RES _obj_setArg(PikaObj* self,
|
|||||||
/* setArg would copy arg */
|
/* setArg would copy arg */
|
||||||
PikaObj* host = obj_getHostObj(self, argPath);
|
PikaObj* host = obj_getHostObj(self, argPath);
|
||||||
PikaObj* oNew = NULL;
|
PikaObj* oNew = NULL;
|
||||||
PIKA_BOOL bNew = PIKA_FALSE;
|
pika_bool bNew = pika_false;
|
||||||
if (NULL == host) {
|
if (NULL == host) {
|
||||||
/* object no found */
|
/* object no found */
|
||||||
return PIKA_RES_ERR_ARG_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);
|
aNew = arg_setName(aNew, sArgName);
|
||||||
if (arg_isObject(aNew)) {
|
if (arg_isObject(aNew)) {
|
||||||
oNew = arg_getPtr(aNew);
|
oNew = arg_getPtr(aNew);
|
||||||
bNew = PIKA_TRUE;
|
bNew = pika_true;
|
||||||
pika_assert(obj_checkAlive(oNew));
|
pika_assert(obj_checkAlive(oNew));
|
||||||
#if PIKA_KERNAL_DEBUG_ENABLE
|
#if PIKA_KERNAL_DEBUG_ENABLE
|
||||||
if (host != oNew) {
|
if (host != oNew) {
|
||||||
@ -732,7 +732,7 @@ static void signal_handler(int sig) {
|
|||||||
|
|
||||||
extern volatile PikaObj* __pikaMain;
|
extern volatile PikaObj* __pikaMain;
|
||||||
PikaObj* newRootObj(char* name, NewFun newObjFun) {
|
PikaObj* newRootObj(char* name, NewFun newObjFun) {
|
||||||
g_PikaObjState.inRootObj = PIKA_TRUE;
|
g_PikaObjState.inRootObj = pika_true;
|
||||||
#if PIKA_POOL_ENABLE
|
#if PIKA_POOL_ENABLE
|
||||||
mem_pool_init();
|
mem_pool_init();
|
||||||
#endif
|
#endif
|
||||||
@ -763,7 +763,7 @@ PikaObj* newRootObj(char* name, NewFun newObjFun) {
|
|||||||
}
|
}
|
||||||
__pikaMain = newObj;
|
__pikaMain = newObj;
|
||||||
obj_setName(newObj, name);
|
obj_setName(newObj, name);
|
||||||
g_PikaObjState.inRootObj = PIKA_FALSE;
|
g_PikaObjState.inRootObj = pika_false;
|
||||||
return newObj;
|
return newObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -808,7 +808,7 @@ exit:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
|
PikaObj* _arg_to_obj(Arg* self, pika_bool* pIsTemp) {
|
||||||
if (NULL == self) {
|
if (NULL == self) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -821,7 +821,7 @@ PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
|
|||||||
PikaObj* obj = newNormalObj(New_PikaStdData_String);
|
PikaObj* obj = newNormalObj(New_PikaStdData_String);
|
||||||
obj_setStr(obj, "str", arg_getStr(self));
|
obj_setStr(obj, "str", arg_getStr(self));
|
||||||
if (NULL != pIsTemp) {
|
if (NULL != pIsTemp) {
|
||||||
*pIsTemp = PIKA_TRUE;
|
*pIsTemp = pika_true;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -830,7 +830,7 @@ PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
|
|||||||
PikaObj* obj = newNormalObj(New_PikaStdData_ByteArray);
|
PikaObj* obj = newNormalObj(New_PikaStdData_ByteArray);
|
||||||
obj_setArg(obj, "raw", self);
|
obj_setArg(obj, "raw", self);
|
||||||
if (NULL != pIsTemp) {
|
if (NULL != pIsTemp) {
|
||||||
*pIsTemp = PIKA_TRUE;
|
*pIsTemp = pika_true;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -840,8 +840,8 @@ PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) {
|
|||||||
|
|
||||||
static PikaObj* _obj_getObjDirect(PikaObj* self,
|
static PikaObj* _obj_getObjDirect(PikaObj* self,
|
||||||
char* name,
|
char* name,
|
||||||
PIKA_BOOL* pIsTemp) {
|
pika_bool* pIsTemp) {
|
||||||
*pIsTemp = PIKA_FALSE;
|
*pIsTemp = pika_false;
|
||||||
if (NULL == self) {
|
if (NULL == self) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -867,7 +867,7 @@ static PikaObj* _obj_getObjDirect(PikaObj* self,
|
|||||||
/* found class */
|
/* found class */
|
||||||
if (type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
|
if (type == ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR ||
|
||||||
type == ARG_TYPE_METHOD_CONSTRUCTOR) {
|
type == ARG_TYPE_METHOD_CONSTRUCTOR) {
|
||||||
*pIsTemp = PIKA_TRUE;
|
*pIsTemp = pika_true;
|
||||||
PikaObj* method_args_obj = New_TinyObj(NULL);
|
PikaObj* method_args_obj = New_TinyObj(NULL);
|
||||||
Arg* cls_obj_arg = obj_runMethodArg(self, method_args_obj, arg_obj);
|
Arg* cls_obj_arg = obj_runMethodArg(self, method_args_obj, arg_obj);
|
||||||
obj_deinit(method_args_obj);
|
obj_deinit(method_args_obj);
|
||||||
@ -884,7 +884,7 @@ static PikaObj* _obj_getObjDirect(PikaObj* self,
|
|||||||
|
|
||||||
static PikaObj* _obj_getObjWithKeepDeepth(PikaObj* self,
|
static PikaObj* _obj_getObjWithKeepDeepth(PikaObj* self,
|
||||||
char* objPath,
|
char* objPath,
|
||||||
PIKA_BOOL* pIsTemp,
|
pika_bool* pIsTemp,
|
||||||
int32_t keepDeepth) {
|
int32_t keepDeepth) {
|
||||||
char objPath_buff[PIKA_PATH_BUFF_SIZE];
|
char objPath_buff[PIKA_PATH_BUFF_SIZE];
|
||||||
char* objPath_ptr = objPath_buff;
|
char* objPath_ptr = objPath_buff;
|
||||||
@ -912,19 +912,19 @@ exit:
|
|||||||
|
|
||||||
PikaObj* obj_getObj(PikaObj* self, char* objPath) {
|
PikaObj* obj_getObj(PikaObj* self, char* objPath) {
|
||||||
pika_assert(NULL != 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);
|
return _obj_getObjWithKeepDeepth(self, objPath, &is_temp, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
PikaObj* obj_getHostObj(PikaObj* self, char* objPath) {
|
PikaObj* obj_getHostObj(PikaObj* self, char* objPath) {
|
||||||
pika_assert(NULL != 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);
|
return _obj_getObjWithKeepDeepth(self, objPath, &is_temp, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
PikaObj* obj_getHostObjWithIsTemp(PikaObj* self,
|
PikaObj* obj_getHostObjWithIsTemp(PikaObj* self,
|
||||||
char* objPath,
|
char* objPath,
|
||||||
PIKA_BOOL* pIsTemp) {
|
pika_bool* pIsTemp) {
|
||||||
return _obj_getObjWithKeepDeepth(self, objPath, pIsTemp, 1);
|
return _obj_getObjWithKeepDeepth(self, objPath, pIsTemp, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1223,7 +1223,7 @@ enum PIKA_SHELL_STATE {
|
|||||||
|
|
||||||
static void _obj_runChar_beforeRun(PikaObj* self, ShellConfig* shell) {
|
static void _obj_runChar_beforeRun(PikaObj* self, ShellConfig* shell) {
|
||||||
/* create the line buff for the first time */
|
/* create the line buff for the first time */
|
||||||
shell->inBlock = PIKA_FALSE;
|
shell->inBlock = pika_false;
|
||||||
shell->stat = PIKA_SHELL_STATE_NORMAL;
|
shell->stat = PIKA_SHELL_STATE_NORMAL;
|
||||||
shell->line_position = 0;
|
shell->line_position = 0;
|
||||||
shell->line_curpos = 0;
|
shell->line_curpos = 0;
|
||||||
@ -1246,18 +1246,18 @@ typedef enum {
|
|||||||
__FILTER_SUCCESS_DROP_ALL_PEEKED
|
__FILTER_SUCCESS_DROP_ALL_PEEKED
|
||||||
} FilterReturn;
|
} FilterReturn;
|
||||||
|
|
||||||
PIKA_BOOL _filter_msg_hi_pika_handler(FilterItem* msg,
|
pika_bool _filter_msg_hi_pika_handler(FilterItem* msg,
|
||||||
PikaObj* self,
|
PikaObj* self,
|
||||||
ShellConfig* shell) {
|
ShellConfig* shell) {
|
||||||
pika_platform_printf("Yes, I am here\r\n");
|
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,
|
PikaObj* self,
|
||||||
ShellConfig* shell) {
|
ShellConfig* shell) {
|
||||||
pika_platform_printf("OK, see you\r\n");
|
pika_platform_printf("OK, see you\r\n");
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define __MSG_DECLARE
|
#define __MSG_DECLARE
|
||||||
@ -1485,7 +1485,7 @@ char* shHistory_getNext(ShellHistory* self) {
|
|||||||
|
|
||||||
static void handle_history_navigation(char inputChar,
|
static void handle_history_navigation(char inputChar,
|
||||||
ShellConfig* shell,
|
ShellConfig* shell,
|
||||||
PIKA_BOOL bIsUp) {
|
pika_bool bIsUp) {
|
||||||
#if PIKA_SHELL_HISTORY_ENABLE
|
#if PIKA_SHELL_HISTORY_ENABLE
|
||||||
if (NULL == shell->history) {
|
if (NULL == shell->history) {
|
||||||
shell->history = shHistory_create(PIKA_SHELL_HISTORY_NUM);
|
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) {
|
if (inputChar == PIKA_KEY_UP) {
|
||||||
_putc_cmd(PIKA_KEY_DOWN, 1);
|
_putc_cmd(PIKA_KEY_DOWN, 1);
|
||||||
ctrl = SHELL_CTRL_CONTINUE;
|
ctrl = SHELL_CTRL_CONTINUE;
|
||||||
handle_history_navigation(inputChar, shell, PIKA_TRUE);
|
handle_history_navigation(inputChar, shell, pika_true);
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
if (inputChar == PIKA_KEY_DOWN) {
|
if (inputChar == PIKA_KEY_DOWN) {
|
||||||
ctrl = SHELL_CTRL_CONTINUE;
|
ctrl = SHELL_CTRL_CONTINUE;
|
||||||
handle_history_navigation(inputChar, shell, PIKA_FALSE);
|
handle_history_navigation(inputChar, shell, pika_false);
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1658,7 +1658,7 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
|
|||||||
strsDeinit(&buffs);
|
strsDeinit(&buffs);
|
||||||
/* go out from block */
|
/* go out from block */
|
||||||
if ((shell->lineBuff[0] != ' ') && (shell->lineBuff[0] != '\t')) {
|
if ((shell->lineBuff[0] != ' ') && (shell->lineBuff[0] != '\t')) {
|
||||||
shell->inBlock = PIKA_FALSE;
|
shell->inBlock = pika_false;
|
||||||
input_line = obj_getStr(self, shell->blockBuffName);
|
input_line = obj_getStr(self, shell->blockBuffName);
|
||||||
ctrl = shell->handler(self, input_line, shell);
|
ctrl = shell->handler(self, input_line, shell);
|
||||||
__clearBuff(shell);
|
__clearBuff(shell);
|
||||||
@ -1674,7 +1674,7 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
|
|||||||
/* go in block */
|
/* go in block */
|
||||||
if (shell->blockBuffName != NULL && 0 != strGetSize(shell->lineBuff)) {
|
if (shell->blockBuffName != NULL && 0 != strGetSize(shell->lineBuff)) {
|
||||||
if (shell->lineBuff[strGetSize(shell->lineBuff) - 1] == ':') {
|
if (shell->lineBuff[strGetSize(shell->lineBuff) - 1] == ':') {
|
||||||
shell->inBlock = PIKA_TRUE;
|
shell->inBlock = pika_true;
|
||||||
char _n = '\n';
|
char _n = '\n';
|
||||||
strAppendWithSize(shell->lineBuff, &_n, 1);
|
strAppendWithSize(shell->lineBuff, &_n, 1);
|
||||||
obj_setStr(self, shell->blockBuffName, shell->lineBuff);
|
obj_setStr(self, shell->blockBuffName, shell->lineBuff);
|
||||||
@ -1706,11 +1706,11 @@ enum shellCTRL _do_obj_runChar(PikaObj* self,
|
|||||||
if (NULL == queue->buffer) {
|
if (NULL == queue->buffer) {
|
||||||
/* need initialize first */
|
/* need initialize first */
|
||||||
byteQueue_init(queue, &shell->filter_fifo.buffer,
|
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_bool result = byteQueue_writeOne(queue, inputChar);
|
||||||
pika_assert(result != PIKA_FALSE);
|
pika_assert(result != pika_false);
|
||||||
|
|
||||||
int16_t byte_count;
|
int16_t byte_count;
|
||||||
do {
|
do {
|
||||||
@ -1722,7 +1722,7 @@ enum shellCTRL _do_obj_runChar(PikaObj* self,
|
|||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
result = byteQueue_readOne(queue, (uint8_t*)&inputChar);
|
result = byteQueue_readOne(queue, (uint8_t*)&inputChar);
|
||||||
pika_assert(PIKA_FALSE != result);
|
pika_assert(pika_false != result);
|
||||||
|
|
||||||
if (SHELL_CTRL_EXIT ==
|
if (SHELL_CTRL_EXIT ==
|
||||||
_inner_do_obj_runChar(self, inputChar, shell)) {
|
_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* buff = pikaMalloc(PIKA_READ_FILE_BUFF_SIZE);
|
||||||
char input[2] = {0};
|
char input[2] = {0};
|
||||||
int buff_i = 0;
|
int buff_i = 0;
|
||||||
PIKA_BOOL is_exit = PIKA_FALSE;
|
pika_bool is_exit = pika_false;
|
||||||
PIKA_BOOL is_first_line = PIKA_TRUE;
|
pika_bool is_first_line = pika_true;
|
||||||
while (1) {
|
while (1) {
|
||||||
input[1] = input[0];
|
input[1] = input[0];
|
||||||
input[0] = cfg->fn_getchar();
|
input[0] = cfg->fn_getchar();
|
||||||
@ -1810,7 +1810,7 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
|
|||||||
}
|
}
|
||||||
if (is_first_line) {
|
if (is_first_line) {
|
||||||
if ('\n' == input[0]) {
|
if ('\n' == input[0]) {
|
||||||
is_first_line = PIKA_FALSE;
|
is_first_line = pika_false;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1842,7 +1842,7 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
|
|||||||
pika_platform_printf("=============== [ Run] ===============\r\n");
|
pika_platform_printf("=============== [ Run] ===============\r\n");
|
||||||
obj_run(self, (char*)buff);
|
obj_run(self, (char*)buff);
|
||||||
if (NULL != strstr(buff, "exit()")) {
|
if (NULL != strstr(buff, "exit()")) {
|
||||||
is_exit = PIKA_TRUE;
|
is_exit = pika_true;
|
||||||
}
|
}
|
||||||
pikaFree(buff, PIKA_READ_FILE_BUFF_SIZE);
|
pikaFree(buff, PIKA_READ_FILE_BUFF_SIZE);
|
||||||
if (is_exit) {
|
if (is_exit) {
|
||||||
@ -2004,7 +2004,7 @@ void method_returnInt(Args* args, int64_t val) {
|
|||||||
args_pushArg_name(args, "@rt", arg_newInt(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) {
|
if (val == _PIKA_BOOL_ERR) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2225,26 +2225,26 @@ int _pikaGC_markDumpHandler(PikaGC* gc) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PIKA_BOOL obj_checkAlive(PikaObj* self) {
|
pika_bool obj_checkAlive(PikaObj* self) {
|
||||||
#if !PIKA_GC_MARK_SWEEP_ENABLE
|
#if !PIKA_GC_MARK_SWEEP_ENABLE
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
#else
|
#else
|
||||||
PIKA_BOOL ret = PIKA_FALSE;
|
pika_bool ret = pika_false;
|
||||||
if (NULL == g_PikaObjState.gcChain) {
|
if (NULL == g_PikaObjState.gcChain) {
|
||||||
ret = PIKA_FALSE;
|
ret = pika_false;
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
PikaObj* obj = g_PikaObjState.gcChain;
|
PikaObj* obj = g_PikaObjState.gcChain;
|
||||||
while (NULL != obj) {
|
while (NULL != obj) {
|
||||||
if (obj == self) {
|
if (obj == self) {
|
||||||
ret = PIKA_TRUE;
|
ret = pika_true;
|
||||||
goto __exit;
|
goto __exit;
|
||||||
}
|
}
|
||||||
obj = obj->gcNext;
|
obj = obj->gcNext;
|
||||||
}
|
}
|
||||||
__exit:
|
__exit:
|
||||||
#if PIKA_KERNAL_DEBUG_ENABLE
|
#if PIKA_KERNAL_DEBUG_ENABLE
|
||||||
if (ret == PIKA_TRUE) {
|
if (ret == pika_true) {
|
||||||
self->isAlive = ret;
|
self->isAlive = ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2358,9 +2358,9 @@ void pikaGC_unlock(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PIKA_BOOL pikaGC_islock(void) {
|
pika_bool pikaGC_islock(void) {
|
||||||
#if !PIKA_GC_MARK_SWEEP_ENABLE
|
#if !PIKA_GC_MARK_SWEEP_ENABLE
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
#else
|
#else
|
||||||
return g_PikaObjState.markSweepBusy > 0;
|
return g_PikaObjState.markSweepBusy > 0;
|
||||||
#endif
|
#endif
|
||||||
@ -2381,7 +2381,7 @@ PikaObj* New_PikaObj(void) {
|
|||||||
self->aName = NULL;
|
self->aName = NULL;
|
||||||
self->name = "PikaObj";
|
self->name = "PikaObj";
|
||||||
self->parent = NULL;
|
self->parent = NULL;
|
||||||
self->isAlive = PIKA_TRUE;
|
self->isAlive = pika_true;
|
||||||
#endif
|
#endif
|
||||||
#if PIKA_GC_MARK_SWEEP_ENABLE && PIKA_KERNAL_DEBUG_ENABLE
|
#if PIKA_GC_MARK_SWEEP_ENABLE && PIKA_KERNAL_DEBUG_ENABLE
|
||||||
self->gcRoot = NULL;
|
self->gcRoot = NULL;
|
||||||
@ -2456,7 +2456,7 @@ PikaObj* obj_importModuleWithByteCode(PikaObj* self,
|
|||||||
Arg* aModule = obj_getArg((PikaObj*)__pikaMain, name);
|
Arg* aModule = obj_getArg((PikaObj*)__pikaMain, name);
|
||||||
PikaObj* oModule = arg_getPtr(aModule);
|
PikaObj* oModule = arg_getPtr(aModule);
|
||||||
obj_setArg(self, name, 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));
|
pika_assert(arg_isObject(aModule));
|
||||||
/* decrase refcnt to avoid circle reference */
|
/* decrase refcnt to avoid circle reference */
|
||||||
obj_refcntDec(oModule);
|
obj_refcntDec(oModule);
|
||||||
@ -2668,7 +2668,7 @@ static void _thread_event(void* arg) {
|
|||||||
void _do_pks_eventListener_send(PikaEventListener* self,
|
void _do_pks_eventListener_send(PikaEventListener* self,
|
||||||
uint32_t eventId,
|
uint32_t eventId,
|
||||||
Arg* eventData,
|
Arg* eventData,
|
||||||
PIKA_BOOL pickupWhenNoVM) {
|
pika_bool pickupWhenNoVM) {
|
||||||
#if !PIKA_EVENT_ENABLE
|
#if !PIKA_EVENT_ENABLE
|
||||||
pika_platform_printf("PIKA_EVENT_ENABLE is not enable");
|
pika_platform_printf("PIKA_EVENT_ENABLE is not enable");
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -2704,7 +2704,7 @@ void _do_pks_eventListener_send(PikaEventListener* self,
|
|||||||
void pks_eventListener_send(PikaEventListener* self,
|
void pks_eventListener_send(PikaEventListener* self,
|
||||||
uint32_t eventId,
|
uint32_t eventId,
|
||||||
Arg* eventData) {
|
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,
|
void pks_eventListener_sendSignal(PikaEventListener* self,
|
||||||
|
@ -89,8 +89,8 @@ struct PikaObj {
|
|||||||
char* name;
|
char* name;
|
||||||
Arg* aName;
|
Arg* aName;
|
||||||
PikaObj* parent;
|
PikaObj* parent;
|
||||||
PIKA_BOOL isAlive;
|
pika_bool isAlive;
|
||||||
PIKA_BOOL isGCRoot;
|
pika_bool isGCRoot;
|
||||||
#endif
|
#endif
|
||||||
#if PIKA_GC_MARK_SWEEP_ENABLE && PIKA_KERNAL_DEBUG_ENABLE
|
#if PIKA_GC_MARK_SWEEP_ENABLE && PIKA_KERNAL_DEBUG_ENABLE
|
||||||
PikaObj* gcRoot;
|
PikaObj* gcRoot;
|
||||||
@ -118,7 +118,7 @@ struct RangeData {
|
|||||||
typedef struct PikaObjState PikaObjState;
|
typedef struct PikaObjState PikaObjState;
|
||||||
struct PikaObjState {
|
struct PikaObjState {
|
||||||
Arg* helpModulesCmodule;
|
Arg* helpModulesCmodule;
|
||||||
PIKA_BOOL inRootObj;
|
pika_bool inRootObj;
|
||||||
#if PIKA_GC_MARK_SWEEP_ENABLE
|
#if PIKA_GC_MARK_SWEEP_ENABLE
|
||||||
PikaObj* gcChain;
|
PikaObj* gcChain;
|
||||||
uint32_t objCnt;
|
uint32_t objCnt;
|
||||||
@ -153,7 +153,7 @@ static inline void obj_setFlag(PikaObj* self, uint16_t flag) {
|
|||||||
self->flag |= flag;
|
self->flag |= flag;
|
||||||
#if PIKA_KERNAL_DEBUG_ENABLE
|
#if PIKA_KERNAL_DEBUG_ENABLE
|
||||||
if (flag == OBJ_FLAG_GC_ROOT) {
|
if (flag == OBJ_FLAG_GC_ROOT) {
|
||||||
self->isGCRoot = PIKA_TRUE;
|
self->isGCRoot = pika_true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ static inline void obj_clearFlag(PikaObj* self, uint16_t flag) {
|
|||||||
self->flag &= ~flag;
|
self->flag &= ~flag;
|
||||||
#if PIKA_KERNAL_DEBUG_ENABLE
|
#if PIKA_KERNAL_DEBUG_ENABLE
|
||||||
if (flag == OBJ_FLAG_GC_ROOT) {
|
if (flag == OBJ_FLAG_GC_ROOT) {
|
||||||
self->isGCRoot = PIKA_FALSE;
|
self->isGCRoot = pika_false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ void* obj_getPtr(PikaObj* self, char* argPath);
|
|||||||
pika_float obj_getFloat(PikaObj* self, char* argPath);
|
pika_float obj_getFloat(PikaObj* self, char* argPath);
|
||||||
char* obj_getStr(PikaObj* self, char* argPath);
|
char* obj_getStr(PikaObj* self, char* argPath);
|
||||||
int64_t obj_getInt(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);
|
Arg* obj_getArg(PikaObj* self, char* argPath);
|
||||||
uint8_t* obj_getBytes(PikaObj* self, char* argPath);
|
uint8_t* obj_getBytes(PikaObj* self, char* argPath);
|
||||||
size_t obj_getBytesSize(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_getHostObj(PikaObj* self, char* objPath);
|
||||||
PikaObj* obj_getHostObjWithIsTemp(PikaObj* self,
|
PikaObj* obj_getHostObjWithIsTemp(PikaObj* self,
|
||||||
char* objPath,
|
char* objPath,
|
||||||
PIKA_BOOL* pIsClass);
|
pika_bool* pIsClass);
|
||||||
|
|
||||||
// subProcess
|
// subProcess
|
||||||
int32_t obj_freeObj(PikaObj* self, char* subObjectName);
|
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_returnStr(Args* args, char* val);
|
||||||
void method_returnInt(Args* args, int64_t 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_returnFloat(Args* args, pika_float val);
|
||||||
void method_returnPtr(Args* args, void* val);
|
void method_returnPtr(Args* args, void* val);
|
||||||
void method_returnObj(Args* args, void* val);
|
void method_returnObj(Args* args, void* val);
|
||||||
@ -351,7 +351,7 @@ typedef struct FilterFIFO {
|
|||||||
|
|
||||||
typedef struct FilterItem FilterItem;
|
typedef struct FilterItem FilterItem;
|
||||||
|
|
||||||
typedef PIKA_BOOL FilterMessageHandler(FilterItem* msg,
|
typedef pika_bool FilterMessageHandler(FilterItem* msg,
|
||||||
PikaObj* self,
|
PikaObj* self,
|
||||||
ShellConfig* shell);
|
ShellConfig* shell);
|
||||||
|
|
||||||
@ -391,7 +391,7 @@ struct ShellConfig {
|
|||||||
size_t line_position;
|
size_t line_position;
|
||||||
size_t line_curpos;
|
size_t line_curpos;
|
||||||
char* blockBuffName;
|
char* blockBuffName;
|
||||||
PIKA_BOOL inBlock;
|
pika_bool inBlock;
|
||||||
char lastChar;
|
char lastChar;
|
||||||
sh_getchar fn_getchar;
|
sh_getchar fn_getchar;
|
||||||
uint8_t stat;
|
uint8_t stat;
|
||||||
@ -514,7 +514,7 @@ void pks_eventListener_removeEvent(PikaEventListener* self, uint32_t eventId);
|
|||||||
void _do_pks_eventListener_send(PikaEventListener* self,
|
void _do_pks_eventListener_send(PikaEventListener* self,
|
||||||
uint32_t eventId,
|
uint32_t eventId,
|
||||||
Arg* eventData,
|
Arg* eventData,
|
||||||
PIKA_BOOL pickupWhenNoVM);
|
pika_bool pickupWhenNoVM);
|
||||||
|
|
||||||
void pks_eventListener_sendSignal(PikaEventListener* self,
|
void pks_eventListener_sendSignal(PikaEventListener* self,
|
||||||
uint32_t eventId,
|
uint32_t eventId,
|
||||||
@ -560,7 +560,7 @@ static inline uint8_t obj_refcntNow(PikaObj* self) {
|
|||||||
__FUNCTION__)
|
__FUNCTION__)
|
||||||
|
|
||||||
char* obj_cacheStr(PikaObj* self, char* str);
|
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);
|
Arg* arg_toStrArg(Arg* arg);
|
||||||
|
|
||||||
#define PIKASCRIPT_VERSION_TO_NUM(majer, minor, micro) \
|
#define PIKASCRIPT_VERSION_TO_NUM(majer, minor, micro) \
|
||||||
@ -716,14 +716,14 @@ void obj_printModules(PikaObj* self);
|
|||||||
void obj_appendGcChain(PikaObj* self);
|
void obj_appendGcChain(PikaObj* self);
|
||||||
void obj_removeGcChain(PikaObj* self);
|
void obj_removeGcChain(PikaObj* self);
|
||||||
void obj_enableGC(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 obj_setName(PikaObj* self, char* name);
|
||||||
|
|
||||||
void pikaGC_mark(void);
|
void pikaGC_mark(void);
|
||||||
void pikaGC_markDump(void);
|
void pikaGC_markDump(void);
|
||||||
void pikaGC_lock(void);
|
void pikaGC_lock(void);
|
||||||
void pikaGC_unlock(void);
|
void pikaGC_unlock(void);
|
||||||
PIKA_BOOL pikaGC_islock(void);
|
pika_bool pikaGC_islock(void);
|
||||||
uint32_t pikaGC_count(void);
|
uint32_t pikaGC_count(void);
|
||||||
uint32_t pikaGC_countMarked(void);
|
uint32_t pikaGC_countMarked(void);
|
||||||
uint32_t pikaGC_markSweep(void);
|
uint32_t pikaGC_markSweep(void);
|
||||||
|
176
src/PikaParser.c
176
src/PikaParser.c
@ -55,7 +55,7 @@ void Cursor_deinit(struct Cursor* cs);
|
|||||||
|
|
||||||
/* Cursor high level api */
|
/* Cursor high level api */
|
||||||
char* Cursor_popToken(Args* buffs, char** pStmt, char* devide);
|
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* Cursor_splitCollect(Args* buffs, char* stmt, char* devide, int index);
|
||||||
|
|
||||||
char* pika_lines2Asm(Args* outBuffs, char* multiLine);
|
char* pika_lines2Asm(Args* outBuffs, char* multiLine);
|
||||||
@ -179,22 +179,22 @@ static enum StmtType Lexer_matchStmtType(char* right) {
|
|||||||
enum StmtType stmtType = STMT_none;
|
enum StmtType stmtType = STMT_none;
|
||||||
char* rightWithoutSubStmt = _remove_sub_stmt(&buffs, right);
|
char* rightWithoutSubStmt = _remove_sub_stmt(&buffs, right);
|
||||||
|
|
||||||
PIKA_BOOL is_get_operator = PIKA_FALSE;
|
pika_bool is_get_operator = pika_false;
|
||||||
PIKA_BOOL is_get_method = PIKA_FALSE;
|
pika_bool is_get_method = pika_false;
|
||||||
PIKA_BOOL is_get_string = PIKA_FALSE;
|
pika_bool is_get_string = pika_false;
|
||||||
PIKA_BOOL is_get_bytes = PIKA_FALSE;
|
pika_bool is_get_bytes = pika_false;
|
||||||
PIKA_BOOL is_get_number = PIKA_FALSE;
|
pika_bool is_get_number = pika_false;
|
||||||
PIKA_BOOL is_get_symbol = PIKA_FALSE;
|
pika_bool is_get_symbol = pika_false;
|
||||||
PIKA_BOOL is_get_list = PIKA_FALSE;
|
pika_bool is_get_list = pika_false;
|
||||||
PIKA_BOOL is_get_slice = PIKA_FALSE;
|
pika_bool is_get_slice = pika_false;
|
||||||
PIKA_BOOL is_get_dict = PIKA_FALSE;
|
pika_bool is_get_dict = pika_false;
|
||||||
PIKA_BOOL is_get_import = PIKA_FALSE;
|
pika_bool is_get_import = pika_false;
|
||||||
PIKA_BOOL is_get_chain = PIKA_FALSE;
|
pika_bool is_get_chain = pika_false;
|
||||||
Cursor_forEach(cs, rightWithoutSubStmt) {
|
Cursor_forEach(cs, rightWithoutSubStmt) {
|
||||||
Cursor_iterStart(&cs);
|
Cursor_iterStart(&cs);
|
||||||
/* collect type */
|
/* collect type */
|
||||||
if (strEqu(cs.token1.pyload, " import ")) {
|
if (strEqu(cs.token1.pyload, " import ")) {
|
||||||
is_get_import = PIKA_TRUE;
|
is_get_import = pika_true;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
if (strEqu(cs.token2.pyload, "[")) {
|
if (strEqu(cs.token2.pyload, "[")) {
|
||||||
@ -204,17 +204,17 @@ static enum StmtType Lexer_matchStmtType(char* right) {
|
|||||||
strEqu(cs.token1.pyload, "]") ||
|
strEqu(cs.token1.pyload, "]") ||
|
||||||
strEqu(cs.token1.pyload, ")")) {
|
strEqu(cs.token1.pyload, ")")) {
|
||||||
/* keep the last one of the chain or slice */
|
/* keep the last one of the chain or slice */
|
||||||
is_get_slice = PIKA_TRUE;
|
is_get_slice = pika_true;
|
||||||
is_get_chain = PIKA_FALSE;
|
is_get_chain = pika_false;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
/* ( <,> | <=> ) + <[> */
|
/* ( <,> | <=> ) + <[> */
|
||||||
is_get_list = PIKA_TRUE;
|
is_get_list = pika_true;
|
||||||
}
|
}
|
||||||
if (strEqu(cs.token1.pyload, "[") && cs.iter_index == 1) {
|
if (strEqu(cs.token1.pyload, "[") && cs.iter_index == 1) {
|
||||||
/* VOID + <[> */
|
/* VOID + <[> */
|
||||||
is_get_list = PIKA_TRUE;
|
is_get_list = pika_true;
|
||||||
is_get_method = PIKA_FALSE;
|
is_get_method = pika_false;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
if (strEqu(cs.token1.pyload, "...")) {
|
if (strEqu(cs.token1.pyload, "...")) {
|
||||||
@ -228,41 +228,41 @@ static enum StmtType Lexer_matchStmtType(char* right) {
|
|||||||
if (strIsStartWith(cs.token1.pyload, ".")) {
|
if (strIsStartWith(cs.token1.pyload, ".")) {
|
||||||
if (cs.iter_index != 1) {
|
if (cs.iter_index != 1) {
|
||||||
/* keep the last one of the chain or slice */
|
/* keep the last one of the chain or slice */
|
||||||
is_get_chain = PIKA_TRUE;
|
is_get_chain = pika_true;
|
||||||
is_get_slice = PIKA_FALSE;
|
is_get_slice = pika_false;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strEqu(cs.token1.pyload, "{")) {
|
if (strEqu(cs.token1.pyload, "{")) {
|
||||||
is_get_dict = PIKA_TRUE;
|
is_get_dict = pika_true;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
if (cs.token1.type == TOKEN_operator) {
|
if (cs.token1.type == TOKEN_operator) {
|
||||||
is_get_operator = PIKA_TRUE;
|
is_get_operator = pika_true;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
/* <(> */
|
/* <(> */
|
||||||
if (strEqu(cs.token1.pyload, "(")) {
|
if (strEqu(cs.token1.pyload, "(")) {
|
||||||
is_get_method = PIKA_TRUE;
|
is_get_method = pika_true;
|
||||||
is_get_slice = PIKA_FALSE;
|
is_get_slice = pika_false;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
if (cs.token1.type == TOKEN_literal) {
|
if (cs.token1.type == TOKEN_literal) {
|
||||||
if (cs.token1.pyload[0] == '\'' || cs.token1.pyload[0] == '"') {
|
if (cs.token1.pyload[0] == '\'' || cs.token1.pyload[0] == '"') {
|
||||||
is_get_string = PIKA_TRUE;
|
is_get_string = pika_true;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
if (cs.token1.pyload[1] == '\'' || cs.token1.pyload[1] == '"') {
|
if (cs.token1.pyload[1] == '\'' || cs.token1.pyload[1] == '"') {
|
||||||
if (cs.token1.pyload[0] == 'b') {
|
if (cs.token1.pyload[0] == 'b') {
|
||||||
is_get_bytes = PIKA_TRUE;
|
is_get_bytes = pika_true;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is_get_number = PIKA_TRUE;
|
is_get_number = pika_true;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
if (cs.token1.type == TOKEN_symbol) {
|
if (cs.token1.type == TOKEN_symbol) {
|
||||||
is_get_symbol = PIKA_TRUE;
|
is_get_symbol = pika_true;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
iter_continue:
|
iter_continue:
|
||||||
@ -978,24 +978,24 @@ void _Cursor_beforeIter(struct Cursor* cs) {
|
|||||||
|
|
||||||
uint8_t Token_isBranketStart(LexToken* token) {
|
uint8_t Token_isBranketStart(LexToken* token) {
|
||||||
if (token->type != TOKEN_devider) {
|
if (token->type != TOKEN_devider) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
if (strEqu(token->pyload, "(") || strEqu(token->pyload, "[") ||
|
if (strEqu(token->pyload, "(") || 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) {
|
uint8_t Token_isBranketEnd(LexToken* token) {
|
||||||
if (token->type != TOKEN_devider) {
|
if (token->type != TOKEN_devider) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
if (strEqu(token->pyload, ")") || strEqu(token->pyload, "]") ||
|
if (strEqu(token->pyload, ")") || 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) {
|
uint8_t Token_isBranket(LexToken* token) {
|
||||||
@ -1005,10 +1005,10 @@ uint8_t Token_isBranket(LexToken* token) {
|
|||||||
uint8_t _Cursor_count(char* stmt,
|
uint8_t _Cursor_count(char* stmt,
|
||||||
TokenType type,
|
TokenType type,
|
||||||
char* pyload,
|
char* pyload,
|
||||||
PIKA_BOOL bSkipbracket) {
|
pika_bool bSkipbracket) {
|
||||||
/* fast return */
|
/* fast return */
|
||||||
if (!strstr(stmt, pyload)) {
|
if (!strstr(stmt, pyload)) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
Args buffs = {0};
|
Args buffs = {0};
|
||||||
uint8_t res = 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) {
|
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) {
|
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) {
|
char* Cursor_popToken(Args* buffs, char** pStmt, char* devide) {
|
||||||
Arg* out_item = arg_newStr("");
|
Arg* out_item = arg_newStr("");
|
||||||
Arg* tokenStream_after = 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_forEach(cs, *pStmt) {
|
||||||
Cursor_iterStart(&cs);
|
Cursor_iterStart(&cs);
|
||||||
if (!is_find_devide) {
|
if (!is_find_devide) {
|
||||||
if ((cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, devide)) ||
|
if ((cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, devide)) ||
|
||||||
cs.iter_index == cs.length) {
|
cs.iter_index == cs.length) {
|
||||||
is_find_devide = PIKA_TRUE;
|
is_find_devide = pika_true;
|
||||||
Cursor_iterEnd(&cs);
|
Cursor_iterEnd(&cs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1282,31 +1282,31 @@ char* Suger_format(Args* outBuffs, char* right) {
|
|||||||
return right;
|
return right;
|
||||||
}
|
}
|
||||||
|
|
||||||
PIKA_BOOL is_format = PIKA_FALSE;
|
pika_bool is_format = pika_false;
|
||||||
Cursor_forEach(ps1, right) {
|
Cursor_forEach(ps1, right) {
|
||||||
Cursor_iterStart(&ps1);
|
Cursor_iterStart(&ps1);
|
||||||
if (ps1.bracket_deepth == 0 && strEqu(ps1.token1.pyload, "%")) {
|
if (ps1.bracket_deepth == 0 && strEqu(ps1.token1.pyload, "%")) {
|
||||||
is_format = PIKA_TRUE;
|
is_format = pika_true;
|
||||||
}
|
}
|
||||||
Cursor_iterEnd(&ps1);
|
Cursor_iterEnd(&ps1);
|
||||||
}
|
}
|
||||||
Cursor_deinit(&ps1);
|
Cursor_deinit(&ps1);
|
||||||
if (PIKA_FALSE == is_format) {
|
if (pika_false == is_format) {
|
||||||
return right;
|
return right;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* res = right;
|
char* res = right;
|
||||||
Arg* str_buf = arg_newStr("");
|
Arg* str_buf = arg_newStr("");
|
||||||
Arg* var_buf = arg_newStr("");
|
Arg* var_buf = arg_newStr("");
|
||||||
PIKA_BOOL is_in_format = PIKA_FALSE;
|
pika_bool is_in_format = pika_false;
|
||||||
PIKA_BOOL is_tuple = PIKA_FALSE;
|
pika_bool is_tuple = pika_false;
|
||||||
PIKA_BOOL is_out_vars = PIKA_FALSE;
|
pika_bool is_out_vars = pika_false;
|
||||||
Args buffs = {0};
|
Args buffs = {0};
|
||||||
char* fmt = NULL;
|
char* fmt = NULL;
|
||||||
Cursor_forEach(cs, right) {
|
Cursor_forEach(cs, right) {
|
||||||
char* item = "";
|
char* item = "";
|
||||||
Cursor_iterStart(&cs);
|
Cursor_iterStart(&cs);
|
||||||
if (PIKA_FALSE == is_in_format) {
|
if (pika_false == is_in_format) {
|
||||||
if (cs.token1.type != TOKEN_literal) {
|
if (cs.token1.type != TOKEN_literal) {
|
||||||
item = cs.token1.pyload;
|
item = cs.token1.pyload;
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
@ -1320,16 +1320,16 @@ char* Suger_format(Args* outBuffs, char* right) {
|
|||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
/* found the format stmt */
|
/* found the format stmt */
|
||||||
is_in_format = PIKA_TRUE;
|
is_in_format = pika_true;
|
||||||
fmt = strsCopy(&buffs, cs.token1.pyload);
|
fmt = strsCopy(&buffs, cs.token1.pyload);
|
||||||
goto iter_continue;
|
goto iter_continue;
|
||||||
}
|
}
|
||||||
if (PIKA_TRUE == is_in_format) {
|
if (pika_true == is_in_format) {
|
||||||
/* check the format vars */
|
/* check the format vars */
|
||||||
if (strEqu(cs.token1.pyload, "%")) {
|
if (strEqu(cs.token1.pyload, "%")) {
|
||||||
/* is a tuple */
|
/* is a tuple */
|
||||||
if (strEqu(cs.token2.pyload, "(")) {
|
if (strEqu(cs.token2.pyload, "(")) {
|
||||||
is_tuple = PIKA_TRUE;
|
is_tuple = pika_true;
|
||||||
} else {
|
} else {
|
||||||
var_buf = arg_strAppend(var_buf, cs.token2.pyload);
|
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 */
|
/* found the end of tuple */
|
||||||
if (cs.iter_index == cs.length) {
|
if (cs.iter_index == cs.length) {
|
||||||
is_out_vars = PIKA_TRUE;
|
is_out_vars = pika_true;
|
||||||
is_in_format = PIKA_FALSE;
|
is_in_format = pika_false;
|
||||||
} else {
|
} else {
|
||||||
/* push the vars inner the tuple */
|
/* push the vars inner the tuple */
|
||||||
var_buf = arg_strAppend(var_buf, cs.token2.pyload);
|
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* aSubstmt = arg_newStr("");
|
||||||
Arg* aNewStmt = arg_newStr("");
|
Arg* aNewStmt = arg_newStr("");
|
||||||
char* sStmt = *psStmt;
|
char* sStmt = *psStmt;
|
||||||
PIKA_BOOL bIsGetSubstmt = PIKA_FALSE;
|
pika_bool bIsGetSubstmt = pika_false;
|
||||||
Args buffs = {0};
|
Args buffs = {0};
|
||||||
Cursor_forEach(cs, sStmt) {
|
Cursor_forEach(cs, sStmt) {
|
||||||
Cursor_iterStart(&cs);
|
Cursor_iterStart(&cs);
|
||||||
@ -1494,7 +1494,7 @@ char* Parser_popSubStmt(Args* outbuffs, char** psStmt, char* delimiter) {
|
|||||||
}
|
}
|
||||||
if (strEqu(cs.token1.pyload, delimiter)) {
|
if (strEqu(cs.token1.pyload, delimiter)) {
|
||||||
/* found delimiter */
|
/* found delimiter */
|
||||||
bIsGetSubstmt = PIKA_TRUE;
|
bIsGetSubstmt = pika_true;
|
||||||
Cursor_iterEnd(&cs);
|
Cursor_iterEnd(&cs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1516,13 +1516,13 @@ int Parser_getSubStmtNum(char* subStmts, char* delimiter) {
|
|||||||
if (strEqu(subStmts, ",")) {
|
if (strEqu(subStmts, ",")) {
|
||||||
return 0;
|
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* _Parser_popLastSubStmt(Args* outbuffs,
|
||||||
char** stmt_p,
|
char** stmt_p,
|
||||||
char* delimiter,
|
char* delimiter,
|
||||||
PIKA_BOOL bSkipBracket) {
|
pika_bool bSkipBracket) {
|
||||||
uint8_t last_stmt_i = 0;
|
uint8_t last_stmt_i = 0;
|
||||||
char* stmt = *stmt_p;
|
char* stmt = *stmt_p;
|
||||||
Cursor_forEach(cs, stmt) {
|
Cursor_forEach(cs, stmt) {
|
||||||
@ -1570,7 +1570,7 @@ char* _Parser_popLastSubStmt(Args* outbuffs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
char* Parser_popLastSubStmt(Args* outbuffs, char** stmt_p, char* delimiter) {
|
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) {
|
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
|
#endif
|
||||||
AST_setNodeAttr(ast, (char*)"slice", "slice");
|
AST_setNodeAttr(ast, (char*)"slice", "slice");
|
||||||
stmt = strsCopy(buffs, stmt);
|
stmt = strsCopy(buffs, stmt);
|
||||||
char* laststmt = _Parser_popLastSubStmt(buffs, &stmt, "[", PIKA_FALSE);
|
char* laststmt = _Parser_popLastSubStmt(buffs, &stmt, "[", pika_false);
|
||||||
AST_parseSubStmt(ast, stmt);
|
AST_parseSubStmt(ast, stmt);
|
||||||
char* slice_list = strsCut(buffs, laststmt, '[', ']');
|
char* slice_list = strsCut(buffs, laststmt, '[', ']');
|
||||||
pika_assert(slice_list != NULL);
|
pika_assert(slice_list != NULL);
|
||||||
@ -1645,8 +1645,8 @@ char* _Suger_process(Args* out_buffs,
|
|||||||
char* ret = line;
|
char* ret = line;
|
||||||
char* stmt1 = "";
|
char* stmt1 = "";
|
||||||
char* stmt2 = "";
|
char* stmt2 = "";
|
||||||
PIKA_BOOL got_tokens = PIKA_FALSE;
|
pika_bool got_tokens = pika_false;
|
||||||
PIKA_BOOL skip = PIKA_FALSE;
|
pika_bool skip = pika_false;
|
||||||
Args buffs = {0};
|
Args buffs = {0};
|
||||||
|
|
||||||
if (1 != Cursor_count(line, TOKEN_operator, token1)) {
|
if (1 != Cursor_count(line, TOKEN_operator, token1)) {
|
||||||
@ -1663,14 +1663,14 @@ char* _Suger_process(Args* out_buffs,
|
|||||||
if (!got_tokens) {
|
if (!got_tokens) {
|
||||||
if (strEqu(cs.token1.pyload, token1) &&
|
if (strEqu(cs.token1.pyload, token1) &&
|
||||||
strEqu(cs.token2.pyload, token2)) {
|
strEqu(cs.token2.pyload, token2)) {
|
||||||
got_tokens = PIKA_TRUE;
|
got_tokens = pika_true;
|
||||||
Cursor_iterEnd(&cs);
|
Cursor_iterEnd(&cs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
stmt1 = strsAppend(&buffs, stmt1, cs.token1.pyload);
|
stmt1 = strsAppend(&buffs, stmt1, cs.token1.pyload);
|
||||||
} else {
|
} else {
|
||||||
if (!skip) {
|
if (!skip) {
|
||||||
skip = PIKA_TRUE;
|
skip = pika_true;
|
||||||
Cursor_iterEnd(&cs);
|
Cursor_iterEnd(&cs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1821,13 +1821,13 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
|
|||||||
char* laststmt = methodstmt;
|
char* laststmt = methodstmt;
|
||||||
/* for method()() */
|
/* for method()() */
|
||||||
int iBracketNum =
|
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) {
|
if (iBracketNum > 1) {
|
||||||
laststmt =
|
laststmt =
|
||||||
_Parser_popLastSubStmt(&buffs, &methodstmt, "(", PIKA_FALSE);
|
_Parser_popLastSubStmt(&buffs, &methodstmt, "(", pika_false);
|
||||||
/* for (...) */
|
/* for (...) */
|
||||||
if (_Cursor_count(laststmt, TOKEN_devider, "(", PIKA_FALSE) == 1) {
|
if (_Cursor_count(laststmt, TOKEN_devider, "(", pika_false) == 1) {
|
||||||
char* sMethodCheck = strsGetFirstToken(&buffs, laststmt, '(');
|
char* sMethodCheck = strsGetFirstToken(&buffs, laststmt, '(');
|
||||||
if (strEqu(sMethodCheck, "")) {
|
if (strEqu(sMethodCheck, "")) {
|
||||||
laststmt = strsAppend(&buffs, ".", laststmt);
|
laststmt = strsAppend(&buffs, ".", laststmt);
|
||||||
@ -1993,7 +1993,7 @@ char* _defGetDefault(Args* outBuffs, char** psDeclearOut) {
|
|||||||
char* sArgList = strsCut(&buffs, sDeclear, '(', ')');
|
char* sArgList = strsCut(&buffs, sDeclear, '(', ')');
|
||||||
char* sDefaultOut = NULL;
|
char* sDefaultOut = NULL;
|
||||||
pika_assert(NULL != sArgList);
|
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++) {
|
for (int i = 0; i < iArgNum; i++) {
|
||||||
char* sItem = Cursor_popToken(&buffs, &sArgList, ",");
|
char* sItem = Cursor_popToken(&buffs, &sArgList, ",");
|
||||||
char* sDefaultVal = NULL;
|
char* sDefaultVal = NULL;
|
||||||
@ -2360,15 +2360,15 @@ exit:
|
|||||||
return strsReturnOut(&buffs, out_buffs, line_out);
|
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
|
#if PIKA_NANO_ENABLE
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
#endif
|
#endif
|
||||||
PIKA_BOOL res = PIKA_FALSE;
|
pika_bool res = pika_false;
|
||||||
Cursor_forEach(cs, arg_list) {
|
Cursor_forEach(cs, arg_list) {
|
||||||
Cursor_iterStart(&cs);
|
Cursor_iterStart(&cs);
|
||||||
if ((cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, ","))) {
|
if ((cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, ","))) {
|
||||||
res = PIKA_TRUE;
|
res = pika_true;
|
||||||
}
|
}
|
||||||
Cursor_iterEnd(&cs);
|
Cursor_iterEnd(&cs);
|
||||||
}
|
}
|
||||||
@ -2383,7 +2383,7 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) {
|
|||||||
Args buffs = {0};
|
Args buffs = {0};
|
||||||
char* line_out = line;
|
char* line_out = line;
|
||||||
int space_num = _getSpaceNum(line);
|
int space_num = _getSpaceNum(line);
|
||||||
PIKA_BOOL is_assign = PIKA_FALSE;
|
pika_bool is_assign = pika_false;
|
||||||
Arg* stmt = arg_newStr("");
|
Arg* stmt = arg_newStr("");
|
||||||
Arg* out_list = arg_newStr("");
|
Arg* out_list = arg_newStr("");
|
||||||
Arg* out_item = 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_forEach(cs, line) {
|
||||||
Cursor_iterStart(&cs);
|
Cursor_iterStart(&cs);
|
||||||
if (cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, "=")) {
|
if (cs.bracket_deepth == 0 && strEqu(cs.token1.pyload, "=")) {
|
||||||
is_assign = PIKA_TRUE;
|
is_assign = pika_true;
|
||||||
Cursor_iterEnd(&cs);
|
Cursor_iterEnd(&cs);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -2874,7 +2874,7 @@ PIKA_RES pika_lines2Bytes(ByteCodeFrame* bf, char* py_lines) {
|
|||||||
return PIKA_RES_ERR_SYNTAX_ERROR;
|
return PIKA_RES_ERR_SYNTAX_ERROR;
|
||||||
#else
|
#else
|
||||||
Parser* parser = New_parser();
|
Parser* parser = New_parser();
|
||||||
parser->isGenBytecode = PIKA_TRUE;
|
parser->isGenBytecode = pika_true;
|
||||||
parser->bytecode_frame = bf;
|
parser->bytecode_frame = bf;
|
||||||
if (1 == (uintptr_t)parser_lines2BackendCode(parser, py_lines)) {
|
if (1 == (uintptr_t)parser_lines2BackendCode(parser, py_lines)) {
|
||||||
parser_deinit(parser);
|
parser_deinit(parser);
|
||||||
@ -2887,7 +2887,7 @@ PIKA_RES pika_lines2Bytes(ByteCodeFrame* bf, char* py_lines) {
|
|||||||
|
|
||||||
char* pika_lines2Asm(Args* outBuffs, char* multi_line) {
|
char* pika_lines2Asm(Args* outBuffs, char* multi_line) {
|
||||||
Parser* parser = New_parser();
|
Parser* parser = New_parser();
|
||||||
parser->isGenBytecode = PIKA_FALSE;
|
parser->isGenBytecode = pika_false;
|
||||||
char* sAsm = parser_lines2BackendCode(parser, multi_line);
|
char* sAsm = parser_lines2BackendCode(parser, multi_line);
|
||||||
if (NULL == sAsm) {
|
if (NULL == sAsm) {
|
||||||
parser_deinit(parser);
|
parser_deinit(parser);
|
||||||
@ -3245,7 +3245,7 @@ char* AST_genAsm(AST* oAST, Args* outBuffs) {
|
|||||||
#if !PIKA_NANO_ENABLE
|
#if !PIKA_NANO_ENABLE
|
||||||
if (NULL != sDefaultStmts) {
|
if (NULL != sDefaultStmts) {
|
||||||
int iStmtNum =
|
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++) {
|
for (int i = 0; i < iStmtNum; i++) {
|
||||||
char* sStmt = Cursor_popToken(&buffs, &sDefaultStmts, ",");
|
char* sStmt = Cursor_popToken(&buffs, &sDefaultStmts, ",");
|
||||||
char* sArgName = strsGetFirstToken(&buffs, sStmt, '=');
|
char* sArgName = strsGetFirstToken(&buffs, sStmt, '=');
|
||||||
@ -3341,8 +3341,8 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define IS_SPACE_OR_TAB(ch) ((ch) == ' ' || (ch) == '\t')
|
#define IS_SPACE_OR_TAB(ch) ((ch) == ' ' || (ch) == '\t')
|
||||||
static PIKA_BOOL _strCheckCodeBlockFlag(char* sLine) {
|
static pika_bool _strCheckCodeBlockFlag(char* sLine) {
|
||||||
PIKA_BOOL bStart = PIKA_FALSE, bEnd = PIKA_FALSE;
|
pika_bool bStart = pika_false, bEnd = pika_false;
|
||||||
char *pStart = sLine, *pEnd = sLine + strlen(sLine) - 1;
|
char *pStart = sLine, *pEnd = sLine + strlen(sLine) - 1;
|
||||||
while (pStart <= pEnd && IS_SPACE_OR_TAB(*pStart)) {
|
while (pStart <= pEnd && IS_SPACE_OR_TAB(*pStart)) {
|
||||||
pStart++;
|
pStart++;
|
||||||
@ -3351,21 +3351,21 @@ static PIKA_BOOL _strCheckCodeBlockFlag(char* sLine) {
|
|||||||
pEnd--;
|
pEnd--;
|
||||||
}
|
}
|
||||||
if (pEnd - pStart < 2) {
|
if (pEnd - pStart < 2) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
if (strncmp(pStart, "```", 3) == 0) {
|
if (strncmp(pStart, "```", 3) == 0) {
|
||||||
bStart = PIKA_TRUE;
|
bStart = pika_true;
|
||||||
}
|
}
|
||||||
if (pEnd - pStart >= 5 && strncmp(pEnd - 2, "```", 3) == 0) {
|
if (pEnd - pStart >= 5 && strncmp(pEnd - 2, "```", 3) == 0) {
|
||||||
bEnd = PIKA_TRUE;
|
bEnd = pika_true;
|
||||||
}
|
}
|
||||||
if (bStart && bEnd) {
|
if (bStart && bEnd) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
if (bStart || bEnd) {
|
if (bStart || bEnd) {
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
}
|
}
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* _parser_fixDocStringIndent(Parser* self,
|
static char* _parser_fixDocStringIndent(Parser* self,
|
||||||
@ -3376,7 +3376,7 @@ static char* _parser_fixDocStringIndent(Parser* self,
|
|||||||
Arg* aOut = arg_newStr("");
|
Arg* aOut = arg_newStr("");
|
||||||
char* sOut = NULL;
|
char* sOut = NULL;
|
||||||
uint32_t iLineNum = strCountSign(sBuff, '\n');
|
uint32_t iLineNum = strCountSign(sBuff, '\n');
|
||||||
PIKA_BOOL bInCodeBlock = PIKA_FALSE;
|
pika_bool bInCodeBlock = pika_false;
|
||||||
int iIndentCodeBlock = 0;
|
int iIndentCodeBlock = 0;
|
||||||
for (int i = 0; i < iLineNum; i++) {
|
for (int i = 0; i < iLineNum; i++) {
|
||||||
char* sLine = strsPopToken(&buffs, &sBuff, '\n');
|
char* sLine = strsPopToken(&buffs, &sBuff, '\n');
|
||||||
@ -3385,7 +3385,7 @@ static char* _parser_fixDocStringIndent(Parser* self,
|
|||||||
}
|
}
|
||||||
int iIndentThis = strGetIndent(sLine);
|
int iIndentThis = strGetIndent(sLine);
|
||||||
int iIndentStrip = iIndentThis;
|
int iIndentStrip = iIndentThis;
|
||||||
PIKA_BOOL bCodeBlockFlag = _strCheckCodeBlockFlag(sLine);
|
pika_bool bCodeBlockFlag = _strCheckCodeBlockFlag(sLine);
|
||||||
if (bCodeBlockFlag) {
|
if (bCodeBlockFlag) {
|
||||||
bInCodeBlock = !bInCodeBlock;
|
bInCodeBlock = !bInCodeBlock;
|
||||||
iIndentCodeBlock = iIndentStrip;
|
iIndentCodeBlock = iIndentStrip;
|
||||||
|
@ -95,7 +95,7 @@ struct Parser {
|
|||||||
Args genBuffs;
|
Args genBuffs;
|
||||||
BlockState blockState;
|
BlockState blockState;
|
||||||
fn_parser_Ast2BeckendCode fn_ast2BeckendCode;
|
fn_parser_Ast2BeckendCode fn_ast2BeckendCode;
|
||||||
PIKA_BOOL isGenBytecode;
|
pika_bool isGenBytecode;
|
||||||
ByteCodeFrame* bytecode_frame;
|
ByteCodeFrame* bytecode_frame;
|
||||||
uint8_t thisBlockDeepth;
|
uint8_t thisBlockDeepth;
|
||||||
};
|
};
|
||||||
@ -148,7 +148,7 @@ uint8_t Cursor_count(char* stmt, TokenType type, char* pyload);
|
|||||||
uint8_t _Cursor_count(char* stmt,
|
uint8_t _Cursor_count(char* stmt,
|
||||||
TokenType type,
|
TokenType type,
|
||||||
char* pyload,
|
char* pyload,
|
||||||
PIKA_BOOL bSkipbracket);
|
pika_bool bSkipbracket);
|
||||||
|
|
||||||
AST* AST_parseStmt(AST* ast, char* stmt);
|
AST* AST_parseStmt(AST* ast, char* stmt);
|
||||||
char* AST_genAsm(AST* oAST, Args* outBuffs);
|
char* AST_genAsm(AST* oAST, Args* outBuffs);
|
||||||
|
@ -159,17 +159,17 @@ int pika_pvsprintf(char** buff, const char* fmt, va_list args) {
|
|||||||
return required_size;
|
return required_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PIKA_BOOL _check_no_buff_format(char* format) {
|
static pika_bool _check_no_buff_format(char* format) {
|
||||||
while (*format) {
|
while (*format) {
|
||||||
if (*format == '%') {
|
if (*format == '%') {
|
||||||
++format;
|
++format;
|
||||||
if (*format != 's' && *format != '%') {
|
if (*format != 's' && *format != '%') {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++format;
|
++format;
|
||||||
}
|
}
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _no_buff_vprintf(char* fmt, va_list args) {
|
static int _no_buff_vprintf(char* fmt, va_list args) {
|
||||||
@ -379,8 +379,8 @@ PIKA_WEAK void pika_hook_instruct(void) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PIKA_WEAK PIKA_BOOL pika_hook_arg_cache_filter(void* self) {
|
PIKA_WEAK pika_bool pika_hook_arg_cache_filter(void* self) {
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PIKA_WEAK void pika_platform_thread_delay(void) {
|
PIKA_WEAK void pika_platform_thread_delay(void) {
|
||||||
|
@ -111,9 +111,10 @@ typedef enum {
|
|||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
/* pikascript bool type */
|
/* pikascript bool type */
|
||||||
#define PIKA_BOOL int64_t
|
#define pika_bool int64_t
|
||||||
#define PIKA_TRUE 1
|
#define pika_true 1
|
||||||
#define PIKA_FALSE 0
|
#define pika_false 0
|
||||||
|
|
||||||
#define _PIKA_BOOL_ERR -1
|
#define _PIKA_BOOL_ERR -1
|
||||||
|
|
||||||
#define _PIKA_INT_ERR (-999999999)
|
#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_platform_sleep_ms(uint32_t ms);
|
||||||
|
|
||||||
void pika_hook_instruct(void);
|
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_malloc(size_t size);
|
||||||
void pika_user_free(void* ptr, size_t size);
|
void pika_user_free(void* ptr, size_t size);
|
||||||
uint8_t pika_is_locked_pikaMemory(void);
|
uint8_t pika_is_locked_pikaMemory(void);
|
||||||
|
280
src/PikaVM.c
280
src/PikaVM.c
@ -41,6 +41,7 @@ static pika_platform_thread_mutex_t g_pikaGIL = {0};
|
|||||||
volatile VMSignal g_PikaVMSignal = {.signal_ctrl = VM_SIGNAL_CTRL_NONE,
|
volatile VMSignal g_PikaVMSignal = {.signal_ctrl = VM_SIGNAL_CTRL_NONE,
|
||||||
|
|
||||||
.vm_cnt = 0,
|
.vm_cnt = 0,
|
||||||
|
.vm_now = NULL,
|
||||||
#if PIKA_EVENT_ENABLE
|
#if PIKA_EVENT_ENABLE
|
||||||
.cq =
|
.cq =
|
||||||
{
|
{
|
||||||
@ -56,7 +57,7 @@ volatile VMSignal g_PikaVMSignal = {.signal_ctrl = VM_SIGNAL_CTRL_NONE,
|
|||||||
extern volatile PikaObjState g_PikaObjState;
|
extern volatile PikaObjState g_PikaObjState;
|
||||||
|
|
||||||
/* private */
|
/* private */
|
||||||
static PIKA_BOOL _checkLReg(char* data);
|
static pika_bool _checkLReg(char* data);
|
||||||
static uint8_t _getLRegIndex(char* data);
|
static uint8_t _getLRegIndex(char* data);
|
||||||
static PikaObj* New_Locals(Args* args);
|
static PikaObj* New_Locals(Args* args);
|
||||||
char* string_slice(Args* outBuffs, char* str, int start, int end);
|
char* string_slice(Args* outBuffs, char* str, int start, int end);
|
||||||
@ -124,23 +125,23 @@ int _VMEvent_getEventPickupCnt(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if PIKA_EVENT_ENABLE
|
#if PIKA_EVENT_ENABLE
|
||||||
static PIKA_BOOL _ecq_isEmpty(volatile EventCQ* cq) {
|
static pika_bool _ecq_isEmpty(volatile EventCQ* cq) {
|
||||||
return (PIKA_BOOL)(cq->head == cq->tail);
|
return (pika_bool)(cq->head == cq->tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PIKA_BOOL _ecq_isFull(volatile EventCQ* cq) {
|
static pika_bool _ecq_isFull(volatile EventCQ* cq) {
|
||||||
return (PIKA_BOOL)((cq->tail + 1) % PIKA_EVENT_LIST_SIZE == cq->head);
|
return (pika_bool)((cq->tail + 1) % PIKA_EVENT_LIST_SIZE == cq->head);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PIKA_SETJMP_ENABLE
|
#if PIKA_SETJMP_ENABLE
|
||||||
|
|
||||||
static PIKA_BOOL _jcq_isEmpty(volatile JmpBufCQ* cq) {
|
static pika_bool _jcq_isEmpty(volatile JmpBufCQ* cq) {
|
||||||
return (PIKA_BOOL)(cq->head == cq->tail);
|
return (pika_bool)(cq->head == cq->tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PIKA_BOOL _jcq_isFull(volatile JmpBufCQ* cq) {
|
static pika_bool _jcq_isFull(volatile JmpBufCQ* cq) {
|
||||||
return (PIKA_BOOL)((cq->tail + 1) % PIKA_JMP_BUF_LIST_SIZE == cq->head);
|
return (pika_bool)((cq->tail + 1) % PIKA_JMP_BUF_LIST_SIZE == cq->head);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jmp_buf* _jcq_pop(volatile JmpBufCQ* cq) {
|
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;
|
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;
|
g_PikaVMSignal.signal_ctrl = VM_SIGNAL_CTRL_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,16 +555,16 @@ static int arg_getLen(Arg* self) {
|
|||||||
|
|
||||||
static void VMState_initReg(VMState* self) {
|
static void VMState_initReg(VMState* self) {
|
||||||
for (uint8_t i = 0; i < PIKA_REGIST_SIZE; i++) {
|
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') &&
|
if ((data[0] == '$') && (data[1] == 'l') && (data[2] >= '0') &&
|
||||||
(data[2] <= '9')) {
|
(data[2] <= '9')) {
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
}
|
}
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t _getLRegIndex(char* data) {
|
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 (ARG_TYPE_STRING == eType) {
|
||||||
#if PIKA_STRING_UTF8_ENABLE
|
#if PIKA_STRING_UTF8_ENABLE
|
||||||
PIKA_BOOL bIsTemp = PIKA_FALSE;
|
pika_bool bIsTemp = pika_false;
|
||||||
aObjNew = arg_newObj(_arg_to_obj(aObj, &bIsTemp));
|
aObjNew = arg_newObj(_arg_to_obj(aObj, &bIsTemp));
|
||||||
eType = arg_getType(aObjNew);
|
eType = arg_getType(aObjNew);
|
||||||
#else
|
#else
|
||||||
@ -667,7 +668,7 @@ Arg* _vm_get(VMState* vm, PikaObj* self, Arg* aKey, Arg* aObj) {
|
|||||||
if (NULL != vm) {
|
if (NULL != vm) {
|
||||||
aRes = _do_pikaVM_runByteCodeReturn(oArg, oArg, oArg,
|
aRes = _do_pikaVM_runByteCodeReturn(oArg, oArg, oArg,
|
||||||
(uint8_t*)bytes, vm->run_state,
|
(uint8_t*)bytes, vm->run_state,
|
||||||
PIKA_TRUE, "@res_item");
|
pika_true, "@res_item");
|
||||||
} else {
|
} else {
|
||||||
aRes = pikaVM_runByteCodeReturn(oArg, (uint8_t*)bytes, "@res_item");
|
aRes = pikaVM_runByteCodeReturn(oArg, (uint8_t*)bytes, "@res_item");
|
||||||
}
|
}
|
||||||
@ -929,17 +930,17 @@ static Arg* VM_instruction_handler_REF(PikaObj* self,
|
|||||||
PikaObj* oHost = NULL;
|
PikaObj* oHost = NULL;
|
||||||
char* arg_path = data;
|
char* arg_path = data;
|
||||||
char* arg_name = strPointToLastToken(arg_path, '.');
|
char* arg_name = strPointToLastToken(arg_path, '.');
|
||||||
PIKA_BOOL is_temp = PIKA_FALSE;
|
pika_bool is_temp = pika_false;
|
||||||
|
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case 'T':
|
case 'T':
|
||||||
if (strEqu(arg_path, (char*)"True")) {
|
if (strEqu(arg_path, (char*)"True")) {
|
||||||
return arg_setBool(aRetReg, "", PIKA_TRUE);
|
return arg_setBool(aRetReg, "", pika_true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
if (strEqu(arg_path, (char*)"False")) {
|
if (strEqu(arg_path, (char*)"False")) {
|
||||||
return arg_setBool(aRetReg, "", PIKA_FALSE);
|
return arg_setBool(aRetReg, "", pika_false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
@ -1232,25 +1233,25 @@ static void _type_list_parse(FunctionArgsInfo* f) {
|
|||||||
/* default */
|
/* default */
|
||||||
if (iAssign > 0) {
|
if (iAssign > 0) {
|
||||||
iArgc -= iAssign;
|
iArgc -= iAssign;
|
||||||
f->is_default = PIKA_TRUE;
|
f->is_default = pika_true;
|
||||||
f->n_default = iAssign;
|
f->n_default = iAssign;
|
||||||
}
|
}
|
||||||
/* vars */
|
/* vars */
|
||||||
if (iStar == 1) {
|
if (iStar == 1) {
|
||||||
f->is_vars = PIKA_TRUE;
|
f->is_vars = pika_true;
|
||||||
f->n_positional = iArgc - 1;
|
f->n_positional = iArgc - 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* kw */
|
/* kw */
|
||||||
if (iStar == 2) {
|
if (iStar == 2) {
|
||||||
f->is_keys = PIKA_TRUE;
|
f->is_keys = pika_true;
|
||||||
f->n_positional = iArgc - 1;
|
f->n_positional = iArgc - 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* vars and kw */
|
/* vars and kw */
|
||||||
if (iStar == 3) {
|
if (iStar == 3) {
|
||||||
f->is_vars = PIKA_TRUE;
|
f->is_vars = pika_true;
|
||||||
f->is_keys = PIKA_TRUE;
|
f->is_keys = pika_true;
|
||||||
f->n_positional = iArgc - 2;
|
f->n_positional = iArgc - 2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1265,7 +1266,7 @@ static void _kw_push(FunctionArgsInfo* f, Arg* call_arg, int i) {
|
|||||||
if (NULL == f->kw_keys) {
|
if (NULL == f->kw_keys) {
|
||||||
f->kw_keys = New_pikaDict();
|
f->kw_keys = New_pikaDict();
|
||||||
}
|
}
|
||||||
arg_setIsKeyword(call_arg, PIKA_FALSE);
|
arg_setIsKeyword(call_arg, pika_false);
|
||||||
pikaDict_setArg(f->kw, call_arg);
|
pikaDict_setArg(f->kw, call_arg);
|
||||||
char kw_keys_index_buff[11] = {0};
|
char kw_keys_index_buff[11] = {0};
|
||||||
char* kw_keys_index = fast_itoa(kw_keys_index_buff, i);
|
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);
|
pika_assert(obj->constructor == New_PikaStdData_Dict);
|
||||||
PikaDict* dict = obj_getPtr(obj, "dict");
|
PikaDict* dict = obj_getPtr(obj, "dict");
|
||||||
int i_item = 0;
|
int i_item = 0;
|
||||||
while (PIKA_TRUE) {
|
while (pika_true) {
|
||||||
Arg* item_val = args_getArgByIndex(&dict->super, i_item);
|
Arg* item_val = args_getArgByIndex(&dict->super, i_item);
|
||||||
if (NULL == item_val) {
|
if (NULL == item_val) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* unpack as keyword arg */
|
/* unpack as keyword arg */
|
||||||
arg_setIsKeyword(item_val, PIKA_TRUE);
|
arg_setIsKeyword(item_val, pika_true);
|
||||||
stack_pushArg(&stack_tmp, arg_copy(item_val));
|
stack_pushArg(&stack_tmp, arg_copy(item_val));
|
||||||
i_item++;
|
i_item++;
|
||||||
}
|
}
|
||||||
@ -1629,7 +1630,7 @@ PikaObj* New_PikaStdData_Tuple(Args* args);
|
|||||||
|
|
||||||
static Arg* _vm_create_list_or_tuple(PikaObj* self,
|
static Arg* _vm_create_list_or_tuple(PikaObj* self,
|
||||||
VMState* vm,
|
VMState* vm,
|
||||||
PIKA_BOOL is_list) {
|
pika_bool is_list) {
|
||||||
#if PIKA_BUILTIN_STRUCT_ENABLE
|
#if PIKA_BUILTIN_STRUCT_ENABLE
|
||||||
NewFun constructor = is_list ? New_PikaStdData_List : New_PikaStdData_Tuple;
|
NewFun constructor = is_list ? New_PikaStdData_List : New_PikaStdData_Tuple;
|
||||||
uint8_t n_arg = VMState_getInputArgNum(vm);
|
uint8_t n_arg = VMState_getInputArgNum(vm);
|
||||||
@ -1660,14 +1661,14 @@ static Arg* VM_instruction_handler_LST(PikaObj* self,
|
|||||||
VMState* vm,
|
VMState* vm,
|
||||||
char* data,
|
char* data,
|
||||||
Arg* arg_ret_reg) {
|
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,
|
static Arg* VM_instruction_handler_TPL(PikaObj* self,
|
||||||
VMState* vm,
|
VMState* vm,
|
||||||
char* data,
|
char* data,
|
||||||
Arg* arg_ret_reg) {
|
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) {
|
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,
|
static InstructUnit* _find_instruct_unit(ByteCodeFrame* bcframe,
|
||||||
int32_t pc_start,
|
int32_t iPcStart,
|
||||||
enum InstructIndex index,
|
enum InstructIndex index,
|
||||||
int32_t* p_offset,
|
int32_t* iOffset_p,
|
||||||
PIKA_BOOL search_upwards) {
|
pika_bool bIsForward) {
|
||||||
/* find instruct unit */
|
/* find instruct unit */
|
||||||
int instructArray_size = instructArray_getSize(&(bcframe->instruct_array));
|
int instructArray_size = instructArray_getSize(&(bcframe->instruct_array));
|
||||||
while (1) {
|
while (1) {
|
||||||
*p_offset += (search_upwards ? -1 : 1) * instructUnit_getSize();
|
*iOffset_p += (bIsForward ? -1 : 1) * instructUnit_getSize();
|
||||||
if (pc_start + *p_offset >= instructArray_size) {
|
if (iPcStart + *iOffset_p >= instructArray_size) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (pc_start + *p_offset < 0) {
|
if (iPcStart + *iOffset_p < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
InstructUnit* unit = instructArray_getByOffset(
|
InstructUnit* unit = instructArray_getByOffset(
|
||||||
&(bcframe->instruct_array), pc_start + *p_offset);
|
&(bcframe->instruct_array), iPcStart + *iOffset_p);
|
||||||
if (index == instructUnit_getInstructIndex(unit)) {
|
if (index == instructUnit_getInstructIndex(unit)) {
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static InstructUnit* _find_ins_unit_up(ByteCodeFrame* bcframe,
|
static InstructUnit* _find_ins_unit_forward(ByteCodeFrame* bcframe,
|
||||||
int32_t pc_start,
|
int32_t pc_start,
|
||||||
enum InstructIndex index,
|
enum InstructIndex index,
|
||||||
int32_t* p_offset) {
|
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,
|
int32_t pc_start,
|
||||||
enum InstructIndex index,
|
enum InstructIndex index,
|
||||||
int32_t* p_offset) {
|
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
|
#if !PIKA_NANO_ENABLE
|
||||||
@ -1775,9 +1776,9 @@ static char* _find_super_class_name(ByteCodeFrame* bcframe, int32_t pc_start) {
|
|||||||
/* find super class */
|
/* find super class */
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
char* super_class_name = NULL;
|
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 =
|
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(
|
super_class_name = constPool_getByOffset(
|
||||||
&(bcframe->const_pool), instructUnit_getConstPoolIndex(unit_run));
|
&(bcframe->const_pool), instructUnit_getConstPoolIndex(unit_run));
|
||||||
return super_class_name;
|
return super_class_name;
|
||||||
@ -1827,8 +1828,8 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
|||||||
PikaObj* oThis = NULL;
|
PikaObj* oThis = NULL;
|
||||||
Arg* aMethod = NULL;
|
Arg* aMethod = NULL;
|
||||||
Arg* aStack = NULL;
|
Arg* aStack = NULL;
|
||||||
PIKA_BOOL bIsTemp = PIKA_FALSE;
|
pika_bool bIsTemp = pika_false;
|
||||||
PIKA_BOOL bSkipInit = PIKA_FALSE;
|
pika_bool bSkipInit = pika_false;
|
||||||
char* sSysOut;
|
char* sSysOut;
|
||||||
int iNumUsed = 0;
|
int iNumUsed = 0;
|
||||||
arg_newReg(arg_reg1, 32);
|
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 (vm->pc - 2 * (int)instructUnit_getSize() >= 0) {
|
||||||
if (CLS == VMstate_getInstructWithOffset(
|
if (CLS == VMstate_getInstructWithOffset(
|
||||||
vm, -2 * (int)instructUnit_getSize())) {
|
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;
|
goto exit;
|
||||||
}
|
}
|
||||||
/* create a tuple */
|
/* 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;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1865,9 +1866,9 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
|||||||
if (strEqu(sRunPath, "super")) {
|
if (strEqu(sRunPath, "super")) {
|
||||||
sRunPath = _find_super_class_name(vm->bytecode_frame, vm->pc);
|
sRunPath = _find_super_class_name(vm->bytecode_frame, vm->pc);
|
||||||
sArgName = strPointToLastToken(sRunPath, '.');
|
sArgName = strPointToLastToken(sRunPath, '.');
|
||||||
vm->in_super = PIKA_TRUE;
|
vm->in_super = pika_true;
|
||||||
vm->super_invoke_deepth = VMState_getInvokeDeepthNow(vm);
|
vm->super_invoke_deepth = VMState_getInvokeDeepthNow(vm);
|
||||||
bSkipInit = PIKA_TRUE;
|
bSkipInit = pika_true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1951,7 +1952,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
|||||||
#if !PIKA_NANO_ENABLE
|
#if !PIKA_NANO_ENABLE
|
||||||
if (!bSkipInit && vm->in_super &&
|
if (!bSkipInit && vm->in_super &&
|
||||||
VMState_getInvokeDeepthNow(vm) == vm->super_invoke_deepth - 1) {
|
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));
|
oThis = obj_getPtr(vm->locals, _find_self_name(vm));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2196,9 +2197,9 @@ static Arg* VM_instruction_handler_BYT(PikaObj* self,
|
|||||||
return arg_newBytes((uint8_t*)data, strGetSize(data));
|
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
|
#if PIKA_NANO_ENABLE
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
#endif
|
#endif
|
||||||
if (obj_getFlag(self, OBJ_FLAG_PROXY_SETATTR)) {
|
if (obj_getFlag(self, OBJ_FLAG_PROXY_SETATTR)) {
|
||||||
obj_setStr(self, "@name", name);
|
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 */
|
0x72, 0x5f, 0x5f, 0x00, /* const pool */
|
||||||
};
|
};
|
||||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
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,
|
static Arg* VM_instruction_handler_OUT(PikaObj* self,
|
||||||
@ -2232,7 +2233,7 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self,
|
|||||||
pika_assert(sArgPath != NULL);
|
pika_assert(sArgPath != NULL);
|
||||||
char* sArgName = strPointToLastToken(sArgPath, '.');
|
char* sArgName = strPointToLastToken(sArgPath, '.');
|
||||||
PikaObj* oHost = NULL;
|
PikaObj* oHost = NULL;
|
||||||
PIKA_BOOL bIsTemp = PIKA_FALSE;
|
pika_bool bIsTemp = pika_false;
|
||||||
arg_newReg(aOutReg, PIKA_ARG_BUFF_SIZE);
|
arg_newReg(aOutReg, PIKA_ARG_BUFF_SIZE);
|
||||||
Arg* aOut = stack_popArg(&vm->stack, &aOutReg);
|
Arg* aOut = stack_popArg(&vm->stack, &aOutReg);
|
||||||
if (NULL == aOut) {
|
if (NULL == aOut) {
|
||||||
@ -2241,7 +2242,7 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self,
|
|||||||
ArgType eOutArgType = arg_getType(aOut);
|
ArgType eOutArgType = arg_getType(aOut);
|
||||||
if (VMState_getInvokeDeepthNow(vm) > 0) {
|
if (VMState_getInvokeDeepthNow(vm) > 0) {
|
||||||
/* in block, is a kw arg */
|
/* in block, is a kw arg */
|
||||||
arg_setIsKeyword(aOut, PIKA_TRUE);
|
arg_setIsKeyword(aOut, pika_true);
|
||||||
arg_setName(aOut, sArgPath);
|
arg_setName(aOut, sArgPath);
|
||||||
Arg* res = arg_copy_noalloc(aOut, aRetReg);
|
Arg* res = arg_copy_noalloc(aOut, aRetReg);
|
||||||
arg_deinit(aOut);
|
arg_deinit(aOut);
|
||||||
@ -2381,7 +2382,7 @@ static Arg* _VM_JEZ(PikaObj* self,
|
|||||||
int pika_assert) {
|
int pika_assert) {
|
||||||
int thisBlockDeepth = VMState_getBlockDeepthNow(vm);
|
int thisBlockDeepth = VMState_getBlockDeepthNow(vm);
|
||||||
int jmp_expect = fast_atoi(data);
|
int jmp_expect = fast_atoi(data);
|
||||||
vm->ireg[thisBlockDeepth] = (PIKA_BOOL)!pika_assert;
|
vm->ireg[thisBlockDeepth] = (pika_bool)!pika_assert;
|
||||||
|
|
||||||
if (0 == pika_assert) {
|
if (0 == pika_assert) {
|
||||||
/* jump */
|
/* jump */
|
||||||
@ -2835,9 +2836,9 @@ static Arg* VM_instruction_handler_OPT(PikaObj* self,
|
|||||||
if (data[1] == 'i' && data[2] == 'n') {
|
if (data[1] == 'i' && data[2] == 'n') {
|
||||||
if (op.t1 == ARG_TYPE_STRING && op.t2 == ARG_TYPE_STRING) {
|
if (op.t1 == ARG_TYPE_STRING && op.t2 == ARG_TYPE_STRING) {
|
||||||
if (strstr(arg_getStr(op.a2), arg_getStr(op.a1))) {
|
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 {
|
} else {
|
||||||
op.res = arg_setBool(op.res, "", PIKA_FALSE);
|
op.res = arg_setBool(op.res, "", pika_false);
|
||||||
}
|
}
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -3076,7 +3077,7 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self,
|
|||||||
/* assert failed */
|
/* assert failed */
|
||||||
if ((arg_getType(arg1) == ARG_TYPE_INT && arg_getInt(arg1) == 0) ||
|
if ((arg_getType(arg1) == ARG_TYPE_INT && arg_getInt(arg1) == 0) ||
|
||||||
(arg_getType(arg1) == ARG_TYPE_BOOL &&
|
(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));
|
stack_pushArg(&vm->stack, arg_newInt(PIKA_RES_ERR_ASSERT));
|
||||||
res = VM_instruction_handler_RIS(self, vm, data, arg_ret_reg);
|
res = VM_instruction_handler_RIS(self, vm, data, arg_ret_reg);
|
||||||
// if (vm->run_state->try_state == TRY_STATE_NONE) {
|
// if (vm->run_state->try_state == TRY_STATE_NONE) {
|
||||||
@ -3243,42 +3244,43 @@ static struct {
|
|||||||
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
||||||
const uint16_t signature_dict[PIKA_INSTRUCT_SIGNATURE_DICT_COUNT];
|
const uint16_t signature_dict[PIKA_INSTRUCT_SIGNATURE_DICT_COUNT];
|
||||||
#endif
|
#endif
|
||||||
} VM = {
|
} g_PikaVMInsSet = {
|
||||||
.default_ins_set =
|
.default_ins_set =
|
||||||
{
|
{
|
||||||
.ins_set = &VM_default_instruction_set,
|
.ins_set = &VM_default_instruction_set,
|
||||||
.next = NULL,
|
.next = NULL,
|
||||||
},
|
},
|
||||||
.list = (VMInstructionSetItem*)&VM.default_ins_set,
|
.list = (VMInstructionSetItem*)&g_PikaVMInsSet.default_ins_set,
|
||||||
.recent = (VMInstructionSetItem*)&VM.default_ins_set,
|
.recent = (VMInstructionSetItem*)&g_PikaVMInsSet.default_ins_set,
|
||||||
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
||||||
.signature_dict = {PIKA_INSTRUCT_SIGNATURE_DICT},
|
.signature_dict = {PIKA_INSTRUCT_SIGNATURE_DICT},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
|
pika_bool pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
|
||||||
pika_assert(NULL != ins_set);
|
pika_assert(NULL != ins_set);
|
||||||
|
|
||||||
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
#if PIKA_INSTRUCT_SIGNATURE_DICT_COUNT > 0
|
||||||
uint16_t signature = ins_set->signature;
|
uint16_t signature = ins_set->signature;
|
||||||
|
|
||||||
PIKA_BOOL ins_set_valid = PIKA_FALSE;
|
pika_bool ins_set_valid = pika_false;
|
||||||
for (int n = 0; n < sizeof(VM.signature_dict) / sizeof(uint16_t); n++) {
|
for (int n = 0;
|
||||||
if (VM.signature_dict[n] == signature) {
|
n < sizeof(g_PikaVMInsSet.signature_dict) / sizeof(uint16_t); n++) {
|
||||||
ins_set_valid = PIKA_TRUE;
|
if (g_PikaVMInsSet.signature_dict[n] == signature) {
|
||||||
|
ins_set_valid = pika_true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ins_set_valid) {
|
if (!ins_set_valid) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* check whether the target instruction set exists or not */
|
/* check whether the target instruction set exists or not */
|
||||||
VMInstructionSetItem* list_item = VM.list;
|
VMInstructionSetItem* list_item = g_PikaVMInsSet.list;
|
||||||
do {
|
do {
|
||||||
if (list_item->ins_set->signature == signature) {
|
if (list_item->ins_set->signature == signature) {
|
||||||
return PIKA_TRUE; /* already exist */
|
return pika_true; /* already exist */
|
||||||
}
|
}
|
||||||
|
|
||||||
list_item = list_item->next;
|
list_item = list_item->next;
|
||||||
@ -3287,7 +3289,7 @@ PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
|
|||||||
VMInstructionSetItem* item =
|
VMInstructionSetItem* item =
|
||||||
pika_platform_malloc(sizeof(VMInstructionSetItem));
|
pika_platform_malloc(sizeof(VMInstructionSetItem));
|
||||||
if (NULL == item) {
|
if (NULL == item) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
item->ins_set = ins_set;
|
item->ins_set = ins_set;
|
||||||
item->next = NULL;
|
item->next = NULL;
|
||||||
@ -3295,12 +3297,12 @@ PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
|
|||||||
/* add item to the tail of VM.list */
|
/* add item to the tail of VM.list */
|
||||||
list_item->next = item;
|
list_item->next = item;
|
||||||
|
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const VMInstruction* instructUnit_getInstruct(
|
static const VMInstruction* instructUnit_getInstruct(
|
||||||
enum InstructIndex ins_idx) {
|
enum InstructIndex ins_idx) {
|
||||||
VMInstructionSetItem* item = VM.recent;
|
VMInstructionSetItem* item = g_PikaVMInsSet.recent;
|
||||||
|
|
||||||
if ((ins_idx >= item->ins_set->op_idx_start) &&
|
if ((ins_idx >= item->ins_set->op_idx_start) &&
|
||||||
(ins_idx <= item->ins_set->op_idx_end)) {
|
(ins_idx <= item->ins_set->op_idx_end)) {
|
||||||
@ -3309,11 +3311,11 @@ static const VMInstruction* instructUnit_getInstruct(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* search list */
|
/* search list */
|
||||||
item = VM.list;
|
item = g_PikaVMInsSet.list;
|
||||||
do {
|
do {
|
||||||
if ((ins_idx >= item->ins_set->op_idx_start) &&
|
if ((ins_idx >= item->ins_set->op_idx_start) &&
|
||||||
(ins_idx <= item->ins_set->op_idx_end)) {
|
(ins_idx <= item->ins_set->op_idx_end)) {
|
||||||
VM.recent = item;
|
g_PikaVMInsSet.recent = item;
|
||||||
return &(item->ins_set
|
return &(item->ins_set
|
||||||
->instructions[ins_idx - item->ins_set->op_idx_start]);
|
->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 pikaVM_getInstructFromAsm(char* ins_str) {
|
||||||
enum InstructIndex ins_idx =
|
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) {
|
if (__INSTRUCTION_UNKNOWN == ins_idx) {
|
||||||
VMInstructionSetItem* item = VM.list;
|
VMInstructionSetItem* item = g_PikaVMInsSet.list;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ins_idx = __find_ins_idx_in_ins_set(ins_str, item->ins_set);
|
ins_idx = __find_ins_idx_in_ins_set(ins_str, item->ins_set);
|
||||||
if (__INSTRUCTION_UNKNOWN != ins_idx) {
|
if (__INSTRUCTION_UNKNOWN != ins_idx) {
|
||||||
VM.recent = item;
|
g_PikaVMInsSet.recent = item;
|
||||||
return ins_idx;
|
return ins_idx;
|
||||||
}
|
}
|
||||||
item = item->next;
|
item = item->next;
|
||||||
@ -3362,8 +3364,8 @@ enum InstructIndex pikaVM_getInstructFromAsm(char* ins_str) {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
PIKA_BOOL pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
|
pika_bool pikaVM_registerInstructionSet(VMInstructionSet* ins_set) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum InstructIndex pikaVM_getInstructFromAsm(char* ins_str) {
|
enum InstructIndex pikaVM_getInstructFromAsm(char* ins_str) {
|
||||||
@ -3592,7 +3594,7 @@ VMParameters* _do_pikaVM_runByteCode(PikaObj* self,
|
|||||||
VMParameters* globals,
|
VMParameters* globals,
|
||||||
uint8_t* bytecode,
|
uint8_t* bytecode,
|
||||||
RunState* run_state,
|
RunState* run_state,
|
||||||
PIKA_BOOL is_const_bytecode) {
|
pika_bool is_const_bytecode) {
|
||||||
ByteCodeFrame bytecode_frame_stack = {0};
|
ByteCodeFrame bytecode_frame_stack = {0};
|
||||||
ByteCodeFrame* bytecode_frame_p = NULL;
|
ByteCodeFrame* bytecode_frame_p = NULL;
|
||||||
uint8_t is_use_heap_bytecode = 1;
|
uint8_t is_use_heap_bytecode = 1;
|
||||||
@ -3606,7 +3608,7 @@ VMParameters* _do_pikaVM_runByteCode(PikaObj* self,
|
|||||||
/* get bytecode_ptr from stack */
|
/* get bytecode_ptr from stack */
|
||||||
bytecode_frame_p = &bytecode_frame_stack;
|
bytecode_frame_p = &bytecode_frame_stack;
|
||||||
/* no def/class ins, no need cache bytecode */
|
/* no def/class ins, no need cache bytecode */
|
||||||
is_const_bytecode = PIKA_TRUE;
|
is_const_bytecode = pika_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load or generate byte code frame */
|
/* 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,
|
RunState run_state = {.try_state = TRY_STATE_NONE,
|
||||||
.try_result = TRY_RESULT_NONE};
|
.try_result = TRY_RESULT_NONE};
|
||||||
return _do_pikaVM_runByteCode(self, self, self, (uint8_t*)bytecode,
|
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,
|
Arg* pikaVM_runByteCodeReturn(PikaObj* self,
|
||||||
@ -3687,7 +3693,7 @@ Arg* _do_pikaVM_runByteCodeReturn(PikaObj* self,
|
|||||||
VMParameters* globals,
|
VMParameters* globals,
|
||||||
uint8_t* bytecode,
|
uint8_t* bytecode,
|
||||||
RunState* run_state,
|
RunState* run_state,
|
||||||
PIKA_BOOL is_const_bytecode,
|
pika_bool is_const_bytecode,
|
||||||
char* return_name) {
|
char* return_name) {
|
||||||
_do_pikaVM_runByteCode(self, locals, globals, bytecode, run_state,
|
_do_pikaVM_runByteCode(self, locals, globals, bytecode, run_state,
|
||||||
is_const_bytecode);
|
is_const_bytecode);
|
||||||
@ -3706,7 +3712,7 @@ VMParameters* pikaVM_runByteCodeInconstant(PikaObj* self, uint8_t* bytecode) {
|
|||||||
RunState run_state = {.try_state = TRY_STATE_NONE,
|
RunState run_state = {.try_state = TRY_STATE_NONE,
|
||||||
.try_result = TRY_RESULT_NONE};
|
.try_result = TRY_RESULT_NONE};
|
||||||
return _do_pikaVM_runByteCode(self, self, self, (uint8_t*)bytecode,
|
return _do_pikaVM_runByteCode(self, self, self, (uint8_t*)bytecode,
|
||||||
&run_state, PIKA_FALSE);
|
&run_state, pika_false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void constPool_update(ConstPool* self) {
|
void constPool_update(ConstPool* self) {
|
||||||
@ -3820,7 +3826,7 @@ void byteCodeFrame_init(ByteCodeFrame* self) {
|
|||||||
extern const char magic_code_pyo[4];
|
extern const char magic_code_pyo[4];
|
||||||
void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
|
void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
|
||||||
uint8_t* bytes,
|
uint8_t* bytes,
|
||||||
PIKA_BOOL is_const) {
|
pika_bool is_const) {
|
||||||
if (bytes[0] == magic_code_pyo[0] && bytes[1] == magic_code_pyo[1] &&
|
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]) {
|
bytes[2] == magic_code_pyo[2] && bytes[3] == magic_code_pyo[3]) {
|
||||||
/* load from file, found magic code, skip head */
|
/* 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) {
|
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) {
|
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) {
|
static char* instructUnit_getInstructStr(InstructUnit* self) {
|
||||||
enum InstructIndex op_idx = instructUnit_getInstructIndex(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) {
|
if (NULL != ins_str) {
|
||||||
return (char*)ins_str;
|
return (char*)ins_str;
|
||||||
}
|
}
|
||||||
VMInstructionSetItem* item = VM.list;
|
VMInstructionSetItem* item = g_PikaVMInsSet.list;
|
||||||
do {
|
do {
|
||||||
ins_str = __find_ins_str_in_ins_set(op_idx, item->ins_set);
|
ins_str = __find_ins_str_in_ins_set(op_idx, item->ins_set);
|
||||||
if (NULL != ins_str) {
|
if (NULL != ins_str) {
|
||||||
VM.recent = item;
|
g_PikaVMInsSet.recent = item;
|
||||||
return (char*)ins_str;
|
return (char*)ins_str;
|
||||||
}
|
}
|
||||||
item = item->next;
|
item = item->next;
|
||||||
@ -4062,7 +4069,7 @@ void VMState_solveUnusedStack(VMState* vm) {
|
|||||||
arg_deinit(arg);
|
arg_deinit(arg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
arg_print(arg, PIKA_TRUE, "\r\n");
|
arg_print(arg, pika_true, "\r\n");
|
||||||
arg_deinit(arg);
|
arg_deinit(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4078,50 +4085,51 @@ static VMParameters* _pikaVM_runByteCodeFrameWithState(
|
|||||||
int size = bytecode_frame->instruct_array.size;
|
int size = bytecode_frame->instruct_array.size;
|
||||||
/* locals is the local scope */
|
/* locals is the local scope */
|
||||||
|
|
||||||
VMState* vm_ptr = (VMState*)pikaMalloc(sizeof(VMState));
|
VMState* vm = (VMState*)pikaMalloc(sizeof(VMState));
|
||||||
vm_ptr->bytecode_frame = bytecode_frame;
|
vm->bytecode_frame = bytecode_frame;
|
||||||
vm_ptr->locals = locals;
|
vm->locals = locals;
|
||||||
vm_ptr->globals = globals;
|
vm->globals = globals;
|
||||||
vm_ptr->jmp = 0;
|
vm->jmp = 0;
|
||||||
vm_ptr->pc = pc;
|
vm->pc = pc;
|
||||||
vm_ptr->loop_deepth = 0;
|
vm->loop_deepth = 0;
|
||||||
vm_ptr->error_code = PIKA_RES_OK;
|
vm->error_code = PIKA_RES_OK;
|
||||||
vm_ptr->line_error_code = PIKA_RES_OK;
|
vm->line_error_code = PIKA_RES_OK;
|
||||||
vm_ptr->try_error_code = PIKA_RES_OK;
|
vm->try_error_code = PIKA_RES_OK;
|
||||||
vm_ptr->run_state = run_state;
|
vm->run_state = run_state;
|
||||||
vm_ptr->ins_cnt = 0;
|
vm->ins_cnt = 0;
|
||||||
vm_ptr->in_super = PIKA_FALSE;
|
vm->in_super = pika_false;
|
||||||
vm_ptr->super_invoke_deepth = 0;
|
vm->super_invoke_deepth = 0;
|
||||||
stack_init(&(vm_ptr->stack));
|
stack_init(&(vm->stack));
|
||||||
VMState_initReg(vm_ptr);
|
VMState_initReg(vm);
|
||||||
if (g_PikaVMSignal.vm_cnt == 0) {
|
if (g_PikaVMSignal.vm_cnt == 0) {
|
||||||
pks_vmSignal_setCtrlElear();
|
pks_vmSignal_setCtrlClear();
|
||||||
}
|
}
|
||||||
g_PikaVMSignal.vm_cnt++;
|
g_PikaVMSignal.vm_cnt++;
|
||||||
while (vm_ptr->pc < size) {
|
g_PikaVMSignal.vm_now = vm;
|
||||||
if (vm_ptr->pc == VM_PC_EXIT) {
|
while (vm->pc < size) {
|
||||||
|
if (vm->pc == VM_PC_EXIT) {
|
||||||
break;
|
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);
|
uint8_t is_new_line = instructUnit_getIsNewLine(this_ins_unit);
|
||||||
if (is_new_line) {
|
if (is_new_line) {
|
||||||
VMState_solveUnusedStack(vm_ptr);
|
VMState_solveUnusedStack(vm);
|
||||||
stack_reset(&(vm_ptr->stack));
|
stack_reset(&(vm->stack));
|
||||||
vm_ptr->error_code = 0;
|
vm->error_code = 0;
|
||||||
vm_ptr->line_error_code = 0;
|
vm->line_error_code = 0;
|
||||||
}
|
}
|
||||||
vm_ptr->pc = pikaVM_runInstructUnit(self, vm_ptr, this_ins_unit);
|
vm->pc = pikaVM_runInstructUnit(self, vm, this_ins_unit);
|
||||||
vm_ptr->ins_cnt++;
|
vm->ins_cnt++;
|
||||||
#if PIKA_INSTRUCT_HOOK_ENABLE
|
#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();
|
pika_hook_instruct();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (vm_ptr->ins_cnt % PIKA_INSTRUCT_YIELD_PERIOD == 0) {
|
if (vm->ins_cnt % PIKA_INSTRUCT_YIELD_PERIOD == 0) {
|
||||||
_pikaVM_yield();
|
_pikaVM_yield();
|
||||||
}
|
}
|
||||||
if (0 != vm_ptr->error_code) {
|
if (0 != vm->error_code) {
|
||||||
vm_ptr->line_error_code = vm_ptr->error_code;
|
vm->line_error_code = vm->error_code;
|
||||||
InstructUnit* head_ins_unit = this_ins_unit;
|
InstructUnit* head_ins_unit = this_ins_unit;
|
||||||
/* get first ins of a line */
|
/* get first ins of a line */
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -4130,11 +4138,11 @@ static VMParameters* _pikaVM_runByteCodeFrameWithState(
|
|||||||
}
|
}
|
||||||
head_ins_unit--;
|
head_ins_unit--;
|
||||||
}
|
}
|
||||||
if (vm_ptr->run_state->try_state) {
|
if (vm->run_state->try_state) {
|
||||||
vm_ptr->try_error_code = vm_ptr->error_code;
|
vm->try_error_code = vm->error_code;
|
||||||
}
|
}
|
||||||
/* print inses of a line */
|
/* print inses of a line */
|
||||||
if (!vm_ptr->run_state->try_state) {
|
if (!vm->run_state->try_state) {
|
||||||
while (1) {
|
while (1) {
|
||||||
if (head_ins_unit != this_ins_unit) {
|
if (head_ins_unit != this_ins_unit) {
|
||||||
pika_platform_printf(" ");
|
pika_platform_printf(" ");
|
||||||
@ -4150,15 +4158,15 @@ static VMParameters* _pikaVM_runByteCodeFrameWithState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pika_platform_error_handle();
|
pika_platform_error_handle();
|
||||||
vm_ptr->error_code = 0;
|
vm->error_code = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VMState_solveUnusedStack(vm_ptr);
|
VMState_solveUnusedStack(vm);
|
||||||
stack_deinit(&(vm_ptr->stack));
|
stack_deinit(&(vm->stack));
|
||||||
g_PikaVMSignal.vm_cnt--;
|
g_PikaVMSignal.vm_cnt--;
|
||||||
|
|
||||||
VMParameters* result = locals;
|
VMParameters* result = locals;
|
||||||
pikaFree(vm_ptr, sizeof(VMState));
|
pikaFree(vm, sizeof(VMState));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4224,7 +4232,7 @@ PikaObj* pikaVM_runFile(PikaObj* self, char* file_name) {
|
|||||||
pikaMaker_setPWD(maker, pwd);
|
pikaMaker_setPWD(maker, pwd);
|
||||||
pikaMaker_compileModuleWithDepends(maker, module_name);
|
pikaMaker_compileModuleWithDepends(maker, module_name);
|
||||||
_do_pikaMaker_linkCompiledModules(maker, "pikaModules_cache.py.a",
|
_do_pikaMaker_linkCompiledModules(maker, "pikaModules_cache.py.a",
|
||||||
PIKA_FALSE);
|
pika_false);
|
||||||
pikaMaker_deinit(maker);
|
pikaMaker_deinit(maker);
|
||||||
pika_platform_printf("(pikascript) all succeed.\r\n\r\n");
|
pika_platform_printf("(pikascript) all succeed.\r\n\r\n");
|
||||||
|
|
||||||
|
22
src/PikaVM.h
22
src/PikaVM.h
@ -84,10 +84,10 @@ struct VMState {
|
|||||||
uint8_t line_error_code;
|
uint8_t line_error_code;
|
||||||
uint8_t try_error_code;
|
uint8_t try_error_code;
|
||||||
uint32_t ins_cnt;
|
uint32_t ins_cnt;
|
||||||
PIKA_BOOL in_super;
|
pika_bool in_super;
|
||||||
uint8_t super_invoke_deepth;
|
uint8_t super_invoke_deepth;
|
||||||
RunState* run_state;
|
RunState* run_state;
|
||||||
PIKA_BOOL ireg[PIKA_REGIST_SIZE];
|
pika_bool ireg[PIKA_REGIST_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -97,9 +97,9 @@ typedef struct {
|
|||||||
int8_t n_arg;
|
int8_t n_arg;
|
||||||
int8_t i_arg;
|
int8_t i_arg;
|
||||||
int8_t n_input;
|
int8_t n_input;
|
||||||
PIKA_BOOL is_vars;
|
pika_bool is_vars;
|
||||||
PIKA_BOOL is_keys;
|
pika_bool is_keys;
|
||||||
PIKA_BOOL is_default;
|
pika_bool is_default;
|
||||||
ArgType method_type;
|
ArgType method_type;
|
||||||
PikaTuple* tuple;
|
PikaTuple* tuple;
|
||||||
PikaDict* kw;
|
PikaDict* kw;
|
||||||
@ -151,6 +151,7 @@ typedef struct VMSignal VMSignal;
|
|||||||
struct VMSignal {
|
struct VMSignal {
|
||||||
VM_SIGNAL_CTRL signal_ctrl;
|
VM_SIGNAL_CTRL signal_ctrl;
|
||||||
int vm_cnt;
|
int vm_cnt;
|
||||||
|
VMState* vm_now;
|
||||||
#if PIKA_EVENT_ENABLE
|
#if PIKA_EVENT_ENABLE
|
||||||
EventCQ cq;
|
EventCQ cq;
|
||||||
int event_pickup_cnt;
|
int event_pickup_cnt;
|
||||||
@ -181,6 +182,7 @@ struct VMInstructionSet {
|
|||||||
uint16_t op_idx_end;
|
uint16_t op_idx_end;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
VMState* pikaVM_getCurrent(void);
|
||||||
VMParameters* pikaVM_run(PikaObj* self, char* pyLine);
|
VMParameters* pikaVM_run(PikaObj* self, char* pyLine);
|
||||||
VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
VMParameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
||||||
VMParameters* pikaVM_runByteCodeFrame(PikaObj* self,
|
VMParameters* pikaVM_runByteCodeFrame(PikaObj* self,
|
||||||
@ -314,7 +316,7 @@ void instructArray_printAsArray(InstructArray* self);
|
|||||||
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes);
|
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes);
|
||||||
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
|
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
|
||||||
void byteCodeFrame_init(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_runByteCode(PikaObj* self, const uint8_t* bytecode);
|
||||||
VMParameters* pikaVM_runByteCodeInconstant(PikaObj* self, uint8_t* bytecode);
|
VMParameters* pikaVM_runByteCodeInconstant(PikaObj* self, uint8_t* bytecode);
|
||||||
Arg* pikaVM_runByteCodeReturn(PikaObj* self,
|
Arg* pikaVM_runByteCodeReturn(PikaObj* self,
|
||||||
@ -325,7 +327,7 @@ Arg* _do_pikaVM_runByteCodeReturn(PikaObj* self,
|
|||||||
VMParameters* globals,
|
VMParameters* globals,
|
||||||
uint8_t* bytecode,
|
uint8_t* bytecode,
|
||||||
RunState* run_state,
|
RunState* run_state,
|
||||||
PIKA_BOOL is_const_bytecode,
|
pika_bool is_const_bytecode,
|
||||||
char* return_name);
|
char* return_name);
|
||||||
InstructUnit* instructArray_getNow(InstructArray* self);
|
InstructUnit* instructArray_getNow(InstructArray* self);
|
||||||
InstructUnit* instructArray_getNext(InstructArray* self);
|
InstructUnit* instructArray_getNext(InstructArray* self);
|
||||||
@ -344,10 +346,10 @@ VMParameters* _do_pikaVM_runByteCode(PikaObj* self,
|
|||||||
VMParameters* globals,
|
VMParameters* globals,
|
||||||
uint8_t* bytecode,
|
uint8_t* bytecode,
|
||||||
RunState* run_state,
|
RunState* run_state,
|
||||||
PIKA_BOOL is_const_bytecode);
|
pika_bool is_const_bytecode);
|
||||||
void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
|
void _do_byteCodeFrame_loadByteCode(ByteCodeFrame* self,
|
||||||
uint8_t* bytes,
|
uint8_t* bytes,
|
||||||
PIKA_BOOL is_const);
|
pika_bool is_const);
|
||||||
Arg* _vm_get(VMState* vm, PikaObj* self, Arg* key, Arg* obj);
|
Arg* _vm_get(VMState* vm, PikaObj* self, Arg* key, Arg* obj);
|
||||||
void __vm_List_append(PikaObj* self, Arg* arg);
|
void __vm_List_append(PikaObj* self, Arg* arg);
|
||||||
void __vm_List___init__(PikaObj* self);
|
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);
|
void __vm_Dict___init__(PikaObj* self);
|
||||||
VM_SIGNAL_CTRL VMSignal_getCtrl(void);
|
VM_SIGNAL_CTRL VMSignal_getCtrl(void);
|
||||||
void pks_vm_exit(void);
|
void pks_vm_exit(void);
|
||||||
void pks_vmSignal_setCtrlElear(void);
|
void pks_vmSignal_setCtrlClear(void);
|
||||||
PIKA_RES __eventListener_popEvent(PikaEventListener** lisener_p,
|
PIKA_RES __eventListener_popEvent(PikaEventListener** lisener_p,
|
||||||
uint32_t* id,
|
uint32_t* id,
|
||||||
Arg** signal,
|
Arg** signal,
|
||||||
|
@ -48,11 +48,11 @@
|
|||||||
|
|
||||||
#if defined(__MSG_DECLARE)
|
#if defined(__MSG_DECLARE)
|
||||||
#define __add_filter_msg(__name, __msg, ...) \
|
#define __add_filter_msg(__name, __msg, ...) \
|
||||||
PIKA_BOOL _filter_msg_##__name##_handler( FilterItem *msg, \
|
pika_bool _filter_msg_##__name##_handler( FilterItem *msg, \
|
||||||
PikaObj* self, \
|
PikaObj* self, \
|
||||||
ShellConfig* shell);
|
ShellConfig* shell);
|
||||||
#define __add_filter_item(__name, ...) \
|
#define __add_filter_item(__name, ...) \
|
||||||
PIKA_BOOL _filter_msg_##__name##_handler( FilterItem *msg, \
|
pika_bool _filter_msg_##__name##_handler( FilterItem *msg, \
|
||||||
PikaObj* self, \
|
PikaObj* self, \
|
||||||
ShellConfig* shell);
|
ShellConfig* shell);
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,15 +37,15 @@
|
|||||||
* add_filter_msg(
|
* add_filter_msg(
|
||||||
* <name>,
|
* <name>,
|
||||||
* <string>,
|
* <string>,
|
||||||
* [.is_visible = PIKA_TRUE,]
|
* [.is_visible = pika_true,]
|
||||||
* [.is_case_insensitive = PIKA_TRUE,]
|
* [.is_case_insensitive = pika_true,]
|
||||||
* [.ignore_mask = mask value,]
|
* [.ignore_mask = mask value,]
|
||||||
* [.target = your own object address/value,]
|
* [.target = your own object address/value,]
|
||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
|
|
||||||
add_filter_msg(hi_pika, "###Hi Pika")
|
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:
|
/* 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>,
|
* <name>,
|
||||||
* .message = (const uint8_t []){< num0, num1, ... >},
|
* .message = (const uint8_t []){< num0, num1, ... >},
|
||||||
* .size = <array size>,
|
* .size = <array size>,
|
||||||
* [.is_visible = PIKA_TRUE,]
|
* [.is_visible = pika_true,]
|
||||||
* [.is_case_insensitive = PIKA_TRUE,]
|
* [.is_case_insensitive = pika_true,]
|
||||||
* [.ignore_mask = mask value,]
|
* [.ignore_mask = mask value,]
|
||||||
* [.target = your own object address/value,]
|
* [.target = your own object address/value,]
|
||||||
* )
|
* )
|
||||||
|
@ -32,24 +32,24 @@
|
|||||||
#include "dataString.h"
|
#include "dataString.h"
|
||||||
#include "stdlib.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
|
#if !PIKA_ARG_CACHE_ENABLE
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
#else
|
#else
|
||||||
if (PIKA_FALSE == pika_hook_arg_cache_filter(self)) {
|
if (pika_false == pika_hook_arg_cache_filter(self)) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
extern PikaMemInfo g_PikaMemInfo;
|
extern PikaMemInfo g_PikaMemInfo;
|
||||||
if (self->heap_size < PIKA_ARG_CACHE_SIZE ||
|
if (self->heap_size < PIKA_ARG_CACHE_SIZE ||
|
||||||
self->heap_size > 2 * 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) {
|
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.cache_pool[g_PikaMemInfo.cache_pool_top++] = (uint8_t*)self;
|
||||||
g_PikaMemInfo.heapUsed -= mem_align(sizeof(Arg) + size);
|
g_PikaMemInfo.heapUsed -= mem_align(sizeof(Arg) + size);
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,8 +132,8 @@ static Arg* _arg_set_hash(Arg* self,
|
|||||||
}
|
}
|
||||||
self->size = size;
|
self->size = size;
|
||||||
self->flag = 0;
|
self->flag = 0;
|
||||||
arg_setSerialized(self, PIKA_TRUE);
|
arg_setSerialized(self, pika_true);
|
||||||
// arg_setIsKeyword(self, PIKA_FALSE);
|
// arg_setIsKeyword(self, pika_false);
|
||||||
arg_setNext(self, next);
|
arg_setNext(self, next);
|
||||||
}
|
}
|
||||||
self->name_hash = nameHash;
|
self->name_hash = nameHash;
|
||||||
@ -365,7 +365,7 @@ __exit:
|
|||||||
return result;
|
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() */
|
/* use arg_toStrArg() */
|
||||||
Arg* str_arg = arg_toStrArg(self);
|
Arg* str_arg = arg_toStrArg(self);
|
||||||
if (NULL == str_arg) {
|
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));
|
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));
|
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);
|
return *(int64_t*)arg_getContent(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
PIKA_BOOL arg_getBool(Arg* self) {
|
pika_bool arg_getBool(Arg* self) {
|
||||||
pika_assert(NULL != self);
|
pika_assert(NULL != self);
|
||||||
if (NULL == arg_getContent(self)) {
|
if (NULL == arg_getContent(self)) {
|
||||||
return _PIKA_BOOL_ERR;
|
return _PIKA_BOOL_ERR;
|
||||||
}
|
}
|
||||||
return *(PIKA_BOOL*)arg_getContent(self);
|
return *(pika_bool*)arg_getContent(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* arg_getPtr(Arg* 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);
|
return arg_copy(arg_src);
|
||||||
}
|
}
|
||||||
arg_refcntInc(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);
|
arg_dict = arg_copy_content(arg_dict, arg_src);
|
||||||
return arg_dict;
|
return arg_dict;
|
||||||
}
|
}
|
||||||
@ -663,26 +663,26 @@ void arg_deinit(Arg* self) {
|
|||||||
arg_freeContent(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) {
|
if (NULL == self || NULL == other) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
if (arg_getType(self) != arg_getType(other)) {
|
if (arg_getType(self) != arg_getType(other)) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
if (arg_getType(self) == ARG_TYPE_OBJECT) {
|
if (arg_getType(self) == ARG_TYPE_OBJECT) {
|
||||||
if (arg_getPtr(self) != arg_getPtr(other)) {
|
if (arg_getPtr(self) != arg_getPtr(other)) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (arg_getType(self) == ARG_TYPE_STRING) {
|
if (arg_getType(self) == ARG_TYPE_STRING) {
|
||||||
if (strEqu(arg_getStr(self), arg_getStr(other))) {
|
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),
|
if (0 != pika_platform_memcmp(arg_getContent(self), arg_getContent(other),
|
||||||
arg_getContentSize(self))) {
|
arg_getContentSize(self))) {
|
||||||
return PIKA_FALSE;
|
return pika_false;
|
||||||
}
|
}
|
||||||
return PIKA_TRUE;
|
return pika_true;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ uint32_t arg_getContentSize(Arg* self);
|
|||||||
Hash hash_time33(char* str);
|
Hash hash_time33(char* str);
|
||||||
|
|
||||||
Arg* arg_setInt(Arg* self, char* name, int64_t val);
|
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_setFloat(Arg* self, char* name, pika_float val);
|
||||||
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer);
|
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer);
|
||||||
Arg* arg_setStr(Arg* self, char* name, char* string);
|
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));
|
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));
|
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);
|
int64_t arg_getInt(Arg* self);
|
||||||
PIKA_BOOL arg_getBool(Arg* self);
|
pika_bool arg_getBool(Arg* self);
|
||||||
pika_float arg_getFloat(Arg* self);
|
pika_float arg_getFloat(Arg* self);
|
||||||
void* arg_getPtr(Arg* self);
|
void* arg_getPtr(Arg* self);
|
||||||
char* arg_getStr(Arg* self);
|
char* arg_getStr(Arg* self);
|
||||||
@ -182,7 +182,7 @@ Arg* arg_setHeapStruct(Arg* self,
|
|||||||
void* arg_getHeapStruct(Arg* self);
|
void* arg_getHeapStruct(Arg* self);
|
||||||
void arg_deinitHeap(Arg* self);
|
void arg_deinitHeap(Arg* self);
|
||||||
Arg* arg_toStrArg(Arg* arg);
|
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);
|
Arg* arg_loadFile(Arg* self, char* filename);
|
||||||
|
|
||||||
#define ARG_FLAG_SERIALIZED 0x01
|
#define ARG_FLAG_SERIALIZED 0x01
|
||||||
@ -301,7 +301,7 @@ static inline uint8_t argType_isNative(ArgType type) {
|
|||||||
arg_init_stack(&__name, __##__name##_buff, __size)
|
arg_init_stack(&__name, __##__name##_buff, __size)
|
||||||
|
|
||||||
void arg_init_stack(Arg* self, uint8_t* buffer, uint32_t 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);
|
Hash hash_time33EndWith(char* str, char end);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -202,7 +202,7 @@ int64_t args_getInt(Args* self, char* name) {
|
|||||||
return _PIKA_INT_ERR;
|
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);
|
Arg* arg = args_getArg(self, name);
|
||||||
if (NULL == arg) {
|
if (NULL == arg) {
|
||||||
return _PIKA_BOOL_ERR;
|
return _PIKA_BOOL_ERR;
|
||||||
|
@ -75,7 +75,7 @@ void* args_getPtr(Args* self, char* name);
|
|||||||
|
|
||||||
PIKA_RES args_setInt(Args* self, char* name, int64_t int64In);
|
PIKA_RES args_setInt(Args* self, char* name, int64_t int64In);
|
||||||
int64_t args_getInt(Args* self, char* name);
|
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);
|
char* args_print(Args* self, char* name);
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ Pool pool_init(uint32_t size, uint8_t aline) {
|
|||||||
pool.mem = pika_platform_malloc(pool_aline(&pool, pool.size));
|
pool.mem = pika_platform_malloc(pool_aline(&pool, pool.size));
|
||||||
pool.first_free_block = 0;
|
pool.first_free_block = 0;
|
||||||
pool.purl_free_block_start = 0;
|
pool.purl_free_block_start = 0;
|
||||||
pool.inited = PIKA_TRUE;
|
pool.inited = pika_true;
|
||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ struct Pool{
|
|||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t first_free_block;
|
uint32_t first_free_block;
|
||||||
uint32_t purl_free_block_start;
|
uint32_t purl_free_block_start;
|
||||||
PIKA_BOOL inited;
|
pika_bool inited;
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
@ -99,7 +99,7 @@ char* queue_popStr(Queue* queue) {
|
|||||||
ByteQueue* byteQueue_init(ByteQueue* queue,
|
ByteQueue* byteQueue_init(ByteQueue* queue,
|
||||||
void* buffer,
|
void* buffer,
|
||||||
uint_fast16_t size,
|
uint_fast16_t size,
|
||||||
PIKA_BOOL is_queue_full) {
|
pika_bool is_queue_full) {
|
||||||
pika_assert(NULL != queue);
|
pika_assert(NULL != queue);
|
||||||
pika_assert(NULL != buffer);
|
pika_assert(NULL != buffer);
|
||||||
pika_assert(size > 0);
|
pika_assert(size > 0);
|
||||||
@ -116,10 +116,10 @@ ByteQueue* byteQueue_init(ByteQueue* queue,
|
|||||||
return 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);
|
pika_assert(NULL != queue);
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
PIKA_BOOL result = PIKA_FALSE;
|
pika_bool result = pika_false;
|
||||||
|
|
||||||
/* ------------------atomicity sensitive start---------------- */
|
/* ------------------atomicity sensitive start---------------- */
|
||||||
do {
|
do {
|
||||||
@ -141,17 +141,17 @@ PIKA_BOOL byteQueue_readOne(ByteQueue* queue, uint8_t* byte_ptr) {
|
|||||||
if (NULL != byte_ptr) {
|
if (NULL != byte_ptr) {
|
||||||
*byte_ptr = byte;
|
*byte_ptr = byte;
|
||||||
}
|
}
|
||||||
result = PIKA_TRUE;
|
result = pika_true;
|
||||||
} while (0);
|
} while (0);
|
||||||
/* ------------------atomicity sensitive end ---------------- */
|
/* ------------------atomicity sensitive end ---------------- */
|
||||||
|
|
||||||
return result;
|
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);
|
pika_assert(NULL != queue);
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
PIKA_BOOL result = PIKA_FALSE;
|
pika_bool result = pika_false;
|
||||||
|
|
||||||
/* ------------------atomicity sensitive start---------------- */
|
/* ------------------atomicity sensitive start---------------- */
|
||||||
do {
|
do {
|
||||||
@ -169,7 +169,7 @@ PIKA_BOOL byteQueue_peekOne(ByteQueue* queue, uint8_t* byte_ptr) {
|
|||||||
if (NULL != byte_ptr) {
|
if (NULL != byte_ptr) {
|
||||||
*byte_ptr = byte;
|
*byte_ptr = byte;
|
||||||
}
|
}
|
||||||
result = PIKA_TRUE;
|
result = pika_true;
|
||||||
} while (0);
|
} while (0);
|
||||||
/* ------------------atomicity sensitive end ---------------- */
|
/* ------------------atomicity sensitive end ---------------- */
|
||||||
|
|
||||||
@ -200,9 +200,9 @@ void byteQueue_dropAllPeeked(ByteQueue* queue) {
|
|||||||
/* ------------------atomicity sensitive end ---------------- */
|
/* ------------------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_assert(NULL != queue);
|
||||||
PIKA_BOOL result = PIKA_FALSE;
|
pika_bool result = pika_false;
|
||||||
|
|
||||||
/* ------------------atomicity sensitive start---------------- */
|
/* ------------------atomicity sensitive start---------------- */
|
||||||
do {
|
do {
|
||||||
@ -218,7 +218,7 @@ PIKA_BOOL byteQueue_writeOne(ByteQueue* queue, uint8_t byte) {
|
|||||||
queue->tail = 0;
|
queue->tail = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = PIKA_TRUE;
|
result = pika_true;
|
||||||
} while (0);
|
} while (0);
|
||||||
/* ------------------atomicity sensitive end ---------------- */
|
/* ------------------atomicity sensitive end ---------------- */
|
||||||
|
|
||||||
|
@ -76,14 +76,14 @@ void queue_init(Queue* queue);
|
|||||||
ByteQueue *byteQueue_init( ByteQueue *queue,
|
ByteQueue *byteQueue_init( ByteQueue *queue,
|
||||||
void *buffer,
|
void *buffer,
|
||||||
uint_fast16_t size,
|
uint_fast16_t size,
|
||||||
PIKA_BOOL is_queue_full);
|
pika_bool is_queue_full);
|
||||||
PIKA_BOOL byteQueue_readOne(ByteQueue *queue, uint8_t *byte_ptr);
|
pika_bool byteQueue_readOne(ByteQueue *queue, uint8_t *byte_ptr);
|
||||||
PIKA_BOOL byteQueue_peekOne(ByteQueue *queue, uint8_t *byte_ptr);
|
pika_bool byteQueue_peekOne(ByteQueue *queue, uint8_t *byte_ptr);
|
||||||
void byteQueue_resetPeek(ByteQueue *queue);
|
void byteQueue_resetPeek(ByteQueue *queue);
|
||||||
void byteQueue_dropAllPeeked(ByteQueue *queue);
|
void byteQueue_dropAllPeeked(ByteQueue *queue);
|
||||||
uint_fast16_t byteQueue_getPeekedNumber(ByteQueue *queue);
|
uint_fast16_t byteQueue_getPeekedNumber(ByteQueue *queue);
|
||||||
uint_fast16_t byteQueue_peekAvailableCount(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
|
#endif
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -93,7 +93,7 @@ int32_t stack_deinit(Stack* stack) {
|
|||||||
void stack_pushPyload(Stack* stack,
|
void stack_pushPyload(Stack* stack,
|
||||||
uint8_t* in,
|
uint8_t* in,
|
||||||
size_t size,
|
size_t size,
|
||||||
PIKA_BOOL is_sample_copy) {
|
pika_bool is_sample_copy) {
|
||||||
size_t stack_size_after_push =
|
size_t stack_size_after_push =
|
||||||
size + (stack->sp - arg_getContent(stack->stack_pyload));
|
size + (stack->sp - arg_getContent(stack->stack_pyload));
|
||||||
if (stack_size_after_push > stack->stack_totle_size) {
|
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,
|
pika_platform_memcpy(top->content, ((Arg*)in)->_.buffer,
|
||||||
size - sizeof(Arg));
|
size - sizeof(Arg));
|
||||||
/* transfer to serialized form */
|
/* transfer to serialized form */
|
||||||
arg_setSerialized(top, PIKA_TRUE);
|
arg_setSerialized(top, pika_true);
|
||||||
}
|
}
|
||||||
stack->sp += size;
|
stack->sp += size;
|
||||||
}
|
}
|
||||||
@ -128,8 +128,8 @@ uint8_t* stack_popPyload(Stack* stack, int32_t size) {
|
|||||||
return stack->sp;
|
return stack->sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
|
static int32_t _stack_pushArg(Stack* stack, Arg* arg, pika_bool is_alloc) {
|
||||||
PIKA_BOOL is_big_arg = PIKA_FALSE;
|
pika_bool is_big_arg = pika_false;
|
||||||
stack->top++;
|
stack->top++;
|
||||||
size_t size = arg_getTotleSize(arg);
|
size_t size = arg_getTotleSize(arg);
|
||||||
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
|
//! 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);
|
arg_refcntInc(arg);
|
||||||
|
|
||||||
if (arg_isSerialized(arg)) {
|
if (arg_isSerialized(arg)) {
|
||||||
is_big_arg = PIKA_TRUE;
|
is_big_arg = pika_true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_big_arg) {
|
if (is_big_arg) {
|
||||||
/* push a pointer to this arg */
|
/* push a pointer to this arg */
|
||||||
stack_pushSize(stack, -1);
|
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 {
|
} else {
|
||||||
stack_pushSize(stack, size);
|
stack_pushSize(stack, size);
|
||||||
stack_pushPyload(stack, (uint8_t*)arg, size,
|
stack_pushPyload(stack, (uint8_t*)arg, size,
|
||||||
(PIKA_BOOL)arg_isSerialized(arg));
|
(pika_bool)arg_isSerialized(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_big_arg) {
|
if (is_big_arg) {
|
||||||
@ -171,9 +171,9 @@ int32_t stack_pushArg(Stack* stack, Arg* arg) {
|
|||||||
pika_assert(obj_checkAlive(arg_getPtr(arg)));
|
pika_assert(obj_checkAlive(arg_getPtr(arg)));
|
||||||
}
|
}
|
||||||
if (arg_isSerialized(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) {
|
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);
|
return stack_pushArg(stack, newArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* _stack_popArg(Stack* stack, Arg* arg_dict, PIKA_BOOL is_alloc) {
|
Arg* _stack_popArg(Stack* stack, Arg* arg_dict, pika_bool is_alloc) {
|
||||||
PIKA_BOOL is_big_arg = PIKA_FALSE;
|
pika_bool is_big_arg = pika_false;
|
||||||
if (stack->top == 0) {
|
if (stack->top == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
stack->top--;
|
stack->top--;
|
||||||
int32_t size = stack_popSize(stack);
|
int32_t size = stack_popSize(stack);
|
||||||
if (size == -1) {
|
if (size == -1) {
|
||||||
is_big_arg = PIKA_TRUE;
|
is_big_arg = pika_true;
|
||||||
size = sizeof(Arg*);
|
size = sizeof(Arg*);
|
||||||
}
|
}
|
||||||
Arg* arg = NULL;
|
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) {
|
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) {
|
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) {
|
char* stack_popStr(Stack* stack, char* outBuff) {
|
||||||
|
@ -94,10 +94,10 @@ const char bracketStart[] = {'(', '[', '{', '\'', '\"'};
|
|||||||
const char bracketEnd[] = {')', ']', '}', '\'', '\"'};
|
const char bracketEnd[] = {')', ']', '}', '\'', '\"'};
|
||||||
#define BRACKET_TYPE_NUM (sizeof(bracketStart) / sizeof(char))
|
#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 iCount = 0;
|
||||||
int32_t iTotalDepth = 0;
|
int32_t iTotalDepth = 0;
|
||||||
PIKA_BOOL bEscaped = PIKA_FALSE;
|
pika_bool bEscaped = pika_false;
|
||||||
for (size_t i = 0; strIn[i] != '\0'; i++) {
|
for (size_t i = 0; strIn[i] != '\0'; i++) {
|
||||||
if (!bracketDepth0) {
|
if (!bracketDepth0) {
|
||||||
if (strIn[i] == sign) {
|
if (strIn[i] == sign) {
|
||||||
@ -122,7 +122,7 @@ int _strCountSign(char* strIn, char sign, PIKA_BOOL bracketDepth0) {
|
|||||||
if (cCurrentChar == sign && iTotalDepth == 0) {
|
if (cCurrentChar == sign && iTotalDepth == 0) {
|
||||||
iCount++;
|
iCount++;
|
||||||
}
|
}
|
||||||
bEscaped = PIKA_FALSE;
|
bEscaped = pika_false;
|
||||||
}
|
}
|
||||||
return iCount;
|
return iCount;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ int strPathGetFileName(char* input, char* output);
|
|||||||
int strGetIndent(char* string);
|
int strGetIndent(char* string);
|
||||||
int strIsBlank(char* string);
|
int strIsBlank(char* string);
|
||||||
int strOnly(char* string, char ch);
|
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
|
#endif
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -85,6 +85,10 @@ extern "C" {
|
|||||||
#define arg_newNull arg_newNone
|
#define arg_newNull arg_newNone
|
||||||
#define arg_setNull arg_setNone
|
#define arg_setNull arg_setNone
|
||||||
|
|
||||||
|
#define PIKA_BOOL pika_bool
|
||||||
|
#define PIKA_TRUE pika_true
|
||||||
|
#define PIKA_FALSE pika_false
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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_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
|
#endif
|
||||||
|
|
||||||
TEST_END
|
TEST_END
|
@ -30,7 +30,7 @@ impl PyType {
|
|||||||
return "Arg*".to_string();
|
return "Arg*".to_string();
|
||||||
}
|
}
|
||||||
if self.type_name == "bool"{
|
if self.type_name == "bool"{
|
||||||
return "PIKA_BOOL".to_string();
|
return "pika_bool".to_string();
|
||||||
}
|
}
|
||||||
if self.type_name == "@tupleVarPar" {
|
if self.type_name == "@tupleVarPar" {
|
||||||
return "PikaTuple*".to_string();
|
return "PikaTuple*".to_string();
|
||||||
@ -49,7 +49,7 @@ impl PyType {
|
|||||||
return "int64_t".to_string();
|
return "int64_t".to_string();
|
||||||
}
|
}
|
||||||
if self.type_name == "bool" {
|
if self.type_name == "bool" {
|
||||||
return "PIKA_BOOL".to_string();
|
return "pika_bool".to_string();
|
||||||
}
|
}
|
||||||
if self.type_name == "float" {
|
if self.type_name == "float" {
|
||||||
return "pika_float".to_string();
|
return "pika_float".to_string();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user