mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
support RES on pikaCompiler
This commit is contained in:
parent
287d515bd0
commit
df65e2def9
@ -79,7 +79,7 @@ pika_float PikaStdLib_SysObj_float(PikaObj* self, Arg* arg) {
|
||||
if (ARG_TYPE_FLOAT == type) {
|
||||
return (float)arg_getFloat(arg);
|
||||
}
|
||||
obj_setSysOut(self, "[error] convert to pika_float type faild.");
|
||||
obj_setSysOut(self, "[error] convert to pika_float type failed.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return -99999.99999;
|
||||
}
|
||||
@ -105,7 +105,7 @@ int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg) {
|
||||
uint8_t val = *arg_getBytes(arg);
|
||||
return val;
|
||||
}
|
||||
obj_setSysOut(self, "[error] convert to int type faild.");
|
||||
obj_setSysOut(self, "[error] convert to int type failed.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return -999999999;
|
||||
}
|
||||
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
// "--gtest_filter=parser.multi_import"
|
||||
// "--gtest_filter=pikaMain.synac_err_1"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -79,7 +79,7 @@ pika_float PikaStdLib_SysObj_float(PikaObj* self, Arg* arg) {
|
||||
if (ARG_TYPE_FLOAT == type) {
|
||||
return (float)arg_getFloat(arg);
|
||||
}
|
||||
obj_setSysOut(self, "[error] convert to pika_float type faild.");
|
||||
obj_setSysOut(self, "[error] convert to pika_float type failed.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return -99999.99999;
|
||||
}
|
||||
@ -105,7 +105,7 @@ int PikaStdLib_SysObj_int(PikaObj* self, Arg* arg) {
|
||||
uint8_t val = *arg_getBytes(arg);
|
||||
return val;
|
||||
}
|
||||
obj_setSysOut(self, "[error] convert to int type faild.");
|
||||
obj_setSysOut(self, "[error] convert to int type failed.");
|
||||
obj_setErrorCode(self, 1);
|
||||
return -999999999;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ PikaObj* pika_cjson_Parse(PikaObj* self, char* value) {
|
||||
cJSON* item = cJSON_Parse(value);
|
||||
if (NULL == item) {
|
||||
obj_setErrorCode(self, 3);
|
||||
__platform_printf("Error: cJSON parse faild.\r\n");
|
||||
__platform_printf("Error: cJSON parse failed.\r\n");
|
||||
return NULL;
|
||||
}
|
||||
PikaObj* cjson_obj = newNormalObj(New_pika_cjson_cJSON);
|
||||
|
@ -20,7 +20,7 @@ void pika_lua_eval(PikaObj* self, char* cmd) {
|
||||
int res = luaL_dostring(pika_L, cmd);
|
||||
if (LUA_OK != res) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
obj_setSysOut(self, "Error: Lua dostring faild.\r\n");
|
||||
obj_setSysOut(self, "Error: Lua dostring failed.\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,10 +61,16 @@ static void __handler_instructArray_output_file(InstructArray* self,
|
||||
__platform_fclose()
|
||||
*/
|
||||
|
||||
int pikaCompile(char* output_file_name, char* py_lines) {
|
||||
PIKA_RES pikaCompile(char* output_file_name, char* py_lines) {
|
||||
PIKA_RES res = PIKA_RES_OK;
|
||||
ByteCodeFrame bytecode_frame = {0};
|
||||
|
||||
FILE* bytecode_f = __platform_fopen(output_file_name, "wb+");
|
||||
if (NULL == bytecode_f) {
|
||||
__platform_printf("Error: open file %s failed.\r\n", output_file_name);
|
||||
res = PIKA_RES_ERR_IO_ERROR;
|
||||
goto exit;
|
||||
}
|
||||
/* main process */
|
||||
|
||||
/* step 1, get size of const pool and instruct array */
|
||||
@ -73,7 +79,11 @@ int pikaCompile(char* output_file_name, char* py_lines) {
|
||||
bytecode_frame.instruct_array.output_f = bytecode_f;
|
||||
bytecode_frame.instruct_array.output_redirect_fun =
|
||||
__handler_instructArray_output_none;
|
||||
Parser_linesToBytes(&bytecode_frame, py_lines);
|
||||
res = Parser_linesToBytes(&bytecode_frame, py_lines);
|
||||
if (PIKA_RES_OK != res) {
|
||||
__platform_printf(" Error: Syntax error.\r\n");
|
||||
goto exit;
|
||||
}
|
||||
uint32_t const_pool_size = bytecode_frame.const_pool.size;
|
||||
uint32_t instruct_array_size = bytecode_frame.instruct_array.size;
|
||||
byteCodeFrame_deinit(&bytecode_frame);
|
||||
@ -105,12 +115,15 @@ int pikaCompile(char* output_file_name, char* py_lines) {
|
||||
bytecode_frame.instruct_array.output_redirect_fun =
|
||||
__handler_instructArray_output_none;
|
||||
Parser_linesToBytes(&bytecode_frame, py_lines);
|
||||
byteCodeFrame_deinit(&bytecode_frame);
|
||||
|
||||
/* deinit */
|
||||
__platform_fclose(bytecode_f);
|
||||
exit:
|
||||
byteCodeFrame_deinit(&bytecode_frame);
|
||||
if (NULL != bytecode_f) {
|
||||
__platform_fclose(bytecode_f);
|
||||
}
|
||||
/* succeed */
|
||||
return 0;
|
||||
return res;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -120,12 +133,12 @@ int pikaCompile(char* output_file_name, char* py_lines) {
|
||||
__platform_fwrite()
|
||||
__platform_fclose()
|
||||
*/
|
||||
int pikaCompileFileWithOutputName(char* output_file_name,
|
||||
char* input_file_name) {
|
||||
PIKA_RES pikaCompileFileWithOutputName(char* output_file_name,
|
||||
char* input_file_name) {
|
||||
Args buffs = {0};
|
||||
Arg* input_file_arg = arg_loadFile(NULL, input_file_name);
|
||||
if (NULL == input_file_arg) {
|
||||
return 1;
|
||||
return PIKA_RES_ERR_IO_ERROR;
|
||||
}
|
||||
char* lines = (char*)arg_getBytes(input_file_arg);
|
||||
/* replace the "\r\n" to "\n" */
|
||||
@ -134,19 +147,20 @@ int pikaCompileFileWithOutputName(char* output_file_name,
|
||||
lines = strsReplace(&buffs, lines, "\n\n", "\n");
|
||||
/* add '\n' at the end */
|
||||
lines = strsAppend(&buffs, lines, "\n\n");
|
||||
pikaCompile(output_file_name, lines);
|
||||
PIKA_RES res = pikaCompile(output_file_name, lines);
|
||||
arg_deinit(input_file_arg);
|
||||
strsDeinit(&buffs);
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
int pikaCompileFile(char* input_file_name) {
|
||||
PIKA_RES pikaCompileFile(char* input_file_name) {
|
||||
Args buffs = {0};
|
||||
char* output_file_name = strsGetFirstToken(&buffs, input_file_name, '.');
|
||||
output_file_name = strsAppend(&buffs, input_file_name, ".o");
|
||||
pikaCompileFileWithOutputName(output_file_name, input_file_name);
|
||||
PIKA_RES res =
|
||||
pikaCompileFileWithOutputName(output_file_name, input_file_name);
|
||||
strsDeinit(&buffs);
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
LibObj* New_LibObj(Args* args) {
|
||||
@ -400,7 +414,8 @@ exit:
|
||||
return res;
|
||||
}
|
||||
|
||||
static void __Maker_compileModuleWithInfo(PikaMaker* self, char* module_name) {
|
||||
static PIKA_RES __Maker_compileModuleWithInfo(PikaMaker* self,
|
||||
char* module_name) {
|
||||
Args buffs = {0};
|
||||
char* input_file_name = strsAppend(&buffs, module_name, ".py");
|
||||
char* input_file_path =
|
||||
@ -411,13 +426,16 @@ static void __Maker_compileModuleWithInfo(PikaMaker* self, char* module_name) {
|
||||
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);
|
||||
PIKA_RES res =
|
||||
pikaCompileFileWithOutputName(output_file_path, input_file_path);
|
||||
strsDeinit(&buffs);
|
||||
return res;
|
||||
}
|
||||
|
||||
PikaMaker* New_PikaMaker(void) {
|
||||
PikaMaker* self = New_TinyObj(NULL);
|
||||
obj_setStr(self, "pwd", "");
|
||||
obj_setInt(self, "err", 0);
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -432,10 +450,15 @@ void pikaMaker_setState(PikaMaker* self, char* module_name, char* state) {
|
||||
obj_setStr(module_obj, "state", state);
|
||||
}
|
||||
|
||||
void pikaMaker_compileModule(PikaMaker* self, char* module_name) {
|
||||
__Maker_compileModuleWithInfo(self, module_name);
|
||||
PIKA_RES pikaMaker_compileModule(PikaMaker* self, char* module_name) {
|
||||
PIKA_RES res = __Maker_compileModuleWithInfo(self, module_name);
|
||||
/* update compile info */
|
||||
pikaMaker_setState(self, module_name, "compiled");
|
||||
if (PIKA_RES_OK == res) {
|
||||
pikaMaker_setState(self, module_name, "compiled");
|
||||
} else {
|
||||
pikaMaker_setState(self, module_name, "failed");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int pikaMaker_getDependencies(PikaMaker* self, char* module_name) {
|
||||
@ -589,8 +612,14 @@ char* pikaMaker_getFirstNocompiled(PikaMaker* self) {
|
||||
return obj_getStr(self, "res");
|
||||
}
|
||||
|
||||
void pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name) {
|
||||
pikaMaker_compileModule(self, module_name);
|
||||
PIKA_RES pikaMaker_compileModuleWithDepends(PikaMaker* self,
|
||||
char* module_name) {
|
||||
PIKA_RES res = PIKA_RES_OK;
|
||||
res = pikaMaker_compileModule(self, module_name);
|
||||
if (PIKA_RES_OK != res) {
|
||||
obj_setInt(self, "err", res);
|
||||
return res;
|
||||
}
|
||||
pikaMaker_getDependencies(self, module_name);
|
||||
while (1) {
|
||||
char* uncompiled = pikaMaker_getFirstNocompiled(self);
|
||||
@ -598,9 +627,14 @@ void pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name) {
|
||||
if (NULL == uncompiled) {
|
||||
break;
|
||||
}
|
||||
pikaMaker_compileModule(self, uncompiled);
|
||||
res = pikaMaker_compileModule(self, uncompiled);
|
||||
if (PIKA_RES_OK != res) {
|
||||
obj_setInt(self, "err", res);
|
||||
return res;
|
||||
}
|
||||
pikaMaker_getDependencies(self, uncompiled);
|
||||
}
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
||||
int32_t __foreach_handler_linkCompiledModules(Arg* argEach, Args* context) {
|
||||
@ -624,7 +658,13 @@ int32_t __foreach_handler_linkCompiledModules(Arg* argEach, Args* context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path) {
|
||||
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self,
|
||||
char* lib_path) {
|
||||
PIKA_RES compile_err = obj_getInt(self, "err");
|
||||
if (PIKA_RES_OK != compile_err) {
|
||||
__platform_printf(" Error: compile failed, link aborted.\r\n");
|
||||
return compile_err;
|
||||
}
|
||||
Args context = {0};
|
||||
LibObj* lib = New_LibObj(NULL);
|
||||
Args buffs = {0};
|
||||
@ -643,11 +683,13 @@ void pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path) {
|
||||
Lib_loadLibraryFileToArray(lib_file_path, folder_path);
|
||||
LibObj_deinit(lib);
|
||||
strsDeinit(&buffs);
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
|
||||
void pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name) {
|
||||
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name) {
|
||||
Args buffs = {0};
|
||||
char* lib_file_path = strsAppend(&buffs, "pikascript-api/", lib_name);
|
||||
pikaMaker_linkCompiledModulesFullPath(self, lib_file_path);
|
||||
PIKA_RES res = pikaMaker_linkCompiledModulesFullPath(self, lib_file_path);
|
||||
strsDeinit(&buffs);
|
||||
return res;
|
||||
}
|
||||
|
@ -3,10 +3,10 @@
|
||||
#include "PikaObj.h"
|
||||
#include "stdint.h"
|
||||
|
||||
int pikaCompileFile(char* input_file_name);
|
||||
int pikaCompileFileWithOutputName(char* output_file_name,
|
||||
char* input_file_name);
|
||||
int pikaCompile(char* output_file_name, char* py_lines);
|
||||
PIKA_RES pikaCompileFile(char* input_file_name);
|
||||
PIKA_RES pikaCompileFileWithOutputName(char* output_file_name,
|
||||
char* input_file_name);
|
||||
PIKA_RES pikaCompile(char* output_file_name, char* py_lines);
|
||||
|
||||
LibObj* New_LibObj(Args* args);
|
||||
void LibObj_deinit(LibObj* self);
|
||||
@ -22,14 +22,14 @@ 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);
|
||||
PIKA_RES pikaMaker_compileModule(PikaMaker* self, char* module_name);
|
||||
int pikaMaker_getDependencies(PikaMaker* self, char* module_name);
|
||||
void pikaMaker_printStates(PikaMaker* self);
|
||||
char* pikaMaker_getFirstNocompiled(PikaMaker* self);
|
||||
void pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name);
|
||||
void pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
|
||||
PIKA_RES pikaMaker_compileModuleWithDepends(PikaMaker* self, char* module_name);
|
||||
PIKA_RES pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path);
|
||||
PIKA_RES pikaMaker_linkCompiledModules(PikaMaker* self, char* lib_name);
|
||||
int LibObj_loadLibrary(LibObj* self, uint8_t* library_bytes);
|
||||
void pikaMaker_linkCompiledModulesFullPath(PikaMaker* self, char* lib_path);
|
||||
|
||||
#define LIB_VERSION_NUMBER 2
|
||||
#define LIB_INFO_BLOCK_SIZE 32
|
||||
|
@ -270,7 +270,6 @@ void _temp_obj_shellLineProcess(PikaObj* self, ShellConfig* cfg);
|
||||
__platform_fwrite()
|
||||
__platform_fclose()
|
||||
*/
|
||||
int pikaCompile(char* output_file_name, char* py_lines);
|
||||
Method obj_getNativeMethod(PikaObj* self, char* method_name);
|
||||
PIKA_RES obj_runNativeMethod(PikaObj* self, char* method_name, Args* args);
|
||||
Arg* obj_newObjInPackage(NewFun newObjFun);
|
||||
|
@ -2506,18 +2506,12 @@ exit:
|
||||
return out_ASM;
|
||||
};
|
||||
|
||||
char* Parser_linesToBytes(ByteCodeFrame* bf, char* py_lines) {
|
||||
return _Parser_linesToBytesOrAsm(NULL, bf, py_lines);
|
||||
}
|
||||
|
||||
int bytecodeFrame_fromLines(ByteCodeFrame* bytecode_frame, char* multi_line) {
|
||||
if (NULL == Parser_linesToBytes(bytecode_frame, multi_line)) {
|
||||
/* error */
|
||||
return 1;
|
||||
PIKA_RES Parser_linesToBytes(ByteCodeFrame* bf, char* py_lines) {
|
||||
if (1 == (uintptr_t)_Parser_linesToBytesOrAsm(NULL, bf, py_lines)) {
|
||||
return PIKA_RES_OK;
|
||||
}
|
||||
/* succeed */
|
||||
return 0;
|
||||
};
|
||||
return PIKA_RES_ERR_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
char* Parser_linesToAsm(Args* outBuffs, char* multi_line) {
|
||||
return _Parser_linesToBytesOrAsm(outBuffs, NULL, multi_line);
|
||||
@ -3024,7 +3018,7 @@ ByteCodeFrame* byteCodeFrame_appendFromAsm(ByteCodeFrame* self, char* pikaAsm) {
|
||||
char* Parser_linesToArray(char* lines) {
|
||||
ByteCodeFrame bytecode_frame;
|
||||
byteCodeFrame_init(&bytecode_frame);
|
||||
bytecodeFrame_fromLines(&bytecode_frame, lines);
|
||||
Parser_linesToBytes(&bytecode_frame, lines);
|
||||
/* do something */
|
||||
byteCodeFrame_print(&bytecode_frame);
|
||||
|
||||
|
@ -100,12 +100,11 @@ struct Cursor {
|
||||
|
||||
char* Parser_fileToAsm(Args* outBuffs, char* filename);
|
||||
char* Parser_linesToAsm(Args* outBuffs, char* multiLine);
|
||||
char* Parser_linesToBytes(ByteCodeFrame* bf, char* py_lines);
|
||||
PIKA_RES Parser_linesToBytes(ByteCodeFrame* bf, char* py_lines);
|
||||
char* Parser_linesToArray(char* lines);
|
||||
|
||||
char* instructUnit_fromAsmLine(Args* outBuffs, char* pikaAsm);
|
||||
ByteCodeFrame* byteCodeFrame_appendFromAsm(ByteCodeFrame* bf, char* pikaAsm);
|
||||
int bytecodeFrame_fromLines(ByteCodeFrame* bytecode_frame, char* python_lines);
|
||||
|
||||
#define Cursor_forEach(cursor) \
|
||||
_Cursor_beforeIter(&cursor); \
|
||||
|
@ -1255,7 +1255,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
||||
arg_num_used += VMState_loadArgsFromMethodArg(
|
||||
vm, obj_this, sub_locals->list, method, run_path, arg_num_used);
|
||||
|
||||
/* load args faild */
|
||||
/* load args failed */
|
||||
if (vm->error_code != 0) {
|
||||
goto exit;
|
||||
}
|
||||
@ -1290,7 +1290,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self,
|
||||
}
|
||||
VMState_loadArgsFromMethodArg(vm, new_obj, sub_locals->list, method_arg,
|
||||
"__init__", arg_num_used);
|
||||
/* load args faild */
|
||||
/* load args failed */
|
||||
if (vm->error_code != 0) {
|
||||
goto init_exit;
|
||||
}
|
||||
@ -2211,7 +2211,7 @@ static Arg* VM_instruction_handler_ASS(PikaObj* self,
|
||||
arg2 = stack_popArg(&vm->stack, ®2);
|
||||
arg1 = stack_popArg(&vm->stack, ®1);
|
||||
}
|
||||
/* assert faild */
|
||||
/* assert failed */
|
||||
if (arg_getType(arg1) == ARG_TYPE_INT && arg_getInt(arg1) == 0) {
|
||||
stack_pushArg(&vm->stack, arg_newInt(PIKA_RES_ERR_ASSERT));
|
||||
res = VM_instruction_handler_RIS(self, vm, data, arg_ret_reg);
|
||||
@ -2506,7 +2506,7 @@ static VMParameters* __pikaVM_runPyLines_or_byteCode(PikaObj* self,
|
||||
if (is_run_py) {
|
||||
/* generate byte code */
|
||||
byteCodeFrame_init(bytecode_frame_p);
|
||||
if (1 == bytecodeFrame_fromLines(bytecode_frame_p, py_lines)) {
|
||||
if (PIKA_RES_OK != Parser_linesToBytes(bytecode_frame_p, py_lines)) {
|
||||
__platform_printf("Error: Syntax error.\r\n");
|
||||
globals = NULL;
|
||||
goto exit;
|
||||
|
@ -2,4 +2,4 @@
|
||||
#define PIKA_VERSION_MINOR 11
|
||||
#define PIKA_VERSION_MICRO 5
|
||||
|
||||
#define PIKA_EDIT_TIME "2022/10/23 18:55:43"
|
||||
#define PIKA_EDIT_TIME "2022/10/24 10:14:10"
|
||||
|
@ -234,7 +234,7 @@ PIKA_RES args_setStructWithSize(Args* self,
|
||||
uint32_t struct_size) {
|
||||
Arg* struct_arg = arg_setStruct(NULL, name, struct_ptr, struct_size);
|
||||
if (NULL == struct_arg) {
|
||||
/* faild */
|
||||
/* failed */
|
||||
return PIKA_RES_ERR_ARG_NO_FOUND;
|
||||
}
|
||||
args_setArg(self, struct_arg);
|
||||
@ -262,7 +262,7 @@ PIKA_RES args_setHeapStructWithSize(Args* self,
|
||||
Arg* struct_arg = arg_setHeapStruct(NULL, name, struct_ptr, struct_size,
|
||||
struct_deinit_fun);
|
||||
if (NULL == struct_arg) {
|
||||
/* faild */
|
||||
/* failed */
|
||||
return PIKA_RES_ERR_ARG_NO_FOUND;
|
||||
}
|
||||
args_setArg(self, struct_arg);
|
||||
|
@ -59,7 +59,7 @@ char* strCut(char* strOut, char* strIn, char startSign, char endSign) {
|
||||
/* succeed */
|
||||
return strOut;
|
||||
}
|
||||
/* faild */
|
||||
/* failed */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -377,7 +377,7 @@ TEST(cJSON, test6) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(cJSON, parse_faild) {
|
||||
TEST(cJSON, parse_failed) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* pikaMain = newRootObj("pikaMain", New_PikaMain);
|
||||
|
@ -256,7 +256,7 @@ TEST(compiler, import_bf_mem) {
|
||||
"\n";
|
||||
ByteCodeFrame bf;
|
||||
byteCodeFrame_init(&bf);
|
||||
bytecodeFrame_fromLines(&bf, lines);
|
||||
Parser_linesToBytes(&bf, lines);
|
||||
obj_importModuleWithByteCodeFrame(pikaMain, "mtest", &bf);
|
||||
byteCodeFrame_deinit(&bf);
|
||||
obj_deinit(pikaMain);
|
||||
@ -271,7 +271,7 @@ TEST(compiler, import_bf1) {
|
||||
"\n";
|
||||
ByteCodeFrame bf;
|
||||
byteCodeFrame_init(&bf);
|
||||
bytecodeFrame_fromLines(&bf, lines);
|
||||
Parser_linesToBytes(&bf, lines);
|
||||
obj_importModuleWithByteCodeFrame(pikaMain, "mtest", &bf);
|
||||
obj_run(pikaMain,
|
||||
"mtest.mytest()\n"
|
||||
@ -291,7 +291,7 @@ TEST(compiler, import_bf2) {
|
||||
"\n";
|
||||
ByteCodeFrame bf;
|
||||
byteCodeFrame_init(&bf);
|
||||
bytecodeFrame_fromLines(&bf, lines);
|
||||
Parser_linesToBytes(&bf, lines);
|
||||
obj_importModuleWithByteCodeFrame(pikaMain, "mtest", &bf);
|
||||
obj_run(pikaMain,
|
||||
"m = mtest.Test()\n"
|
||||
|
@ -35,12 +35,13 @@ TEST(except, trycmodule1) {
|
||||
"import pika_cjson\n"
|
||||
"try:\n"
|
||||
" b = pika_cjson.Parse('')\n"
|
||||
" print('after faild')\n"
|
||||
" print('after failed')\n"
|
||||
"except:\n"
|
||||
" print('parse faild')\n"
|
||||
" print('parse failed')\n"
|
||||
"\n");
|
||||
/* collect */
|
||||
EXPECT_STREQ("BEGIN\r\n", log_buff[2]);
|
||||
EXPECT_STREQ("parse failed\r\n", log_buff[0]);
|
||||
/* assert */
|
||||
/* deinit */
|
||||
obj_deinit(pikaMain);
|
||||
|
@ -1091,7 +1091,7 @@ TEST(pikaMain, complex_str) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, synac_err_1) {
|
||||
TEST(pikaMain, syntax_err_1) {
|
||||
/* init */
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
/* run */
|
||||
|
@ -8,6 +8,25 @@
|
||||
#include "dataStrs.h"
|
||||
#include "libpikabinder.h"
|
||||
|
||||
void help(char* argv0) {
|
||||
Args buffs = {0};
|
||||
char* exe = argv0;
|
||||
printf(
|
||||
"Usage:\r\n"
|
||||
" %s"
|
||||
" - [Binding C modules and compile all from main.py]\r\n"
|
||||
" %s test.py"
|
||||
" - [Compile all from test.py]\r\n"
|
||||
" %s test.py -o out.a"
|
||||
" - [Compile all from test.py and link to out.a]\r\n"
|
||||
" %s -c test.py"
|
||||
" - [Only compile test.py to test.py.o]\r\n"
|
||||
" %s -c test.py -o out.o"
|
||||
" - [Only compile test.py to out.o]\r\n",
|
||||
exe, exe, exe, exe, exe);
|
||||
strsDeinit(&buffs);
|
||||
}
|
||||
|
||||
/* fake implement */
|
||||
PikaObj* __pikaMain;
|
||||
void New_PikaStdLib_SysObj(void) {}
|
||||
@ -20,7 +39,6 @@ char* string_slice(Args* outBuffs, char* str, int start, int end) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void help(char* argv0);
|
||||
int main(int argc, char** argv) {
|
||||
int parc = argc - 1;
|
||||
if (0 == parc) {
|
||||
@ -29,9 +47,9 @@ int main(int argc, char** argv) {
|
||||
pika_binder();
|
||||
PikaMaker* maker = New_PikaMaker();
|
||||
pikaMaker_compileModuleWithDepends(maker, "main");
|
||||
pikaMaker_linkCompiledModules(maker, "pikaModules.py.a");
|
||||
PIKA_RES res = pikaMaker_linkCompiledModules(maker, "pikaModules.py.a");
|
||||
obj_deinit(maker);
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* example: ./rust-msc-latest-linux -h | --help */
|
||||
@ -52,9 +70,9 @@ int main(int argc, char** argv) {
|
||||
*subfix = '\0';
|
||||
}
|
||||
pikaMaker_compileModuleWithDepends(maker, module_entry);
|
||||
pikaMaker_linkCompiledModules(maker, "pikaModules.py.a");
|
||||
PIKA_RES res = pikaMaker_linkCompiledModules(maker, "pikaModules.py.a");
|
||||
obj_deinit(maker);
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
/* example ./rust-msc-latest-linux main.py -o out.a */
|
||||
@ -68,9 +86,9 @@ int main(int argc, char** argv) {
|
||||
*subfix = '\0';
|
||||
}
|
||||
pikaMaker_compileModuleWithDepends(maker, module_entry);
|
||||
pikaMaker_linkCompiledModules(maker, argv[3]);
|
||||
PIKA_RES res = pikaMaker_linkCompiledModules(maker, argv[3]);
|
||||
obj_deinit(maker);
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,9 +106,10 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
module_out = strsAppend(&buffs, module_out, ".py.o");
|
||||
printf("compiling %s to %s...\r\n", module_entry, module_out);
|
||||
pikaCompileFileWithOutputName(module_out, module_entry);
|
||||
PIKA_RES res =
|
||||
pikaCompileFileWithOutputName(module_out, module_entry);
|
||||
strsDeinit(&buffs);
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,33 +119,14 @@ int main(int argc, char** argv) {
|
||||
/* compile only */
|
||||
char* module_entry = argv[2];
|
||||
printf("compiling %s to %s...\r\n", module_entry, argv[4]);
|
||||
pikaCompileFileWithOutputName(argv[4], module_entry);
|
||||
return 0;
|
||||
PIKA_RES res = pikaCompileFileWithOutputName(argv[4], module_entry);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/* no valid input */
|
||||
printf("invalid input\r\n");
|
||||
printf("Invalid input.\r\n");
|
||||
help(argv[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void help(char* argv0) {
|
||||
Args buffs = {0};
|
||||
char* exe = argv0;
|
||||
printf(
|
||||
"Usage:\r\n"
|
||||
" %s"
|
||||
" - [Binding C modules and compile all from main.py]\r\n"
|
||||
" %s test.py"
|
||||
" - [Compile all from test.py]\r\n"
|
||||
" %s test.py -o out.a"
|
||||
" - [Compile all from test.py and link to out.a]\r\n"
|
||||
" %s -c test.py"
|
||||
" - [Only compile test.py to test.py.o]\r\n"
|
||||
" %s -c test.py -o out.o"
|
||||
" - [Only compile test.py to out.o]\r\n",
|
||||
exe, exe, exe, exe, exe);
|
||||
strsDeinit(&buffs);
|
||||
return -1;
|
||||
}
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user