aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-04-07 14:45:10 +0800
committerLi Jin <dragon-fly@qq.com>2022-04-07 14:45:10 +0800
commit911204c19378ef943c8daec5205fd60caa523321 (patch)
tree2f625b7b7c5f809376117e6e9d4cf1085efeb3da /src
parent599a89c2194110592bff2d91ecf9304be3e8ba4d (diff)
downloadyuescript-911204c19378ef943c8daec5205fd60caa523321.tar.gz
yuescript-911204c19378ef943c8daec5205fd60caa523321.tar.bz2
yuescript-911204c19378ef943c8daec5205fd60caa523321.zip
change the behavior dealing with class and common table when doing mixin.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 936809f..e7da2dd 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -60,7 +60,7 @@ using namespace parserlib;
60 60
61typedef std::list<std::string> str_list; 61typedef std::list<std::string> str_list;
62 62
63const std::string_view version = "0.10.10"sv; 63const std::string_view version = "0.10.11"sv;
64const std::string_view extension = "yue"sv; 64const std::string_view extension = "yue"sv;
65 65
66class YueCompilerImpl { 66class YueCompilerImpl {
@@ -5338,13 +5338,16 @@ private:
5338 temp.back() += "{ }"s + nll(classDecl); 5338 temp.back() += "{ }"s + nll(classDecl);
5339 } 5339 }
5340 if (classDecl->mixes) { 5340 if (classDecl->mixes) {
5341 auto item = getUnusedName("_item_"sv);
5342 auto cls = getUnusedName("_cls_"sv);
5341 auto mixin = getUnusedName("_mixin_"sv); 5343 auto mixin = getUnusedName("_mixin_"sv);
5342 auto key = getUnusedName("_key_"sv); 5344 auto key = getUnusedName("_key_"sv);
5343 auto val = getUnusedName("_val_"sv); 5345 auto val = getUnusedName("_val_"sv);
5344 auto mixins = _parser.toString(classDecl->mixes); 5346 auto mixins = _parser.toString(classDecl->mixes);
5345 _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; 5347 _buf << "for "sv << item << " in *{"sv << mixins << "}\n"sv;
5346 _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__base or "sv << mixin << '\n'; 5348 _buf << '\t' << cls << ',' << mixin << '=' << item << ".__base?,"sv << item << ".__base or "sv << item << '\n';
5347 _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << baseVar << '[' << key << "]==nil"sv; 5349 _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << '\n';
5350 _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << baseVar << '[' << key << "]==nil and (not "sv << cls << " or not "sv << key << "\\match \"^__\")"sv;
5348 transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common); 5351 transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common);
5349 } 5352 }
5350 transformAssignment(toAst<ExpListAssign_t>(baseVar + ".__index ?\?= "s + baseVar, classDecl), temp); 5353 transformAssignment(toAst<ExpListAssign_t>(baseVar + ".__index ?\?= "s + baseVar, classDecl), temp);