From 911204c19378ef943c8daec5205fd60caa523321 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 7 Apr 2022 14:45:10 +0800 Subject: change the behavior dealing with class and common table when doing mixin. --- src/yuescript/yue_compiler.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') 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; typedef std::list str_list; -const std::string_view version = "0.10.10"sv; +const std::string_view version = "0.10.11"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -5338,13 +5338,16 @@ private: temp.back() += "{ }"s + nll(classDecl); } if (classDecl->mixes) { + auto item = getUnusedName("_item_"sv); + auto cls = getUnusedName("_cls_"sv); auto mixin = getUnusedName("_mixin_"sv); auto key = getUnusedName("_key_"sv); auto val = getUnusedName("_val_"sv); auto mixins = _parser.toString(classDecl->mixes); - _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; - _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__base or "sv << mixin << '\n'; - _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << baseVar << '[' << key << "]==nil"sv; + _buf << "for "sv << item << " in *{"sv << mixins << "}\n"sv; + _buf << '\t' << cls << ',' << mixin << '=' << item << ".__base?,"sv << item << ".__base or "sv << item << '\n'; + _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << '\n'; + _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << baseVar << '[' << key << "]==nil and (not "sv << cls << " or not "sv << key << "\\match \"^__\")"sv; transformBlock(toAst(clearBuf(), x), temp, ExpUsage::Common); } transformAssignment(toAst(baseVar + ".__index ?\?= "s + baseVar, classDecl), temp); -- cgit v1.2.3-55-g6feb