├── .gitignore ├── .gitmodules ├── .travis.yml ├── Authors ├── Builder ├── .gitignore ├── CMakeLists.txt ├── Doxyfile.in ├── build.sh ├── include │ ├── Builder.h │ ├── PathGetter.h │ ├── PathSet.h │ └── Worker.h └── src │ ├── Builder.cpp │ ├── CmdUtils.h │ ├── Importer.h │ ├── PackageChanger.hpp │ ├── PathGetter.cpp │ ├── PathSet.cpp │ └── Worker.cpp ├── CHANGELOG.md ├── CMakeLists.txt ├── EliteTest ├── bug_list │ ├── 9 │ │ ├── TODO.md │ │ ├── test.elite │ │ └── test.out │ ├── 10 │ │ ├── TODO │ │ ├── test.elite │ │ └── test.out │ ├── 11 │ │ ├── src │ │ │ └── com │ │ │ │ └── hha │ │ │ │ ├── test.elite │ │ │ │ └── work.elite │ │ └── test.out │ └── run_test.py └── full_test │ ├── 1 │ ├── test.elite │ └── test.out │ ├── 2 │ ├── test.elite │ └── test.out │ ├── 3 │ ├── test.elite │ └── test.out │ ├── 4 │ ├── test.elite │ └── test.out │ ├── 5 │ ├── test.elite │ └── test.out │ ├── 6 │ ├── test.elite │ └── test.out │ ├── 7 │ ├── test.elite │ └── test.out │ ├── 8 │ ├── test.elite │ └── test.out │ └── run_test.py ├── ExIconv ├── .gitignore ├── CMakeLists.txt ├── Doxyfile.in ├── build.sh ├── include │ ├── DebugMsg.h │ ├── DebugMsg_Simple.h │ ├── FileUtils.h │ ├── PathUtils.h │ └── estring.h ├── src │ ├── DebugMsg.cpp │ ├── FileUtils.cpp │ ├── PathUtils.cpp │ └── estring.cpp └── test │ ├── CMakeLists.txt │ └── EstringTest.cpp ├── Makefile ├── MetaScriptRunner ├── CMakeLists.txt ├── Doxyfile.in ├── build.sh ├── include │ ├── EPackage.h │ ├── ILoader.h │ ├── LuaGenFunction.h │ ├── MetaScriptRunner.h │ ├── PackageJIT.h │ └── PackageLoader.h └── src │ ├── EPackage.cpp │ ├── LuaGenFunction.cpp │ ├── MetaAPI.cpp │ ├── MetaScriptRunner.cpp │ ├── PackageJIT.cpp │ ├── PackageLoader.cpp │ ├── cJSON.c │ ├── cJSON.h │ ├── llcgAPI.cpp │ └── main.cpp ├── Preprocessor ├── CMakeLists.txt ├── include │ └── Preprocessor.h ├── src │ └── Preprocessor.cpp └── test │ ├── CMakeLists.txt │ ├── PPTest.cpp │ └── t1.ecode ├── README.md ├── appveyor.yml ├── cmake ├── ClangConf.cmake ├── CombineHeader.cmake ├── ExternalProject.cmake ├── Install.cmake ├── MSVCConf.cmake ├── ThirdPartyBuild.cmake ├── UnixGlib.cmake ├── UnixLLVM.cmake └── WindowsLLVM.cmake ├── conf ├── lex.cfg └── parser.cfg ├── doc ├── CMakeLists.txt ├── Doxyfile.in ├── Doxyfile.zh-cn.in ├── _1_introduce.zh-cn.md ├── _2_user_manual.zh-cn.md ├── _3_developers_manual.zh-cn.md ├── design │ ├── Elite语言-原创宏翻译语言.md │ ├── TODO.md │ ├── 使用Elite开发您的Hello World.md │ ├── 元脚本的特殊用法.md │ ├── 函数名重载的设计方案.md │ ├── 各项目文件夹的命名习惯及约定.md │ ├── 常量表达式特性.md │ ├── 构建过程描述文档.md │ ├── 生成器的实现.md │ ├── 符号表设计.md │ ├── 编码转换问题.md │ ├── 编译系统工作流程.png │ ├── 语言特性包.md │ ├── 闭包的实现.md │ ├── 静态语言中添加动态性.md │ ├── 项目文档的构建.md │ └── 项目测试.md ├── developer │ ├── doc.zh-cn.md │ ├── proj_struct.zh-cn.md │ └── test.zh-cn.md ├── elite.ico ├── image │ ├── LALR.gv │ └── a.svg ├── index.en.md ├── index.zh-cn.md ├── manual │ ├── ARC.md │ ├── DesignManual.md │ ├── DesignManual.pdf │ ├── ca.jpg │ ├── classNode.png │ ├── compilers-principles.gv │ ├── cp.png │ ├── cp.svg │ ├── elsevier-with-titles.csl │ ├── heap.pdf │ ├── linker.gv │ ├── linker.png │ ├── linker.svg │ ├── lrtree.dot │ ├── lrtree.png │ ├── missfont.log │ ├── modules.dot │ ├── modules.png │ ├── mp.pdf │ ├── mp.png │ ├── mt.dot │ ├── profile.pdf │ ├── remark-latest.min.js │ └── slides.html ├── misc │ ├── DoxygenLayout.xml │ ├── doxygenextra.css │ ├── footer.html │ ├── github_logo.png │ └── header.html └── user │ ├── install.zh-cn.md │ ├── lang-ref.zh-cn.md │ ├── lex.zh-cn.md │ └── parser.zh-cn.md ├── header_libs ├── cereal-1.1.2 │ └── cereal │ │ ├── access.hpp │ │ ├── archives │ │ ├── adapters.hpp │ │ ├── binary.hpp │ │ ├── json.hpp │ │ ├── portable_binary.hpp │ │ └── xml.hpp │ │ ├── cereal.hpp │ │ ├── details │ │ ├── helpers.hpp │ │ ├── polymorphic_impl.hpp │ │ ├── static_object.hpp │ │ ├── traits.hpp │ │ └── util.hpp │ │ ├── external │ │ ├── base64.hpp │ │ ├── rapidjson │ │ │ ├── document.h │ │ │ ├── filestream.h │ │ │ ├── genericstream.h │ │ │ ├── internal │ │ │ │ ├── pow10.h │ │ │ │ ├── stack.h │ │ │ │ └── strfunc.h │ │ │ ├── license.txt │ │ │ ├── prettywriter.h │ │ │ ├── rapidjson.h │ │ │ ├── reader.h │ │ │ ├── stringbuffer.h │ │ │ └── writer.h │ │ └── rapidxml │ │ │ ├── license.txt │ │ │ ├── manual.html │ │ │ ├── rapidxml.hpp │ │ │ ├── rapidxml_iterators.hpp │ │ │ ├── rapidxml_print.hpp │ │ │ └── rapidxml_utils.hpp │ │ ├── macros.hpp │ │ └── types │ │ ├── array.hpp │ │ ├── base_class.hpp │ │ ├── bitset.hpp │ │ ├── boost_variant.hpp │ │ ├── chrono.hpp │ │ ├── common.hpp │ │ ├── complex.hpp │ │ ├── deque.hpp │ │ ├── forward_list.hpp │ │ ├── list.hpp │ │ ├── map.hpp │ │ ├── memory.hpp │ │ ├── polymorphic.hpp │ │ ├── queue.hpp │ │ ├── set.hpp │ │ ├── stack.hpp │ │ ├── string.hpp │ │ ├── tuple.hpp │ │ ├── unordered_map.hpp │ │ ├── unordered_set.hpp │ │ ├── utility.hpp │ │ ├── valarray.hpp │ │ └── vector.hpp ├── elegantlist │ ├── elegantlist.hpp │ └── eltest.cpp └── sptr │ ├── memheap.hpp │ └── sptr.hpp ├── libs └── .gitkeep ├── packages ├── .gitkeep └── bgc │ ├── bgc.epbc │ ├── libbgc.a │ ├── libgc-lib.a │ ├── package.json │ └── src │ ├── Makefile │ ├── bgc.o │ ├── main.cpp │ └── runtime.cpp ├── scripts ├── chmod_runnable.sh ├── fix_ubuntu │ └── LLVMConfig.cmake ├── fix_ubuntu_llvm.sh ├── install_gtest.sh ├── install_llvm_win32.bat └── makeln(不推荐).sh └── src ├── elite-config.h ├── help.h └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.*~ 2 | *.bc 3 | .fuse* 4 | *.sublime-* 5 | *.lrsave 6 | .clang_complete 7 | bin/ 8 | lib/ 9 | runtime/ 10 | build/ 11 | Lex/bin/ 12 | Lex/build/ 13 | LR_Scanner/bin/ 14 | LR_Scanner/build/ 15 | RedApple/bin/ 16 | RedApple/build/ 17 | third_party/ 18 | extlib/ 19 | build-doc/ 20 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Lex"] 2 | path = Lex 3 | url = https://github.com/elite-lang/Lex.git 4 | 5 | [submodule "LR_Scanner"] 6 | path = LR_Scanner 7 | url = https://github.com/elite-lang/LR_Scanner.git 8 | 9 | [submodule "RedApple"] 10 | path = RedApple 11 | url = https://github.com/elite-lang/RedApple.git 12 | 13 | [submodule "tools"] 14 | path = tools 15 | url = https://github.com/elite-lang/tools.git 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | git: 2 | depth: 3 3 | 4 | compiler: 5 | - gcc 6 | - clang 7 | 8 | matrix: 9 | include: 10 | - os: linux 11 | dist: trusty 12 | sudo: required 13 | 14 | - os: osx 15 | osx_image: xcode7.3 16 | sudo: required 17 | 18 | addons: 19 | apt: 20 | packages: 21 | - llvm-3.6-dev 22 | - libedit-dev 23 | - flex 24 | - bison 25 | 26 | before_install: 27 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi 28 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install llvm flex bison; fi 29 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo sh ./scripts/fix_ubuntu_llvm.sh; fi 30 | - sudo sh ./scripts/install_gtest.sh 31 | - sudo sh ./scripts/chmod_runnable.sh 32 | 33 | script: 34 | - make test 35 | - python ./EliteTest/full_test/run_test.py 36 | 37 | after_success: 38 | - bash <(curl -s https://codecov.io/bash) 39 | -------------------------------------------------------------------------------- /Authors: -------------------------------------------------------------------------------- 1 | ## 请贡献者将自己添加到作者列表中,您的一点一滴贡献,都值得我们永远记忆 ## 2 | ## 我们也会定期检查并更新该列表,以确认是否全部贡献都得到记录 ## 3 | ## 以下列表安装字母序排列,母语非英语的贡献者可以将自己的母语名字添加到英文名后 ## 4 | 5 | ## Please contributors to add yourself to the list of authors , your contribution bit by bit , are worthy of our memories forever ## 6 | ## We also regularly check and update this list to confirm whether all contributions have been recorded ## 7 | ## The following list in alphabetical order , non-native English contributors can add your name in mother tongue after the English name ## 8 | 9 | Norgerman 徐宇楠 10 | Sunxfancy 孙笑凡 11 | Vvliebe 熊汉彪 12 | -------------------------------------------------------------------------------- /Builder/.gitignore: -------------------------------------------------------------------------------- 1 | *.*~ 2 | .fuse* 3 | *.sublime-* 4 | bin/ 5 | build/ 6 | libcharsetdetect/ 7 | libiconv-1.14/ 8 | 9 | -------------------------------------------------------------------------------- /Builder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(Builder) 3 | 4 | if(NOT BUILD_ALL) # BUILD_ALL负责确认是不是所有子项目统一配置构建 5 | SET (CMAKE_BUILD_TYPE Debug) 6 | SET (CMAKE_CXX_COMPILER_ENV_VAR "clang++") 7 | SET (CMAKE_CXX_FLAGS "-std=c++11") 8 | SET (CMAKE_CXX_FLAGS_DEBUG "-g") 9 | SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 10 | SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG") 11 | SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") 12 | SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) 13 | include_directories(../Lex/include 14 | ../LR_Scanner/include 15 | ../RedApple/includes 16 | ../MetaScriptRunner/include 17 | ) 18 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib) 19 | endif() 20 | 21 | 22 | # 核心路径配置 23 | include_directories(src include ../tools) 24 | file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 25 | if(USE_DYNAMIC) 26 | add_library(builder SHARED ${source_files}) # 使用动态库 27 | install(TARGETS builder RUNTIME DESTINATION bin) 28 | else() 29 | add_library(builder STATIC ${source_files}) # 使用静态库 30 | install(TARGETS builder ARCHIVE DESTINATION lib) 31 | endif() 32 | -------------------------------------------------------------------------------- /Builder/Doxyfile.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "@CMAKE_PROJECT_NAME@" 2 | PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ 3 | STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ \ 4 | @PROJECT_BINARY_DIR@ 5 | INPUT = @doxy_main_page@ \ 6 | @PROJECT_SOURCE_DIR@ \ 7 | @PROJECT_BINARY_DIR@ 8 | FILE_PATTERNS = *.h \ 9 | *.c 10 | OUTPUT_LANGUAGE = Chinese 11 | RECURSIVE = YES 12 | EXTRACT_ALL = YES 13 | EXTRACT_PRIVATE = YES 14 | EXTRACT_STATIC = YES 15 | EXCLUDE_PATTERNS = */thirdparty/* 16 | USE_MDFILE_AS_MAINPAGE = @doxy_main_page@ 17 | -------------------------------------------------------------------------------- /Builder/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # @Author: sxf 3 | # @Date: 2015-11-03 08:33:43 4 | # @Last Modified by: sxf 5 | # @Last Modified time: 2015-11-03 08:34:18 6 | 7 | mkdir ./build 8 | cd ./build 9 | cmake .. 10 | make 11 | cd .. -------------------------------------------------------------------------------- /Builder/include/Builder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-08 09:06:35 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 15:47:59 6 | */ 7 | 8 | 9 | #ifndef BUILDER_H 10 | #define BUILDER_H 11 | 12 | #include 13 | #include "PathSet.h" 14 | 15 | class Worker; 16 | 17 | /** 18 | * @brief 项目构建器 19 | */ 20 | class Builder 21 | { 22 | public: 23 | // 构建一个文件 24 | int BuildFile(std::string filename); 25 | 26 | // 构建其中指定的路径 27 | int BuildPath(std::string package, bool isRecursive = false); 28 | 29 | // 自动构建源代码目录下的全部内容 30 | int BuildAll(); 31 | 32 | // 添加一个链接文件, 如果是bc的话, 会自动用llc编译成本地文件, 如果是.o则直接链接 33 | int AddLinkFile(std::string filename); 34 | 35 | // 添加一个链接路径 36 | int AddLinkPath(std::string path); 37 | 38 | // 设置构建路径 39 | int SetBuildPath(std::string path); 40 | 41 | // 扫描SearchPath下的全部符号 42 | int PreBuildAll(); 43 | 44 | // 添加源代码的搜索路径 45 | int AddSrcPath(std::string path); 46 | 47 | // 添加库路径 48 | int AddLibPath(std::string path); 49 | 50 | // 添加链接时参数 51 | int AddLinkArgs(std::string args); 52 | 53 | // 设置Debug过程文件生成路径 54 | void setDebugFilePath(const char* path); 55 | 56 | // 设置工作器 57 | void setWorker(Worker* worker); 58 | 59 | // 构建Builder,需要初始化好的Worker 60 | static Builder* Create(Worker* worker = 0); 61 | void Close(); 62 | 63 | 64 | static int call_llc(std::string filein); 65 | static int call_ld(std::string filein, std::string fileout, std::string link_args); 66 | protected: 67 | Builder(Worker* worker = 0); 68 | ~Builder(); 69 | 70 | Worker* worker = 0; 71 | std::string buildpath; 72 | std::string link_args; 73 | 74 | static std::string make_default_name(const char* filename); 75 | static std::string get_file_name(const char* filename); 76 | 77 | 78 | 79 | /** 80 | * 程序源文件目录 81 | */ 82 | PathSet src_paths; 83 | 84 | /** 85 | * 程序库目录 86 | */ 87 | PathSet lib_paths; 88 | 89 | /** 90 | * 需要链接的C库目录 91 | */ 92 | PathSet link_paths; 93 | 94 | }; 95 | 96 | 97 | 98 | #endif // BUILDER_H 99 | -------------------------------------------------------------------------------- /Builder/include/PathGetter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-08 11:08:05 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-25 10:24:59 6 | */ 7 | 8 | #ifndef PATH_GETTER_H 9 | #define PATH_GETTER_H 10 | 11 | #include 12 | using namespace std; 13 | 14 | class PathGetter_Private; 15 | 16 | /** 17 | * @brief 路径获取类, 可以获取环境变量, 工具链的路径等 18 | */ 19 | class PathGetter 20 | { 21 | public: 22 | static const char* getEliteHome(); 23 | static const char* getEliteLibPath(); 24 | static const char* getEliteCfgPath(); 25 | static const char* getEliteToolsPath(); 26 | static const char* getElitePackagesPath(); 27 | static const char* getDefaultLexCfg(); 28 | static const char* getDefaultParserCfg(); 29 | static const char* getNowPath(); 30 | static bool testFile(const char* file); 31 | static PathGetter_Private* getInstance(); 32 | private: 33 | PathGetter(); 34 | ~PathGetter(); 35 | static PathGetter_Private* instance; 36 | }; 37 | 38 | 39 | 40 | #endif // PATH_GETTER_H 41 | -------------------------------------------------------------------------------- /Builder/include/PathSet.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-08 09:17:30 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-22 08:23:22 6 | */ 7 | 8 | #ifndef PATH_SET_H 9 | #define PATH_SET_H 10 | 11 | #include 12 | #include 13 | 14 | class PathSet_private; 15 | 16 | /** 17 | * @brief 搜索路径集合 18 | */ 19 | class PathSet 20 | { 21 | public: 22 | PathSet(); 23 | ~PathSet(); 24 | 25 | /** 26 | * 添加一个路径 27 | * @method AddPath 28 | * @param path 要添加的目录(绝对路径) 29 | */ 30 | void AddPath(const std::string& path); 31 | 32 | /** 33 | * 查找一个文件在该路径集合中的位置 34 | * @method FindFile 35 | * @param filename 文件名 36 | * @return 第一个找到的文件的绝对路径 37 | */ 38 | std::string FindFile(const std::string& filename); 39 | 40 | /** 41 | * 查找一个包的全部位置 42 | * @method FindPackage 43 | * @param package 包名 44 | * @return 返回全部找到的包的绝对路径 45 | */ 46 | std::vector FindPackage(const std::string& package); 47 | 48 | /** 49 | * 查找目录中全部的包 50 | * @method FindAllPackageName 51 | * @return 返回全部找到的包的名字 52 | */ 53 | std::vector FindAllPackageName(); 54 | 55 | const std::vector& getPaths() { return paths; } 56 | protected: 57 | std::vector paths; 58 | PathSet_private* priv; 59 | }; 60 | 61 | 62 | #endif // PATH_SET_H 63 | -------------------------------------------------------------------------------- /Builder/include/Worker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-11 13:52:11 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 15:35:30 6 | */ 7 | #ifndef WORKER_H 8 | #define WORKER_H 9 | 10 | class LexInterface; 11 | class Parser; 12 | class ScriptRunner; 13 | class CodeGen; 14 | class Builder; 15 | class Node; 16 | /** 17 | * @brief 工作流类, 是词法分析器, 语法分析器, 元脚本解析器, 后端代码生成器整合后的工作流 18 | */ 19 | class Worker 20 | { 21 | public: 22 | void Init(LexInterface* l, Parser* p, ScriptRunner* s, CodeGen* c); 23 | void Run(const char* input, const char* output); 24 | void MetaGen(const char* output); 25 | Node* MakeAST(const char* input); 26 | 27 | static Worker* CreateDefault(const char* lex_cfg, const char* parser_cfg, const char* package_path, Builder* b); 28 | static Worker* Create(LexInterface* l, Parser* p, ScriptRunner* s, CodeGen* c, Builder* b); 29 | 30 | LexInterface* getLex() { return lex; } 31 | Parser* getParser() { return parser; } 32 | ScriptRunner* getScriptRunner() { return script_runner; } 33 | CodeGen* getCodegen() { return codegen; } 34 | Builder* getBuilder() { return builder; } 35 | 36 | Worker(); 37 | ~Worker(); 38 | protected: 39 | LexInterface* lex; 40 | Parser* parser; 41 | ScriptRunner* script_runner; 42 | CodeGen* codegen; 43 | Builder* builder; 44 | }; 45 | 46 | 47 | 48 | #endif // WORKER_H 49 | -------------------------------------------------------------------------------- /Builder/src/CmdUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-12 12:53:36 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-12 13:46:41 6 | */ 7 | 8 | #ifndef CMD_UTILS_H 9 | #define CMD_UTILS_H 10 | 11 | class CmdUtils 12 | { 13 | public: 14 | 15 | }; 16 | 17 | 18 | #endif // CMD_UTILS_H 19 | -------------------------------------------------------------------------------- /Builder/src/Importer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-08 09:02:23 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-08 09:06:23 6 | */ 7 | 8 | 9 | #ifndef IMPORTER_H 10 | #define IMPORTER_H 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | /** 17 | * @brief 包导入器 18 | */ 19 | 20 | class Importer 21 | { 22 | public: 23 | Importer(); 24 | ~Importer(); 25 | 26 | int import(string& name); 27 | }; 28 | 29 | 30 | 31 | #endif // IMPORTER_H 32 | -------------------------------------------------------------------------------- /Builder/src/PackageChanger.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PACKAGE_CHANGER_H 2 | #define PACKAGE_CHANGER_H 3 | 4 | #include 5 | 6 | class PackageChanger { 7 | public: 8 | static std::string pname2path(const std::string& name) { 9 | std::string str = name; 10 | for (auto& i : str) { 11 | if (i == '.') i = '/'; 12 | } 13 | return str; 14 | } 15 | 16 | static std::string path2pname(const std::string& path) { 17 | std::string str = path; 18 | if (*(str.begin()) == '/') str.erase(str.begin()); 19 | if (*(str.rbegin()) == '/') str.erase(--str.end()); 20 | for (auto& i : str) { 21 | if (i == '/') i = '.'; 22 | } 23 | return str; 24 | } 25 | }; 26 | 27 | 28 | 29 | #endif /* end of include guard: PACKAGE_CHANGER_H */ 30 | -------------------------------------------------------------------------------- /Builder/src/PathSet.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-12 10:11:38 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-12 10:11:45 6 | */ 7 | 8 | #include "PathSet.h" 9 | #include "PathUtils.h" 10 | #include "FileUtils.h" 11 | #include "PackageChanger.hpp" 12 | 13 | #include 14 | #include 15 | using namespace std; 16 | 17 | class file_searcher : public IFileTraversal { 18 | public: 19 | file_searcher(const string& name) { 20 | file = name; 21 | } 22 | 23 | virtual void Work(const string& now_path, 24 | const string& filename, 25 | const string& suffix) { 26 | 27 | if (file == filename && ans.empty()) { 28 | ans = now_path + "/" + file; 29 | } 30 | } 31 | string ans; 32 | private: 33 | string file; 34 | }; 35 | 36 | class package_finder : public IFileTraversal { 37 | public: 38 | package_finder(const string& base_path, set& ps) 39 | : packages(ps) { 40 | basepath = base_path; 41 | } 42 | virtual void Work(const string& now_path, 43 | const string& filename, 44 | const string& suffix) { 45 | string s = now_path.substr(basepath.length()); 46 | packages.insert(s); 47 | } 48 | set& packages; 49 | string basepath; 50 | }; 51 | 52 | 53 | PathSet::PathSet() { 54 | 55 | } 56 | 57 | PathSet::~PathSet() { 58 | 59 | } 60 | 61 | 62 | void PathSet::AddPath(const std::string& path) { 63 | paths.push_back(path); 64 | } 65 | 66 | std::string PathSet::FindFile(const std::string& filename) { 67 | file_searcher fs(filename); 68 | for (auto& item : paths) { 69 | FileUtils::dir_traversal(item, fs, FileUtils::only_file); 70 | if (fs.ans.empty() == false) return fs.ans; 71 | } 72 | return string(); 73 | } 74 | 75 | std::vector PathSet::FindPackage(const std::string& package) { 76 | std::vector package_list; 77 | string path = PackageChanger::pname2path(package); 78 | for (auto& item : paths) { 79 | string p = item + "/" + path; 80 | p = PathUtils::native(p); 81 | if (FileUtils::test_dir(p)) { 82 | package_list.push_back(p); 83 | } 84 | } 85 | return package_list; 86 | } 87 | 88 | 89 | std::vector PathSet::FindAllPackageName() { 90 | set packages; 91 | for (string& item : paths) { 92 | package_finder pf(item, packages); 93 | FileUtils::dir_recursive_traversal(item, pf, FileUtils::only_dir); 94 | } 95 | vector v(packages.begin(), packages.end()); 96 | return v; 97 | } 98 | -------------------------------------------------------------------------------- /Builder/src/Worker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-11 16:00:38 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 15:36:14 6 | */ 7 | 8 | 9 | #include "Worker.h" 10 | #include "Lex.h" 11 | #include "Parser.h" 12 | #include "RedCodeGen.h" 13 | #include "MetaScriptRunner.h" 14 | #include "Grammer_Node.h" 15 | #include 16 | 17 | 18 | void Worker::Init(LexInterface* l, Parser* p, ScriptRunner* s, CodeGen* c) { 19 | lex = l; parser = p; script_runner = s; codegen = c; 20 | 21 | // 初始化词法分析器与语法分析器 22 | l->Init(NULL); 23 | p->BuildParser(); 24 | 25 | } 26 | 27 | void Worker::Run(const char* input, const char* output) { 28 | Node* node = MakeAST(input); 29 | codegen->PreScan(node); 30 | codegen->Make(node, output, ""); 31 | } 32 | 33 | Node* Worker::MakeAST(const char* input) { 34 | lex->setData(input); 35 | Grammer_Node* root = Grammer_Node::NewNode(); 36 | int err = parser->Parse(root); 37 | if (err) exit(1); 38 | Node* node = script_runner->getRoot(); 39 | if (node == NULL) { 40 | printf("分析器异常,返回为NULL\n"); 41 | exit(1); 42 | } 43 | node->print(0); 44 | return node; 45 | } 46 | 47 | void Worker::MetaGen(const char* output) { 48 | codegen->MakeMeta(output, "Meta"); 49 | } 50 | 51 | 52 | Worker* Worker::CreateDefault(const char* lex_cfg, 53 | const char* parser_cfg, const char* package_path, Builder* b) { 54 | Lex* l = new Lex(); 55 | Parser* p = Parser::NewLRParser(); 56 | MetaScriptRunner* s = MetaScriptRunner::Create(); 57 | RedCodeGen* c = RedCodeGen::Create(); 58 | 59 | // 配置联系 60 | p->setLex(l); 61 | p->setScriptRunner(s); 62 | 63 | // 向脚本引擎中注入更多接口 64 | c->Init(); 65 | s->setCodeGenContext(c->getContext()); 66 | 67 | // 向脚本引擎中注入各对象 68 | s->setLex(l); 69 | s->setParser(p); 70 | s->setBuilder(b); 71 | 72 | // 配置外置插件 73 | s->setUpLoader(package_path); 74 | 75 | // 配置词法分析器和语法分析器 76 | l->ReadConfig(lex_cfg); 77 | p->AddBNF(parser_cfg); 78 | 79 | printf("Create Default\n"); 80 | 81 | return Create(l, p, s, c, b); 82 | } 83 | 84 | Worker* Worker::Create(LexInterface* l, Parser* p, ScriptRunner* s, CodeGen* c, Builder* b) { 85 | Worker* k = new Worker(); 86 | k->builder = b; 87 | k->Init(l, p, s, c); 88 | return k; 89 | } 90 | 91 | Worker::Worker() { 92 | 93 | } 94 | 95 | Worker::~Worker() { 96 | 97 | } 98 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(Elite) 3 | 4 | SET(VERSION_MAJOR "0") 5 | SET(VERSION_MINOR "9") 6 | SET(VERSION_PATCH "2") 7 | 8 | SET (CMAKE_BUILD_TYPE Debug) # 默认构建Debug模式 9 | 10 | if(UNIX) 11 | include(cmake/UnixLLVM.cmake) # 使用LLVM的CMake自动寻找功能 12 | # include(cmake/UnixGlib.cmake) # 使用Pkg-Config寻找Glibmm 不再依赖Glibmm 13 | include(cmake/ClangConf.cmake) # 使用clang编译 14 | elseif(WIN32) 15 | set(LLVM_SDK_PATH "C:/program files(x86)/LLVM" CACHE PATH "PATH TO LLVM") 16 | set(LLVM_VERSION 3.6 CACHE STRING "LLVM version to use default 3.6") 17 | include(cmake/MSVCConf.cmake) # 使用MSVC编译 18 | #set (LLVM_SDK_PATH D:\\LLVM) 19 | include(cmake/WindowsLLVM.cmake) # 寻找LLVM 20 | endif() 21 | 22 | ## 配置输出目录 23 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin ) 24 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib ) 25 | set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib ) 26 | 27 | ## include路径配置 28 | include_directories(src extlib/include 29 | Lex/include 30 | LR_Scanner/includes 31 | RedApple/includes 32 | Builder/include 33 | MetaScriptRunner/include 34 | ExIconv/include 35 | ) 36 | 37 | 38 | ## 链接目录 39 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/extlib/lib) 40 | 41 | OPTION(BUILD_ALL "构建全部项目 / Build all component together." ON) 42 | OPTION(USE_DYNAMIC "使用动态库 / Build with dynamic libraries." OFF) 43 | 44 | add_subdirectory(ExIconv) 45 | add_subdirectory(Lex) 46 | add_subdirectory(LR_Scanner) 47 | add_subdirectory(RedApple) 48 | add_subdirectory(MetaScriptRunner) 49 | add_subdirectory(Builder) 50 | 51 | set_target_properties( runtime 52 | PROPERTIES 53 | ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/runtime" 54 | LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/runtime" 55 | RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/runtime" 56 | ) 57 | 58 | 59 | 60 | file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 61 | add_executable(elite ${source_files}) 62 | 63 | 64 | if(UNIX) 65 | set (dl_lib_link dl) 66 | endif() 67 | 68 | if (CMAKE_BUILD_TYPE EQUAL "Debug") 69 | set (oolua_lib oolua_d) 70 | else() 71 | set (oolua_lib oolua) 72 | endif() 73 | 74 | 75 | target_link_libraries(elite builder meta red scanner lex ${oolua_lib} lua exiconv iconv charsetdetect charset 76 | ${LLVM_LIBS} ${dl_lib_link}) 77 | 78 | 79 | 80 | 81 | ## 合并Headers 82 | include(cmake/CombineHeader.cmake) 83 | 84 | ## 下载第三方库 85 | include(cmake/ThirdPartyBuild.cmake) 86 | 87 | add_subdirectory(doc) 88 | 89 | include(cmake/Install.cmake) 90 | -------------------------------------------------------------------------------- /EliteTest/bug_list/10/TODO: -------------------------------------------------------------------------------- 1 | 需要修复错误情况下llvm字节码的输出 2 | -------------------------------------------------------------------------------- /EliteTest/bug_list/10/test.elite: -------------------------------------------------------------------------------- 1 | // 八皇后问题 2 | 3 | int sum = 0; 4 | int upperlim = 1; 5 | 6 | // 试探算法从最右边的列开始。 7 | void test(int row, int ld, int rd) 8 | { 9 | if (row != upperlim) 10 | { 11 | // row,ld,rd进行“或”运算,求得所有可以放置皇后的列,对应位为0, 12 | // 然后再取反后“与”上全1的数,来求得当前所有可以放置皇后的位置,对应列改为1 13 | // 也就是求取当前哪些列可以放置皇后 14 | int pos = upperlim & ~(row | ld | rd); 15 | while (pos != 0) // 0 -- 皇后没有地方可放,回溯 16 | { 17 | // 拷贝pos最右边为1的bit,其余bit置0 18 | // 也就是取得可以放皇后的最右边的列 19 | int p = pos & -pos; 20 | 21 | // 将pos最右边为1的bit清零 22 | // 也就是为获取下一次的最右可用列使用做准备, 23 | // 程序将来会回溯到这个位置继续试探 24 | pos -= p; 25 | 26 | // row + p,将当前列置1,表示记录这次皇后放置的列。 27 | // (ld + p) << 1,标记当前皇后左边相邻的列不允许下一个皇后放置。 28 | // (ld + p) >> 1,标记当前皇后右边相邻的列不允许下一个皇后放置。 29 | // 此处的移位操作实际上是记录对角线上的限制,只是因为问题都化归 30 | // 到一行网格上来解决,所以表示为列的限制就可以了。显然,随着移位 31 | // 在每次选择列之前进行,原来N×N网格中某个已放置的皇后针对其对角线 32 | // 上产生的限制都被记录下来了 33 | test(row + p, (ld + p) << 1, (rd + p) >> 1); 34 | } 35 | } 36 | else 37 | { 38 | // row的所有位都为1,即找到了一个成功的布局,回溯 39 | sum++; 40 | } 41 | } 42 | 43 | int main() 44 | { 45 | int n = 8; 46 | upperlim = (upperlim << n) - 1; 47 | test(0, 0, 0); 48 | printf("共有%ld种排列\\n", sum); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /EliteTest/bug_list/10/test.out: -------------------------------------------------------------------------------- 1 | 92 2 | -------------------------------------------------------------------------------- /EliteTest/bug_list/11/src/com/hha/test.elite: -------------------------------------------------------------------------------- 1 | 2 | void hello(int k, int g) { 3 | int y = add(k, g); 4 | printf("%d\n", y); 5 | if (k + g < 5) printf("right\n"); 6 | } 7 | 8 | 9 | void go(int k) { 10 | int a = 0; 11 | while (a < k) { 12 | printf("go-%d\n", a); 13 | a = a + 1; 14 | } 15 | } 16 | 17 | void print(int k) { 18 | for (int i = 0; i < 10; i = i+1) { 19 | printf("hello-%d\n",i); 20 | } 21 | } 22 | 23 | 24 | int main() { 25 | printf("hello world\n"); 26 | hello(1,2); 27 | print(9); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /EliteTest/bug_list/11/src/com/hha/work.elite: -------------------------------------------------------------------------------- 1 | 2 | 3 | int add(int a, int b) { 4 | return a + b; 5 | } 6 | -------------------------------------------------------------------------------- /EliteTest/bug_list/11/test.out: -------------------------------------------------------------------------------- 1 | hello world 2 | 3 3 | right 4 | hello-0 5 | hello-1 6 | hello-2 7 | hello-3 8 | hello-4 9 | hello-5 10 | hello-6 11 | hello-7 12 | hello-8 13 | hello-9 -------------------------------------------------------------------------------- /EliteTest/bug_list/9/TODO.md: -------------------------------------------------------------------------------- 1 | break语句暂未实现 2 | -------------------------------------------------------------------------------- /EliteTest/bug_list/9/test.elite: -------------------------------------------------------------------------------- 1 | // 质因数分解 2 | 3 | int main(){ 4 | int n = 90; 5 | printf("%d=", n); 6 | // n>=2才执行下面的循环 7 | for(int i = 2; i <=n ; i++){ 8 | while(n != i){ 9 | if(n % i == 0){ 10 | printf("%d*", i); 11 | n = n / i; 12 | }else 13 | break; 14 | } 15 | } 16 | printf("%d\n", n); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /EliteTest/bug_list/9/test.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/EliteTest/bug_list/9/test.out -------------------------------------------------------------------------------- /EliteTest/bug_list/run_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Author: sxf 4 | # @Date: 2015-12-20 18:37:22 5 | # @Last Modified by: sxf 6 | # @Last Modified time: 2015-12-21 20:57:38 7 | 8 | import os, sys 9 | import commands 10 | 11 | class TestRunner: 12 | def __init__(self): 13 | self.compile_error = [] 14 | self.run_error = [] 15 | self.output_error = [] 16 | 17 | def walk_dir(self, path): 18 | for line in os.listdir(path): 19 | filepath = os.path.join(path,line) 20 | if os.path.isdir(filepath): 21 | print filepath 22 | ret = self.compile_path(filepath) 23 | if ret != 0: 24 | break 25 | ret = self.run_file(filepath+'/build/test', filepath+'/test.out') 26 | if ret != 0: 27 | break 28 | 29 | 30 | def compile_path(self, path): 31 | cmd = self.bin_path + ' -i ' + path + '/test.elite -d ' + path + '/build/' 32 | status, output = commands.getstatusoutput(cmd) 33 | if status != 0: 34 | print '\033[1;31m' 35 | print '编译失败:', path 36 | print output 37 | print '\033[0m' 38 | self.compile_error.append(path) 39 | return status 40 | 41 | def run_file(self, filepath, output_file): 42 | status, output = commands.getstatusoutput(filepath) 43 | if status != 0: 44 | print '\033[1;31m' 45 | print '运行失败:', filepath 46 | print 'status:', status 47 | print output 48 | print '\033[0m' 49 | self.run_error.append(filepath) 50 | return status 51 | read_data = '' 52 | with open(output_file, 'rU') as f: 53 | read_data = f.read() 54 | if read_data != output: 55 | print '\033[1;31m' 56 | print '执行结果错误:', filepath 57 | print output 58 | print '\033[0m' 59 | self.output_error.append(filepath) 60 | return 1 61 | return 0 62 | 63 | def main(self): 64 | print "测试开始" 65 | self.now_path = os.path.split(os.path.realpath(__file__))[0] 66 | self.bin_path = os.path.normpath(os.path.join(self.now_path, '..', '..', 'bin', 'elite')) 67 | self.elite_path = os.path.normpath(os.path.join(self.now_path, '..', '..')) 68 | print '\033[1;32m' 69 | print "now_path:", self.now_path 70 | print "bin_path:", self.bin_path 71 | print "elite_path:", self.elite_path 72 | print '\033[0m' 73 | os.environ['ELITE_HOME'] = self.elite_path # 设置临时环境变量 74 | self.walk_dir(self.now_path) 75 | return 76 | 77 | if __name__ == '__main__': 78 | tr = TestRunner() 79 | tr.main() 80 | -------------------------------------------------------------------------------- /EliteTest/full_test/1/test.elite: -------------------------------------------------------------------------------- 1 | 2 | void hello() { 3 | printf("hello world"); 4 | } 5 | 6 | int main() { 7 | hello(); 8 | return 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /EliteTest/full_test/1/test.out: -------------------------------------------------------------------------------- 1 | hello world -------------------------------------------------------------------------------- /EliteTest/full_test/2/test.elite: -------------------------------------------------------------------------------- 1 | 2 | void hello(int k, int g) { 3 | int y = k + g; 4 | printf("%d\n", y); 5 | if (k + g < 5) printf("right\n"); 6 | } 7 | 8 | 9 | void go(int k) { 10 | int a = 0; 11 | while (a < k) { 12 | printf("go-%d\n", a); 13 | a = a + 1; 14 | } 15 | } 16 | 17 | void print(int k) { 18 | for (int i = 0; i < 10; i = i+1) { 19 | printf("hello-%d\n",i); 20 | } 21 | } 22 | 23 | 24 | int main() { 25 | printf("hello world\n"); 26 | hello(1,2); 27 | print(9); 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /EliteTest/full_test/2/test.out: -------------------------------------------------------------------------------- 1 | hello world 2 | 3 3 | right 4 | hello-0 5 | hello-1 6 | hello-2 7 | hello-3 8 | hello-4 9 | hello-5 10 | hello-6 11 | hello-7 12 | hello-8 13 | hello-9 -------------------------------------------------------------------------------- /EliteTest/full_test/3/test.elite: -------------------------------------------------------------------------------- 1 | 2 | 3 | int main() { 4 | pair a = new pair(); 5 | pair b = new pair(); 6 | a.x = 1; a.y = 0; 7 | b.x = 2; b.y = 10; 8 | printf("a.x = %d ", a.x); 9 | printf("a.y = %d\n", a.y); 10 | printf("b.x = %d ", b.x); 11 | printf("b.y = %d\n", b.y); 12 | printf("ans = %d\n", dot(a,b)); 13 | return 0; 14 | } 15 | 16 | 17 | int dot(pair a, pair b) { 18 | int k = a.x + b.y; 19 | printf("k = %d\n", k); 20 | return k; 21 | } 22 | 23 | struct pair { 24 | int x; 25 | int y; 26 | } 27 | -------------------------------------------------------------------------------- /EliteTest/full_test/3/test.out: -------------------------------------------------------------------------------- 1 | a.x = 1 a.y = 0 2 | b.x = 2 b.y = 10 3 | k = 11 4 | ans = 11 -------------------------------------------------------------------------------- /EliteTest/full_test/4/test.elite: -------------------------------------------------------------------------------- 1 | 2 | void print(int k) { 3 | @for_n (i, k) { 4 | printf("hello-%d\n", i); 5 | } 6 | } 7 | 8 | defmacro for_n (p, size, code) { 9 | for (int p = 1; p <= size; p = p+1) 10 | code; 11 | } 12 | 13 | int main() { 14 | print(5); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /EliteTest/full_test/4/test.out: -------------------------------------------------------------------------------- 1 | hello-1 2 | hello-2 3 | hello-3 4 | hello-4 5 | hello-5 -------------------------------------------------------------------------------- /EliteTest/full_test/5/test.elite: -------------------------------------------------------------------------------- 1 | `(function !void hello ((set !int k)) ( 2 | (call printf "hello world %d\n" k) 3 | )) 4 | 5 | int main() { 6 | int k = 0; 7 | int[] g = new int[10]; 8 | g[0] = 1; 9 | for (int i = 0; i < 10; ++i) { 10 | g[i] = ++k; 11 | hello(g[i]); 12 | } 13 | printf("hello"); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /EliteTest/full_test/5/test.out: -------------------------------------------------------------------------------- 1 | hello world 1 2 | hello world 2 3 | hello world 3 4 | hello world 4 5 | hello world 5 6 | hello world 6 7 | hello world 7 8 | hello world 8 9 | hello world 9 10 | hello world 10 11 | hello -------------------------------------------------------------------------------- /EliteTest/full_test/6/test.elite: -------------------------------------------------------------------------------- 1 | 2 | void print(int k) { 3 | printf("hello-%d\n",k); 4 | } 5 | 6 | int main() { 7 | FunctionCall("print", 5); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /EliteTest/full_test/6/test.out: -------------------------------------------------------------------------------- 1 | hello-5 -------------------------------------------------------------------------------- /EliteTest/full_test/7/test.elite: -------------------------------------------------------------------------------- 1 | // 这是一道经典的汉诺塔 2 | 3 | void work(int k, int src, int obj) { 4 | if (k==1) { 5 | print(src, obj); 6 | return; 7 | } 8 | work(k - 1, src, 3 - obj - src); 9 | print(src, obj); 10 | work(k - 1, 3 - obj - src, obj); 11 | } 12 | 13 | int main() { 14 | work(3, 0, 2); 15 | return 0; 16 | } 17 | 18 | char[] select(int k) { 19 | if (k == 0) return "A"; 20 | if (k == 1) return "B"; 21 | if (k == 2) return "C"; 22 | return ""; 23 | } 24 | 25 | void print(int src, int obj) { 26 | printf("%s => %s\n", select(src), select(obj)); 27 | } 28 | -------------------------------------------------------------------------------- /EliteTest/full_test/7/test.out: -------------------------------------------------------------------------------- 1 | A => C 2 | A => B 3 | C => B 4 | A => C 5 | B => A 6 | B => C 7 | A => C -------------------------------------------------------------------------------- /EliteTest/full_test/8/test.elite: -------------------------------------------------------------------------------- 1 | // 测试可能有歧义的符号 2 | 3 | int main() { 4 | int x = 10; 5 | if (x == 10) { 6 | int x = 20; 7 | if (x == 20) 8 | printf("1"); 9 | else 10 | printf("0"); 11 | } 12 | if (x == 10) 13 | printf("1"); 14 | else 15 | printf("0"); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /EliteTest/full_test/8/test.out: -------------------------------------------------------------------------------- 1 | 11 -------------------------------------------------------------------------------- /EliteTest/full_test/run_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # @Author: sxf 4 | # @Date: 2015-12-20 18:37:22 5 | # @Last Modified by: sxf 6 | # @Last Modified time: 2015-12-21 20:57:38 7 | 8 | import os, sys 9 | import commands 10 | 11 | class TestRunner: 12 | def __init__(self): 13 | self.compile_error = [] 14 | self.run_error = [] 15 | self.output_error = [] 16 | 17 | def walk_dir(self, path): 18 | for line in os.listdir(path): 19 | filepath = os.path.join(path,line) 20 | if os.path.isdir(filepath): 21 | print filepath 22 | ret = self.compile_path(filepath) 23 | if ret != 0: 24 | sys.exit(1) 25 | ret = self.run_file(filepath+'/build/test', filepath+'/test.out') 26 | if ret != 0: 27 | sys.exit(1) 28 | 29 | 30 | def compile_path(self, path): 31 | cmd = self.bin_path + ' -i ' + path + '/test.elite -d ' + path + '/build/' 32 | status, output = commands.getstatusoutput(cmd) 33 | if status != 0: 34 | print '\033[1;31m' 35 | print '编译失败:', path 36 | print output 37 | print '\033[0m' 38 | self.compile_error.append(path) 39 | return status 40 | 41 | def run_file(self, filepath, output_file): 42 | status, output = commands.getstatusoutput(filepath) 43 | if status != 0: 44 | print '\033[1;31m' 45 | print '运行失败:', filepath 46 | print 'status:', status 47 | print output 48 | print '\033[0m' 49 | self.run_error.append(filepath) 50 | return status 51 | read_data = '' 52 | with open(output_file, 'rU') as f: 53 | read_data = f.read() 54 | if read_data != output: 55 | print '\033[1;31m' 56 | print '执行结果错误:', filepath 57 | print output 58 | print '\033[0m' 59 | self.output_error.append(filepath) 60 | return 1 61 | return 0 62 | 63 | def main(self): 64 | print "测试开始" 65 | self.now_path = os.path.split(os.path.realpath(__file__))[0] 66 | self.bin_path = os.path.normpath(os.path.join(self.now_path, '..', '..', 'bin', 'elite')) 67 | self.elite_path = os.path.normpath(os.path.join(self.now_path, '..', '..')) 68 | print '\033[1;32m' 69 | print "now_path:", self.now_path 70 | print "bin_path:", self.bin_path 71 | print "elite_path:", self.elite_path 72 | print '\033[0m' 73 | os.environ['ELITE_HOME'] = self.elite_path # 设置临时环境变量 74 | self.walk_dir(self.now_path) 75 | return 76 | 77 | if __name__ == '__main__': 78 | tr = TestRunner() 79 | tr.main() -------------------------------------------------------------------------------- /ExIconv/.gitignore: -------------------------------------------------------------------------------- 1 | *.*~ 2 | .fuse* 3 | *.sublime-* 4 | bin/ 5 | build/ 6 | libcharsetdetect/ 7 | libiconv-1.14/ 8 | 9 | -------------------------------------------------------------------------------- /ExIconv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(ExIconv) 3 | 4 | if(NOT BUILD_ALL) 5 | include(../cmake/UnixLLVM.cmake) 6 | SET (CMAKE_CXX_COMPILER_ENV_VAR "clang++") 7 | SET (CMAKE_CXX_FLAGS "-std=c++11") 8 | SET (CMAKE_CXX_FLAGS_DEBUG "-g") 9 | SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 10 | SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG") 11 | SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") 12 | SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) 13 | 14 | include_directories(../extlib/include) 15 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../extlib/lib) 16 | 17 | endif() 18 | 19 | 20 | include_directories(src include) 21 | 22 | file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 23 | 24 | add_library(exiconv STATIC ${source_files}) 25 | target_link_libraries(exiconv iconv charsetdetect) 26 | 27 | install(TARGETS exiconv ARCHIVE DESTINATION lib) 28 | 29 | 30 | if(BUILD_TEST) 31 | add_subdirectory(test) 32 | endif() 33 | -------------------------------------------------------------------------------- /ExIconv/Doxyfile.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "@CMAKE_PROJECT_NAME@" 2 | PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ 3 | STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ \ 4 | @PROJECT_BINARY_DIR@ 5 | INPUT = @doxy_main_page@ \ 6 | @PROJECT_SOURCE_DIR@ \ 7 | @PROJECT_BINARY_DIR@ 8 | FILE_PATTERNS = *.h \ 9 | *.c 10 | OUTPUT_LANGUAGE = Chinese 11 | RECURSIVE = YES 12 | EXTRACT_ALL = YES 13 | EXTRACT_PRIVATE = YES 14 | EXTRACT_STATIC = YES 15 | EXCLUDE_PATTERNS = */thirdparty/* 16 | USE_MDFILE_AS_MAINPAGE = @doxy_main_page@ 17 | -------------------------------------------------------------------------------- /ExIconv/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # @Author: sxf 3 | # @Date: 2015-11-03 08:33:43 4 | # @Last Modified by: sxf 5 | # @Last Modified time: 2015-11-03 08:34:18 6 | 7 | mkdir ./build 8 | cd ./build 9 | cmake .. 10 | make 11 | cd .. -------------------------------------------------------------------------------- /ExIconv/include/DebugMsg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-21 20:35:05 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-22 15:54:44 6 | */ 7 | 8 | 9 | #ifndef DEBUG_MSG_H 10 | #define DEBUG_MSG_H 11 | 12 | #include 13 | using namespace std; 14 | 15 | class DebugMsg_Private; 16 | 17 | /** 18 | * @brief debug信息单例类 19 | */ 20 | class DebugMsg 21 | { 22 | public: 23 | /** 24 | * @brief 设置解释器生成中间变量的目录,设置后自动打印中间过程 25 | * 26 | * @param path 设置路径,设置为NULL或不设置则不打印过程 27 | */ 28 | static void setDebugFilePath(const char* path); 29 | 30 | /** 31 | * @brief 判断是否Debug模式 32 | */ 33 | static bool isDebug(); 34 | 35 | /** 36 | * @brief 获取词法分析器的debug文件输出流 37 | */ 38 | static std::ostream& lex_dbg(); 39 | static void lex_close(); 40 | 41 | static std::ostream& lex_save(); 42 | static void lex_save_close(); 43 | /** 44 | * @brief 获取解析器的debug输出文件流 45 | */ 46 | static std::ostream& parser_dbg(); 47 | static void parser_close(); 48 | 49 | static std::ostream& parser_save(); 50 | static void parser_save_close(); 51 | 52 | /** 53 | * @brief 获取解析器的debug输出文件流 54 | */ 55 | static std::ostream& red_dbg(); 56 | static void red_close(); 57 | 58 | static std::ostream& red_llvm_bc(); 59 | static void red_llvm_bc_close(); 60 | 61 | static std::ostream& lex_graphviz(); 62 | static void lex_graphviz_close(); 63 | 64 | static std::ostream& parser_graphviz(); 65 | static void parser_graphviz_close(); 66 | 67 | static DebugMsg_Private* getInstance(); 68 | private: 69 | static DebugMsg_Private* instance; 70 | }; 71 | 72 | 73 | 74 | #endif // DEBUG_MSG_H 75 | -------------------------------------------------------------------------------- /ExIconv/include/DebugMsg_Simple.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUG_MES_SIMPLE 2 | #define DEBUG_MES_SIMPLE 3 | 4 | #include "DebugMsg.h" 5 | #include 6 | 7 | class DebugMsg_Private { 8 | public: 9 | string dbg_file_path; 10 | bool is_debug_mode; 11 | }; 12 | 13 | void DebugMsg::setDebugFilePath(const char* path) { 14 | getInstance()->is_debug_mode = true; 15 | } 16 | 17 | bool DebugMsg::isDebug() { 18 | return getInstance()->is_debug_mode; 19 | } 20 | 21 | std::ostream& DebugMsg::lex_dbg() { 22 | return std::cout; 23 | } 24 | 25 | void DebugMsg::lex_close() { 26 | } 27 | 28 | std::ostream& DebugMsg::parser_dbg() { 29 | return std::cout; 30 | } 31 | 32 | void DebugMsg::parser_close() { 33 | } 34 | 35 | std::ostream& DebugMsg::red_dbg() { 36 | return std::cout; 37 | } 38 | 39 | void DebugMsg::red_close() { 40 | } 41 | 42 | 43 | DebugMsg_Private* DebugMsg::getInstance() { 44 | if (instance == NULL) 45 | instance = new DebugMsg_Private(); 46 | return instance; 47 | } 48 | 49 | DebugMsg_Private* DebugMsg::instance = NULL; 50 | 51 | 52 | 53 | #endif /* end of include guard: DEBUG_MES_SIMPLE */ 54 | -------------------------------------------------------------------------------- /ExIconv/include/FileUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-11 18:42:32 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-25 14:34:02 6 | */ 7 | 8 | 9 | #ifndef FILE_UTILS_H 10 | #define FILE_UTILS_H 11 | 12 | #include 13 | 14 | /** 15 | * @brief 文件遍历的接口 16 | */ 17 | class IFileTraversal { 18 | public: 19 | virtual void Work(const std::string& now_path, 20 | const std::string& filename, 21 | const std::string& suffix) = 0; 22 | }; 23 | 24 | /** 25 | * @brief 跨平台的文件系统接口 26 | */ 27 | class FileUtils 28 | { 29 | public: 30 | static int create_directory(const std::string& path, bool IgnoreExisting=true); 31 | static int create_directories(const std::string& path, bool IgnoreExisting=true); 32 | static bool isNeedUpdate(const std::string& cfg_path, const std::string& save_path); 33 | static bool test_dir(const std::string& path); 34 | static bool test_file(const std::string& path); 35 | static std::string get_current_path(); 36 | static std::string fileReader(const char* path); 37 | 38 | enum traversal_type { 39 | all, only_file, only_dir 40 | }; 41 | 42 | static int dir_traversal(const std::string& path, IFileTraversal& ifile, traversal_type t); 43 | static int dir_recursive_traversal(const std::string& path, IFileTraversal& ifile, traversal_type t); 44 | }; 45 | 46 | 47 | 48 | #endif // FILE_UTILS_H 49 | -------------------------------------------------------------------------------- /ExIconv/include/PathUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-20 11:38:17 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-20 11:58:04 6 | */ 7 | 8 | 9 | #ifndef PATH_UTILS_H 10 | #define PATH_UTILS_H 11 | 12 | #include 13 | 14 | /** 15 | * @brief 跨平台的路径拼接工具类 16 | */ 17 | class PathUtils 18 | { 19 | public: 20 | static std::string native(const std::string& path); 21 | static std::string parent_path(const std::string& path); 22 | }; 23 | 24 | 25 | #endif // PATH_UTILS_H 26 | -------------------------------------------------------------------------------- /ExIconv/include/estring.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-15 09:43:18 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 22:33:12 6 | */ 7 | #ifndef ESTRING_H 8 | #define ESTRING_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | typedef uint16_t echar_t; 17 | 18 | /** 19 | * @brief 内部使用utf16LE编码的字符串类, 能够实现编码的字符识别和转换 20 | */ 21 | class estring 22 | { 23 | public: 24 | typedef std::basic_string::iterator iterator; 25 | 26 | estring(); 27 | estring(const std::string& str); 28 | estring(const estring& estr); 29 | estring(const char* cstr); 30 | estring(const echar_t* ecstr); 31 | ~estring(); 32 | 33 | void autoreadfile(const std::string& path); 34 | void autoreadstr(const std::string& str); 35 | void readfile(const std::string& path, const std::string& encode); 36 | void readstr (const std::string& str, const std::string& encode); 37 | void readstr (const char* data, const std::string& encode); 38 | 39 | echar_t& operator[] (size_t k); 40 | const echar_t& operator[] (size_t k) const; 41 | const estring& operator= (const estring& estr); 42 | const estring& operator= (const std::string& str); 43 | const estring& operator= (const char* cstr); 44 | const estring& operator= (const echar_t* ecstr); 45 | bool operator== (const estring& estr); 46 | 47 | // const char* c_str(); 48 | const echar_t* ec_str(); 49 | 50 | std::string to_utf8(); 51 | std::string to_str(const std::string& encode); 52 | 53 | int find(echar_t c) const; 54 | int length() const; 55 | 56 | void clear(); 57 | void append(echar_t c); 58 | 59 | /** 60 | * @brief 返回一个子串, 从begin开始, 数size个 61 | * 62 | * @param begin 开始位置 63 | * @param size 子串长度 64 | * 65 | * @return 子串的estring对象 66 | */ 67 | estring substr(int begin, int size); 68 | 69 | static const char* encodedetect (const char* data); 70 | 71 | iterator begin(); 72 | iterator end(); 73 | void push_back(echar_t c); 74 | 75 | private: 76 | static std::string load_full_file(const std::string& path); 77 | 78 | std::basic_string data; 79 | 80 | }; 81 | 82 | 83 | 84 | 85 | 86 | 87 | #endif // ESTRING_H 88 | -------------------------------------------------------------------------------- /ExIconv/src/FileUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-11 18:48:19 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-25 19:54:42 6 | */ 7 | 8 | #include "FileUtils.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | using namespace std; 16 | using namespace llvm::sys; 17 | using namespace llvm::sys::fs; 18 | 19 | int FileUtils::create_directory(const std::string& path, bool IgnoreExisting) { 20 | llvm::sys::fs::create_directory(path, IgnoreExisting); 21 | return 0; 22 | } 23 | 24 | int FileUtils::create_directories(const std::string& path, bool IgnoreExisting) { 25 | llvm::sys::fs::create_directories(path, IgnoreExisting); 26 | return 0; 27 | } 28 | 29 | bool FileUtils::isNeedUpdate(const std::string& cfg_path, const std::string& save_path) { 30 | file_status save_file_status; 31 | status (save_path, save_file_status); 32 | if (!exists(save_file_status)) { 33 | printf("\n\n%s\n##### 文件不存在\n\n\n", save_path.c_str()); 34 | return true; 35 | } 36 | file_status cfg_file_status; 37 | status (cfg_path, cfg_file_status); 38 | if (!exists(cfg_file_status)) { 39 | printf("\n\n%s\n##### 文件不存在\n\n\n", cfg_path.c_str()); 40 | return true; 41 | } 42 | TimeValue save_time = save_file_status.getLastModificationTime(); 43 | TimeValue cfg_time = cfg_file_status.getLastModificationTime(); 44 | 45 | if (save_time > cfg_time) return false; 46 | else { 47 | printf("\n\n##### 时间不正确\n\n\n"); 48 | return true; 49 | } 50 | } 51 | 52 | bool FileUtils::test_dir(const std::string& path) { 53 | file_status file_status; 54 | status (path, file_status); 55 | return exists(file_status) && is_directory(file_status); 56 | } 57 | 58 | bool FileUtils::test_file(const std::string& path) { 59 | file_status file_status; 60 | status (path, file_status); 61 | return exists(file_status) && is_regular_file(file_status); 62 | } 63 | 64 | string FileUtils::get_current_path() { 65 | llvm::SmallVector< char, 128 > result; 66 | current_path(result); 67 | result.append(1, (char)0); 68 | return result.data(); 69 | } 70 | 71 | int FileUtils::dir_traversal(const std::string& path, IFileTraversal& ifile, traversal_type t) { 72 | std::error_code ec; 73 | directory_iterator di(path, ec); 74 | directory_iterator end; 75 | while (di != end) { 76 | auto entry = *di; 77 | bool pd = true; 78 | if (t == only_file) 79 | pd = is_regular_file(entry.path()); 80 | if (t == only_dir) 81 | pd = is_directory(entry.path()); 82 | if (pd) { 83 | ifile.Work( 84 | llvm::sys::path::parent_path(entry.path()).str(), 85 | llvm::sys::path::filename(entry.path()).str(), 86 | llvm::sys::path::extension(entry.path()).str() 87 | ); 88 | } 89 | di.increment(ec); 90 | } 91 | return 0; 92 | } 93 | 94 | int FileUtils::dir_recursive_traversal(const std::string& path, IFileTraversal& ifile, traversal_type t) { 95 | std::error_code ec; 96 | recursive_directory_iterator di(path, ec); 97 | recursive_directory_iterator end; 98 | while (di != end) { 99 | auto entry = *di; 100 | bool pd = true; 101 | if (t == only_file) 102 | pd = is_regular_file(entry.path()); 103 | if (t == only_dir) 104 | pd = is_directory(entry.path()); 105 | if (pd) { 106 | ifile.Work( 107 | llvm::sys::path::parent_path(entry.path()).str(), 108 | llvm::sys::path::filename(entry.path()).str(), 109 | llvm::sys::path::extension(entry.path()).str() 110 | ); 111 | } 112 | di.increment(ec); 113 | } 114 | return 0; 115 | } 116 | 117 | std::string FileUtils::fileReader(const char* path) { 118 | std::ifstream t(path, std::ios::binary); 119 | std::string str; 120 | 121 | t.seekg(0, std::ios::end); 122 | str.reserve(t.tellg()); 123 | t.seekg(0, std::ios::beg); 124 | 125 | str.assign((std::istreambuf_iterator(t)), 126 | std::istreambuf_iterator()); 127 | return str; 128 | } 129 | -------------------------------------------------------------------------------- /ExIconv/src/PathUtils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-20 11:55:34 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-20 12:07:11 6 | */ 7 | 8 | #include "PathUtils.h" 9 | #include 10 | #include 11 | using namespace std; 12 | using namespace llvm; 13 | using namespace llvm::sys; 14 | 15 | std::string PathUtils::native(const std::string& path) { 16 | SmallVector result; 17 | path::native(path, result); 18 | result.append(1, (char)0); 19 | return result.data(); 20 | } 21 | 22 | std::string PathUtils::parent_path(const std::string& path) { 23 | return path::parent_path(path).str(); 24 | } 25 | -------------------------------------------------------------------------------- /ExIconv/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | enable_testing() 2 | find_package(GTest REQUIRED) 3 | 4 | include(../../cmake/ClangConf.cmake) 5 | 6 | include_directories (${CMAKE_CURRENT_SOURCE_DIR}) 7 | include_directories (${GTEST_INCLUDE_DIRS}) 8 | file(GLOB_RECURSE test_source_files ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 9 | 10 | add_executable (estring_test ${test_source_files}) 11 | 12 | target_link_libraries(estring_test exiconv iconv charsetdetect charset ${GTEST_BOTH_LIBRARIES} pthread) 13 | 14 | add_test(EstringTest estring_test) 15 | 16 | add_custom_target( runtest ALL 17 | DEPENDS estring_test) 18 | 19 | add_custom_command(TARGET runtest 20 | POST_BUILD 21 | COMMAND estring_test) 22 | -------------------------------------------------------------------------------- /ExIconv/test/EstringTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-16 12:02:18 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-03-05 17:01:18 6 | */ 7 | #ifdef __APPLE__ 8 | #define GTEST_HAS_POSIX_RE 0 9 | #endif 10 | 11 | #include 12 | #include 13 | #include "estring.h" 14 | 15 | using namespace std; 16 | 17 | #define __ESTRING_TEST__(name) TEST(EstringTest_##name, name) 18 | 19 | __ESTRING_TEST__(Construction) 20 | { 21 | estring str("您好"); 22 | string hello("您好"); 23 | estring str2(hello); 24 | } 25 | 26 | 27 | __ESTRING_TEST__(Equal) 28 | { 29 | estring str("hello您好, 这是一段中英混排"); 30 | string hello("hello您好, 这是一段中英混排"); 31 | estring str2(hello); 32 | EXPECT_EQ(str == str2, true); 33 | } 34 | 35 | __ESTRING_TEST__(ToUtf8) 36 | { 37 | estring str("我的中国心"); 38 | string hello("我的中国心"); 39 | EXPECT_EQ(str.to_utf8() == hello, true); 40 | } 41 | 42 | __ESTRING_TEST__(Select) 43 | { 44 | estring str("hello您好, 这是一段中英混排"); 45 | for (int i = 0; i < 8; ++i) 46 | printf("%04X ", str[i]); 47 | printf("\n"); 48 | EXPECT_EQ(str[4], 'o'); 49 | } 50 | 51 | __ESTRING_TEST__(Select2) 52 | { 53 | estring str("0-9"); 54 | EXPECT_EQ(str[0], '0'); 55 | EXPECT_EQ(str[1], '-'); 56 | EXPECT_EQ(str[2], '9'); 57 | } 58 | 59 | __ESTRING_TEST__(Enter) 60 | { 61 | estring str("hello\n您好, 这是一段中英混排\n" 62 | "这里稍稍有点问题" 63 | "so, I\n want to have a try." 64 | ); 65 | EXPECT_EQ(str[5], '\n'); 66 | EXPECT_EQ(str[18], '\n'); 67 | int i = 19; 68 | while(i < str.length()) { 69 | if (str[i] == '\n') break; 70 | ++i; 71 | } 72 | estring substr = str.substr(19, i-19); // 注意, substr的第二个参数需要的是长度, 而不是到哪里 73 | printf("%s\n",substr.to_utf8().c_str()); 74 | estring ans = "这里稍稍有点问题so, I"; 75 | EXPECT_EQ(substr==ans, true); 76 | } 77 | 78 | 79 | __ESTRING_TEST__(Construction2AndFind) 80 | { 81 | estring str("hello您好, 这是一段中英混排"); 82 | estring estr(str.ec_str()); 83 | EXPECT_EQ(str==estr, true); 84 | EXPECT_EQ(str.find('l'), 2); 85 | } 86 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | elite: 2 | -mkdir build 3 | cd build && cmake .. && make elite 4 | 5 | release: 6 | -mkdir build 7 | cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && make deps && make elite && make runtime 8 | 9 | test: 10 | -mkdir build 11 | cd build && cmake .. -DBUILD_TEST=ON -DCOVERAGE_FLAG=ON && make deps && make elite && make runtime 12 | 13 | only_test: 14 | -mkdir build 15 | cd build && cmake .. -DBUILD_TEST=ON && make 16 | 17 | deps: 18 | -mkdir build 19 | cd build && cmake .. && make deps 20 | 21 | package: 22 | -mkdir build 23 | cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && make package 24 | 25 | .PHONY: 26 | clean: 27 | -rm -rf ./build ./bin ./lib ./runtime ./extlib 28 | -------------------------------------------------------------------------------- /MetaScriptRunner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(MetaScriptRunner) 3 | 4 | if (NOT BUILD_ALL) 5 | set(LLVM_TARGETS_TO_BUILD X86) 6 | set(LLVM_BUILD_RUNTIME OFF) 7 | set(LLVM_BUILD_TOOLS OFF) 8 | 9 | find_package(LLVM REQUIRED CONFIG) 10 | message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") 11 | message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") 12 | 13 | SET (CMAKE_CXX_COMPILER_ENV_VAR "clang++") 14 | SET (CMAKE_CXX_FLAGS "-std=c++11") 15 | SET (CMAKE_CXX_FLAGS_DEBUG "-g") 16 | SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 17 | SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG") 18 | SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") 19 | SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) 20 | 21 | include_directories(lib 22 | ../Lex/include 23 | ../LR_Scanner/include 24 | ../RedApple/includes) 25 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib) 26 | endif() 27 | 28 | 29 | 30 | 31 | # 核心路径配置 32 | include_directories(src include) 33 | file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c) 34 | list(REMOVE_ITEM source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) 35 | 36 | if(USE_DYNAMIC) 37 | add_library(meta SHARED ${source_files}) # 使用动态库 38 | install(TARGETS meta RUNTIME DESTINATION bin) 39 | else() 40 | add_library(meta STATIC ${source_files}) # 使用静态库 41 | install(TARGETS meta ARCHIVE DESTINATION lib) 42 | endif() 43 | 44 | 45 | 46 | if (NOT BUILD_ALL) 47 | 48 | add_executable(toolua ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) 49 | target_link_libraries(toolua meta oolua lua dl lex scanner red) 50 | 51 | # Find the libraries that correspond to the LLVM components 52 | # that we wish to use 53 | llvm_map_components_to_libnames(llvm_libs 54 | support core irreader executionengine interpreter 55 | mc mcjit bitwriter x86codegen target) 56 | 57 | # Link against LLVM libraries 58 | target_link_libraries(toolua ${llvm_libs}) 59 | 60 | endif() 61 | -------------------------------------------------------------------------------- /MetaScriptRunner/Doxyfile.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "@CMAKE_PROJECT_NAME@" 2 | PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@ 3 | STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ \ 4 | @PROJECT_BINARY_DIR@ 5 | INPUT = @doxy_main_page@ \ 6 | @PROJECT_SOURCE_DIR@ \ 7 | @PROJECT_BINARY_DIR@ 8 | FILE_PATTERNS = *.h \ 9 | *.c 10 | OUTPUT_LANGUAGE = Chinese 11 | RECURSIVE = YES 12 | EXTRACT_ALL = YES 13 | EXTRACT_PRIVATE = YES 14 | EXTRACT_STATIC = YES 15 | EXCLUDE_PATTERNS = */thirdparty/* 16 | USE_MDFILE_AS_MAINPAGE = @doxy_main_page@ 17 | -------------------------------------------------------------------------------- /MetaScriptRunner/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # @Author: sxf 3 | # @Date: 2015-11-03 08:33:43 4 | # @Last Modified by: sxf 5 | # @Last Modified time: 2015-11-03 08:34:18 6 | 7 | mkdir ./build 8 | cd ./build 9 | cmake .. 10 | make 11 | cd .. -------------------------------------------------------------------------------- /MetaScriptRunner/include/EPackage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-24 15:55:11 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 13:28:11 6 | */ 7 | 8 | #ifndef E_PACKAGE_H 9 | #define E_PACKAGE_H 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | class MetaScriptRunner; 17 | 18 | /** 19 | * @brief Elite的软件包扩展 20 | * @details 这个类是Elite的插件元数据类,每个软件包都会有一个package.json配置 21 | * 本类负责解析配置数据,存储软件包的各关键路径,加载或卸载该软件包 22 | * 也可以获取到软件包相关的重要配置参数信息,例如名字、版本、是否加载等信息。 23 | */ 24 | class EPackage 25 | { 26 | public: 27 | /** 28 | * @brief 软件包的构造函数 29 | * @details 构造一个插件包时,当前路径需要被确定校验存在,并含有一个package.json的元数据配置项 30 | * 构造中,会解析package.json的相关数据,但不会加载其他任何内容 31 | * 对于自动加载型的插件包,需要在外层再扫描一次,判断并加载。 32 | * 33 | * @param path 当前软件包的路径,应为绝对路径 34 | * @param msr 当前MetaScriptRunner的指针,加载时,可能会加载lua脚本,或者epbc二进制码,该接口负责调用对应功能 35 | */ 36 | EPackage(const string& path, MetaScriptRunner* msr); 37 | ~EPackage(); 38 | 39 | /** 40 | * @brief 获取包的名字, 该名字是识别这个扩展的唯一标识 41 | */ 42 | const string& getName(); 43 | 44 | /** 45 | * @brief 返回版本号, 格式为字符串 46 | */ 47 | const string& getVersion(); 48 | 49 | /** 50 | * @brief 获取一个Runtime时添加链接的字符串 51 | */ 52 | const string& getRuntime(); 53 | 54 | /** 55 | * @brief 判断是否是默认载入这个包 56 | */ 57 | const bool isDefaultLoad(); 58 | 59 | /** 60 | * @brief 判断这个包能否在本平台环境下被载入 61 | */ 62 | const bool canLoadOnPlatform(); 63 | 64 | /** 65 | * @brief 判断这个软包是否已经加载 66 | */ 67 | const bool isLoaded(); 68 | 69 | /** 70 | * @brief 立即加载整个插件 71 | * @details 插件的加载方式是, 搜索当前插件路径下的所有可以识别的文件, 进行载入, 但不会递归到下层文件夹 72 | */ 73 | void Load(); 74 | 75 | 76 | void Run(); 77 | 78 | /** 79 | * @brief 获取当前包的属性值 80 | * 81 | * @param name 属性名 82 | * @return 对应的值 83 | */ 84 | const string& getProp(const string& name); 85 | 86 | static string str_null; 87 | 88 | private: 89 | map props; 90 | string base_path; 91 | MetaScriptRunner* msr; 92 | 93 | /** 94 | * 加载Json配置数据项 95 | * @param json 一段JSON字符串数据 96 | */ 97 | void loadJson(const string& json); 98 | 99 | /** 100 | * @brief 向当前插件包中添加新的属性 101 | * 102 | * @param name 属性名 103 | * @param value 属性值 104 | */ 105 | void insertProp(const string& name, const string& value); 106 | 107 | 108 | /** 109 | * @brief 为runtime属性添加-L寻找路径,否则会造成库找不到. 110 | * 这个函数仅在构造函数中调用一次, 不能多次调用 111 | */ 112 | void addRuntimePath(); 113 | }; 114 | 115 | 116 | 117 | #endif // E_PACKAGE_H 118 | -------------------------------------------------------------------------------- /MetaScriptRunner/include/ILoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-24 16:36:44 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 16:37:01 6 | */ 7 | 8 | #ifndef I_LOADER_H 9 | #define I_LOADER_H 10 | 11 | class ILoader 12 | { 13 | public: 14 | 15 | 16 | }; 17 | 18 | 19 | 20 | #endif // I_LOADER_H 21 | -------------------------------------------------------------------------------- /MetaScriptRunner/include/LuaGenFunction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-24 17:00:30 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 17:14:29 6 | */ 7 | 8 | 9 | #ifndef LUA_GEN_FUNCTION_H 10 | #define LUA_GEN_FUNCTION_H 11 | 12 | #include "ICodeGenFunction.h" 13 | 14 | /** 15 | * @brief 这个类是Lua的回调函数实现 16 | */ 17 | class LuaGenFunction : public ICodeGenFunction 18 | { 19 | public: 20 | LuaGenFunction(); 21 | LuaGenFunction(int lua_code); 22 | ~LuaGenFunction(); 23 | 24 | virtual LValue call(CodeGenContext*, Node*); 25 | private: 26 | int lua_code; 27 | }; 28 | 29 | 30 | 31 | #endif // LUA_GEN_FUNCTION_H 32 | -------------------------------------------------------------------------------- /MetaScriptRunner/include/MetaScriptRunner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-05 21:21:50 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 15:28:09 6 | */ 7 | 8 | 9 | #ifndef META_SCRIPT_RUNNER_H 10 | #define META_SCRIPT_RUNNER_H 11 | 12 | #include "ScriptRunner.h" 13 | 14 | using namespace std; 15 | 16 | namespace OOLUA { 17 | class Script; 18 | } 19 | class PackageLoader; 20 | class CodeGenContext; 21 | class LexInterface; 22 | class Parser; 23 | class Builder; 24 | 25 | /** 26 | * @brief 元脚本解析器类 27 | * @details 元脚本是一种编译时脚本, 负责在编译时执行特定动作和用户自定义行为\n 28 | * 元脚本的首要功能是提供构建语法树的接口, 有此接口, 语法解析器才能在特定的时刻调用元脚本解析器 29 | * 进行代码生成工作\n 30 | * 其次, 元脚本具有配置项目环境, 查看编译状态, 控制包导入, 特殊内容输出等诸多功能, 31 | * 绝大部分功能可以在本子项目中实现\n 32 | * 本元脚本解析器, 采用lua语言作为脚本, 为了安全的向lua中注册函数, 又引入了oolua 33 | * 做C++到lua的绑定 34 | */ 35 | class MetaScriptRunner : public ScriptRunner 36 | { 37 | public: 38 | /** 39 | * @brief 初始化脚本解析器 40 | */ 41 | virtual void Init(); 42 | 43 | /** 44 | * @brief 获取语法树根节点 45 | * @details 这个设计稍稍有点不好, 仅仅对RedApple后端有效 46 | * @return 语法树根节点 47 | */ 48 | virtual Node* getRoot(); // 仅支持后端为RedApple的宏翻译系统,其余系统返回NULL 49 | 50 | /** 51 | * @brief 解析完成后由语法分析器调用 52 | */ 53 | virtual void Finished(); 54 | 55 | /** 56 | * @brief 创建默认的脚本解析器 57 | */ 58 | static MetaScriptRunner* Create(); 59 | 60 | /** 61 | * @brief 执行一个lua脚本 62 | * 63 | * @param filename 脚本的完整或相对路径 64 | * @return 成功为true, 异常为false 65 | */ 66 | bool run_file (string const &filename); 67 | 68 | /** 69 | * @brief 加载一个脚本, 但暂不执行 (需要pcall才执行) 70 | * 71 | * @param filename 脚本的完整或相对路径 72 | * @return 成功为true, 异常为false 73 | */ 74 | bool load_file (string const &filename); 75 | 76 | /** 77 | * @brief 加载一段内存中的lua脚本 (不执行) 78 | * 79 | * @param chunk 脚本字符串 80 | * @return 成功为true, 异常为false 81 | */ 82 | bool load_chunk (string const &chunk); 83 | 84 | /** 85 | * @brief 运行一段内存中的lua脚本 86 | * 87 | * @param chunk 脚本字符串 88 | * @return 成功为true, 异常为false 89 | */ 90 | bool run_chunk (string const &chunk); 91 | 92 | void setUpLoader(const string& path); 93 | 94 | void setCodeGenContext(CodeGenContext* ctx) { context = ctx; } 95 | CodeGenContext* getCodeGenContext() { return context; } 96 | 97 | void setLex(LexInterface* _lex) { lex = _lex; } 98 | LexInterface* getLex() { return lex; } 99 | 100 | void setParser(Parser* _parser) { parser = _parser; } 101 | Parser* getParser() { return parser; } 102 | 103 | void setBuilder(Builder* _builder) { builder = _builder; } 104 | Builder* getBuilder() { return builder; } 105 | 106 | protected: 107 | OOLUA::Script* vm; 108 | Node* root; 109 | PackageLoader* loader = NULL; 110 | CodeGenContext* context = NULL; 111 | LexInterface* lex = NULL; 112 | Parser* parser = NULL; 113 | Builder* builder = NULL; 114 | 115 | MetaScriptRunner(); 116 | ~MetaScriptRunner(); 117 | }; 118 | 119 | 120 | 121 | 122 | 123 | #endif // META_SCRIPT_RUNNER_H 124 | -------------------------------------------------------------------------------- /MetaScriptRunner/include/PackageJIT.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-25 20:40:43 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-29 12:30:59 6 | */ 7 | 8 | 9 | #ifndef PACKAGE_JIT_H 10 | #define PACKAGE_JIT_H 11 | 12 | #include 13 | 14 | class PackageJIT_private; 15 | class MetaScriptRunner; 16 | namespace llvm { 17 | class ExecutionEngine; 18 | }; 19 | 20 | 21 | /** 22 | * @brief C插件的JIT解释器 23 | * @details 为了支持C编写跨平台的插件,我们将使用Clang,将C代码编译成llvm字节码,然后通过JIT解释执行, 24 | * 达到一份编译,跨平台加载的特性 25 | * 本类是LLVM的JIT解释器,同时是一个单例类,所有插件,都将共用该类,进行C插件的加载与运行。 26 | * 注意,本类并没有考虑线程安全的问题,请勿多线程调用本来进行加载。 27 | */ 28 | class PackageJIT 29 | { 30 | public: 31 | /** 32 | * @brief 加载一款C插件 33 | * 34 | * @param path 插件的决定路径,指向一个epbc文件 35 | * @param name 插件名,影响插件的加载入口函数 36 | * @param msr MetaScriptRunner接口 37 | */ 38 | static void LoadPlugin(const std::string& path, const std::string& name, MetaScriptRunner* msr); 39 | 40 | 41 | static void RunPlugin(const std::string& name, MetaScriptRunner* msr); 42 | 43 | /** 44 | * @brief 添加一个动态链接符号 45 | * @details 由于C插件的特殊性,静态链接的函数由于符号名未导出,JIT将无法调用到,所以我们需要为C接口导出动态链接符号 46 | * 47 | * @param name 符号名,一般C函数就是函数名 48 | * @param ptr 对应符号的地址,一般C函数为函数指针 49 | */ 50 | static void AddSymbol(const std::string& name, void* ptr); 51 | 52 | static PackageJIT_private* getInstance(); 53 | 54 | private: 55 | PackageJIT(); 56 | ~PackageJIT(); 57 | static PackageJIT_private* priv; 58 | }; 59 | 60 | 61 | #endif // PACKAGE_JIT_H 62 | -------------------------------------------------------------------------------- /MetaScriptRunner/include/PackageLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-24 15:48:44 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-25 15:24:35 6 | */ 7 | 8 | #ifndef PACKAGE_LOADER_H 9 | #define PACKAGE_LOADER_H 10 | 11 | #include "EPackage.h" 12 | 13 | class MetaScriptRunner; 14 | 15 | /** 16 | * @brief 扩展包加载器 17 | */ 18 | class PackageLoader 19 | { 20 | public: 21 | PackageLoader(const string& base_path, MetaScriptRunner* msr); 22 | ~PackageLoader(); 23 | 24 | /** 25 | * @brief 找出目录下所以的可加载项 26 | */ 27 | void FindAll(); 28 | 29 | /** 30 | * @brief 加载全部默认需要加载的包 31 | */ 32 | void LoadDefault(); 33 | 34 | private: 35 | string base_path; 36 | map packages; 37 | 38 | MetaScriptRunner* msr; 39 | }; 40 | 41 | 42 | #endif // PACKAGE_LOADER_H 43 | -------------------------------------------------------------------------------- /MetaScriptRunner/src/EPackage.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-24 17:15:29 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 15:48:30 6 | */ 7 | 8 | #include "EPackage.h" 9 | #include "cJSON.h" 10 | #include "FileUtils.h" 11 | #include "PathUtils.h" 12 | #include "MetaScriptRunner.h" 13 | #include "PackageJIT.h" 14 | #include "Builder.h" 15 | #include 16 | using namespace std; 17 | 18 | class FileTraversal : public IFileTraversal { 19 | public: 20 | FileTraversal(MetaScriptRunner* msr, EPackage& epkg) 21 | : epkg(epkg) { 22 | this->msr = msr; 23 | } 24 | 25 | virtual void Work(const std::string& now_path, 26 | const std::string& filename, 27 | const std::string& suffix) 28 | { 29 | string filepath = now_path + "/" + filename; 30 | if (suffix == ".lua") { 31 | msr->run_file(filepath); 32 | } 33 | if (suffix == ".epbc") { 34 | PackageJIT::LoadPlugin(filepath, epkg.getName(), msr); 35 | } 36 | } 37 | MetaScriptRunner* msr; 38 | EPackage& epkg; 39 | }; 40 | 41 | 42 | EPackage::EPackage(const string& path, MetaScriptRunner* msr) { 43 | this->msr = msr; 44 | base_path = path; 45 | string json_path = PathUtils::native(base_path+"/package.json"); 46 | string json_data = FileUtils::fileReader(json_path.c_str()); 47 | loadJson(json_data); 48 | addRuntimePath(); 49 | } 50 | 51 | EPackage::~EPackage() { 52 | 53 | } 54 | 55 | void EPackage::Load() { 56 | cout << "Load Package: " << base_path << endl; 57 | FileTraversal ft(msr, *this); 58 | FileUtils::dir_traversal(base_path, ft, FileUtils::only_file); 59 | string link_args = getRuntime(); 60 | if (link_args != str_null) // 添加runtime链接参数 61 | msr->getBuilder()->AddLinkArgs(link_args); 62 | insertProp("package_loaded", "true"); 63 | } 64 | 65 | 66 | void EPackage::Run() { 67 | PackageJIT::RunPlugin(getName(), msr); 68 | } 69 | 70 | const bool EPackage::canLoadOnPlatform() { 71 | string platform = getProp("platform"); 72 | if (platform.empty()) return true; 73 | #if defined(_WIN32) 74 | return platform == "win32"; 75 | #elif defined(__linux__) 76 | return platform == "linux"; 77 | #elif defined(__APPLE__) 78 | return platform == "apple"; 79 | #endif 80 | return false; 81 | } 82 | 83 | const string& EPackage::getName() { 84 | return getProp("name"); 85 | } 86 | 87 | const string& EPackage::getVersion() { 88 | return getProp("version"); 89 | } 90 | 91 | const string& EPackage::getRuntime() { 92 | return getProp("runtime"); 93 | } 94 | 95 | const bool EPackage::isDefaultLoad() { 96 | return getProp("default_load") == "true"; 97 | } 98 | const bool EPackage::isLoaded() { 99 | return getProp("package_loaded") == "true"; 100 | } 101 | 102 | const string& EPackage::getProp(const string& name) { 103 | auto p = props.find(name); 104 | if (p != props.end()) return p->second; 105 | return str_null; 106 | } 107 | 108 | void EPackage::insertProp(const string& name, const string& value) { 109 | props[name] = value; 110 | } 111 | 112 | void EPackage::loadJson(const string& json) { 113 | cJSON* cj = cJSON_Parse(json.c_str()); 114 | if (!cj) { printf("error json format\n"); return; } 115 | 116 | for ( cJSON* p = cj->child; p != NULL; p = p->next ) 117 | if ( p->type == cJSON_String ) 118 | insertProp(p->string, p->valuestring); 119 | 120 | cJSON_Delete(cj); 121 | } 122 | 123 | void EPackage::addRuntimePath() { 124 | string args = getRuntime(); 125 | if (args == str_null) return; 126 | string Lpath = "-L"; 127 | Lpath += base_path; 128 | Lpath += ' '; 129 | Lpath += args; 130 | insertProp("runtime", Lpath); 131 | } 132 | 133 | 134 | string EPackage::str_null; 135 | -------------------------------------------------------------------------------- /MetaScriptRunner/src/LuaGenFunction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-24 17:12:55 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-24 17:14:47 6 | */ 7 | 8 | #include "LuaGenFunction.h" 9 | 10 | LuaGenFunction::LuaGenFunction() { 11 | } 12 | 13 | LuaGenFunction::LuaGenFunction(int lua_code) { 14 | this->lua_code = lua_code; 15 | } 16 | 17 | LuaGenFunction::~LuaGenFunction() { 18 | } 19 | 20 | LValue LuaGenFunction::call(CodeGenContext*, Node*) { 21 | return nullptr; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /MetaScriptRunner/src/MetaScriptRunner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-07 13:52:20 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-25 17:42:32 6 | */ 7 | 8 | #include "MetaScriptRunner.h" 9 | #include "oolua/oolua.h" 10 | #include "PackageLoader.h" 11 | 12 | extern void InitMetaAPI(lua_State*); 13 | 14 | void MetaScriptRunner::Init() { 15 | L = *vm; 16 | ScriptRunner::Init(); 17 | InitMetaAPI(L); 18 | } 19 | 20 | MetaScriptRunner* MetaScriptRunner::Create() { 21 | return new MetaScriptRunner(); 22 | } 23 | 24 | MetaScriptRunner::MetaScriptRunner() { 25 | vm = new OOLUA::Script(); 26 | } 27 | 28 | MetaScriptRunner::~MetaScriptRunner() { 29 | delete vm; 30 | if (loader != NULL) delete loader; 31 | } 32 | 33 | void MetaScriptRunner::setUpLoader(const string& path) { 34 | loader = new PackageLoader(path, this); 35 | loader->FindAll(); 36 | loader->LoadDefault(); 37 | } 38 | 39 | Node* MetaScriptRunner::getRoot() { 40 | return root; 41 | } 42 | 43 | extern Node* node_root; 44 | 45 | void MetaScriptRunner::Finished() { 46 | printf("Great! Finished!\n"); 47 | root = node_root; 48 | } 49 | 50 | bool MetaScriptRunner::run_file (std::string const &filename) { 51 | return vm->run_file(filename); 52 | } 53 | bool MetaScriptRunner::load_file (std::string const &filename) { 54 | return vm->load_file(filename); 55 | } 56 | bool MetaScriptRunner::load_chunk (std::string const &chunk) { 57 | return vm->load_chunk(chunk); 58 | } 59 | bool MetaScriptRunner::run_chunk (std::string const &chunk) { 60 | return vm->run_chunk(chunk); 61 | } 62 | -------------------------------------------------------------------------------- /MetaScriptRunner/src/PackageLoader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-24 17:21:09 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-26 19:21:56 6 | */ 7 | 8 | #include "PackageLoader.h" 9 | #include "FileUtils.h" 10 | #include "PathUtils.h" 11 | #include "MetaScriptRunner.h" 12 | #include "PackageJIT.h" 13 | #include 14 | using namespace std; 15 | 16 | class DirFileTraversal : public IFileTraversal { 17 | public: 18 | DirFileTraversal(map& pkgs, MetaScriptRunner* msr) 19 | : packages(pkgs) 20 | { 21 | this->msr = msr; 22 | } 23 | 24 | virtual void Work(const std::string& now_path, 25 | const std::string& filename, 26 | const std::string& suffix) 27 | { 28 | string cfg_path = PathUtils::native(now_path+"/"+filename+"/package.json"); 29 | if (!FileUtils::test_file(cfg_path)) return; 30 | string path = PathUtils::native(now_path+"/"+filename); 31 | EPackage* pkg = new EPackage(path, msr); 32 | string name = pkg->getName(); 33 | if (name == EPackage::str_null) { delete pkg; return; } 34 | packages[name] = pkg; 35 | } 36 | 37 | map& packages; 38 | MetaScriptRunner* msr; 39 | }; 40 | 41 | 42 | 43 | PackageLoader::PackageLoader(const string& base_path, MetaScriptRunner* msr) { 44 | this->base_path = base_path; 45 | this->msr = msr; 46 | } 47 | 48 | PackageLoader::~PackageLoader() { 49 | 50 | } 51 | 52 | 53 | /** 54 | * @brief 找出目录下所以的可加载项 55 | */ 56 | void PackageLoader::FindAll() { 57 | DirFileTraversal dft(packages, msr); 58 | FileUtils::dir_traversal(base_path, dft, FileUtils::only_dir); 59 | } 60 | 61 | static void HelloWorld() { 62 | cout << "Hello World" << endl; 63 | } 64 | 65 | 66 | /** 67 | * @brief 加载全部默认需要加载的包 68 | */ 69 | void PackageLoader::LoadDefault() { 70 | PackageJIT::AddSymbol("HelloWorld", (void*)HelloWorld); 71 | for (auto& p : packages) { 72 | auto pkg = p.second; 73 | if (pkg->isDefaultLoad() && !pkg->isLoaded() && pkg->canLoadOnPlatform()) 74 | pkg->Load(); 75 | } 76 | 77 | for (auto& p : packages) { 78 | auto pkg = p.second; 79 | if (pkg->isLoaded()) 80 | pkg->Run(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /MetaScriptRunner/src/llcgAPI.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2016-01-01 11:09:47 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 11:19:08 6 | */ 7 | 8 | #include "oolua/oolua.h" 9 | 10 | using namespace OOLUA; 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | extern void InitLLCGAPI(lua_State* L) { 19 | 20 | 21 | } -------------------------------------------------------------------------------- /MetaScriptRunner/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-05 17:14:18 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-11-05 17:23:17 6 | */ 7 | 8 | #include 9 | #include "oolua/oolua.h" 10 | 11 | void say(char const* input) { 12 | printf("%s\n", input); 13 | } 14 | 15 | OOLUA_CFUNC(say, l_say) 16 | 17 | void hello_minimalist_function() { 18 | using namespace OOLUA; //NOLINT(build/namespaces) 19 | Script vm; 20 | set_global(vm, "say", l_say); 21 | run_chunk(vm, "say('Hello Lua')"); 22 | } 23 | 24 | int main(int argc, char const *argv[]) 25 | { 26 | hello_minimalist_function(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Preprocessor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(Preprocessor) 3 | 4 | if(NOT BUILD_ALL) # BUILD_ALL负责确认是不是所有子项目统一配置构建 5 | SET (CMAKE_BUILD_TYPE Debug) 6 | SET (CMAKE_CXX_COMPILER_ENV_VAR "clang++") 7 | SET (CMAKE_CXX_FLAGS "-std=c++11") 8 | SET (CMAKE_CXX_FLAGS_DEBUG "-g") 9 | SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 10 | SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG") 11 | SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") 12 | SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) 13 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../extlib/lib) 14 | endif() 15 | 16 | 17 | # 核心路径配置 18 | include_directories(include src ../extlib/include) 19 | file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) 20 | if(USE_DYNAMIC) 21 | add_library(preprocessor SHARED ${source_files}) # 使用动态库 22 | else() 23 | add_library(preprocessor STATIC ${source_files}) # 使用静态库 24 | endif() 25 | 26 | if(BUILD_TEST) 27 | add_subdirectory(test) 28 | endif() 29 | -------------------------------------------------------------------------------- /Preprocessor/include/Preprocessor.h: -------------------------------------------------------------------------------- 1 | #ifndef PREPROCESSOR_H 2 | #define PREPROCESSOR_H 3 | 4 | #include "lua.hpp" 5 | #include 6 | 7 | class Preprocessor { 8 | public: 9 | Preprocessor (const std::string& input, lua_State* L); 10 | virtual ~Preprocessor (); 11 | 12 | const std::string& genCode(); 13 | const std::string& runCode(); 14 | 15 | std::string output; 16 | const std::string& input; 17 | std::string code_string; 18 | protected: 19 | lua_State* L; 20 | 21 | int add_const_str(std::string::const_iterator p, std::string::const_iterator q); 22 | int pt_size = 0; 23 | 24 | }; 25 | 26 | 27 | 28 | 29 | #endif /* end of include guard: PREPROCESSOR_H */ 30 | -------------------------------------------------------------------------------- /Preprocessor/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | enable_testing() 2 | find_package(GTest REQUIRED) 3 | 4 | include(../../cmake/ClangConf.cmake) 5 | 6 | include_directories (${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include) 7 | include_directories (${GTEST_INCLUDE_DIRS}) 8 | file(GLOB_RECURSE test_source_files ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 9 | 10 | add_executable (pp_test ${test_source_files}) 11 | 12 | link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../extlib) 13 | 14 | target_link_libraries(pp_test preprocessor lua ${GTEST_BOTH_LIBRARIES} pthread) 15 | 16 | add_test(EstringTest pp_test) 17 | 18 | add_custom_target( runtest ALL DEPENDS pp_test) 19 | 20 | add_custom_command(TARGET runtest 21 | POST_BUILD 22 | COMMAND pp_test) 23 | -------------------------------------------------------------------------------- /Preprocessor/test/PPTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-16 12:02:18 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-03-05 17:01:18 6 | */ 7 | 8 | #include 9 | #include "Preprocessor.h" 10 | 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | static std::string fileReader(const char* path) { 16 | std::ifstream t(path, std::ios::binary); 17 | std::string str; 18 | 19 | t.seekg(0, std::ios::end); 20 | str.reserve(t.tellg()); 21 | t.seekg(0, std::ios::beg); 22 | 23 | str.assign((std::istreambuf_iterator(t)), 24 | std::istreambuf_iterator()); 25 | return str; 26 | } 27 | 28 | 29 | #define __PP_TEST__(name) TEST(PP_##name, name) 30 | 31 | __PP_TEST__(Construction) 32 | { 33 | lua_State* L = luaL_newstate(); 34 | luaL_openlibs(L); 35 | string data = fileReader("../../test/t1.ecode"); 36 | cout << data << endl << endl; 37 | Preprocessor pp(data, L); 38 | cout << "----------------------" << endl; 39 | cout << pp.genCode() << endl << endl; 40 | lua_close(L); 41 | } 42 | 43 | 44 | __PP_TEST__(Run) 45 | { 46 | lua_State* L = luaL_newstate(); 47 | luaL_openlibs(L); 48 | string data = fileReader("../../test/t1.ecode"); 49 | Preprocessor pp(data, L); 50 | cout << pp.genCode() << endl << endl; 51 | cout << "---------------------" << endl; 52 | cout << pp.runCode() << endl << endl; 53 | 54 | lua_close(L); 55 | } 56 | -------------------------------------------------------------------------------- /Preprocessor/test/t1.ecode: -------------------------------------------------------------------------------- 1 | # print('hello ecode') 2 | # Escape = True 3 | # if true then 4 | 5 | void print() { 6 | return; 7 | } 8 | 9 | # else 10 | 11 | int main() { 12 | return 0; 13 | } 14 | 15 | # end 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Travis](https://travis-ci.org/elite-lang/Elite.svg?branch=master)](https://travis-ci.org/elite-lang/Elite) 2 | [![Build status](https://ci.appveyor.com/api/projects/status/vrg2p8onq4xrdep6?svg=true)](https://ci.appveyor.com/project/sunxfancy/elite) 3 | [![codecov.io](https://codecov.io/github/elite-lang/Elite/coverage.svg?branch=master)](https://codecov.io/github/elite-lang/Elite?branch=master) 4 | 5 | # Elite - 精锐编译器 6 | 7 | [![Join the chat at https://gitter.im/elite-lang/Elite](https://badges.gitter.im/elite-lang/Elite.svg)](https://gitter.im/elite-lang/Elite?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 8 | 9 | Elite是一款脚本化驱动的编译器,一般的编程语言,语法是固定的,只能使用有限的表达方式,而Elite的语法并非固定,而是由脚本配置而成的,如果需要,随时都可以自由更改。 10 | 11 | 这个特点,使得Elite非常容易自由开发,成为一款领域专业语言(DSL),在自由配置后,方便地表达专业的相关内容。 12 | 13 | 详细请参加文档: 14 | 15 | ## 编译安装 16 | 17 | clone全部仓库,注意添加`--recursive`参数来下载全部子项目 18 | ``` 19 | git clone --depth=1 --recursive git@github.com:elite-lang/Elite.git 20 | ``` 21 | 22 | 本项目是在Ubuntu14.04 64位系统下开发的,依赖cmake-2.8, LLVM-3.6和glibmm-2.4、giomm-2.4, flex-2.5 bison-3.0 23 | lua oolua dyncall 24 | 25 | ``` 26 | sudo apt-get install cmake llvm-3.6-dev libglibmm-2.4-dev flex bison libedit-dev 27 | ``` 28 | 29 | 修复ubuntu源中LLVM-3.6的bug: 30 | 31 | ``` 32 | sudo sh ./scripts/fix_ubuntu_llvm.sh 33 | ``` 34 | 35 | 然后在项目根目录下执行: 36 | ``` 37 | make release 38 | ``` 39 | 即可编译整个项目 40 | 41 | 或者手动进行如下步骤: 42 | ``` 43 | mkdir build && cd build 44 | cmake .. //cmake配置 45 | make deps //下载并构建依赖项目 46 | make //构建项目 47 | ``` 48 | 49 | 50 | 51 | ## 配置环境变量 52 | 53 | 项目不会向系统添加任何文件,希望使用环境变量配置,将编译器添加到PATH目录中,并且ELITE_HOME也确保编译器能够找到默认的词法、语法配置文件 54 | ``` 55 | # for elite 56 | export ELITE_HOME=【您的Elite仓库地址】 57 | export PATH=$ELITE_HOME/bin:$ELITE_HOME/tools:$PATH 58 | ``` 59 | 60 | 61 | ## 入门教程 62 | 63 | elite的语法非常简洁,是类似C语言的强类型语言,并且函数和类型都不需要前向声明,拥有基于结构体的类型系统,由于是使用RedApple作为后端,所以两者的语法几乎完全一致 64 | 65 | 目前支持的语法特性有: 66 | 67 | * 全局函数,无需声明 68 | * 简单的类型系统,支持int、float、double和结构体struct 69 | * 简化的指针,所有结构体变量声明的都是指针 70 | * 支持常量字符串 71 | * for while if 等逻辑控制语句 72 | * import 其他文件 73 | * meta元数据和反射调用 74 | * 用户自定义宏 75 | 76 | 示例代码: 77 | ``` 78 | void hello(int k, int g) { 79 | int y = k + g; 80 | printf("%d\n", y); 81 | if (k + g < 5) printf("right\n"); 82 | } 83 | 84 | 85 | void go(int k) { 86 | int a = 0; 87 | while (a < k) { 88 | printf("go-%d\n", a); 89 | a = a + 1; 90 | } 91 | } 92 | 93 | void print(int k) { 94 | for (int i = 0; i < 10; i = i+1) { 95 | printf("hello-%d\n",i); 96 | } 97 | } 98 | 99 | 100 | void main() { 101 | printf("hello world\n"); 102 | hello(1,2); 103 | print(9); 104 | } 105 | ``` 106 | 107 | 108 | 反射调用: 109 | ``` 110 | void print(int k) { 111 | printf("hello-%d\n",k); 112 | } 113 | 114 | void main() { 115 | FunctionCall("print", 5); 116 | } 117 | 118 | ``` 119 | 120 | 自定义宏的使用: 121 | ``` 122 | void print(int k) { 123 | @for_n (i, k) { 124 | printf("hello-%d\n", i); 125 | } 126 | } 127 | 128 | defmacro for_n (p, size, code) { 129 | for (int p = 1; p <= size; p = p+1) 130 | code; 131 | } 132 | 133 | 134 | void main() { 135 | FunctionCall("print", 5); 136 | } 137 | ``` 138 | 139 | ## Elite项目结构 140 | 141 | Elite分为如下几个模块: 142 | 143 | - Lex 自动机模式的词法分析器,支持Unicode 144 | - LR_Scanner 语法分析器,易于配置使用并自带缓存功能的分析器,使用LALR(1)算法,表达能力强 145 | - RedApple 多遍宏处理功能的后端代码生成器,使用LLVM作为机器码生成平台,并且能够生成元数据 146 | - RedApple/Runtime 代码运行时库,支持反射调用 147 | - Elite/Builder Elite的项目构建工具 148 | - Elite/MetaScriptRunner Elite的元脚本处理工具,使用Lua作为脚本引擎 149 | - EliteShow Elite语言的中间过程展示工具,使用Electron作为GUI框架,方便查看编译过程 150 | 151 | 152 | ![](doc/design/编译系统工作流程.png) 153 | 154 | 155 | ## 加入我们 156 | 157 | 目前,项目还处于开发初期,非常欢迎热爱开源的朋友们参加此项目,这是一个中等规模的C++项目,加入我们的团队,不但能够促进该项目更快的发展,更能带给您不一样的思路和体验。 158 | 159 | 希望和我们交流非常容易,可以选择发邮件或在github上直接和我们联系,都可以。 160 | 161 | - github: 162 | - 邮箱: 163 | - gitter:[参与讨论](https://gitter.im/elite-lang/Elite?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 164 | 165 | ## 特别感谢 166 | 167 | 熊同学赞助的机械键盘,帮助我更快的打字 O(∩_∩)O哈哈~ 168 | 169 | ## 开源协议 170 | 171 | MIT协议,允许任何人基于该项目开发其他项目,无论是开源的还是商业的,仅仅需要您在使用时,附带我们的版权声明即可。 172 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | platform: 2 | - x86 3 | 4 | configuration: 5 | - Release 6 | 7 | clone_depth: 3 # clone entire repository history if not defined 8 | 9 | install: 10 | - git submodule update --init --recursive 11 | - scripts\install_llvm_win32.bat 12 | 13 | before_build: 14 | - mkdir build 15 | - cd build 16 | - cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_SDK_PATH="C:/projects/elite/LLVM_SDK" -DLLVM_VERSION=3.7 .. 17 | 18 | build_script: 19 | - msbuild /p:Configuration=Release "deps.vcxproj" 20 | - msbuild /p:Configuration=Release "elite.vcxproj" -------------------------------------------------------------------------------- /cmake/ClangConf.cmake: -------------------------------------------------------------------------------- 1 | SET (CMAKE_CXX_COMPILER_ENV_VAR "clang++ ") 2 | SET (CMAKE_CXX_FLAGS_DEBUG "-g") 3 | SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") 4 | SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG") 5 | SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") 6 | if (APPLE) 7 | SET (CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") 8 | elseif(COVERAGE_FLAG) 9 | SET (CMAKE_CXX_FLAGS "-std=c++11 -coverage") 10 | else() 11 | SET (CMAKE_CXX_FLAGS "-std=c++11") 12 | endif() 13 | # SET (CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") 14 | # SET (CMAKE_SHARED_LINKER_FLAGS "-static-libgcc -static-libstdc++") 15 | -------------------------------------------------------------------------------- /cmake/CombineHeader.cmake: -------------------------------------------------------------------------------- 1 | 2 | 3 | ADD_CUSTOM_TARGET(header 4 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../ExIconv/include header 5 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../Lex/include header 6 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../LR_Scanner/includes header 7 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../RedApple/includes header 8 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../Builder/include header 9 | COMMAND ${CMAKE_COMMAND} -E copy_directory ../MetaScriptRunner/include header 10 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 11 | COMMENT "Generating headers" 12 | VERBATIM) 13 | 14 | install(DIRECTORY 15 | ${CMAKE_CURRENT_SOURCE_DIR}/build/header 16 | DESTINATION . 17 | FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 18 | GROUP_EXECUTE GROUP_READ WORLD_READ 19 | DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ 20 | GROUP_EXECUTE GROUP_READ WORLD_READ 21 | COMPONENT header 22 | PATTERN ".git" EXCLUDE) 23 | -------------------------------------------------------------------------------- /cmake/MSVCConf.cmake: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/cmake/MSVCConf.cmake -------------------------------------------------------------------------------- /cmake/ThirdPartyBuild.cmake: -------------------------------------------------------------------------------- 1 | include(cmake/ExternalProject.cmake) 2 | 3 | set (third_party_install_path ${CMAKE_CURRENT_SOURCE_DIR}/extlib) 4 | 5 | if (UNIX) 6 | 7 | ExternalProject_Add(libiconv 8 | DOWNLOAD_DIR third_party/ 9 | GIT_REPOSITORY https://github.com/elite-lang/libiconv 10 | SOURCE_DIR third_party/libiconv/ 11 | CMAKE_COMMAND cmake 12 | CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${third_party_install_path} 13 | # INSTALL_COMMAND "" 14 | BUILD_ALWAYS 0 15 | ) 16 | 17 | elseif(WIN32) 18 | 19 | ExternalProject_Add(libiconv 20 | DOWNLOAD_DIR third_party/ 21 | GIT_REPOSITORY https://github.com/elite-lang/libiconv 22 | GIT_TAG Windows-x86 23 | CONFIGURE_COMMAND "" 24 | SOURCE_DIR third_party/libiconv/ 25 | BUILD_COMMAND "cp_libs.bat" 26 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/third_party/libiconv/" 27 | INSTALL_COMMAND "" 28 | ) 29 | 30 | endif() 31 | 32 | 33 | 34 | ExternalProject_Add(libcharsetdetect 35 | DOWNLOAD_DIR third_party/ 36 | GIT_REPOSITORY https://github.com/elite-lang/libcharsetdetect 37 | SOURCE_DIR third_party/libcharsetdetect/ 38 | CMAKE_COMMAND cmake 39 | CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${third_party_install_path} 40 | # INSTALL_COMMAND "" 41 | BUILD_ALWAYS 0 42 | ) 43 | 44 | ExternalProject_Add(liblua 45 | DOWNLOAD_DIR third_party/ 46 | GIT_REPOSITORY https://github.com/elite-lang/lua 47 | SOURCE_DIR third_party/lua/ 48 | CMAKE_COMMAND cmake 49 | CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=${third_party_install_path} 50 | # INSTALL_COMMAND "" 51 | BUILD_ALWAYS 0 52 | ) 53 | 54 | 55 | 56 | 57 | 58 | 59 | ## oolua的构建 60 | if (APPLE) 61 | set(OOLUA_BUILD_COMMAND make "mac") 62 | elseif (UNIX) 63 | set(OOLUA_BUILD_COMMAND make "linux") 64 | elseif (MSVC) 65 | if(MSVC12) 66 | set(OOLUA_BUILD_COMMAND "vs2013x86_build.bat") 67 | elseif(MSVC14) 68 | set(OOLUA_BUILD_COMMAND "vs2015x86_build.bat") 69 | endif() 70 | endif() 71 | 72 | ExternalProject_Add(liboolua 73 | DEPENDS liblua 74 | DOWNLOAD_DIR third_party/ 75 | GIT_REPOSITORY https://github.com/elite-lang/oolua 76 | SOURCE_DIR third_party/oolua/ 77 | CONFIGURE_COMMAND "" 78 | BUILD_COMMAND ${OOLUA_BUILD_COMMAND} 79 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/third_party/oolua/build_scripts/" 80 | INSTALL_COMMAND "" 81 | INSTALL_DIR ${third_party_install_path} 82 | ) 83 | 84 | if (UNIX) 85 | set(COPY_OOLUA_LIB_COMMAND make "cp-unix") 86 | elseif(WIN32) 87 | set(COPY_OOLUA_LIB_COMMAND "cp_win32.bat") 88 | endif() 89 | 90 | ## 在完成编译后,复制库 91 | add_custom_command(OUTPUT copy-liboolua 92 | DEPENDS liboolua 93 | COMMAND ${COPY_OOLUA_LIB_COMMAND} 94 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/third_party/oolua/build_scripts/" 95 | COMMENT "comment" 96 | ) 97 | 98 | 99 | 100 | 101 | 102 | ExternalProject_Add(libdyncall 103 | DOWNLOAD_DIR third_party/ 104 | GIT_REPOSITORY https://github.com/elite-lang/dyncall 105 | SOURCE_DIR third_party/dyncall/ 106 | CMAKE_COMMAND cmake 107 | CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${third_party_install_path} 108 | # INSTALL_COMMAND "" 109 | BUILD_ALWAYS 0 110 | ) 111 | 112 | 113 | # ExternalProject_Add(bdwgc 114 | # DOWNLOAD_DIR third_party/ 115 | # GIT_REPOSITORY https://github.com/elite-lang/bdwgc 116 | # SOURCE_DIR third_party/bdwgc/ 117 | # CMAKE_COMMAND cmake 118 | # CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${third_party_install_path}" 119 | # # INSTALL_COMMAND "" 120 | # BUILD_ALWAYS 0 121 | # ) 122 | 123 | ADD_CUSTOM_TARGET(deps 124 | DEPENDS liblua libiconv libcharsetdetect copy-liboolua libdyncall 125 | ) 126 | -------------------------------------------------------------------------------- /cmake/UnixGlib.cmake: -------------------------------------------------------------------------------- 1 | find_package(PkgConfig) 2 | pkg_check_modules(GLIBMM glibmm-2.4 giomm-2.4) 3 | link_directories(${GLIBMM_LIBRARY_DIRS}) 4 | include_directories(${GLIBMM_INCLUDE_DIRS}) -------------------------------------------------------------------------------- /cmake/UnixLLVM.cmake: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGETS_TO_BUILD X86) 2 | set(LLVM_BUILD_RUNTIME OFF) 3 | set(LLVM_BUILD_TOOLS OFF) 4 | 5 | SET (CMAKE_PREFIX_PATH /usr/local/Cellar/llvm/3.6.2/share/llvm) # fix apple 6 | 7 | find_package(LLVM 3.6 REQUIRED CONFIG) 8 | message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") 9 | message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") 10 | 11 | include_directories(${LLVM_INCLUDE_DIRS}) 12 | add_definitions(${LLVM_DEFINITIONS}) 13 | # Find the libraries that correspond to the LLVM components 14 | # that we wish to use 15 | llvm_map_components_to_libnames(LLVM_LIBS 16 | support core irreader executionengine interpreter 17 | mc mcjit bitwriter x86codegen target native) 18 | -------------------------------------------------------------------------------- /cmake/WindowsLLVM.cmake: -------------------------------------------------------------------------------- 1 | set(LLVM_TARGETS_TO_BUILD X86) 2 | set(LLVM_BUILD_RUNTIME OFF) 3 | set(LLVM_BUILD_TOOLS OFF) 4 | 5 | SET (CMAKE_PREFIX_PATH "${LLVM_SDK_PATH}\\share\\llvm\\cmake") # fix windows 6 | 7 | find_package(LLVM ${LLVM_VERSION} REQUIRED CONFIG) 8 | message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") 9 | message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") 10 | 11 | include_directories(${LLVM_INCLUDE_DIRS}) 12 | add_definitions(${LLVM_DEFINITIONS}) 13 | # Find the libraries that correspond to the LLVM components 14 | # that we wish to use 15 | llvm_map_components_to_libnames(LLVM_LIBS 16 | support core irreader executionengine interpreter 17 | mc mcjit bitwriter x86codegen target native) 18 | -------------------------------------------------------------------------------- /conf/lex.cfg: -------------------------------------------------------------------------------- 1 | int= [0-9]+|0x[0-9A-Fa-f]+ 2 | float= [0-9]*\.[0-9]* 3 | string= \"([^\n\"])*\" 4 | string_nt= @\"([^\n\"])*\" 5 | id= [a-zA-Z_\u4e00-\u9fff][a-zA-Z0-9_\u4e00-\u9fff]* 6 | opta= \+=|\-= 7 | optb= = 8 | optc= [*/%] 9 | optd= [+\-] 10 | opte= >|<|<=|>=|==|!=|\+\+|\-\- 11 | optf= &|&&|\||\|\||!|~ 12 | optg= [\.@`] 13 | sz= \[\] 14 | kh= \[|\] 15 | other= [(){},;:] 16 | script= #[^\n]*\n 17 | ignore= \s+|\/\/[^\n]*\n 18 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FIND_PACKAGE(Doxygen) 2 | OPTION(BUILD_DOCUMENTATION "Create and install the HTML based API documentation (requires Doxygen)" ${DOXYGEN_FOUND}) 3 | 4 | IF(BUILD_DOCUMENTATION) 5 | IF(NOT DOXYGEN_FOUND) 6 | MESSAGE(FATAL_ERROR "Doxygen is needed to build the documentation.") 7 | ENDIF() 8 | 9 | CONFIGURE_FILE(Doxyfile.in Doxyfile @ONLY) 10 | CONFIGURE_FILE(Doxyfile.zh-cn.in Doxyfile.zh-cn @ONLY) 11 | 12 | file(GLOB_RECURSE MARKDOWN_DOC ${PROJECT_SOURCE_DIR}/doc/*.md) 13 | 14 | add_custom_command(OUTPUT html 15 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile 16 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.zh-cn 17 | DEPENDS ${MARKDOWN_DOC} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile* 18 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 19 | ) 20 | 21 | ADD_CUSTOM_TARGET(doc 22 | ALL DEPENDS html 23 | COMMENT "Generating API documentation with Doxygen" 24 | VERBATIM) 25 | 26 | INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/build-doc/html DESTINATION doc COMPONENT doc) 27 | ENDIF() 28 | -------------------------------------------------------------------------------- /doc/Doxyfile.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "@CMAKE_PROJECT_NAME@" 2 | PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_RELEASE@ 3 | STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ 4 | INPUT = @doxy_main_page@ \ 5 | @PROJECT_SOURCE_DIR@ 6 | OUTPUT_DIRECTORY = @PROJECT_SOURCE_DIR@/build-doc 7 | FILE_PATTERNS = *.h \ 8 | *.cpp \ 9 | *.en.md 10 | IMAGE_PATH = ./doc 11 | OUTPUT_LANGUAGE = English 12 | RECURSIVE = YES 13 | EXTRACT_ALL = YES 14 | EXTRACT_PRIVATE = YES 15 | EXTRACT_STATIC = YES 16 | BRIEF_MEMBER_DESC = YES 17 | REPEAT_BRIEF = YES 18 | EXCLUDE_PATTERNS = extlib build bin third_party cmake example lib header_libs 19 | USE_MDFILE_AS_MAINPAGE = index.en.md 20 | SEARCHENGINE = YES 21 | SERVER_BASED_SEARCH = NO 22 | REFERENCED_BY_RELATION = YES 23 | REFERENCES_RELATION = YES 24 | 25 | #--------------------------------------------------------------------------- 26 | # Configuration options related to the HTML output 27 | #--------------------------------------------------------------------------- 28 | 29 | GENERATE_HTML = YES 30 | HTML_OUTPUT = html 31 | HTML_FILE_EXTENSION = .html 32 | HTML_HEADER = ./doc/misc/header.html 33 | HTML_FOOTER = ./doc/misc/footer.html 34 | HTML_EXTRA_STYLESHEET = ./doc/misc/doxygenextra.css 35 | HTML_TIMESTAMP = YES 36 | DISABLE_INDEX = YES 37 | GENERATE_TREEVIEW = YES 38 | TREEVIEW_WIDTH = 250 39 | 40 | GENERATE_LATEX = NO 41 | GENERATE_RTF = NO 42 | GENERATE_MAN = NO 43 | GENERATE_XML = NO 44 | -------------------------------------------------------------------------------- /doc/Doxyfile.zh-cn.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "@CMAKE_PROJECT_NAME@" 2 | PROJECT_NUMBER = @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_RELEASE@ 3 | STRIP_FROM_PATH = @PROJECT_SOURCE_DIR@ 4 | INPUT = @doxy_main_page@ \ 5 | @PROJECT_SOURCE_DIR@ 6 | OUTPUT_DIRECTORY = @PROJECT_SOURCE_DIR@/build-doc 7 | FILE_PATTERNS = *.h \ 8 | *.cpp \ 9 | *.zh-cn.md 10 | 11 | IMAGE_PATH = ./doc 12 | OUTPUT_LANGUAGE = Chinese 13 | RECURSIVE = YES 14 | EXTRACT_ALL = YES 15 | EXTRACT_PRIVATE = YES 16 | EXTRACT_STATIC = YES 17 | BRIEF_MEMBER_DESC = YES 18 | REPEAT_BRIEF = YES 19 | BUILTIN_STL_SUPPORT = YES 20 | EXCLUDE_PATTERNS = extlib build bin third_party cmake example lib header_libs 21 | USE_MDFILE_AS_MAINPAGE = index.zh-cn.md 22 | SEARCHENGINE = YES 23 | SERVER_BASED_SEARCH = NO 24 | REFERENCED_BY_RELATION = YES 25 | REFERENCES_RELATION = YES 26 | 27 | #--------------------------------------------------------------------------- 28 | # Configuration options related to the HTML output 29 | #--------------------------------------------------------------------------- 30 | 31 | GENERATE_HTML = YES 32 | HTML_OUTPUT = html/zh-cn 33 | HTML_FILE_EXTENSION = .html 34 | HTML_HEADER = ./doc/misc/header.html 35 | HTML_FOOTER = ./doc/misc/footer.html 36 | HTML_EXTRA_STYLESHEET = ./doc/misc/doxygenextra.css 37 | HTML_TIMESTAMP = YES 38 | DISABLE_INDEX = YES 39 | GENERATE_TREEVIEW = YES 40 | TREEVIEW_WIDTH = 250 41 | 42 | GENERATE_LATEX = NO 43 | GENERATE_RTF = NO 44 | GENERATE_MAN = NO 45 | GENERATE_XML = NO 46 | -------------------------------------------------------------------------------- /doc/_1_introduce.zh-cn.md: -------------------------------------------------------------------------------- 1 | Elite项目简介 {#md-introduce} 2 | =============== 3 | 4 | Elite是一款编译器,同时也具有编译器生成器的功能,提供类似 [yacc] 和 [lex]的功能,能够解析用户自定义语法,并生成使用LALR分析法的编译器,做到了灵活多遍的语法形式。后端则依托 [LLVM] 项目,实现了编译到llvm字节码的功能,并通过调用llvm工具链,最终生成机器码或通过jit解释执行。 5 | 6 | ## Elite语言特性 7 | 8 | 1. 为用户保留了语法配置脚本、词法配置脚本接口,用来让用户自定义语言。 9 | 2. 使用lua作为元脚本,这是运行在编译器上的脚本,可以控制编译动作和编译器的工作方式。 10 | 3. 使用 [LLVM] 作为后端代码生成器和跨平台的中间语言。生成的LLVM的bc文件( [LLVM-IR] ),可以被打包成Elite的程序库。 11 | 4. Elite是一门带有元数据的语言,拥有运行时环境,可以支持反射调用等功能。 12 | 5. Elite拥有原生调用C函数的功能,可以和C库无缝链接到一起,生成最终的可执行程序。 13 | 6. Elite拥有强大的宏支持,可以像lisp一样对代码在编译时进行处理 14 | 7. Elite是编译型语言,生成的可执行程序是原生的,不依赖虚拟机。 15 | 8. ELite也可以实现脚本化和Jit,但该部分还在开发中 16 | 9. ELite是多遍翻译的语言,无需前向声明 17 | 18 | ## Elite项目的结构 19 | 20 | Elite项目为了实现可自定义语法这一特性,自行开发了词法分析器、语言分析器、后端代码生成器等组件,通过宏翻译机制,控制代码的生成。 21 | 22 | 宏翻译是Elite项目中关键的概念,词法分析器和语法分析器,有点像lex和bison,但它们是脚本化的,更加灵活,语法翻译的配置脚本类似下面的: 23 | 24 | = "while" "(" ")" 25 | {{ return makeList(newIDNode("while"), exp, s); }} 26 | ; 27 | 28 | 29 | 这是一条while语句,语言动作要去控制生成一棵语法树,而这个语法树是类似lisp风格的,由宏组织而成的结构: 30 | 31 | (while (exp-state...) (statement...)) 32 | 33 | 34 | 这样的结构,能够被后端代码生成器识别,然后正确的翻译成一条语句 35 | 36 | 37 | ## 跨平台支持 38 | 39 | 我们的项目从一开始就考虑了跨平台的问题,Windows、Macos、Linux下都可以开发,支持VS2013版以后,gcc4.8以后,clang3.0以后,都可以开发我们的项目。 40 | 41 | ## 开发工具和语言 42 | 43 | 主要使用的语言是C++11,还附带嵌入式lua,部分GUI项目是用js开发的。 44 | 项目最初是在Ubuntu14.04的环境下开发的,目前Linux下的开发较多,其他系统的环境的工具链需要使用时手动配置一下。 45 | 主要的开发工具是clang套件和llvm套件。大部分依赖项我们都已经设置好git仓库地址,编译时会自动下载并编译。 46 | 47 | [yacc]: http://dinosaur.compilertools.net/yacc/ "yacc" 48 | [lex]: http://dinosaur.compilertools.net/lex/ "lex" 49 | [LLVM]: http://llvm.org/ "LLVM" 50 | [LLVM-IR]: http://llvm.org/docs/LangRef.html "LLVM-IR" 51 | -------------------------------------------------------------------------------- /doc/_2_user_manual.zh-cn.md: -------------------------------------------------------------------------------- 1 | 用户帮助手册 {#md-user-manual} 2 | ============ 3 | 4 | 5 | ### 目录 6 | 7 | - @subpage md-install 8 | - @subpage md-default-lang-ref 9 | - @subpage md-lex 10 | - @subpage md-parser 11 | 12 | 13 | ### 关于本手册 ### 14 | 15 | 本手册适合希望使用,了解Elite语言,使用Elite开发其他项目的开发者。 16 | 本文档提供中英双语版,也欢迎贡献其他语言的翻译文档。 17 | 18 | - [English Documents](../index.html) 19 | - [中文文档](#) 20 | -------------------------------------------------------------------------------- /doc/_3_developers_manual.zh-cn.md: -------------------------------------------------------------------------------- 1 | 开发者文档 {#md-develop} 2 | =============== 3 | 4 | 对于每一位贡献者,非常感谢您在百忙之中帮助改进我们的项目。Elite是一款开源软件,我们欢迎任何人帮助我们完善本项目。同时也欢迎您提出任何的意见和建议,帮助我们改进。 5 | 6 | ### 目录 ### 7 | 8 | - @subpage md-proj-struct 9 | - @subpage md-doc 10 | - @subpage md-test 11 | 12 | 13 | ### 贡献本项目 ### 14 | 15 | 如果您是一位开发者,欢迎您帮助我们改进项目,再小的改变都值得我们尊敬。如果您是一位设计师或美术设计人员,欢迎您帮助我们改进项目宣传,包括Logo设计、网页美术设计、帮助文档风格设计。如果您想帮助我们,或与我们洽谈,请与我们联系: 16 | 17 | - github: 18 | - 邮箱: 19 | - gitter:[参与讨论](https://gitter.im/elite-lang/Elite?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 20 | 21 | 贡献代码的流程非常简单,首先您需要从github上fork我们的项目到您的github账户中,通过阅读文档和相关讨论,了解到您具体要添加或修改的内容,您将代码修改完毕并传到您的仓库后,向我们的仓库发送PR即可。 22 | 23 | 贡献代码需要注意的几点: 24 | 25 | - 在您添加一个功能或修改一个功能前,建议您先发一个Issue或任意形式与我们讨论,这样可以避免不同的人实现了相同的功能 26 | - 在您发送PR时,请填写好对应的Commit Message,让我们了解到您希望修改的内容 27 | - 不建议发送大PR,这会造成我们难以测试和审核您的修改 28 | - 如果您希望长期参与此项目,欢迎您加入到开发者团队,有经验的开发者我们会给予更高的项目修改及审核PR的权限 29 | 30 | 31 | 32 | ### 捐助本项目 ### 33 | 34 | 如果您觉得本项目确实能为您的公司提供更好的工具,更方便您的使用,欢迎您捐助本项目。您的捐款能够让项目得到更多的资源,包括更优质的服务器、开发设备、全职的维护人员等,这将促进项目更快的发展,得到更好的维护。从而使得开发者和用户得到双赢,我们也将能够为企业提供更加优秀的开发工具和服务。 35 | 36 | 37 | 38 | ### 关于本手册 ### 39 | 40 | 本手册适合希望开发Elite语言,为Elite增加扩展,修改Elite底层结构的开发者阅读。 41 | 本文档提供中英双语版,也欢迎贡献其他语言的翻译文档。 42 | 43 | - [English Documents](../index.html) 44 | - [中文文档](#) 45 | -------------------------------------------------------------------------------- /doc/design/Elite语言-原创宏翻译语言.md: -------------------------------------------------------------------------------- 1 | Elite语言-原创宏翻译语言 2 | ======================= 3 | 4 | 5 | ## Elite语言正在解决哪方面的问题 6 | 7 | 在专用编程中,有很多东西很难用通用编程语言去描述,人们为了在通用语言中描述这些不好描述的内容,创建了配置文件。然而一旦不好描述的部分占了主体,那么势必造成配置过于繁琐,使用过于复杂等问题。针对这种情况,一般会开发领域专用语言,但问题依旧存在。领域专用语言,难以和通用语言例如C、Java,进行通信,较难使用可靠的开发库。 8 | 9 | Elite是一款可自定语法的编程语言,通过自行配置语法,能够方便的定制需要的语言形式,从而将自己包装成一款领域专用语言,包装后的语言拥有和通用语言一样的编程能力,但又多了自定义的语法形式,避免了过度使用配置文档的问题。 10 | 11 | ## 什么项目适合用Elite开发 12 | 13 | 1. 专业领域的程序库 14 | 2. 具有复杂难以理解配置项的软件包 15 | 3. 拥有复杂抽象模型的软件框架 16 | 4. 快速开发编译器语法原型 17 | 5. 拥有特定语法的交互式控制台程序 18 | 19 | 20 | ## Elite语言特性 21 | 22 | 1. 为用户保留了语法配置脚本、词法配置脚本接口,用来让用户自定义语言。 23 | 2. 使用lua作为元脚本,这是运行在编译器上的脚本,可以控制编译动作和编译器的工作方式。 24 | 3. 使用LLVM作为后端代码生成器和跨平台的中间语言。生成的LLVM的bc文件,可以被打包成Elite的程序库。 25 | 4. Elite是一门带有元数据的语言,拥有运行时环境,可以支持反射调用等功能。 26 | 5. Elite拥有原生调用C函数的功能,可以和C库无缝链接到一起,生成最终的可执行程序。 27 | 6. Elite拥有强大的宏支持,可以像lisp一样对代码在编译时进行处理 28 | 7. Elite是编译型语言,生成的可执行程序是原生的,不依赖虚拟机。 29 | 8. ELite也可以实现脚本化和Jit,但该部分还在开发中 30 | 9. ELite是多遍翻译的语言,无需前向声明 31 | 32 | ## Elite项目的结构 33 | 34 | Elite项目为了实现可自定义语法这一特性,自行开发了词法分析器、语言分析器、后端代码生成器等组件,通过宏翻译机制,控制代码的生成。 35 | 36 | 宏翻译是Elite项目中关键的概念,词法分析器和语法分析器,有点像lex和bison,但它们是脚本化的,更加灵活,语法翻译的配置脚本类似下面的: 37 | 38 | ``` 39 | = "while" "(" ")" 40 | {{ return makeList(newIDNode("while"), exp, s); }} 41 | ; 42 | ``` 43 | 44 | 这是一条while语句,语言动作要去控制生成一棵语法树,而这个语法树是类似lisp风格的,由宏组织而成的结构: 45 | 46 | ``` 47 | (while (exp-state...) (statement...)) 48 | ``` 49 | 50 | 这样的结构,能够被后端代码生成器识别,然后正确的翻译成一条语句 51 | 52 | 53 | ## 跨平台支持 54 | 55 | 我们的项目从一开始就考虑了跨平台的问题,Windows、Macos、Linux下都可以开发,支持VS2013版以后,gcc4.8以后,clang3.0以后,都可以开发我们的项目。 56 | 57 | ## 开发工具和语言 58 | 59 | 主要使用的语言是C++11,还附带嵌入式lua,部分GUI项目是用js开发的。 60 | 项目最初是在Ubuntu14.04的环境下开发的,目前Linux下的开发较多,其他系统的环境的工具链需要使用时手动配置一下。 61 | 主要的开发工具是clang套件和llvm套件。大部分依赖项我们都已经设置好git仓库地址,编译时会自动下载并编译。 62 | 63 | ## 加入我们 64 | 65 | 目前,项目还处于开发初期,非常欢迎热爱开源的朋友们参加此项目,这是一个中等规模的C++项目,加入我们的团队,不但能够促进该项目更快的发展,更能带给您不一样的思路和体验。 66 | 67 | 希望和我们交流非常容易,可以选择发邮件或在github上直接和我们联系,都可以。 68 | 69 | 邮箱:sun_xfancy@gmail.com 70 | 71 | 72 | ## 开源协议 73 | 74 | MIT协议,允许任何人基于该项目开发其他项目,无论是开源的还是商业的,仅仅需要您在使用时,附带我们的版权声明即可。 75 | 76 | -------------------------------------------------------------------------------- /doc/design/TODO.md: -------------------------------------------------------------------------------- 1 | 2 | # 项目简介 3 | 4 | ## 模块化组织整个项目 5 | 6 | 目前划分的模块有 7 | 8 | 元脚本执行器 9 | 词法分析器 10 | 语法分析器 11 | 构建管理器 12 | 后端宏解析器 13 | 14 | 15 | ## 项目依赖项 16 | 文本解析转码库 libiconv1.14 libcharsetdetect 17 | LLVM3.6平台 18 | Lua5.2 19 | flex bison 20 | 21 | # 目前需要进行的工作 22 | 23 | ## 核心任务 24 | 25 | 1. 项目构建器 Builder的完善 ok 26 | 项目构建目前仅能进行单个文件的编译,要实现类似Java的编译方式,给定一个文件夹,编译好最终程序 27 | 28 | 2. 元脚本解析器的完善 29 | 添加更多的可用的元脚本命令,控制编译器编译过程,查看中间变量 30 | 希望添加完整的元脚本控制RedApple宏翻译功能 31 | 32 | 3. 词法分析器的结构优化 ok 33 | 词法分析器结构有些混乱,需要优化结构,整理代码 34 | 35 | 4. 垃圾回收器的加入 ok 36 | 添加手动垃圾delete指令,和保守的垃圾回收器,先避免内存的泄露再说 37 | 38 | 5. 自动化项目构建 ok 39 | 考虑如何自动化构建项目成可用状态,尝试使用travis-ci 40 | 41 | 6. 集成测试 ok 42 | 使用黑盒测试的思路,给定要编译的代码,和其输出的结果,通过编译运行,判断系统工作是否正常 43 | 44 | 7. 添加扩展包 ok 45 | 使用lua进行功能扩展,提供不同语言特性的分离导入 46 | 47 | 8. 中间过程的导出 ok 48 | 使用log模块导出中间调试数据,用作EliteShow的展示 49 | 50 | 9. 添加break语句, 终止循环 ok 51 | 52 | 10. 添加switch, do while, do until语句 53 | 54 | 11. 添加包和函数名修饰 55 | 56 | 57 | ## 次要任务 58 | 59 | 1. 编译器输入参数的处理,目前输入参数有误时没有提示信息 60 | 2. 元脚本解析器的异常处理不足,lua异常没有捕获 61 | 3. 大量的测试任务,建议使用GTest库 62 | 4. 各平台工具链的整合 ok 63 | 5. 各平台运行时库的整合 64 | 6. RedApple的对象模型 65 | 7. RedApple的反射类的接口 ok 66 | 8. 构建脚本太过粗糙,需要改进 ok 67 | 9. Builder中提供查找并调用工具链的功能 ok 68 | 10. 添加JVM平台的相关支持 (方案待定) 69 | 11. 添加continuations(协程)的支持 70 | 12. 添加闭包特性 71 | 13. 添加函数的柯里化包装 72 | 14. 符号重载机制 73 | 15. 类型转换机制和泛类型 74 | -------------------------------------------------------------------------------- /doc/design/使用Elite开发您的Hello World.md: -------------------------------------------------------------------------------- 1 | 使用Elite开发您的Hello World 2 | =========================== 3 | 4 | 一个hello world是多么的鼓舞人心! 5 | 6 | 首先,您需要安装Elite编译器,在bin目录下生成有elite程序,如果您想从源码编译安装,那么您需要参考文档中的:项目构建 7 | 8 | 在首次安装好后,您需要配置环境变量: 9 | 10 | // for elite 11 | export ELITE_HOME=【您的Elite仓库地址】 12 | export PATH=$ELITE_HOME/bin:$ELITE_HOME/tools:$PATH 13 | 14 | 15 | ## 编写hello.elite 16 | 17 | ~~~cpp 18 | void hello() { 19 | printf("hello world"); 20 | } 21 | 22 | void main() { 23 | hello(); 24 | } 25 | ~~~ 26 | 27 | ## 执行编译命令 28 | 29 | elite -i hello.elite 30 | 31 | 32 | `-i`参数是目前唯一能用的编译参数,指定编译某一个文件,日后我们会开发一次编译整个目录 33 | 34 | 于是我们会看到生成的`hello.bc`和元数据`meta.bc` 35 | 36 | 如果您不需要使用反射的话,可用直接使用`llc`工具,将其编译成`.o`文件: 37 | 38 | llc hello.bc -filetype=obj 39 | 40 | 最后一步链接,可用使用gcc或ld进行链接: 41 | 42 | gcc hello.o -o hello 43 | 44 | 45 | 即可生成最后的目标程序,执行一下看看效果吧: 46 | 47 | ./hello 48 | -------------------------------------------------------------------------------- /doc/design/元脚本的特殊用法.md: -------------------------------------------------------------------------------- 1 | 元脚本的特殊用法 2 | =============== 3 | 4 | 首先, 元脚本是编译器执行的脚本, 工作时间为代码文本的语法解析时, 在遇到符合元脚本格式的行时, 就会触发元脚本执行命令. 5 | 6 | 元脚本可以做什么事情呢? 7 | 8 | ## 代码选择性编译及模板式 9 | 10 | 类型C的宏系统, 但由于是脚本引擎, 功能更加丰富. 11 | 12 | # if (RELEASE) then 13 | 14 | void print() { 15 | 16 | } 17 | 18 | # end 19 | 20 | 问题的难点在于if语句的执行问题, 如何让接下来的代码被执行 21 | 一个非常简单的思路就是,将非脚本引擎部分的代码转为函数调用中的数据进行处理 22 | 23 | ## 语法树节点的修改 24 | 25 | 由于是对应时间的处理, 需要用回调形式, 插入到对应的时间点的脚本执行中. 26 | 对应节点的选择和处理, 可以参考jQuery的设计 27 | 28 | BeforeMain(function(node) 29 | local fnode = node.select('name=function p1=hello') 30 | ... 31 | end) 32 | 33 | 34 | ## 和宏模型通信 35 | 36 | 宏模型中可以在宏解析时调用元脚本编写的函数 37 | 38 | void print(int k) { 39 | @for_n (i, k) { 40 | printf("hello-%d\n", i); 41 | } 42 | } 43 | 44 | defmacro for_n (p, size, code) { 45 | for (int p = 1; p <= size; p = p+1) 46 | @add_break(code); // 这里是在调用lua函数 47 | } 48 | 49 | 50 | void main() { 51 | FunctionCall("print", 5); 52 | } 53 | 54 | 55 | ## 考虑单独构建一个预处理单元 56 | -------------------------------------------------------------------------------- /doc/design/函数名重载的设计方案.md: -------------------------------------------------------------------------------- 1 | 2 | C语言不支持函数名重载,这点有些不方便,但其实也有优势,在底层调用时,可以很方便的被各种语言识别,不会出现签名与函数不符的现象. 3 | 4 | 为了同时兼顾签名的可辨识性,又能做到唯一定位,同时支持重载,Elite语言使用如下规则 5 | 6 | 函数名: 7 | 包名 + 类名 + 函数名 + 函数备注名 8 | 函数真实名时,各个元素中间用下划线`_`隔开 9 | 语言内名,各个元素中间使用`.`隔开 10 | 11 | 例如: 12 | 13 | org.hha.NetRobot.connect.tcp() 14 | 15 | C 调用时签名: 16 | 17 | org_hha_NetRobot_connect_tcp() 18 | 19 | 20 | 最后函数备注名是重载用的,我们可以这样写 21 | 22 | void hello.t2() { 23 | 24 | } 25 | 26 | void Run() { 27 | hello(); 28 | } 29 | 30 | 编译器会自动选择多个重载名中合理的函数,但必须能唯一确定为其中一个函数. 31 | -------------------------------------------------------------------------------- /doc/design/各项目文件夹的命名习惯及约定.md: -------------------------------------------------------------------------------- 1 | 各项目文件夹的命名习惯及约定 2 | ========================== 3 | 4 | 无论是子项目还是主项目,各文件夹都有几乎一致的命名方式和含义,下面简要阐述: 5 | 6 | | 目录 | 功能简介 | 7 | | --- | --- | 8 | | src | 源文件目录,用来存放‘cpp’源码和不需要公开接口的‘.h’头文件 | 9 | | include | 公开类的头文件和接口文件 | 10 | | doc | 文档目录,一般是手写文档和文档图片资源的存放 | 11 | | conf | 配置文件 | 12 | | lib | 依赖的库文件,既有自己的组件,也有其他项目库 | 13 | | scripts | 脚本文件 | 14 | | tools | 工具链目录 | 15 | | test | 单元测试文件目录 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/design/常量表达式特性.md: -------------------------------------------------------------------------------- 1 | 2 | 常量表达式是一个不错的特性,我们希望编译器能够在编译时做某些事情,让代码更丰富。 3 | 常量表达式可以求取编译过程中的量,然后将其常量化到程序中,最终生成目标机器代码,这和宏做的事情有类似之处。 4 | 但常量表达式远比宏来的安全,并且我们希望常量表达式能够添加无副作用检测,使得常量表达式能够安全的使用。 5 | 6 | 并且常量表达式同样可以程序库化,方便引用这些特性。 7 | 关注C++11新特性,constexpr 8 | -------------------------------------------------------------------------------- /doc/design/构建过程描述文档.md: -------------------------------------------------------------------------------- 1 | 2 | Elite的构建较为复杂,需要多遍扫描不同的文件。 3 | 4 | ## 代码源文件 5 | 6 | Elite语言的源文件分为如下几种: 7 | 8 | 1. 配置文件 *.cfg 用作词法分析器和语法分析器的配置文件 9 | 2. Elite标准源文件 *.ecode 源文件,里面可以有全局函数、宏、结构体、局部类等 10 | 3. Elite类文件 *.eclass 类文件,可以包含源文件中能包含的全部,但必须包含一个公开的类或接口 11 | 4. Elite编译脚本 *.escript 编译脚本文件,实质上lua代码(暂时不更名,使用lua的后缀) 12 | 5. Elite库文件 *.elib ebc文件的带目录集合体,实质是zip压缩包 13 | 6. Elite编译后文件 *.ebc 编译后的字节码文件,带有反射用的基本信息,而且跨平台易移植。 14 | 7. Elite头文件 *.eh 编译时用来像C语言中.h一样引用用的头文件,可做宏的定义文件使用。 15 | 16 | ## 路径配置 17 | 18 | SDK路径 - 系统环境变量 19 | 源文件路径 - 编译目录 20 | 库路径 - 链接目录 21 | 生成文件路径 - 构建目录 22 | 编译脚本路径 // 日后实现 23 | 头文件路径 // 日后实现 24 | 25 | ## 编译过程 26 | 27 | 1. 词法分析器扫描全部token 28 | 2. 语法分析器处理语法树生成 29 | 3. 元脚本解析 30 | 4. 预先遍历语法树来生成定义元数据 31 | 5. 遍历全部语法树,生成代码 32 | -------------------------------------------------------------------------------- /doc/design/生成器的实现.md: -------------------------------------------------------------------------------- 1 | 生成器的实现 2 | =========== 3 | 4 | 首先在运行时需要创建一个单例类,开启一个临时堆栈,将SP指针切换到新的位置上, 5 | 然后从这里运行一个函数,或将这个函数挂起 6 | 本质上是一种线程切换的思想,然你需要做的却是手动线程切换 7 | 8 | yield 指令可以设置为保存当前寄存器状态,暂时将当前函数挂起,等到下次调用到该生成器函数时,再次恢复到这里。 9 | 10 | 生成器执行完毕,再没有返回值时,返回NULL,并释放当前堆栈 11 | 12 | 试用一下: libconcurrency libcoro libtask 13 | 14 | 生成器模型其实就是很多脚本语言里面的协程模型,可以看做是手动切换的线程 15 | -------------------------------------------------------------------------------- /doc/design/符号表设计.md: -------------------------------------------------------------------------------- 1 | 使用栈式符号表来管理全部系统符号. 2 | 3 | 符号表会分很多层,从名称空间的角度讲,将会分成: 4 | 5 | 1. 包名称空间 6 | 这层是系统初始化时,就会将整个包的全部全局符号载入 7 | 2. 文件名称空间 8 | 这层是每个代码文件中,标注为static的全局符号,表示在一个文件中有效 9 | 3. 类名称空间 10 | 这层是类名称空间, 适用于类中变量和成员函数 11 | 4. 函数名称空间 12 | 函数下在局部名称空间,包含函数参数和局部变量,局部函数等 13 | 5. 语句名称空间 14 | 例如for语句和while语句等,内部是可以有新的名称空间的 15 | -------------------------------------------------------------------------------- /doc/design/编码转换问题.md: -------------------------------------------------------------------------------- 1 | 编码转换问题 2 | ============== 3 | 4 | 5 | 为了很好的解决中文编程的问题,我们的词法分析器是支持中文的,但仅仅是这样还不够,我们需要确定输入文件的编码,并且将不同编码类型的输入字符串,转换为相同的格式。 6 | 内部编码,我们使用UTF-16编码,由于我们的等价类不能很大,尽量保持较小的映射表比较好。 7 | 8 | 于是我们定义多字符集处理的相关工具,编码转换的相关工具等,然后组织成处理工具类 9 | 10 | 11 | 项目依赖Glib库和Gio库,主要需要其中的utf-8字符串和文件系统功能,遍历查找文件夹等。 12 | 但由于到windows下移植困难,计划移除这两个库,替换为自行打包的字符串处理库和llvm::sys::fs库。 13 | 14 | iconv是一款很方便的C语言编码转换库, LuaDist/libiconv提供了cmake版易于移植的编译脚本 15 | libcharsetdetect是seapower制作的一款编码自动识别库 16 | 两者结合使用, 封装成了简单易用的ExIconv库 17 | 这个库主要提供了Glib::ustring类的替换, estring类, 负责编码的自动识别与格式转换 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/design/编译系统工作流程.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/design/编译系统工作流程.png -------------------------------------------------------------------------------- /doc/design/语言特性包.md: -------------------------------------------------------------------------------- 1 | 语言特性扩展包 2 | ============= 3 | 4 | 首先我们使用脚本化的分析器,主要的目的就是语言特性可扩展,语言特性的扩展是使用lua和词法、语法配置实现的。 5 | 6 | 一个语言特性的实现,可能包含许多部分,既有通用的部分,也有平台相关的,一个语言特性包,那么就需要打包成一个zip,里面带有需要放置的到不同位置的数据和资源,有运行时库,也有编译时库和脚本 7 | 8 | ## 可载入型语言特性扩展包 9 | 10 | 核心包含的内容: 11 | 12 | - 包配置json(名称、版本、作者、描述、是否默认载入,设置启动脚本等) 13 | - lua扩展 14 | - C/C++扩展 15 | - 词法外接脚本 16 | - 语法外接脚本 17 | 18 | 载入规则,自动依次载入根目录全部lua脚本进行执行,可以调用函数申请加入新的外接脚本等 19 | 20 | 扩展包配置需要包含的内容: 21 | 22 | - 名称 23 | - 版本 24 | - 作者 25 | - 描述 26 | - 是否默认载入 27 | - 默认加载时机(初始化前、初始化后、编译前、编译后) 28 | - 依赖项 29 | - 该包的支持平台(可以有多个) 30 | 31 | -------------------------------------------------------------------------------- /doc/design/闭包的实现.md: -------------------------------------------------------------------------------- 1 | 闭包的实现 2 | ============ 3 | 4 | 闭包是函数语言的重要特性,一般依赖对象模型实现,当然我觉得不依赖更好 5 | 6 | ## 函数是闭包的特殊形式 7 | 8 | C语言里函数是不能临时定义的,传递也只能通过函数指针,所以不存在闭包的概念,而现在要制作一个闭包,则较为复杂。闭包是包含外部变量的函数,这个函数引用了父函数中的部分临时变量,并将其作为自己函数的一部分,储存了起来,这样,C函数其实是一种特殊的,不包含任何外部变量捕获的闭包。 9 | 10 | ## 如何在C语言下构造闭包 11 | 12 | 闭包可以是一个仿函数,利用对象来模拟,首先,这个闭包可以是一个结构体: 13 | 14 | ``` 15 | struct run_closure{ 16 | void (*fp)(run_closure* t, void); // 第一个参数是函数指针 17 | // 下面是闭包捕获变量 18 | ... 19 | } 20 | void run(run_closure* t, void) { 21 | ... // code 22 | } 23 | ``` 24 | 25 | 创建时,可以这样创建: 26 | 27 | ``` 28 | run_closure* func = new run_closure(); 29 | func.fp = run; 30 | func.some = some; 31 | func.xxx = xxx; 32 | ``` 33 | 34 | 调用时,发现是一个闭包类型,则调用其中的函数指针即可 35 | 36 | 不依赖对象模型的主要目的是将对象和闭包特性分离开,让用户可以单独选择,使用或不使用闭包类型,如果不使用,则丧失定义局部函数和捕获变量的能力,这点不会影响对象系统的其他行为 37 | -------------------------------------------------------------------------------- /doc/design/静态语言中添加动态性.md: -------------------------------------------------------------------------------- 1 | 如果需要在C语言中使用一些动态性的代码, 我们可以考虑这样定义: 2 | 3 | ``` 4 | struct var { 5 | int type; 6 | union { 7 | void* p; 8 | int i; 9 | double d; 10 | } data; 11 | }; 12 | ``` 13 | 14 | 15 | 系统将为每一种类型都分配一个typeid, 静态类型在赋值时, 会将typeid带上 16 | -------------------------------------------------------------------------------- /doc/design/项目文档的构建.md: -------------------------------------------------------------------------------- 1 | 项目文档的构建 2 | ============== 3 | 4 | 5 | 开源项目为了文档和代码统一,一般需要使用文档构建工具进行文档的统一处理,代码中的注释同时也是重要的文档。 6 | 7 | 本系统使用doxygen进行文档生成,使用前,请安装对应平台的doxygen工具,并将其添加到系统环境目录中。 8 | 9 | ## Doxygen文档的构建 10 | 11 | 由于主项目主要起引导作用,并没有多少实质内容的代码,故不提供文档,各个子项目,分别管理自己的文档。 12 | 13 | 在每个项目的构建目录下,使用cmake生成makefile后,可以执行文档生成指令: 14 | 15 | ``` 16 | make doc 17 | ``` 18 | 这样即可在构建目录`build`下,找到html和latex两个版本的文档,推荐使用html的文档,更加方便。 19 | 20 | 21 | ## 注释文档的编写 22 | 23 | 编写程序时,需要添加对应函数和类的注释,方便其他人阅读理解,在生成文档后,也能形成清晰的函数和类的解释部分,注释格式一般如下: 24 | 25 | ``` 26 | // 简单的注释 27 | /** 28 | * @brief 预先扫描宏时的初始化,初始化第一趟扫描 29 | */ 30 | void PreMacro(); 31 | 32 | // 较复杂的注释 33 | /** 34 | * @brief 添加或替换一条宏 35 | * @details 添加或替换一条宏,如果当前名称存在则替换,没有则添加 36 | * 37 | * @param macro_funcs 一组宏定义数组,类似Lua中函数的定义方式 38 | */ 39 | void AddOrReplaceMacros(const FuncReg* macro_funcs); 40 | 41 | ``` 42 | 43 | 这里,`@brief`是函数的简要说明,一般短小精悍,起到提示函数核心功能的作用。 44 | 而`@details`则是函数详细的说明,介绍函数的功能,边界条件,使用方法等。这里甚至可以放置部分示例代码和罗列可用的参数等。 45 | `@param`则表示一个参数,对参数的功能进行详细的阐述。 46 | 47 | 48 | ## 注释的编写原则 49 | 50 | 注释是为了提示自己和他人,避免遗忘一些函数的使用方法和功能,首先应该编写的是接口和重要类的注释及文档,封装在类内部及成员函数的注释则次之。 51 | 52 | 注释不在多,关键函数一定要有注释,相反则让人一眼就能看懂的函数,或者从名字就知道如何使用的函数则无需编写或简要编写。 53 | 54 | 55 | -------------------------------------------------------------------------------- /doc/design/项目测试.md: -------------------------------------------------------------------------------- 1 | 项目测试 2 | ======== 3 | 4 | 项目使用google test进行测试, 使用前请先安装好google test框架 5 | 6 | ## Ubuntu安装google test 7 | 在项目目录执行: 8 | ``` 9 | sudo sh ./scripts/install_gtest.sh 10 | ``` 11 | 12 | 13 | ## 开启测试 14 | 15 | 用cmake配置时, 添加参数: 16 | 17 | ``` 18 | cd build 19 | cmake -DBUILD_TEST=ON .. 20 | make 21 | ``` 22 | 或者直接: 23 | ``` 24 | make test 25 | ``` 26 | 即可 27 | 28 | 29 | ## 编写测试用例 30 | 31 | 每个子项目下的`test`目录是专门存放测试用例和测试数据的: 32 | 33 | ```cpp 34 | // EstringTest.cpp 35 | #include 36 | #include "estring.h" 37 | 38 | #define __ESTRING_TEST__(name) TEST(EstringTest_##name, name) 39 | 40 | __ESTRING_TEST__(Construction) 41 | { 42 | 43 | } 44 | 45 | ``` 46 | 47 | 48 | -------------------------------------------------------------------------------- /doc/developer/doc.zh-cn.md: -------------------------------------------------------------------------------- 1 | 文档构建 {#md-doc} 2 | ========= 3 | 4 | [TOC] 5 | 6 | 7 | 本项目文档是使用 [doxygen] 工具构建的,全部文档内容使用Markdown和代码内注释进行编写。本章将介绍如何维护本系列文档,以及本机构建文档的方法。 8 | 9 | @section doc-install 安装doxygen工具 10 | 11 | 对于ubuntu和darwin的用户,非常方便,使用控制台即可轻松安装。windows用户和其他版本linux系统请从官网下载安装包。 12 | 13 | ubuntu: 14 | 15 | sudo apt-get install doxygen 16 | 17 | darwin: 18 | 19 | 1. Press Command+Space and type Terminal and press enter/return key. 20 | 2. Run in Terminal app: 21 | 22 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null 23 | 24 | and press enter/return key. Wait for the command to finish. 25 | 26 | 3. Run: `brew install doxygen` 27 | 28 | 其他系统: 29 | 30 | [前往官网下载](https://www.stack.nl/~dimitri/doxygen/download.html) 31 | 32 | @section doc-build 构建项目文档 33 | 34 | 项目文档的构建非常简单,首先在安装好 [doxygen],并确认其指令能够在命令行下使用后,在构建项目时的build文件夹内,执行: 35 | 36 | make doc 37 | 38 | 我们会在`build/doc`路径下构建,并将生成后的html文件放置到build目录外层的`build-doc/html`目录下,由于该文件夹下文件数目过多,建议直接用浏览器输入绝对路径访问: 39 | 40 | file:///%绝对路径%/Elite/build-doc/html/zh-cn/index.html 41 | 42 | 即可查看刚刚生成的中文版文档。英文版文档则去掉路径中的`zh-cn`即可查看 43 | 44 | file:///%绝对路径%/Elite/build-doc/html/index.html 45 | 46 | @section learn-how-to-use 学习如何使用doxygen 47 | 48 | 可以查看doxygen的手册来了解: [doxygen文档] 49 | 50 | 51 | 52 | @section proj-doxygen 本项目的文档编写规范 53 | 54 | 本系列文档是中英双语版,`*.zh-cn.md`为中文版,`*.en.md`为英文版。 55 | 56 | 目前英文版文档还没有开始构建,欢迎英语好的朋友帮忙进行翻译。 57 | 58 | 59 | 注释风格: 60 | 61 | ~~~cpp 62 | /** 63 | * @brief 设置解释器生成中间变量的目录,设置后自动打印中间过程 64 | * 65 | * @param path 设置路径,设置为NULL或不设置则不打印过程 66 | */ 67 | static void setDebugFilePath(const char* path); 68 | ~~~ 69 | 70 | 注释统一编写到头文件中,尽量不要在cpp文件中编写重要的注释。 71 | 72 | cpp中常用的注释往往是遇到了可能的漏洞,或TODO标记,使用示例: 73 | 74 | ~~~cpp 75 | /// FIXME: 这个位置可能产生XXX漏洞 76 | /// TODO: 日后可以添加相关的XXX信息 77 | ~~~ 78 | 79 | 80 | 81 | 82 | [doxygen]: http://www.doxygen.org/ 83 | [doxygen文档]: https://www.stack.nl/~dimitri/doxygen/manual/index.html 84 | -------------------------------------------------------------------------------- /doc/developer/proj_struct.zh-cn.md: -------------------------------------------------------------------------------- 1 | 项目结构介绍 {#md-proj-struct} 2 | ================== 3 | 4 | [TOC] 5 | 6 | 7 | @section proj-struct-folders 各项目文件夹命名习惯及约定 8 | 9 | 无论是子项目还是主项目,各文件夹都有几乎一致的命名方式和含义,下面简要阐述: 10 | 11 | 12 | 目录 | 功能简介 13 | ------- | --------------------------------- 14 | src | 源文件目录,用来存放‘cpp’源码和不需要公开接口的‘.h’头文件 15 | include | 公开类的头文件和接口文件 16 | doc | 文档目录,一般是手写文档和文档图片资源的存放 17 | conf | 配置文件 18 | lib | 依赖的库文件,既有自己的组件,也有其他项目库 19 | scripts | 脚本文件 20 | tools | 工具链目录 21 | test | 单元测试文件目录 22 | -------------------------------------------------------------------------------- /doc/developer/test.zh-cn.md: -------------------------------------------------------------------------------- 1 | 项目测试 {#md-test} 2 | ============== 3 | 4 | [TOC] 5 | 6 | 测试是项目可靠和稳定的保障,目前测试用例尚不完善,欢迎帮忙完善测试代码,编写更全的测试用例。 7 | 8 | @section unit-test 单元测试 9 | 10 | 11 | 项目使用google test进行测试, 使用前请先安装好google test框架 12 | 13 | @subsection test-install-gtest Ubuntu安装google test 14 | 在项目目录执行: 15 | 16 | sudo sh ./scripts/install_gtest.sh 17 | 18 | 19 | @subsection test-open 开启测试 20 | 21 | 用cmake配置时, 添加参数: 22 | 23 | cd build 24 | cmake -DBUILD_TEST=ON .. 25 | make 26 | 27 | 或者直接: 28 | 29 | make test 30 | 31 | 即可 32 | 33 | 34 | @subsection test-dev 编写测试用例 35 | 36 | 每个子项目下的`test`目录是专门存放测试用例和测试数据的: 37 | 38 | ~~~cpp 39 | // EstringTest.cpp 40 | #include 41 | #include "estring.h" 42 | 43 | #define __ESTRING_TEST__(name) TEST(EstringTest_##name, name) 44 | 45 | __ESTRING_TEST__(Construction) 46 | { 47 | estring str("您好"); 48 | string hello("您好"); 49 | estring str2(hello); 50 | } 51 | ~~~ 52 | 53 | 54 | @section full-test 集成测试 55 | 56 | @subsection full-test-run 运行集成测试 57 | 58 | 集成测试需要依赖python2,请提前自行安装好python解释器。 59 | 60 | 然后在项目文件夹下执行 61 | 62 | ./EliteTest/full-test/run_test.py 63 | 64 | 即可运行集成测试。 65 | 66 | 67 | @subsection full-test-dev 编写集成测试用例 68 | 69 | 一个集成测试是由源代码、期待的正确输出结果两部分组成,需要时,还可以增加文件读入。 70 | 源码需要统一命名为`test.elite`,正确的输出结果统一命名为test.out 71 | 72 | full_test目录下可以放任意名称的文件夹作为该测试用例的名字。 73 | -------------------------------------------------------------------------------- /doc/elite.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/elite.ico -------------------------------------------------------------------------------- /doc/index.en.md: -------------------------------------------------------------------------------- 1 | Elite Compiler 2 | ================== 3 | 4 | 5 | 英文文档暂缺翻译, 欢迎您帮助我们完善该部分 6 | -------------------------------------------------------------------------------- /doc/index.zh-cn.md: -------------------------------------------------------------------------------- 1 | Elite - 精锐编译器 2 | ================== 3 | 4 | Elite是一款脚本化驱动的编译器,一般的编程语言,语法是固定的,只能使用有限的表达方式,而Elite的语法并非固定,而是由脚本配置而成的,如果需要,随时都可以自由更改。 5 | 6 | 这个特点,使得Elite非常容易自由开发,成为一款领域专业语言(DSL),在自由配置后,方便地表达专业的相关内容。 7 | 8 | ## 其他语言文档 9 | 10 | - [English Documents](../index.html) 11 | - [中文文档](#) 12 | 13 | ## 下载、使用和贡献代码 14 | 15 | Elite是一款开源项目,任何人都可以免费使用,修改和发布该项目代码,遵循MIT协议。 16 | 17 | - 下载: 18 | - [编译安装指南](md-install.html) 19 | - [贡献本项目](md-develop.html) 20 | 21 | ## Elite语言正在解决哪方面的问题 22 | 23 | 在专用编程中,有很多东西很难用通用编程语言去描述,人们为了在通用语言中描述这些不好描述的内容,创建了配置文件。然而一旦不好描述的部分占了主体,那么势必造成配置过于繁琐,使用过于复杂等问题。针对这种情况,一般会开发领域专用语言,但问题依旧存在。领域专用语言,难以和通用语言例如C、Java,进行通信,较难使用可靠的开发库。 24 | 25 | Elite是一款可自定语法的编程语言,通过自行配置语法,能够方便的定制需要的语言形式,从而将自己包装成一款领域专用语言,包装后的语言拥有和通用语言一样的编程能力,但又多了自定义的语法形式,避免了过度使用配置文档的问题。 26 | 27 | ## 什么项目适合用Elite开发 28 | 29 | 1. 专业领域的程序库 30 | 2. 具有复杂难以理解配置项的软件包 31 | 3. 拥有复杂抽象模型的软件框架 32 | 4. 快速开发编译器语法原型 33 | 5. 拥有特定语法的交互式控制台程序 34 | 35 | 36 | ## 加入我们 37 | 38 | 目前,项目还处于开发初期,非常欢迎热爱开源的朋友们参加此项目,这是一个中等规模的C++项目,加入我们的团队,不但能够促进该项目更快的发展,更能带给您不一样的思路和体验。 39 | 40 | 希望和我们交流非常容易,可以选择发邮件或在github上直接和我们联系,都可以。 41 | 42 | - github: 43 | - 邮箱: 44 | - gitter:[参与讨论] (https://gitter.im/elite-lang/Elite?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 45 | 46 | ## 开源协议 47 | 48 | MIT协议,允许任何人基于该项目开发其他项目,无论是开源的还是商业的,仅仅需要您在使用时,附带我们的版权声明即可。 49 | 50 | ## 关于本文档 51 | 52 | 本文档分为三部分,其一是用户帮助文档,其二是开发者文档,最后还包括全部代码的注释文档。本文档也属于开源项目的一部分,欢迎大家帮助我们完善和改进本文档。本文档使用Markdown格式编写,使用doxygen工具生成。 53 | 54 | 关于文档的构建与使用:[文件构建参考](md-doc.html) 55 | -------------------------------------------------------------------------------- /doc/manual/ARC.md: -------------------------------------------------------------------------------- 1 | 智能指针的编译器级实现 2 | ================== 3 | 4 | 5 | 智能指针的使用非常普遍,但手动编写十分麻烦,我们可以自动添加引用计数部分的代码,在指针对象离开对应作用域时,自动添加减少引用的代码,在复制指针值的时候,自动增加引用的代码使得引用计数能够正常的工作。 6 | 7 | 我们目前可以实现编译器级别的修改,那么我们希望能够方便的实现普遍性的引用计数,必要时候的垃圾回收,并且是自由可配置的垃圾回收机制。 8 | -------------------------------------------------------------------------------- /doc/manual/DesignManual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/DesignManual.pdf -------------------------------------------------------------------------------- /doc/manual/ca.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/ca.jpg -------------------------------------------------------------------------------- /doc/manual/classNode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/classNode.png -------------------------------------------------------------------------------- /doc/manual/compilers-principles.gv: -------------------------------------------------------------------------------- 1 | digraph g { 2 | rankdir=LR 3 | node [shape=box] 4 | source [shape=plaintext] 5 | source -> "lexcial ananlysis" 6 | "lexcial ananlysis" -> parsing [label=" token"] 7 | parsing -> "marco translate" [label=" AST "] 8 | "marco translate" -> LLC [label= " .bc"] 9 | LLC -> ".o file" 10 | ".o file" [shape=plaintext] 11 | } 12 | -------------------------------------------------------------------------------- /doc/manual/cp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/cp.png -------------------------------------------------------------------------------- /doc/manual/cp.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | g 11 | 12 | 13 | source 14 | source 15 | 16 | 17 | lexcial ananlysis 18 | 19 | lexcial ananlysis 20 | 21 | 22 | source->lexcial ananlysis 23 | 24 | 25 | 26 | 27 | parsing 28 | 29 | parsing 30 | 31 | 32 | lexcial ananlysis->parsing 33 | 34 | 35 |  token 36 | 37 | 38 | marco translate 39 | 40 | marco translate 41 | 42 | 43 | parsing->marco translate 44 | 45 | 46 |  AST 47 | 48 | 49 | LLC 50 | 51 | LLC 52 | 53 | 54 | marco translate->LLC 55 | 56 | 57 |  .bc 58 | 59 | 60 | .o file 61 | .o file 62 | 63 | 64 | LLC->.o file 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /doc/manual/heap.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/heap.pdf -------------------------------------------------------------------------------- /doc/manual/linker.gv: -------------------------------------------------------------------------------- 1 | digraph g { 2 | rankdir=LR 3 | node [shape=box] 4 | "main.out" [shape=plaintext] 5 | file3, file2, file1 [shape=plaintext] 6 | file1 -> "file1.bc" [label=compile] 7 | file2 -> "file2.bc" [label=compile] 8 | file3 -> "file3.bc" [label=compile] 9 | "file1.bc" -> "file1.o" [label=llc] 10 | "file2.bc" -> "file2.o" [label=llc] 11 | "file3.bc" -> "file3.o" [label=llc] 12 | "file1.o" -> linker 13 | "file2.o" -> linker 14 | "file3.o" -> linker 15 | linker -> "main.out" 16 | } 17 | -------------------------------------------------------------------------------- /doc/manual/linker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/linker.png -------------------------------------------------------------------------------- /doc/manual/lrtree.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | node [shape=Mrecord] 3 | i2,i3,i4[label="i"] 4 | rank = same 5 | head 6 | {for "(;;)" "return i"} 7 | {"i=0" "i for 11 | for -> "(;;)" -> "return i" 12 | "(;;)" -> "i=0" -> "i "++ i" 13 | "i=0" -> "=" -> i4 -> "0" 14 | "i "<" -> i -> j 15 | "++ i" -> "++" -> i2 16 | "return i" -> return -> i3 17 | } 18 | -------------------------------------------------------------------------------- /doc/manual/lrtree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/lrtree.png -------------------------------------------------------------------------------- /doc/manual/missfont.log: -------------------------------------------------------------------------------- 1 | mktextfm Hei 2 | mktextfm Hei 3 | mktextfm Hei 4 | mktextfm SongTi 5 | mktextfm SongTi 6 | mktextfm SongTi 7 | -------------------------------------------------------------------------------- /doc/manual/modules.dot: -------------------------------------------------------------------------------- 1 | digraph g { 2 | graph [autosize=false, size="16,8", resolution=100, overlap=prism, overlap_scaling=0.01, ratio=0.7]; 3 | node [shape=Mrecord] 4 | lp [label="Lexical analyzer and Parser"] 5 | macro [label="Macro Translator"] 6 | llcg [label="Low-Level Code Generator"] 7 | pm [label="Pass Manager"] 8 | model [label="Node Models"] 9 | lp -> model [label=" each action will build the model"] 10 | model -> pm [label="run a model"] 11 | pm -> macro [label="each pass will call"] 12 | macro -> model [label="get varibles"] 13 | macro -> macro [label=" recursive call"] 14 | macro -> llcg [label=" each macro will call"] 15 | } 16 | -------------------------------------------------------------------------------- /doc/manual/modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/modules.png -------------------------------------------------------------------------------- /doc/manual/mp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/mp.pdf -------------------------------------------------------------------------------- /doc/manual/mp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/mp.png -------------------------------------------------------------------------------- /doc/manual/mt.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | node [shape=Mrecord] 3 | 4 | } 5 | -------------------------------------------------------------------------------- /doc/manual/profile.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/manual/profile.pdf -------------------------------------------------------------------------------- /doc/misc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /doc/misc/github_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/doc/misc/github_logo.png -------------------------------------------------------------------------------- /doc/misc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 |
22 | $searchbox 23 | 24 | 25 | -------------------------------------------------------------------------------- /doc/user/install.zh-cn.md: -------------------------------------------------------------------------------- 1 | 安装教程 {#md-install} 2 | ========== 3 | 4 | [TOC] 5 | 6 | 7 | @section ins-precompiled 使用预编译版 8 | 9 | 如果您仅仅是想使用Elite去开发应用程序,那么推荐您下载我们预编译好的版本 10 | 11 | 下载页: 12 | 13 | 仅仅需要您配置好环境变量即可,Mac & Linux: 14 | 15 | // for elite 16 | export ELITE_HOME=【您的Elitei安装目录】 17 | export PATH=$ELITE_HOME/bin:$PATH 18 | 19 | 20 | Windows用户: 21 | 22 | 23 | 24 | 25 | 26 | @section ins-compile 从源码编译安装 27 | 28 | 首先,从源码编译安装能够提供给您更丰富的自定义功能,您可以通过修改配置,使用不同的版本。而且自行编译安装,您可以任意修改任何默认配置代码和添加删除功能,这对于开发人员和需要定制化软件的人员更为方便。 29 | 30 | 首先预先您使用git clone完整的项目仓库,请注意使用`--recursive`参数来下载全部子项目: 31 | 32 | git clone --depth=1 --recursive git@github.com:elite-lang/Elite.git 33 | 34 | 35 | @subsection ins-linux Linux环境下的编译 36 | 37 | #### 开发环境和依赖项 38 | 39 | 本项目是在Ubuntu14.04 64位系统下开发的,依赖以下开发库: 40 | 41 | - cmake-2.8 42 | - LLVM-3.6 43 | - flex-2.5 44 | - bison-3.0 45 | - lua-5.2 46 | - oolua-2.0 47 | - dyncall-0.8 48 | 49 | Ubuntu14.04 用户可以直接使用如下命令从源中安装以上软件包: 50 | 51 | sudo apt-get install cmake llvm-3.6-dev libglibmm-2.4-dev flex bison libedit-dev 52 | 53 | ubuntu源中LLVM-3.6的CMake脚本存在bug,如果您安装了llvm-3.6-dev后cmake项目时仍找不到LLVM,那么请执行下面的脚本修复: 54 | 55 | sudo sh ./scripts/fix_ubuntu_llvm.sh 56 | 57 | 58 | #### 编译选项 59 | 60 | 默认Release编译时,只需要您在项目根目录下执行: 61 | 62 | make release 63 | 64 | 65 | 或者您可以手动自行配置编译参数: 66 | 67 | mkdir build && cd build 68 | cmake .. //cmake配置 69 | make deps //下载并构建依赖项目 70 | make elite //构建项目 71 | 72 | 73 | 可选的编译参数有: 74 | 75 | | 参数 | 描述 | 默认参数 | 76 | | --- | --- | --- | 77 | | CMAKE_BUILD_TYPE | 构建类型 | Debug | 78 | | BUILD_TEST | 是否构建测试 | OFF | 79 | | COVERAGE_FLAG | 覆盖率测试 | OFF | 80 | 81 | 82 | 使用时可以如下添加到CMake指令后 83 | 84 | cmake -DCMAKE_BUILD_TYPE=Release 85 | 86 | 87 | 88 | @subsection ins-mac MacOSX环境下的编译 89 | 90 | Mac下的编译方式同样为CMake,构建方式也完全一致,仅仅是依赖项的安装有所区别。 91 | 92 | #### 依赖项和工具 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | @subsection ins-windows Windows环境下的编译 101 | 102 | Windows下支持使用VS2013及以上版本,不建议使用MinGW和Cygwin等兼容平台。 103 | -------------------------------------------------------------------------------- /doc/user/lex.zh-cn.md: -------------------------------------------------------------------------------- 1 | 词法分析器文档 {#md-lex} 2 | ================= 3 | 4 | [TOC] 5 | 6 | 为了支持Elite语法可变的特性,我们也设计了一款高效的词法分析器,方便用户在需要时,修改默认的词法配置。 7 | 8 | \section lex-basic 词法分析器的基本配置 9 | 10 | 词法分析器的配置非常简单,是一个类似ini的文件。 11 | 我们需要在每一行前指定一条token的名字,等号后面接一个正则表达式。下面是一个例子: 12 | 13 | int=[0-9]+ 14 | float=[0-9]*\.[0-9]* 15 | id=[a-zA-Z_]\w* 16 | opta= =|\+=|\-= 17 | optc= [*/] 18 | optd= [+\-] 19 | opte= >|<|<=|>=|==|!= 20 | other=[(){},;:] 21 | ignore=\s+ 22 | 23 | 注意:词法分析器的`=`前不能有多余的空格,之后可以有,这是为了适应不同语言的token命名 24 | 25 | `ignore`是一条特殊的匹配,表示所有的要忽略的词法元素,所有匹配到的元素都将自动忽略,不会传递到语法分析器中。 26 | 27 | \section lex-super Lex词法分析器的高级支持 28 | 29 | Lex词法分析器拥有众多优良特性,例如:Unicode支持,自动编码识别等。使用这些特性能够使得编译器更加方便,更加智能。 30 | 31 | \subsection lex-i18n 国际化支持 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc/user/parser.zh-cn.md: -------------------------------------------------------------------------------- 1 | 语法分析器文档 {#md-parser} 2 | ================= 3 | 4 | 5 | [TOC] 6 | 7 | Elite最终的特性之一就是语法可变的特性,这方便了开发人员自行设计DSL 8 | 9 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/details/static_object.hpp: -------------------------------------------------------------------------------- 1 | /*! \file static_object.hpp 2 | \brief Internal polymorphism static object support 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of cereal nor the 15 | names of its contributors may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | #ifndef CEREAL_DETAILS_STATIC_OBJECT_HPP_ 29 | #define CEREAL_DETAILS_STATIC_OBJECT_HPP_ 30 | 31 | //! Prevent link optimization from removing non-referenced static objects 32 | /*! Especially for polymorphic support, we create static objects which 33 | may not ever be explicitly referenced. Most linkers will detect this 34 | and remove the code causing various unpleasant runtime errors. These 35 | macros, adopted from Boost (see force_include.hpp) prevent this 36 | (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 37 | Use, modification and distribution is subject to the Boost Software 38 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 39 | http://www.boost.org/LICENSE_1_0.txt) */ 40 | 41 | #ifdef _MSC_VER 42 | # define CEREAL_DLL_EXPORT __declspec(dllexport) 43 | # define CEREAL_USED 44 | #else // clang or gcc 45 | # define CEREAL_DLL_EXPORT 46 | # define CEREAL_USED __attribute__ ((__used__)) 47 | #endif 48 | 49 | namespace cereal 50 | { 51 | namespace detail 52 | { 53 | //! A static, pre-execution object 54 | /*! This class will create a single copy (singleton) of some 55 | type and ensures that merely referencing this type will 56 | cause it to be instantiated and initialized pre-execution. 57 | For example, this is used heavily in the polymorphic pointer 58 | serialization mechanisms to bind various archive types with 59 | different polymorphic classes */ 60 | template 61 | class CEREAL_DLL_EXPORT StaticObject 62 | { 63 | private: 64 | //! Forces instantiation at pre-execution time 65 | static void instantiate( T const & ) {} 66 | 67 | static T & create() 68 | { 69 | static T t; 70 | instantiate(instance); 71 | return t; 72 | } 73 | 74 | StaticObject( StaticObject const & /*other*/ ) {} 75 | 76 | public: 77 | static T & getInstance() 78 | { 79 | return create(); 80 | } 81 | 82 | private: 83 | static T & instance; 84 | }; 85 | 86 | template T & StaticObject::instance = StaticObject::create(); 87 | } // namespace detail 88 | } // namespace cereal 89 | 90 | #endif // CEREAL_DETAILS_STATIC_OBJECT_HPP_ -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/details/util.hpp: -------------------------------------------------------------------------------- 1 | /*! \file util.hpp 2 | \brief Internal misc utilities 3 | \ingroup Internal */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_DETAILS_UTIL_HPP_ 31 | #define CEREAL_DETAILS_UTIL_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | #ifdef _MSC_VER 37 | namespace cereal 38 | { 39 | namespace util 40 | { 41 | //! Demangles the type encoded in a string 42 | /*! @internal */ 43 | inline std::string demangle( std::string const & name ) 44 | { return name; } 45 | 46 | //! Gets the demangled name of a type 47 | /*! @internal */ 48 | template inline 49 | std::string demangledName() 50 | { return typeid( T ).name(); } 51 | } // namespace util 52 | } // namespace cereal 53 | #else // clang or gcc 54 | #include 55 | #include 56 | namespace cereal 57 | { 58 | namespace util 59 | { 60 | //! Demangles the type encoded in a string 61 | /*! @internal */ 62 | inline std::string demangle(std::string mangledName) 63 | { 64 | int status = 0; 65 | char *demangledName = nullptr; 66 | std::size_t len; 67 | 68 | demangledName = abi::__cxa_demangle(mangledName.c_str(), 0, &len, &status); 69 | 70 | std::string retName(demangledName); 71 | free(demangledName); 72 | 73 | return retName; 74 | } 75 | 76 | //! Gets the demangled name of a type 77 | /*! @internal */ 78 | template inline 79 | std::string demangledName() 80 | { return demangle(typeid(T).name()); } 81 | } 82 | } // namespace cereal 83 | #endif // clang or gcc branch of _MSC_VER 84 | #endif // CEREAL_DETAILS_UTIL_HPP_ 85 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/external/rapidjson/filestream.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_FILESTREAM_H_ 2 | #define RAPIDJSON_FILESTREAM_H_ 3 | 4 | #include 5 | 6 | namespace rapidjson { 7 | 8 | //! Wrapper of C file stream for input or output. 9 | /*! 10 | This simple wrapper does not check the validity of the stream. 11 | \implements Stream 12 | */ 13 | class FileStream { 14 | public: 15 | typedef char Ch; //!< Character type. Only support char. 16 | 17 | FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); } 18 | 19 | char Peek() const { return current_; } 20 | char Take() { char c = current_; Read(); return c; } 21 | size_t Tell() const { return count_; } 22 | void Put(char c) { fputc(c, fp_); } 23 | 24 | // Not implemented 25 | char* PutBegin() { return 0; } 26 | size_t PutEnd(char*) { return 0; } 27 | 28 | private: 29 | void Read() { 30 | RAPIDJSON_ASSERT(fp_ != 0); 31 | int c = fgetc(fp_); 32 | if (c != EOF) { 33 | current_ = (char)c; 34 | count_++; 35 | } 36 | else 37 | current_ = '\0'; 38 | } 39 | 40 | FILE* fp_; 41 | char current_; 42 | size_t count_; 43 | }; 44 | 45 | } // namespace rapidjson 46 | 47 | #endif // RAPIDJSON_FILESTREAM_H_ 48 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/external/rapidjson/genericstream.h: -------------------------------------------------------------------------------- 1 | // Generic*Stream code from https://code.google.com/p/rapidjson/issues/detail?id=20 2 | #ifndef RAPIDJSON_GENERICSTREAM_H_ 3 | #define RAPIDJSON_GENERICSTREAM_H_ 4 | 5 | #include "rapidjson.h" 6 | #include 7 | 8 | #ifdef _MSC_VER 9 | #pragma warning(push) 10 | #pragma warning(disable: 4127) // conditional expression is constant 11 | #pragma warning(disable: 4512) // assignment operator could not be generated 12 | #pragma warning(disable: 4100) // unreferenced formal parameter 13 | #endif 14 | 15 | namespace rapidjson { 16 | 17 | //! Wrapper of std::istream for input. 18 | class GenericReadStream { 19 | public: 20 | typedef char Ch; //!< Character type (byte). 21 | 22 | //! Constructor. 23 | /*! 24 | \param is Input stream. 25 | */ 26 | GenericReadStream(std::istream & is) : is_(&is) { 27 | } 28 | 29 | 30 | Ch Peek() const { 31 | if(is_->eof()) return '\0'; 32 | return static_cast(is_->peek()); 33 | } 34 | 35 | Ch Take() { 36 | if(is_->eof()) return '\0'; 37 | return static_cast(is_->get()); 38 | } 39 | 40 | size_t Tell() const { 41 | return (int)is_->tellg(); 42 | } 43 | 44 | // Not implemented 45 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 46 | void Flush() { RAPIDJSON_ASSERT(false); } 47 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 48 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 49 | 50 | std::istream * is_; 51 | }; 52 | 53 | 54 | //! Wrapper of std::ostream for output. 55 | class GenericWriteStream { 56 | public: 57 | typedef char Ch; //!< Character type. Only support char. 58 | 59 | //! Constructor 60 | /*! 61 | \param os Output stream. 62 | */ 63 | GenericWriteStream(std::ostream& os) : os_(os) { 64 | } 65 | 66 | void Put(char c) { 67 | os_.put(c); 68 | } 69 | 70 | void PutN(char c, size_t n) { 71 | for (size_t i = 0; i < n; ++i) { 72 | Put(c); 73 | } 74 | } 75 | 76 | void Flush() { 77 | os_.flush(); 78 | } 79 | 80 | size_t Tell() const { 81 | return (int)os_.tellp(); 82 | } 83 | 84 | // Not implemented 85 | char Peek() const { RAPIDJSON_ASSERT(false); } 86 | char Take() { RAPIDJSON_ASSERT(false); } 87 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 88 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 89 | 90 | private: 91 | std::ostream& os_; 92 | }; 93 | 94 | template<> 95 | inline void PutN(GenericWriteStream& stream, char c, size_t n) { 96 | stream.PutN(c, n); 97 | } 98 | 99 | } // namespace rapidjson 100 | 101 | // On MSVC, restore warnings state 102 | #ifdef _MSC_VER 103 | #pragma warning(pop) 104 | #endif 105 | #endif // RAPIDJSON_GENERICSTREAM_H_ 106 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/external/rapidjson/internal/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_INTERNAL_STACK_H_ 2 | #define RAPIDJSON_INTERNAL_STACK_H_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | /////////////////////////////////////////////////////////////////////////////// 8 | // Stack 9 | 10 | //! A type-unsafe stack for storing different types of data. 11 | /*! \tparam Allocator Allocator for allocating stack memory. 12 | */ 13 | template 14 | class Stack { 15 | public: 16 | Stack(Allocator* allocator, size_t stack_capacity) : allocator_(allocator), own_allocator_(0), stack_(0), stack_top_(0), stack_end_(0), stack_capacity_(stack_capacity) { 17 | RAPIDJSON_ASSERT(stack_capacity_ > 0); 18 | if (!allocator_) 19 | own_allocator_ = allocator_ = new Allocator(); 20 | stack_top_ = stack_ = (char*)allocator_->Malloc(stack_capacity_); 21 | stack_end_ = stack_ + stack_capacity_; 22 | } 23 | 24 | ~Stack() { 25 | Allocator::Free(stack_); 26 | delete own_allocator_; // Only delete if it is owned by the stack 27 | } 28 | 29 | void Clear() { /*stack_top_ = 0;*/ stack_top_ = stack_; } 30 | 31 | template 32 | T* Push(size_t count = 1) { 33 | // Expand the stack if needed 34 | if (stack_top_ + sizeof(T) * count >= stack_end_) { 35 | size_t new_capacity = stack_capacity_ * 2; 36 | size_t size = GetSize(); 37 | size_t new_size = GetSize() + sizeof(T) * count; 38 | if (new_capacity < new_size) 39 | new_capacity = new_size; 40 | stack_ = (char*)allocator_->Realloc(stack_, stack_capacity_, new_capacity); 41 | stack_capacity_ = new_capacity; 42 | stack_top_ = stack_ + size; 43 | stack_end_ = stack_ + stack_capacity_; 44 | } 45 | T* ret = (T*)stack_top_; 46 | stack_top_ += sizeof(T) * count; 47 | return ret; 48 | } 49 | 50 | template 51 | T* Pop(size_t count) { 52 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); 53 | stack_top_ -= count * sizeof(T); 54 | return (T*)stack_top_; 55 | } 56 | 57 | template 58 | T* Top() { 59 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 60 | return (T*)(stack_top_ - sizeof(T)); 61 | } 62 | 63 | template 64 | T* Bottom() { return (T*)stack_; } 65 | 66 | Allocator& GetAllocator() { return *allocator_; } 67 | size_t GetSize() const { return stack_top_ - stack_; } 68 | size_t GetCapacity() const { return stack_capacity_; } 69 | 70 | private: 71 | Allocator* allocator_; 72 | Allocator* own_allocator_; 73 | char *stack_; 74 | char *stack_top_; 75 | char *stack_end_; 76 | size_t stack_capacity_; 77 | }; 78 | 79 | } // namespace internal 80 | } // namespace rapidjson 81 | 82 | #endif // RAPIDJSON_STACK_H_ 83 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/external/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 2 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 3 | 4 | namespace rapidjson { 5 | namespace internal { 6 | 7 | //! Custom strlen() which works on different character types. 8 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 9 | \param s Null-terminated input string. 10 | \return Number of characters in the string. 11 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 12 | */ 13 | template 14 | inline SizeType StrLen(const Ch* s) { 15 | const Ch* p = s; 16 | while (*p != '\0') 17 | ++p; 18 | return SizeType(p - s); 19 | } 20 | 21 | } // namespace internal 22 | } // namespace rapidjson 23 | 24 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 25 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/external/rapidjson/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011 Milo Yip 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/external/rapidjson/stringbuffer.h: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDJSON_STRINGBUFFER_H_ 2 | #define RAPIDJSON_STRINGBUFFER_H_ 3 | 4 | #include "rapidjson.h" 5 | #include "internal/stack.h" 6 | 7 | namespace rapidjson { 8 | 9 | //! Represents an in-memory output stream. 10 | /*! 11 | \tparam Encoding Encoding of the stream. 12 | \tparam Allocator type for allocating memory buffer. 13 | \implements Stream 14 | */ 15 | template 16 | struct GenericStringBuffer { 17 | typedef typename Encoding::Ch Ch; 18 | 19 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 20 | 21 | void Put(Ch c) { *stack_.template Push() = c; } 22 | 23 | void Clear() { stack_.Clear(); } 24 | 25 | const char* GetString() const { 26 | // Push and pop a null terminator. This is safe. 27 | *stack_.template Push() = '\0'; 28 | stack_.template Pop(1); 29 | 30 | return stack_.template Bottom(); 31 | } 32 | 33 | size_t Size() const { return stack_.GetSize(); } 34 | 35 | static const size_t kDefaultCapacity = 256; 36 | mutable internal::Stack stack_; 37 | }; 38 | 39 | typedef GenericStringBuffer > StringBuffer; 40 | 41 | //! Implement specialized version of PutN() with memset() for better performance. 42 | template<> 43 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 44 | memset(stream.stack_.Push(n), c, n * sizeof(c)); 45 | } 46 | 47 | } // namespace rapidjson 48 | 49 | #endif // RAPIDJSON_STRINGBUFFER_H_ 50 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/external/rapidxml/license.txt: -------------------------------------------------------------------------------- 1 | Use of this software is granted under one of the following two licenses, 2 | to be chosen freely by the user. 3 | 4 | 1. Boost Software License - Version 1.0 - August 17th, 2003 5 | =============================================================================== 6 | 7 | Copyright (c) 2006, 2007 Marcin Kalicinski 8 | 9 | Permission is hereby granted, free of charge, to any person or organization 10 | obtaining a copy of the software and accompanying documentation covered by 11 | this license (the "Software") to use, reproduce, display, distribute, 12 | execute, and transmit the Software, and to prepare derivative works of the 13 | Software, and to permit third-parties to whom the Software is furnished to 14 | do so, all subject to the following: 15 | 16 | The copyright notices in the Software and this entire statement, including 17 | the above license grant, this restriction and the following disclaimer, 18 | must be included in all copies of the Software, in whole or in part, and 19 | all derivative works of the Software, unless such copies or derivative 20 | works are solely in the form of machine-executable object code generated by 21 | a source language processor. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | DEALINGS IN THE SOFTWARE. 30 | 31 | 2. The MIT License 32 | =============================================================================== 33 | 34 | Copyright (c) 2006, 2007 Marcin Kalicinski 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | of the Software, and to permit persons to whom the Software is furnished to do so, 41 | subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 52 | IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/external/rapidxml/rapidxml_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDXML_UTILS_HPP_INCLUDED 2 | #define RAPIDXML_UTILS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective. 8 | 9 | #include "rapidxml.hpp" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace rapidxml 16 | { 17 | 18 | //! Represents data loaded from a file 19 | template 20 | class file 21 | { 22 | 23 | public: 24 | 25 | //! Loads file into the memory. Data will be automatically destroyed by the destructor. 26 | //! \param filename Filename to load. 27 | file(const char *filename) 28 | { 29 | using namespace std; 30 | 31 | // Open stream 32 | basic_ifstream stream(filename, ios::binary); 33 | if (!stream) 34 | throw runtime_error(string("cannot open file ") + filename); 35 | stream.unsetf(ios::skipws); 36 | 37 | // Determine stream size 38 | stream.seekg(0, ios::end); 39 | size_t size = stream.tellg(); 40 | stream.seekg(0); 41 | 42 | // Load data and add terminating 0 43 | m_data.resize(size + 1); 44 | stream.read(&m_data.front(), static_cast(size)); 45 | m_data[size] = 0; 46 | } 47 | 48 | //! Loads file into the memory. Data will be automatically destroyed by the destructor 49 | //! \param stream Stream to load from 50 | file(std::basic_istream &stream) 51 | { 52 | using namespace std; 53 | 54 | // Load data and add terminating 0 55 | stream.unsetf(ios::skipws); 56 | m_data.assign(istreambuf_iterator(stream), istreambuf_iterator()); 57 | if (stream.fail() || stream.bad()) 58 | throw runtime_error("error reading stream"); 59 | m_data.push_back(0); 60 | } 61 | 62 | //! Gets file data. 63 | //! \return Pointer to data of file. 64 | Ch *data() 65 | { 66 | return &m_data.front(); 67 | } 68 | 69 | //! Gets file data. 70 | //! \return Pointer to data of file. 71 | const Ch *data() const 72 | { 73 | return &m_data.front(); 74 | } 75 | 76 | //! Gets file data size. 77 | //! \return Size of file data, in characters. 78 | std::size_t size() const 79 | { 80 | return m_data.size(); 81 | } 82 | 83 | private: 84 | 85 | std::vector m_data; // File data 86 | 87 | }; 88 | 89 | //! Counts children of node. Time complexity is O(n). 90 | //! \return Number of children of node 91 | template 92 | inline std::size_t count_children(xml_node *node) 93 | { 94 | xml_node *child = node->first_node(); 95 | std::size_t count = 0; 96 | while (child) 97 | { 98 | ++count; 99 | child = child->next_sibling(); 100 | } 101 | return count; 102 | } 103 | 104 | //! Counts attributes of node. Time complexity is O(n). 105 | //! \return Number of attributes of node 106 | template 107 | inline std::size_t count_attributes(xml_node *node) 108 | { 109 | xml_attribute *attr = node->first_attribute(); 110 | std::size_t count = 0; 111 | while (attr) 112 | { 113 | ++count; 114 | attr = attr->next_attribute(); 115 | } 116 | return count; 117 | } 118 | 119 | } 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/macros.hpp: -------------------------------------------------------------------------------- 1 | /*! \file macros.hpp 2 | \brief Preprocessor macros that can customise the cereal library 3 | 4 | By default, cereal looks for serialization functions with very 5 | specific names, that is: serialize, load, save, load_minimal, 6 | or save_minimal. 7 | 8 | This file allows an advanced user to change these names to conform 9 | to some other style or preference. This is implemented using 10 | preprocessor macros. 11 | 12 | As a result of this, in internal cereal code you will see macros 13 | used for these function names. In user code, you should name 14 | the functions like you normally would and not use the macros 15 | to improve readability. 16 | \ingroup utility */ 17 | /* 18 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 19 | All rights reserved. 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions are met: 23 | * Redistributions of source code must retain the above copyright 24 | notice, this list of conditions and the following disclaimer. 25 | * Redistributions in binary form must reproduce the above copyright 26 | notice, this list of conditions and the following disclaimer in the 27 | documentation and/or other materials provided with the distribution. 28 | * Neither the name of cereal nor the 29 | names of its contributors may be used to endorse or promote products 30 | derived from this software without specific prior written permission. 31 | 32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 33 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 34 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 35 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 36 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 37 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 38 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 39 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 41 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | */ 43 | 44 | #ifndef CEREAL_MACROS_HPP_ 45 | #define CEREAL_MACROS_HPP_ 46 | 47 | #ifndef CEREAL_SERIALIZE_FUNCTION_NAME 48 | //! The serialization/deserialization function name to search for. 49 | /*! You can define @c CEREAL_SERIALIZE_FUNCTION_NAME to be different assuming 50 | you do so before this file is included. */ 51 | #define CEREAL_SERIALIZE_FUNCTION_NAME serialize 52 | #endif // CEREAL_SERIALIZE_FUNCTION_NAME 53 | 54 | #ifndef CEREAL_LOAD_FUNCTION_NAME 55 | //! The deserialization (load) function name to search for. 56 | /*! You can define @c CEREAL_LOAD_FUNCTION_NAME to be different assuming you do so 57 | before this file is included. */ 58 | #define CEREAL_LOAD_FUNCTION_NAME load 59 | #endif // CEREAL_LOAD_FUNCTION_NAME 60 | 61 | #ifndef CEREAL_SAVE_FUNCTION_NAME 62 | //! The serialization (save) function name to search for. 63 | /*! You can define @c CEREAL_SAVE_FUNCTION_NAME to be different assuming you do so 64 | before this file is included. */ 65 | #define CEREAL_SAVE_FUNCTION_NAME save 66 | #endif // CEREAL_SAVE_FUNCTION_NAME 67 | 68 | #ifndef CEREAL_LOAD_MINIMAL_FUNCTION_NAME 69 | //! The deserialization (load_minimal) function name to search for. 70 | /*! You can define @c CEREAL_LOAD_MINIMAL_FUNCTION_NAME to be different assuming you do so 71 | before this file is included. */ 72 | #define CEREAL_LOAD_MINIMAL_FUNCTION_NAME load_minimal 73 | #endif // CEREAL_LOAD_MINIMAL_FUNCTION_NAME 74 | 75 | #ifndef CEREAL_SAVE_MINIMAL_FUNCTION_NAME 76 | //! The serialization (save_minimal) function name to search for. 77 | /*! You can define @c CEREAL_SAVE_MINIMAL_FUNCTION_NAME to be different assuming you do so 78 | before this file is included. */ 79 | #define CEREAL_SAVE_MINIMAL_FUNCTION_NAME save_minimal 80 | #endif // CEREAL_SAVE_MINIMAL_FUNCTION_NAME 81 | 82 | #endif // CEREAL_MACROS_HPP_ 83 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/array.hpp: -------------------------------------------------------------------------------- 1 | /*! \file array.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_ARRAY_HPP_ 31 | #define CEREAL_TYPES_ARRAY_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::array primitive types 39 | //! using binary serialization, if supported 40 | template inline 41 | typename std::enable_if, Archive>::value 42 | && std::is_arithmetic::value, void>::type 43 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 44 | { 45 | ar( binary_data( array.data(), sizeof(array) ) ); 46 | } 47 | 48 | //! Loading for std::array primitive types 49 | //! using binary serialization, if supported 50 | template inline 51 | typename std::enable_if, Archive>::value 52 | && std::is_arithmetic::value, void>::type 53 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 54 | { 55 | ar( binary_data( array.data(), sizeof(array) ) ); 56 | } 57 | 58 | //! Saving for std::array all other types 59 | template inline 60 | typename std::enable_if, Archive>::value 61 | || !std::is_arithmetic::value, void>::type 62 | CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::array const & array ) 63 | { 64 | for( auto const & i : array ) 65 | ar( i ); 66 | } 67 | 68 | //! Loading for std::array all other types 69 | template inline 70 | typename std::enable_if, Archive>::value 71 | || !std::is_arithmetic::value, void>::type 72 | CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array & array ) 73 | { 74 | for( auto & i : array ) 75 | ar( i ); 76 | } 77 | } // namespace cereal 78 | 79 | #endif // CEREAL_TYPES_ARRAY_HPP_ 80 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/bitset.hpp: -------------------------------------------------------------------------------- 1 | /*! \file bitset.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_BITSET_HPP_ 31 | #define CEREAL_TYPES_BITSET_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace bitset_detail 39 | { 40 | //! The type the bitset is encoded with 41 | /*! @internal */ 42 | enum class type : uint8_t 43 | { 44 | ulong, 45 | ullong, 46 | string 47 | }; 48 | } 49 | 50 | //! Serializing (save) for std::bitset 51 | template inline 52 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::bitset const & bits ) 53 | { 54 | try 55 | { 56 | auto const b = bits.to_ulong(); 57 | ar( CEREAL_NVP_("type", bitset_detail::type::ulong) ); 58 | ar( CEREAL_NVP_("data", b) ); 59 | } 60 | catch( std::overflow_error const & ) 61 | { 62 | try 63 | { 64 | auto const b = bits.to_ullong(); 65 | ar( CEREAL_NVP_("type", bitset_detail::type::ullong) ); 66 | ar( CEREAL_NVP_("data", b) ); 67 | } 68 | catch( std::overflow_error const & ) 69 | { 70 | ar( CEREAL_NVP_("type", bitset_detail::type::string) ); 71 | ar( CEREAL_NVP_("data", bits.to_string()) ); 72 | } 73 | } 74 | } 75 | 76 | //! Serializing (load) for std::bitset 77 | template inline 78 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::bitset & bits ) 79 | { 80 | bitset_detail::type t; 81 | ar( CEREAL_NVP_("type", t) ); 82 | 83 | switch( t ) 84 | { 85 | case bitset_detail::type::ulong: 86 | { 87 | unsigned long b; 88 | ar( CEREAL_NVP_("data", b) ); 89 | bits = std::bitset( b ); 90 | break; 91 | } 92 | case bitset_detail::type::ullong: 93 | { 94 | unsigned long long b; 95 | ar( CEREAL_NVP_("data", b) ); 96 | bits = std::bitset( b ); 97 | break; 98 | } 99 | case bitset_detail::type::string: 100 | { 101 | std::string b; 102 | ar( CEREAL_NVP_("data", b) ); 103 | bits = std::bitset( b ); 104 | break; 105 | } 106 | default: 107 | throw Exception("Invalid bitset data representation"); 108 | } 109 | } 110 | } // namespace cereal 111 | 112 | #endif // CEREAL_TYPES_BITSET_HPP_ 113 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/chrono.hpp: -------------------------------------------------------------------------------- 1 | /*! \file chrono.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_CHRONO_HPP_ 31 | #define CEREAL_TYPES_CHRONO_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Saving std::chrono::duration 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::duration const & dur ) 40 | { 41 | ar( CEREAL_NVP_("count", dur.count()) ); 42 | } 43 | 44 | //! Loading std::chrono::duration 45 | template inline 46 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::duration & dur ) 47 | { 48 | R count; 49 | ar( CEREAL_NVP_("count", count) ); 50 | 51 | dur = std::chrono::duration{count}; 52 | } 53 | 54 | //! Saving std::chrono::time_point 55 | template inline 56 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::chrono::time_point const & dur ) 57 | { 58 | ar( CEREAL_NVP_("time_since_epoch", dur.time_since_epoch()) ); 59 | } 60 | 61 | //! Loading std::chrono::time_point 62 | template inline 63 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::chrono::time_point & dur ) 64 | { 65 | D elapsed; 66 | ar( CEREAL_NVP_("time_since_epoch", elapsed) ); 67 | 68 | dur = std::chrono::time_point{elapsed}; 69 | } 70 | } // namespace cereal 71 | 72 | #endif // CEREAL_TYPES_CHRONO_HPP_ 73 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/complex.hpp: -------------------------------------------------------------------------------- 1 | /*! \file complex.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_COMPLEX_HPP_ 31 | #define CEREAL_TYPES_COMPLEX_HPP_ 32 | 33 | #include 34 | 35 | namespace cereal 36 | { 37 | //! Serializing (save) for std::complex 38 | template inline 39 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::complex const & comp ) 40 | { 41 | ar( CEREAL_NVP_("real", comp.real()), 42 | CEREAL_NVP_("imag", comp.imag()) ); 43 | } 44 | 45 | //! Serializing (load) for std::complex 46 | template inline 47 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::complex & bits ) 48 | { 49 | T real, imag; 50 | ar( CEREAL_NVP_("real", real), 51 | CEREAL_NVP_("imag", imag) ); 52 | bits = {real, imag}; 53 | } 54 | } // namespace cereal 55 | 56 | #endif // CEREAL_TYPES_COMPLEX_HPP_ 57 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/deque.hpp: -------------------------------------------------------------------------------- 1 | /*! \file deque.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_DEQUE_HPP_ 31 | #define CEREAL_TYPES_DEQUE_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::deque 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::deque const & deque ) 41 | { 42 | ar( make_size_tag( static_cast(deque.size()) ) ); 43 | 44 | for( auto const & i : deque ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::deque 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::deque & deque ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | deque.resize( static_cast( size ) ); 56 | 57 | for( auto & i : deque ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_DEQUE_HPP_ 63 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/forward_list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file forward_list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_FORWARD_LIST_HPP_ 31 | #define CEREAL_TYPES_FORWARD_LIST_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::forward_list all other types 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::forward_list const & forward_list ) 41 | { 42 | // write the size - note that this is slow because we need to traverse 43 | // the entire list. there are ways we could avoid this but this was chosen 44 | // since it works in the most general fashion with any archive type 45 | size_type const size = std::distance( forward_list.begin(), forward_list.end() ); 46 | 47 | ar( make_size_tag( size ) ); 48 | 49 | // write the list 50 | for( const auto & i : forward_list ) 51 | ar( i ); 52 | } 53 | 54 | //! Loading for std::forward_list all other types from 55 | template 56 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::forward_list & forward_list ) 57 | { 58 | size_type size; 59 | ar( make_size_tag( size ) ); 60 | 61 | forward_list.resize( static_cast( size ) ); 62 | 63 | for( auto & i : forward_list ) 64 | ar( i ); 65 | } 66 | } // namespace cereal 67 | 68 | #endif // CEREAL_TYPES_FORWARD_LIST_HPP_ 69 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/list.hpp: -------------------------------------------------------------------------------- 1 | /*! \file list.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_LIST_HPP_ 31 | #define CEREAL_TYPES_LIST_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Saving for std::list 39 | template inline 40 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::list const & list ) 41 | { 42 | ar( make_size_tag( static_cast(list.size()) ) ); 43 | 44 | for( auto const & i : list ) 45 | ar( i ); 46 | } 47 | 48 | //! Loading for std::list 49 | template inline 50 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::list & list ) 51 | { 52 | size_type size; 53 | ar( make_size_tag( size ) ); 54 | 55 | list.resize( static_cast( size ) ); 56 | 57 | for( auto & i : list ) 58 | ar( i ); 59 | } 60 | } // namespace cereal 61 | 62 | #endif // CEREAL_TYPES_LIST_HPP_ 63 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/set.hpp: -------------------------------------------------------------------------------- 1 | /*! \file set.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_SET_HPP_ 31 | #define CEREAL_TYPES_SET_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | namespace set_detail 39 | { 40 | //! @internal 41 | template inline 42 | void save( Archive & ar, SetT const & set ) 43 | { 44 | ar( make_size_tag( static_cast(set.size()) ) ); 45 | 46 | for( const auto & i : set ) 47 | ar( i ); 48 | } 49 | 50 | //! @internal 51 | template inline 52 | void load( Archive & ar, SetT & set ) 53 | { 54 | size_type size; 55 | ar( make_size_tag( size ) ); 56 | 57 | set.clear(); 58 | 59 | auto hint = set.begin(); 60 | for( size_type i = 0; i < size; ++i ) 61 | { 62 | typename SetT::key_type key; 63 | 64 | ar( key ); 65 | #ifdef CEREAL_OLDER_GCC 66 | hint = set.insert( hint, std::move( key ) ); 67 | #else // NOT CEREAL_OLDER_GCC 68 | hint = set.emplace_hint( hint, std::move( key ) ); 69 | #endif // NOT CEREAL_OLDER_GCC 70 | } 71 | } 72 | } 73 | 74 | //! Saving for std::set 75 | template inline 76 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::set const & set ) 77 | { 78 | set_detail::save( ar, set ); 79 | } 80 | 81 | //! Loading for std::set 82 | template inline 83 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::set & set ) 84 | { 85 | set_detail::load( ar, set ); 86 | } 87 | 88 | //! Saving for std::multiset 89 | template inline 90 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::multiset const & multiset ) 91 | { 92 | set_detail::save( ar, multiset ); 93 | } 94 | 95 | //! Loading for std::multiset 96 | template inline 97 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::multiset & multiset ) 98 | { 99 | set_detail::load( ar, multiset ); 100 | } 101 | } // namespace cereal 102 | 103 | #endif // CEREAL_TYPES_SET_HPP_ 104 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/stack.hpp: -------------------------------------------------------------------------------- 1 | /*! \file stack.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STACK_HPP_ 31 | #define CEREAL_TYPES_STACK_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | // The default container for stack is deque, so let's include that too 37 | #include 38 | 39 | namespace cereal 40 | { 41 | namespace stack_detail 42 | { 43 | //! Allows access to the protected container in stack 44 | template inline 45 | C const & container( std::stack const & stack ) 46 | { 47 | struct H : public std::stack 48 | { 49 | static C const & get( std::stack const & s ) 50 | { 51 | return s.*(&H::c); 52 | } 53 | }; 54 | 55 | return H::get( stack ); 56 | } 57 | } 58 | 59 | //! Saving for std::stack 60 | template inline 61 | void CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::stack const & stack ) 62 | { 63 | ar( CEREAL_NVP_("container", stack_detail::container( stack )) ); 64 | } 65 | 66 | //! Loading for std::stack 67 | template inline 68 | void CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::stack & stack ) 69 | { 70 | C container; 71 | ar( CEREAL_NVP_("container", container) ); 72 | stack = std::stack( std::move( container ) ); 73 | } 74 | } // namespace cereal 75 | 76 | #endif // CEREAL_TYPES_STACK_HPP_ 77 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/string.hpp: -------------------------------------------------------------------------------- 1 | /*! \file string.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_STRING_HPP_ 31 | #define CEREAL_TYPES_STRING_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serialization for basic_string types, if binary data is supported 39 | template inline 40 | typename std::enable_if, Archive>::value, void>::type 41 | CEREAL_SAVE_FUNCTION_NAME(Archive & ar, std::basic_string const & str) 42 | { 43 | // Save number of chars + the data 44 | ar( make_size_tag( static_cast(str.size()) ) ); 45 | ar( binary_data( str.data(), str.size() * sizeof(CharT) ) ); 46 | } 47 | 48 | //! Serialization for basic_string types, if binary data is supported 49 | template inline 50 | typename std::enable_if, Archive>::value, void>::type 51 | CEREAL_LOAD_FUNCTION_NAME(Archive & ar, std::basic_string & str) 52 | { 53 | size_type size; 54 | ar( make_size_tag( size ) ); 55 | str.resize(static_cast(size)); 56 | ar( binary_data( const_cast( str.data() ), static_cast(size) * sizeof(CharT) ) ); 57 | } 58 | } // namespace cereal 59 | 60 | #endif // CEREAL_TYPES_STRING_HPP_ 61 | 62 | -------------------------------------------------------------------------------- /header_libs/cereal-1.1.2/cereal/types/utility.hpp: -------------------------------------------------------------------------------- 1 | /*! \file utility.hpp 2 | \brief Support for types found in \ 3 | \ingroup STLSupport */ 4 | /* 5 | Copyright (c) 2014, Randolph Voorhies, Shane Grant 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of cereal nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #ifndef CEREAL_TYPES_UTILITY_HPP_ 31 | #define CEREAL_TYPES_UTILITY_HPP_ 32 | 33 | #include 34 | #include 35 | 36 | namespace cereal 37 | { 38 | //! Serializing for std::pair 39 | template inline 40 | void CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, std::pair & pair ) 41 | { 42 | ar( CEREAL_NVP_("first", pair.first), 43 | CEREAL_NVP_("second", pair.second) ); 44 | } 45 | } // namespace cereal 46 | 47 | #endif // CEREAL_TYPES_UTILITY_HPP_ 48 | -------------------------------------------------------------------------------- /header_libs/elegantlist/elegantlist.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ELEGANT_LIST_H 2 | #define ELEGANT_LIST_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | class ElegantList { 11 | public: 12 | ElegantList() : os(std::cout) {} 13 | ElegantList(ostream& out_stream) : os(out_stream) {} 14 | 15 | void print(const string& data) { 16 | if (data == "(") { 17 | os << endl; 18 | ++level; 19 | printTab(); 20 | } 21 | os << data << ' '; 22 | if (data == ")") { 23 | --level; 24 | } 25 | } 26 | private: 27 | void printTab() { 28 | for (int i = 1; i < level; ++i) 29 | os << " "; 30 | } 31 | ostream& os; 32 | int level; 33 | }; 34 | 35 | 36 | 37 | #endif /* end of include guard: ELEGANT_LIST_H */ 38 | -------------------------------------------------------------------------------- /header_libs/elegantlist/eltest.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "elegantlist.hpp" 3 | 4 | ElegantList el; 5 | 6 | int main() { 7 | 8 | el.print("("); 9 | el.print("function"); 10 | el.print("hello"); 11 | el.print("("); 12 | el.print("set"); 13 | el.print("int"); 14 | el.print("var"); 15 | el.print(")"); 16 | el.print("("); 17 | el.print("("); 18 | el.print("set"); 19 | el.print("int"); 20 | el.print("x"); 21 | el.print(")"); 22 | el.print("("); 23 | el.print("return"); 24 | el.print("0"); 25 | el.print(")"); 26 | el.print(")"); 27 | el.print(")"); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /header_libs/sptr/memheap.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MEM_HEAP_HPP 2 | #define MEM_HEAP_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | class MemHeap { 12 | 13 | // 内部使用的节点类型 14 | struct MemObjNode { 15 | size_t size; 16 | int count; 17 | void* data[]; 18 | }; 19 | 20 | public: 21 | MemHeap() { 22 | 23 | } 24 | 25 | inline static void ref (void* ptr) { 26 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 27 | ++(p->count); 28 | } 29 | 30 | inline static void unref (void* ptr) { 31 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 32 | --(p->count); 33 | if (p->count == 0) getInstance()->release(ptr); 34 | } 35 | 36 | void* allocate(size_t size) { 37 | MemObjNode* p = (MemObjNode*) malloc(size + sizeof(MemObjNode)); 38 | if (p == NULL) return NULL; 39 | p->size = size; 40 | p->count = 1; 41 | all.insert(&(p->data)); 42 | printf("allocate %p\n", &(p->data)); 43 | return &(p->data); 44 | } 45 | 46 | void release(void* ptr) { 47 | if (ptr == NULL) return; 48 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 49 | all.erase(ptr); 50 | free(p); 51 | printf("release %p\n", ptr); 52 | } 53 | 54 | inline static MemHeap* getInstance() { 55 | static MemHeap instance; 56 | return &instance; 57 | } 58 | 59 | inline static void push_stack(void* ptr) { 60 | getInstance()->stack.insert(ptr); 61 | } 62 | 63 | inline static void pop_stack(void* ptr) { 64 | getInstance()->stack.erase(ptr); 65 | } 66 | 67 | 68 | static void runGC() { 69 | auto inst = getInstance(); 70 | for (void* p : inst->stack) { 71 | inst->markChildren(p); 72 | } 73 | 74 | vector v; 75 | for (void* ptr : inst->all) { 76 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 77 | if (p->count < 0) p->count = -(p->count); 78 | else v.push_back(ptr); 79 | } 80 | for (void* p : v) inst->release(p); 81 | } 82 | 83 | protected: 84 | 85 | unordered_set stack; 86 | unordered_set all; 87 | void* heap; 88 | 89 | void markChildren(void* ptr) { 90 | MemObjNode* p = (MemObjNode*) ((char*) ptr - sizeof(MemObjNode)); 91 | 92 | // 如果打了标记则退出, 否则设置标记, 标记方式则是改变符号位 93 | if (p->count < 0) return; 94 | p->count = -(p->count); 95 | printf("tag %p\n", ptr); 96 | 97 | size_t size = (p->size) / sizeof(char*); 98 | char** end = (char**)ptr + size; 99 | for (char** i = (char**)ptr; i < end; ++i) { 100 | if (all.find(*i) != all.end()) { 101 | markChildren(*i); 102 | } 103 | } 104 | } 105 | 106 | }; 107 | 108 | 109 | 110 | #endif /* end of include guard: MEM_HEAP_HPP */ 111 | -------------------------------------------------------------------------------- /header_libs/sptr/sptr.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SPTR_HPP 2 | #define SPTR_HPP 3 | 4 | #include "memheap.hpp" 5 | 6 | void* operator new (size_t size, MemHeap* ptr) { 7 | if (ptr) return ptr->allocate(size); 8 | static MemHeap* p = MemHeap::getInstance(); 9 | return p->allocate(size); 10 | } 11 | 12 | 13 | inline void sptr_ref(void* p) { 14 | MemHeap::ref(p); 15 | } 16 | 17 | inline void sptr_unref(void* p) { 18 | MemHeap::unref(p); 19 | } 20 | 21 | 22 | template 23 | class sptr { 24 | public: 25 | sptr() { 26 | ptr = NULL; 27 | } 28 | 29 | sptr(T* p) { 30 | ptr = p; 31 | } 32 | 33 | sptr(const sptr& p) { 34 | ptr = p.ptr; 35 | ref(); 36 | } 37 | 38 | sptr& operator=(T* p) { 39 | unref(); 40 | ptr = p; 41 | return *this; 42 | } 43 | 44 | sptr& operator=(const sptr& p) { 45 | unref(); 46 | ptr = p.ptr; 47 | ref(); 48 | return *this; 49 | } 50 | 51 | virtual ~sptr() { 52 | unref(); 53 | } 54 | 55 | inline T* get() { 56 | return ptr; 57 | } 58 | 59 | inline void wrapper(T* p) { 60 | ptr = p; 61 | } 62 | inline T* unwrapper() { 63 | ref(); 64 | return ptr; 65 | } 66 | 67 | inline T* operator -> () { 68 | return ptr; 69 | } 70 | inline T& operator * () { 71 | return *ptr; 72 | } 73 | 74 | protected: 75 | inline void ref() { 76 | if (ptr) MemHeap::ref(ptr); 77 | } 78 | inline void unref() { 79 | if (ptr) MemHeap::unref(ptr); 80 | } 81 | 82 | T* ptr; 83 | }; 84 | 85 | template 86 | class sptr_stack : public sptr { 87 | public: 88 | sptr_stack() : sptr() { 89 | MemHeap::push_stack(this->ptr); 90 | } 91 | 92 | sptr_stack(T* p) : sptr(p) { 93 | MemHeap::push_stack(this->ptr); 94 | } 95 | 96 | sptr_stack(const sptr& p) : sptr(p) { 97 | MemHeap::push_stack(this->ptr); 98 | } 99 | 100 | 101 | sptr& operator=(T* p) { 102 | pop(); 103 | sptr::operator=(p); 104 | return *this; 105 | } 106 | 107 | sptr& operator=(const sptr& p) { 108 | pop(); 109 | sptr::operator=(p); 110 | return *this; 111 | } 112 | 113 | virtual ~sptr_stack() { 114 | pop(); 115 | } 116 | 117 | protected: 118 | inline void pop() { 119 | if (this->ptr) MemHeap::pop_stack(this->ptr); 120 | } 121 | }; 122 | 123 | 124 | #endif /* end of include guard: SPTR_HPP */ 125 | -------------------------------------------------------------------------------- /libs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/libs/.gitkeep -------------------------------------------------------------------------------- /packages/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/packages/.gitkeep -------------------------------------------------------------------------------- /packages/bgc/bgc.epbc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/packages/bgc/bgc.epbc -------------------------------------------------------------------------------- /packages/bgc/libbgc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/packages/bgc/libbgc.a -------------------------------------------------------------------------------- /packages/bgc/libgc-lib.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/packages/bgc/libgc-lib.a -------------------------------------------------------------------------------- /packages/bgc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bgc", 3 | "default_load": "true", 4 | "platform": "linux", 5 | "version": "0.0.1", 6 | "runtime": "-lbgc -lgc-lib" 7 | } 8 | -------------------------------------------------------------------------------- /packages/bgc/src/Makefile: -------------------------------------------------------------------------------- 1 | all : ../test2.epbc ../libbgc.a 2 | 3 | ../test2.epbc : main.cpp 4 | clang++ -std=c++11 -emit-llvm -fno-use-cxa-atexit -I../../../build/header -c main.cpp -o ../bgc.epbc 5 | 6 | ../libbgc.a : bgc.o 7 | ar rcs $@ $^ 8 | 9 | bgc.o : runtime.cpp 10 | clang++ -std=c++11 -I../../../extlib/include -c runtime.cpp -o bgc.o 11 | -------------------------------------------------------------------------------- /packages/bgc/src/bgc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elite-lang/EliteOld/f123d67d99c11fe04aa437be7a64b530563d42cc/packages/bgc/src/bgc.o -------------------------------------------------------------------------------- /packages/bgc/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-26 09:53:58 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 17:03:08 6 | */ 7 | 8 | #include 9 | #include "ICodeGenContext.h" 10 | #include "CodeGenContext.h" 11 | #include "Model/nodes.h" 12 | #include "Pass.h" 13 | #include "PassManager.h" 14 | 15 | using namespace std; 16 | 17 | 18 | extern "C" { 19 | 20 | static LValue new_macro(CodeGenContext* context, Node* node) { 21 | printf("Happy New Year! ~ From Bcg Package\n"); 22 | TypeNode* tn = (TypeNode*) node; 23 | LValue t = context->FindSrcType(tn->getTypeName()); 24 | 25 | // 第二个参数,构造函数表 26 | node = node->getNext(); 27 | 28 | // 第三个参数,维度信息 29 | vector args; 30 | node = node->getNext(); 31 | if (node != NULL) 32 | for (Node* p = node->getChild(); p != NULL; p = p->getNext()) { 33 | args.push_back(p->codeGen(context)); 34 | } 35 | if (args.size() == 0) { 36 | return context->getLLCG()->New(t,args, "bgc_malloc"); 37 | } else { 38 | return context->getLLCG()->NewArray(t, args, "bgc_malloc_array"); 39 | } 40 | return NULL; 41 | } 42 | 43 | static const FuncReg macro_funcs[] = { 44 | {"new", new_macro}, 45 | {0, 0} 46 | }; 47 | 48 | extern void bgc_elite_plugin_init(ICodeGenContext* context) { 49 | printf("Bgc plugin loaded.\n"); 50 | if (context == NULL) printf("Error for context\n"); 51 | else { 52 | auto pm = context->getPassManager(); 53 | auto main_list = pm->getPassList("main"); 54 | Pass* pass = *(main_list->begin()); 55 | pass->AddOrReplaceMacros(macro_funcs); 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /packages/bgc/src/runtime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | extern "C" { 8 | 9 | 10 | extern void* bgc_malloc(int size) { 11 | return GC_malloc(size); 12 | } 13 | 14 | extern void* bgc_malloc_array(int size, ...) { 15 | va_list argp; /* 定义保存函数参数的结构 */ 16 | va_start( argp, size ); 17 | std::vector wd; 18 | int v; int num = 1; 19 | do { 20 | v = va_arg(argp, int); 21 | if (v != 0) { 22 | wd.push_back(v); 23 | num *= v; 24 | } 25 | } while (v != 0); 26 | va_end( argp ); /* 将argp置为NULL */ 27 | 28 | int full_size = wd.size()*sizeof(int) + size* num; 29 | int* ans = (int*) GC_malloc(full_size); 30 | int* i = ans; 31 | for (auto p = wd.begin(); p != wd.end(); ++p, ++i) { 32 | *i = *p; 33 | } 34 | return (void*) i; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /scripts/chmod_runnable.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # @Author: sxf 3 | # @Date: 2015-12-21 20:29:17 4 | # @Last Modified by: sxf 5 | # @Last Modified time: 2015-12-21 20:30:15 6 | 7 | chmod -R a+x tools -------------------------------------------------------------------------------- /scripts/fix_ubuntu_llvm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # @Author: sxf 3 | # @Date: 2015-12-15 18:41:10 4 | # @Last Modified by: sxf 5 | # @Last Modified time: 2015-12-16 13:12:22 6 | 7 | 8 | cp -f ./scripts/fix_ubuntu/LLVMConfig.cmake /usr/share/llvm-3.6/cmake/LLVMConfig.cmake 9 | 10 | # 这段脚本的主要目的是修复ubuntu源里面llvm包的一个bug, 会造成llvm的cmake文件找不到 11 | # 如果您也使用ubuntu开发, 您可以在项目目录下执行: ./scripts/fix_ubuntu_llvm.sh 修复问题 12 | -------------------------------------------------------------------------------- /scripts/install_gtest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # @Author: sxf 3 | # @Date: 2015-12-16 18:31:22 4 | # @Last Modified by: sxf 5 | # @Last Modified time: 2015-12-16 18:32:56 6 | 7 | cd /usr/src/ 8 | git clone --depth=1 https://github.com/google/googletest.git 9 | cd googletest 10 | cmake -E make_directory build 11 | cmake -E chdir build cmake .. 12 | cmake --build build 13 | cmake --build build --target install 14 | rm -rf build 15 | -------------------------------------------------------------------------------- /scripts/install_llvm_win32.bat: -------------------------------------------------------------------------------- 1 | git clone --depth=1 https://github.com/elite-lang/LLVM_Windows_37.git LLVM_SDK 2 | -------------------------------------------------------------------------------- /scripts/makeln(不推荐).sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # @Author: sxf 3 | # @Date: 2015-11-02 13:21:24 4 | # @Last Modified by: sxf 5 | # @Last Modified time: 2015-12-10 11:40:36 6 | 7 | # 这个sh脚本是用来生成各个项目依赖库的软链接的 8 | 9 | cd .. 10 | 11 | # for LR_Scanner 12 | ln -s -T ../../Lex/include ./LR_Scanner/lib/lex_include 13 | ln -s -t ./LR_Scanner/lib/ ../../Lex/build/liblex.a 14 | 15 | # for Builder 16 | ln -s -T ../../Lex/include ./Builder/lib/lex 17 | ln -s -t ./Builder/lib/ ../../Lex/build/liblex.a 18 | ln -s -T ../../LR_Scanner/includes ./Builder/lib/scanner 19 | ln -s -t ./Builder/lib/ ../../LR_Scanner/build/libscanner.a 20 | ln -s -T ../../MetaScriptRunner/include ./Builder/lib/meta 21 | ln -s -t ./Builder/lib/ ../../MetaScriptRunner/build/libmeta.a 22 | ln -s -T ../../RedApple/includes ./Builder/lib/redapple 23 | ln -s -t ./Builder/lib/ ../../RedApple/build/libred.a 24 | 25 | # for MetaScriptRunner 26 | ln -s -T ../../Lex/include ./MetaScriptRunner/lib/lex 27 | ln -s -t ./MetaScriptRunner/lib/ ../../Lex/build/liblex.a 28 | ln -s -T ../../LR_Scanner/includes ./MetaScriptRunner/lib/scanner 29 | ln -s -t ./MetaScriptRunner/lib/ ../../LR_Scanner/build/libscanner.a 30 | ln -s -T ../../RedApple/includes ./MetaScriptRunner/lib/redapple 31 | ln -s -t ./MetaScriptRunner/lib/ ../../RedApple/build/libred.a 32 | 33 | # for Main 34 | ln -s -t ./extlib/ ../Lex/build/liblex.a 35 | ln -s -T ../Lex/include ./extlib/lex 36 | ln -s -t ./extlib/ ../LR_Scanner/build/libscanner.a 37 | ln -s -T ../LR_Scanner/includes ./extlib/scanner 38 | ln -s -t ./extlib/ ../RedApple/build/libred.a 39 | ln -s -T ../RedApple/includes ./extlib/redapple 40 | ln -s -t ./extlib/ ../Builder/build/libbuilder.a 41 | ln -s -T ../Builder/include ./extlib/builder 42 | ln -s -t ./extlib/ ../MetaScriptRunner/build/libmeta.a 43 | ln -s -T ../MetaScriptRunner/include ./extlib/meta 44 | 45 | 46 | mkdir ./build 47 | mkdir ./Lex/build 48 | mkdir ./LR_Scanner/build 49 | mkdir ./MetaScriptRunner/build 50 | mkdir ./Builder/build 51 | mkdir ./RedApple/build 52 | -------------------------------------------------------------------------------- /src/elite-config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-22 08:29:16 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-30 16:52:43 6 | */ 7 | 8 | 9 | #define ELITE_VERSION_MAJOR "0" 10 | #define ELITE_VERSION_MINOR "9" 11 | #define ELITE_VERSION_RELEASE "2" 12 | #define ELITE_VERSION_NUM 9 13 | 14 | #define ELITE_VERSION "Elite " ELITE_VERSION_MAJOR "." ELITE_VERSION_MINOR 15 | #define ELITE_RELEASE ELITE_VERSION "." ELITE_VERSION_RELEASE 16 | -------------------------------------------------------------------------------- /src/help.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-12-07 10:43:17 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2015-12-30 11:28:12 6 | */ 7 | 8 | #include "elite-config.h" 9 | 10 | const char* help_message = 11 | "欢迎使用精锐编译器" ELITE_RELEASE "版\r\n" 12 | "Welcome to use " ELITE_RELEASE "\r\n\r\n" 13 | "----------------------------------------------------------\r\n" 14 | "-h/--help\t\t打印帮助信息 / Print help message\r\n" 15 | "-s/--src \t\t指定源程序路径 / Set the source file path\r\n" 16 | "-d/--dir \t\t指定输出文件路径 / Set the output file path\r\n" 17 | "--show\t\t\t展示模式 / Show Mode\r\n" 18 | "-c\t\t\t仅编译不链接 / Only compile files without link\r\n" 19 | "-i/--in \t\t单独编译一个文件 / Compiler only one file\r\n" 20 | "-l/--lex <*.cfg>\t指定词法配置 / Set the lex config file\r\n" 21 | "-p/--parser <*.cfg>\t指定语法配置 / Set the parser config file\r\n" 22 | "----------------------------------------------------------\r\n\r\n" 23 | ; 24 | 25 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: sxf 3 | * @Date: 2015-11-02 20:13:16 4 | * @Last Modified by: sxf 5 | * @Last Modified time: 2016-01-01 15:38:44 6 | */ 7 | 8 | #include 9 | #include "Builder.h" 10 | #include "Worker.h" 11 | #include "PathGetter.h" 12 | #include 13 | #include "help.h" 14 | #include "PathUtils.h" 15 | #include "llvm/Support/Signals.h" 16 | 17 | using namespace std; 18 | 19 | const char* safe_getNext(int argc, const char *argv[], int& i) { 20 | if (++i < argc) { 21 | return argv[i]; 22 | } else { 23 | printf("缺少正确的参数\n"); 24 | exit(0); 25 | } 26 | } 27 | 28 | int is_show_time = 0; 29 | 30 | const char* cscw = "-s参数不能和-i参数同时使用, 请选其一指定单独编译或编译文件夹\n"; 31 | 32 | int main(int argc, const char *argv[]) 33 | { 34 | llvm::sys::PrintStackTraceOnErrorSignal(); 35 | 36 | string nowdir = PathGetter::getNowPath(); 37 | string dir = "build"; // 默认构建位置,当前目录下新建build 38 | string srcdir = "src"; // 默认源文件目录 39 | string package; 40 | string onlyfile; // 单独只构建一个文件 41 | string defalut_lex = PathGetter::getDefaultLexCfg(); 42 | string defalut_parser = PathGetter::getDefaultParserCfg(); 43 | int only_one_file = -1; 44 | int close_link = 0; 45 | if (argc <= 1) cout << help_message; 46 | else { 47 | int i = 0; 48 | while (i < argc-1) { 49 | ++i; 50 | string opt(argv[i]); 51 | if (opt == "-h" || opt == "--help") { 52 | cout << help_message; 53 | exit(0); 54 | } 55 | if (opt == "-d" || opt == "--dir") { 56 | dir = safe_getNext(argc, argv, i); 57 | continue; 58 | } 59 | if (opt == "--show") { 60 | is_show_time = 1; continue; 61 | } 62 | if (opt == "-c") { 63 | close_link = 1; continue; 64 | } 65 | if (opt == "-s" || opt == "--src") { 66 | if (only_one_file == 1) { 67 | cout << cscw; 68 | exit(0); 69 | } 70 | srcdir = safe_getNext(argc, argv, i); 71 | only_one_file = 0; 72 | continue; 73 | } 74 | if (opt == "-pkg" || opt == "--package") { 75 | if (only_one_file == 1) { 76 | cout << cscw; 77 | exit(0); 78 | } 79 | package = safe_getNext(argc, argv, i); 80 | only_one_file = 0; 81 | continue; 82 | } 83 | if (opt == "-i" || opt == "--in") { 84 | if (only_one_file == 0) { 85 | cout << cscw; 86 | exit(0); 87 | } 88 | onlyfile = safe_getNext(argc, argv, i); 89 | only_one_file = 1; continue; 90 | } 91 | if (opt == "-p" || opt == "--parser") { 92 | defalut_parser = safe_getNext(argc, argv, i); 93 | } 94 | if (opt == "-l" || opt == "--lex") { 95 | defalut_lex = safe_getNext(argc, argv, i); 96 | } 97 | } 98 | if (only_one_file == -1) 99 | only_one_file = 0; 100 | 101 | 102 | // 创建Worker和Builder 103 | defalut_lex = PathUtils::native(defalut_lex); 104 | defalut_parser = PathUtils::native(defalut_parser); 105 | Builder* builder = Builder::Create(); 106 | if (is_show_time == 1) 107 | builder->setDebugFilePath(dir.c_str()); 108 | Worker* worker = Worker::CreateDefault( 109 | defalut_lex.c_str(), defalut_parser.c_str(), 110 | PathGetter::getElitePackagesPath(), 111 | builder 112 | ); 113 | builder->setWorker(worker); 114 | builder->SetBuildPath(dir); 115 | 116 | if (only_one_file == 1) { 117 | builder->BuildFile(onlyfile); 118 | } else { 119 | builder->AddSrcPath(srcdir); 120 | builder->BuildPath(package); 121 | } 122 | 123 | builder->Close(); 124 | } 125 | return 0; 126 | } 127 | --------------------------------------------------------------------------------