mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
assert for test_import_bf1/2 is ok
This commit is contained in:
parent
876ea81576
commit
c3bc444af0
@ -19,7 +19,7 @@ void PikaStdTask_Task___init__(PikaObj* self) {
|
||||
};
|
||||
PIKA_PYTHON_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
obj_setRefObject(__pikaMain, "__calls", obj_getPtr(self, "calls"));
|
||||
obj_setRef(__pikaMain, "__calls", obj_getPtr(self, "calls"));
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
||||
|
@ -19,7 +19,7 @@ void PikaStdTask_Task___init__(PikaObj* self) {
|
||||
};
|
||||
PIKA_PYTHON_END
|
||||
pikaVM_runByteCode(self, (uint8_t*)bytes);
|
||||
obj_setRefObject(__pikaMain, "__calls", obj_getPtr(self, "calls"));
|
||||
obj_setRef(__pikaMain, "__calls", obj_getPtr(self, "calls"));
|
||||
}
|
||||
|
||||
void PikaStdTask_Task_call_always(PikaObj* self, Arg* fun_todo) {
|
||||
|
@ -1,13 +1,18 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
extern "C" {
|
||||
#include "BaseObj.h"
|
||||
#include "PikaMain.h"
|
||||
#include "PikaParser.h"
|
||||
#include "PikaStdLib_MemChecker.h"
|
||||
#include "PikaVM.h"
|
||||
#include "dataArgs.h"
|
||||
#include "dataMemory.h"
|
||||
#include "dataStrs.h"
|
||||
#include "pikaCompiler.h"
|
||||
#include "pikaScript.h"
|
||||
#include "pika_config_gtest.h"
|
||||
}
|
||||
|
||||
extern char log_buff[LOG_BUFF_MAX][LOG_SIZE];
|
||||
TEST(compiler, file) {
|
||||
char* lines =(char*)
|
||||
"len = __calls.len()\n"
|
||||
@ -113,7 +118,6 @@ TEST(compiler, demo1) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
|
||||
TEST(compiler, snake_file) {
|
||||
char* lines =(char*)
|
||||
"from PikaObj import *\n"
|
||||
@ -254,4 +258,61 @@ TEST(compiler, snake_file) {
|
||||
" isUpdate = 1\n";
|
||||
pikaCompile((char*)"snake.bin", (char*)lines);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(compiler, import_bf_mem) {
|
||||
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
char* lines =(char*)
|
||||
"def mytest():\n"
|
||||
" print('test')\n"
|
||||
"\n";
|
||||
ByteCodeFrame bf;
|
||||
byteCodeFrame_init(&bf);
|
||||
bytecodeFrame_fromMultiLine(&bf, lines);
|
||||
obj_importModuleWithByteCodeFrame(pikaMain, (char*)"mtest", &bf);
|
||||
byteCodeFrame_deinit(&bf);
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(compiler, import_bf1) {
|
||||
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
char* lines =(char*)
|
||||
"def mytest():\n"
|
||||
" print('test_import_bf1')\n"
|
||||
"\n";
|
||||
ByteCodeFrame bf;
|
||||
byteCodeFrame_init(&bf);
|
||||
bytecodeFrame_fromMultiLine(&bf, lines);
|
||||
obj_importModuleWithByteCodeFrame(pikaMain, (char*)"mtest", &bf);
|
||||
obj_run(pikaMain, (char*)
|
||||
"mtest.mytest()\n"
|
||||
"\n"
|
||||
);
|
||||
EXPECT_STREQ(log_buff[0], "test_import_bf1\r\n");
|
||||
byteCodeFrame_deinit(&bf);
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(compiler, import_bf2) {
|
||||
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
|
||||
char* lines =(char*)
|
||||
"class Test:\n"
|
||||
" def mytest(self):\n"
|
||||
" print('test_import_bf2')\n"
|
||||
"\n";
|
||||
ByteCodeFrame bf;
|
||||
byteCodeFrame_init(&bf);
|
||||
bytecodeFrame_fromMultiLine(&bf, lines);
|
||||
obj_importModuleWithByteCodeFrame(pikaMain, (char*)"mtest", &bf);
|
||||
obj_run(pikaMain, (char*)
|
||||
"m = mtest.Test()\n"
|
||||
"m.mytest()\n"
|
||||
"\n"
|
||||
);
|
||||
byteCodeFrame_deinit(&bf);
|
||||
obj_deinit(pikaMain);
|
||||
EXPECT_STREQ(log_buff[0], "test_import_bf2\r\n");
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ TEST(object_test, obj_mem) {
|
||||
size_t mem_size = obj_getBytesSize(self, (char*)"mem");
|
||||
char* mem_test_out = (char*)obj_getBytes(self, (char*)"mem");
|
||||
ArgType arg_type = arg_getType(obj_getArg(self, (char*)"mem"));
|
||||
obj_loadMem(self, (char*)"mem", mem_out_buff);
|
||||
obj_loadBytes(self, (char*)"mem", mem_out_buff);
|
||||
/* assert */
|
||||
EXPECT_EQ(mem_size, sizeof(mem_test));
|
||||
EXPECT_EQ(mem_test_out[0], 0x33);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "dataMemory.h"
|
||||
#include "dataString.h"
|
||||
#include "dataStrs.h"
|
||||
#include "PikaMain.h"
|
||||
|
||||
static const uint64_t __talbe_fast_atoi[][10] = {
|
||||
{0, 1e0, 2e0, 3e0, 4e0, 5e0, 6e0, 7e0, 8e0, 9e0},
|
||||
@ -137,13 +138,13 @@ int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t obj_setRefObject(PikaObj* self, char* argPath, void* pointer) {
|
||||
int32_t obj_setRef(PikaObj* self, char* argPath, void* pointer) {
|
||||
PikaObj* obj = obj_getHostObj(self, argPath);
|
||||
if (NULL == obj) {
|
||||
return 1;
|
||||
}
|
||||
char* name = strPointToLastToken(argPath, '.');
|
||||
args_setRefObj(obj->list, name, pointer);
|
||||
args_setRef(obj->list, name, pointer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -215,7 +216,7 @@ size_t obj_getBytesSize(PikaObj* self, char* argPath) {
|
||||
return args_getBytesSize(obj->list, argName);
|
||||
}
|
||||
|
||||
size_t obj_loadMem(PikaObj* self, char* argPath, uint8_t* out_buff) {
|
||||
size_t obj_loadBytes(PikaObj* self, char* argPath, uint8_t* out_buff) {
|
||||
size_t size_mem = obj_getBytesSize(self, argPath);
|
||||
void* src = obj_getBytes(self, argPath);
|
||||
if (0 == size_mem) {
|
||||
@ -890,12 +891,6 @@ Arg* arg_setWeakRef(Arg* self, char* name, PikaObj* obj) {
|
||||
return arg_setPtr(self, name, ARG_TYPE_OBJECT, obj);
|
||||
}
|
||||
|
||||
PikaObj* obj_importModuleWithByteCodeFrame(PikaObj* self,
|
||||
char* name,
|
||||
ByteCodeFrame* byteCode_frame) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t obj_newDirectObj(PikaObj* self, char* objName, NewFun newFunPtr) {
|
||||
Arg* new_obj = arg_newDirectObj(newFunPtr);
|
||||
new_obj = arg_setName(new_obj, objName);
|
||||
@ -918,3 +913,11 @@ int32_t obj_newObj(PikaObj* self,
|
||||
NewFun newFunPtr) {
|
||||
return obj_newMetaObj(self, objName, newFunPtr);
|
||||
}
|
||||
|
||||
PikaObj* obj_importModuleWithByteCodeFrame(PikaObj* self,
|
||||
char* name,
|
||||
ByteCodeFrame* byteCode_frame) {
|
||||
obj_newDirectObj(self, name, New_PikaMain);
|
||||
pikaVM_runByteCodeFrame(obj_getObj(self, name), byteCode_frame);
|
||||
return self;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ int32_t obj_disable(PikaObj* self);
|
||||
|
||||
// arg type operations
|
||||
int32_t obj_setInt(PikaObj* self, char* argPath, int64_t val);
|
||||
int32_t obj_setRefObject(PikaObj* self, char* argPath, void* pointer);
|
||||
int32_t obj_setRef(PikaObj* self, char* argPath, void* pointer);
|
||||
int32_t obj_setPtr(PikaObj* self, char* argPath, void* pointer);
|
||||
int32_t obj_setFloat(PikaObj* self, char* argPath, float value);
|
||||
int32_t obj_setStr(PikaObj* self, char* argPath, char* str);
|
||||
@ -118,7 +118,7 @@ int64_t obj_getInt(PikaObj* self, char* argPath);
|
||||
Arg* obj_getArg(PikaObj* self, char* argPath);
|
||||
uint8_t* obj_getBytes(PikaObj* self, char* argPath);
|
||||
size_t obj_getBytesSize(PikaObj* self, char* argPath);
|
||||
size_t obj_loadMem(PikaObj* self, char* argPath, uint8_t* out_buff);
|
||||
size_t obj_loadBytes(PikaObj* self, char* argPath, uint8_t* out_buff);
|
||||
|
||||
char* obj_print(PikaObj* self, char* name);
|
||||
|
||||
@ -127,9 +127,6 @@ int32_t obj_load(PikaObj* self, Args* args, char* name);
|
||||
|
||||
// subObject
|
||||
int32_t obj_addOther(PikaObj* self, char* subObjectName, void* new_projcetFun);
|
||||
int32_t obj_setObjWithoutClass(PikaObj* self,
|
||||
char* subObjectName,
|
||||
void* new_projcetFun);
|
||||
PikaObj* obj_getObj(PikaObj* self, char* objPath);
|
||||
PikaObj* obj_getHostObj(PikaObj* self, char* objPath);
|
||||
|
||||
|
@ -523,7 +523,7 @@ static Arg* VM_instruction_handler_RAS(PikaObj* self, VMState* vs, char* data) {
|
||||
}
|
||||
/* use "data" object to run */
|
||||
PikaObj* runAs = obj_getObj(vs->locals, data);
|
||||
args_setRefObj(vs->locals->list, "__runAs", runAs);
|
||||
args_setRef(vs->locals->list, "__runAs", runAs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ int32_t args_setPtr(Args* self, char* name, void* argPointer) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
int32_t args_setRefObj(Args* self, char* name, void* argPointer) {
|
||||
int32_t args_setRef(Args* self, char* name, void* argPointer) {
|
||||
int32_t errCode = 0;
|
||||
Arg* argNew = New_arg(NULL);
|
||||
argNew = arg_setRef(argNew, name, argPointer);
|
||||
|
@ -64,7 +64,7 @@ int32_t args_setFloatWithDefaultName(Args* self, float argFloat);
|
||||
int32_t args_setFloat(Args* self, char* name, float argFloat);
|
||||
float args_getFloat(Args* self, char* name);
|
||||
|
||||
int32_t args_setRefObj(Args* self, char* name, void* argPointer);
|
||||
int32_t args_setRef(Args* self, char* name, void* argPointer);
|
||||
int32_t args_setPtr(Args* self, char* name, void* argPointer);
|
||||
void* args_getPtr(Args* self, char* name);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user