mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
serilized to api
use mask in arg for serilized support isKeyword flag for arg
This commit is contained in:
parent
004c0b45fc
commit
6726169ad9
@ -5,7 +5,7 @@ from PikaStdData import ByteArray
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
host = "127.0.0.1"
|
||||
port = 9999 + random.randint(0, 100)
|
||||
port = 9999 + random.randint(0, 1000)
|
||||
print("port:", port)
|
||||
server.bind((host, port))
|
||||
server.listen(5)
|
||||
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
// "--gtest_filter=parser.issues_I5MIFO"
|
||||
"--gtest_filter=object_test.test6"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -5,7 +5,7 @@ from PikaStdData import ByteArray
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
host = "127.0.0.1"
|
||||
port = 9999 + random.randint(0, 100)
|
||||
port = 9999 + random.randint(0, 1000)
|
||||
print("port:", port)
|
||||
server.bind((host, port))
|
||||
server.listen(5)
|
||||
@ -17,13 +17,13 @@ res = server.accept()
|
||||
accept = res[0]
|
||||
addr = res[1]
|
||||
|
||||
print("recv from client: %s" % str(addr))
|
||||
print("recv from client: %s" % str(addr))
|
||||
|
||||
client.send(String("send test from client").encode())
|
||||
print("server recv:", ByteArray(accept.recv(1024)).decode())
|
||||
print("server recv:", ByteArray(accept.recv(1024)).decode())
|
||||
|
||||
accept.send(String("send test from server").encode())
|
||||
print("client recv:", ByteArray(client.recv(1024)).decode())
|
||||
print("client recv:", ByteArray(client.recv(1024)).decode())
|
||||
|
||||
accept.close()
|
||||
client.close()
|
||||
|
@ -100,10 +100,10 @@ typedef enum {
|
||||
/* clang-format off */
|
||||
|
||||
/* pikascript bool type */
|
||||
typedef enum {
|
||||
PIKA_TRUE = 1,
|
||||
PIKA_FALSE = 0,
|
||||
} PIKA_BOOL;
|
||||
typedef enum{
|
||||
PIKA_TRUE = 1,
|
||||
PIKA_FALSE = 0,
|
||||
}PIKA_BOOL;
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
|
@ -57,7 +57,8 @@ static Arg* arg_init_hash(Hash nameHash,
|
||||
self->size = size;
|
||||
self->name_hash = nameHash;
|
||||
self->type = type;
|
||||
self->serialized = PIKA_TRUE;
|
||||
arg_setSerialized(self, PIKA_TRUE);
|
||||
arg_setIsKeyword(self, PIKA_FALSE);
|
||||
__platform_memset(arg_getContent(self), 0,
|
||||
aline_by(size, sizeof(uint32_t)));
|
||||
if (NULL != content) {
|
||||
@ -81,7 +82,8 @@ void arg_init_stack(Arg* self, uint8_t* buffer, uint32_t size) {
|
||||
self->size = size;
|
||||
self->type = ARG_TYPE_UNDEF;
|
||||
self->name_hash = 0;
|
||||
self->serialized = PIKA_FALSE;
|
||||
arg_setSerialized(self, PIKA_FALSE);
|
||||
arg_setIsKeyword(self, PIKA_FALSE);
|
||||
}
|
||||
|
||||
uint32_t arg_totleSize(Arg* self) {
|
||||
@ -339,7 +341,7 @@ Arg* arg_copy_noalloc(Arg* arg_src, Arg* arg_dict) {
|
||||
if (ARG_TYPE_OBJECT == arg_type) {
|
||||
obj_refcntInc((PikaObj*)arg_getPtr(arg_src));
|
||||
}
|
||||
arg_dict->serialized = PIKA_FALSE;
|
||||
arg_setSerialized(arg_dict, PIKA_FALSE);
|
||||
arg_dict = arg_setContent(arg_dict, arg_getContent(arg_src),
|
||||
arg_getContentSize(arg_src));
|
||||
arg_dict = arg_setNameHash(arg_dict, arg_getNameHash(arg_src));
|
||||
@ -423,7 +425,7 @@ void arg_deinit(Arg* self) {
|
||||
}
|
||||
/* deinit arg pointed heap */
|
||||
arg_deinitHeap(self);
|
||||
if (!self->serialized) {
|
||||
if (!arg_getSerialized(self)) {
|
||||
return;
|
||||
}
|
||||
/* free the ref */
|
||||
|
@ -56,17 +56,19 @@ typedef enum {
|
||||
typedef void (*StructDeinitFun)(void* struct_);
|
||||
|
||||
typedef struct Arg Arg;
|
||||
|
||||
typedef union {
|
||||
Arg* next;
|
||||
uint8_t* buffer;
|
||||
} _arg_union;
|
||||
|
||||
struct Arg {
|
||||
_arg_union _;
|
||||
uint32_t size;
|
||||
uint8_t type;
|
||||
PIKA_BOOL serialized;
|
||||
Hash name_hash;
|
||||
uint8_t content[];
|
||||
_arg_union _; // 32/64 bit
|
||||
uint32_t size; // 32 bit
|
||||
uint8_t type; // 8 bit
|
||||
PIKA_BOOL flag; //
|
||||
Hash name_hash; // 32bit
|
||||
uint8_t content[]; // n bit
|
||||
};
|
||||
|
||||
Arg* arg_getNext(Arg* self);
|
||||
@ -131,8 +133,22 @@ uint8_t argType_isObject(ArgType type);
|
||||
|
||||
#define arg_getNext(self) ((self)->_.next)
|
||||
#define arg_getSize(self) ((self)->size)
|
||||
|
||||
#define ARG_FLAG_MASK_SERIALIZED 0x01
|
||||
#define ARG_FLAG_MASK_ISKEYWORD 0x02
|
||||
|
||||
#define arg_getSerialized(self) ((self)->flag & ARG_FLAG_MASK_SERIALIZED)
|
||||
#define arg_setSerialized(self, _serialized) \
|
||||
((self)->flag = ((self)->flag & ~ARG_FLAG_MASK_SERIALIZED) | \
|
||||
((_serialized) ? ARG_FLAG_MASK_SERIALIZED : 0))
|
||||
#define arg_getIsKeyword(self) ((self)->flag & ARG_FLAG_MASK_ISKEYWORD)
|
||||
|
||||
#define arg_setIsKeyword(self, _isKeyword) \
|
||||
((self)->flag = ((self)->flag & ~ARG_FLAG_MASK_ISKEYWORD) | \
|
||||
((_isKeyword) ? ARG_FLAG_MASK_ISKEYWORD : 0))
|
||||
|
||||
#define arg_getContent(self) \
|
||||
((self)->serialized ? (self)->content : ((self)->_.buffer))
|
||||
(arg_getSerialized(self) ? (self)->content : ((self)->_.buffer))
|
||||
#define arg_getNext(self) ((self)->_.next)
|
||||
#define arg_setNext(self, __next) ((self)->_.next = (__next))
|
||||
|
||||
|
@ -88,7 +88,7 @@ PIKA_RES args_setStr(Args* self, char* name, char* strIn) {
|
||||
|
||||
PIKA_RES args_pushArg(Args* self, Arg* arg) {
|
||||
Arg* new_arg = NULL;
|
||||
if (!arg->serialized) {
|
||||
if (!arg_getSerialized(arg)) {
|
||||
new_arg = arg_copy(arg);
|
||||
arg_deinit(arg);
|
||||
} else {
|
||||
@ -306,7 +306,7 @@ PIKA_RES __updateArg(Args* self, Arg* argNew) {
|
||||
arg_setNext((Arg*)priorNode, (Arg*)nodeToUpdate);
|
||||
goto exit;
|
||||
exit:
|
||||
if (!argNew->serialized) {
|
||||
if (!arg_getSerialized(argNew)) {
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
arg_freeContent(argNew);
|
||||
|
@ -74,14 +74,14 @@ void stack_pushPyload(Stack* stack, Arg* content, size_t size) {
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
if (content->serialized) {
|
||||
if (arg_getSerialized(content)) {
|
||||
__platform_memcpy(stack->sp, content, size);
|
||||
} else {
|
||||
__platform_memcpy(stack->sp, content, sizeof(Arg));
|
||||
__platform_memcpy(stack->sp + sizeof(Arg), content->_.buffer,
|
||||
size - sizeof(Arg));
|
||||
/* transfer to serialized form */
|
||||
((Arg*)stack->sp)->serialized = PIKA_TRUE;
|
||||
arg_setSerialized((Arg*)stack->sp, PIKA_TRUE);
|
||||
}
|
||||
stack->sp += size;
|
||||
}
|
||||
@ -116,7 +116,7 @@ static int32_t _stack_pushArg(Stack* stack, Arg* arg, PIKA_BOOL is_alloc) {
|
||||
|
||||
int32_t stack_pushArg(Stack* stack, Arg* arg) {
|
||||
pika_assert(arg != NULL);
|
||||
if (arg->serialized) {
|
||||
if (arg_getSerialized(arg)) {
|
||||
return _stack_pushArg(stack, arg, PIKA_TRUE);
|
||||
}
|
||||
return _stack_pushArg(stack, arg, PIKA_FALSE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user