diff options
author | Li Jin <dragon-fly@qq.com> | 2021-02-17 11:22:07 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-02-17 11:22:07 +0800 |
commit | 7066392d1c974065181d95d93274136dcd625d43 (patch) | |
tree | cf51eafc2c52cbc12246a306bca172d799193d30 | |
parent | 90cd12ad9ef465f3e435e1bd034dcfbe4e19d016 (diff) | |
download | yuescript-7066392d1c974065181d95d93274136dcd625d43.tar.gz yuescript-7066392d1c974065181d95d93274136dcd625d43.tar.bz2 yuescript-7066392d1c974065181d95d93274136dcd625d43.zip |
stop reusing variables, rename project.
-rw-r--r-- | .gitignore | 8 | ||||
-rw-r--r-- | CMakeLists.txt | 16 | ||||
-rw-r--r-- | MoonPlus.vcxproj.user | 4 | ||||
-rw-r--r-- | README.md | 63 | ||||
-rw-r--r-- | Yuescript.sln (renamed from MoonPlus.sln) | 2 | ||||
-rw-r--r-- | Yuescript.vcxproj (renamed from MoonPlus.vcxproj) | 39 | ||||
-rw-r--r-- | Yuescript.vcxproj.filters (renamed from MoonPlus.vcxproj.filters) | 84 | ||||
-rw-r--r-- | appveyor.yml | 2 | ||||
-rw-r--r-- | docker/Dockerfile | 8 | ||||
-rw-r--r-- | makefile | 22 | ||||
-rw-r--r-- | moonplus-dev-1.rockspec | 33 | ||||
-rw-r--r-- | spec/inputs/ambiguous.yue (renamed from spec/inputs/ambiguous.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/assign.yue (renamed from spec/inputs/assign.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/attrib.yue (renamed from spec/inputs/attrib.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/backcall.yue (renamed from spec/inputs/backcall.mp) | 14 | ||||
-rw-r--r-- | spec/inputs/bubbling.yue (renamed from spec/inputs/bubbling.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/class.yue (renamed from spec/inputs/class.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/comprehension.yue (renamed from spec/inputs/comprehension.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/cond.yue (renamed from spec/inputs/cond.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/destructure.yue (renamed from spec/inputs/destructure.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/do.yue (renamed from spec/inputs/do.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/existential.yue (renamed from spec/inputs/existential.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/export.yue (renamed from spec/inputs/export.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/export_default.yue (renamed from spec/inputs/export_default.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/funcs.yue (renamed from spec/inputs/funcs.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/global.yue (renamed from spec/inputs/global.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/goto.yue (renamed from spec/inputs/goto.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/import.yue (renamed from spec/inputs/import.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/lists.yue (renamed from spec/inputs/lists.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/literals.yue (renamed from spec/inputs/literals.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/local.yue (renamed from spec/inputs/local.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/loops.yue (renamed from spec/inputs/loops.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/macro-export.yue (renamed from spec/inputs/macro-export.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/macro-teal.yue (renamed from spec/inputs/macro-teal.mp) | 12 | ||||
-rw-r--r-- | spec/inputs/macro.yue (renamed from spec/inputs/macro.mp) | 2 | ||||
-rw-r--r-- | spec/inputs/multiline_chain.yue (renamed from spec/inputs/multiline_chain.mp) | 37 | ||||
-rw-r--r-- | spec/inputs/operators.yue (renamed from spec/inputs/operators.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/plus.yue (renamed from spec/inputs/plus.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/return.yue (renamed from spec/inputs/return.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/string.yue (renamed from spec/inputs/string.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/stub.yue (renamed from spec/inputs/stub.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/switch.yue (renamed from spec/inputs/switch.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/syntax.yue (renamed from spec/inputs/syntax.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/tables.yue (renamed from spec/inputs/tables.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/teal-lang.yue (renamed from spec/inputs/teal-lang.mp) | 2 | ||||
-rw-r--r-- | spec/inputs/unless_else.yue (renamed from spec/inputs/unless_else.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/using.yue (renamed from spec/inputs/using.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/whitespace.yue (renamed from spec/inputs/whitespace.mp) | 0 | ||||
-rw-r--r-- | spec/inputs/with.yue (renamed from spec/inputs/with.mp) | 0 | ||||
-rw-r--r-- | src/yue.cpp (renamed from src/moonp.cpp) | 102 | ||||
-rw-r--r-- | src/yuescript/ast.cpp (renamed from src/MoonP/ast.cpp) | 2 | ||||
-rw-r--r-- | src/yuescript/ast.hpp (renamed from src/MoonP/ast.hpp) | 2 | ||||
-rw-r--r-- | src/yuescript/parser.cpp (renamed from src/MoonP/parser.cpp) | 2 | ||||
-rw-r--r-- | src/yuescript/parser.hpp (renamed from src/MoonP/parser.hpp) | 0 | ||||
-rw-r--r-- | src/yuescript/stacktraceplus.h (renamed from src/MoonP/stacktraceplus.h) | 32 | ||||
-rw-r--r-- | src/yuescript/yue_ast.h (renamed from src/MoonP/moon_ast.h) | 2 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.cpp (renamed from src/MoonP/moon_compiler.cpp) | 288 | ||||
-rw-r--r-- | src/yuescript/yue_compiler.h (renamed from src/MoonP/moon_compiler.h) | 18 | ||||
-rw-r--r-- | src/yuescript/yue_parser.cpp (renamed from src/MoonP/moon_parser.cpp) | 22 | ||||
-rw-r--r-- | src/yuescript/yue_parser.h (renamed from src/MoonP/moon_parser.h) | 12 | ||||
-rw-r--r-- | src/yuescript/yuescript.cpp (renamed from src/MoonP/moonplus.cpp) | 50 | ||||
-rw-r--r-- | src/yuescript/yuescript.h (renamed from src/MoonP/moonplus.h) | 90 | ||||
-rw-r--r-- | yuescript-dev-1.rockspec | 33 |
63 files changed, 510 insertions, 493 deletions
@@ -1,10 +1,10 @@ | |||
1 | moonp | 1 | yue |
2 | !src/MoonP | 2 | !src/yuescript/ |
3 | build | 3 | build |
4 | build.luarocks | 4 | build.luarocks |
5 | spec/outputs | 5 | spec/outputs |
6 | moonplus-*.rock* | 6 | yuescript-*.rock* |
7 | !moonplus-dev-1.rockspec | 7 | !yuescript-dev-1.rockspec |
8 | .vs | 8 | .vs |
9 | bin | 9 | bin |
10 | src/lua/*.o | 10 | src/lua/*.o |
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fcb248..d323b6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | project ( moonp CXX ) | 1 | project ( yue CXX ) |
2 | cmake_minimum_required ( VERSION 3.1 ) | 2 | cmake_minimum_required ( VERSION 3.1 ) |
3 | 3 | ||
4 | MESSAGE(STATUS "Lua: using information from luarocks") | 4 | MESSAGE(STATUS "Lua: using information from luarocks") |
@@ -28,15 +28,15 @@ enable_language( CXX ) | |||
28 | include_directories( src ${LUA_INCLUDE_DIR} ) | 28 | include_directories( src ${LUA_INCLUDE_DIR} ) |
29 | add_definitions( -std=c++17 -O3 -fPIC ) | 29 | add_definitions( -std=c++17 -O3 -fPIC ) |
30 | 30 | ||
31 | add_library( libmoonp MODULE src/MoonP/ast.cpp src/MoonP/parser.cpp src/MoonP/moon_parser.cpp src/MoonP/moon_compiler.cpp src/MoonP/moonplus.cpp) | 31 | add_library( libyue MODULE src/yuescript/ast.cpp src/yuescript/parser.cpp src/yuescript/yue_parser.cpp src/yuescript/yue_compiler.cpp src/yuescript/yuescript.cpp) |
32 | set_target_properties( libmoonp PROPERTIES PREFIX "" ) | 32 | set_target_properties( libyue PROPERTIES PREFIX "" ) |
33 | set_target_properties( libmoonp PROPERTIES OUTPUT_NAME "moonp" ) | 33 | set_target_properties( libyue PROPERTIES OUTPUT_NAME "yue" ) |
34 | target_link_libraries( libmoonp ${LUA_LIBRARIES} ) | 34 | target_link_libraries( libyue ${LUA_LIBRARIES} ) |
35 | 35 | ||
36 | add_executable( moonp src/MoonP/ast.cpp src/MoonP/moon_compiler.cpp src/MoonP/moon_parser.cpp src/MoonP/moonplus.cpp src/MoonP/parser.cpp src/moonp.cpp ) | 36 | add_executable( yue src/yuescript/ast.cpp src/yuescript/yue_compiler.cpp src/yuescript/yue_parser.cpp src/yuescript/yuescript.cpp src/yuescript/parser.cpp src/yue.cpp ) |
37 | target_link_libraries( moonp ${LUA_LIBRARIES} ) | 37 | target_link_libraries( yue ${LUA_LIBRARIES} ) |
38 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | 38 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
39 | target_link_options( moonp PRIVATE -ldl -lpthread -lstdc++fs ) | 39 | target_link_options( yue PRIVATE -ldl -lpthread -lstdc++fs ) |
40 | endif() | 40 | endif() |
41 | 41 | ||
42 | install(CODE "") | 42 | install(CODE "") |
diff --git a/MoonPlus.vcxproj.user b/MoonPlus.vcxproj.user deleted file mode 100644 index 88a5509..0000000 --- a/MoonPlus.vcxproj.user +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | <?xml version="1.0" encoding="utf-8"?> | ||
2 | <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
3 | <PropertyGroup /> | ||
4 | </Project> \ No newline at end of file | ||
@@ -1,14 +1,14 @@ | |||
1 | # MoonPlus | 1 | # YueScript |
2 | 2 | ||
3 | |macOS|Linux|Windows| | 3 | |macOS|Linux|Windows| |
4 | |:---:|:---:|:-----:| | 4 | |:---:|:---:|:-----:| |
5 | |||[](https://ci.appveyor.com/project/pigpigyyy/moonplus/branch/master)| | 5 | |||[](https://ci.appveyor.com/project/pigpigyyy/moonplus/branch/master)| |
6 | 6 | ||
7 | MoonPlus is a compiler with features from [Moonscript language](https://github.com/leafo/moonscript) 0.5.0 and adopting new features to make Moonscript more up to date. | 7 | Yuescript is a Moonscript dialect. It is derived from [Moonscript language](https://github.com/leafo/moonscript) 0.5.0 and continuously adopting new features to be more up to date. |
8 | 8 | ||
9 | Since original Moonscript has been used to write web framework [lapis](https://github.com/leafo/lapis) and run a few business web sites like [itch.io](https://itch.io) and [streak.club](https://streak.club) with some large code bases. The original language is getting too hard to adopt new features for those may break the stablility for existing applications. | 9 | Moonscript is a language that compiles to Lua. Since original Moonscript has been used to write web framework [lapis](https://github.com/leafo/lapis) and run a few business web sites like [itch.io](https://itch.io) and [streak.club](https://streak.club) with some large code bases. The original language is getting too hard to adopt new features for those may break the stablility for existing applications. |
10 | 10 | ||
11 | So MoonPlus is a new code base for pushing the language to go forward and being a playground to try introducing new language syntax or programing paradigms to make Moonscript language more expressive and productive. | 11 | So Yuescript is a new code base for pushing the language to go forward and being a playground to try introducing new language syntax or programing paradigms to make Moonscript language more expressive and productive. |
12 | 12 | ||
13 | 13 | ||
14 | 14 | ||
@@ -16,8 +16,9 @@ So MoonPlus is a new code base for pushing the language to go forward and being | |||
16 | 16 | ||
17 | * No other dependencies needed except modified **parserlib** library from Achilleas Margaritis with some performance enhancement. **lpeg** library is no longer needed. | 17 | * No other dependencies needed except modified **parserlib** library from Achilleas Margaritis with some performance enhancement. **lpeg** library is no longer needed. |
18 | * Written in C++17. | 18 | * Written in C++17. |
19 | * Support full Moonscript language features, generate the same Lua codes with original compiler. | 19 | * Support most of the features from Moonscript language. Generate Lua codes in the same way like the original compiler. |
20 | * Reserve line numbers from Moonscript sources in compiled Lua codes to help with debugging. | 20 | * Reserve line numbers from source file in the compiled Lua codes to help debugging. |
21 | * More features like macro, existential operator, backcall operator, Javascript-like export syntax and etc. | ||
21 | * See other details in the [changelog](./CHANGELOG.md). | 22 | * See other details in the [changelog](./CHANGELOG.md). |
22 | 23 | ||
23 | 24 | ||
@@ -26,27 +27,27 @@ So MoonPlus is a new code base for pushing the language to go forward and being | |||
26 | 27 | ||
27 | * **Lua Module** | 28 | * **Lua Module** |
28 | 29 | ||
29 |   Build `moonp.so` file with | 30 |   Build `yue.so` file with |
30 | 31 | ||
31 | ```sh | 32 | ```sh |
32 | > make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua | 33 | > make shared LUAI=/usr/local/include/lua LUAL=/usr/local/lib/lua |
33 | ``` | 34 | ``` |
34 | 35 | ||
35 |   Then get the binary file from path `bin/shared/moonp.so`. | 36 |   Then get the binary file from path `bin/shared/yue.so`. |
36 | 37 | ||
37 |   Or you can install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module with | 38 |   Or you can install [luarocks](https://luarocks.org), a package manager for Lua modules. Then install it as a Lua module with |
38 | 39 | ||
39 | ```sh | 40 | ```sh |
40 | > luarocks install moonplus | 41 | > luarocks install yuescript |
41 | ``` | 42 | ``` |
42 | 43 | ||
43 |   Then require the MoonPlus module in Lua: | 44 |   Then require the Yuescript module in Lua: |
44 | 45 | ||
45 | ```Lua | 46 | ```Lua |
46 | require("moonp")("main") -- require `main.mp` | 47 | require("yue")("main") -- require `main.yue` |
47 | 48 | ||
48 | local moonp = require("moonp") | 49 | local yue = require("yue") |
49 | local codes, err, globals = moonp.to_lua([[ | 50 | local codes, err, globals = yue.to_lua([[ |
50 | f = -> | 51 | f = -> |
51 | print "hello world" | 52 | print "hello world" |
52 | f! | 53 | f! |
@@ -66,21 +67,21 @@ f! | |||
66 | > make install | 67 | > make install |
67 | ``` | 68 | ``` |
68 | 69 | ||
69 |   Build MoonPlus tool without macro feature: | 70 |   Build Yuescript tool without macro feature: |
70 | ```sh | 71 | ```sh |
71 | > make install NO_MACRO=true | 72 | > make install NO_MACRO=true |
72 | ``` | 73 | ``` |
73 | 74 | ||
74 |   Build MoonPlus tool without built-in Lua binary: | 75 |   Build Yuescript tool without built-in Lua binary: |
75 | ```sh | 76 | ```sh |
76 | > make install NO_LUA=true | 77 | > make install NO_LUA=true |
77 | ``` | 78 | ``` |
78 | 79 | ||
79 |   Use MoonPlus tool with: | 80 |   Use Yuescript tool with: |
80 | 81 | ||
81 | ```sh | 82 | ```sh |
82 | > moonp -h | 83 | > yue -h |
83 | Usage: moonp [options|files|directories] ... | 84 | Usage: yue [options|files|directories] ... |
84 | 85 | ||
85 | -h Print this message | 86 | -h Print this message |
86 | -e str Execute a file or raw codes | 87 | -e str Execute a file or raw codes |
@@ -99,30 +100,18 @@ Usage: moonp [options|files|directories] ... | |||
99 | in a single line to start/stop multi-line mode | 100 | in a single line to start/stop multi-line mode |
100 | ``` | 101 | ``` |
101 |   Use cases: | 102 |   Use cases: |
102 |   Recursively compile every moon+ file with extension `.mp` under current path: `moonp .` | 103 |   Recursively compile every Yuescript file with extension `.yue` under current path: `yue .` |
103 |   Compile and save results to a target path: `moonp -t /target/path/ .` | 104 |   Compile and save results to a target path: `yue -t /target/path/ .` |
104 |   Compile and reserve debug info: `moonp -l .` | 105 |   Compile and reserve debug info: `yue -l .` |
105 |   Compile and generate minified codes: `moonp -m .` | 106 |   Compile and generate minified codes: `yue -m .` |
106 |   Execute raw codes: `moonp -e 'print 123'` | 107 |   Execute raw codes: `yue -e 'print 123'` |
107 |   Execute a moon+ file: `moonp -e main.mp` | 108 |   Execute a Yuescript file: `yue -e main.yue` |
108 | 109 | ||
109 | 110 | ||
110 | 111 | ||
111 | * **Docker Hub** | ||
112 | Try moonp in another easy way: https://hub.docker.com/r/moonplus/moonplus. | ||
113 | ```bash | ||
114 | docker run -it moonplus/moonplus:0.4.19 | ||
115 | ``` | ||
116 | |||
117 | The REPL console should be ready, | ||
118 | ```bash | ||
119 | Moonscript+ 0.4.19 | ||
120 | > | ||
121 | ``` | ||
122 | |||
123 | ## Editor Support | 112 | ## Editor Support |
124 | 113 | ||
125 | * [Vim](https://github.com/pigpigyyy/MoonPlus-vim) | 114 | * [Vim](https://github.com/pigpigyyy/Yuescript-vim) |
126 | 115 | ||
127 | 116 | ||
128 | 117 | ||
diff --git a/MoonPlus.sln b/Yuescript.sln index 252e9b4..7328cef 100644 --- a/MoonPlus.sln +++ b/Yuescript.sln | |||
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 | |||
3 | # Visual Studio Version 16 | 3 | # Visual Studio Version 16 |
4 | VisualStudioVersion = 16.0.29806.167 | 4 | VisualStudioVersion = 16.0.29806.167 |
5 | MinimumVisualStudioVersion = 10.0.40219.1 | 5 | MinimumVisualStudioVersion = 10.0.40219.1 |
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MoonPlus", "MoonPlus.vcxproj", "{CF4F54DB-61FE-48E0-BA2E-4168BA27ECBD}" | 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Yuescript", "Yuescript.vcxproj", "{CF4F54DB-61FE-48E0-BA2E-4168BA27ECBD}" |
7 | EndProject | 7 | EndProject |
8 | Global | 8 | Global |
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution | 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution |
diff --git a/MoonPlus.vcxproj b/Yuescript.vcxproj index d01007c..e284a4b 100644 --- a/MoonPlus.vcxproj +++ b/Yuescript.vcxproj | |||
@@ -21,8 +21,9 @@ | |||
21 | <PropertyGroup Label="Globals"> | 21 | <PropertyGroup Label="Globals"> |
22 | <VCProjectVersion>16.0</VCProjectVersion> | 22 | <VCProjectVersion>16.0</VCProjectVersion> |
23 | <ProjectGuid>{CF4F54DB-61FE-48E0-BA2E-4168BA27ECBD}</ProjectGuid> | 23 | <ProjectGuid>{CF4F54DB-61FE-48E0-BA2E-4168BA27ECBD}</ProjectGuid> |
24 | <RootNamespace>MoonPlus</RootNamespace> | 24 | <RootNamespace>Yuescript</RootNamespace> |
25 | <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | 25 | <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> |
26 | <ProjectName>Yuescript</ProjectName> | ||
26 | </PropertyGroup> | 27 | </PropertyGroup> |
27 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | 28 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
28 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | 29 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
@@ -73,25 +74,25 @@ | |||
73 | <LinkIncremental>true</LinkIncremental> | 74 | <LinkIncremental>true</LinkIncremental> |
74 | <IntDir>$(SolutionDir)\build\windows\$(Configuration)\</IntDir> | 75 | <IntDir>$(SolutionDir)\build\windows\$(Configuration)\</IntDir> |
75 | <OutDir>$(SolutionDir)\bin\windows\$(Configuration)\</OutDir> | 76 | <OutDir>$(SolutionDir)\bin\windows\$(Configuration)\</OutDir> |
76 | <TargetName>moonp</TargetName> | 77 | <TargetName>yue</TargetName> |
77 | </PropertyGroup> | 78 | </PropertyGroup> |
78 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | 79 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
79 | <LinkIncremental>true</LinkIncremental> | 80 | <LinkIncremental>true</LinkIncremental> |
80 | <OutDir>$(SolutionDir)\bin\windows\$(Platform)\$(Configuration)\</OutDir> | 81 | <OutDir>$(SolutionDir)\bin\windows\$(Platform)\$(Configuration)\</OutDir> |
81 | <IntDir>$(SolutionDir)\build\windows\$(Platform)\$(Configuration)\</IntDir> | 82 | <IntDir>$(SolutionDir)\build\windows\$(Platform)\$(Configuration)\</IntDir> |
82 | <TargetName>moonp</TargetName> | 83 | <TargetName>yue</TargetName> |
83 | </PropertyGroup> | 84 | </PropertyGroup> |
84 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | 85 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
85 | <LinkIncremental>false</LinkIncremental> | 86 | <LinkIncremental>false</LinkIncremental> |
86 | <IntDir>$(SolutionDir)\build\windows\$(Configuration)\</IntDir> | 87 | <IntDir>$(SolutionDir)\build\windows\$(Configuration)\</IntDir> |
87 | <OutDir>$(SolutionDir)\bin\windows\$(Configuration)\</OutDir> | 88 | <OutDir>$(SolutionDir)\bin\windows\$(Configuration)\</OutDir> |
88 | <TargetName>moonp</TargetName> | 89 | <TargetName>yue</TargetName> |
89 | </PropertyGroup> | 90 | </PropertyGroup> |
90 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | 91 | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
91 | <LinkIncremental>false</LinkIncremental> | 92 | <LinkIncremental>false</LinkIncremental> |
92 | <OutDir>$(SolutionDir)\bin\windows\$(Platform)\$(Configuration)\</OutDir> | 93 | <OutDir>$(SolutionDir)\bin\windows\$(Platform)\$(Configuration)\</OutDir> |
93 | <IntDir>$(SolutionDir)\build\windows\$(Platform)\$(Configuration)\</IntDir> | 94 | <IntDir>$(SolutionDir)\build\windows\$(Platform)\$(Configuration)\</IntDir> |
94 | <TargetName>moonp</TargetName> | 95 | <TargetName>yue</TargetName> |
95 | </PropertyGroup> | 96 | </PropertyGroup> |
96 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | 97 | <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
97 | <ClCompile> | 98 | <ClCompile> |
@@ -194,12 +195,12 @@ | |||
194 | <ClCompile Include="src\lua\lutf8lib.c" /> | 195 | <ClCompile Include="src\lua\lutf8lib.c" /> |
195 | <ClCompile Include="src\lua\lvm.c" /> | 196 | <ClCompile Include="src\lua\lvm.c" /> |
196 | <ClCompile Include="src\lua\lzio.c" /> | 197 | <ClCompile Include="src\lua\lzio.c" /> |
197 | <ClCompile Include="src\moonp.cpp" /> | 198 | <ClCompile Include="src\yue.cpp" /> |
198 | <ClCompile Include="src\MoonP\ast.cpp" /> | 199 | <ClCompile Include="src\yuescript\ast.cpp" /> |
199 | <ClCompile Include="src\MoonP\moonplus.cpp" /> | 200 | <ClCompile Include="src\yuescript\parser.cpp" /> |
200 | <ClCompile Include="src\MoonP\moon_compiler.cpp" /> | 201 | <ClCompile Include="src\yuescript\yuescript.cpp" /> |
201 | <ClCompile Include="src\MoonP\moon_parser.cpp" /> | 202 | <ClCompile Include="src\yuescript\yue_compiler.cpp" /> |
202 | <ClCompile Include="src\MoonP\parser.cpp" /> | 203 | <ClCompile Include="src\yuescript\yue_parser.cpp" /> |
203 | </ItemGroup> | 204 | </ItemGroup> |
204 | <ItemGroup> | 205 | <ItemGroup> |
205 | <ClInclude Include="src\linenoise.hpp" /> | 206 | <ClInclude Include="src\linenoise.hpp" /> |
@@ -230,15 +231,15 @@ | |||
230 | <ClInclude Include="src\lua\lundump.h" /> | 231 | <ClInclude Include="src\lua\lundump.h" /> |
231 | <ClInclude Include="src\lua\lvm.h" /> | 232 | <ClInclude Include="src\lua\lvm.h" /> |
232 | <ClInclude Include="src\lua\lzio.h" /> | 233 | <ClInclude Include="src\lua\lzio.h" /> |
233 | <ClInclude Include="src\MoonP\ast.hpp" /> | 234 | <ClInclude Include="src\yuescript\ast.hpp" /> |
234 | <ClInclude Include="src\MoonP\moonplus.h" /> | 235 | <ClInclude Include="src\yuescript\parser.hpp" /> |
235 | <ClInclude Include="src\MoonP\moon_ast.h" /> | 236 | <ClInclude Include="src\yuescript\stacktraceplus.h" /> |
236 | <ClInclude Include="src\MoonP\moon_compiler.h" /> | 237 | <ClInclude Include="src\yuescript\yuescript.h" /> |
237 | <ClInclude Include="src\MoonP\moon_parser.h" /> | 238 | <ClInclude Include="src\yuescript\yue_ast.h" /> |
238 | <ClInclude Include="src\MoonP\parser.hpp" /> | 239 | <ClInclude Include="src\yuescript\yue_compiler.h" /> |
239 | <ClInclude Include="src\MoonP\stacktraceplus.h" /> | 240 | <ClInclude Include="src\yuescript\yue_parser.h" /> |
240 | </ItemGroup> | 241 | </ItemGroup> |
241 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | 242 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
242 | <ImportGroup Label="ExtensionTargets"> | 243 | <ImportGroup Label="ExtensionTargets"> |
243 | </ImportGroup> | 244 | </ImportGroup> |
244 | </Project> \ No newline at end of file | 245 | </Project> |
diff --git a/MoonPlus.vcxproj.filters b/Yuescript.vcxproj.filters index 6e61e9c..97385f3 100644 --- a/MoonPlus.vcxproj.filters +++ b/Yuescript.vcxproj.filters | |||
@@ -5,32 +5,14 @@ | |||
5 | <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | 5 | <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> |
6 | <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> | 6 | <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> |
7 | </Filter> | 7 | </Filter> |
8 | <Filter Include="src\MoonP"> | ||
9 | <UniqueIdentifier>{c88639d5-457d-42eb-b852-65682c89c618}</UniqueIdentifier> | ||
10 | </Filter> | ||
11 | <Filter Include="src\lua"> | 8 | <Filter Include="src\lua"> |
12 | <UniqueIdentifier>{338bdf98-6a02-4589-a373-c7bca25c746b}</UniqueIdentifier> | 9 | <UniqueIdentifier>{338bdf98-6a02-4589-a373-c7bca25c746b}</UniqueIdentifier> |
13 | </Filter> | 10 | </Filter> |
11 | <Filter Include="src\yuescript"> | ||
12 | <UniqueIdentifier>{af398a57-cb37-4862-a5e8-5ec539259611}</UniqueIdentifier> | ||
13 | </Filter> | ||
14 | </ItemGroup> | 14 | </ItemGroup> |
15 | <ItemGroup> | 15 | <ItemGroup> |
16 | <ClCompile Include="src\MoonP\ast.cpp"> | ||
17 | <Filter>src\MoonP</Filter> | ||
18 | </ClCompile> | ||
19 | <ClCompile Include="src\MoonP\moon_compiler.cpp"> | ||
20 | <Filter>src\MoonP</Filter> | ||
21 | </ClCompile> | ||
22 | <ClCompile Include="src\MoonP\moon_parser.cpp"> | ||
23 | <Filter>src\MoonP</Filter> | ||
24 | </ClCompile> | ||
25 | <ClCompile Include="src\MoonP\parser.cpp"> | ||
26 | <Filter>src\MoonP</Filter> | ||
27 | </ClCompile> | ||
28 | <ClCompile Include="src\moonp.cpp"> | ||
29 | <Filter>src</Filter> | ||
30 | </ClCompile> | ||
31 | <ClCompile Include="src\MoonP\moonplus.cpp"> | ||
32 | <Filter>src\MoonP</Filter> | ||
33 | </ClCompile> | ||
34 | <ClCompile Include="src\lua\lapi.c"> | 16 | <ClCompile Include="src\lua\lapi.c"> |
35 | <Filter>src\lua</Filter> | 17 | <Filter>src\lua</Filter> |
36 | </ClCompile> | 18 | </ClCompile> |
@@ -127,29 +109,26 @@ | |||
127 | <ClCompile Include="src\lua\lzio.c"> | 109 | <ClCompile Include="src\lua\lzio.c"> |
128 | <Filter>src\lua</Filter> | 110 | <Filter>src\lua</Filter> |
129 | </ClCompile> | 111 | </ClCompile> |
112 | <ClCompile Include="src\yuescript\ast.cpp"> | ||
113 | <Filter>src\yuescript</Filter> | ||
114 | </ClCompile> | ||
115 | <ClCompile Include="src\yuescript\parser.cpp"> | ||
116 | <Filter>src\yuescript</Filter> | ||
117 | </ClCompile> | ||
118 | <ClCompile Include="src\yuescript\yue_compiler.cpp"> | ||
119 | <Filter>src\yuescript</Filter> | ||
120 | </ClCompile> | ||
121 | <ClCompile Include="src\yuescript\yue_parser.cpp"> | ||
122 | <Filter>src\yuescript</Filter> | ||
123 | </ClCompile> | ||
124 | <ClCompile Include="src\yuescript\yuescript.cpp"> | ||
125 | <Filter>src\yuescript</Filter> | ||
126 | </ClCompile> | ||
127 | <ClCompile Include="src\yue.cpp"> | ||
128 | <Filter>src</Filter> | ||
129 | </ClCompile> | ||
130 | </ItemGroup> | 130 | </ItemGroup> |
131 | <ItemGroup> | 131 | <ItemGroup> |
132 | <ClInclude Include="src\MoonP\ast.hpp"> | ||
133 | <Filter>src\MoonP</Filter> | ||
134 | </ClInclude> | ||
135 | <ClInclude Include="src\MoonP\moon_ast.h"> | ||
136 | <Filter>src\MoonP</Filter> | ||
137 | </ClInclude> | ||
138 | <ClInclude Include="src\MoonP\moon_compiler.h"> | ||
139 | <Filter>src\MoonP</Filter> | ||
140 | </ClInclude> | ||
141 | <ClInclude Include="src\MoonP\moon_parser.h"> | ||
142 | <Filter>src\MoonP</Filter> | ||
143 | </ClInclude> | ||
144 | <ClInclude Include="src\MoonP\parser.hpp"> | ||
145 | <Filter>src\MoonP</Filter> | ||
146 | </ClInclude> | ||
147 | <ClInclude Include="src\MoonP\moonplus.h"> | ||
148 | <Filter>src\MoonP</Filter> | ||
149 | </ClInclude> | ||
150 | <ClInclude Include="src\MoonP\stacktraceplus.h"> | ||
151 | <Filter>src\MoonP</Filter> | ||
152 | </ClInclude> | ||
153 | <ClInclude Include="src\linenoise.hpp"> | 132 | <ClInclude Include="src\linenoise.hpp"> |
154 | <Filter>src</Filter> | 133 | <Filter>src</Filter> |
155 | </ClInclude> | 134 | </ClInclude> |
@@ -234,5 +213,26 @@ | |||
234 | <ClInclude Include="src\lua\lzio.h"> | 213 | <ClInclude Include="src\lua\lzio.h"> |
235 | <Filter>src\lua</Filter> | 214 | <Filter>src\lua</Filter> |
236 | </ClInclude> | 215 | </ClInclude> |
216 | <ClInclude Include="src\yuescript\ast.hpp"> | ||
217 | <Filter>src\yuescript</Filter> | ||
218 | </ClInclude> | ||
219 | <ClInclude Include="src\yuescript\parser.hpp"> | ||
220 | <Filter>src\yuescript</Filter> | ||
221 | </ClInclude> | ||
222 | <ClInclude Include="src\yuescript\stacktraceplus.h"> | ||
223 | <Filter>src\yuescript</Filter> | ||
224 | </ClInclude> | ||
225 | <ClInclude Include="src\yuescript\yue_ast.h"> | ||
226 | <Filter>src\yuescript</Filter> | ||
227 | </ClInclude> | ||
228 | <ClInclude Include="src\yuescript\yue_compiler.h"> | ||
229 | <Filter>src\yuescript</Filter> | ||
230 | </ClInclude> | ||
231 | <ClInclude Include="src\yuescript\yue_parser.h"> | ||
232 | <Filter>src\yuescript</Filter> | ||
233 | </ClInclude> | ||
234 | <ClInclude Include="src\yuescript\yuescript.h"> | ||
235 | <Filter>src\yuescript</Filter> | ||
236 | </ClInclude> | ||
237 | </ItemGroup> | 237 | </ItemGroup> |
238 | </Project> \ No newline at end of file | 238 | </Project> \ No newline at end of file |
diff --git a/appveyor.yml b/appveyor.yml index 94125fd..c7f83e9 100644 --- a/appveyor.yml +++ b/appveyor.yml | |||
@@ -8,7 +8,7 @@ configuration: | |||
8 | - Release | 8 | - Release |
9 | platform: x86 | 9 | platform: x86 |
10 | build: | 10 | build: |
11 | project: MoonPlus.sln | 11 | project: Yuescript.sln |
12 | parallel: true | 12 | parallel: true |
13 | verbosity: normal | 13 | verbosity: normal |
14 | test: off | 14 | test: off |
diff --git a/docker/Dockerfile b/docker/Dockerfile index c4ccab9..d1e75b1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile | |||
@@ -11,10 +11,6 @@ RUN cd /tmp && wget https://luarocks.org/releases/luarocks-3.3.1.tar.gz \ | |||
11 | && make && make install \ | 11 | && make && make install \ |
12 | && cd /tmp ; rm -rf luarocks-3.3.1 luarocks-3.3.1.tar.gz | 12 | && cd /tmp ; rm -rf luarocks-3.3.1 luarocks-3.3.1.tar.gz |
13 | 13 | ||
14 | RUN luarocks install moonplus | 14 | RUN luarocks install yuescript |
15 | 15 | ||
16 | RUN cd /tmp && git clone https://github.com/pigpigyyy/MoonPlus \ | 16 | CMD ["yue"] |
17 | && cd MoonPlus && make install \ | ||
18 | && cd /tmp ; rm -rf MoonPlus/ | ||
19 | |||
20 | CMD ["moonp"] | ||
@@ -1,6 +1,6 @@ | |||
1 | #### PROJECT SETTINGS #### | 1 | #### PROJECT SETTINGS #### |
2 | # The name of the executable to be created | 2 | # The name of the executable to be created |
3 | BIN_NAME := moonp | 3 | BIN_NAME := yue |
4 | # Compiler used | 4 | # Compiler used |
5 | CXX ?= g++ | 5 | CXX ?= g++ |
6 | # Extension of source files used in the project | 6 | # Extension of source files used in the project |
@@ -42,10 +42,10 @@ TEST_OUTPUT = ./spec/outputs | |||
42 | UNAME_S:=$(shell uname -s) | 42 | UNAME_S:=$(shell uname -s) |
43 | 43 | ||
44 | ifeq ($(NO_LUA),true) | 44 | ifeq ($(NO_LUA),true) |
45 | COMPILE_FLAGS += -DMOONP_NO_MACRO -DMOONP_COMPILER_ONLY | 45 | COMPILE_FLAGS += -DYUE_NO_MACRO -DYUE_COMPILER_ONLY |
46 | else | 46 | else |
47 | ifeq ($(NO_MACRO),true) | 47 | ifeq ($(NO_MACRO),true) |
48 | COMPILE_FLAGS += -DMOONP_NO_MACRO | 48 | COMPILE_FLAGS += -DYUE_NO_MACRO |
49 | endif | 49 | endif |
50 | INCLUDES += -I ./src/lua | 50 | INCLUDES += -I ./src/lua |
51 | LINK_FLAGS += -L ./src/lua -llua -ldl | 51 | LINK_FLAGS += -L ./src/lua -llua -ldl |
@@ -117,7 +117,7 @@ ifeq ($(SOURCES),) | |||
117 | endif | 117 | endif |
118 | 118 | ||
119 | ifeq ($(NO_LUA),true) | 119 | ifeq ($(NO_LUA),true) |
120 | SOURCES := $(filter-out ./src/MoonP/moonplus.cpp, $(SOURCES)) | 120 | SOURCES := $(filter-out ./src/yuescript/yue.cpp, $(SOURCES)) |
121 | endif | 121 | endif |
122 | 122 | ||
123 | # Set the object file names, with the source directory stripped | 123 | # Set the object file names, with the source directory stripped |
@@ -199,7 +199,7 @@ endif | |||
199 | @echo -n "Total build time: " | 199 | @echo -n "Total build time: " |
200 | @$(END_TIME) | 200 | @$(END_TIME) |
201 | 201 | ||
202 | $(BUILD_PATH)/moonp.so: src/MoonP/ast.cpp src/MoonP/moon_compiler.cpp src/MoonP/moon_parser.cpp src/MoonP/moonplus.cpp src/MoonP/parser.cpp | 202 | $(BUILD_PATH)/yue.so: src/yuescript/ast.cpp src/yuescript/yue_compiler.cpp src/yuescript/yue_parser.cpp src/yuescript/yue.cpp src/yuescript/parser.cpp |
203 | $(CMD_PREFIX)$(CXX) $(CXXFLAGS) -I $(SRC_PATH) -I $(LUAI) -L $(LUAL) -llua -o $@ -fPIC -shared $? | 203 | $(CMD_PREFIX)$(CXX) $(CXXFLAGS) -I $(SRC_PATH) -I $(LUAI) -L $(LUAL) -llua -o $@ -fPIC -shared $? |
204 | 204 | ||
205 | # Standard, non-optimized release build | 205 | # Standard, non-optimized release build |
@@ -211,10 +211,10 @@ else | |||
211 | @echo "Beginning release build" | 211 | @echo "Beginning release build" |
212 | endif | 212 | endif |
213 | @$(START_TIME) | 213 | @$(START_TIME) |
214 | @$(MAKE) $(BUILD_PATH)/moonp.so --no-print-directory | 214 | @$(MAKE) $(BUILD_PATH)/yue.so --no-print-directory |
215 | @echo -n "Total build time: " | 215 | @echo -n "Total build time: " |
216 | @$(END_TIME) | 216 | @$(END_TIME) |
217 | @mv $(BUILD_PATH)/moonp.so $(BIN_PATH)/moonp.so | 217 | @mv $(BUILD_PATH)/yue.so $(BIN_PATH)/yue.so |
218 | 218 | ||
219 | # Create the directories used in the build | 219 | # Create the directories used in the build |
220 | .PHONY: dirs | 220 | .PHONY: dirs |
@@ -248,13 +248,13 @@ clean: | |||
248 | @echo "Deleting generated Lua codes" | 248 | @echo "Deleting generated Lua codes" |
249 | @$(RM) -r $(TEST_OUTPUT) | 249 | @$(RM) -r $(TEST_OUTPUT) |
250 | 250 | ||
251 | # Test Moonscript compiler | 251 | # Test Yuescript compiler |
252 | .PHONY: test | 252 | .PHONY: test |
253 | test: debug | 253 | test: release |
254 | @echo "Compiling Moonscript codes..." | 254 | @echo "Compiling Yuescript codes..." |
255 | @$(START_TIME) | 255 | @$(START_TIME) |
256 | @./$(BIN_NAME) $(TEST_INPUT) -t $(TEST_OUTPUT) -tl_enabled=true | 256 | @./$(BIN_NAME) $(TEST_INPUT) -t $(TEST_OUTPUT) -tl_enabled=true |
257 | @./$(BIN_NAME) $(TEST_INPUT)/teal-lang.mp -o $(TEST_OUTPUT)/teal-lang.lua | 257 | @./$(BIN_NAME) $(TEST_INPUT)/teal-lang.yue -o $(TEST_OUTPUT)/teal-lang.lua |
258 | @echo -en "Compile time: " | 258 | @echo -en "Compile time: " |
259 | @$(END_TIME) | 259 | @$(END_TIME) |
260 | 260 | ||
diff --git a/moonplus-dev-1.rockspec b/moonplus-dev-1.rockspec deleted file mode 100644 index 40db89b..0000000 --- a/moonplus-dev-1.rockspec +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | rockspec_format = "3.0" | ||
2 | package = "MoonPlus" | ||
3 | version = "dev-1" | ||
4 | source = { | ||
5 | url = "git+https://github.com/pigpigyyy/MoonPlus" | ||
6 | } | ||
7 | description = { | ||
8 | summary = "MoonPlus is a compiler for Moonscript written in C++.", | ||
9 | detailed = [[ | ||
10 | MoonPlus is a compiler with features from Moonscript language 0.5.0 and implementing new features to make Moonscript more up to date. ]], | ||
11 | homepage = "https://github.com/pigpigyyy/MoonPlus", | ||
12 | maintainer = "Li Jin <dragon-fly@qq.com>", | ||
13 | labels = {"moonscript","cpp","transpiler"}, | ||
14 | license = "MIT" | ||
15 | } | ||
16 | dependencies = { | ||
17 | "lua >= 5.1", | ||
18 | } | ||
19 | build = { | ||
20 | type = "cmake", | ||
21 | variables = { | ||
22 | LUA_INCDIR="$(LUA_INCDIR)", | ||
23 | LUA="$(LUA)", | ||
24 | }, | ||
25 | install = { | ||
26 | lib = { | ||
27 | "build.luarocks/moonp.so" | ||
28 | }, | ||
29 | bin = { | ||
30 | "build.luarocks/moonp" | ||
31 | } | ||
32 | } | ||
33 | } | ||
diff --git a/spec/inputs/ambiguous.mp b/spec/inputs/ambiguous.yue index d147e8e..d147e8e 100644 --- a/spec/inputs/ambiguous.mp +++ b/spec/inputs/ambiguous.yue | |||
diff --git a/spec/inputs/assign.mp b/spec/inputs/assign.yue index dac2ba3..dac2ba3 100644 --- a/spec/inputs/assign.mp +++ b/spec/inputs/assign.yue | |||
diff --git a/spec/inputs/attrib.mp b/spec/inputs/attrib.yue index 7e9a42c..7e9a42c 100644 --- a/spec/inputs/attrib.mp +++ b/spec/inputs/attrib.yue | |||
diff --git a/spec/inputs/backcall.mp b/spec/inputs/backcall.yue index 0d52f3f..bad3a56 100644 --- a/spec/inputs/backcall.mp +++ b/spec/inputs/backcall.yue | |||
@@ -36,6 +36,20 @@ arr[3] |> f 1, 2, _, 4, 5 | |||
36 | 36 | ||
37 | a = {"1","2","3"} |> table.concat("") |> tonumber |> f1(1, 2, 3, _) |> f2(1, _, 3) | 37 | a = {"1","2","3"} |> table.concat("") |> tonumber |> f1(1, 2, 3, _) |> f2(1, _, 3) |
38 | 38 | ||
39 | readFile("example.txt") |> | ||
40 | extract(_, language, {}) |> | ||
41 | parse(_, language) |> | ||
42 | emit |> | ||
43 | render |> | ||
44 | |||
45 | |||
46 | readFile("example.txt") \ | ||
47 | |> extract(_, language, {}) \ | ||
48 | |> parse(_, language) \ | ||
49 | |> emit \ | ||
50 | |> render \ | ||
51 | |||
52 | |||
39 | readFile "example.txt" | 53 | readFile "example.txt" |
40 | |> extract _, language, {} | 54 | |> extract _, language, {} |
41 | |> parse _, language | 55 | |> parse _, language |
diff --git a/spec/inputs/bubbling.mp b/spec/inputs/bubbling.yue index 23a85d4..23a85d4 100644 --- a/spec/inputs/bubbling.mp +++ b/spec/inputs/bubbling.yue | |||
diff --git a/spec/inputs/class.mp b/spec/inputs/class.yue index ca8b58c..ca8b58c 100644 --- a/spec/inputs/class.mp +++ b/spec/inputs/class.yue | |||
diff --git a/spec/inputs/comprehension.mp b/spec/inputs/comprehension.yue index b6adb94..b6adb94 100644 --- a/spec/inputs/comprehension.mp +++ b/spec/inputs/comprehension.yue | |||
diff --git a/spec/inputs/cond.mp b/spec/inputs/cond.yue index 3dee99b..3dee99b 100644 --- a/spec/inputs/cond.mp +++ b/spec/inputs/cond.yue | |||
diff --git a/spec/inputs/destructure.mp b/spec/inputs/destructure.yue index 49e6393..49e6393 100644 --- a/spec/inputs/destructure.mp +++ b/spec/inputs/destructure.yue | |||
diff --git a/spec/inputs/do.mp b/spec/inputs/do.yue index 2fbcbb9..2fbcbb9 100644 --- a/spec/inputs/do.mp +++ b/spec/inputs/do.yue | |||
diff --git a/spec/inputs/existential.mp b/spec/inputs/existential.yue index 3055705..3055705 100644 --- a/spec/inputs/existential.mp +++ b/spec/inputs/existential.yue | |||
diff --git a/spec/inputs/export.mp b/spec/inputs/export.yue index 085510e..085510e 100644 --- a/spec/inputs/export.mp +++ b/spec/inputs/export.yue | |||
diff --git a/spec/inputs/export_default.mp b/spec/inputs/export_default.yue index 73f43ac..73f43ac 100644 --- a/spec/inputs/export_default.mp +++ b/spec/inputs/export_default.yue | |||
diff --git a/spec/inputs/funcs.mp b/spec/inputs/funcs.yue index 0e45ff1..0e45ff1 100644 --- a/spec/inputs/funcs.mp +++ b/spec/inputs/funcs.yue | |||
diff --git a/spec/inputs/global.mp b/spec/inputs/global.yue index 7d6cfde..7d6cfde 100644 --- a/spec/inputs/global.mp +++ b/spec/inputs/global.yue | |||
diff --git a/spec/inputs/goto.mp b/spec/inputs/goto.yue index 1197251..1197251 100644 --- a/spec/inputs/goto.mp +++ b/spec/inputs/goto.yue | |||
diff --git a/spec/inputs/import.mp b/spec/inputs/import.yue index e075404..e075404 100644 --- a/spec/inputs/import.mp +++ b/spec/inputs/import.yue | |||
diff --git a/spec/inputs/lists.mp b/spec/inputs/lists.yue index 15eb9ab..15eb9ab 100644 --- a/spec/inputs/lists.mp +++ b/spec/inputs/lists.yue | |||
diff --git a/spec/inputs/literals.mp b/spec/inputs/literals.yue index d4b0326..d4b0326 100644 --- a/spec/inputs/literals.mp +++ b/spec/inputs/literals.yue | |||
diff --git a/spec/inputs/local.mp b/spec/inputs/local.yue index 33251a9..33251a9 100644 --- a/spec/inputs/local.mp +++ b/spec/inputs/local.yue | |||
diff --git a/spec/inputs/loops.mp b/spec/inputs/loops.yue index 8946a2f..8946a2f 100644 --- a/spec/inputs/loops.mp +++ b/spec/inputs/loops.yue | |||
diff --git a/spec/inputs/macro-export.mp b/spec/inputs/macro-export.yue index d669975..d669975 100644 --- a/spec/inputs/macro-export.mp +++ b/spec/inputs/macro-export.yue | |||
diff --git a/spec/inputs/macro-teal.mp b/spec/inputs/macro-teal.yue index 37cde1c..3a9bb2b 100644 --- a/spec/inputs/macro-teal.mp +++ b/spec/inputs/macro-teal.yue | |||
@@ -1,17 +1,17 @@ | |||
1 | $ -> | 1 | $ -> |
2 | import "moonp" as {:options} | 2 | import "yue" as {:options} |
3 | if options.tl_enabled | 3 | if options.tl_enabled |
4 | options.target_extension = "tl" | 4 | options.target_extension = "tl" |
5 | package.path ..= "?.lua;./spec/lib/?.lua" | 5 | package.path ..= "?.lua;./spec/lib/?.lua" |
6 | 6 | ||
7 | macro to_lua = (codes)-> | 7 | macro to_lua = (codes)-> |
8 | "require('moonp').to_lua(#{codes}, reserve_line_number:false, same_module:true)" | 8 | "require('yue').to_lua(#{codes}, reserve_line_number:false, same_module:true)" |
9 | 9 | ||
10 | macro trim = (name)-> | 10 | macro trim = (name)-> |
11 | "if result = #{name}\\match '[\\'\"](.*)[\\'\"]' then result else #{name}" | 11 | "if result = #{name}\\match '[\\'\"](.*)[\\'\"]' then result else #{name}" |
12 | 12 | ||
13 | export macro local = (decl, value = nil)-> | 13 | export macro local = (decl, value = nil)-> |
14 | import "moonp" as {options:{:tl_enabled}} | 14 | import "yue" as {options:{:tl_enabled}} |
15 | name, type = ($trim decl)\match "(.-):(.*)" | 15 | name, type = ($trim decl)\match "(.-):(.*)" |
16 | if not (name and type) | 16 | if not (name and type) |
17 | error "invalid local varaible declaration for \"#{decl}\"" | 17 | error "invalid local varaible declaration for \"#{decl}\"" |
@@ -27,7 +27,7 @@ export macro local = (decl, value = nil)-> | |||
27 | } | 27 | } |
28 | 28 | ||
29 | export macro function = (decl, value)-> | 29 | export macro function = (decl, value)-> |
30 | import "moonp" as {options:{:tl_enabled}} | 30 | import "yue" as {options:{:tl_enabled}} |
31 | import "tl" | 31 | import "tl" |
32 | decl = $trim decl | 32 | decl = $trim decl |
33 | name, type = decl\match "(.-)(%(.*)" | 33 | name, type = decl\match "(.-)(%(.*)" |
@@ -50,7 +50,7 @@ export macro function = (decl, value)-> | |||
50 | } | 50 | } |
51 | 51 | ||
52 | export macro record = (name, decl)-> | 52 | export macro record = (name, decl)-> |
53 | import "moonp" as {options:{:tl_enabled}} | 53 | import "yue" as {options:{:tl_enabled}} |
54 | codes = if tl_enabled | 54 | codes = if tl_enabled |
55 | "local record #{name} | 55 | "local record #{name} |
56 | #{decl} | 56 | #{decl} |
@@ -64,7 +64,7 @@ end" | |||
64 | } | 64 | } |
65 | 65 | ||
66 | export macro method = (decl, value)-> | 66 | export macro method = (decl, value)-> |
67 | import "moonp" as {options:{:tl_enabled}} | 67 | import "yue" as {options:{:tl_enabled}} |
68 | import "tl" | 68 | import "tl" |
69 | decl = $trim decl | 69 | decl = $trim decl |
70 | tab, sym, func, type = decl\match "(.-)([%.:])(.-)(%(.*)" | 70 | tab, sym, func, type = decl\match "(.-)([%.:])(.-)(%(.*)" |
diff --git a/spec/inputs/macro.mp b/spec/inputs/macro.yue index f0292c7..eb3cf75 100644 --- a/spec/inputs/macro.mp +++ b/spec/inputs/macro.yue | |||
@@ -1,5 +1,5 @@ | |||
1 | $ -> | 1 | $ -> |
2 | package.moonpath = "?.mp;./spec/inputs/?.mp" | 2 | package.yuepath = "?.yue;./spec/inputs/?.yue" |
3 | 3 | ||
4 | import "macro-export" as { | 4 | import "macro-export" as { |
5 | $, -- import all macros | 5 | $, -- import all macros |
diff --git a/spec/inputs/multiline_chain.mp b/spec/inputs/multiline_chain.yue index e1e363f..d582ed0 100644 --- a/spec/inputs/multiline_chain.mp +++ b/spec/inputs/multiline_chain.yue | |||
@@ -1,15 +1,44 @@ | |||
1 | x = a | 1 | x = a |
2 | .b | 2 | .b |
3 | .c | ||
4 | --[[chain item]] .d | ||
3 | 5 | ||
4 | x | 6 | x |
5 | .y = a | 7 | .y = a |
6 | \b! | 8 | .b |
9 | \c! | ||
7 | 10 | ||
8 | func 1, arg2 | 11 | func 1, arg2 |
9 | .value | 12 | .value |
10 | \get!, arg3 | 13 | \get!, arg3 |
11 | .value | 14 | .value |
12 | \get! | 15 | \get! |
16 | * 1 | ||
17 | * x? | ||
18 | .y? | ||
19 | .z? | ||
20 | * 3 | ||
21 | |||
22 | tbb = | ||
23 | k1: a | ||
24 | \b 123 | ||
25 | .c! | ||
26 | k2: | ||
27 | w1: a! | ||
28 | .b | ||
29 | \c! | ||
30 | |||
31 | tb = f1{} | ||
32 | .a | ||
33 | |> f2? "abc", _ | ||
34 | |||
35 | f = -> [a | ||
36 | .b | ||
37 | \c 123 for {a} in *vals] | ||
38 | |||
39 | f1 = -> x, a | ||
40 | \b 123 | ||
41 | .c "abc" | ||
13 | 42 | ||
14 | result = origin | 43 | result = origin |
15 | .transform.root | 44 | .transform.root |
@@ -33,9 +62,8 @@ origin.transform.root.gameObject | |||
33 | \Where (x)-> x.name\EndsWith "(Clone)" | 62 | \Where (x)-> x.name\EndsWith "(Clone)" |
34 | \Destroy! | 63 | \Destroy! |
35 | 64 | ||
36 | with item() | 65 | with item |
37 | .itemFieldA = 123 | 66 | .itemFieldA = 123 |
38 | item = x | ||
39 | 67 | ||
40 | \callMethod!\chainCall! | 68 | \callMethod!\chainCall! |
41 | 69 | ||
@@ -59,6 +87,9 @@ with item() | |||
59 | for v in *values | 87 | for v in *values |
60 | \itemMethodC v | 88 | \itemMethodC v |
61 | 89 | ||
90 | for i = 1, counter | ||
91 | \itemMethodC i | ||
92 | |||
62 | unless .b | 93 | unless .b |
63 | .c = while .itemFieldD | 94 | .c = while .itemFieldD |
64 | \itemNext! | 95 | \itemNext! |
diff --git a/spec/inputs/operators.mp b/spec/inputs/operators.yue index 57e58d6..57e58d6 100644 --- a/spec/inputs/operators.mp +++ b/spec/inputs/operators.yue | |||
diff --git a/spec/inputs/plus.mp b/spec/inputs/plus.yue index e387090..e387090 100644 --- a/spec/inputs/plus.mp +++ b/spec/inputs/plus.yue | |||
diff --git a/spec/inputs/return.mp b/spec/inputs/return.yue index f170ffd..f170ffd 100644 --- a/spec/inputs/return.mp +++ b/spec/inputs/return.yue | |||
diff --git a/spec/inputs/string.mp b/spec/inputs/string.yue index 5d8f772..5d8f772 100644 --- a/spec/inputs/string.mp +++ b/spec/inputs/string.yue | |||
diff --git a/spec/inputs/stub.mp b/spec/inputs/stub.yue index 60347e7..60347e7 100644 --- a/spec/inputs/stub.mp +++ b/spec/inputs/stub.yue | |||
diff --git a/spec/inputs/switch.mp b/spec/inputs/switch.yue index ac3dbea..ac3dbea 100644 --- a/spec/inputs/switch.mp +++ b/spec/inputs/switch.yue | |||
diff --git a/spec/inputs/syntax.mp b/spec/inputs/syntax.yue index 4df5785..4df5785 100644 --- a/spec/inputs/syntax.mp +++ b/spec/inputs/syntax.yue | |||
diff --git a/spec/inputs/tables.mp b/spec/inputs/tables.yue index 2c6dff9..2c6dff9 100644 --- a/spec/inputs/tables.mp +++ b/spec/inputs/tables.yue | |||
diff --git a/spec/inputs/teal-lang.mp b/spec/inputs/teal-lang.yue index 3368b95..1993203 100644 --- a/spec/inputs/teal-lang.mp +++ b/spec/inputs/teal-lang.yue | |||
@@ -1,5 +1,5 @@ | |||
1 | $ -> | 1 | $ -> |
2 | package.moonpath = "?.mp;./spec/inputs/?.mp" | 2 | package.yuepath = "?.yue;./spec/inputs/?.yue" |
3 | 3 | ||
4 | import "macro-teal" as {$} | 4 | import "macro-teal" as {$} |
5 | 5 | ||
diff --git a/spec/inputs/unless_else.mp b/spec/inputs/unless_else.yue index b421d4d..b421d4d 100644 --- a/spec/inputs/unless_else.mp +++ b/spec/inputs/unless_else.yue | |||
diff --git a/spec/inputs/using.mp b/spec/inputs/using.yue index fe0a433..fe0a433 100644 --- a/spec/inputs/using.mp +++ b/spec/inputs/using.yue | |||
diff --git a/spec/inputs/whitespace.mp b/spec/inputs/whitespace.yue index 329280f..329280f 100644 --- a/spec/inputs/whitespace.mp +++ b/spec/inputs/whitespace.yue | |||
diff --git a/spec/inputs/with.mp b/spec/inputs/with.yue index d88e109..d88e109 100644 --- a/spec/inputs/with.mp +++ b/spec/inputs/with.yue | |||
diff --git a/src/moonp.cpp b/src/yue.cpp index 27c6016..b5f91ff 100644 --- a/src/moonp.cpp +++ b/src/yue.cpp | |||
@@ -6,8 +6,8 @@ The above copyright notice and this permission notice shall be included in all c | |||
6 | 6 | ||
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
8 | 8 | ||
9 | #include "MoonP/moon_compiler.h" | 9 | #include "yuescript/yue_compiler.h" |
10 | #include "MoonP/moon_parser.h" | 10 | #include "yuescript/yue_parser.h" |
11 | 11 | ||
12 | #include <iostream> | 12 | #include <iostream> |
13 | #include <iomanip> | 13 | #include <iomanip> |
@@ -24,29 +24,29 @@ using namespace std::string_view_literals; | |||
24 | #include "ghc/fs_std.hpp" | 24 | #include "ghc/fs_std.hpp" |
25 | #include "linenoise.hpp" | 25 | #include "linenoise.hpp" |
26 | 26 | ||
27 | #if not (defined MOONP_NO_MACRO && defined MOONP_COMPILER_ONLY) | 27 | #if not (defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) |
28 | #define _DEFER(code,line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto){code;}) | 28 | #define _DEFER(code,line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto){code;}) |
29 | #define DEFER(code) _DEFER(code,__LINE__) | 29 | #define DEFER(code) _DEFER(code,__LINE__) |
30 | extern "C" { | 30 | extern "C" { |
31 | #include "lua.h" | 31 | #include "lua.h" |
32 | #include "lauxlib.h" | 32 | #include "lauxlib.h" |
33 | #include "lualib.h" | 33 | #include "lualib.h" |
34 | int luaopen_moonp(lua_State* L); | 34 | int luaopen_yue(lua_State* L); |
35 | } // extern "C" | 35 | } // extern "C" |
36 | 36 | ||
37 | static void openlibs(void* state) { | 37 | static void openlibs(void* state) { |
38 | lua_State* L = static_cast<lua_State*>(state); | 38 | lua_State* L = static_cast<lua_State*>(state); |
39 | luaL_openlibs(L); | 39 | luaL_openlibs(L); |
40 | luaopen_moonp(L); | 40 | luaopen_yue(L); |
41 | } | 41 | } |
42 | 42 | ||
43 | void pushMoonp(lua_State* L, std::string_view name) { | 43 | void pushYue(lua_State* L, std::string_view name) { |
44 | lua_getglobal(L, "package"); // package | 44 | lua_getglobal(L, "package"); // package |
45 | lua_getfield(L, -1, "loaded"); // package loaded | 45 | lua_getfield(L, -1, "loaded"); // package loaded |
46 | lua_getfield(L, -1, "moonp"); // package loaded moonp | 46 | lua_getfield(L, -1, "yue"); // package loaded yue |
47 | lua_pushlstring(L, &name.front(), name.size()); // package loaded moonp name | 47 | lua_pushlstring(L, &name.front(), name.size()); // package loaded yue name |
48 | lua_gettable(L, -2); // loaded[name], package loaded moonp item | 48 | lua_gettable(L, -2); // loaded[name], package loaded yue item |
49 | lua_insert(L, -4); // item package loaded moonp | 49 | lua_insert(L, -4); // item package loaded yue |
50 | lua_pop(L, 3); // item | 50 | lua_pop(L, 3); // item |
51 | } | 51 | } |
52 | 52 | ||
@@ -71,15 +71,15 @@ void pushOptions(lua_State* L, int lineOffset) { | |||
71 | lua_pushinteger(L, lineOffset); | 71 | lua_pushinteger(L, lineOffset); |
72 | lua_rawset(L, -3); | 72 | lua_rawset(L, -3); |
73 | } | 73 | } |
74 | #endif // not (defined MOONP_NO_MACRO && defined MOONP_COMPILER_ONLY) | 74 | #endif // not (defined YUE_NO_MACRO && defined YUE_COMPILER_ONLY) |
75 | 75 | ||
76 | #ifndef MOONP_NO_MACRO | 76 | #ifndef YUE_NO_MACRO |
77 | #define MOONP_ARGS nullptr,openlibs | 77 | #define YUE_ARGS nullptr,openlibs |
78 | #else | 78 | #else |
79 | #define MOONP_ARGS | 79 | #define YUE_ARGS |
80 | #endif // MOONP_NO_MACRO | 80 | #endif // YUE_NO_MACRO |
81 | 81 | ||
82 | #ifndef MOONP_COMPILER_ONLY | 82 | #ifndef YUE_COMPILER_ONLY |
83 | static const char luaminifyCodes[] = | 83 | static const char luaminifyCodes[] = |
84 | #include "LuaMinify.h" | 84 | #include "LuaMinify.h" |
85 | 85 | ||
@@ -92,16 +92,16 @@ static void pushLuaminify(lua_State* L) { | |||
92 | luaL_error(L, err.c_str()); | 92 | luaL_error(L, err.c_str()); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | #endif // MOONP_COMPILER_ONLY | 95 | #endif // YUE_COMPILER_ONLY |
96 | 96 | ||
97 | int main(int narg, const char** args) { | 97 | int main(int narg, const char** args) { |
98 | const char* help = | 98 | const char* help = |
99 | "Usage: moonp [options|files|directories] ...\n\n" | 99 | "Usage: yue [options|files|directories] ...\n\n" |
100 | " -h Print this message\n" | 100 | " -h Print this message\n" |
101 | #ifndef MOONP_COMPILER_ONLY | 101 | #ifndef YUE_COMPILER_ONLY |
102 | " -e str Execute a file or raw codes\n" | 102 | " -e str Execute a file or raw codes\n" |
103 | " -m Generate minified codes\n" | 103 | " -m Generate minified codes\n" |
104 | #endif // MOONP_COMPILER_ONLY | 104 | #endif // YUE_COMPILER_ONLY |
105 | " -t path Specify where to place compiled files\n" | 105 | " -t path Specify where to place compiled files\n" |
106 | " -o file Write output to file\n" | 106 | " -o file Write output to file\n" |
107 | " -s Use spaces in generated codes instead of tabs\n" | 107 | " -s Use spaces in generated codes instead of tabs\n" |
@@ -109,19 +109,19 @@ int main(int narg, const char** args) { | |||
109 | " -b Dump compile time (doesn't write output)\n" | 109 | " -b Dump compile time (doesn't write output)\n" |
110 | " -l Write line numbers from source codes\n" | 110 | " -l Write line numbers from source codes\n" |
111 | " -v Print version\n" | 111 | " -v Print version\n" |
112 | #ifndef MOONP_COMPILER_ONLY | 112 | #ifndef YUE_COMPILER_ONLY |
113 | " -- Read from standard in, print to standard out\n" | 113 | " -- Read from standard in, print to standard out\n" |
114 | " (Must be first and only argument)\n\n" | 114 | " (Must be first and only argument)\n\n" |
115 | " Execute without options to enter REPL, type symbol '$'\n" | 115 | " Execute without options to enter REPL, type symbol '$'\n" |
116 | " in a single line to start/stop multi-line mode\n" | 116 | " in a single line to start/stop multi-line mode\n" |
117 | #endif // MOONP_COMPILER_ONLY | 117 | #endif // YUE_COMPILER_ONLY |
118 | ; | 118 | ; |
119 | #ifndef MOONP_COMPILER_ONLY | 119 | #ifndef YUE_COMPILER_ONLY |
120 | if (narg == 1) { | 120 | if (narg == 1) { |
121 | lua_State* L = luaL_newstate(); | 121 | lua_State* L = luaL_newstate(); |
122 | openlibs(L); | 122 | openlibs(L); |
123 | DEFER(lua_close(L)); | 123 | DEFER(lua_close(L)); |
124 | pushMoonp(L, "insert_loader"sv); | 124 | pushYue(L, "insert_loader"sv); |
125 | if (lua_pcall(L, 0, 0, 0) != 0) { | 125 | if (lua_pcall(L, 0, 0, 0) != 0) { |
126 | std::cout << lua_tostring(L, -1) << '\n'; | 126 | std::cout << lua_tostring(L, -1) << '\n'; |
127 | return 1; | 127 | return 1; |
@@ -131,7 +131,7 @@ int main(int narg, const char** args) { | |||
131 | linenoise::SetCompletionCallback([](const char* editBuffer, std::vector<std::string>& completions) { | 131 | linenoise::SetCompletionCallback([](const char* editBuffer, std::vector<std::string>& completions) { |
132 | std::string buf = editBuffer; | 132 | std::string buf = editBuffer; |
133 | std::string tmp = buf; | 133 | std::string tmp = buf; |
134 | MoonP::Utils::trim(tmp); | 134 | yue::Utils::trim(tmp); |
135 | if (tmp.empty()) return; | 135 | if (tmp.empty()) return; |
136 | std::string pre; | 136 | std::string pre; |
137 | auto pos = buf.find_first_not_of(" \t\n"); | 137 | auto pos = buf.find_first_not_of(" \t\n"); |
@@ -176,33 +176,33 @@ int main(int narg, const char** args) { | |||
176 | break; | 176 | break; |
177 | } | 177 | } |
178 | }); | 178 | }); |
179 | std::cout << "Moonscript+ "sv << MoonP::version << '\n'; | 179 | std::cout << "Yuescript "sv << yue::version << '\n'; |
180 | while (true) { | 180 | while (true) { |
181 | count++; | 181 | count++; |
182 | std::string codes; | 182 | std::string codes; |
183 | bool quit = linenoise::Readline("> ", codes); | 183 | bool quit = linenoise::Readline("> ", codes); |
184 | if (quit) return 0; | 184 | if (quit) return 0; |
185 | linenoise::AddHistory(codes.c_str()); | 185 | linenoise::AddHistory(codes.c_str()); |
186 | MoonP::Utils::trim(codes); | 186 | yue::Utils::trim(codes); |
187 | if (codes == "$"sv) { | 187 | if (codes == "$"sv) { |
188 | codes.clear(); | 188 | codes.clear(); |
189 | for (std::string line; !(quit = linenoise::Readline("", line));) { | 189 | for (std::string line; !(quit = linenoise::Readline("", line));) { |
190 | auto temp = line; | 190 | auto temp = line; |
191 | MoonP::Utils::trim(temp); | 191 | yue::Utils::trim(temp); |
192 | if (temp == "$"sv) { | 192 | if (temp == "$"sv) { |
193 | break; | 193 | break; |
194 | } | 194 | } |
195 | codes += '\n'; | 195 | codes += '\n'; |
196 | codes += line; | 196 | codes += line; |
197 | linenoise::AddHistory(line.c_str()); | 197 | linenoise::AddHistory(line.c_str()); |
198 | MoonP::Utils::trim(codes); | 198 | yue::Utils::trim(codes); |
199 | } | 199 | } |
200 | if (quit) return 0; | 200 | if (quit) return 0; |
201 | } | 201 | } |
202 | codes.insert(0, "global *\n"sv); | 202 | codes.insert(0, "global *\n"sv); |
203 | int top = lua_gettop(L); | 203 | int top = lua_gettop(L); |
204 | DEFER(lua_settop(L, top)); | 204 | DEFER(lua_settop(L, top)); |
205 | pushMoonp(L, "loadstring"sv); | 205 | pushYue(L, "loadstring"sv); |
206 | lua_pushlstring(L, codes.c_str(), codes.size()); | 206 | lua_pushlstring(L, codes.c_str(), codes.size()); |
207 | lua_pushstring(L, (std::string("=(repl ") + std::to_string(count) + ')').c_str()); | 207 | lua_pushstring(L, (std::string("=(repl ") + std::to_string(count) + ')').c_str()); |
208 | pushOptions(L, -1); | 208 | pushOptions(L, -1); |
@@ -226,7 +226,7 @@ int main(int narg, const char** args) { | |||
226 | continue; | 226 | continue; |
227 | } | 227 | } |
228 | lua_pop(L, 1); | 228 | lua_pop(L, 1); |
229 | pushMoonp(L, "pcall"sv); | 229 | pushYue(L, "pcall"sv); |
230 | lua_insert(L, -2); | 230 | lua_insert(L, -2); |
231 | int last = lua_gettop(L) - 2; | 231 | int last = lua_gettop(L) - 2; |
232 | if (lua_pcall(L, 1, LUA_MULTRET, 0) != 0) { | 232 | if (lua_pcall(L, 1, LUA_MULTRET, 0) != 0) { |
@@ -251,8 +251,8 @@ int main(int narg, const char** args) { | |||
251 | return 0; | 251 | return 0; |
252 | } | 252 | } |
253 | bool minify = false; | 253 | bool minify = false; |
254 | #endif // MOONP_COMPILER_ONLY | 254 | #endif // YUE_COMPILER_ONLY |
255 | MoonP::MoonConfig config; | 255 | yue::YueConfig config; |
256 | config.implicitReturnRoot = true; | 256 | config.implicitReturnRoot = true; |
257 | config.lintGlobalVariable = false; | 257 | config.lintGlobalVariable = false; |
258 | config.reserveLineNumber = false; | 258 | config.reserveLineNumber = false; |
@@ -274,12 +274,12 @@ int main(int narg, const char** args) { | |||
274 | while ((ch = std::cin.get()) != EOF) { | 274 | while ((ch = std::cin.get()) != EOF) { |
275 | codes += ch; | 275 | codes += ch; |
276 | } | 276 | } |
277 | MoonP::MoonConfig conf; | 277 | yue::YueConfig conf; |
278 | conf.implicitReturnRoot = true; | 278 | conf.implicitReturnRoot = true; |
279 | conf.lintGlobalVariable = false; | 279 | conf.lintGlobalVariable = false; |
280 | conf.reserveLineNumber = false; | 280 | conf.reserveLineNumber = false; |
281 | conf.useSpaceOverTab = true; | 281 | conf.useSpaceOverTab = true; |
282 | auto result = MoonP::MoonCompiler{MOONP_ARGS}.compile(codes, conf); | 282 | auto result = yue::YueCompiler{YUE_ARGS}.compile(codes, conf); |
283 | if (result.error.empty()) { | 283 | if (result.error.empty()) { |
284 | std::cout << result.codes; | 284 | std::cout << result.codes; |
285 | return 0; | 285 | return 0; |
@@ -288,14 +288,14 @@ int main(int narg, const char** args) { | |||
288 | std::cout << result.error << '\n'; | 288 | std::cout << result.error << '\n'; |
289 | return 1; | 289 | return 1; |
290 | } | 290 | } |
291 | #ifndef MOONP_COMPILER_ONLY | 291 | #ifndef YUE_COMPILER_ONLY |
292 | } else if (arg == "-e"sv) { | 292 | } else if (arg == "-e"sv) { |
293 | ++i; | 293 | ++i; |
294 | if (i < narg) { | 294 | if (i < narg) { |
295 | lua_State* L = luaL_newstate(); | 295 | lua_State* L = luaL_newstate(); |
296 | openlibs(L); | 296 | openlibs(L); |
297 | DEFER(lua_close(L)); | 297 | DEFER(lua_close(L)); |
298 | pushMoonp(L, "insert_loader"sv); | 298 | pushYue(L, "insert_loader"sv); |
299 | if (lua_pcall(L, 0, 0, 0) != 0) { | 299 | if (lua_pcall(L, 0, 0, 0) != 0) { |
300 | std::cout << lua_tostring(L, -1) << '\n'; | 300 | std::cout << lua_tostring(L, -1) << '\n'; |
301 | return 1; | 301 | return 1; |
@@ -308,7 +308,7 @@ int main(int narg, const char** args) { | |||
308 | if (ext == ".lua") { | 308 | if (ext == ".lua") { |
309 | lua_getglobal(L, "load"); | 309 | lua_getglobal(L, "load"); |
310 | } else { | 310 | } else { |
311 | pushMoonp(L, "loadstring"sv); | 311 | pushYue(L, "loadstring"sv); |
312 | } | 312 | } |
313 | std::string s( | 313 | std::string s( |
314 | (std::istreambuf_iterator<char>(input)), | 314 | (std::istreambuf_iterator<char>(input)), |
@@ -316,7 +316,7 @@ int main(int narg, const char** args) { | |||
316 | lua_pushlstring(L, s.c_str(), s.size()); | 316 | lua_pushlstring(L, s.c_str(), s.size()); |
317 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); | 317 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); |
318 | } else { | 318 | } else { |
319 | pushMoonp(L, "loadstring"sv); | 319 | pushYue(L, "loadstring"sv); |
320 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); | 320 | lua_pushlstring(L, evalStr.c_str(), evalStr.size()); |
321 | lua_pushliteral(L, "=(eval str)"); | 321 | lua_pushliteral(L, "=(eval str)"); |
322 | } | 322 | } |
@@ -329,7 +329,7 @@ int main(int narg, const char** args) { | |||
329 | return 1; | 329 | return 1; |
330 | } | 330 | } |
331 | lua_pop(L, 1); | 331 | lua_pop(L, 1); |
332 | pushMoonp(L, "pcall"sv); | 332 | pushYue(L, "pcall"sv); |
333 | lua_insert(L, -2); | 333 | lua_insert(L, -2); |
334 | int argCount = 0; | 334 | int argCount = 0; |
335 | i++; | 335 | i++; |
@@ -354,7 +354,7 @@ int main(int narg, const char** args) { | |||
354 | } | 354 | } |
355 | } else if (arg == "-m"sv) { | 355 | } else if (arg == "-m"sv) { |
356 | minify = true; | 356 | minify = true; |
357 | #endif // MOONP_COMPILER_ONLY | 357 | #endif // YUE_COMPILER_ONLY |
358 | } else if (arg == "-s"sv) { | 358 | } else if (arg == "-s"sv) { |
359 | config.useSpaceOverTab = true; | 359 | config.useSpaceOverTab = true; |
360 | } else if (arg == "-l"sv) { | 360 | } else if (arg == "-l"sv) { |
@@ -375,7 +375,7 @@ int main(int narg, const char** args) { | |||
375 | std::cout << help; | 375 | std::cout << help; |
376 | return 0; | 376 | return 0; |
377 | } else if (arg == "-v"sv) { | 377 | } else if (arg == "-v"sv) { |
378 | std::cout << "Moonscript+ version: "sv << MoonP::version << '\n'; | 378 | std::cout << "Yuescript version: "sv << yue::version << '\n'; |
379 | return 0; | 379 | return 0; |
380 | } else if (arg == "-o"sv) { | 380 | } else if (arg == "-o"sv) { |
381 | ++i; | 381 | ++i; |
@@ -397,7 +397,7 @@ int main(int narg, const char** args) { | |||
397 | if (!item.is_directory()) { | 397 | if (!item.is_directory()) { |
398 | auto ext = item.path().extension().string(); | 398 | auto ext = item.path().extension().string(); |
399 | for (char& ch : ext) ch = std::tolower(ch); | 399 | for (char& ch : ext) ch = std::tolower(ch); |
400 | if (!ext.empty() && ext.substr(1) == MoonP::extension) { | 400 | if (!ext.empty() && ext.substr(1) == yue::extension) { |
401 | files.emplace_back(item.path().string(), item.path().lexically_relative(arg).string()); | 401 | files.emplace_back(item.path().string(), item.path().lexically_relative(arg).string()); |
402 | } | 402 | } |
403 | } | 403 | } |
@@ -425,12 +425,12 @@ int main(int narg, const char** args) { | |||
425 | std::istreambuf_iterator<char>()); | 425 | std::istreambuf_iterator<char>()); |
426 | if (dumpCompileTime) { | 426 | if (dumpCompileTime) { |
427 | auto start = std::chrono::high_resolution_clock::now(); | 427 | auto start = std::chrono::high_resolution_clock::now(); |
428 | auto result = MoonP::MoonCompiler{MOONP_ARGS}.compile(s, config); | 428 | auto result = yue::YueCompiler{YUE_ARGS}.compile(s, config); |
429 | auto end = std::chrono::high_resolution_clock::now(); | 429 | auto end = std::chrono::high_resolution_clock::now(); |
430 | if (!result.codes.empty()) { | 430 | if (!result.codes.empty()) { |
431 | std::chrono::duration<double> diff = end - start; | 431 | std::chrono::duration<double> diff = end - start; |
432 | start = std::chrono::high_resolution_clock::now(); | 432 | start = std::chrono::high_resolution_clock::now(); |
433 | MoonP::MoonParser{}.parse<MoonP::File_t>(s); | 433 | yue::YueParser{}.parse<yue::File_t>(s); |
434 | end = std::chrono::high_resolution_clock::now(); | 434 | end = std::chrono::high_resolution_clock::now(); |
435 | std::chrono::duration<double> parseDiff = end - start; | 435 | std::chrono::duration<double> parseDiff = end - start; |
436 | std::ostringstream buf; | 436 | std::ostringstream buf; |
@@ -445,7 +445,7 @@ int main(int narg, const char** args) { | |||
445 | return std::tuple{1, file.first, buf.str()}; | 445 | return std::tuple{1, file.first, buf.str()}; |
446 | } | 446 | } |
447 | } | 447 | } |
448 | auto result = MoonP::MoonCompiler{MOONP_ARGS}.compile(s, config); | 448 | auto result = yue::YueCompiler{YUE_ARGS}.compile(s, config); |
449 | if (result.error.empty()) { | 449 | if (result.error.empty()) { |
450 | if (!writeToFile) { | 450 | if (!writeToFile) { |
451 | return std::tuple{0, file.first, result.codes + '\n'}; | 451 | return std::tuple{0, file.first, result.codes + '\n'}; |
@@ -475,7 +475,7 @@ int main(int narg, const char** args) { | |||
475 | if (output) { | 475 | if (output) { |
476 | const auto& codes = result.codes; | 476 | const auto& codes = result.codes; |
477 | if (config.reserveLineNumber) { | 477 | if (config.reserveLineNumber) { |
478 | auto head = std::string("-- [moonp]: "sv) + file.first + '\n'; | 478 | auto head = std::string("-- [yue]: "sv) + file.first + '\n'; |
479 | output.write(head.c_str(), head.size()); | 479 | output.write(head.c_str(), head.size()); |
480 | } | 480 | } |
481 | output.write(codes.c_str(), codes.size()); | 481 | output.write(codes.c_str(), codes.size()); |
@@ -497,7 +497,7 @@ int main(int narg, const char** args) { | |||
497 | results.push_back(std::move(task)); | 497 | results.push_back(std::move(task)); |
498 | } | 498 | } |
499 | int ret = 0; | 499 | int ret = 0; |
500 | #ifndef MOONP_COMPILER_ONLY | 500 | #ifndef YUE_COMPILER_ONLY |
501 | lua_State* L = nullptr; | 501 | lua_State* L = nullptr; |
502 | DEFER({ | 502 | DEFER({ |
503 | if (L) lua_close(L); | 503 | if (L) lua_close(L); |
@@ -507,7 +507,7 @@ int main(int narg, const char** args) { | |||
507 | luaL_openlibs(L); | 507 | luaL_openlibs(L); |
508 | pushLuaminify(L); | 508 | pushLuaminify(L); |
509 | } | 509 | } |
510 | #endif // MOONP_COMPILER_ONLY | 510 | #endif // YUE_COMPILER_ONLY |
511 | std::list<std::string> errs; | 511 | std::list<std::string> errs; |
512 | for (auto& result : results) { | 512 | for (auto& result : results) { |
513 | int val = 0; | 513 | int val = 0; |
@@ -518,7 +518,7 @@ int main(int narg, const char** args) { | |||
518 | ret = val; | 518 | ret = val; |
519 | errs.push_back(msg); | 519 | errs.push_back(msg); |
520 | } else { | 520 | } else { |
521 | #ifndef MOONP_COMPILER_ONLY | 521 | #ifndef YUE_COMPILER_ONLY |
522 | if (minify) { | 522 | if (minify) { |
523 | std::ifstream input(file, std::ios::in); | 523 | std::ifstream input(file, std::ios::in); |
524 | if (input) { | 524 | if (input) { |
@@ -560,7 +560,7 @@ int main(int narg, const char** args) { | |||
560 | } | 560 | } |
561 | #else | 561 | #else |
562 | std::cout << msg; | 562 | std::cout << msg; |
563 | #endif // MOONP_COMPILER_ONLY | 563 | #endif // YUE_COMPILER_ONLY |
564 | } | 564 | } |
565 | } | 565 | } |
566 | for (const auto& err : errs) { | 566 | for (const auto& err : errs) { |
diff --git a/src/MoonP/ast.cpp b/src/yuescript/ast.cpp index 4929021..3deefb1 100644 --- a/src/MoonP/ast.cpp +++ b/src/yuescript/ast.cpp | |||
@@ -11,7 +11,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |||
11 | 11 | ||
12 | #include <cassert> | 12 | #include <cassert> |
13 | 13 | ||
14 | #include "MoonP/ast.hpp" | 14 | #include "yuescript/ast.hpp" |
15 | 15 | ||
16 | 16 | ||
17 | namespace parserlib { | 17 | namespace parserlib { |
diff --git a/src/MoonP/ast.hpp b/src/yuescript/ast.hpp index 104202d..c88fcf9 100644 --- a/src/MoonP/ast.hpp +++ b/src/yuescript/ast.hpp | |||
@@ -17,7 +17,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |||
17 | #include <stdexcept> | 17 | #include <stdexcept> |
18 | #include <type_traits> | 18 | #include <type_traits> |
19 | 19 | ||
20 | #include "MoonP/parser.hpp" | 20 | #include "yuescript/parser.hpp" |
21 | 21 | ||
22 | 22 | ||
23 | namespace parserlib { | 23 | namespace parserlib { |
diff --git a/src/MoonP/parser.cpp b/src/yuescript/parser.cpp index 8dc2ff9..a44ae34 100644 --- a/src/MoonP/parser.cpp +++ b/src/yuescript/parser.cpp | |||
@@ -16,7 +16,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |||
16 | #include <unordered_map> | 16 | #include <unordered_map> |
17 | #include <unordered_set> | 17 | #include <unordered_set> |
18 | 18 | ||
19 | #include "MoonP/parser.hpp" | 19 | #include "yuescript/parser.hpp" |
20 | 20 | ||
21 | 21 | ||
22 | namespace parserlib { | 22 | namespace parserlib { |
diff --git a/src/MoonP/parser.hpp b/src/yuescript/parser.hpp index f70475f..f70475f 100644 --- a/src/MoonP/parser.hpp +++ b/src/yuescript/parser.hpp | |||
diff --git a/src/MoonP/stacktraceplus.h b/src/yuescript/stacktraceplus.h index e884a2c..b165754 100644 --- a/src/MoonP/stacktraceplus.h +++ b/src/yuescript/stacktraceplus.h | |||
@@ -36,7 +36,7 @@ local string_gmatch = string.gmatch | |||
36 | local string_sub = string.sub | 36 | local string_sub = string.sub |
37 | local table_concat = table.concat | 37 | local table_concat = table.concat |
38 | 38 | ||
39 | local moonp = require("moonp") | 39 | local yue = require("yue") |
40 | 40 | ||
41 | local _M = { | 41 | local _M = { |
42 | max_tb_output_len = 70, -- controls the maximum length of the 'stringified' table before cutting with ' (more...)' | 42 | max_tb_output_len = 70, -- controls the maximum length of the 'stringified' table before cutting with ' (more...)' |
@@ -161,8 +161,8 @@ local function GuessFunctionName(info) | |||
161 | if type(info.source) == "string" and info.source:sub(1,1) == "@" then | 161 | if type(info.source) == "string" and info.source:sub(1,1) == "@" then |
162 | local fname = info.source:sub(2) | 162 | local fname = info.source:sub(2) |
163 | local text | 163 | local text |
164 | if moonp.file_exist(fname) then | 164 | if yue.file_exist(fname) then |
165 | text = moonp.read_file(fname) | 165 | text = yue.read_file(fname) |
166 | end | 166 | end |
167 | if not text then | 167 | if not text then |
168 | -- print("file not found: "..tostring(err)) -- whoops! | 168 | -- print("file not found: "..tostring(err)) -- whoops! |
@@ -317,27 +317,27 @@ function Dumper:DumpLocals (level) | |||
317 | end | 317 | end |
318 | end | 318 | end |
319 | 319 | ||
320 | local function getMoonLineNumber(fname, line) | 320 | local function getYueLineNumber(fname, line) |
321 | local moonCompiled = require("moonp").moon_compiled | 321 | local yueCompiled = require("yue").yue_compiled |
322 | local source = moonCompiled["@"..fname] | 322 | local source = yueCompiled["@"..fname] |
323 | if not source then | 323 | if not source then |
324 | source = moonCompiled["@="..fname] | 324 | source = yueCompiled["@="..fname] |
325 | end | 325 | end |
326 | if not source then | 326 | if not source then |
327 | local name_path = fname:gsub("%.", moonp.dirsep) | 327 | local name_path = fname:gsub("%.", yue.dirsep) |
328 | local file_exist, file_path | 328 | local file_exist, file_path |
329 | for path in package.path:gmatch("[^;]+") do | 329 | for path in package.path:gmatch("[^;]+") do |
330 | file_path = path:gsub("?", name_path) | 330 | file_path = path:gsub("?", name_path) |
331 | file_exist = moonp.file_exist(file_path) | 331 | file_exist = yue.file_exist(file_path) |
332 | if file_exist then | 332 | if file_exist then |
333 | break | 333 | break |
334 | end | 334 | end |
335 | end | 335 | end |
336 | if file_exist then | 336 | if file_exist then |
337 | local codes = moonp.read_file(file_path) | 337 | local codes = yue.read_file(file_path) |
338 | local moonFile = codes:match("^%s*--%s*%[moonp%]:%s*([^\n]*)") | 338 | local yueFile = codes:match("^%s*--%s*%[yue%]:%s*([^\n]*)") |
339 | if moonFile then | 339 | if yueFile then |
340 | fname = moonFile:gsub("^%s*(.-)%s*$", "%1") | 340 | fname = yueFile:gsub("^%s*(.-)%s*$", "%1") |
341 | source = codes | 341 | source = codes |
342 | end | 342 | end |
343 | end | 343 | end |
@@ -409,12 +409,12 @@ function _M.stacktrace(thread, message, level) | |||
409 | local fn = fname:match("%[string \"(.-)\"%]") | 409 | local fn = fname:match("%[string \"(.-)\"%]") |
410 | if fn then fname = fn end | 410 | if fn then fname = fn end |
411 | fname = fname:gsub("^%s*(.-)%s*$", "%1") | 411 | fname = fname:gsub("^%s*(.-)%s*$", "%1") |
412 | fname, line = getMoonLineNumber(fname, line) | 412 | fname, line = getYueLineNumber(fname, line) |
413 | if _M.simplified then | 413 | if _M.simplified then |
414 | message = table.concat({ | 414 | message = table.concat({ |
415 | "", fname, ":", | 415 | "", fname, ":", |
416 | line, ": ", msg}) | 416 | line, ": ", msg}) |
417 | message = message:gsub("^%(moonplus%):%s*%d+:%s*", "") | 417 | message = message:gsub("^%(yuescript%):%s*%d+:%s*", "") |
418 | message = message:gsub("%s(%d+):", "%1:") | 418 | message = message:gsub("%s(%d+):", "%1:") |
419 | else | 419 | else |
420 | message = table.concat({ | 420 | message = table.concat({ |
@@ -441,7 +441,7 @@ Stack Traceback | |||
441 | elseif info.what == "main" or info.what == "Lua" then | 441 | elseif info.what == "main" or info.what == "Lua" then |
442 | info.source = info.source | 442 | info.source = info.source |
443 | end | 443 | end |
444 | info.source, info.currentline = getMoonLineNumber(info.source, info.currentline) | 444 | info.source, info.currentline = getYueLineNumber(info.source, info.currentline) |
445 | if info.what == "main" then | 445 | if info.what == "main" then |
446 | if _M.simplified then | 446 | if _M.simplified then |
447 | dumper:add_f("(%d) '%s':%d\r\n", level_to_show, info.source, info.currentline) | 447 | dumper:add_f("(%d) '%s':%d\r\n", level_to_show, info.source, info.currentline) |
diff --git a/src/MoonP/moon_ast.h b/src/yuescript/yue_ast.h index 6b738d4..090765c 100644 --- a/src/MoonP/moon_ast.h +++ b/src/yuescript/yue_ast.h | |||
@@ -8,7 +8,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
8 | 8 | ||
9 | #pragma once | 9 | #pragma once |
10 | 10 | ||
11 | #include "MoonP/ast.hpp" | 11 | #include "yuescript/ast.hpp" |
12 | 12 | ||
13 | namespace parserlib { | 13 | namespace parserlib { |
14 | 14 | ||
diff --git a/src/MoonP/moon_compiler.cpp b/src/yuescript/yue_compiler.cpp index 24e4a97..22311f4 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
@@ -12,12 +12,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
12 | #include <stack> | 12 | #include <stack> |
13 | #include <vector> | 13 | #include <vector> |
14 | #include <memory> | 14 | #include <memory> |
15 | #include <cassert> | ||
16 | 15 | ||
17 | #include "MoonP/moon_parser.h" | 16 | #include "yuescript/yue_parser.h" |
18 | #include "MoonP/moon_compiler.h" | 17 | #include "yuescript/yue_compiler.h" |
19 | 18 | ||
20 | #ifndef MOONP_NO_MACRO | 19 | #ifndef YUE_NO_MACRO |
21 | 20 | ||
22 | extern "C" { | 21 | extern "C" { |
23 | #include "lua.h" | 22 | #include "lua.h" |
@@ -26,7 +25,7 @@ extern "C" { | |||
26 | } // extern "C" | 25 | } // extern "C" |
27 | 26 | ||
28 | // name of table stored in lua registry | 27 | // name of table stored in lua registry |
29 | #define MOONP_MODULE "__moon_modules__" | 28 | #define YUE_MODULE "__yue_modules__" |
30 | 29 | ||
31 | #if LUA_VERSION_NUM > 501 | 30 | #if LUA_VERSION_NUM > 501 |
32 | #ifndef LUA_COMPAT_5_1 | 31 | #ifndef LUA_COMPAT_5_1 |
@@ -34,9 +33,9 @@ extern "C" { | |||
34 | #endif // LUA_COMPAT_5_1 | 33 | #endif // LUA_COMPAT_5_1 |
35 | #endif // LUA_VERSION_NUM | 34 | #endif // LUA_VERSION_NUM |
36 | 35 | ||
37 | #endif // MOONP_NO_MACRO | 36 | #endif // YUE_NO_MACRO |
38 | 37 | ||
39 | namespace MoonP { | 38 | namespace yue { |
40 | using namespace std::string_view_literals; | 39 | using namespace std::string_view_literals; |
41 | using namespace parserlib; | 40 | using namespace parserlib; |
42 | 41 | ||
@@ -46,6 +45,12 @@ using namespace parserlib; | |||
46 | 45 | ||
47 | #define _DEFER(code,line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto){code;}) | 46 | #define _DEFER(code,line) std::shared_ptr<void> _defer_##line(nullptr, [&](auto){code;}) |
48 | #define DEFER(code) _DEFER(code,__LINE__) | 47 | #define DEFER(code) _DEFER(code,__LINE__) |
48 | #define YUEE(msg,node) throw std::logic_error( \ | ||
49 | _info.errorMessage( \ | ||
50 | std::string("[File] ") + __FILE__ \ | ||
51 | + ", [Func] " + __FUNCTION__ \ | ||
52 | + ", [Line] " + std::to_string(__LINE__) \ | ||
53 | + ", [Error] " + msg, node)) | ||
49 | 54 | ||
50 | typedef std::list<std::string> str_list; | 55 | typedef std::list<std::string> str_list; |
51 | 56 | ||
@@ -53,13 +58,13 @@ inline std::string s(std::string_view sv) { | |||
53 | return std::string(sv); | 58 | return std::string(sv); |
54 | } | 59 | } |
55 | 60 | ||
56 | const std::string_view version = "0.6.3"sv; | 61 | const std::string_view version = "0.6.5"sv; |
57 | const std::string_view extension = "mp"sv; | 62 | const std::string_view extension = "yue"sv; |
58 | 63 | ||
59 | class MoonCompilerImpl { | 64 | class YueCompilerImpl { |
60 | public: | 65 | public: |
61 | #ifndef MOONP_NO_MACRO | 66 | #ifndef YUE_NO_MACRO |
62 | MoonCompilerImpl(lua_State* sharedState, | 67 | YueCompilerImpl(lua_State* sharedState, |
63 | const std::function<void(void*)>& luaOpen, | 68 | const std::function<void(void*)>& luaOpen, |
64 | bool sameModule, | 69 | bool sameModule, |
65 | std::string_view moduleName = {}): | 70 | std::string_view moduleName = {}): |
@@ -72,8 +77,8 @@ public: | |||
72 | _sameModule = true; | 77 | _sameModule = true; |
73 | int top = lua_gettop(L); | 78 | int top = lua_gettop(L); |
74 | DEFER(lua_settop(L, top)); | 79 | DEFER(lua_settop(L, top)); |
75 | lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE | 80 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE |
76 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[MOONP_MODULE], tb | 81 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb |
77 | BREAK_IF(lua_istable(L, -1) == 0); | 82 | BREAK_IF(lua_istable(L, -1) == 0); |
78 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb | 83 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb |
79 | BREAK_IF(idx == 0); | 84 | BREAK_IF(idx == 0); |
@@ -81,19 +86,19 @@ public: | |||
81 | BLOCK_END | 86 | BLOCK_END |
82 | } | 87 | } |
83 | 88 | ||
84 | ~MoonCompilerImpl() { | 89 | ~YueCompilerImpl() { |
85 | if (L && _stateOwner) { | 90 | if (L && _stateOwner) { |
86 | lua_close(L); | 91 | lua_close(L); |
87 | L = nullptr; | 92 | L = nullptr; |
88 | } | 93 | } |
89 | } | 94 | } |
90 | #endif // MOONP_NO_MACRO | 95 | #endif // YUE_NO_MACRO |
91 | 96 | ||
92 | CompileInfo compile(std::string_view codes, const MoonConfig& config) { | 97 | CompileInfo compile(std::string_view codes, const YueConfig& config) { |
93 | _config = config; | 98 | _config = config; |
94 | #ifndef MOONP_NO_MACRO | 99 | #ifndef YUE_NO_MACRO |
95 | if (L) passOptions(); | 100 | if (L) passOptions(); |
96 | #endif // MOONP_NO_MACRO | 101 | #endif // YUE_NO_MACRO |
97 | _info = _parser.parse<File_t>(codes); | 102 | _info = _parser.parse<File_t>(codes); |
98 | std::unique_ptr<GlobalVars> globals; | 103 | std::unique_ptr<GlobalVars> globals; |
99 | std::unique_ptr<Options> options; | 104 | std::unique_ptr<Options> options; |
@@ -119,14 +124,14 @@ public: | |||
119 | globals->push_back({var.first, line, col}); | 124 | globals->push_back({var.first, line, col}); |
120 | } | 125 | } |
121 | } | 126 | } |
122 | #ifndef MOONP_NO_MACRO | 127 | #ifndef YUE_NO_MACRO |
123 | if (L) { | 128 | if (L) { |
124 | int top = lua_gettop(L); | 129 | int top = lua_gettop(L); |
125 | DEFER(lua_settop(L, top)); | 130 | DEFER(lua_settop(L, top)); |
126 | if (!options) { | 131 | if (!options) { |
127 | options = std::make_unique<Options>(); | 132 | options = std::make_unique<Options>(); |
128 | } | 133 | } |
129 | pushMoonp("options"sv); | 134 | pushYue("options"sv); |
130 | lua_pushnil(L); // options startKey | 135 | lua_pushnil(L); // options startKey |
131 | while (lua_next(L, -2) != 0) { // options key value | 136 | while (lua_next(L, -2) != 0) { // options key value |
132 | size_t len = 0; | 137 | size_t len = 0; |
@@ -138,7 +143,7 @@ public: | |||
138 | lua_pop(L, 1); // options key | 143 | lua_pop(L, 1); // options key |
139 | } | 144 | } |
140 | } | 145 | } |
141 | #endif // MOONP_NO_MACRO | 146 | #endif // YUE_NO_MACRO |
142 | return {std::move(out.back()), Empty, std::move(globals), std::move(options)}; | 147 | return {std::move(out.back()), Empty, std::move(globals), std::move(options)}; |
143 | } catch (const std::logic_error& error) { | 148 | } catch (const std::logic_error& error) { |
144 | return {Empty, error.what(), std::move(globals), std::move(options)}; | 149 | return {Empty, error.what(), std::move(globals), std::move(options)}; |
@@ -162,31 +167,31 @@ public: | |||
162 | _withVars = {}; | 167 | _withVars = {}; |
163 | _continueVars = {}; | 168 | _continueVars = {}; |
164 | _enableReturn = {}; | 169 | _enableReturn = {}; |
165 | #ifndef MOONP_NO_MACRO | 170 | #ifndef YUE_NO_MACRO |
166 | if (_useModule) { | 171 | if (_useModule) { |
167 | _useModule = false; | 172 | _useModule = false; |
168 | if (!_sameModule) { | 173 | if (!_sameModule) { |
169 | int top = lua_gettop(L); | 174 | int top = lua_gettop(L); |
170 | DEFER(lua_settop(L, top)); | 175 | DEFER(lua_settop(L, top)); |
171 | lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE | 176 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE |
172 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[MOONP_MODULE], tb | 177 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb |
173 | int idx = static_cast<int>(lua_objlen(L, -1)); | 178 | int idx = static_cast<int>(lua_objlen(L, -1)); |
174 | lua_pushnil(L); // tb nil | 179 | lua_pushnil(L); // tb nil |
175 | lua_rawseti(L, -2, idx); // tb[idx] = nil, tb | 180 | lua_rawseti(L, -2, idx); // tb[idx] = nil, tb |
176 | } | 181 | } |
177 | } | 182 | } |
178 | #endif // MOONP_NO_MACRO | 183 | #endif // YUE_NO_MACRO |
179 | } | 184 | } |
180 | private: | 185 | private: |
181 | #ifndef MOONP_NO_MACRO | 186 | #ifndef YUE_NO_MACRO |
182 | bool _stateOwner = false; | 187 | bool _stateOwner = false; |
183 | bool _useModule = false; | 188 | bool _useModule = false; |
184 | bool _sameModule = false; | 189 | bool _sameModule = false; |
185 | lua_State* L = nullptr; | 190 | lua_State* L = nullptr; |
186 | std::function<void(void*)> _luaOpen; | 191 | std::function<void(void*)> _luaOpen; |
187 | #endif // MOONP_NO_MACRO | 192 | #endif // YUE_NO_MACRO |
188 | MoonConfig _config; | 193 | YueConfig _config; |
189 | MoonParser _parser; | 194 | YueParser _parser; |
190 | ParseInfo _info; | 195 | ParseInfo _info; |
191 | int _indentOffset = 0; | 196 | int _indentOffset = 0; |
192 | std::stack<bool> _varArgs; | 197 | std::stack<bool> _varArgs; |
@@ -523,7 +528,7 @@ private: | |||
523 | case id<Statement_t>(): { | 528 | case id<Statement_t>(): { |
524 | return static_cast<Statement_t*>(body); | 529 | return static_cast<Statement_t*>(body); |
525 | } | 530 | } |
526 | default: assert(false); break; | 531 | default: YUEE("AST node mismatch", body); break; |
527 | } | 532 | } |
528 | return nullptr; | 533 | return nullptr; |
529 | } | 534 | } |
@@ -875,7 +880,7 @@ private: | |||
875 | statement->appendix.set(nullptr); | 880 | statement->appendix.set(nullptr); |
876 | break; | 881 | break; |
877 | } | 882 | } |
878 | default: assert(false); break; | 883 | default: YUEE("AST node mismatch", appendix->item.get()); break; |
879 | } | 884 | } |
880 | } | 885 | } |
881 | auto content = statement->content.get(); | 886 | auto content = statement->content.get(); |
@@ -947,7 +952,7 @@ private: | |||
947 | } | 952 | } |
948 | break; | 953 | break; |
949 | } | 954 | } |
950 | default: assert(false); break; | 955 | default: YUEE("AST node mismatch", content); break; |
951 | } | 956 | } |
952 | if (statement->needSep && !out.back().empty()) { | 957 | if (statement->needSep && !out.back().empty()) { |
953 | auto index = std::string::npos; | 958 | auto index = std::string::npos; |
@@ -1287,7 +1292,7 @@ private: | |||
1287 | case id<Switch_t>(): transformSwitch(static_cast<Switch_t*>(value), out, ExpUsage::Closure); break; | 1292 | case id<Switch_t>(): transformSwitch(static_cast<Switch_t*>(value), out, ExpUsage::Closure); break; |
1288 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(value), out); break; | 1293 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(value), out); break; |
1289 | case id<Exp_t>(): transformExp(static_cast<Exp_t*>(value), out, ExpUsage::Closure); break; | 1294 | case id<Exp_t>(): transformExp(static_cast<Exp_t*>(value), out, ExpUsage::Closure); break; |
1290 | default: assert(false); break; | 1295 | default: YUEE("AST node mismatch", value); break; |
1291 | } | 1296 | } |
1292 | } | 1297 | } |
1293 | 1298 | ||
@@ -1411,7 +1416,7 @@ private: | |||
1411 | } | 1416 | } |
1412 | break; | 1417 | break; |
1413 | } | 1418 | } |
1414 | default: assert(false); break; | 1419 | default: YUEE("AST node mismatch", pair); break; |
1415 | } | 1420 | } |
1416 | } | 1421 | } |
1417 | return pairs; | 1422 | return pairs; |
@@ -1574,7 +1579,7 @@ private: | |||
1574 | } | 1579 | } |
1575 | break; | 1580 | break; |
1576 | } | 1581 | } |
1577 | default: assert(false); break; | 1582 | default: YUEE("AST node mismatch", action); break; |
1578 | } | 1583 | } |
1579 | } | 1584 | } |
1580 | 1585 | ||
@@ -1632,7 +1637,7 @@ private: | |||
1632 | ifCondPairs.back().second = node; | 1637 | ifCondPairs.back().second = node; |
1633 | ifCondPairs.emplace_back(); | 1638 | ifCondPairs.emplace_back(); |
1634 | break; | 1639 | break; |
1635 | default: assert(false); break; | 1640 | default: YUEE("AST node mismatch", node); break; |
1636 | } | 1641 | } |
1637 | } | 1642 | } |
1638 | auto assign = ifCondPairs.front().first->assign.get(); | 1643 | auto assign = ifCondPairs.front().first->assign.get(); |
@@ -1853,7 +1858,7 @@ private: | |||
1853 | transformExp(arg, out, ExpUsage::Closure); | 1858 | transformExp(arg, out, ExpUsage::Closure); |
1854 | return; | 1859 | return; |
1855 | } | 1860 | } |
1856 | default: assert(false); return; | 1861 | default: YUEE("invalid expression usage", x); return; |
1857 | } | 1862 | } |
1858 | } | 1863 | } |
1859 | } | 1864 | } |
@@ -1863,7 +1868,9 @@ private: | |||
1863 | transform_backcall_exp(exp->backcalls.objects(), out, usage, assignList); | 1868 | transform_backcall_exp(exp->backcalls.objects(), out, usage, assignList); |
1864 | return; | 1869 | return; |
1865 | } | 1870 | } |
1866 | assert(usage == ExpUsage::Closure); | 1871 | if (usage != ExpUsage::Closure) { |
1872 | YUEE("invalid expression usage", exp); | ||
1873 | } | ||
1867 | str_list temp; | 1874 | str_list temp; |
1868 | transform_backcall_exp(exp->backcalls.objects(), temp, ExpUsage::Closure); | 1875 | transform_backcall_exp(exp->backcalls.objects(), temp, ExpUsage::Closure); |
1869 | for (auto _opValue : exp->opValues.objects()) { | 1876 | for (auto _opValue : exp->opValues.objects()) { |
@@ -1881,7 +1888,7 @@ private: | |||
1881 | case id<simple_table_t>(): transform_simple_table(static_cast<simple_table_t*>(item), out); break; | 1888 | case id<simple_table_t>(): transform_simple_table(static_cast<simple_table_t*>(item), out); break; |
1882 | case id<ChainValue_t>(): transformChainValue(static_cast<ChainValue_t*>(item), out, ExpUsage::Closure); break; | 1889 | case id<ChainValue_t>(): transformChainValue(static_cast<ChainValue_t*>(item), out, ExpUsage::Closure); break; |
1883 | case id<String_t>(): transformString(static_cast<String_t*>(item), out); break; | 1890 | case id<String_t>(): transformString(static_cast<String_t*>(item), out); break; |
1884 | default: assert(false); break; | 1891 | default: YUEE("AST node mismatch", value); break; |
1885 | } | 1892 | } |
1886 | } | 1893 | } |
1887 | 1894 | ||
@@ -1916,7 +1923,7 @@ private: | |||
1916 | out.push_back(s("..."sv)); | 1923 | out.push_back(s("..."sv)); |
1917 | break; | 1924 | break; |
1918 | case id<Parens_t>(): transformParens(static_cast<Parens_t*>(item), out); break; | 1925 | case id<Parens_t>(): transformParens(static_cast<Parens_t*>(item), out); break; |
1919 | default: assert(false); break; | 1926 | default: YUEE("AST node mismatch", item); break; |
1920 | } | 1927 | } |
1921 | } | 1928 | } |
1922 | 1929 | ||
@@ -1945,7 +1952,7 @@ private: | |||
1945 | case id<Comprehension_t>(): transformComprehension(static_cast<Comprehension_t*>(value), out, ExpUsage::Closure); break; | 1952 | case id<Comprehension_t>(): transformComprehension(static_cast<Comprehension_t*>(value), out, ExpUsage::Closure); break; |
1946 | case id<FunLit_t>(): transformFunLit(static_cast<FunLit_t*>(value), out); break; | 1953 | case id<FunLit_t>(): transformFunLit(static_cast<FunLit_t*>(value), out); break; |
1947 | case id<Num_t>(): transformNum(static_cast<Num_t*>(value), out); break; | 1954 | case id<Num_t>(): transformNum(static_cast<Num_t*>(value), out); break; |
1948 | default: assert(false); break; | 1955 | default: YUEE("AST node mismatch", value); break; |
1949 | } | 1956 | } |
1950 | } | 1957 | } |
1951 | 1958 | ||
@@ -2304,10 +2311,10 @@ private: | |||
2304 | } | 2311 | } |
2305 | } | 2312 | } |
2306 | 2313 | ||
2307 | #ifndef MOONP_NO_MACRO | 2314 | #ifndef YUE_NO_MACRO |
2308 | void passOptions() { | 2315 | void passOptions() { |
2309 | if (!_config.options.empty()) { | 2316 | if (!_config.options.empty()) { |
2310 | pushMoonp("options"sv); // options | 2317 | pushYue("options"sv); // options |
2311 | for (const auto& option : _config.options) { | 2318 | for (const auto& option : _config.options) { |
2312 | lua_pushlstring(L, option.second.c_str(), option.second.size()); | 2319 | lua_pushlstring(L, option.second.c_str(), option.second.size()); |
2313 | lua_setfield(L, -2, option.first.c_str()); | 2320 | lua_setfield(L, -2, option.first.c_str()); |
@@ -2318,8 +2325,8 @@ private: | |||
2318 | 2325 | ||
2319 | void pushCurrentModule() { | 2326 | void pushCurrentModule() { |
2320 | if (_useModule) { | 2327 | if (_useModule) { |
2321 | lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE | 2328 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE |
2322 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[MOONP_MODULE], tb | 2329 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb |
2323 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb | 2330 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb |
2324 | lua_rawgeti(L, -1, idx); // tb[idx], tb cur | 2331 | lua_rawgeti(L, -1, idx); // tb[idx], tb cur |
2325 | lua_remove(L, -2); // cur | 2332 | lua_remove(L, -2); // cur |
@@ -2334,14 +2341,14 @@ private: | |||
2334 | passOptions(); | 2341 | passOptions(); |
2335 | _stateOwner = true; | 2342 | _stateOwner = true; |
2336 | } | 2343 | } |
2337 | lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE | 2344 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE |
2338 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[MOONP_MODULE], tb | 2345 | lua_rawget(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE], tb |
2339 | if (lua_isnil(L, -1) != 0) { // tb == nil | 2346 | if (lua_isnil(L, -1) != 0) { // tb == nil |
2340 | lua_pop(L, 1); | 2347 | lua_pop(L, 1); |
2341 | lua_newtable(L); // tb | 2348 | lua_newtable(L); // tb |
2342 | lua_pushliteral(L, MOONP_MODULE); // tb MOONP_MODULE | 2349 | lua_pushliteral(L, YUE_MODULE); // tb YUE_MODULE |
2343 | lua_pushvalue(L, -2); // tb MOONP_MODULE tb | 2350 | lua_pushvalue(L, -2); // tb YUE_MODULE tb |
2344 | lua_rawset(L, LUA_REGISTRYINDEX); // reg[MOONP_MODULE] = tb, tb | 2351 | lua_rawset(L, LUA_REGISTRYINDEX); // reg[YUE_MODULE] = tb, tb |
2345 | } // tb | 2352 | } // tb |
2346 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb | 2353 | int idx = static_cast<int>(lua_objlen(L, -1)); // idx = #tb, tb |
2347 | lua_newtable(L); // tb cur | 2354 | lua_newtable(L); // tb cur |
@@ -2350,20 +2357,20 @@ private: | |||
2350 | lua_remove(L, -2); // cur | 2357 | lua_remove(L, -2); // cur |
2351 | } | 2358 | } |
2352 | 2359 | ||
2353 | void pushMoonp(std::string_view name) { | 2360 | void pushYue(std::string_view name) { |
2354 | lua_getglobal(L, "package"); // package | 2361 | lua_getglobal(L, "package"); // package |
2355 | lua_getfield(L, -1, "loaded"); // package loaded | 2362 | lua_getfield(L, -1, "loaded"); // package loaded |
2356 | lua_getfield(L, -1, "moonp"); // package loaded moonp | 2363 | lua_getfield(L, -1, "yue"); // package loaded yue |
2357 | lua_pushlstring(L, &name.front(), name.size()); // package loaded moonp name | 2364 | lua_pushlstring(L, &name.front(), name.size()); // package loaded yue name |
2358 | lua_gettable(L, -2); // loaded[name], package loaded moonp item | 2365 | lua_gettable(L, -2); // loaded[name], package loaded yue item |
2359 | lua_insert(L, -4); // item package loaded moonp | 2366 | lua_insert(L, -4); // item package loaded yue |
2360 | lua_pop(L, 3); // item | 2367 | lua_pop(L, 3); // item |
2361 | } | 2368 | } |
2362 | 2369 | ||
2363 | bool isModuleLoaded(std::string_view name) { | 2370 | bool isModuleLoaded(std::string_view name) { |
2364 | int top = lua_gettop(L); | 2371 | int top = lua_gettop(L); |
2365 | DEFER(lua_settop(L, top)); | 2372 | DEFER(lua_settop(L, top)); |
2366 | lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE | 2373 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE |
2367 | lua_rawget(L, LUA_REGISTRYINDEX); // modules | 2374 | lua_rawget(L, LUA_REGISTRYINDEX); // modules |
2368 | lua_pushlstring(L, &name.front(), name.size()); | 2375 | lua_pushlstring(L, &name.front(), name.size()); |
2369 | lua_rawget(L, -2); // modules module | 2376 | lua_rawget(L, -2); // modules module |
@@ -2374,7 +2381,7 @@ private: | |||
2374 | } | 2381 | } |
2375 | 2382 | ||
2376 | void pushModuleTable(std::string_view name) { | 2383 | void pushModuleTable(std::string_view name) { |
2377 | lua_pushliteral(L, MOONP_MODULE); // MOONP_MODULE | 2384 | lua_pushliteral(L, YUE_MODULE); // YUE_MODULE |
2378 | lua_rawget(L, LUA_REGISTRYINDEX); // modules | 2385 | lua_rawget(L, LUA_REGISTRYINDEX); // modules |
2379 | lua_pushlstring(L, &name.front(), name.size()); | 2386 | lua_pushlstring(L, &name.front(), name.size()); |
2380 | lua_rawget(L, -2); // modules module | 2387 | lua_rawget(L, -2); // modules module |
@@ -2442,7 +2449,7 @@ private: | |||
2442 | pushCurrentModule(); // cur | 2449 | pushCurrentModule(); // cur |
2443 | int top = lua_gettop(L) - 1; | 2450 | int top = lua_gettop(L) - 1; |
2444 | DEFER(lua_settop(L, top)); | 2451 | DEFER(lua_settop(L, top)); |
2445 | pushMoonp("loadstring"sv); // cur loadstring | 2452 | pushYue("loadstring"sv); // cur loadstring |
2446 | lua_pushlstring(L, macroCodes.c_str(), macroCodes.size()); // cur loadstring codes | 2453 | lua_pushlstring(L, macroCodes.c_str(), macroCodes.size()); // cur loadstring codes |
2447 | lua_pushlstring(L, chunkName.c_str(), chunkName.size()); // cur loadstring codes chunk | 2454 | lua_pushlstring(L, chunkName.c_str(), chunkName.size()); // cur loadstring codes chunk |
2448 | pushOptions(macro->m_begin.m_line - 1); // cur loadstring codes chunk options | 2455 | pushOptions(macro->m_begin.m_line - 1); // cur loadstring codes chunk options |
@@ -2455,7 +2462,7 @@ private: | |||
2455 | throw std::logic_error(_info.errorMessage(s("failed to load macro codes, at (macro "sv) + macroName + s("): "sv) + err, macro->macroLit)); | 2462 | throw std::logic_error(_info.errorMessage(s("failed to load macro codes, at (macro "sv) + macroName + s("): "sv) + err, macro->macroLit)); |
2456 | } | 2463 | } |
2457 | lua_pop(L, 1); // cur f | 2464 | lua_pop(L, 1); // cur f |
2458 | pushMoonp("pcall"sv); // cur f pcall | 2465 | pushYue("pcall"sv); // cur f pcall |
2459 | lua_insert(L, -2); // cur pcall f | 2466 | lua_insert(L, -2); // cur pcall f |
2460 | if (lua_pcall(L, 1, 2, 0) != 0) { // f(), cur success macro | 2467 | if (lua_pcall(L, 1, 2, 0) != 0) { // f(), cur success macro |
2461 | std::string err = lua_tostring(L, -1); | 2468 | std::string err = lua_tostring(L, -1); |
@@ -2482,7 +2489,7 @@ private: | |||
2482 | void transformMacro(Macro_t* macro, str_list&, bool) { | 2489 | void transformMacro(Macro_t* macro, str_list&, bool) { |
2483 | throw std::logic_error(_info.errorMessage("macro feature not supported"sv, macro)); | 2490 | throw std::logic_error(_info.errorMessage("macro feature not supported"sv, macro)); |
2484 | } | 2491 | } |
2485 | #endif // MOONP_NO_MACRO | 2492 | #endif // YUE_NO_MACRO |
2486 | 2493 | ||
2487 | void transformReturn(Return_t* returnNode, str_list& out) { | 2494 | void transformReturn(Return_t* returnNode, str_list& out) { |
2488 | if (!_enableReturn.top()) { | 2495 | if (!_enableReturn.top()) { |
@@ -2613,11 +2620,11 @@ private: | |||
2613 | case id<self_t>(): | 2620 | case id<self_t>(): |
2614 | arg.name = "self"sv; | 2621 | arg.name = "self"sv; |
2615 | break; | 2622 | break; |
2616 | default: assert(false); break; | 2623 | default: YUEE("AST node mismatch", selfName->name.get()); break; |
2617 | } | 2624 | } |
2618 | break; | 2625 | break; |
2619 | } | 2626 | } |
2620 | default: assert(false); break; | 2627 | default: YUEE("AST node mismatch", def->name.get()); break; |
2621 | } | 2628 | } |
2622 | forceAddToScope(arg.name); | 2629 | forceAddToScope(arg.name); |
2623 | if (def->defaultValue) { | 2630 | if (def->defaultValue) { |
@@ -2710,7 +2717,7 @@ private: | |||
2710 | case id<self_t>(): | 2717 | case id<self_t>(): |
2711 | out.push_back(s("self"sv)); | 2718 | out.push_back(s("self"sv)); |
2712 | break; | 2719 | break; |
2713 | default: assert(false); break; | 2720 | default: YUEE("AST node mismatch", name); break; |
2714 | } | 2721 | } |
2715 | } | 2722 | } |
2716 | 2723 | ||
@@ -3170,24 +3177,24 @@ private: | |||
3170 | temp.back() = s(temp.back().front() == '[' ? "[ "sv : "["sv) + temp.back() + s("]"sv); | 3177 | temp.back() = s(temp.back().front() == '[' ? "[ "sv : "["sv) + temp.back() + s("]"sv); |
3171 | break; | 3178 | break; |
3172 | case id<InvokeArgs_t>(): transformInvokeArgs(static_cast<InvokeArgs_t*>(item), temp); break; | 3179 | case id<InvokeArgs_t>(): transformInvokeArgs(static_cast<InvokeArgs_t*>(item), temp); break; |
3173 | default: assert(false); break; | 3180 | default: YUEE("AST node mismatch", item); break; |
3174 | } | 3181 | } |
3175 | } | 3182 | } |
3176 | switch (usage) { | 3183 | switch (usage) { |
3177 | case ExpUsage::Common: | 3184 | case ExpUsage::Common: |
3178 | out.push_back(indent() + join(temp) + nll(chainList.front())); | 3185 | out.push_back(indent() + join(temp) + nll(x)); |
3179 | break; | 3186 | break; |
3180 | case ExpUsage::Return: | 3187 | case ExpUsage::Return: |
3181 | out.push_back(indent() + s("return "sv) + join(temp) + nll(chainList.front())); | 3188 | out.push_back(indent() + s("return "sv) + join(temp) + nll(x)); |
3182 | break; | 3189 | break; |
3183 | case ExpUsage::Assignment: assert(false); break; | 3190 | case ExpUsage::Assignment: YUEE("invalid expression usage", x); break; |
3184 | default: | 3191 | default: |
3185 | out.push_back(join(temp)); | 3192 | out.push_back(join(temp)); |
3186 | break; | 3193 | break; |
3187 | } | 3194 | } |
3188 | } | 3195 | } |
3189 | 3196 | ||
3190 | #ifndef MOONP_NO_MACRO | 3197 | #ifndef YUE_NO_MACRO |
3191 | std::tuple<std::string,std::string,str_list> expandMacroStr(ChainValue_t* chainValue) { | 3198 | std::tuple<std::string,std::string,str_list> expandMacroStr(ChainValue_t* chainValue) { |
3192 | const auto& chainList = chainValue->items.objects(); | 3199 | const auto& chainList = chainValue->items.objects(); |
3193 | auto x = ast_to<Callable_t>(chainList.front())->item.to<MacroName_t>(); | 3200 | auto x = ast_to<Callable_t>(chainList.front())->item.to<MacroName_t>(); |
@@ -3212,7 +3219,7 @@ private: | |||
3212 | } | 3219 | } |
3213 | auto fcodes = _parser.toString(args->back()); | 3220 | auto fcodes = _parser.toString(args->back()); |
3214 | Utils::trim(fcodes); | 3221 | Utils::trim(fcodes); |
3215 | pushMoonp("loadstring"sv); // loadstring | 3222 | pushYue("loadstring"sv); // loadstring |
3216 | lua_pushlstring(L, fcodes.c_str(), fcodes.size()); // loadstring codes | 3223 | lua_pushlstring(L, fcodes.c_str(), fcodes.size()); // loadstring codes |
3217 | lua_pushliteral(L, "=(macro in-place)"); // loadstring codes chunk | 3224 | lua_pushliteral(L, "=(macro in-place)"); // loadstring codes chunk |
3218 | pushOptions(args->back()->m_begin.m_line - 1); // loadstring codes chunk options | 3225 | pushOptions(args->back()->m_begin.m_line - 1); // loadstring codes chunk options |
@@ -3225,7 +3232,7 @@ private: | |||
3225 | throw std::logic_error(_info.errorMessage(s("failed to load macro codes, at (macro in-place): "sv) + err, x)); | 3232 | throw std::logic_error(_info.errorMessage(s("failed to load macro codes, at (macro in-place): "sv) + err, x)); |
3226 | } | 3233 | } |
3227 | lua_pop(L, 1); // f | 3234 | lua_pop(L, 1); // f |
3228 | pushMoonp("pcall"sv); // f pcall | 3235 | pushYue("pcall"sv); // f pcall |
3229 | lua_insert(L, -2); // pcall f | 3236 | lua_insert(L, -2); // pcall f |
3230 | if (lua_pcall(L, 1, 2, 0) != 0) { // f(), success macroFunc | 3237 | if (lua_pcall(L, 1, 2, 0) != 0) { // f(), success macroFunc |
3231 | std::string err = lua_tostring(L, -1); | 3238 | std::string err = lua_tostring(L, -1); |
@@ -3236,7 +3243,7 @@ private: | |||
3236 | throw std::logic_error(_info.errorMessage(s("failed to generate macro function\n"sv) + err, x)); | 3243 | throw std::logic_error(_info.errorMessage(s("failed to generate macro function\n"sv) + err, x)); |
3237 | } // true macroFunc | 3244 | } // true macroFunc |
3238 | lua_remove(L, -2); // macroFunc | 3245 | lua_remove(L, -2); // macroFunc |
3239 | pushMoonp("pcall"sv); // macroFunc pcall | 3246 | pushYue("pcall"sv); // macroFunc pcall |
3240 | lua_insert(L, -2); // pcall macroFunc | 3247 | lua_insert(L, -2); // pcall macroFunc |
3241 | bool success = lua_pcall(L, 1, 2, 0) == 0; | 3248 | bool success = lua_pcall(L, 1, 2, 0) == 0; |
3242 | if (!success) { // err | 3249 | if (!success) { // err |
@@ -3254,7 +3261,7 @@ private: | |||
3254 | if (lua_isfunction(L, -1) == 0) { | 3261 | if (lua_isfunction(L, -1) == 0) { |
3255 | throw std::logic_error(_info.errorMessage("can not resolve macro"sv, x)); | 3262 | throw std::logic_error(_info.errorMessage("can not resolve macro"sv, x)); |
3256 | } // cur macroFunc | 3263 | } // cur macroFunc |
3257 | pushMoonp("pcall"sv); // cur macroFunc pcall | 3264 | pushYue("pcall"sv); // cur macroFunc pcall |
3258 | lua_insert(L, -2); // cur pcall macroFunc | 3265 | lua_insert(L, -2); // cur pcall macroFunc |
3259 | auto item = *(++chainList.begin()); | 3266 | auto item = *(++chainList.begin()); |
3260 | const node_container* args = nullptr; | 3267 | const node_container* args = nullptr; |
@@ -3457,11 +3464,11 @@ private: | |||
3457 | } | 3464 | } |
3458 | } | 3465 | } |
3459 | } | 3466 | } |
3460 | #endif // MOONP_NO_MACRO | 3467 | #endif // YUE_NO_MACRO |
3461 | 3468 | ||
3462 | void transformChainValue(ChainValue_t* chainValue, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr, bool allowBlockMacroReturn = false) { | 3469 | void transformChainValue(ChainValue_t* chainValue, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr, bool allowBlockMacroReturn = false) { |
3463 | if (isMacroChain(chainValue)) { | 3470 | if (isMacroChain(chainValue)) { |
3464 | #ifndef MOONP_NO_MACRO | 3471 | #ifndef YUE_NO_MACRO |
3465 | ast_ptr<false,ast_node> node; | 3472 | ast_ptr<false,ast_node> node; |
3466 | std::unique_ptr<input> codes; | 3473 | std::unique_ptr<input> codes; |
3467 | std::string luaCodes; | 3474 | std::string luaCodes; |
@@ -3515,7 +3522,7 @@ private: | |||
3515 | #else | 3522 | #else |
3516 | (void)allowBlockMacroReturn; | 3523 | (void)allowBlockMacroReturn; |
3517 | throw std::logic_error(_info.errorMessage("macro feature not supported"sv, chainValue)); | 3524 | throw std::logic_error(_info.errorMessage("macro feature not supported"sv, chainValue)); |
3518 | #endif // MOONP_NO_MACRO | 3525 | #endif // YUE_NO_MACRO |
3519 | } | 3526 | } |
3520 | const auto& chainList = chainValue->items.objects(); | 3527 | const auto& chainList = chainValue->items.objects(); |
3521 | if (transformChainEndWithEOP(chainList, out, usage, assignList)) { | 3528 | if (transformChainEndWithEOP(chainList, out, usage, assignList)) { |
@@ -3561,7 +3568,7 @@ private: | |||
3561 | case id<DoubleString_t>(): transformDoubleString(static_cast<DoubleString_t*>(arg), temp); break; | 3568 | case id<DoubleString_t>(): transformDoubleString(static_cast<DoubleString_t*>(arg), temp); break; |
3562 | case id<LuaString_t>(): transformLuaString(static_cast<LuaString_t*>(arg), temp); break; | 3569 | case id<LuaString_t>(): transformLuaString(static_cast<LuaString_t*>(arg), temp); break; |
3563 | case id<TableLit_t>(): transformTableLit(static_cast<TableLit_t*>(arg), temp); break; | 3570 | case id<TableLit_t>(): transformTableLit(static_cast<TableLit_t*>(arg), temp); break; |
3564 | default: assert(false); break; | 3571 | default: YUEE("AST node mismatch", arg); break; |
3565 | } | 3572 | } |
3566 | } | 3573 | } |
3567 | out.push_back(s("("sv) + join(temp, ", "sv) + s(")"sv)); | 3574 | out.push_back(s("("sv) + join(temp, ", "sv) + s(")"sv)); |
@@ -3624,7 +3631,7 @@ private: | |||
3624 | temp.back() = indent() + s("if "sv) + temp.back() + s(" then"sv) + nll(item); | 3631 | temp.back() = indent() + s("if "sv) + temp.back() + s(" then"sv) + nll(item); |
3625 | pushScope(); | 3632 | pushScope(); |
3626 | break; | 3633 | break; |
3627 | default: assert(false); break; | 3634 | default: YUEE("AST node mismatch", item); break; |
3628 | } | 3635 | } |
3629 | } | 3636 | } |
3630 | if (auto stmt = comp->value.as<Statement_t>()) { | 3637 | if (auto stmt = comp->value.as<Statement_t>()) { |
@@ -3680,7 +3687,7 @@ private: | |||
3680 | temp.back() = indent() + s("if "sv) + temp.back() + s(" then"sv) + nll(item); | 3687 | temp.back() = indent() + s("if "sv) + temp.back() + s(" then"sv) + nll(item); |
3681 | pushScope(); | 3688 | pushScope(); |
3682 | break; | 3689 | break; |
3683 | default: assert(false); break; | 3690 | default: YUEE("AST node mismatch", item); break; |
3684 | } | 3691 | } |
3685 | } | 3692 | } |
3686 | { | 3693 | { |
@@ -3760,13 +3767,13 @@ private: | |||
3760 | varAfter.push_back(desVar); | 3767 | varAfter.push_back(desVar); |
3761 | break; | 3768 | break; |
3762 | } | 3769 | } |
3763 | default: assert(false); break; | 3770 | default: YUEE("AST node mismatch", item); break; |
3764 | } | 3771 | } |
3765 | } | 3772 | } |
3766 | switch (loopTarget->getId()) { | 3773 | switch (loopTarget->getId()) { |
3767 | case id<star_exp_t>(): { | 3774 | case id<star_exp_t>(): { |
3768 | auto star_exp = static_cast<star_exp_t*>(loopTarget); | 3775 | auto star_exp = static_cast<star_exp_t*>(loopTarget); |
3769 | auto listVar = singleVariableFrom(star_exp->value); | 3776 | std::string listVar; |
3770 | auto indexVar = getUnusedName("_index_"sv); | 3777 | auto indexVar = getUnusedName("_index_"sv); |
3771 | varAfter.push_back(indexVar); | 3778 | varAfter.push_back(indexVar); |
3772 | auto value = singleValueFrom(star_exp->value); | 3779 | auto value = singleValueFrom(star_exp->value); |
@@ -3779,12 +3786,6 @@ private: | |||
3779 | auto slice = ast_cast<Slice_t>(chainList.back()); | 3786 | auto slice = ast_cast<Slice_t>(chainList.back()); |
3780 | BREAK_IF(!slice); | 3787 | BREAK_IF(!slice); |
3781 | endWithSlice = true; | 3788 | endWithSlice = true; |
3782 | if (listVar.empty() && chainList.size() == 2 && | ||
3783 | ast_is<Callable_t>(chainList.front())) { | ||
3784 | transformCallable(static_cast<Callable_t*>(chainList.front()), temp); | ||
3785 | listVar = temp.back(); | ||
3786 | temp.pop_back(); | ||
3787 | } | ||
3788 | chainList.pop_back(); | 3789 | chainList.pop_back(); |
3789 | auto chain = x->new_ptr<ChainValue_t>(); | 3790 | auto chain = x->new_ptr<ChainValue_t>(); |
3790 | for (auto item : chainList) { | 3791 | for (auto item : chainList) { |
@@ -3808,12 +3809,10 @@ private: | |||
3808 | stepValue = temp.back(); | 3809 | stepValue = temp.back(); |
3809 | temp.pop_back(); | 3810 | temp.pop_back(); |
3810 | } | 3811 | } |
3811 | if (listVar.empty()) { | 3812 | listVar = getUnusedName("_list_"sv); |
3812 | listVar = getUnusedName("_list_"sv); | 3813 | varBefore.push_back(listVar); |
3813 | varBefore.push_back(listVar); | 3814 | transformChainValue(chain, temp, ExpUsage::Closure); |
3814 | transformChainValue(chain, temp, ExpUsage::Closure); | 3815 | _buf << indent() << "local "sv << listVar << " = "sv << temp.back() << nll(nameList); |
3815 | _buf << indent() << "local "sv << listVar << " = "sv << temp.back() << nll(nameList); | ||
3816 | } | ||
3817 | std::string maxVar; | 3816 | std::string maxVar; |
3818 | if (!stopValue.empty()) { | 3817 | if (!stopValue.empty()) { |
3819 | maxVar = getUnusedName("_max_"sv); | 3818 | maxVar = getUnusedName("_max_"sv); |
@@ -3859,7 +3858,7 @@ private: | |||
3859 | _buf << indent() << "for "sv << join(vars, ", "sv) << " in "sv << temp.back() << " do"sv << nlr(loopTarget); | 3858 | _buf << indent() << "for "sv << join(vars, ", "sv) << " in "sv << temp.back() << " do"sv << nlr(loopTarget); |
3860 | out.push_back(clearBuf()); | 3859 | out.push_back(clearBuf()); |
3861 | break; | 3860 | break; |
3862 | default: assert(false); break; | 3861 | default: YUEE("AST node mismatch", loopTarget); break; |
3863 | } | 3862 | } |
3864 | for (auto& var : varBefore) addToScope(var); | 3863 | for (auto& var : varBefore) addToScope(var); |
3865 | pushScope(); | 3864 | pushScope(); |
@@ -3926,7 +3925,7 @@ private: | |||
3926 | switch (arg->getId()) { | 3925 | switch (arg->getId()) { |
3927 | case id<Exp_t>(): transformExp(static_cast<Exp_t*>(arg), temp, ExpUsage::Closure); break; | 3926 | case id<Exp_t>(): transformExp(static_cast<Exp_t*>(arg), temp, ExpUsage::Closure); break; |
3928 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(arg), temp); break; | 3927 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(arg), temp); break; |
3929 | default: assert(false); break; | 3928 | default: YUEE("AST node mismatch", arg); break; |
3930 | } | 3929 | } |
3931 | } | 3930 | } |
3932 | out.push_back(s("("sv) + join(temp, ", "sv) + s(")"sv)); | 3931 | out.push_back(s("("sv) + join(temp, ", "sv) + s(")"sv)); |
@@ -3963,7 +3962,7 @@ private: | |||
3963 | transformBlock(newBlock, out, usage, assignList); | 3962 | transformBlock(newBlock, out, usage, assignList); |
3964 | break; | 3963 | break; |
3965 | } | 3964 | } |
3966 | default: assert(false); break; | 3965 | default: YUEE("AST node mismatch", body); break; |
3967 | } | 3966 | } |
3968 | } | 3967 | } |
3969 | 3968 | ||
@@ -4172,13 +4171,13 @@ private: | |||
4172 | case id<LuaString_t>(): transformLuaString(static_cast<LuaString_t*>(key), temp); | 4171 | case id<LuaString_t>(): transformLuaString(static_cast<LuaString_t*>(key), temp); |
4173 | temp.back() = s("[ "sv) + temp.back() + s("]"sv); | 4172 | temp.back() = s("[ "sv) + temp.back() + s("]"sv); |
4174 | break; | 4173 | break; |
4175 | default: assert(false); break; | 4174 | default: YUEE("AST node mismatch", key); break; |
4176 | } | 4175 | } |
4177 | auto value = pair->value.get(); | 4176 | auto value = pair->value.get(); |
4178 | switch (value->getId()) { | 4177 | switch (value->getId()) { |
4179 | case id<Exp_t>(): transformExp(static_cast<Exp_t*>(value), temp, ExpUsage::Closure); break; | 4178 | case id<Exp_t>(): transformExp(static_cast<Exp_t*>(value), temp, ExpUsage::Closure); break; |
4180 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(value), temp); break; | 4179 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(value), temp); break; |
4181 | default: assert(false); break; | 4180 | default: YUEE("AST node mismatch", value); break; |
4182 | } | 4181 | } |
4183 | out.push_back(temp.front() + s(" = "sv) + temp.back()); | 4182 | out.push_back(temp.front() + s(" = "sv) + temp.back()); |
4184 | } | 4183 | } |
@@ -4188,7 +4187,7 @@ private: | |||
4188 | switch (name->getId()) { | 4187 | switch (name->getId()) { |
4189 | case id<SelfName_t>(): transformSelfName(static_cast<SelfName_t*>(name), out); break; | 4188 | case id<SelfName_t>(): transformSelfName(static_cast<SelfName_t*>(name), out); break; |
4190 | case id<Name_t>(): out.push_back(_parser.toString(name)); break; | 4189 | case id<Name_t>(): out.push_back(_parser.toString(name)); break; |
4191 | default: assert(false); break; | 4190 | default: YUEE("AST node mismatch", name); break; |
4192 | } | 4191 | } |
4193 | } | 4192 | } |
4194 | 4193 | ||
@@ -4232,7 +4231,7 @@ private: | |||
4232 | } | 4231 | } |
4233 | break; | 4232 | break; |
4234 | } | 4233 | } |
4235 | default: assert(false); break; | 4234 | default: YUEE("AST node mismatch", content); break; |
4236 | } | 4235 | } |
4237 | } | 4236 | } |
4238 | out.push_back(temp.empty() ? s("\"\""sv) : join(temp, " .. "sv)); | 4237 | out.push_back(temp.empty() ? s("\"\""sv) : join(temp, " .. "sv)); |
@@ -4244,7 +4243,7 @@ private: | |||
4244 | case id<SingleString_t>(): transformSingleString(static_cast<SingleString_t*>(str), out); break; | 4243 | case id<SingleString_t>(): transformSingleString(static_cast<SingleString_t*>(str), out); break; |
4245 | case id<DoubleString_t>(): transformDoubleString(static_cast<DoubleString_t*>(str), out); break; | 4244 | case id<DoubleString_t>(): transformDoubleString(static_cast<DoubleString_t*>(str), out); break; |
4246 | case id<LuaString_t>(): transformLuaString(static_cast<LuaString_t*>(str), out); break; | 4245 | case id<LuaString_t>(): transformLuaString(static_cast<LuaString_t*>(str), out); break; |
4247 | default: assert(false); break; | 4246 | default: YUEE("AST node mismatch", str); break; |
4248 | } | 4247 | } |
4249 | } | 4248 | } |
4250 | 4249 | ||
@@ -4396,7 +4395,7 @@ private: | |||
4396 | case id<Statement_t>(): | 4395 | case id<Statement_t>(): |
4397 | transformStatement(static_cast<Statement_t*>(content), statements); | 4396 | transformStatement(static_cast<Statement_t*>(content), statements); |
4398 | break; | 4397 | break; |
4399 | default: assert(false); break; | 4398 | default:YUEE("AST node mismatch", content); break; |
4400 | } | 4399 | } |
4401 | } | 4400 | } |
4402 | for (auto& member : members) { | 4401 | for (auto& member : members) { |
@@ -4602,7 +4601,7 @@ private: | |||
4602 | case id<normal_pair_t>(): | 4601 | case id<normal_pair_t>(): |
4603 | transform_normal_pair(static_cast<normal_pair_t*>(keyValue), temp); | 4602 | transform_normal_pair(static_cast<normal_pair_t*>(keyValue), temp); |
4604 | break; | 4603 | break; |
4605 | default: assert(false); break; | 4604 | default: YUEE("AST node mismatch", keyValue); break; |
4606 | } | 4605 | } |
4607 | if (type == MemType::Property) { | 4606 | if (type == MemType::Property) { |
4608 | incIndentOffset(); | 4607 | incIndentOffset(); |
@@ -4621,7 +4620,7 @@ private: | |||
4621 | case id<AssignableChain_t>(): transformAssignableChain(static_cast<AssignableChain_t*>(item), out); break; | 4620 | case id<AssignableChain_t>(): transformAssignableChain(static_cast<AssignableChain_t*>(item), out); break; |
4622 | case id<Variable_t>(): transformVariable(static_cast<Variable_t*>(item), out); break; | 4621 | case id<Variable_t>(): transformVariable(static_cast<Variable_t*>(item), out); break; |
4623 | case id<SelfName_t>(): transformSelfName(static_cast<SelfName_t*>(item), out); break; | 4622 | case id<SelfName_t>(): transformSelfName(static_cast<SelfName_t*>(item), out); break; |
4624 | default: assert(false); break; | 4623 | default: YUEE("AST node mismatch", item); break; |
4625 | } | 4624 | } |
4626 | } | 4625 | } |
4627 | 4626 | ||
@@ -4646,14 +4645,8 @@ private: | |||
4646 | checkAssignable(with->valueList); | 4645 | checkAssignable(with->valueList); |
4647 | auto vars = getAssignVars(with); | 4646 | auto vars = getAssignVars(with); |
4648 | if (vars.front().empty()) { | 4647 | if (vars.front().empty()) { |
4649 | if (with->assigns->values.objects().size() == 1) { | 4648 | withVar = getUnusedName("_with_"sv); |
4650 | auto var = singleVariableFrom(with->assigns->values.objects().front()); | 4649 | { |
4651 | if (!var.empty()) { | ||
4652 | withVar = var; | ||
4653 | } | ||
4654 | } | ||
4655 | if (withVar.empty()) { | ||
4656 | withVar = getUnusedName("_with_"sv); | ||
4657 | auto assignment = x->new_ptr<ExpListAssign_t>(); | 4650 | auto assignment = x->new_ptr<ExpListAssign_t>(); |
4658 | assignment->expList.set(toAst<ExpList_t>(withVar, x)); | 4651 | assignment->expList.set(toAst<ExpList_t>(withVar, x)); |
4659 | auto assign = x->new_ptr<Assign_t>(); | 4652 | auto assign = x->new_ptr<Assign_t>(); |
@@ -4693,21 +4686,18 @@ private: | |||
4693 | transformAssignment(assignment, temp); | 4686 | transformAssignment(assignment, temp); |
4694 | } | 4687 | } |
4695 | } else { | 4688 | } else { |
4696 | withVar = singleVariableFrom(with->valueList); | 4689 | withVar = getUnusedName("_with_"sv); |
4697 | if (withVar.empty()) { | 4690 | auto assignment = x->new_ptr<ExpListAssign_t>(); |
4698 | withVar = getUnusedName("_with_"sv); | 4691 | assignment->expList.set(toAst<ExpList_t>(withVar, x)); |
4699 | auto assignment = x->new_ptr<ExpListAssign_t>(); | 4692 | auto assign = x->new_ptr<Assign_t>(); |
4700 | assignment->expList.set(toAst<ExpList_t>(withVar, x)); | 4693 | assign->values.dup(with->valueList->exprs); |
4701 | auto assign = x->new_ptr<Assign_t>(); | 4694 | assignment->action.set(assign); |
4702 | assign->values.dup(with->valueList->exprs); | 4695 | if (!returnValue) { |
4703 | assignment->action.set(assign); | 4696 | scoped = true; |
4704 | if (!returnValue) { | 4697 | temp.push_back(indent() + s("do"sv) + nll(with)); |
4705 | scoped = true; | 4698 | pushScope(); |
4706 | temp.push_back(indent() + s("do"sv) + nll(with)); | ||
4707 | pushScope(); | ||
4708 | } | ||
4709 | transformAssignment(assignment, temp); | ||
4710 | } | 4699 | } |
4700 | transformAssignment(assignment, temp); | ||
4711 | } | 4701 | } |
4712 | if (!with->eop && !scoped && !returnValue) { | 4702 | if (!with->eop && !scoped && !returnValue) { |
4713 | pushScope(); | 4703 | pushScope(); |
@@ -4843,7 +4833,7 @@ private: | |||
4843 | } | 4833 | } |
4844 | break; | 4834 | break; |
4845 | } | 4835 | } |
4846 | default: assert(false); break; | 4836 | default: YUEE("AST node mismatch", item); break; |
4847 | } | 4837 | } |
4848 | } | 4838 | } |
4849 | 4839 | ||
@@ -4942,7 +4932,7 @@ private: | |||
4942 | case id<normal_pair_t>(): transform_normal_pair(static_cast<normal_pair_t*>(pair), temp); break; | 4932 | case id<normal_pair_t>(): transform_normal_pair(static_cast<normal_pair_t*>(pair), temp); break; |
4943 | case id<TableBlockIndent_t>(): transformTableBlockIndent(static_cast<TableBlockIndent_t*>(pair), temp); break; | 4933 | case id<TableBlockIndent_t>(): transformTableBlockIndent(static_cast<TableBlockIndent_t*>(pair), temp); break; |
4944 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(pair), temp); break; | 4934 | case id<TableBlock_t>(): transformTableBlock(static_cast<TableBlock_t*>(pair), temp); break; |
4945 | default: assert(false); break; | 4935 | default: YUEE("AST node mismatch", pair); break; |
4946 | } | 4936 | } |
4947 | temp.back() = indent() + temp.back() + (pair == pairs.back() ? Empty : s(","sv)) + nll(pair); | 4937 | temp.back() = indent() + temp.back() + (pair == pairs.back() ? Empty : s(","sv)) + nll(pair); |
4948 | } | 4938 | } |
@@ -4986,7 +4976,7 @@ private: | |||
4986 | temp.back() = indent() + s("if "sv) + temp.back() + s(" then"sv) + nll(item); | 4976 | temp.back() = indent() + s("if "sv) + temp.back() + s(" then"sv) + nll(item); |
4987 | pushScope(); | 4977 | pushScope(); |
4988 | break; | 4978 | break; |
4989 | default: assert(false); break; | 4979 | default: YUEE("AST node mismatch", item); break; |
4990 | } | 4980 | } |
4991 | } | 4981 | } |
4992 | transformExp(comp->key, kv, ExpUsage::Closure); | 4982 | transformExp(comp->key, kv, ExpUsage::Closure); |
@@ -5158,7 +5148,7 @@ private: | |||
5158 | expList->exprs.push_back(exp); | 5148 | expList->exprs.push_back(exp); |
5159 | break; | 5149 | break; |
5160 | } | 5150 | } |
5161 | default: assert(false); break; | 5151 | default: YUEE("AST node mismatch", name); break; |
5162 | } | 5152 | } |
5163 | } | 5153 | } |
5164 | if (objAssign) { | 5154 | if (objAssign) { |
@@ -5196,7 +5186,7 @@ private: | |||
5196 | } | 5186 | } |
5197 | if (auto tabLit = import->target.as<ImportTabLit_t>()) { | 5187 | if (auto tabLit = import->target.as<ImportTabLit_t>()) { |
5198 | auto newTab = x->new_ptr<ImportTabLit_t>(); | 5188 | auto newTab = x->new_ptr<ImportTabLit_t>(); |
5199 | #ifndef MOONP_NO_MACRO | 5189 | #ifndef YUE_NO_MACRO |
5200 | bool importAllMacro = false; | 5190 | bool importAllMacro = false; |
5201 | std::list<std::pair<std::string,std::string>> macroPairs; | 5191 | std::list<std::pair<std::string,std::string>> macroPairs; |
5202 | for (auto item : tabLit->items.objects()) { | 5192 | for (auto item : tabLit->items.objects()) { |
@@ -5220,7 +5210,7 @@ private: | |||
5220 | case id<normal_pair_t>(): | 5210 | case id<normal_pair_t>(): |
5221 | newTab->items.push_back(item); | 5211 | newTab->items.push_back(item); |
5222 | break; | 5212 | break; |
5223 | default: assert(false); break; | 5213 | default: YUEE("AST node mismatch", item); break; |
5224 | } | 5214 | } |
5225 | } | 5215 | } |
5226 | if (importAllMacro || !macroPairs.empty()) { | 5216 | if (importAllMacro || !macroPairs.empty()) { |
@@ -5231,7 +5221,7 @@ private: | |||
5231 | pushCurrentModule(); // cur | 5221 | pushCurrentModule(); // cur |
5232 | int top = lua_gettop(L) - 1; // Lua state may be setup by pushCurrentModule() | 5222 | int top = lua_gettop(L) - 1; // Lua state may be setup by pushCurrentModule() |
5233 | DEFER(lua_settop(L, top)); | 5223 | DEFER(lua_settop(L, top)); |
5234 | pushMoonp("find_modulepath"sv); // cur find_modulepath | 5224 | pushYue("find_modulepath"sv); // cur find_modulepath |
5235 | lua_pushlstring(L, moduleName.c_str(), moduleName.size()); // cur find_modulepath moduleName | 5225 | lua_pushlstring(L, moduleName.c_str(), moduleName.size()); // cur find_modulepath moduleName |
5236 | if (lua_pcall(L, 1, 1, 0) != 0) { | 5226 | if (lua_pcall(L, 1, 1, 0) != 0) { |
5237 | std::string err = lua_tostring(L, -1); | 5227 | std::string err = lua_tostring(L, -1); |
@@ -5243,7 +5233,7 @@ private: | |||
5243 | std::string moduleFullName = lua_tostring(L, -1); | 5233 | std::string moduleFullName = lua_tostring(L, -1); |
5244 | lua_pop(L, 1); // cur | 5234 | lua_pop(L, 1); // cur |
5245 | if (!isModuleLoaded(moduleFullName)) { | 5235 | if (!isModuleLoaded(moduleFullName)) { |
5246 | pushMoonp("read_file"sv); // cur read_file | 5236 | pushYue("read_file"sv); // cur read_file |
5247 | lua_pushlstring(L, moduleFullName.c_str(), moduleFullName.size()); // cur load_text moduleFullName | 5237 | lua_pushlstring(L, moduleFullName.c_str(), moduleFullName.size()); // cur load_text moduleFullName |
5248 | if (lua_pcall(L, 1, 1, 0) != 0) { | 5238 | if (lua_pcall(L, 1, 1, 0) != 0) { |
5249 | std::string err = lua_tostring(L, -1); | 5239 | std::string err = lua_tostring(L, -1); |
@@ -5253,8 +5243,8 @@ private: | |||
5253 | throw std::logic_error(_info.errorMessage("failed to get module text"sv, x)); | 5243 | throw std::logic_error(_info.errorMessage("failed to get module text"sv, x)); |
5254 | } // cur text | 5244 | } // cur text |
5255 | std::string text = lua_tostring(L, -1); | 5245 | std::string text = lua_tostring(L, -1); |
5256 | auto compiler = MoonCompilerImpl(L, _luaOpen, false, moduleFullName); | 5246 | auto compiler = YueCompilerImpl(L, _luaOpen, false, moduleFullName); |
5257 | MoonConfig config; | 5247 | YueConfig config; |
5258 | config.lineOffset = 0; | 5248 | config.lineOffset = 0; |
5259 | config.lintGlobalVariable = false; | 5249 | config.lintGlobalVariable = false; |
5260 | config.reserveLineNumber = false; | 5250 | config.reserveLineNumber = false; |
@@ -5279,7 +5269,7 @@ private: | |||
5279 | lua_setfield(L, -3, pair.second.c_str()); // cur[second] = val, cur mod | 5269 | lua_setfield(L, -3, pair.second.c_str()); // cur[second] = val, cur mod |
5280 | } | 5270 | } |
5281 | } | 5271 | } |
5282 | #else // MOONP_NO_MACRO | 5272 | #else // YUE_NO_MACRO |
5283 | for (auto item : tabLit->items.objects()) { | 5273 | for (auto item : tabLit->items.objects()) { |
5284 | switch (item->getId()) { | 5274 | switch (item->getId()) { |
5285 | case id<MacroName_t>(): | 5275 | case id<MacroName_t>(): |
@@ -5292,10 +5282,10 @@ private: | |||
5292 | case id<normal_pair_t>(): | 5282 | case id<normal_pair_t>(): |
5293 | newTab->items.push_back(item); | 5283 | newTab->items.push_back(item); |
5294 | break; | 5284 | break; |
5295 | default: assert(false); break; | 5285 | default: YUEE("AST node mismatch", item); break; |
5296 | } | 5286 | } |
5297 | } | 5287 | } |
5298 | #endif // MOONP_NO_MACRO | 5288 | #endif // YUE_NO_MACRO |
5299 | if (newTab->items.empty()) { | 5289 | if (newTab->items.empty()) { |
5300 | out.push_back(Empty); | 5290 | out.push_back(Empty); |
5301 | return; | 5291 | return; |
@@ -5339,7 +5329,7 @@ private: | |||
5339 | case id<ImportFrom_t>(): | 5329 | case id<ImportFrom_t>(): |
5340 | transformImportFrom(static_cast<ImportFrom_t*>(content), out); | 5330 | transformImportFrom(static_cast<ImportFrom_t*>(content), out); |
5341 | break; | 5331 | break; |
5342 | default: assert(false); break; | 5332 | default: YUEE("AST node mismatch", content); break; |
5343 | } | 5333 | } |
5344 | } | 5334 | } |
5345 | 5335 | ||
@@ -5598,25 +5588,25 @@ private: | |||
5598 | } | 5588 | } |
5599 | }; | 5589 | }; |
5600 | 5590 | ||
5601 | const std::string MoonCompilerImpl::Empty; | 5591 | const std::string YueCompilerImpl::Empty; |
5602 | 5592 | ||
5603 | MoonCompiler::MoonCompiler(void* sharedState, | 5593 | YueCompiler::YueCompiler(void* sharedState, |
5604 | const std::function<void(void*)>& luaOpen, | 5594 | const std::function<void(void*)>& luaOpen, |
5605 | bool sameModule): | 5595 | bool sameModule): |
5606 | #ifndef MOONP_NO_MACRO | 5596 | #ifndef YUE_NO_MACRO |
5607 | _compiler(std::make_unique<MoonCompilerImpl>(static_cast<lua_State*>(sharedState), luaOpen, sameModule)) {} | 5597 | _compiler(std::make_unique<YueCompilerImpl>(static_cast<lua_State*>(sharedState), luaOpen, sameModule)) {} |
5608 | #else | 5598 | #else |
5609 | _compiler(std::make_unique<MoonCompilerImpl>()) { | 5599 | _compiler(std::make_unique<YueCompilerImpl>()) { |
5610 | (void)sharedState; | 5600 | (void)sharedState; |
5611 | (void)luaOpen; | 5601 | (void)luaOpen; |
5612 | (void)sameModule; | 5602 | (void)sameModule; |
5613 | } | 5603 | } |
5614 | #endif // MOONP_NO_MACRO | 5604 | #endif // YUE_NO_MACRO |
5615 | 5605 | ||
5616 | MoonCompiler::~MoonCompiler() {} | 5606 | YueCompiler::~YueCompiler() {} |
5617 | 5607 | ||
5618 | CompileInfo MoonCompiler::compile(std::string_view codes, const MoonConfig& config) { | 5608 | CompileInfo YueCompiler::compile(std::string_view codes, const YueConfig& config) { |
5619 | return _compiler->compile(codes, config); | 5609 | return _compiler->compile(codes, config); |
5620 | } | 5610 | } |
5621 | 5611 | ||
5622 | } // namespace MoonP | 5612 | } // namespace yue |
diff --git a/src/MoonP/moon_compiler.h b/src/yuescript/yue_compiler.h index 5855b2d..2e8c86a 100644 --- a/src/MoonP/moon_compiler.h +++ b/src/yuescript/yue_compiler.h | |||
@@ -16,14 +16,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
16 | #include <unordered_map> | 16 | #include <unordered_map> |
17 | #include <functional> | 17 | #include <functional> |
18 | 18 | ||
19 | namespace MoonP { | 19 | namespace yue { |
20 | 20 | ||
21 | extern const std::string_view version; | 21 | extern const std::string_view version; |
22 | extern const std::string_view extension; | 22 | extern const std::string_view extension; |
23 | 23 | ||
24 | using Options = std::unordered_map<std::string,std::string>; | 24 | using Options = std::unordered_map<std::string,std::string>; |
25 | 25 | ||
26 | struct MoonConfig { | 26 | struct YueConfig { |
27 | bool lintGlobalVariable = false; | 27 | bool lintGlobalVariable = false; |
28 | bool implicitReturnRoot = true; | 28 | bool implicitReturnRoot = true; |
29 | bool reserveLineNumber = true; | 29 | bool reserveLineNumber = true; |
@@ -47,17 +47,17 @@ struct CompileInfo { | |||
47 | std::unique_ptr<Options> options; | 47 | std::unique_ptr<Options> options; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | class MoonCompilerImpl; | 50 | class YueCompilerImpl; |
51 | 51 | ||
52 | class MoonCompiler { | 52 | class YueCompiler { |
53 | public: | 53 | public: |
54 | MoonCompiler(void* luaState = nullptr, | 54 | YueCompiler(void* luaState = nullptr, |
55 | const std::function<void(void*)>& luaOpen = nullptr, | 55 | const std::function<void(void*)>& luaOpen = nullptr, |
56 | bool sameModule = false); | 56 | bool sameModule = false); |
57 | virtual ~MoonCompiler(); | 57 | virtual ~YueCompiler(); |
58 | CompileInfo compile(std::string_view codes, const MoonConfig& config = {}); | 58 | CompileInfo compile(std::string_view codes, const YueConfig& config = {}); |
59 | private: | 59 | private: |
60 | std::unique_ptr<MoonCompilerImpl> _compiler; | 60 | std::unique_ptr<YueCompilerImpl> _compiler; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | } // namespace MoonP | 63 | } // namespace yue |
diff --git a/src/MoonP/moon_parser.cpp b/src/yuescript/yue_parser.cpp index a581e15..cf3da01 100644 --- a/src/MoonP/moon_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
@@ -6,11 +6,11 @@ The above copyright notice and this permission notice shall be included in all c | |||
6 | 6 | ||
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
8 | 8 | ||
9 | #include "MoonP/moon_parser.h" | 9 | #include "yuescript/yue_parser.h" |
10 | 10 | ||
11 | namespace pl = parserlib; | 11 | namespace pl = parserlib; |
12 | 12 | ||
13 | namespace MoonP { | 13 | namespace yue { |
14 | using namespace std::string_view_literals; | 14 | using namespace std::string_view_literals; |
15 | 15 | ||
16 | std::unordered_set<std::string> LuaKeywords = { | 16 | std::unordered_set<std::string> LuaKeywords = { |
@@ -29,10 +29,10 @@ std::unordered_set<std::string> Keywords = { | |||
29 | "until", "while", // Lua keywords | 29 | "until", "while", // Lua keywords |
30 | "as", "class", "continue", "export", "extends", | 30 | "as", "class", "continue", "export", "extends", |
31 | "from", "global", "import", "macro", "switch", | 31 | "from", "global", "import", "macro", "switch", |
32 | "unless", "using", "when", "with" // Moon keywords | 32 | "unless", "using", "when", "with" // Yue keywords |
33 | }; | 33 | }; |
34 | 34 | ||
35 | MoonParser::MoonParser() { | 35 | YueParser::YueParser() { |
36 | plain_space = *set(" \t"); | 36 | plain_space = *set(" \t"); |
37 | Break = nl(-expr('\r') >> '\n'); | 37 | Break = nl(-expr('\r') >> '\n'); |
38 | Any = Break | any(); | 38 | Any = Break | any(); |
@@ -245,7 +245,7 @@ MoonParser::MoonParser() { | |||
245 | IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> plain_body; | 245 | IfElse = -(Break >> *EmptyLine >> CheckIndent) >> key("else") >> plain_body; |
246 | If = key("if") >> Seperator >> IfCond >> plain_body_with("then") >> *IfElseIf >> -IfElse; | 246 | If = key("if") >> Seperator >> IfCond >> plain_body_with("then") >> *IfElseIf >> -IfElse; |
247 | Unless = key("unless") >> Seperator >> IfCond >> plain_body_with("then") >> *IfElseIf >> -IfElse; | 247 | Unless = key("unless") >> Seperator >> IfCond >> plain_body_with("then") >> *IfElseIf >> -IfElse; |
248 | 248 | ||
249 | While = key("while") >> disable_do_chain(Exp) >> plain_body_with("do"); | 249 | While = key("while") >> disable_do_chain(Exp) >> plain_body_with("do"); |
250 | Repeat = key("repeat") >> Body >> Break >> *EmptyLine >> CheckIndent >> key("until") >> Exp; | 250 | Repeat = key("repeat") >> Body >> Break >> *EmptyLine >> CheckIndent >> key("until") >> Exp; |
251 | 251 | ||
@@ -611,7 +611,7 @@ MoonParser::MoonParser() { | |||
611 | File = White >> -Shebang >> Block >> eof(); | 611 | File = White >> -Shebang >> Block >> eof(); |
612 | } | 612 | } |
613 | 613 | ||
614 | ParseInfo MoonParser::parse(std::string_view codes, rule& r) { | 614 | ParseInfo YueParser::parse(std::string_view codes, rule& r) { |
615 | ParseInfo res; | 615 | ParseInfo res; |
616 | try { | 616 | try { |
617 | res.codes = std::make_unique<input>(); | 617 | res.codes = std::make_unique<input>(); |
@@ -650,19 +650,19 @@ ParseInfo MoonParser::parse(std::string_view codes, rule& r) { | |||
650 | return res; | 650 | return res; |
651 | } | 651 | } |
652 | 652 | ||
653 | std::string MoonParser::toString(ast_node* node) { | 653 | std::string YueParser::toString(ast_node* node) { |
654 | return _converter.to_bytes(std::wstring(node->m_begin.m_it, node->m_end.m_it)); | 654 | return _converter.to_bytes(std::wstring(node->m_begin.m_it, node->m_end.m_it)); |
655 | } | 655 | } |
656 | 656 | ||
657 | std::string MoonParser::toString(input::iterator begin, input::iterator end) { | 657 | std::string YueParser::toString(input::iterator begin, input::iterator end) { |
658 | return _converter.to_bytes(std::wstring(begin, end)); | 658 | return _converter.to_bytes(std::wstring(begin, end)); |
659 | } | 659 | } |
660 | 660 | ||
661 | input MoonParser::encode(std::string_view codes) { | 661 | input YueParser::encode(std::string_view codes) { |
662 | return _converter.from_bytes(&codes.front(), &codes.back() + 1); | 662 | return _converter.from_bytes(&codes.front(), &codes.back() + 1); |
663 | } | 663 | } |
664 | 664 | ||
665 | std::string MoonParser::decode(const input& codes) { | 665 | std::string YueParser::decode(const input& codes) { |
666 | return _converter.to_bytes(codes); | 666 | return _converter.to_bytes(codes); |
667 | } | 667 | } |
668 | 668 | ||
@@ -716,4 +716,4 @@ std::string ParseInfo::errorMessage(std::string_view msg, const input_range* loc | |||
716 | return buf.str(); | 716 | return buf.str(); |
717 | } | 717 | } |
718 | 718 | ||
719 | } // namespace MoonP | 719 | } // namespace yue |
diff --git a/src/MoonP/moon_parser.h b/src/yuescript/yue_parser.h index b165070..f9a0d54 100644 --- a/src/MoonP/moon_parser.h +++ b/src/yuescript/yue_parser.h | |||
@@ -16,10 +16,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
16 | #include <sstream> | 16 | #include <sstream> |
17 | #include <string_view> | 17 | #include <string_view> |
18 | 18 | ||
19 | #include "MoonP/ast.hpp" | 19 | #include "yuescript/ast.hpp" |
20 | #include "MoonP/moon_ast.h" | 20 | #include "yuescript/yue_ast.h" |
21 | 21 | ||
22 | namespace MoonP { | 22 | namespace yue { |
23 | using namespace parserlib; | 23 | using namespace parserlib; |
24 | 24 | ||
25 | struct ParseInfo { | 25 | struct ParseInfo { |
@@ -42,9 +42,9 @@ struct identity { typedef T type; }; | |||
42 | extern std::unordered_set<std::string> LuaKeywords; | 42 | extern std::unordered_set<std::string> LuaKeywords; |
43 | extern std::unordered_set<std::string> Keywords; | 43 | extern std::unordered_set<std::string> Keywords; |
44 | 44 | ||
45 | class MoonParser { | 45 | class YueParser { |
46 | public: | 46 | public: |
47 | MoonParser(); | 47 | YueParser(); |
48 | 48 | ||
49 | template<class AST> | 49 | template<class AST> |
50 | ParseInfo parse(std::string_view codes) { | 50 | ParseInfo parse(std::string_view codes) { |
@@ -314,4 +314,4 @@ namespace Utils { | |||
314 | void trim(std::string& str); | 314 | void trim(std::string& str); |
315 | }; | 315 | }; |
316 | 316 | ||
317 | } // namespace MoonP | 317 | } // namespace yue |
diff --git a/src/MoonP/moonplus.cpp b/src/yuescript/yuescript.cpp index 9b9689c..9928f4d 100644 --- a/src/MoonP/moonplus.cpp +++ b/src/yuescript/yuescript.cpp | |||
@@ -5,28 +5,28 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of | |||
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
6 | 6 | ||
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
8 | #include "MoonP/moon_compiler.h" | 8 | #include "yuescript/yue_compiler.h" |
9 | 9 | ||
10 | extern "C" { | 10 | extern "C" { |
11 | 11 | ||
12 | #include "lua.h" | 12 | #include "lua.h" |
13 | #include "lauxlib.h" | 13 | #include "lauxlib.h" |
14 | 14 | ||
15 | static const char moonplusCodes[] = | 15 | static const char yuescriptCodes[] = |
16 | #include "MoonP/moonplus.h" | 16 | #include "yuescript/yuescript.h" |
17 | 17 | ||
18 | static void init_moonplus(lua_State* L) { | 18 | static void init_yuescript(lua_State* L) { |
19 | if (luaL_loadbuffer(L, moonplusCodes, sizeof(moonplusCodes) / sizeof(moonplusCodes[0]) - 1, "=(moonplus)") != 0) { | 19 | if (luaL_loadbuffer(L, yuescriptCodes, sizeof(yuescriptCodes) / sizeof(yuescriptCodes[0]) - 1, "=(yuescript)") != 0) { |
20 | std::string err = std::string("failed to load moonplus module.\n") + lua_tostring(L, -1); | 20 | std::string err = std::string("failed to load yuescript module.\n") + lua_tostring(L, -1); |
21 | luaL_error(L, err.c_str()); | 21 | luaL_error(L, err.c_str()); |
22 | } else if (lua_pcall(L, 0, 0, 0) != 0) { | 22 | } else if (lua_pcall(L, 0, 0, 0) != 0) { |
23 | std::string err = std::string("failed to init moonplus module.\n") + lua_tostring(L, -1); | 23 | std::string err = std::string("failed to init yuescript module.\n") + lua_tostring(L, -1); |
24 | luaL_error(L, err.c_str()); | 24 | luaL_error(L, err.c_str()); |
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | static const char stpCodes[] = | 28 | static const char stpCodes[] = |
29 | #include "MoonP/stacktraceplus.h" | 29 | #include "yuescript/stacktraceplus.h" |
30 | 30 | ||
31 | static int init_stacktraceplus(lua_State* L) { | 31 | static int init_stacktraceplus(lua_State* L) { |
32 | if (luaL_loadbuffer(L, stpCodes, sizeof(stpCodes) / sizeof(stpCodes[0]) - 1, "=(stacktraceplus)") != 0) { | 32 | if (luaL_loadbuffer(L, stpCodes, sizeof(stpCodes) / sizeof(stpCodes[0]) - 1, "=(stacktraceplus)") != 0) { |
@@ -39,10 +39,10 @@ static int init_stacktraceplus(lua_State* L) { | |||
39 | return 1; | 39 | return 1; |
40 | } | 40 | } |
41 | 41 | ||
42 | static int moontolua(lua_State* L) { | 42 | static int yuetolua(lua_State* L) { |
43 | size_t size = 0; | 43 | size_t size = 0; |
44 | const char* input = luaL_checklstring(L, 1, &size); | 44 | const char* input = luaL_checklstring(L, 1, &size); |
45 | MoonP::MoonConfig config; | 45 | yue::YueConfig config; |
46 | bool sameModule = false; | 46 | bool sameModule = false; |
47 | if (lua_gettop(L) == 2) { | 47 | if (lua_gettop(L) == 2) { |
48 | luaL_checktype(L, 2, LUA_TTABLE); | 48 | luaL_checktype(L, 2, LUA_TTABLE); |
@@ -84,7 +84,7 @@ static int moontolua(lua_State* L) { | |||
84 | lua_pop(L, 1); | 84 | lua_pop(L, 1); |
85 | } | 85 | } |
86 | std::string s(input, size); | 86 | std::string s(input, size); |
87 | auto result = MoonP::MoonCompiler(L, nullptr, sameModule).compile(s, config); | 87 | auto result = yue::YueCompiler(L, nullptr, sameModule).compile(s, config); |
88 | if (result.codes.empty() && !result.error.empty()) { | 88 | if (result.codes.empty() && !result.error.empty()) { |
89 | lua_pushnil(L); | 89 | lua_pushnil(L); |
90 | } else { | 90 | } else { |
@@ -115,23 +115,23 @@ static int moontolua(lua_State* L) { | |||
115 | return 3; | 115 | return 3; |
116 | } | 116 | } |
117 | 117 | ||
118 | int luaopen_moonp(lua_State* L) { | 118 | int luaopen_yue(lua_State* L) { |
119 | lua_getglobal(L, "package"); // package | 119 | lua_getglobal(L, "package"); // package |
120 | lua_getfield(L, -1, "loaded"); // package loaded | 120 | lua_getfield(L, -1, "loaded"); // package loaded |
121 | lua_createtable(L, 0, 0); // package loaded moonp | 121 | lua_createtable(L, 0, 0); // package loaded yue |
122 | lua_pushcfunction(L, moontolua); // package loaded moonp func | 122 | lua_pushcfunction(L, yuetolua); // package loaded yue func |
123 | lua_setfield(L, -2, "to_lua"); // moonp["to_lua"] = func, package loaded moonp | 123 | lua_setfield(L, -2, "to_lua"); // yue["to_lua"] = func, package loaded yue |
124 | lua_pushlstring(L, &MoonP::version.front(), MoonP::version.size()); // package loaded moonp version | 124 | lua_pushlstring(L, &yue::version.front(), yue::version.size()); // package loaded yue version |
125 | lua_setfield(L, -2, "version"); // moonp["version"] = version, package loaded moonp | 125 | lua_setfield(L, -2, "version"); // yue["version"] = version, package loaded yue |
126 | lua_createtable(L, 0, 0); // package loaded moonp options | 126 | lua_createtable(L, 0, 0); // package loaded yue options |
127 | lua_pushlstring(L, &MoonP::extension.front(), MoonP::extension.size()); // package loaded moonp options ext | 127 | lua_pushlstring(L, &yue::extension.front(), yue::extension.size()); // package loaded yue options ext |
128 | lua_setfield(L, -2, "extension"); // options["extension"] = ext, package loaded moonp options | 128 | lua_setfield(L, -2, "extension"); // options["extension"] = ext, package loaded yue options |
129 | lua_setfield(L, -2, "options"); // moonp["options"] = options, package loaded moonp | 129 | lua_setfield(L, -2, "options"); // yue["options"] = options, package loaded yue |
130 | lua_pushcfunction(L, init_stacktraceplus); // package loaded moonp func1 | 130 | lua_pushcfunction(L, init_stacktraceplus); // package loaded yue func1 |
131 | lua_setfield(L, -2, "load_stacktraceplus"); // moonp["load_stacktraceplus"] = func1, package loaded moonp | 131 | lua_setfield(L, -2, "load_stacktraceplus"); // yue["load_stacktraceplus"] = func1, package loaded yue |
132 | lua_setfield(L, -2, "moonp"); // loaded["moonp"] = moonp, package loaded | 132 | lua_setfield(L, -2, "yue"); // loaded["yue"] = yue, package loaded |
133 | lua_pop(L, 2); // empty | 133 | lua_pop(L, 2); // empty |
134 | init_moonplus(L); | 134 | init_yuescript(L); |
135 | return 0; | 135 | return 0; |
136 | } | 136 | } |
137 | 137 | ||
diff --git a/src/MoonP/moonplus.h b/src/yuescript/yuescript.h index ff82e9f..433751e 100644 --- a/src/MoonP/moonplus.h +++ b/src/yuescript/yuescript.h | |||
@@ -1,6 +1,6 @@ | |||
1 | R"moonplus_codes( | 1 | R"yuescript_codes( |
2 | --[[ | 2 | --[[ |
3 | Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin | 3 | Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin, 2021 |
4 | 4 | ||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | of this software and associated documentation files (the "Software"), to deal | 6 | of this software and associated documentation files (the "Software"), to deal |
@@ -20,17 +20,17 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 | THE SOFTWARE.]] | 21 | THE SOFTWARE.]] |
22 | 22 | ||
23 | local moonp = require("moonp") | 23 | local yue = require("yue") |
24 | local concat, insert, remove = table.concat, table.insert, table.remove | 24 | local concat, insert, remove = table.concat, table.insert, table.remove |
25 | local unpack = unpack or table.unpack | 25 | local unpack = unpack or table.unpack |
26 | local lua = { | 26 | local lua = { |
27 | loadstring = loadstring, | 27 | loadstring = loadstring, |
28 | load = load | 28 | load = load |
29 | } | 29 | } |
30 | local split, get_options, create_moonpath, moon_loader, load_text, moon_call, loadstring, loadfile, dofile, insert_loader, remove_loader, moon_require, find_modulepath | 30 | local split, get_options, create_yuepath, yue_loader, load_text, yue_call, loadstring, loadfile, dofile, insert_loader, remove_loader, yue_require, find_modulepath |
31 | moonp.dirsep = "/" | 31 | yue.dirsep = "/" |
32 | moonp.moon_compiled = { } | 32 | yue.yue_compiled = { } |
33 | moonp.file_exist = function(fname) | 33 | yue.file_exist = function(fname) |
34 | local file = io.open(fname) | 34 | local file = io.open(fname) |
35 | if file then | 35 | if file then |
36 | file:close() | 36 | file:close() |
@@ -39,7 +39,7 @@ moonp.file_exist = function(fname) | |||
39 | return false | 39 | return false |
40 | end | 40 | end |
41 | end | 41 | end |
42 | moonp.read_file = function(fname) | 42 | yue.read_file = function(fname) |
43 | local file, err = io.open(fname) | 43 | local file, err = io.open(fname) |
44 | if not file then | 44 | if not file then |
45 | return nil, err | 45 | return nil, err |
@@ -72,9 +72,9 @@ get_options = function(...) | |||
72 | return { }, ... | 72 | return { }, ... |
73 | end | 73 | end |
74 | end | 74 | end |
75 | create_moonpath = function(package_path) | 75 | create_yuepath = function(package_path) |
76 | local extension = moonp.options.extension | 76 | local extension = yue.options.extension |
77 | local moonpaths | 77 | local yuepaths |
78 | do | 78 | do |
79 | local _accum_0 = { } | 79 | local _accum_0 = { } |
80 | local _len_0 = 1 | 80 | local _len_0 = 1 |
@@ -96,19 +96,19 @@ create_moonpath = function(package_path) | |||
96 | break | 96 | break |
97 | end | 97 | end |
98 | end | 98 | end |
99 | moonpaths = _accum_0 | 99 | yuepaths = _accum_0 |
100 | end | 100 | end |
101 | return concat(moonpaths, ";") | 101 | return concat(yuepaths, ";") |
102 | end | 102 | end |
103 | find_modulepath = function(name) | 103 | find_modulepath = function(name) |
104 | if not package.moonpath then | 104 | if not package.yuepath then |
105 | package.moonpath = create_moonpath(package.path) | 105 | package.yuepath = create_yuepath(package.path) |
106 | end | 106 | end |
107 | local name_path = name:gsub("%.", moonp.dirsep) | 107 | local name_path = name:match("[\\/]") and name or name:gsub("%.", yue.dirsep) |
108 | local file_exist, file_path | 108 | local file_exist, file_path |
109 | for path in package.moonpath:gmatch("[^;]+") do | 109 | for path in package.yuepath:gmatch("[^;]+") do |
110 | file_path = path:gsub("?", name_path) | 110 | file_path = path:gsub("?", name_path) |
111 | file_exist = moonp.file_exist(file_path) | 111 | file_exist = yue.file_exist(file_path) |
112 | if file_exist then | 112 | if file_exist then |
113 | break | 113 | break |
114 | end | 114 | end |
@@ -122,11 +122,11 @@ end | |||
122 | load_text = function(name) | 122 | load_text = function(name) |
123 | local file_path = find_modulepath(name) | 123 | local file_path = find_modulepath(name) |
124 | if file_path then | 124 | if file_path then |
125 | return moonp.read_file(file_path), file_path | 125 | return yue.read_file(file_path), file_path |
126 | end | 126 | end |
127 | return nil, nil | 127 | return nil, nil |
128 | end | 128 | end |
129 | moon_loader = function(name) | 129 | yue_loader = function(name) |
130 | local text, file_path = load_text(name) | 130 | local text, file_path = load_text(name) |
131 | if text then | 131 | if text then |
132 | local res, err = loadstring(text, file_path) | 132 | local res, err = loadstring(text, file_path) |
@@ -135,27 +135,27 @@ moon_loader = function(name) | |||
135 | end | 135 | end |
136 | return res | 136 | return res |
137 | end | 137 | end |
138 | return nil, "Could not find moonp file" | 138 | return nil, "Could not find yue file" |
139 | end | 139 | end |
140 | moon_call = function(f, ...) | 140 | yue_call = function(f, ...) |
141 | local args = { | 141 | local args = { |
142 | ... | 142 | ... |
143 | } | 143 | } |
144 | return xpcall((function() | 144 | return xpcall((function() |
145 | return f(unpack(args)) | 145 | return f(unpack(args)) |
146 | end), function(err) | 146 | end), function(err) |
147 | return moonp.stp.stacktrace(err, 1) | 147 | return yue.stp.stacktrace(err, 1) |
148 | end) | 148 | end) |
149 | end | 149 | end |
150 | loadstring = function(...) | 150 | loadstring = function(...) |
151 | local options, str, chunk_name, mode, env = get_options(...) | 151 | local options, str, chunk_name, mode, env = get_options(...) |
152 | chunk_name = chunk_name or "=(moonplus.loadstring)" | 152 | chunk_name = chunk_name or "=(yuescript.loadstring)" |
153 | local code, err = moonp.to_lua(str, options) | 153 | local code, err = yue.to_lua(str, options) |
154 | if not code then | 154 | if not code then |
155 | return nil, err | 155 | return nil, err |
156 | end | 156 | end |
157 | if chunk_name then | 157 | if chunk_name then |
158 | moonp.moon_compiled["@" .. chunk_name] = code | 158 | yue.yue_compiled["@" .. chunk_name] = code |
159 | end | 159 | end |
160 | return (lua.loadstring or lua.load)(code, chunk_name, unpack({ | 160 | return (lua.loadstring or lua.load)(code, chunk_name, unpack({ |
161 | mode, | 161 | mode, |
@@ -163,7 +163,7 @@ loadstring = function(...) | |||
163 | })) | 163 | })) |
164 | end | 164 | end |
165 | loadfile = function(fname, ...) | 165 | loadfile = function(fname, ...) |
166 | local text = moonp.read_file(fname) | 166 | local text = yue.read_file(fname) |
167 | return loadstring(text, tostring(fname), ...) | 167 | return loadstring(text, tostring(fname), ...) |
168 | end | 168 | end |
169 | dofile = function(...) | 169 | dofile = function(...) |
@@ -174,35 +174,35 @@ insert_loader = function(pos) | |||
174 | if pos == nil then | 174 | if pos == nil then |
175 | pos = 2 | 175 | pos = 2 |
176 | end | 176 | end |
177 | if not package.moonpath then | 177 | if not package.yuepath then |
178 | package.moonpath = create_moonpath(package.path) | 178 | package.yuepath = create_yuepath(package.path) |
179 | end | 179 | end |
180 | local loaders = package.loaders or package.searchers | 180 | local loaders = package.loaders or package.searchers |
181 | for _index_0 = 1, #loaders do | 181 | for _index_0 = 1, #loaders do |
182 | local loader = loaders[_index_0] | 182 | local loader = loaders[_index_0] |
183 | if loader == moon_loader then | 183 | if loader == yue_loader then |
184 | return false | 184 | return false |
185 | end | 185 | end |
186 | end | 186 | end |
187 | insert(loaders, pos, moon_loader) | 187 | insert(loaders, pos, yue_loader) |
188 | return true | 188 | return true |
189 | end | 189 | end |
190 | remove_loader = function() | 190 | remove_loader = function() |
191 | local loaders = package.loaders or package.searchers | 191 | local loaders = package.loaders or package.searchers |
192 | for i, loader in ipairs(loaders) do | 192 | for i, loader in ipairs(loaders) do |
193 | if loader == moon_loader then | 193 | if loader == yue_loader then |
194 | remove(loaders, i) | 194 | remove(loaders, i) |
195 | return true | 195 | return true |
196 | end | 196 | end |
197 | end | 197 | end |
198 | return false | 198 | return false |
199 | end | 199 | end |
200 | moon_require = function(name) | 200 | yue_require = function(name) |
201 | insert_loader() | 201 | insert_loader() |
202 | local success, res = xpcall((function() | 202 | local success, res = xpcall((function() |
203 | return require(name) | 203 | return require(name) |
204 | end), function(err) | 204 | end), function(err) |
205 | local msg = moonp.stp.stacktrace(err, 1) | 205 | local msg = yue.stp.stacktrace(err, 1) |
206 | print(msg) | 206 | print(msg) |
207 | return msg | 207 | return msg |
208 | end) | 208 | end) |
@@ -212,21 +212,21 @@ moon_require = function(name) | |||
212 | return nil | 212 | return nil |
213 | end | 213 | end |
214 | end | 214 | end |
215 | setmetatable(moonp, { | 215 | setmetatable(yue, { |
216 | __index = function(self, key) | 216 | __index = function(self, key) |
217 | if not (key == "stp") then | 217 | if not (key == "stp") then |
218 | return nil | 218 | return nil |
219 | end | 219 | end |
220 | local stp = rawget(moonp, "stp") | 220 | local stp = rawget(yue, "stp") |
221 | if not stp then | 221 | if not stp then |
222 | do | 222 | do |
223 | local _with_0 = moonp.load_stacktraceplus() | 223 | local _with_0 = yue.load_stacktraceplus() |
224 | _with_0.dump_locals = false | 224 | _with_0.dump_locals = false |
225 | _with_0.simplified = true | 225 | _with_0.simplified = true |
226 | stp = _with_0 | 226 | stp = _with_0 |
227 | end | 227 | end |
228 | rawset(moonp, "stp", stp) | 228 | rawset(yue, "stp", stp) |
229 | rawset(moonp, "load_stacktraceplus", nil) | 229 | rawset(yue, "load_stacktraceplus", nil) |
230 | end | 230 | end |
231 | return stp | 231 | return stp |
232 | end, | 232 | end, |
@@ -237,15 +237,15 @@ setmetatable(moonp, { | |||
237 | for k, v in pairs({ | 237 | for k, v in pairs({ |
238 | insert_loader = insert_loader, | 238 | insert_loader = insert_loader, |
239 | remove_loader = remove_loader, | 239 | remove_loader = remove_loader, |
240 | loader = moon_loader, | 240 | loader = yue_loader, |
241 | dofile = dofile, | 241 | dofile = dofile, |
242 | loadfile = loadfile, | 242 | loadfile = loadfile, |
243 | loadstring = loadstring, | 243 | loadstring = loadstring, |
244 | create_moonpath = create_moonpath, | 244 | create_yuepath = create_yuepath, |
245 | find_modulepath = find_modulepath, | 245 | find_modulepath = find_modulepath, |
246 | pcall = moon_call, | 246 | pcall = yue_call, |
247 | require = moon_require | 247 | require = yue_require |
248 | }) do | 248 | }) do |
249 | moonp[k] = v | 249 | yue[k] = v |
250 | end | 250 | end |
251 | )moonplus_codes"; | 251 | )yuescript_codes"; |
diff --git a/yuescript-dev-1.rockspec b/yuescript-dev-1.rockspec new file mode 100644 index 0000000..75835fc --- /dev/null +++ b/yuescript-dev-1.rockspec | |||
@@ -0,0 +1,33 @@ | |||
1 | rockspec_format = "3.0" | ||
2 | package = "Yuescript" | ||
3 | version = "dev-1" | ||
4 | source = { | ||
5 | url = "git+https://github.com/pigpigyyy/yuescript" | ||
6 | } | ||
7 | description = { | ||
8 | summary = "Yuescript is a Moonscript dialect.", | ||
9 | detailed = [[ | ||
10 | Yuescript is a Moonscript dialect. It is derived from Moonscript language 0.5.0 and continuously adopting new features to be more up to date. ]], | ||
11 | homepage = "https://github.com/pigpigyyy/yuescript", | ||
12 | maintainer = "Li Jin <dragon-fly@qq.com>", | ||
13 | labels = {"yuescript","cpp","transpiler","moonscript"}, | ||
14 | license = "MIT" | ||
15 | } | ||
16 | dependencies = { | ||
17 | "lua >= 5.1", | ||
18 | } | ||
19 | build = { | ||
20 | type = "cmake", | ||
21 | variables = { | ||
22 | LUA_INCDIR="$(LUA_INCDIR)", | ||
23 | LUA="$(LUA)", | ||
24 | }, | ||
25 | install = { | ||
26 | lib = { | ||
27 | "build.luarocks/yue.so" | ||
28 | }, | ||
29 | bin = { | ||
30 | "build.luarocks/yue" | ||
31 | } | ||
32 | } | ||
33 | } | ||