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(
|
||||
self, pikaParseLineToAsm(buffs, (char*)"a = 'xy '", NULL));
|
||||
globals = pikaVM_runAsmWithArgs(
|
||||
self, globals, pikaParseLineToAsm(buffs, (char*)"b = a", NULL));
|
||||
globals =
|
||||
pikaVM_runAsmWithArgs(self, globals, globals,
|
||||
pikaParseLineToAsm(buffs, (char*)"b = a", NULL));
|
||||
|
||||
args_deinit(buffs);
|
||||
ASSERT_STREQ(args_getStr(globals->attributeList, (char*)"b"), (char*)"xy ");
|
||||
@ -124,7 +125,7 @@ TEST(VM, Run_add_multy) {
|
||||
Parameters* globals =
|
||||
pikaVM_runAsm(self, pikaParseLineToAsm(buffs, (char*)"b = 2", NULL));
|
||||
globals = pikaVM_runAsmWithArgs(
|
||||
self, globals,
|
||||
self, globals, globals,
|
||||
pikaParseLineToAsm(buffs, (char*)"a = plusInt(1,b)", NULL));
|
||||
|
||||
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,
|
||||
Parameters* globals,
|
||||
Parameters* locals,
|
||||
enum Instruct instruct,
|
||||
char* data,
|
||||
Queue* invokeQuene0,
|
||||
Queue* invokeQuene1,
|
||||
int32_t* jmp,
|
||||
char* programConter) {
|
||||
Parameters* globals,
|
||||
Parameters* locals,
|
||||
enum Instruct instruct,
|
||||
char* data,
|
||||
Queue* invokeQuene0,
|
||||
Queue* invokeQuene1,
|
||||
int32_t* jmp,
|
||||
char* programConter) {
|
||||
if (instruct == NUM) {
|
||||
Arg* numArg = New_arg(NULL);
|
||||
if (strIsContain(data, '.')) {
|
||||
@ -383,8 +383,8 @@ Arg* pikaVM_runInstruct(PikaObj* self,
|
||||
char* methodCode = (char*)methodPtr;
|
||||
if (methodCode[0] == 'B' && methodCode[2] == '\n') {
|
||||
/* VM method */
|
||||
subLocals =
|
||||
pikaVM_runAsmWithArgs(methodHostObj, subLocals, methodCode);
|
||||
subLocals = pikaVM_runAsmWithArgs(methodHostObj, subLocals, globals,
|
||||
methodCode);
|
||||
/* get method return */
|
||||
returnArg = arg_copy(
|
||||
args_getArg(subLocals->attributeList, (char*)"return"));
|
||||
@ -548,8 +548,8 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
||||
}
|
||||
|
||||
Arg* resArg =
|
||||
pikaVM_runInstruct(self, globals, globals, instruct, data,
|
||||
invokeQuene0, invokeQuene1, &jmp, programCounter);
|
||||
pikaVM_runInstruct(self, globals, globals, instruct, data, invokeQuene0,
|
||||
invokeQuene1, &jmp, programCounter);
|
||||
if (NULL != resArg) {
|
||||
queue_pushArg(invokeQuene0, resArg);
|
||||
}
|
||||
@ -584,6 +584,7 @@ char* useFlashAsBuff(char* pikaAsm, Args* buffs) {
|
||||
|
||||
Parameters* pikaVM_runAsmWithArgs(PikaObj* self,
|
||||
Parameters* globals,
|
||||
Parameters* locals,
|
||||
char* pikaAsm) {
|
||||
int lineAddr = 0;
|
||||
int size = strGetSize(pikaAsm);
|
||||
@ -614,7 +615,7 @@ Parameters* pikaVM_runAsmWithArgs(PikaObj* self,
|
||||
|
||||
Parameters* pikaVM_runAsm(PikaObj* self, char* pikaAsm) {
|
||||
Parameters* globals = New_TinyObj(NULL);
|
||||
globals = pikaVM_runAsmWithArgs(self, globals, pikaAsm);
|
||||
globals = pikaVM_runAsmWithArgs(self, globals, globals, pikaAsm);
|
||||
return globals;
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,12 @@
|
||||
#define __PIKA__VM__H
|
||||
#include "PikaObj.h"
|
||||
|
||||
|
||||
Parameters* pikaVM_run(PikaObj* self, char* pyLine);
|
||||
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);
|
||||
char* useFlashAsBuff(char* pikaAsm, Args* buffs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user