diff options
author | Li Jin <dragon-fly@qq.com> | 2022-04-07 14:45:10 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-04-07 14:45:10 +0800 |
commit | 911204c19378ef943c8daec5205fd60caa523321 (patch) | |
tree | 2f625b7b7c5f809376117e6e9d4cf1085efeb3da /src | |
parent | 599a89c2194110592bff2d91ecf9304be3e8ba4d (diff) | |
download | yuescript-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-x | src/yuescript/yue_compiler.cpp | 11 |
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 | ||
61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
62 | 62 | ||
63 | const std::string_view version = "0.10.10"sv; | 63 | const std::string_view version = "0.10.11"sv; |
64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
65 | 65 | ||
66 | class YueCompilerImpl { | 66 | class 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); |