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;
|
||||
/* return arg directly */
|
||||
if (strEqu(data, "")) {
|
||||
return_arg = arg_copy(queue_popArg(vs->q1));
|
||||
return_arg = arg_copy(queue_popArg(vs->qSuper));
|
||||
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)) {
|
||||
call_arg = arg_setPtr(NULL, "", ARG_TYPE_POINTER, method_host_obj);
|
||||
} 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 */
|
||||
if (NULL == call_arg) {
|
||||
@ -322,7 +322,7 @@ static Arg* __VM_OUT(PikaObj* self,
|
||||
VMState* vs,
|
||||
char* data,
|
||||
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);
|
||||
PikaObj* hostObj = vs->locals;
|
||||
/* 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) {
|
||||
int thisBlockDeepth;
|
||||
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);
|
||||
arg_deinit(assertArg);
|
||||
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) {
|
||||
Arg* outArg = NULL;
|
||||
Arg* arg1 = arg_copy(queue_popArg(vs->q1));
|
||||
Arg* arg2 = arg_copy(queue_popArg(vs->q1));
|
||||
Arg* arg1 = arg_copy(queue_popArg(vs->qSuper));
|
||||
Arg* arg2 = arg_copy(queue_popArg(vs->qSuper));
|
||||
ArgType type_arg1 = arg_getType(arg1);
|
||||
ArgType type_arg2 = arg_getType(arg2);
|
||||
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) {
|
||||
/* exit jmp signal */
|
||||
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);
|
||||
return NULL;
|
||||
}
|
||||
@ -733,21 +733,21 @@ static int pikaVM_runInstructUnit(PikaObj* self,
|
||||
|
||||
char* data = VMState_getConstWithInstructUnit(vs, ins_unit);
|
||||
|
||||
vs->q0 = args_getPtr(vs->locals->list, invode_deepth0_str);
|
||||
vs->q1 = args_getPtr(vs->locals->list, invode_deepth1_str);
|
||||
vs->qThis = args_getPtr(vs->locals->list, invode_deepth0_str);
|
||||
vs->qSuper = args_getPtr(vs->locals->list, invode_deepth1_str);
|
||||
|
||||
if (NULL == vs->q0) {
|
||||
vs->q0 = New_queue();
|
||||
args_setPtr(vs->locals->list, invode_deepth0_str, vs->q0);
|
||||
if (NULL == vs->qThis) {
|
||||
vs->qThis = New_queue();
|
||||
args_setPtr(vs->locals->list, invode_deepth0_str, vs->qThis);
|
||||
}
|
||||
if (NULL == vs->q1) {
|
||||
vs->q1 = New_queue();
|
||||
args_setPtr(vs->locals->list, invode_deepth1_str, vs->q1);
|
||||
if (NULL == vs->qSuper) {
|
||||
vs->qSuper = New_queue();
|
||||
args_setPtr(vs->locals->list, invode_deepth1_str, vs->qSuper);
|
||||
}
|
||||
/* run instruct */
|
||||
resArg = VM_instruct_handler_table[instruct](self, vs, data);
|
||||
if (NULL != resArg) {
|
||||
queue_pushArg(vs->q0, resArg);
|
||||
queue_pushArg(vs->qThis, resArg);
|
||||
}
|
||||
goto nextLine;
|
||||
nextLine:
|
||||
@ -1142,8 +1142,8 @@ VMParameters* pikaVM_runByteCodeWithState(PikaObj* self,
|
||||
.locals = locals,
|
||||
.globals = globals,
|
||||
.jmp = 0,
|
||||
.q0 = NULL,
|
||||
.q1 = NULL,
|
||||
.qThis = NULL,
|
||||
.qSuper = NULL,
|
||||
.pc = pc,
|
||||
.error_code = 0,
|
||||
};
|
||||
|
@ -40,8 +40,9 @@ enum Instruct {
|
||||
typedef struct VMState_t {
|
||||
VMParameters* locals;
|
||||
VMParameters* globals;
|
||||
Queue* q0;
|
||||
Queue* q1;
|
||||
Queue* qThis;
|
||||
Queue* qSuper;
|
||||
Queue* q[10];
|
||||
int32_t jmp;
|
||||
int32_t pc;
|
||||
ByteCodeFrame* bytecode_frame;
|
||||
|
@ -29,12 +29,16 @@
|
||||
#include "PikaPlatform.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) {
|
||||
Args* args = New_args(NULL);
|
||||
args_setInt(args, "__t", 0);
|
||||
args_setInt(args, "__b", 0);
|
||||
Queue* queue = args;
|
||||
return queue;
|
||||
queue_init(args) ;
|
||||
return (Queue*)args;
|
||||
}
|
||||
|
||||
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_pushStr(Queue* queue, char* str);
|
||||
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);
|
||||
float queue_popFloat(Queue* queue);
|
||||
char* queue_popStr(Queue* queue);
|
||||
Arg* queue_popArg(Queue* queue);
|
||||
int32_t queue_deinit_stack(Queue* queue);
|
||||
void queue_init(Queue* queue);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user