mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
use Maker to build modules
This commit is contained in:
parent
753369e3d9
commit
9d871387dc
4
port/linux/.vscode/c_cpp_properties.json
vendored
4
port/linux/.vscode/c_cpp_properties.json
vendored
@ -11,9 +11,7 @@
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c99",
|
||||
"cppStandard": "c++14",
|
||||
"intelliSenseMode": "linux-clang-x64",
|
||||
"configurationProvider": "ms-vscode.cmake-tools"
|
||||
"cppStandard": "c++14"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
@ -497,6 +497,20 @@ TEST(lib, load_err_file_type) {
|
||||
}
|
||||
|
||||
TEST(lib, lib_file_to_array) {
|
||||
Lib_loadLibraryFileToArray("test/python/lib_to_file.py.a",
|
||||
"test/python");
|
||||
Lib_loadLibraryFileToArray("test/python/lib_to_file.py.a", "test/python");
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(make, maker) {
|
||||
PikaMaker* maker = New_PikaMaker();
|
||||
obj_deinit(maker);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(make, compile) {
|
||||
PikaMaker* maker = New_PikaMaker();
|
||||
pikaMaker_setPWD(maker, "package/pikascript/");
|
||||
pikaMaker_compileModule(maker, "main");
|
||||
obj_deinit(maker);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
@ -353,3 +353,34 @@ exit:
|
||||
arg_deinit(file_arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
static void __Maker_compileModuleWithInfo(PikaMaker* self, char* module_name) {
|
||||
Args buffs = {0};
|
||||
char* input_file_name = strsAppend(&buffs, module_name, ".py");
|
||||
char* input_file_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), input_file_name);
|
||||
__platform_printf(" compiling %s...\r\n", input_file_name);
|
||||
char* output_file_name = strsAppend(&buffs, module_name, ".py.o");
|
||||
char* output_file_path = NULL;
|
||||
output_file_path =
|
||||
strsAppend(&buffs, obj_getStr(self, "pwd"), "pikascript-api/");
|
||||
output_file_path = strsAppend(&buffs, output_file_path, output_file_name);
|
||||
pikaCompileFileWithOutputName(output_file_path, input_file_path);
|
||||
strsDeinit(&buffs);
|
||||
}
|
||||
|
||||
PikaMaker* New_PikaMaker(void) {
|
||||
PikaMaker* self = New_TinyObj(NULL);
|
||||
obj_setStr(self, "pwd", "");
|
||||
return self;
|
||||
}
|
||||
|
||||
void pikaMaker_setPWD(PikaMaker* self, char* pwd) {
|
||||
obj_setStr(self, "pwd", pwd);
|
||||
}
|
||||
|
||||
void pikaMaker_compileModule(PikaMaker* self, char* module_name) {
|
||||
__Maker_compileModuleWithInfo(self, module_name);
|
||||
/* update compile info */
|
||||
obj_setStr(self, module_name, "compiled");
|
||||
}
|
||||
|
@ -20,6 +20,10 @@ void LibObj_listModules(LibObj* self);
|
||||
int LibObj_saveLibraryFile(LibObj* self, char* output_file_name);
|
||||
int LibObj_loadLibraryFile(LibObj* self, char* input_file_name);
|
||||
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);
|
||||
|
||||
|
||||
#define LIB_VERSION_NUMBER 1
|
||||
#define LIB_INFO_BLOCK_SIZE 32
|
||||
|
@ -95,6 +95,7 @@ typedef struct MethodInfo_t {
|
||||
} MethodInfo;
|
||||
|
||||
typedef PikaObj LibObj;
|
||||
typedef PikaObj PikaMaker;
|
||||
|
||||
/* operation */
|
||||
int32_t obj_deinit(PikaObj* self);
|
||||
|
@ -1,22 +1,19 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "BaseObj.h"
|
||||
#include "PikaCompiler.h"
|
||||
#include "PikaObj.h"
|
||||
#include "PikaParser.h"
|
||||
#include "dataStrs.h"
|
||||
#include "PikaCompiler.h"
|
||||
#include "libpikabinder.h"
|
||||
|
||||
PikaObj* __pikaMain;
|
||||
|
||||
void pikaCompileFileWithInfo(char* filename){
|
||||
__platform_printf(" compiling %s...\r\n", filename);
|
||||
pikaCompileFile(filename);
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
/* run pika_binder to bind C modules */
|
||||
pika_binder();
|
||||
pikaCompileFileWithInfo("main.py");
|
||||
return;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ cp target/release/libpikabinder.a libpikabinder
|
||||
|
||||
cd ../pikaByteCodeGen
|
||||
cp ../pikaCompiler/libpikabinder . -r
|
||||
rm pikascript/pikascript-core -r
|
||||
cp ../../src pikascript/pikascript-core -r
|
||||
rm build -rf
|
||||
mkdir build
|
||||
|
Loading…
x
Reference in New Issue
Block a user