aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--spec/outputs/class.lua7
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp11
2 files changed, 11 insertions, 7 deletions
diff --git a/spec/outputs/class.lua b/spec/outputs/class.lua
index 3ec92d1..8f7c126 100644
--- a/spec/outputs/class.lua
+++ b/spec/outputs/class.lua
@@ -1096,9 +1096,10 @@ do
1096 } 1096 }
1097 } 1097 }
1098 for _index_0 = 1, #_list_0 do 1098 for _index_0 = 1, #_list_0 do
1099 local _mixin_0 = _list_0[_index_0] 1099 local _item_0 = _list_0[_index_0]
1100 for _key_0, _val_0 in pairs(_mixin_0.__base or _mixin_0) do 1100 local _cls_0, _mixin_0 = (_item_0.__base ~= nil), _item_0.__base or _item_0
1101 if _base_0[_key_0] == nil then 1101 for _key_0, _val_0 in pairs(_mixin_0) do
1102 if _base_0[_key_0] == nil and (not _cls_0 or not _key_0:match("^__")) then
1102 _base_0[_key_0] = _val_0 1103 _base_0[_key_0] = _val_0
1103 end 1104 end
1104 end 1105 end
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);