mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add globals is ok
This commit is contained in:
parent
96fec2858d
commit
582af57772
@ -92,8 +92,9 @@ TEST(VM, ref_a_b) {
|
|||||||
|
|
||||||
Parameters* globals = pikaVM_runAsm(
|
Parameters* globals = pikaVM_runAsm(
|
||||||
self, pikaParseLineToAsm(buffs, (char*)"a = 'xy '", NULL));
|
self, pikaParseLineToAsm(buffs, (char*)"a = 'xy '", NULL));
|
||||||
globals = pikaVM_runAsmWithArgs(
|
globals =
|
||||||
self, globals, pikaParseLineToAsm(buffs, (char*)"b = a", NULL));
|
pikaVM_runAsmWithArgs(self, globals, globals,
|
||||||
|
pikaParseLineToAsm(buffs, (char*)"b = a", NULL));
|
||||||
|
|
||||||
args_deinit(buffs);
|
args_deinit(buffs);
|
||||||
ASSERT_STREQ(args_getStr(globals->attributeList, (char*)"b"), (char*)"xy ");
|
ASSERT_STREQ(args_getStr(globals->attributeList, (char*)"b"), (char*)"xy ");
|
||||||
@ -124,7 +125,7 @@ TEST(VM, Run_add_multy) {
|
|||||||
Parameters* globals =
|
Parameters* globals =
|
||||||
pikaVM_runAsm(self, pikaParseLineToAsm(buffs, (char*)"b = 2", NULL));
|
pikaVM_runAsm(self, pikaParseLineToAsm(buffs, (char*)"b = 2", NULL));
|
||||||
globals = pikaVM_runAsmWithArgs(
|
globals = pikaVM_runAsmWithArgs(
|
||||||
self, globals,
|
self, globals, globals,
|
||||||
pikaParseLineToAsm(buffs, (char*)"a = plusInt(1,b)", NULL));
|
pikaParseLineToAsm(buffs, (char*)"a = plusInt(1,b)", NULL));
|
||||||
|
|
||||||
args_deinit(buffs);
|
args_deinit(buffs);
|
||||||
|
27
src/PikaVM.c
27
src/PikaVM.c
@ -101,14 +101,14 @@ int fast_atoi(char* src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Arg* pikaVM_runInstruct(PikaObj* self,
|
Arg* pikaVM_runInstruct(PikaObj* self,
|
||||||
Parameters* globals,
|
Parameters* globals,
|
||||||
Parameters* locals,
|
Parameters* locals,
|
||||||
enum Instruct instruct,
|
enum Instruct instruct,
|
||||||
char* data,
|
char* data,
|
||||||
Queue* invokeQuene0,
|
Queue* invokeQuene0,
|
||||||
Queue* invokeQuene1,
|
Queue* invokeQuene1,
|
||||||
int32_t* jmp,
|
int32_t* jmp,
|
||||||
char* programConter) {
|
char* programConter) {
|
||||||
if (instruct == NUM) {
|
if (instruct == NUM) {
|
||||||
Arg* numArg = New_arg(NULL);
|
Arg* numArg = New_arg(NULL);
|
||||||
if (strIsContain(data, '.')) {
|
if (strIsContain(data, '.')) {
|
||||||
@ -383,8 +383,8 @@ Arg* pikaVM_runInstruct(PikaObj* self,
|
|||||||
char* methodCode = (char*)methodPtr;
|
char* methodCode = (char*)methodPtr;
|
||||||
if (methodCode[0] == 'B' && methodCode[2] == '\n') {
|
if (methodCode[0] == 'B' && methodCode[2] == '\n') {
|
||||||
/* VM method */
|
/* VM method */
|
||||||
subLocals =
|
subLocals = pikaVM_runAsmWithArgs(methodHostObj, subLocals, globals,
|
||||||
pikaVM_runAsmWithArgs(methodHostObj, subLocals, methodCode);
|
methodCode);
|
||||||
/* get method return */
|
/* get method return */
|
||||||
returnArg = arg_copy(
|
returnArg = arg_copy(
|
||||||
args_getArg(subLocals->attributeList, (char*)"return"));
|
args_getArg(subLocals->attributeList, (char*)"return"));
|
||||||
@ -548,8 +548,8 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Arg* resArg =
|
Arg* resArg =
|
||||||
pikaVM_runInstruct(self, globals, globals, instruct, data,
|
pikaVM_runInstruct(self, globals, globals, instruct, data, invokeQuene0,
|
||||||
invokeQuene0, invokeQuene1, &jmp, programCounter);
|
invokeQuene1, &jmp, programCounter);
|
||||||
if (NULL != resArg) {
|
if (NULL != resArg) {
|
||||||
queue_pushArg(invokeQuene0, resArg);
|
queue_pushArg(invokeQuene0, resArg);
|
||||||
}
|
}
|
||||||
@ -584,6 +584,7 @@ char* useFlashAsBuff(char* pikaAsm, Args* buffs) {
|
|||||||
|
|
||||||
Parameters* pikaVM_runAsmWithArgs(PikaObj* self,
|
Parameters* pikaVM_runAsmWithArgs(PikaObj* self,
|
||||||
Parameters* globals,
|
Parameters* globals,
|
||||||
|
Parameters* locals,
|
||||||
char* pikaAsm) {
|
char* pikaAsm) {
|
||||||
int lineAddr = 0;
|
int lineAddr = 0;
|
||||||
int size = strGetSize(pikaAsm);
|
int size = strGetSize(pikaAsm);
|
||||||
@ -614,7 +615,7 @@ Parameters* pikaVM_runAsmWithArgs(PikaObj* self,
|
|||||||
|
|
||||||
Parameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm) {
|
Parameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm) {
|
||||||
Parameters* globals = New_TinyObj(NULL);
|
Parameters* globals = New_TinyObj(NULL);
|
||||||
globals = pikaVM_runAsmWithArgs(self, globals, pikaAsm);
|
globals = pikaVM_runAsmWithArgs(self, globals, globals, pikaAsm);
|
||||||
return globals;
|
return globals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
#define __PIKA__VM__H
|
#define __PIKA__VM__H
|
||||||
#include "PikaObj.h"
|
#include "PikaObj.h"
|
||||||
|
|
||||||
|
|
||||||
Parameters* pikaVM_run(PikaObj* self, char* pyLine);
|
Parameters* pikaVM_run(PikaObj* self, char* pyLine);
|
||||||
Parameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
Parameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
||||||
Parameters* pikaVM_runAsmWithArgs(PikaObj* self, Parameters* globals, char* pikaAsm);
|
Parameters* pikaVM_runAsmWithArgs(PikaObj* self,
|
||||||
|
Parameters* globals,
|
||||||
|
Parameters* locals,
|
||||||
|
char* pikaAsm);
|
||||||
|
|
||||||
int32_t __clearInvokeQueues(Parameters* globals);
|
int32_t __clearInvokeQueues(Parameters* globals);
|
||||||
char* useFlashAsBuff(char* pikaAsm, Args* buffs);
|
char* useFlashAsBuff(char* pikaAsm, Args* buffs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user