load bytecode ok

This commit is contained in:
lyon 2022-05-07 14:46:24 +08:00
parent 2a3b272ccd
commit 94a47b1fbc
4 changed files with 33 additions and 5 deletions

View File

@ -514,3 +514,11 @@ TEST(make, compile) {
obj_deinit(maker);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(make, depend) {
PikaMaker* maker = New_PikaMaker();
pikaMaker_setPWD(maker, "package/pikascript/");
pikaMaker_getDependencies(maker, "main");
obj_deinit(maker);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -385,8 +385,26 @@ void pikaMaker_compileModule(PikaMaker* self, char* module_name) {
obj_setStr(self, module_name, "compiled");
}
void pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
__Maker_compileModuleWithInfo(self, module_name);
/* update compile info */
obj_setStr(self, module_name, "compiled");
int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
int res = 0;
ByteCodeFrame bf = {0};
Args buffs = {0};
byteCodeFrame_init(&bf);
char* file_path = strsAppend(&buffs, obj_getStr(self, "pwd"), module_name);
file_path = strsAppend(&buffs, file_path, ".py.o");
Arg* file_arg = arg_loadFile(NULL, file_path);
if (NULL == file_arg) {
res = 1;
goto exit;
}
byteCodeFrame_loadByteCode(&bf, arg_getBytes(file_arg));
byteCodeFrame_print(&bf);
exit:
if (NULL != file_arg) {
arg_deinit(file_arg);
}
strsDeinit(&buffs);
byteCodeFrame_deinit(&bf);
return res;
}

View File

@ -23,6 +23,7 @@ int Lib_loadLibraryFileToArray(char* origin_file_name, char* pikascript_root);
PikaMaker* New_PikaMaker(void);
void pikaMaker_setPWD(PikaMaker* self, char* pwd);
void pikaMaker_compileModule(PikaMaker* self, char* module_name);
int pikaMaker_getDependencies(PikaMaker* self, char* module_name);
#define LIB_VERSION_NUMBER 1

View File

@ -29,8 +29,8 @@
#define __PIKA_VM__H
#include "PikaObj.h"
#include "dataQueue.h"
#include "dataStack.h"
#include "dataQueueObj.h"
#include "dataStack.h"
enum Instruct {
#define __INS_ENUM
@ -126,6 +126,7 @@ void constPool_printAsArray(ConstPool* self);
void instructArray_printAsArray(InstructArray* self);
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes);
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
void byteCodeFrame_init(ByteCodeFrame* self);
VMParameters* pikaVM_runByteCode(PikaObj* self, uint8_t* bytecode);
#endif