aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-02-17 12:17:44 +0800
committerLi Jin <dragon-fly@qq.com>2021-02-17 12:17:44 +0800
commitf19ba3e5ba71adf8092252bac21381ba75870792 (patch)
treee6b04ce0a636ab21759a56f7e4f6752038b001b9
parent7066392d1c974065181d95d93274136dcd625d43 (diff)
downloadyuescript-f19ba3e5ba71adf8092252bac21381ba75870792.tar.gz
yuescript-f19ba3e5ba71adf8092252bac21381ba75870792.tar.bz2
yuescript-f19ba3e5ba71adf8092252bac21381ba75870792.zip
fix macro issue.
-rw-r--r--spec/inputs/macro.yue7
-rw-r--r--src/yuescript/yue_compiler.cpp7
2 files changed, 9 insertions, 5 deletions
diff --git a/spec/inputs/macro.yue b/spec/inputs/macro.yue
index eb3cf75..6a255fe 100644
--- a/spec/inputs/macro.yue
+++ b/spec/inputs/macro.yue
@@ -226,17 +226,18 @@ $chainB(
226) 226)
227 227
228macro chainC = (...)-> 228macro chainC = (...)->
229 import "moonp" as {:to_lua} 229 import "yue" as {:to_lua}
230 callable = nil 230 callable = nil
231 config = { 231 config = {
232 implicit_return_root: false 232 implicit_return_root: false
233 reserve_line_number: false 233 reserve_line_number: false
234 } 234 }
235 for item in *{...} 235 for item in *{...}
236 itemCodes = to_lua(item,config)\gsub '%s*$',''
236 if callable? 237 if callable?
237 callable = "#{callable}:#{to_lua(item,config)\gsub '%s*$',''}" 238 callable = "#{callable}:#{itemCodes}"
238 else 239 else
239 callable = to_lua(item,config)\gsub '%s*$','' 240 callable = itemCodes
240 { 241 {
241 codes: $showMacro "chainC", callable 242 codes: $showMacro "chainC", callable
242 type: "lua" 243 type: "lua"
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 22311f4..4917e4e 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
61const std::string_view version = "0.6.5"sv; 61const std::string_view version = "0.6.6"sv;
62const std::string_view extension = "yue"sv; 62const std::string_view extension = "yue"sv;
63 63
64class YueCompilerImpl { 64class YueCompilerImpl {
@@ -593,6 +593,7 @@ private:
593 case id<ExpList_t>(): return static_cast<Exp_t*>(exportNode->target.to<ExpList_t>()->exprs.back()); 593 case id<ExpList_t>(): return static_cast<Exp_t*>(exportNode->target.to<ExpList_t>()->exprs.back());
594 } 594 }
595 } 595 }
596 return nullptr;
596 } 597 }
597 case id<Local_t>(): { 598 case id<Local_t>(): {
598 if (auto localValues = static_cast<Local_t*>(stmt->content.get())->item.as<local_values_t>()) { 599 if (auto localValues = static_cast<Local_t*>(stmt->content.get())->item.as<local_values_t>()) {
@@ -600,6 +601,7 @@ private:
600 return static_cast<Exp_t*>(expList->exprs.back()); 601 return static_cast<Exp_t*>(expList->exprs.back());
601 } 602 }
602 } 603 }
604 return nullptr;
603 } 605 }
604 case id<Global_t>(): { 606 case id<Global_t>(): {
605 if (auto globalValues = static_cast<Global_t*>(stmt->content.get())->item.as<global_values_t>()) { 607 if (auto globalValues = static_cast<Global_t*>(stmt->content.get())->item.as<global_values_t>()) {
@@ -607,6 +609,7 @@ private:
607 return static_cast<Exp_t*>(expList->exprs.back()); 609 return static_cast<Exp_t*>(expList->exprs.back());
608 } 610 }
609 } 611 }
612 return nullptr;
610 } 613 }
611 } 614 }
612 return nullptr; 615 return nullptr;
@@ -3318,7 +3321,7 @@ private:
3318 throw std::logic_error(_info.errorMessage(s("failed to expand macro: "sv) + err, x)); 3321 throw std::logic_error(_info.errorMessage(s("failed to expand macro: "sv) + err, x));
3319 } // cur success res 3322 } // cur success res
3320 if (lua_toboolean(L, -2) == 0) { 3323 if (lua_toboolean(L, -2) == 0) {
3321 std::string err = lua_tostring(L, -2); 3324 std::string err = lua_tostring(L, -1);
3322 throw std::logic_error(_info.errorMessage(s("failed to expand macro: "sv) + err, x)); 3325 throw std::logic_error(_info.errorMessage(s("failed to expand macro: "sv) + err, x));
3323 } 3326 }
3324 lua_remove(L, -2); // cur res 3327 lua_remove(L, -2); // cur res