From 49f44f799b39dcc4ffe69502638108398732f8df Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 6 Apr 2022 17:21:36 +0800 Subject: adding support for fixing issue #85. --- src/yuescript/yue_compiler.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 3720915..3394f1f 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.9"sv; +const std::string_view version = "0.10.10"sv; const std::string_view extension = "yue"sv; class YueCompilerImpl { @@ -5268,7 +5268,7 @@ private: if (clsDecl) { std::string clsName; bool newDefined = false; - std::tie(clsName,newDefined) = defineClassVariable(clsDecl->name); + std::tie(clsName, newDefined) = defineClassVariable(clsDecl->name); if (newDefined) varDefs.push_back(clsName); } } @@ -5337,17 +5337,17 @@ private: } else { temp.back() += "{ }"s + nll(classDecl); } + transformAssignment(toAst(baseVar + ".__index ?\?= "s + baseVar, classDecl), temp); if (classDecl->mixes) { - auto mixin = getUnusedName("_mixin_"); - auto key = getUnusedName("_key_"); - auto val = getUnusedName("_val_"); + 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\n"sv; - _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if not "sv << key << "\\match\"^__\" and "sv << baseVar << '[' << key << "] == nil"sv; + _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << key << "~=\"__class\""sv; transformBlock(toAst(clearBuf(), x), temp, ExpUsage::Common); } - temp.push_back(indent() + baseVar + ".__index = "s + baseVar + nll(classDecl)); str_list tmp; if (usage == ExpUsage::Assignment) { auto assign = x->new_ptr(); @@ -5366,7 +5366,7 @@ private: } else { if (extend) { _buf << indent(1) << "__init = function(self, ...)"sv << nll(classDecl); - _buf << indent(2) << "return _class_0.__parent.__init(self, ...)"sv << nll(classDecl); + _buf << indent(2) << "return "sv << classVar << ".__parent.__init(self, ...)"sv << nll(classDecl); _buf << indent(1) << "end,"sv << nll(classDecl); } else { _buf << indent(1) << "__init = function() end,"sv << nll(classDecl); -- cgit v1.2.3-55-g6feb