This commit is contained in:
pikastech 2022-08-05 13:51:52 +08:00
parent b47e2795d1
commit 554ce93439
7 changed files with 32 additions and 29 deletions

View File

@ -163,14 +163,14 @@ int32_t obj_setFloat(PikaObj* self, char* argPath, double value) {
return 0;
}
int32_t obj_setStr(PikaObj* self, char* argPath, char* str) {
PIKA_RES obj_setStr(PikaObj* self, char* argPath, char* str) {
PikaObj* obj = obj_getHostObj(self, argPath);
if (NULL == obj) {
return 1;
return PIKA_RES_ERR_INVALID_PTR;
}
char* name = strPointToLastToken(argPath, '.');
args_setStr(obj->list, name, str);
return 0;
return PIKA_RES_OK;
}
int32_t obj_setBytes(PikaObj* self, char* argPath, uint8_t* src, size_t size) {

View File

@ -104,7 +104,7 @@ int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val);
int32_t obj_setRef(PikaObj* self, char* argPath, void* pointer);
int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer);
int32_t obj_setFloat(PikaObj* self, char* argPath, double value);
int32_t obj_setStr(PikaObj* self, char* argPath, char* str);
PIKA_RES obj_setStr(PikaObj* self, char* argPath, char* str);
int32_t obj_setArg(PikaObj* self, char* argPath, Arg* arg);
int32_t obj_setArg_noCopy(PikaObj* self, char* argPath, Arg* arg);
int32_t obj_setBytes(PikaObj* self, char* argPath, uint8_t* src, size_t size);

View File

