diff options
Diffstat (limited to 'src/yue.cpp')
-rw-r--r-- | src/yue.cpp | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index 6011d94..07d0fef 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
@@ -9,28 +9,28 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
9 | #include "yuescript/yue_compiler.h" | 9 | #include "yuescript/yue_compiler.h" |
10 | #include "yuescript/yue_parser.h" | 10 | #include "yuescript/yue_parser.h" |
11 | 11 | ||
12 | #include <iostream> | 12 | #include <chrono> |
13 | #include <iomanip> | ||
14 | #include <cstdlib> | 13 | #include <cstdlib> |
15 | #include <limits> | ||
16 | #include <fstream> | 14 | #include <fstream> |
17 | #include <chrono> | ||
18 | #include <future> | 15 | #include <future> |
16 | #include <iomanip> | ||
17 | #include <iostream> | ||
18 | #include <limits> | ||
19 | #include <memory> | ||
19 | #include <sstream> | 20 | #include <sstream> |
20 | #include <tuple> | ||
21 | #include <string_view> | 21 | #include <string_view> |
22 | #include <memory> | 22 | #include <tuple> |
23 | using namespace std::string_view_literals; | 23 | using namespace std::string_view_literals; |
24 | using namespace std::string_literals; | 24 | using namespace std::string_literals; |
25 | #include "ghc/fs_std.hpp" | 25 | #include "ghc/fs_std.hpp" |
26 | #include "linenoise.hpp" | 26 | #include "linenoise.hpp" |
27 | 27 | ||
28 | #if not (defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) | 28 | #if not(defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) |
29 | #define _DEFER(code,line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto){code;}) | 29 | #define _DEFER(code, line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto) { code; }) |
30 | #define DEFER(code) _DEFER(code,__LINE__) | 30 | #define DEFER(code) _DEFER(code, __LINE__) |
31 | extern "C" { | 31 | extern "C" { |
32 | #include "lua.h" | ||
33 | #include "lauxlib.h" | 32 | #include "lauxlib.h" |
33 | #include "lua.h" | ||
34 | #include "lualib.h" | 34 | #include "lualib.h" |
35 | int luaopen_yue(lua_State* L); | 35 | int luaopen_yue(lua_State* L); |
36 | } // extern "C" | 36 | } // extern "C" |
@@ -81,7 +81,7 @@ void pushOptions(lua_State* L, int lineOffset) { | |||
81 | #endif // not (defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) | 81 | #endif // not (defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) |
82 | 82 | ||
83 | #ifndef YUE_NO_MACRO | 83 | #ifndef YUE_NO_MACRO |
84 | #define YUE_ARGS nullptr,openlibs | 84 | #define YUE_ARGS nullptr, openlibs |
85 | #else | 85 | #else |
86 | #define YUE_ARGS | 86 | #define YUE_ARGS |
87 | #endif // YUE_NO_MACRO | 87 | #endif // YUE_NO_MACRO |
@@ -90,7 +90,7 @@ void pushOptions(lua_State* L, int lineOffset) { | |||
90 | static const char luaminifyCodes[] = | 90 | static const char luaminifyCodes[] = |
91 | #include "LuaMinify.h" | 91 | #include "LuaMinify.h" |
92 | 92 | ||
93 | static void pushLuaminify(lua_State* L) { | 93 | static void pushLuaminify(lua_State * L) { |
94 | if (luaL_loadbuffer(L, luaminifyCodes, sizeof(luaminifyCodes) / sizeof(luaminifyCodes[0]) - 1, "=(luaminify)") != 0) { | 94 | if (luaL_loadbuffer(L, luaminifyCodes, sizeof(luaminifyCodes) / sizeof(luaminifyCodes[0]) - 1, "=(luaminify)") != 0) { |
95 | std::string err = "failed to load luaminify module.\n"s + lua_tostring(L, -1); | 95 | std::string err = "failed to load luaminify module.\n"s + lua_tostring(L, -1); |
96 | luaL_error(L, err.c_str()); | 96 | luaL_error(L, err.c_str()); |
@@ -103,27 +103,27 @@ static void pushLuaminify(lua_State* L) { | |||
103 | 103 | ||
104 | int main(int narg, const char** args) { | 104 | int main(int narg, const char** args) { |
105 | const char* help = | 105 | const char* help = |
106 | "Usage: yue [options|files|directories] ...\n\n" | 106 | "Usage: yue [options|files|directories] ...\n\n" |
107 | " -h Print this message\n" | 107 | " -h Print this message\n" |
108 | #ifndef YUE_COMPILER_ONLY | 108 | #ifndef YUE_COMPILER_ONLY |
109 | " -e str Execute a file or raw codes\n" | 109 | " -e str Execute a file or raw codes\n" |
110 | " -m Generate minified codes\n" | 110 | " -m Generate minified codes\n" |
111 | #endif // YUE_COMPILER_ONLY | 111 | #endif // YUE_COMPILER_ONLY |
112 | " -t path Specify where to place compiled files\n" | 112 | " -t path Specify where to place compiled files\n" |
113 | " -o file Write output to file\n" | 113 | " -o file Write output to file\n" |
114 | " -s Use spaces in generated codes instead of tabs\n" | 114 | " -s Use spaces in generated codes instead of tabs\n" |
115 | " -p Write output to standard out\n" | 115 | " -p Write output to standard out\n" |
116 | " -b Dump compile time (doesn't write output)\n" | 116 | " -b Dump compile time (doesn't write output)\n" |
117 | " -g Dump global variables used in NAME LINE COLUMN\n" | 117 | " -g Dump global variables used in NAME LINE COLUMN\n" |
118 | " -l Write line numbers from source codes\n" | 118 | " -l Write line numbers from source codes\n" |
119 | " -v Print version\n" | 119 | " -v Print version\n" |
120 | #ifndef YUE_COMPILER_ONLY | 120 | #ifndef YUE_COMPILER_ONLY |
121 | " -- Read from standard in, print to standard out\n" | 121 | " -- Read from standard in, print to standard out\n" |
122 | " (Must be first and only argument)\n\n" | 122 | " (Must be first and only argument)\n\n" |
123 | " Execute without options to enter REPL, type symbol '$'\n" | 123 | " Execute without options to enter REPL, type symbol '$'\n" |
124 | " in a single line to start/stop multi-line mode\n" | 124 | " in a single line to start/stop multi-line mode\n" |
125 | #endif // YUE_COMPILER_ONLY | 125 | #endif // YUE_COMPILER_ONLY |
126 | ; | 126 | ; |
127 | #ifndef YUE_COMPILER_ONLY | 127 | #ifndef YUE_COMPILER_ONLY |
128 | if (narg == 1) { | 128 | if (narg == 1) { |
129 | lua_State* L = luaL_newstate(); | 129 | lua_State* L = luaL_newstate(); |
@@ -276,7 +276,7 @@ int main(int narg, const char** args) { | |||
276 | std::string targetPath; | 276 | std::string targetPath; |
277 | std::string resultFile; | 277 | std::string resultFile; |
278 | std::string workPath; | 278 | std::string workPath; |
279 | std::list<std::pair<std::string,std::string>> files; | 279 | std::list<std::pair<std::string, std::string>> files; |
280 | for (int i = 1; i < narg; ++i) { | 280 | for (int i = 1; i < narg; ++i) { |
281 | std::string arg = args[i]; | 281 | std::string arg = args[i]; |
282 | if (arg == "--"sv) { | 282 | if (arg == "--"sv) { |
@@ -449,7 +449,7 @@ int main(int narg, const char** args) { | |||
449 | std::cout << "Error: -o can not be used with multiple input files\n"sv; | 449 | std::cout << "Error: -o can not be used with multiple input files\n"sv; |
450 | std::cout << help; | 450 | std::cout << help; |
451 | } | 451 | } |
452 | std::list<std::future<std::tuple<int,std::string,std::string>>> results; | 452 | std::list<std::future<std::tuple<int, std::string, std::string>>> results; |
453 | for (const auto& file : files) { | 453 | for (const auto& file : files) { |
454 | auto task = std::async(std::launch::async, [=]() { | 454 | auto task = std::async(std::launch::async, [=]() { |
455 | std::ifstream input(file.first, std::ios::in); | 455 | std::ifstream input(file.first, std::ios::in); |