From f61b96675547c8bf40c7f646e3766f4139efd927 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Fri, 22 Jan 2021 17:53:34 +0800 Subject: fix issue #36 --- spec/inputs/funcs.mp | 1 + spec/inputs/macro.mp | 2 +- src/MoonP/moon_compiler.cpp | 11 +++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/inputs/funcs.mp b/spec/inputs/funcs.mp index 4176e33..0e45ff1 100644 --- a/spec/inputs/funcs.mp +++ b/spec/inputs/funcs.mp @@ -46,6 +46,7 @@ _ = (x = if something then yeah else no) -> something = (hello=100, world=(x=[[yeah cool]])-> print "eat rice") -> print hello +_ = () => _ = (x, y) => _ = (@x, @y) => _ = (x=1) => diff --git a/spec/inputs/macro.mp b/spec/inputs/macro.mp index fafa522..be88a3f 100644 --- a/spec/inputs/macro.mp +++ b/spec/inputs/macro.mp @@ -110,7 +110,7 @@ do a += $get_inner_hygienic! print a -macro lua lua = (codes)-> "#{codes}" +macro lua lua = (codes)-> codes x = 0 diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index d49cf14..e8649ae 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp @@ -53,7 +53,7 @@ inline std::string s(std::string_view sv) { return std::string(sv); } -const std::string_view version = "0.4.22"sv; +const std::string_view version = "0.4.23"sv; const std::string_view extension = "mp"sv; class MoonCompilerImpl { @@ -1877,9 +1877,12 @@ private: auto& args = *it; auto& initArgs = *(++it); auto& bodyCodes = *(++it); - _buf << "function("sv << - (isFatArrow ? s("self, "sv) : Empty) << - args << ')'; + _buf << "function("sv; + if (isFatArrow) { + _buf << "self"sv; + if (!args.empty()) _buf << ", "sv; + } + _buf << args << ')'; if (!initArgs.empty() || !bodyCodes.empty()) { _buf << nlr(argsDef) << initArgs << bodyCodes; popScope(); -- cgit v1.2.3-55-g6feb