diff options
Diffstat (limited to '')
| -rw-r--r-- | CHANGELOG.md | 59 | ||||
| -rw-r--r-- | src/yuescript/yue_compiler.cpp | 16 |
2 files changed, 57 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index bf8a24e..3e1be05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
| @@ -1,15 +1,40 @@ | |||
| 1 | # Changelog | 1 | # Changelog |
| 2 | 2 | ||
| 3 | The implementation for original Moonscript language 0.5.0 can be found in the `0.5.0` branch of MoonPlus. The Moonscript with fixes and new features is in the master branch of MoonPlus. Here are the changelogs for each MoonPlus version. | 3 | The implementation for original Moonscript language 0.5.0 can be found in the `0.5.0` branch of Yuescript. The Moonscript with fixes and new features is in the main branch of Yuescript. Here are the changelogs for each Yuescript version. |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | ## v0.6.6 | ||
| 7 | |||
| 8 | ### Fixed Issues | ||
| 9 | |||
| 10 | * Simplify macro syntax. Macro function can either return a code string or a config table. | ||
| 11 | |||
| 12 | ```moonscript | ||
| 13 | macro local = (var)-> "global *" | ||
| 14 | |||
| 15 | $local x | ||
| 16 | x = 1 | ||
| 17 | y = 2 | ||
| 18 | z = 3 | ||
| 19 | |||
| 20 | macro local = (var)-> | ||
| 21 | { | ||
| 22 | codes: "local #{var}" | ||
| 23 | type: "lua" | ||
| 24 | locals: {var} | ||
| 25 | } | ||
| 26 | |||
| 27 | $local y | ||
| 28 | y = 1 | ||
| 29 | ``` | ||
| 30 | |||
| 31 | * Change Yuescript file extension to '.yue' because some of the Moonscript syntax are no longer supported and some codes written in Yuescript syntax won't be accepted by Moonscript compiler. | ||
| 32 | * | ||
| 6 | 33 | ||
| 7 | ## v0.4.16 | 34 | ## v0.4.16 |
| 8 | 35 | ||
| 9 | ### Fixed Issues | 36 | ### Fixed Issues |
| 10 | 37 | ||
| 11 | * Change MoonPlus file extension to '.mp' because some of the Moonscript syntax are no longer supported and some codes written in MoonPlus syntax won't be accepted by Moonscript compiler. | ||
| 12 | |||
| 13 | * Remove support for escape new line symbol, binary operator expressions can now be written multiline without escape new line symbol. | 38 | * Remove support for escape new line symbol, binary operator expressions can now be written multiline without escape new line symbol. |
| 14 | 39 | ||
| 15 | * Fix an issue when extending class without name. | 40 | * Fix an issue when extending class without name. |
| @@ -37,7 +62,7 @@ The implementation for original Moonscript language 0.5.0 can be found in the `0 | |||
| 37 | okay = yeah, | 62 | okay = yeah, |
| 38 | fine = alright | 63 | fine = alright |
| 39 | }) | 64 | }) |
| 40 | -- compiled in fixed MoonPlus compiler | 65 | -- compiled in fixed Yuescript compiler |
| 41 | -- get one table as argument | 66 | -- get one table as argument |
| 42 | another(hello, one, two, three, four, { | 67 | another(hello, one, two, three, four, { |
| 43 | yeah = man, | 68 | yeah = man, |
| @@ -163,13 +188,13 @@ The implementation for original Moonscript language 0.5.0 can be found in the `0 | |||
| 163 | 188 | ||
| 164 | * Add variadic arguments declaration check. | 189 | * Add variadic arguments declaration check. |
| 165 | 190 | ||
| 166 | * `moonp` now supports recursively traversing any directory and compiling any moon file in the path. | 191 | * `yue` now supports recursively traversing any directory and compiling any moon file in the path. |
| 167 | 192 | ||
| 168 | * `moonp` now supports REPL functions for Moonscript. | 193 | * `yue` now supports REPL functions for Moonscript. |
| 169 | 194 | ||
| 170 | * Add `useSpaceOverTab` function to `moonp`. | 195 | * Add `useSpaceOverTab` function to `yue`. |
| 171 | 196 | ||
| 172 | * Add Lua codes minify function to `moonp`. | 197 | * Add Lua codes minify function to `yue`. |
| 173 | 198 | ||
| 174 | 199 | ||
| 175 | 200 | ||
| @@ -186,14 +211,14 @@ The implementation for original Moonscript language 0.5.0 can be found in the `0 | |||
| 186 | * Add macro functions. | 211 | * Add macro functions. |
| 187 | ```Moonscript | 212 | ```Moonscript |
| 188 | -- file 'macro.mp' | 213 | -- file 'macro.mp' |
| 189 | export macro block config = (debugging = true)-> | 214 | export macro config = (debugging = true)-> |
| 190 | global debugMode = debugging == "true" | 215 | global debugMode = debugging == "true" |
| 191 | "" | 216 | "" |
| 192 | 217 | ||
| 193 | export macro block asserts = (cond)-> | 218 | export macro asserts = (cond)-> |
| 194 | debugMode and "assert #{cond}" or "" | 219 | debugMode and "assert #{cond}" or "" |
| 195 | 220 | ||
| 196 | export macro expr assert = (cond)-> | 221 | export macro assert = (cond)-> |
| 197 | debugMode and "assert #{cond}" or "#{cond}" | 222 | debugMode and "assert #{cond}" or "#{cond}" |
| 198 | 223 | ||
| 199 | $config! | 224 | $config! |
| @@ -201,7 +226,7 @@ $config! | |||
| 201 | -- file 'main.mp' | 226 | -- file 'main.mp' |
| 202 | import 'macro' as {:$config, :$assert, :$asserts} | 227 | import 'macro' as {:$config, :$assert, :$asserts} |
| 203 | 228 | ||
| 204 | macro expr and = (...)-> "#{ table.concat {...}, ' and ' }" | 229 | macro and = (...)-> "#{ table.concat {...}, ' and ' }" |
| 205 | 230 | ||
| 206 | $asserts item ~= nil | 231 | $asserts item ~= nil |
| 207 | $config false | 232 | $config false |
| @@ -243,11 +268,11 @@ From original Moonscript compiler: | |||
| 243 | ### Added Features | 268 | ### Added Features |
| 244 | 269 | ||
| 245 | * Allow value lists in for and local statement to be multiline. | 270 | * Allow value lists in for and local statement to be multiline. |
| 246 | * `moonp` now compiles source files in multiple threads to speed up compilation. | 271 | * `yue` now compiles source files in multiple threads to speed up compilation. |
| 247 | * Add placeholder support for backcall operator. | 272 | * Add placeholder support for backcall operator. |
| 248 | * Add placeholder support for backcall statement. | 273 | * Add placeholder support for backcall statement. |
| 249 | * Add fat arrow support for backcall statement. | 274 | * Add fat arrow support for backcall statement. |
| 250 | * Add option to compile MoonPlus as a Lua C lib. Got MoonPlus released to `Luarocks`. | 275 | * Add option to compile Yuescript as a Lua C lib. Got Yuescript released to `Luarocks`. |
| 251 | * Move old `export` statement functions to `global` statement to match the `local` statement. | 276 | * Move old `export` statement functions to `global` statement to match the `local` statement. |
| 252 | * Change `export` statement behavier to support module management. Moon codes with `export` statement can not explicit return values in root scope. And codes with `export default` can export only one value as the module content. Use cases: | 277 | * Change `export` statement behavier to support module management. Moon codes with `export` statement can not explicit return values in root scope. And codes with `export default` can export only one value as the module content. Use cases: |
| 253 | ```Moonscript | 278 | ```Moonscript |
| @@ -459,7 +484,7 @@ in original Moonscript compiles to: | |||
| 459 | ```Lua | 484 | ```Lua |
| 460 | local f | 485 | local f |
| 461 | f = function(x) | 486 | f = function(x) |
| 462 | local _ = "abc", 123 -- report error in MoonPlus | 487 | local _ = "abc", 123 -- report error in Yuescript |
| 463 | return x + 1 | 488 | return x + 1 |
| 464 | end | 489 | end |
| 465 | ``` | 490 | ``` |
| @@ -491,7 +516,7 @@ tree:addChild((function() | |||
| 491 | end)()) | 516 | end)()) |
| 492 | 517 | ||
| 493 | -- codes added with a break will still run | 518 | -- codes added with a break will still run |
| 494 | local _ -- report error in MoonPlus instead of creating | 519 | local _ -- report error in Yuescript instead of creating |
| 495 | do -- an anonymous function to bind the object method | 520 | do -- an anonymous function to bind the object method |
| 496 | local _base_0 = tree | 521 | local _base_0 = tree |
| 497 | local _fn_0 = _base_0.addChild | 522 | local _fn_0 = _base_0.addChild |
| @@ -506,7 +531,7 @@ end | |||
| 506 | ``` | 531 | ``` |
| 507 | 532 | ||
| 508 | * Reusing variables which helps generate reduced Lua codes. | 533 | * Reusing variables which helps generate reduced Lua codes. |
| 509 | For example, MoonPlus will generate codes from: | 534 | For example, Yuescript will generate codes from: |
| 510 | 535 | ||
| 511 | ```Moonscript | 536 | ```Moonscript |
| 512 | with leaf | 537 | with leaf |
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 4917e4e..7be0c84 100644 --- a/src/yuescript/yue_compiler.cpp +++ b/src/yuescript/yue_compiler.cpp | |||
| @@ -58,7 +58,7 @@ inline std::string s(std::string_view sv) { | |||
| 58 | return std::string(sv); | 58 | return std::string(sv); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | const std::string_view version = "0.6.6"sv; | 61 | const std::string_view version = "0.6.7"sv; |
| 62 | const std::string_view extension = "yue"sv; | 62 | const std::string_view extension = "yue"sv; |
| 63 | 63 | ||
| 64 | class YueCompilerImpl { | 64 | class YueCompilerImpl { |
| @@ -3460,6 +3460,20 @@ private: | |||
| 3460 | info.node.set(exp); | 3460 | info.node.set(exp); |
| 3461 | } | 3461 | } |
| 3462 | } | 3462 | } |
| 3463 | if (auto block = info.node.as<Block_t>()) { | ||
| 3464 | for (auto stmt_ : block->statements.objects()) { | ||
| 3465 | auto stmt = static_cast<Statement_t*>(stmt_); | ||
| 3466 | if (auto global = stmt->content.as<Global_t>()) { | ||
| 3467 | if (global->item.is<global_op_t>()) { | ||
| 3468 | throw std::logic_error(_info.errorMessage(s("can not insert global statement with wildcard operator from macro"sv), x)); | ||
| 3469 | } | ||
| 3470 | } else if (auto local = stmt->content.as<Local_t>()) { | ||
| 3471 | if (local->item.is<local_flag_t>()) { | ||
| 3472 | throw std::logic_error(_info.errorMessage(s("can not insert local statement with wildcard operator from macro"sv), x)); | ||
| 3473 | } | ||
| 3474 | } | ||
| 3475 | } | ||
| 3476 | } | ||
| 3463 | return {info.node, std::move(info.codes), Empty, std::move(localVars)}; | 3477 | return {info.node, std::move(info.codes), Empty, std::move(localVars)}; |
| 3464 | } else { | 3478 | } else { |
| 3465 | if (!isBlock) throw std::logic_error(_info.errorMessage(s("failed to expanded empty macro as expr"sv), x)); | 3479 | if (!isBlock) throw std::logic_error(_info.errorMessage(s("failed to expanded empty macro as expr"sv), x)); |
