Parcourir la source

refactor & feat: Runtime改为Interface

SongZihuan il y a 3 ans
Parent
commit
107ea3cb95

+ 9 - 0
include/interface/aFunit.h

@@ -0,0 +1,9 @@
+#ifndef AFUN_AFUNIT_H
+#define AFUN_AFUNIT_H
+
+#include "it-init.h"
+#include "it-reader.h"
+#include "it-inter.h"
+#include "it-exception.h"
+
+#endif //AFUN_AFUNIT_H

+ 1 - 1
include/runtime/func-exit.h → include/interface/func-exit.h

@@ -3,7 +3,7 @@
 #include "aFunlangExport.h"
 #include "aFuncore.h"
 
-namespace aFunrt {
+namespace aFunit {
     class ExitFunction : public aFuncore::Function {
         class CallFunc : public CallFunction {
             const aFuncore::Code::ByteCode *call_code;

+ 1 - 1
include/runtime/func-exit.inline.h → include/interface/func-exit.inline.h

@@ -3,7 +3,7 @@
 
 #include "func-exit.h"
 
-namespace aFunrt {
+namespace aFunit {
     inline ExitFunction::ExitFunction(aFuncore::Inter &inter_) : Object("Function", inter_) {
 
     }

+ 1 - 1
include/runtime/func-import.h → include/interface/func-import.h

@@ -3,7 +3,7 @@
 #include "aFunlangExport.h"
 #include "aFuncore.h"
 
-namespace aFunrt {
+namespace aFunit {
     class ImportFunction : public aFuncore::Function {
         class CallFunc : public CallFunction {
             const aFuncore::Code::ByteCode *call_code;

+ 1 - 1
include/runtime/func-import.inline.h → include/interface/func-import.inline.h

@@ -2,7 +2,7 @@
 #define AFUN_FUNC_IMPORT_INLINE_H
 #include "func-import.h"
 
-namespace aFunrt {
+namespace aFunit {
     inline ImportFunction::ImportFunction(aFuncore::Inter &inter_) : Object("Function", inter_) {
 
     }

+ 20 - 0
include/interface/it-exception.h

@@ -0,0 +1,20 @@
+#ifndef AFUN_IT_EXCEPTION_H
+#define AFUN_IT_EXCEPTION_H
+#include "aFuntool.h"
+
+namespace aFunit {
+    class aFunitException : public aFuntool::aFunException {
+    public:
+        inline explicit aFunitException(const std::string &msg);
+    };
+
+    class readerFileOpenError : public aFunitException {
+    public:
+        inline explicit readerFileOpenError(const aFuntool::FilePath &file);
+    };
+
+}
+
+#include "it-exception.inline.h"
+
+#endif //AFUN_IT_EXCEPTION_H

+ 17 - 0
include/interface/it-exception.inline.h

@@ -0,0 +1,17 @@
+#ifndef AFUN_IT_EXCEPTION_INLINE_H
+#define AFUN_IT_EXCEPTION_INLINE_H
+
+#include "it-exception.h"
+
+namespace aFunit {
+    inline aFunitException::aFunitException(const std::string &msg) : aFunException{msg} {
+
+    }
+
+    inline readerFileOpenError::readerFileOpenError(const aFuntool::FilePath &file)
+        : aFunitException("Reader cannot open file: " + file) {
+
+    }
+}
+
+#endif //AFUN_IT_EXCEPTION_INLINE_H

+ 5 - 5
include/runtime/rt-init.h → include/interface/it-init.h

@@ -1,9 +1,9 @@
-#ifndef AFUN_RT_INIT_H
-#define AFUN_RT_INIT_H
+#ifndef AFUN_IT_INIT_H
+#define AFUN_IT_INIT_H
 #include "aFunlangExport.h"
 #include "aFuncore.h"
 
-namespace aFunrt {
+namespace aFunit {
     struct aFunInitInfo : public aFuncore::InitInfo {
         aFuntool::LogLevel lang_level;
 
@@ -18,6 +18,6 @@ namespace aFunrt {
     AFUN_LANG_EXPORT bool aFunInit(aFunInitInfo *info);
 }
 
-#include "rt-init.inline.h"
+#include "it-init.inline.h"
 
-#endif //AFUN_RT_INIT_H
+#endif //AFUN_IT_INIT_H

+ 5 - 5
include/runtime/rt-init.inline.h → include/interface/it-init.inline.h

@@ -1,9 +1,9 @@
-#ifndef AFUN_RT_INIT_INLINE_H
-#define AFUN_RT_INIT_INLINE_H
+#ifndef AFUN_IT_INIT_INLINE_H
+#define AFUN_IT_INIT_INLINE_H
 
-#include "rt-init.h"
+#include "it-init.h"
 
-namespace aFunrt {
+namespace aFunit {
     inline aFunInitInfo::aFunInitInfo(const std::string &base_dir_,
                                       aFuntool::LogFactory &factor_,
                                       bool log_asyn_,
@@ -15,4 +15,4 @@ namespace aFunrt {
 }
 
 
-#endif //AFUN_RT_INIT_INLINE_H
+#endif //AFUN_IT_INIT_INLINE_H

+ 4 - 4
include/runtime/rt-inter.h → include/interface/it-inter.h

@@ -1,9 +1,9 @@
-#ifndef AFUN_RT_INTER_H
-#define AFUN_RT_INTER_H
+#ifndef AFUN_IT_INTER_H
+#define AFUN_IT_INTER_H
 #include "aFunlangExport.h"
 #include "aFuncore.h"
 
-namespace aFunrt {
+namespace aFunit {
     class AFUN_LANG_EXPORT aFunEnvironment : public aFuncore::Environment {
     public:
         explicit aFunEnvironment(int argc = 0, char **argv = nullptr);
@@ -11,4 +11,4 @@ namespace aFunrt {
 }
 
 
-#endif //AFUN_RT_INTER_H
+#endif //AFUN_IT_INTER_H

+ 6 - 6
include/runtime/rt-reader.h → include/interface/it-reader.h

@@ -1,11 +1,11 @@
-#ifndef AFUN_RT_READER_H
-#define AFUN_RT_READER_H
+#ifndef AFUN_IT_READER_H
+#define AFUN_IT_READER_H
 #include <functional>
 #include "aFunlangExport.h"
 #include "aFuncore.h"
-#include "rt-init.h"
+#include "it-init.h"
 
-namespace aFunrt {
+namespace aFunit {
     class AFUN_LANG_EXPORT StringReader : public aFuncore::Reader {
     public:
         inline StringReader(std::string str_, const aFuntool::FilePath &path_);
@@ -27,6 +27,6 @@ namespace aFunrt {
 
 }
 
-#include "rt-reader.inline.h"
+#include "it-reader.inline.h"
 
-#endif //AFUN_RT_READER_H
+#endif //AFUN_IT_READER_H

+ 6 - 6
include/runtime/rt-reader.inline.h → include/interface/it-reader.inline.h

@@ -1,9 +1,9 @@
-#ifndef AFUN_RT_READER_INLINE_H
-#define AFUN_RT_READER_INLINE_H
-#include "rt-reader.h"
-#include "rt-exception.h"
+#ifndef AFUN_IT_READER_INLINE_H
+#define AFUN_IT_READER_INLINE_H
+#include "it-reader.h"
+#include "it-exception.h"
 
-namespace aFunrt {
+namespace aFunit {
     inline StringReader::StringReader(std::string str_, const aFuntool::FilePath &path_)
         : Reader{path_, 0}, str{std::move(str_)} {
         index = 0;
@@ -19,4 +19,4 @@ namespace aFunrt {
     }
 }
 
-#endif //AFUN_RT_READER_INLINE_H
+#endif //AFUN_IT_READER_INLINE_H

+ 0 - 9
include/runtime/aFunrt.h

@@ -1,9 +0,0 @@
-#ifndef AFUN_AFUNRT_H
-#define AFUN_AFUNRT_H
-
-#include "rt-init.h"
-#include "rt-reader.h"
-#include "rt-inter.h"
-#include "rt-exception.h"
-
-#endif //AFUN_AFUNRT_H

+ 0 - 20
include/runtime/rt-exception.h

@@ -1,20 +0,0 @@
-#ifndef AFUN_RT_EXCEPTION_H
-#define AFUN_RT_EXCEPTION_H
-#include "aFuntool.h"
-
-namespace aFunrt {
-    class aFunrtException : public aFuntool::aFunException {
-    public:
-        inline explicit aFunrtException(const std::string &msg);
-    };
-
-    class readerFileOpenError : public aFunrtException {
-    public:
-        inline explicit readerFileOpenError(const aFuntool::FilePath &file);
-    };
-
-}
-
-#include "rt-exception.inline.h"
-
-#endif //AFUN_RT_EXCEPTION_H

+ 0 - 17
include/runtime/rt-exception.inline.h

@@ -1,17 +0,0 @@
-#ifndef AFUN_RT_EXCEPTION_INLINE_H
-#define AFUN_RT_EXCEPTION_INLINE_H
-
-#include "rt-exception.h"
-
-namespace aFunrt {
-    inline aFunrtException::aFunrtException(const std::string &msg) : aFunException{msg} {
-
-    }
-
-    inline readerFileOpenError::readerFileOpenError(const aFuntool::FilePath &file)
-        : aFunrtException("Reader cannot open file: " + file) {
-
-    }
-}
-
-#endif //AFUN_RT_EXCEPTION_INLINE_H

+ 6 - 6
src/CMakeLists.txt

@@ -4,8 +4,8 @@ set(install_include_tool ${INSTALL_INCLUDEDIR})
 set(build_include_core ${PROJECT_SOURCE_DIR}/include/core)
 set(install_include_core ${INSTALL_INCLUDEDIR})
 
-set(build_include_runtime ${PROJECT_SOURCE_DIR}/include/runtime)
-set(install_include_runtime ${INSTALL_INCLUDEDIR})
+set(build_include_interface ${PROJECT_SOURCE_DIR}/include/interface)
+set(install_include_interface ${INSTALL_INCLUDEDIR})
 
 set(build_include_
     ${hgt_dir}
@@ -13,7 +13,7 @@ set(build_include_
     ${build_include_tool}
     ${build_include_core}
     ${build_include_core_info}
-    ${build_include_runtime})
+    ${build_include_interface})
 
 set(build_include)
 foreach(dir IN LISTS build_include_)
@@ -25,7 +25,7 @@ set(install_include $<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}>)
 
 add_subdirectory(tool)
 add_subdirectory(core)  # core 依赖 tool
-add_subdirectory(runtime)  # runtime 依赖 core
+add_subdirectory(interface)  # interface 依赖 core
 
 # source在子目录中被使用, 为了避免子目录访问到source, 子目录将在此前面被执行
 file(GLOB source
@@ -50,6 +50,6 @@ target_link_libraries(aFun-xx PUBLIC rt-shared FFlags::fflags)
 target_link_libraries(aFun-ct PUBLIC rt-static FFlags::fflags)
 
 install(TARGETS aFun-xx aFun-ct
-        RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT advanced-runtime
+        RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT dev
         PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev
-        PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT advanced-dev)
+        PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev)

+ 2 - 2
src/__main.h

@@ -1,12 +1,12 @@
 #ifndef AFUN_MAIN_H
 #define AFUN_MAIN_H
-#include "aFunrt.h"
+#include "aFunit.h"
 #include "fflags.h"
 
 namespace aFun {
     using namespace aFuntool;
     using namespace aFuncore;
-    using namespace aFunrt;
+    using namespace aFunit;
 };
 
 void printError(ff_FFlags *ff);

+ 2 - 2
src/runtime/CMakeLists.txt → src/interface/CMakeLists.txt

@@ -38,8 +38,8 @@ foreach(tgt rt-shared rt-static)
     define_FILENAME(${tgt})
 endforeach()
 
-set_target_properties(rt-shared PROPERTIES OUTPUT_NAME "aFunrt")
-set_target_properties(rt-static PROPERTIES OUTPUT_NAME "aFunrt-s")
+set_target_properties(rt-shared PROPERTIES OUTPUT_NAME "aFunit")
+set_target_properties(rt-static PROPERTIES OUTPUT_NAME "aFunit-s")
 
 target_link_libraries(rt-shared PUBLIC core-shared)
 target_link_libraries(rt-static PUBLIC core-static)

+ 1 - 1
src/runtime/func-exit.cpp → src/interface/func-exit.cpp

@@ -1,6 +1,6 @@
 #include "func-exit.h"
 
-namespace aFunrt {
+namespace aFunit {
     aFuncore::Function::CallFunction *ExitFunction::getCallFunction(const aFuncore::Code::ByteCode *code, aFuncore::Inter &inter) {
         return dynamic_cast<CallFunction *>(new CallFunc(code, inter));
     }

+ 1 - 1
src/runtime/func-import.cpp → src/interface/func-import.cpp

@@ -1,6 +1,6 @@
 #include "func-import.h"
 
-namespace aFunrt {
+namespace aFunit {
     aFuncore::Function::CallFunction *ImportFunction::getCallFunction(const aFuncore::Code::ByteCode *code, aFuncore::Inter &inter) {
         return dynamic_cast<CallFunction *>(new CallFunc(code, inter));
     }

+ 2 - 2
src/runtime/rt-init.cpp → src/interface/it-init.cpp

@@ -1,6 +1,6 @@
-#include "rt-init.h"
+#include "it-init.h"
 
-namespace aFunrt {
+namespace aFunit {
     aFuntool::Logger *aFunLogger = nullptr;
 
     bool aFunInit(aFunInitInfo *info) {

+ 2 - 2
src/runtime/rt-inter.cpp → src/interface/it-inter.cpp

@@ -1,8 +1,8 @@
-#include "rt-inter.h"
+#include "it-inter.h"
 #include "func-exit.h"
 #include "func-import.h"
 
-namespace aFunrt {
+namespace aFunit {
     aFunEnvironment::aFunEnvironment(int argc, char **argv) : Environment(argc, argv)  {
         {  // 退出函数
             auto exit = new ExitFunction(*this);

+ 3 - 3
src/runtime/rt-reader.cpp → src/interface/it-reader.cpp

@@ -1,7 +1,7 @@
-#include "rt-reader.h"
-#include "rt-init.h"
+#include "it-reader.h"
+#include "it-init.h"
 
-namespace aFunrt {
+namespace aFunit {
     size_t StringReader::readText(char *dest, size_t read_len, ReadMode &mode) {
         if (index == len)  // 读取到末尾
             return 0;

+ 1 - 1
test/src/CMakeLists.txt

@@ -34,6 +34,6 @@ add_new_test(core-up-msg COMMAND "$<TARGET_FILE:core-up-msg>")
 add_new_test(core-reader COMMAND "$<TARGET_FILE:core-reader>")
 add_new_test(core-lexical COMMAND "$<TARGET_FILE:core-lexical>")
 
-add_new_test(rt-syntactic COMMAND "$<TARGET_FILE:rt-syntactic>")
+add_new_test(it-syntactic COMMAND "$<TARGET_FILE:it-syntactic>")
 
 add_new_test(run-code COMMAND "$<TARGET_FILE:run-code>")

+ 4 - 4
test/src/rt-syntactic.cpp → test/src/it-syntactic.cpp

@@ -1,5 +1,5 @@
 #include <cstdio>
-#include "aFunrt.h"
+#include "aFunit.h"
 
 const char *str = "{if true [HelloWorld (10)]}\n";
 const char *str2 = "{if true [HelloWorld (10)\n";
@@ -89,7 +89,7 @@ int main(int argc, char **) {
     std::string md5_2;
 
     {
-        auto reader = aFunrt::StringReader(str, "str");
+        auto reader = aFunit::StringReader(str, "str");
         auto parser = aFuncore::Parser(reader);
         auto code = aFuncore::Code("test.aun");
         bool ret = parser.parserCode(code);
@@ -101,7 +101,7 @@ int main(int argc, char **) {
     }
 
     {
-        auto reader = aFunrt::StringReader(str2, "str2");
+        auto reader = aFunit::StringReader(str2, "str2");
         auto parser = aFuncore::Parser(reader);
         auto code = aFuncore::Code("test2.aun");
         parser.parserCode(code);
@@ -121,7 +121,7 @@ int main(int argc, char **) {
         fprintf(file, "%s", str);
         aFuntool::fileClose(file);
 
-        auto reader = aFunrt::FileReader("test.aun");
+        auto reader = aFunit::FileReader("test.aun");
         auto parser = aFuncore::Parser(reader);
         auto code = aFuncore::Code("test.aun");
         bool ret = parser.parserCode(code);

+ 2 - 2
test/src/run-code.cpp

@@ -1,6 +1,6 @@
-#include "aFunrt.h"
+#include "aFunit.h"
 
-using namespace aFunrt;
+using namespace aFunit;
 using namespace aFuncore;
 using namespace aFuntool;
 

+ 1 - 1
test/src/tool-byte.cpp

@@ -61,7 +61,7 @@ int main() {
         printf("rtest8 = %d, test = %d\n", rtest8, test8);
         printf("rtest16 = %d, test = %d\n", rtest16, test16);
         printf("rtest32 = %d, test = %d\n", rtest32, test32);
-        printf("rtest64 = %ld, test = %ld\n", rtest64, test64);
+        printf("rtest64 = %lld, test = %lld\n", rtest64, test64);
         printf("rtestStr = %s\ntestStr = %s\n", rtestStr.c_str(), testStr.c_str());
         return EXIT_FAILURE;
     }