Explorar o código

feat: 调整clib的导入函数

SongZihuan %!s(int64=4) %!d(string=hai) anos
pai
achega
86f31ff98c

+ 6 - 6
CMakeLists.txt

@@ -25,8 +25,8 @@ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})
 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH})
 
 SET(HELLOVM_INCLUDE_DICT
-        ${CMAKE_CURRENT_SOURCE_DIR}/include
-        ${CMAKE_CURRENT_SOURCE_DIR}/vmcore/include
+        ${VirtualMath_SOURCE_DIR}/include
+        ${VirtualMath_SOURCE_DIR}/vmcore/include
         )
 
 IF (GC)
@@ -39,16 +39,16 @@ ADD_DEFINITIONS(-DCC=\"${CMAKE_C_COMPILER}\")
 ADD_DEFINITIONS(-DSYS=\"${CMAKE_SYSTEM}.${CMAKE_SYSTEM_PROCESSOR}\")
 INCLUDE_DIRECTORIES(${HELLOVM_INCLUDE_DICT} BEFORE)
 
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_LIST)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/argument SRC_LIST)
+AUX_SOURCE_DIRECTORY(${VirtualMath_SOURCE_DIR}/src SRC_LIST)
+AUX_SOURCE_DIRECTORY(${VirtualMath_SOURCE_DIR}/argument SRC_LIST)
 
 MESSAGE(STATUS "hellovm src = ${SRC_LIST}")
-MESSAGE(STATUS "project dir is ${PROJECT_SOURCE_DIR}")
+MESSAGE(STATUS "project dir is ${VirtualMath_SOURCE_DIR}")
 MESSAGE(STATUS "cmake file in is ${CMAKE_CURRENT_SOURCE_DIR}")
 MESSAGE(STATUS "vmcore on ${vmcore_BINARY_DIR}")
 
 LINK_DIRECTORIES(${vmcore_BINARY_DIR})  # 添加vmcore的构建目录为寻找lib的目录
-ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/vmcore)
+ADD_SUBDIRECTORY(${VirtualMath_SOURCE_DIR}/vmcore)
 
 IF (PG)
     ADD_COMPILE_OPTIONS(-pg)

+ 16 - 15
vmcore/CMakeLists.txt

@@ -3,23 +3,24 @@ PROJECT(vmcore C)
 SET(CMAKE_C_STANDARD 11)
 
 SET(VMCORE_INCLUDE_DICT
-        ${CMAKE_CURRENT_SOURCE_DIR}/include
-        ${CMAKE_CURRENT_SOURCE_DIR}/parser/include
-        ${CMAKE_CURRENT_SOURCE_DIR}/src/include
-        ${CMAKE_CURRENT_SOURCE_DIR}/ofunc/include
-        ${CMAKE_CURRENT_SOURCE_DIR}/md5/include
+        ${vmcore_SOURCE_DIR}/include
+        ${vmcore_SOURCE_DIR}/parser/include
+        ${vmcore_SOURCE_DIR}/src/include
+        ${vmcore_SOURCE_DIR}/ofunc/include
+        ${vmcore_SOURCE_DIR}/md5/include
+        ${vmcore_SOURCE_DIR}/ofunc/clib/include
         )
 
 SET(VMCORE_SRC_DIR
-        ${CMAKE_CURRENT_SOURCE_DIR}/memory
-        ${CMAKE_CURRENT_SOURCE_DIR}/src
-        ${CMAKE_CURRENT_SOURCE_DIR}/gc
-        ${CMAKE_CURRENT_SOURCE_DIR}/file
-        ${CMAKE_CURRENT_SOURCE_DIR}/parser
-        ${CMAKE_CURRENT_SOURCE_DIR}/ofunc/src
-        ${CMAKE_CURRENT_SOURCE_DIR}/ofunc/clib
-        ${CMAKE_CURRENT_SOURCE_DIR}/signalhandler
-        ${CMAKE_CURRENT_SOURCE_DIR}/md5
+        ${vmcore_SOURCE_DIR}/memory
+        ${vmcore_SOURCE_DIR}/src
+        ${vmcore_SOURCE_DIR}/gc
+        ${vmcore_SOURCE_DIR}/file
+        ${vmcore_SOURCE_DIR}/parser
+        ${vmcore_SOURCE_DIR}/ofunc/src
+        ${vmcore_SOURCE_DIR}/ofunc/clib
+        ${vmcore_SOURCE_DIR}/signalhandler
+        ${vmcore_SOURCE_DIR}/md5
         )
 
 # 添加头文件
