mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add q_array in vmstate
This commit is contained in:
parent
c5a088d97f
commit
0d8ef5e5f7
36
src/PikaVM.c
36
src/PikaVM.c
@ -201,7 +201,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, VMState* vs, char* data) {
|
|||||||
ByteCodeFrame* method_bytecodeFrame;
|
ByteCodeFrame* method_bytecodeFrame;
|
||||||
/* return arg directly */
|
/* return arg directly */
|
||||||
if (strEqu(data, "")) {
|
if (strEqu(data, "")) {
|
||||||
return_arg = arg_copy(queue_popArg(vs->q1));
|
return_arg = arg_copy(queue_popArg(vs->qSuper));
|
||||||
goto RUN_exit;
|
goto RUN_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, VMState* vs, char* data) {
|
|||||||
if ((method_type == ARG_TYPE_OBJECT_METHOD) && (call_arg_index == 0)) {
|
if ((method_type == ARG_TYPE_OBJECT_METHOD) && (call_arg_index == 0)) {
|
||||||
call_arg = arg_setPtr(NULL, "", ARG_TYPE_POINTER, method_host_obj);
|
call_arg = arg_setPtr(NULL, "", ARG_TYPE_POINTER, method_host_obj);
|
||||||
} else {
|
} else {
|
||||||
call_arg = arg_copy(queue_popArg(vs->q1));
|
call_arg = arg_copy(queue_popArg(vs->qSuper));
|
||||||
}
|
}
|
||||||
/* exit when there is no arg in queue */
|
/* exit when there is no arg in queue */
|
||||||
if (NULL == call_arg) {
|
if (NULL == call_arg) {
|
||||||
@ -322,7 +322,7 @@ static Arg* __VM_OUT(PikaObj* self,
|
|||||||
VMState* vs,
|
VMState* vs,
|
||||||
char* data,
|
char* data,
|
||||||
is_init_obj_t is_init_obj) {
|
is_init_obj_t is_init_obj) {
|
||||||
Arg* outArg = arg_copy(queue_popArg(vs->q0));
|
Arg* outArg = arg_copy(queue_popArg(vs->qThis));
|
||||||
ArgType outArg_type = arg_getType(outArg);
|
ArgType outArg_type = arg_getType(outArg);
|
||||||
PikaObj* hostObj = vs->locals;
|
PikaObj* hostObj = vs->locals;
|
||||||
/* match global_list */
|
/* match global_list */
|
||||||
@ -414,7 +414,7 @@ static Arg* VM_instruction_handler_JMP(PikaObj* self, VMState* vs, char* data) {
|
|||||||
static Arg* VM_instruction_handler_JEZ(PikaObj* self, VMState* vs, char* data) {
|
static Arg* VM_instruction_handler_JEZ(PikaObj* self, VMState* vs, char* data) {
|
||||||
int thisBlockDeepth;
|
int thisBlockDeepth;
|
||||||
thisBlockDeepth = VMState_getBlockDeepthNow(vs);
|
thisBlockDeepth = VMState_getBlockDeepthNow(vs);
|
||||||
Arg* assertArg = arg_copy(queue_popArg(vs->q0));
|
Arg* assertArg = arg_copy(queue_popArg(vs->qThis));
|
||||||
int assert = arg_getInt(assertArg);
|
int assert = arg_getInt(assertArg);
|
||||||
arg_deinit(assertArg);
|
arg_deinit(assertArg);
|
||||||
char __else[] = "__else0";
|
char __else[] = "__else0";
|
||||||
@ -429,8 +429,8 @@ static Arg* VM_instruction_handler_JEZ(PikaObj* self, VMState* vs, char* data) {
|
|||||||
|
|
||||||
static Arg* VM_instruction_handler_OPT(PikaObj* self, VMState* vs, char* data) {
|
static Arg* VM_instruction_handler_OPT(PikaObj* self, VMState* vs, char* data) {
|
||||||
Arg* outArg = NULL;
|
Arg* outArg = NULL;
|
||||||
Arg* arg1 = arg_copy(queue_popArg(vs->q1));
|
Arg* arg1 = arg_copy(queue_popArg(vs->qSuper));
|
||||||
Arg* arg2 = arg_copy(queue_popArg(vs->q1));
|
Arg* arg2 = arg_copy(queue_popArg(vs->qSuper));
|
||||||
ArgType type_arg1 = arg_getType(arg1);
|
ArgType type_arg1 = arg_getType(arg1);
|
||||||
ArgType type_arg2 = arg_getType(arg2);
|
ArgType type_arg2 = arg_getType(arg2);
|
||||||
int num1_i = 0;
|
int num1_i = 0;
|
||||||
@ -638,7 +638,7 @@ static Arg* VM_instruction_handler_DEF(PikaObj* self, VMState* vs, char* data) {
|
|||||||
static Arg* VM_instruction_handler_RET(PikaObj* self, VMState* vs, char* data) {
|
static Arg* VM_instruction_handler_RET(PikaObj* self, VMState* vs, char* data) {
|
||||||
/* exit jmp signal */
|
/* exit jmp signal */
|
||||||
vs->jmp = -999;
|
vs->jmp = -999;
|
||||||
Arg* returnArg = arg_copy(queue_popArg(vs->q0));
|
Arg* returnArg = arg_copy(queue_popArg(vs->qThis));
|
||||||
method_returnArg(vs->locals->list, returnArg);
|
method_returnArg(vs->locals->list, returnArg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -733,21 +733,21 @@ static int pikaVM_runInstructUnit(PikaObj* self,
|
|||||||
|
|
||||||
char* data = VMState_getConstWithInstructUnit(vs, ins_unit);
|
char* data = VMState_getConstWithInstructUnit(vs, ins_unit);
|
||||||
|
|
||||||
vs->q0 = args_getPtr(vs->locals->list, invode_deepth0_str);
|
vs->qThis = args_getPtr(vs->locals->list, invode_deepth0_str);
|
||||||
vs->q1 = args_getPtr(vs->locals->list, invode_deepth1_str);
|
vs->qSuper = args_getPtr(vs->locals->list, invode_deepth1_str);
|
||||||
|
|
||||||
if (NULL == vs->q0) {
|
if (NULL == vs->qThis) {
|
||||||
vs->q0 = New_queue();
|
vs->qThis = New_queue();
|
||||||
args_setPtr(vs->locals->list, invode_deepth0_str, vs->q0);
|
args_setPtr(vs->locals->list, invode_deepth0_str, vs->qThis);
|
||||||
}
|
}
|
||||||
if (NULL == vs->q1) {
|
if (NULL == vs->qSuper) {
|
||||||
vs->q1 = New_queue();
|
vs->qSuper = New_queue();
|
||||||
args_setPtr(vs->locals->list, invode_deepth1_str, vs->q1);
|
args_setPtr(vs->locals->list, invode_deepth1_str, vs->qSuper);
|
||||||
}
|
}
|
||||||
/* run instruct */
|
/* run instruct */
|
||||||
resArg = VM_instruct_handler_table[instruct](self, vs, data);
|
resArg = VM_instruct_handler_table[instruct](self, vs, data);
|
||||||
if (NULL != resArg) {
|
if (NULL != resArg) {
|
||||||
queue_pushArg(vs->q0, resArg);
|
queue_pushArg(vs->qThis, resArg);
|
||||||
}
|
}
|
||||||
goto nextLine;
|
goto nextLine;
|
||||||
nextLine:
|
nextLine:
|
||||||
@ -1142,8 +1142,8 @@ VMParameters* pikaVM_runByteCodeWithState(PikaObj* self,
|
|||||||
.locals = locals,
|
.locals = locals,
|
||||||
.globals = globals,
|
.globals = globals,
|
||||||
.jmp = 0,
|
.jmp = 0,
|
||||||
.q0 = NULL,
|
.qThis = NULL,
|
||||||
.q1 = NULL,
|
.qSuper = NULL,
|
||||||
.pc = pc,
|
.pc = pc,
|
||||||
.error_code = 0,
|
.error_code = 0,
|
||||||
};
|
};
|
||||||
|
@ -40,8 +40,9 @@ enum Instruct {
|
|||||||
typedef struct VMState_t {
|
typedef struct VMState_t {
|
||||||
VMParameters* locals;
|
VMParameters* locals;
|
||||||
VMParameters* globals;
|
VMParameters* globals;
|
||||||
Queue* q0;
|
Queue* qThis;
|
||||||
Queue* q1;
|
Queue* qSuper;
|
||||||
|
Queue* q[10];
|
||||||
int32_t jmp;
|
int32_t jmp;
|
||||||
int32_t pc;
|
int32_t pc;
|
||||||
ByteCodeFrame* bytecode_frame;
|
ByteCodeFrame* bytecode_frame;
|
||||||
|
@ -29,12 +29,16 @@
|
|||||||
#include "PikaPlatform.h"
|
#include "PikaPlatform.h"
|
||||||
#include "dataArgs.h"
|
#include "dataArgs.h"
|
||||||
|
|
||||||
|
void queue_init(Queue* queue) {
|
||||||
|
args_setInt(queue, "__t", 0);
|
||||||
|
args_setInt(queue, "__b", 0);
|
||||||
|
return queue;
|
||||||
|
}
|
||||||
|
|
||||||
Queue* New_queue(void) {
|
Queue* New_queue(void) {
|
||||||
Args* args = New_args(NULL);
|
Args* args = New_args(NULL);
|
||||||
args_setInt(args, "__t", 0);
|
queue_init(args) ;
|
||||||
args_setInt(args, "__b", 0);
|
return (Queue*)args;
|
||||||
Queue* queue = args;
|
|
||||||
return queue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t queue_deinit(Queue* queue) {
|
int32_t queue_deinit(Queue* queue) {
|
||||||
|
@ -37,10 +37,12 @@ int32_t queue_pushInt(Queue* queue, int val);
|
|||||||
int32_t queue_pushFloat(Queue* queue, float val);
|
int32_t queue_pushFloat(Queue* queue, float val);
|
||||||
int32_t queue_pushStr(Queue* queue, char* str);
|
int32_t queue_pushStr(Queue* queue, char* str);
|
||||||
int32_t queue_pushArg(Queue* queue, Arg* arg);
|
int32_t queue_pushArg(Queue* queue, Arg* arg);
|
||||||
char *fast_itoa(char *buf, uint32_t val);
|
char* fast_itoa(char* buf, uint32_t val);
|
||||||
|
|
||||||
int64_t queue_popInt(Queue* queue);
|
int64_t queue_popInt(Queue* queue);
|
||||||
float queue_popFloat(Queue* queue);
|
float queue_popFloat(Queue* queue);
|
||||||
char* queue_popStr(Queue* queue);
|
char* queue_popStr(Queue* queue);
|
||||||
Arg* queue_popArg(Queue* queue);
|
Arg* queue_popArg(Queue* queue);
|
||||||
|
int32_t queue_deinit_stack(Queue* queue);
|
||||||
|
void queue_init(Queue* queue);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user