mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add jmp_block for run_instruct
This commit is contained in:
parent
38244dfe0b
commit
8dc99a2362
29
src/PikaVM.c
29
src/PikaVM.c
@ -109,6 +109,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
|
|||||||
Queue* invokeQuene0,
|
Queue* invokeQuene0,
|
||||||
Queue* invokeQuene1,
|
Queue* invokeQuene1,
|
||||||
int32_t* jmp,
|
int32_t* jmp,
|
||||||
|
int32_t* jmp_block,
|
||||||
char* programConter,
|
char* programConter,
|
||||||
char* asmStart) {
|
char* asmStart) {
|
||||||
if (instruct == NUM) {
|
if (instruct == NUM) {
|
||||||
@ -491,9 +492,11 @@ int getThisBlockDeepth(char* start, char* code, int* offset) {
|
|||||||
return thisBlockDeepth;
|
return thisBlockDeepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getAddrOffsetFromJmp(char* start, char* code, int32_t jmp) {
|
int32_t VM_getAddrOffsetFromJmp(char* start,
|
||||||
int offset = 0;
|
char* code,
|
||||||
int thisBlockDeepth = getThisBlockDeepth(start, code, &offset);
|
int32_t jmp,
|
||||||
|
int32_t offset,
|
||||||
|
int thisBlockDeepth) {
|
||||||
char* codeNow = code + offset;
|
char* codeNow = code + offset;
|
||||||
int8_t blockNum = 0;
|
int8_t blockNum = 0;
|
||||||
if (jmp > 0) {
|
if (jmp > 0) {
|
||||||
@ -531,6 +534,14 @@ int32_t getAddrOffsetFromJmp(char* start, char* code, int32_t jmp) {
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t VM_getAddrOffsetFromJmpByThisBlockDeepth(char* start,
|
||||||
|
char* code,
|
||||||
|
int32_t jmp) {
|
||||||
|
int offset = 0;
|
||||||
|
int thisBlockDeepth = getThisBlockDeepth(start, code, &offset);
|
||||||
|
return VM_getAddrOffsetFromJmp(start, code, jmp, offset, thisBlockDeepth);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t pikaVM_runAsmLine(PikaObj* self,
|
int32_t pikaVM_runAsmLine(PikaObj* self,
|
||||||
Parameters* locals,
|
Parameters* locals,
|
||||||
Parameters* globals,
|
Parameters* globals,
|
||||||
@ -541,6 +552,7 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
|||||||
char* line = strs_getLine(buffs, programCounter);
|
char* line = strs_getLine(buffs, programCounter);
|
||||||
int32_t nextAddr = lineAddr + strGetSize(line) + 1;
|
int32_t nextAddr = lineAddr + strGetSize(line) + 1;
|
||||||
int32_t jmp = 0;
|
int32_t jmp = 0;
|
||||||
|
int32_t jmp_block = -1;
|
||||||
enum Instruct instruct;
|
enum Instruct instruct;
|
||||||
char invokeDeepth0[2] = {0}, invokeDeepth1[2] = {0};
|
char invokeDeepth0[2] = {0}, invokeDeepth1[2] = {0};
|
||||||
char* data;
|
char* data;
|
||||||
@ -569,9 +581,9 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
|||||||
invokeQuene1 = New_queue();
|
invokeQuene1 = New_queue();
|
||||||
args_setPtr(locals->list, invokeDeepth1, invokeQuene1);
|
args_setPtr(locals->list, invokeDeepth1, invokeQuene1);
|
||||||
}
|
}
|
||||||
resArg =
|
resArg = pikaVM_runInstruct(self, locals, globals, instruct, data,
|
||||||
pikaVM_runInstruct(self, locals, globals, instruct, data, invokeQuene0,
|
invokeQuene0, invokeQuene1, &jmp, &jmp_block,
|
||||||
invokeQuene1, &jmp, programCounter, pikaAsm);
|
programCounter, pikaAsm);
|
||||||
if (NULL != resArg) {
|
if (NULL != resArg) {
|
||||||
queue_pushArg(invokeQuene0, resArg);
|
queue_pushArg(invokeQuene0, resArg);
|
||||||
}
|
}
|
||||||
@ -582,7 +594,10 @@ nextLine:
|
|||||||
return -99999;
|
return -99999;
|
||||||
}
|
}
|
||||||
if (jmp != 0) {
|
if (jmp != 0) {
|
||||||
return lineAddr + getAddrOffsetFromJmp(pikaAsm, programCounter, jmp);
|
if (-1 == jmp_block) {
|
||||||
|
return lineAddr + VM_getAddrOffsetFromJmpByThisBlockDeepth(
|
||||||
|
pikaAsm, programCounter, jmp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nextAddr;
|
return nextAddr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user