aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/MoonP/moon_compiler.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp
index 046bf28..3a326b1 100644
--- a/src/MoonP/moon_compiler.cpp
+++ b/src/MoonP/moon_compiler.cpp
@@ -3017,7 +3017,7 @@ private:
3017 const auto& chainList = chainValue->items.objects(); 3017 const auto& chainList = chainValue->items.objects();
3018 std::string type, codes; 3018 std::string type, codes;
3019 std::tie(type, codes) = expandMacroStr(chainValue); 3019 std::tie(type, codes) = expandMacroStr(chainValue);
3020 std::string targetType(usage == ExpUsage::Common ? "block"sv : "expr"sv); 3020 std::string targetType(usage != ExpUsage::Common || chainList.size() > 2 ? "expr"sv : "block"sv);
3021 if (type != targetType) { 3021 if (type != targetType) {
3022 throw std::logic_error(_info.errorMessage(s("macro type mismatch, "sv) + targetType + s(" expected, got "sv) + type + '.', x)); 3022 throw std::logic_error(_info.errorMessage(s("macro type mismatch, "sv) + targetType + s(" expected, got "sv) + type + '.', x));
3023 } 3023 }
@@ -3026,7 +3026,11 @@ private:
3026 if (codes.empty()) { 3026 if (codes.empty()) {
3027 return {x->new_ptr<Block_t>().get(),std::move(info.codes)}; 3027 return {x->new_ptr<Block_t>().get(),std::move(info.codes)};
3028 } 3028 }
3029 info = _parser.parse<Block_t>(codes); 3029 if (type == "expr"sv) {
3030 info = _parser.parse<Exp_t>(codes);
3031 } else {
3032 info = _parser.parse<Block_t>(codes);
3033 }
3030 } else { 3034 } else {
3031 info = _parser.parse<Exp_t>(codes); 3035 info = _parser.parse<Exp_t>(codes);
3032 } 3036 }
@@ -3042,9 +3046,7 @@ private:
3042 node->m_end.m_col = col; 3046 node->m_end.m_col = col;
3043 return traversal::Continue; 3047 return traversal::Continue;
3044 }); 3048 });
3045 if (usage == ExpUsage::Common) { 3049 if (type == "expr"sv) {
3046 return {info.node,std::move(info.codes)};
3047 } else {
3048 ast_ptr<false, Exp_t> exp; 3050 ast_ptr<false, Exp_t> exp;
3049 exp.set(info.node); 3051 exp.set(info.node);
3050 if (!exp->opValues.empty() || chainList.size() > 2) { 3052 if (!exp->opValues.empty() || chainList.size() > 2) {
@@ -3064,15 +3066,28 @@ private:
3064 exp = x->new_ptr<Exp_t>(); 3066 exp = x->new_ptr<Exp_t>();
3065 exp->value.set(value); 3067 exp->value.set(value);
3066 } 3068 }
3067 return {exp.get(),std::move(info.codes)}; 3069 if (usage == ExpUsage::Common) {
3070 auto expList = x->new_ptr<ExpList_t>();
3071 expList->exprs.push_back(exp);
3072 auto exps = x->new_ptr<ExpListAssign_t>();
3073 exps->expList.set(expList);
3074 auto stmt = x->new_ptr<Statement_t>();
3075 stmt->content.set(exps);
3076 auto block = x->new_ptr<Block_t>();
3077 block->statements.push_back(stmt);
3078 info.node.set(block);
3079 } else {
3080 info.node.set(exp);
3081 }
3068 } 3082 }
3083 return {info.node,std::move(info.codes)};
3069 } 3084 }
3070 3085
3071 void transformChainValue(ChainValue_t* chainValue, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { 3086 void transformChainValue(ChainValue_t* chainValue, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) {
3072 if (isMacroChain(chainValue)) { 3087 if (isMacroChain(chainValue)) {
3073 ast_ptr<false,ast_node> node; 3088 ast_ptr<false,ast_node> node;
3074 std::unique_ptr<input> codes; 3089 std::unique_ptr<input> codes;
3075 std::tie(node,codes) = expandMacro(chainValue, usage); 3090 std::tie(node, codes) = expandMacro(chainValue, usage);
3076 if (usage == ExpUsage::Common) { 3091 if (usage == ExpUsage::Common) {
3077 transformBlock(node.to<Block_t>(), out, usage, assignList); 3092 transformBlock(node.to<Block_t>(), out, usage, assignList);
3078 } else { 3093 } else {
@@ -4983,3 +4998,4 @@ std::tuple<std::string,std::string,GlobalVars> MoonCompiler::compile(std::string
4983} 4998}
4984 4999
4985} // namespace MoonP 5000} // namespace MoonP
5001