move type to __arg

This commit is contained in:
Gabriel Wang 2022-01-24 19:50:53 +00:00 committed by Lyon
parent d61fcacb4a
commit 0278a9d3fb
5 changed files with 27 additions and 29 deletions

View File

@ -131,9 +131,7 @@ int main(void)
uint32_t n = 0;
/* run unit test */
obj_deinit(pikaScriptInit());
/* benchmark */
uint64_t nCycleUsed_c,nCycleUsed_pika = 0;
printf("[----------benchmark----------]\r\n");

View File

@ -390,7 +390,7 @@ PikaObj* obj_getObjDirect(PikaObj* self, char* name) {
}
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));
char token_buff[32] = {0};
int32_t token_num = strGetTokenNum(objPath, '.');

View File

@ -67,16 +67,14 @@ uint8_t* content_init_hash(Hash nameHash,
uint8_t* content,
uint32_t size,
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
__arg * self = (__arg *)pikaMalloc(nextLength + sizeLength + nameSize +
size + typeSize);
__arg * self = (__arg *)pikaMalloc(sizeof(__arg) + size + typeSize);
self->next = (__arg *)next;
self->size = size;
self->name_hash = nameHash;
self->type = type;
if (NULL != content) {
__platform_memcpy(self->content, content, size);
@ -84,6 +82,9 @@ uint8_t* content_init_hash(Hash nameHash,
__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;
return (uint8_t *)self;
@ -150,11 +151,16 @@ uint8_t* content_setType(uint8_t* self, ArgType type) {
}
__arg * arg = (__arg *)self;
(*(ArgType *)((uintptr_t)(arg->content) + arg->size)) = type;
arg->type = type;
return self;
}
ArgType content_getType(uint8_t* self) {
__arg * arg = (__arg *)self;
return arg->type;
}
Arg* arg_newContent(Arg* self, uint32_t size) {
uint8_t* newContent = content_init("", TYPE_NONE, NULL, size, NULL);
arg_freeContent(self);
@ -177,10 +183,7 @@ Arg* arg_setType(Arg* self, ArgType 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);
}
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) {
if (NULL == self) {

View File

@ -47,19 +47,14 @@ typedef struct __arg __arg;
struct __arg {
__arg *next;
uint32_t size;
uint16_t size;
uint8_t type;
uint8_t : 8;
Hash name_hash;
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);
#define content_getNameHash(__addr) (((__arg *)(__addr))->name_hash)

View File

@ -35,6 +35,15 @@ void* pikaMalloc(uint32_t size) {
if (0 != __is_locked_pikaMemory()) {
__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;
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed) {
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;