mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
move type to __arg
This commit is contained in:
parent
d61fcacb4a
commit
0278a9d3fb
@ -131,9 +131,7 @@ int main(void)
|
|||||||
uint32_t n = 0;
|
uint32_t n = 0;
|
||||||
/* run unit test */
|
/* run unit test */
|
||||||
obj_deinit(pikaScriptInit());
|
obj_deinit(pikaScriptInit());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* benchmark */
|
/* benchmark */
|
||||||
uint64_t nCycleUsed_c,nCycleUsed_pika = 0;
|
uint64_t nCycleUsed_c,nCycleUsed_pika = 0;
|
||||||
printf("[----------benchmark----------]\r\n");
|
printf("[----------benchmark----------]\r\n");
|
||||||
|
@ -390,7 +390,7 @@ PikaObj* obj_getObjDirect(PikaObj* self, char* name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PikaObj* obj_getObj(PikaObj* self, char* objPath, int32_t keepDeepth) {
|
PikaObj* obj_getObj(PikaObj* self, char* objPath, int32_t keepDeepth) {
|
||||||
char objPath_buff[64];
|
static char objPath_buff[64];
|
||||||
__platform_memcpy(objPath_buff, objPath, sizeof(objPath_buff));
|
__platform_memcpy(objPath_buff, objPath, sizeof(objPath_buff));
|
||||||
char token_buff[32] = {0};
|
char token_buff[32] = {0};
|
||||||
int32_t token_num = strGetTokenNum(objPath, '.');
|
int32_t token_num = strGetTokenNum(objPath, '.');
|
||||||
|
@ -67,16 +67,14 @@ uint8_t* content_init_hash(Hash nameHash,
|
|||||||
uint8_t* content,
|
uint8_t* content,
|
||||||
uint32_t size,
|
uint32_t size,
|
||||||
uint8_t* next) {
|
uint8_t* next) {
|
||||||
const uint8_t nextLength = sizeof(uint8_t*);
|
|
||||||
const uint8_t sizeLength = sizeof(uint32_t);
|
|
||||||
uint16_t nameSize = sizeof(Hash); // use hash
|
|
||||||
uint16_t typeSize = sizeof(ArgType); // use enum
|
uint16_t typeSize = sizeof(ArgType); // use enum
|
||||||
__arg * self = (__arg *)pikaMalloc(nextLength + sizeLength + nameSize +
|
__arg * self = (__arg *)pikaMalloc(sizeof(__arg) + size + typeSize);
|
||||||
size + typeSize);
|
|
||||||
|
|
||||||
self->next = (__arg *)next;
|
self->next = (__arg *)next;
|
||||||
self->size = size;
|
self->size = size;
|
||||||
self->name_hash = nameHash;
|
self->name_hash = nameHash;
|
||||||
|
self->type = type;
|
||||||
|
|
||||||
if (NULL != content) {
|
if (NULL != content) {
|
||||||
__platform_memcpy(self->content, content, size);
|
__platform_memcpy(self->content, content, size);
|
||||||
@ -84,6 +82,9 @@ uint8_t* content_init_hash(Hash nameHash,
|
|||||||
__platform_memset(self->content, 0, size);
|
__platform_memset(self->content, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Todo: Why remove this cause problem? no API read value from this location
|
||||||
|
*! please refer to content_setType and content_getType
|
||||||
|
*/
|
||||||
(*(ArgType *)((uintptr_t)(self->content) + size)) = type;
|
(*(ArgType *)((uintptr_t)(self->content) + size)) = type;
|
||||||
|
|
||||||
return (uint8_t *)self;
|
return (uint8_t *)self;
|
||||||
@ -150,11 +151,16 @@ uint8_t* content_setType(uint8_t* self, ArgType type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__arg * arg = (__arg *)self;
|
__arg * arg = (__arg *)self;
|
||||||
(*(ArgType *)((uintptr_t)(arg->content) + arg->size)) = type;
|
arg->type = type;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArgType content_getType(uint8_t* self) {
|
||||||
|
__arg * arg = (__arg *)self;
|
||||||
|
return arg->type;
|
||||||
|
}
|
||||||
|
|
||||||
Arg* arg_newContent(Arg* self, uint32_t size) {
|
Arg* arg_newContent(Arg* self, uint32_t size) {
|
||||||
uint8_t* newContent = content_init("", TYPE_NONE, NULL, size, NULL);
|
uint8_t* newContent = content_init("", TYPE_NONE, NULL, size, NULL);
|
||||||
arg_freeContent(self);
|
arg_freeContent(self);
|
||||||
@ -177,10 +183,7 @@ Arg* arg_setType(Arg* self, ArgType type) {
|
|||||||
return content_setType(self, type);
|
return content_setType(self, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgType content_getType(uint8_t* self) {
|
|
||||||
__arg * arg = (__arg *)self;
|
|
||||||
return (*(ArgType *)((uintptr_t)(arg->content) + arg->size));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -236,13 +239,6 @@ char* arg_getStr(Arg* self) {
|
|||||||
return (char*)arg_getContent(self);
|
return (char*)arg_getContent(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t content_typeOffset(uint8_t* self) {
|
|
||||||
const uint8_t nextLength = sizeof(uint8_t*);
|
|
||||||
const uint8_t sizeLength = sizeof(uint32_t);
|
|
||||||
uint16_t size = content_getSize(self);
|
|
||||||
uint16_t nameSize = sizeof(Hash);
|
|
||||||
return nextLength + sizeLength + nameSize + size;
|
|
||||||
}
|
|
||||||
|
|
||||||
Hash arg_getNameHash(Arg* self) {
|
Hash arg_getNameHash(Arg* self) {
|
||||||
if (NULL == self) {
|
if (NULL == self) {
|
||||||
|
@ -47,19 +47,14 @@ typedef struct __arg __arg;
|
|||||||
|
|
||||||
struct __arg {
|
struct __arg {
|
||||||
__arg *next;
|
__arg *next;
|
||||||
uint32_t size;
|
uint16_t size;
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t : 8;
|
||||||
Hash name_hash;
|
Hash name_hash;
|
||||||
uint8_t content[];
|
uint8_t content[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
uint16_t content_typeOffset(uint8_t* content);
|
|
||||||
|
|
||||||
#define content_contentOffset(...) offsetof(__arg, content)
|
|
||||||
#define content_sizeOffset(...) offsetof(__arg, size)
|
|
||||||
#define content_nextOffset(...) offsetof(__arg, next)
|
|
||||||
#define content_nameOffset(...) offsetof(__arg, name_hash)
|
|
||||||
|
|
||||||
//uint32_t content_getNameHash(uint8_t* content);
|
//uint32_t content_getNameHash(uint8_t* content);
|
||||||
#define content_getNameHash(__addr) (((__arg *)(__addr))->name_hash)
|
#define content_getNameHash(__addr) (((__arg *)(__addr))->name_hash)
|
||||||
|
|
||||||
|
@ -35,6 +35,15 @@ void* pikaMalloc(uint32_t size) {
|
|||||||
if (0 != __is_locked_pikaMemory()) {
|
if (0 != __is_locked_pikaMemory()) {
|
||||||
__platform_wait();
|
__platform_wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! if you unsure about the __impl_pikaMalloc, uncomment this to force alignment
|
||||||
|
#if 0
|
||||||
|
/* force alignment to avoid unaligned access */
|
||||||
|
if (sizeof(int_fast8_t) > 1) {
|
||||||
|
size = (size + sizeof(int_fast8_t) - 1) & ~(sizeof(int_fast8_t) - 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
pikaMemInfo.heapUsed += size;
|
pikaMemInfo.heapUsed += size;
|
||||||
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
|
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
|
||||||
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user