@ -1301,7 +1301,7 @@ char* Parser_popSubStmt(Args* outbuffs, char** stmt_p, char* delimiter) {
Arg* substmt_arg = arg_newStr("");
Arg* newstmt_arg = arg_newStr("");
char* stmt = *stmt_p;
PIKA_BOOL is_get_substmt = 0;
PIKA_BOOL is_get_substmt = PIKA_FALSE;
Args buffs = {0};
ParserState_forEachToken(ps, stmt) {
ParserState_iterStart(&ps);
@ -1319,7 +1319,7 @@ char* Parser_popSubStmt(Args* outbuffs, char** stmt_p, char* delimiter) {
}
if (strEqu(ps.token1.pyload, delimiter)) {
/* found delimiter */
is_get_substmt = 1;
is_get_substmt = PIKA_TRUE;
ParserState_iterEnd(&ps);
continue;
}
@ -2540,7 +2540,10 @@ ByteCodeFrame* byteCodeFrame_appendFromAsm(ByteCodeFrame* self, char* pikaAsm) {
};
uint16_t const_pool_offset;
uint16_t exist_offset;
int invoke_deepth_int = 0;
uint8_t space_num = 0;
uint8_t invoke_deepth_i = 0;
uint8_t ins_str_i = 0;
for (int i = 0; i < strCountSign(pikaAsm, '\n'); i++) {
Args buffs = {0};
char* line = strsGetLine(&buffs, asmer.line_pointer);
@ -2567,9 +2570,6 @@ ByteCodeFrame* byteCodeFrame_appendFromAsm(ByteCodeFrame* self, char* pikaAsm) {
/* get constPool offset */
const_pool_offset = 0;
uint8_t space_num = 0;
uint8_t invoke_deepth_i = 0;
uint8_t ins_str_i = 0;
for (int i = 0; i < (int)strGetSize(line); i++) {
if (space_num < 2) {
if (line[i] == ' ') {
@ -2607,7 +2607,7 @@ ByteCodeFrame* byteCodeFrame_appendFromAsm(ByteCodeFrame* self, char* pikaAsm) {
const_pool_offset = exist_offset;
}
int invoke_deepth_int = fast_atoi(invoke_deepth);
invoke_deepth_int = fast_atoi(invoke_deepth);
/* load Asm to byte code unit */
instructUnit_setBlockDeepth(&ins_unit, asmer.block_deepth_now);
instructUnit_setInvokeDeepth(&ins_unit, invoke_deepth_int);

View File

@ -197,7 +197,7 @@ static void VMState_delLReg(VMState* vs, uint8_t index) {
static void VMState_initReg(VMState* vs) {
for (uint8_t i = 0; i < PIKA_REGIST_SIZE; i++) {
vs->lreg[i] = NULL;
vs->ireg[i] = 0;
vs->ireg[i] = PIKA_FALSE;
}
}
@ -1167,20 +1167,20 @@ static Arg* VM_instruction_handler_JEZ(PikaObj* self,
int jmp_expect = fast_atoi(data);
arg_newReg(pika_assertArg_reg, PIKA_ARG_BUFF_SIZE);
Arg* pika_assertArg = stack_popArg(&(vs->stack), &pika_assertArg_reg);
int pika_assert = 0;
PIKA_BOOL pika_assert = PIKA_FALSE;
if (NULL != pika_assertArg) {
pika_assert = arg_getInt(pika_assertArg);
pika_assert = (PIKA_BOOL)arg_getInt(pika_assertArg);
}
arg_deinit(pika_assertArg);
vs->ireg[thisBlockDeepth] = !pika_assert;
vs->ireg[thisBlockDeepth] = (PIKA_BOOL)!pika_assert;
if (0 == pika_assert) {
if (PIKA_FALSE == pika_assert) {
/* jump */
vs->jmp = jmp_expect;
}
/* restore loop deepth */
if (2 == jmp_expect && 0 == pika_assert) {
if (2 == jmp_expect && PIKA_FALSE == pika_assert) {
int block_deepth_now = VMState_getBlockDeepthNow(vs);
vs->loop_deepth = block_deepth_now;
}

View File

@ -53,7 +53,7 @@ static Arg* arg_init_hash(Hash nameHash,
uint32_t size,
Arg* next) {
Arg* self = (Arg*)pikaMalloc(sizeof(Arg) + size);
self->next = next;
arg_setNext(self, next);
self->size = size;
self->name_hash = nameHash;
self->type = type;
@ -77,7 +77,7 @@ static Arg* arg_init(char* name,
}
void arg_init_stack(Arg* self, uint8_t* buffer, uint32_t size) {
self->buffer = buffer;
self->_.buffer = buffer;
self->size = size;
self->type = ARG_TYPE_UNDEF;
self->name_hash = 0;
@ -328,7 +328,7 @@ Arg* arg_copy_noalloc(Arg* arg_src, Arg* arg_dict) {
if (NULL == arg_src) {
return NULL;
}
if (NULL == arg_dict){
if (NULL == arg_dict) {
return arg_copy(arg_src);
}
/* size is too big to be copied by noalloc */

View File

@ -56,11 +56,14 @@ typedef enum {
typedef void (*StructDeinitFun)(void* struct_);
typedef struct Arg Arg;
typedef union{
Arg* next;
uint8_t * buffer;
} __arg_union;
struct Arg {
union {
Arg* next;
uint8_t* buffer;
};
__arg_union _;
uint32_t size;
uint8_t type;
PIKA_BOOL serialized;
@ -128,12 +131,12 @@ void arg_printBytes(Arg* self);
Arg* arg_loadFile(Arg* self, char* filename);
uint8_t argType_isObject(ArgType type);
#define arg_getNext(self) ((self)->next)
#define arg_getNext(self) ((self)->_.next)
#define arg_getSize(self) ((self)->size)
#define arg_getContent(self) \
((self)->serialized ? (self)->content : ((self)->buffer))
#define arg_getNext(self) ((self)->next)
#define arg_setNext(self, __next) ((self)->next = (__next))
((self)->serialized ? (self)->content : ((self)->_.buffer))
#define arg_getNext(self) ((self)->_.next)
#define arg_setNext(self, __next) ((self)->_.next = (__next))
#define argType_isObject(type) \
((type) == ARG_TYPE_OBJECT || (type) == ARG_TYPE_OBJECT_NEW)

View File

@ -78,7 +78,7 @@ void stack_pushPyload(Stack* stack, Arg* content, size_t size) {
__platform_memcpy(stack->sp, content, size);
} else {
__platform_memcpy(stack->sp, content, sizeof(Arg));
__platform_memcpy(stack->sp + sizeof(Arg), content->buffer,
__platform_memcpy(stack->sp + sizeof(Arg), content->_.buffer,
size - sizeof(Arg));
/* transfer to serialized form */
((Arg*)stack->sp)->serialized = PIKA_TRUE;