@@ -63,7 +64,7 @@ ENDIF()
 TARGET_LINK_LIBRARIES(vmcore ${libffi} ${libdl} m)
 TARGET_INCLUDE_DIRECTORIES(vmcore PRIVATE VMCORE_INCLUDE_DICT)
 SET_TARGET_PROPERTIES(vmcore PROPERTIES
-        PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/virtualmath.h  # 设置public的头文件
+        PUBLIC_HEADER ${vmcore_SOURCE_DIR}/include/virtualmath.h  # 设置public的头文件
         OUTPUT_NAME "vmcore"  # 设置输出名
         VERSION 2.1  # 设置版本号
         )

+ 6 - 0
vmcore/ofunc/clib/lib.h

@@ -0,0 +1,6 @@
+#ifndef VIRTUALMATH_LIB_H
+#define VIRTUALMATH_LIB_H
+#include "__ofunc.h"
+void registeredSysLib(R_FUNC);
+
+#endif //VIRTUALMATH_LIB_H

+ 2 - 2
vmcore/ofunc/clib/manager.c

@@ -1,10 +1,10 @@
 #include "__virtualmath.h"
-#include "clib.h"
+#include "lib.h"
 
 static struct InFo{
     char *name;
     Registered reg;
-} ManagerInFo[] = {{"sys", registeredSysFunction},
+} ManagerInFo[] = {{"sys", registeredSysLib},
                    {NULL, NULL}};
 
 bool checkCLib(char *file) {

+ 235 - 0
vmcore/ofunc/clib/sys_lib.c

@@ -0,0 +1,235 @@
+#include "lib.h"
+
+static ResultType vm_setNowRunCore(O_FUNC, bool type){
+    LinkValue *function_value = NULL;
+    ArgumentParser ap[] = {{.type=name_value, .name=L"func", .must=1, .long_arg=false},
+                           {.must=-1}};
+    setResultCore(result);
+    {
+        parserArgumentUnion(ap, arg, CNEXT_NT);
+        if (!CHECK_RESULT(result))
+            return result->type;
+        freeResult(result);
+    }
+    function_value = ap[0].value;
+    function_value->value->data.function.function_data.run = type;
+    result->value = function_value;
+    gc_addTmpLink(&result->value->gc_status);
+    result->type = R_opt;
+    return R_opt;
+}
+
+static ResultType vm_isnowrun(O_FUNC){
+    return vm_setNowRunCore(CO_FUNC(arg, var_list, result, belong), true);
+}
+
+static ResultType vm_disnowrun(O_FUNC){
+    return vm_setNowRunCore(CO_FUNC(arg, var_list, result, belong), false);
+}
+
+static ResultType vm_quit(O_FUNC){
+    if (arg != NULL)
+        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
+    else
+        setResultError(E_QuitException, L"vmcore quit()", LINEFILE, true, CNEXT_NT);
+    return R_error;
+}
+
+static ResultType vm_setAssert(O_FUNC, enum AssertRunType type){
+    setResultCore(result);
+    if (arg != NULL) {
+        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
+        return R_error;
+    }
+
+    inter->data.assert_run = type;
+    setResult(result, inter);
+    return result->type;
+}
+
+static ResultType vm_assertignore(O_FUNC){
+    return vm_setAssert(CO_FUNC(arg, var_list, result, belong), assert_ignore);
+}
+
+static ResultType vm_assertrun(O_FUNC){
+    return vm_setAssert(CO_FUNC(arg, var_list, result, belong), assert_run);
+}
+
+static ResultType vm_assertraise(O_FUNC){
+    return vm_setAssert(CO_FUNC(arg, var_list, result, belong), assert_raise);
+}
+
+static ResultType vm_selfunCore(O_FUNC, bool type){
+    LinkValue *function_value = NULL;
+    ArgumentParser ap[] = {{.type=name_value, .name=L"func", .must=1, .long_arg=false},
+                           {.must=-1}};
+    bool push;
+    setResultCore(result);
+    {
+        parserArgumentUnion(ap, arg, CNEXT_NT);
+        if (!CHECK_RESULT(result))
+            return result->type;
+        freeResult(result);
+    }
+    function_value = ap[0].value;
+    push = function_value->value->data.function.function_data.push;
+    if (push && !type) {  // 原本是push, 现在设定为非push
+        function_value->value->data.function.function_data.push = false;
+        if (function_value->value->object.out_var != NULL)
+            function_value->value->object.out_var = pushVarList(function_value->value->object.out_var, inter);
+    } else if (!push && type) {
+        if (function_value->value->object.out_var != NULL)
+            function_value->value->object.out_var = popVarList(function_value->value->object.out_var);
+    }
+
+    result->value = function_value;
+    gc_addTmpLink(&result->value->gc_status);
+    result->type = R_opt;
+    return R_opt;
+}
+
+static ResultType vm_selfun(O_FUNC){
+    return vm_selfunCore(CO_FUNC(arg, var_list, result, belong), false);
+}
+
+static ResultType vm_nselfun(O_FUNC){
+    return vm_selfunCore(CO_FUNC(arg, var_list, result, belong), true);
+}
+
+static ResultType vm_setfreemode(O_FUNC, bool type){
+    setResultCore(result);
+    if (arg != NULL) {
+        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
+        return R_error;
+    }
+
+    inter->data.free_mode = type;
+    setResult(result, inter);
+    return result->type;
+}
+
+static ResultType vm_freemode(O_FUNC){
+    return vm_setfreemode(CO_FUNC(arg, var_list, result, belong), true);
+}
+
+static ResultType vm_nfreemode(O_FUNC){
+    return vm_setfreemode(CO_FUNC(arg, var_list, result, belong), false);
+}
+
+static ResultType vm_opt_mode(O_FUNC, enum OptMode mode){
+    setResultCore(result);
+    if (arg != NULL) {
+        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
+        return R_error;
+    }
+
+    inter->data.opt_mode = mode;
+    setResult(result, inter);
+    return result->type;
+}
+
+static ResultType vm_free_opt(O_FUNC){
+    return vm_opt_mode(CO_FUNC(arg, var_list, result, belong), om_free);
+}
+
+static ResultType vm_normal_opt(O_FUNC){
+    return vm_opt_mode(CO_FUNC(arg, var_list, result, belong), om_normal);
+}
+
+static ResultType vm_simple_opt(O_FUNC){
+    return vm_opt_mode(CO_FUNC(arg, var_list, result, belong), om_simple);
+}
+
+static ResultType vm_exec(O_FUNC){
+    ArgumentParser ap[] = {{.type=name_value, .name=L"cm", .must=1, .long_arg=false},
+                           {.type=name_value, .name=L"var", .must=0, .long_arg=false},
+                           {.type=name_value, .name=L"out", .must=0, .long_arg=false},
+                           {.must=-1}};
+    LinkValue *str;
+    LinkValue *var;
+    LinkValue *out;
+    Statement *new_st;
+    VarList *run;
+
+    setResultCore(result);
+    parserArgumentUnion(ap, arg, CNEXT_NT);
+    if (!CHECK_RESULT(result))
+        return result->type;
+    freeResult(result);
+
+    str = ap[0].value;
+    var = ap[1].value;
+    out = ap[2].value;
+    if (str->value->type != V_str) {
+        setResultError(E_TypeException, ONLY_ACC(cm, str), LINEFILE, true, CNEXT_NT);
+        return result->type;
+    }
+
+    if (var != NULL && var->value->type != V_dict) {
+        setResultError(E_TypeException, ONLY_ACC(var, dict), LINEFILE, true, CNEXT_NT);
+        return R_error;
+    }
+
+    if (out != NULL) {
+        if (out->value->type != V_bool) {
+            setResultError(E_TypeException, ONLY_ACC(out, bool), LINEFILE, true, CNEXT_NT);
+            return R_error;
+        } else if (var == NULL) {
+            setResultError(E_TypeException, L"missing parameters: var", LINEFILE, true, CNEXT_NT);
+            return R_error;
+        }
+    } else
+        out = false;
+
+    {
+        ParserMessage *pm = makeParserMessageStr(str->value->data.str.str, false);
+        new_st = makeStatement(0, "exec");
+        parserCommandList(pm, inter, true, new_st);
+
+        if (pm->status == int_error) {
+            setResultError(E_KeyInterrupt, KEY_INTERRUPT, LINEFILE, true, CNEXT_NT);
+            return R_error;
+        } else if (pm->status != success) {
+            wchar_t *wcs_message = memStrToWcs(pm->status_message, false);
+            setResultError(E_TypeException, wcs_message, LINEFILE, true, CNEXT_NT);
+            memFree(wcs_message);
+            return R_error;
+        }
+
+        freeParserMessage(pm, true);
+    }
+
+    if (var != NULL) {
+        run = makeVarList(inter, false, var->value->data.dict.dict);
+        if (out)
+            run->next = var_list;
+    } else
+        run = var_list;
+
+    includeSafeInterStatement(CFUNC(new_st, run, result, belong));
+    freeStatement(new_st);
+
+    if (var != NULL)
+        freeVarList(run);
+
+    return result->type;
+}
+
+void registeredSysLib(R_FUNC){
+    NameFunc tmp[] = {{L"is_now_run",             vm_isnowrun,       fp_no_, .var=nfv_notpush},
+                      {L"dis_now_run",            vm_disnowrun,      fp_no_, .var=nfv_notpush},
+                      {L"quit",                   vm_quit,           fp_no_, .var=nfv_notpush},
+                      {L"exec",                   vm_exec,           fp_no_, .var=nfv_notpush},
+                      {L"assert_ignore",          vm_assertignore,   fp_no_, .var=nfv_notpush},
+                      {L"assert_run",             vm_assertrun,      fp_no_, .var=nfv_notpush},
+                      {L"assert_raise",           vm_assertraise,    fp_no_, .var=nfv_notpush},
+                      {L"self_fun",               vm_selfun,         fp_no_, .var=nfv_notpush},
+                      {L"no_self_fun",            vm_nselfun,        fp_no_, .var=nfv_notpush},
+                      {L"free_mode",              vm_freemode,       fp_no_, .var=nfv_notpush},
+                      {L"normal_mode",            vm_nfreemode,      fp_no_, .var=nfv_notpush},
+                      {L"free_opt",               vm_free_opt,       fp_no_, .var=nfv_notpush},
+                      {L"normal_opt",             vm_normal_opt,     fp_no_, .var=nfv_notpush},
+                      {L"simple_opt",             vm_simple_opt,     fp_no_, .var=nfv_notpush},
+                      {NULL, NULL}};
+    iterBaseNameFunc(tmp, belong, CFUNC_CORE(var_list));
+}

+ 28 - 227
vmcore/ofunc/src/sys.c

@@ -16,7 +16,7 @@ static ResultType vm_super(O_FUNC){
     arg_father = ap[0].value->value;
     arg_child = ap[1].value->value;
     if (arg_child == arg_father) {
-        if (arg_child->object.inherit != NULL){
+        if (arg_child->object.inherit != NULL) {
             result->value = COPY_LINKVALUE(arg_child->object.inherit->value, inter);
             result->type = R_opt;
             gc_addTmpLink(&result->value->gc_status);
@@ -33,12 +33,11 @@ static ResultType vm_super(O_FUNC){
         }
     }
 
-    if (next_father != NULL){
+    if (next_father != NULL) {
         result->value = next_father;
         result->type = R_opt;
         gc_addTmpLink(&result->value->gc_status);
-    }
-    else
+    } else
         setResultError(E_SuperException, L"object has no next father", LINEFILE, true, CNEXT_NT);
 
     return result->type;
@@ -46,7 +45,8 @@ static ResultType vm_super(O_FUNC){
 
 static ResultType vm_setNowRunCore(O_FUNC, bool type){
     LinkValue *function_value = NULL;
-    ArgumentParser ap[] = {{.type=name_value, .name=L"func", .must=1, .long_arg=false}, {.must=-1}};
+    ArgumentParser ap[] = {{.type=name_value, .name=L"func", .must=1, .long_arg=false},
+                           {.must=-1}};
     setResultCore(result);
     {
         parserArgumentUnion(ap, arg, CNEXT_NT);
@@ -64,7 +64,8 @@ static ResultType vm_setNowRunCore(O_FUNC, bool type){
 
 static ResultType vm_setMethodCore(O_FUNC, enum FunctionPtType type){
     LinkValue *function_value = NULL;
-    ArgumentParser ap[] = {{.type=name_value, .name=L"func", .must=1, .long_arg=false}, {.must=-1}};
+    ArgumentParser ap[] = {{.type=name_value, .name=L"func", .must=1, .long_arg=false},
+                           {.must=-1}};
     setResultCore(result);
     {
         parserArgumentUnion(ap, arg, CNEXT_NT);
@@ -152,232 +153,32 @@ static ResultType vm_disnowrun(O_FUNC){
     return vm_setNowRunCore(CO_FUNC(arg, var_list, result, belong), false);
 }
 
-static ResultType vm_quit(O_FUNC){
-    if (arg != NULL)
-        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
-    else
-        setResultError(E_QuitException, L"vmcore quit()", LINEFILE, true, CNEXT_NT);
-    return R_error;
-}
-
 static ResultType vm_open(O_FUNC){
     return callBackCore(inter->data.base_obj[B_FILE], arg, LINEFILE, 0, CNEXT_NT);
 }
 
-static ResultType vm_setAssert(O_FUNC, enum AssertRunType type){
-    setResultCore(result);
-    if (arg != NULL) {
-        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
-        return R_error;
-    }
-
-    inter->data.assert_run = type;
-    setResult(result, inter);
-    return result->type;
-}
-
-static ResultType vm_assertignore(O_FUNC){
-    return vm_setAssert(CO_FUNC(arg, var_list, result, belong), assert_ignore);
-}
-
-static ResultType vm_assertrun(O_FUNC){
-    return vm_setAssert(CO_FUNC(arg, var_list, result, belong), assert_run);
-}
-
-static ResultType vm_assertraise(O_FUNC){
-    return vm_setAssert(CO_FUNC(arg, var_list, result, belong), assert_raise);
-}
-
-static ResultType vm_selfunCore(O_FUNC, bool type){
-    LinkValue *function_value = NULL;
-    ArgumentParser ap[] = {{.type=name_value, .name=L"func", .must=1, .long_arg=false}, {.must=-1}};
-    bool push;
-    setResultCore(result);
-    {
-        parserArgumentUnion(ap, arg, CNEXT_NT);
-        if (!CHECK_RESULT(result))
-            return result->type;
-        freeResult(result);
-    }
-    function_value = ap[0].value;
-    push = function_value->value->data.function.function_data.push;
-    if (push && !type) {  // 原本是push, 现在设定为非push
-        function_value->value->data.function.function_data.push = false;
-        if (function_value->value->object.out_var != NULL)
-            function_value->value->object.out_var = pushVarList(function_value->value->object.out_var, inter);
-    } else if (!push && type){
-        if (function_value->value->object.out_var != NULL)
-            function_value->value->object.out_var = popVarList(function_value->value->object.out_var);
-    }
-
-    result->value = function_value;
-    gc_addTmpLink(&result->value->gc_status);
-    result->type = R_opt;
-    return R_opt;
-}
-
-static ResultType vm_selfun(O_FUNC){
-    return vm_selfunCore(CO_FUNC(arg, var_list, result, belong), false);
-}
-
-static ResultType vm_nselfun(O_FUNC){
-    return vm_selfunCore(CO_FUNC(arg, var_list, result, belong), true);
-}
-
-static ResultType vm_setfreemode(O_FUNC, bool type){
-    setResultCore(result);
-    if (arg != NULL) {
-        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
-        return R_error;
-    }
-
-    inter->data.free_mode = type;
-    setResult(result, inter);
-    return result->type;
-}
-
-static ResultType vm_freemode(O_FUNC){
-    return vm_setfreemode(CO_FUNC(arg, var_list, result, belong), true);
-}
-
-static ResultType vm_nfreemode(O_FUNC){
-    return vm_setfreemode(CO_FUNC(arg, var_list, result, belong), false);
-}
-
-static ResultType vm_opt_mode(O_FUNC, enum OptMode mode){
-    setResultCore(result);
-    if (arg != NULL) {
-        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
-        return R_error;
-    }
-
-    inter->data.opt_mode = mode;
-    setResult(result, inter);
-    return result->type;
-}
-
-static ResultType vm_free_opt(O_FUNC){
-    return vm_opt_mode(CO_FUNC(arg, var_list, result, belong), om_free);
-}
-
-static ResultType vm_normal_opt(O_FUNC){
-    return vm_opt_mode(CO_FUNC(arg, var_list, result, belong), om_normal);
-}
-
-static ResultType vm_simple_opt(O_FUNC){
-    return vm_opt_mode(CO_FUNC(arg, var_list, result, belong), om_simple);
-}
-
-static ResultType vm_exec(O_FUNC){
-    ArgumentParser ap[] = {{.type=name_value, .name=L"cm", .must=1, .long_arg=false},
-                           {.type=name_value, .name=L"var", .must=0, .long_arg=false},
-                           {.type=name_value, .name=L"out", .must=0, .long_arg=false},
-                           {.must=-1}};
-    LinkValue *str;
-    LinkValue *var;
-    LinkValue *out;
-    Statement *new_st;
-    VarList *run;
-
-    setResultCore(result);
-    parserArgumentUnion(ap, arg, CNEXT_NT);
-    if (!CHECK_RESULT(result))
-        return result->type;
-    freeResult(result);
-
-    str = ap[0].value;
-    var = ap[1].value;
-    out = ap[2].value;
-    if (str->value->type != V_str) {
-        setResultError(E_TypeException, ONLY_ACC(cm, str), LINEFILE, true, CNEXT_NT);
-        return result->type;
-    }
-
-    if (var != NULL && var->value->type != V_dict) {
-        setResultError(E_TypeException, ONLY_ACC(var, dict), LINEFILE, true, CNEXT_NT);
-        return R_error;
-    }
-
-    if (out != NULL) {
-        if (out->value->type != V_bool) {
-            setResultError(E_TypeException, ONLY_ACC(out, bool), LINEFILE, true, CNEXT_NT);
-            return R_error;
-        } else if (var == NULL) {
-            setResultError(E_TypeException, L"missing parameters: var", LINEFILE, true, CNEXT_NT);
-            return R_error;
-        }
-    } else
-        out = false;
-
-    {
-        ParserMessage *pm = makeParserMessageStr(str->value->data.str.str, false);
-        new_st = makeStatement(0, "exec");
-        parserCommandList(pm, inter, true, new_st);
-
-        if (pm->status == int_error) {
-            setResultError(E_KeyInterrupt, KEY_INTERRUPT, LINEFILE, true, CNEXT_NT);
-            return R_error;
-        }
-        else if (pm->status != success) {
-            wchar_t *wcs_message = memStrToWcs(pm->status_message, false);
-            setResultError(E_TypeException, wcs_message, LINEFILE, true, CNEXT_NT);
-            memFree(wcs_message);
-            return R_error;
-        }
-
-        freeParserMessage(pm, true);
-    }
-
-    if (var != NULL) {
-        run = makeVarList(inter, false, var->value->data.dict.dict);
-        if (out)
-            run->next = var_list;
-    } else
-        run = var_list;
-
-    includeSafeInterStatement(CFUNC(new_st, run, result, belong));
-    freeStatement(new_st);
-
-    if (var != NULL)
-        freeVarList(run);
-
-    return result->type;
-}
-
 void registeredSysFunction(R_FUNC){
-    NameFunc tmp[] = {{L"super",              vm_super,        fp_no_, .var=nfv_notpush},
-                      {L"static_method",         vm_no_,          fp_no_, .var=nfv_notpush},
-                      {L"func_method",       vm_func_,        fp_no_, .var=nfv_notpush},
-                      {L"func_class_method",  vm_func_class,   fp_no_, .var=nfv_notpush},
-                      {L"func_obj_method", vm_func_obj,     fp_no_, .var=nfv_notpush},
-                      {L"class_method",        vm_class,        fp_no_, .var=nfv_notpush},
-                      {L"obj_method",       vm_obj,          fp_no_, .var=nfv_notpush},
-                      {L"simple_method",       vm_all,          fp_no_, .var=nfv_notpush},
-                      {L"func_simple_method", vm_func_all,     fp_no_, .var=nfv_notpush},
-                      {L"cls_method",          vm_cls,          fp_no_, .var=nfv_notpush},
-                      {L"func_cls_method",    vm_func_cls,     fp_no_, .var=nfv_notpush},
-                      {L"cls_obj_method", vm_cls_obj,     fp_no_, .var=nfv_notpush},
-                      {L"cls_class_method",          vm_cls_class,          fp_no_, .var=nfv_notpush},
-                      {L"cls_simple_method",    vm_cls_all,     fp_no_, .var=nfv_notpush},
-                      {L"func_cls_obj_method", vm_func_cls_obj,     fp_no_, .var=nfv_notpush},
-                      {L"func_cls_obj_method",          vm_func_cls_class,          fp_no_, .var=nfv_notpush},
-                      {L"func_cls_simple_method",    vm_func_cls_all,     fp_no_, .var=nfv_notpush},
-
-                      {L"is_now_run",           vm_isnowrun,     fp_no_, .var=nfv_notpush},
-                      {L"dis_now_run",          vm_disnowrun,    fp_no_, .var=nfv_notpush},
-                      {L"quit",               vm_quit,         fp_no_, .var=nfv_notpush},
-                      {L"exec",               vm_exec,         fp_no_, .var=nfv_notpush},
-                      {L"open",               vm_open,         fp_no_, .var=nfv_notpush},
-                      {L"assert_ignore",      vm_assertignore, fp_no_, .var=nfv_notpush},
-                      {L"assert_run",         vm_assertrun,    fp_no_, .var=nfv_notpush},
-                      {L"assert_raise",       vm_assertraise,  fp_no_, .var=nfv_notpush},
-                      {L"self_fun",             vm_selfun,           fp_no_, .var=nfv_notpush},
-                      {L"no_self_fun",            vm_nselfun,          fp_no_, .var=nfv_notpush},
-                      {L"free_mode", vm_freemode,                 fp_no_, .var=nfv_notpush},
-                      {L"normal_mode", vm_nfreemode,              fp_no_, .var=nfv_notpush},
-                      {L"free_opt", vm_free_opt,                  fp_no_, .var=nfv_notpush},
-                      {L"normal_opt", vm_normal_opt,              fp_no_, .var=nfv_notpush},
-                      {L"simple_opt", vm_simple_opt,              fp_no_, .var=nfv_notpush},
+    NameFunc tmp[] = {{L"super",                  vm_super,          fp_no_, .var=nfv_notpush},
+                      {L"static_method",          vm_no_,            fp_no_, .var=nfv_notpush},
+                      {L"func_method",            vm_func_,          fp_no_, .var=nfv_notpush},
+                      {L"func_class_method",      vm_func_class,     fp_no_, .var=nfv_notpush},
+                      {L"func_obj_method",        vm_func_obj,       fp_no_, .var=nfv_notpush},
+                      {L"class_method",           vm_class,          fp_no_, .var=nfv_notpush},
+                      {L"obj_method",             vm_obj,            fp_no_, .var=nfv_notpush},
+                      {L"simple_method",          vm_all,            fp_no_, .var=nfv_notpush},
+                      {L"func_simple_method",     vm_func_all,       fp_no_, .var=nfv_notpush},
+                      {L"cls_method",             vm_cls,            fp_no_, .var=nfv_notpush},
+                      {L"func_cls_method",        vm_func_cls,       fp_no_, .var=nfv_notpush},
+                      {L"cls_obj_method",         vm_cls_obj,        fp_no_, .var=nfv_notpush},
+                      {L"cls_class_method",       vm_cls_class,      fp_no_, .var=nfv_notpush},
+                      {L"cls_simple_method",      vm_cls_all,        fp_no_, .var=nfv_notpush},
+                      {L"func_cls_obj_method",    vm_func_cls_obj,   fp_no_, .var=nfv_notpush},
+                      {L"func_cls_obj_method",    vm_func_cls_class, fp_no_, .var=nfv_notpush},
+                      {L"func_cls_simple_method", vm_func_cls_all,   fp_no_, .var=nfv_notpush},
+
+                      {L"is_now_run",             vm_isnowrun,       fp_no_, .var=nfv_notpush},
+                      {L"dis_now_run",            vm_disnowrun,      fp_no_, .var=nfv_notpush},
+                      {L"open",                   vm_open,           fp_no_, .var=nfv_notpush},
                       {NULL, NULL}};
     iterBaseNameFunc(tmp, belong, CFUNC_CORE(var_list));
 }

+ 5 - 6
vmcore/src/runfile.c

@@ -67,7 +67,7 @@ int checkFileDir(char **file_dir, FUNC) {
         char arr_cwd[200];
         char *p_cwd = NULL;
         getcwd(arr_cwd, 200);
-        p_cwd = memStrcatIter(arr_cwd, false, SEP, *file_dir);
+        p_cwd = memStrcatIter(arr_cwd, false, SEP, *file_dir, NULL);  // 以NULL结尾表示结束
         if (isExist(&p_cwd, false, "__init__.vm")) {
             memFree(*file_dir);
             *file_dir = p_cwd;
@@ -80,7 +80,7 @@ int checkFileDir(char **file_dir, FUNC) {
     char *path = memStrcpy(getenv("VIRTUALMATHPATH"));
     for (char *tmp = strtok(path, ";"), *new_dir; tmp != NULL; tmp = strtok(NULL, ";")) {
         if (*(tmp + (memStrlen(tmp) - 1)) != SEP_CH)
-            new_dir = memStrcatIter(tmp, false, SEP, *file_dir);
+            new_dir = memStrcatIter(tmp, false, SEP, *file_dir, NULL);  // 以NULL结尾表示结束
         else
             new_dir = memStrcat(tmp, *file_dir, false, false);
 
@@ -96,7 +96,7 @@ int checkFileDir(char **file_dir, FUNC) {
 }
 
     clib:
-    if (checkCLib(*file_dir))
+    if (checkCLib(*file_dir))  // 检查是否为 clib
         return 2;
 
     error_:
@@ -179,8 +179,7 @@ ResultType importFileCore(char **path, char **split, int *status, FUNC) {
     *path = memWcsToStr(result->value->value->data.str.str, false);
     *split = splitDir(*path);  // 自动去除末尾路径分隔符
     freeResult(result);
-    if ((*status = checkFileDir(path, CNEXT)) == 0)
-        return result->type;
+    *status = checkFileDir(path, CNEXT);
 
     return result->type;
 }
@@ -188,7 +187,7 @@ ResultType importFileCore(char **path, char **split, int *status, FUNC) {
 ResultType runImportFile(Inter *import_inter, char **path, int status, FUNC) {
     setResultCore(result);
     if (status == 2)
-        importClibCore(*path, belong, CFUNC_CORE(inter->var_list));
+        importClibCore(*path, belong, CFUNC_CORE(import_inter->var_list));
     else
         importVMFileCore(import_inter, *path, st->line, st->code_file, CNEXT_NT);