diff options
author | Li Jin <dragon-fly@qq.com> | 2022-04-06 17:21:36 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-04-06 17:21:57 +0800 |
commit | 49f44f799b39dcc4ffe69502638108398732f8df (patch) | |
tree | 0e9a3ee00aac9f8fdd7ae1c69e9a21ca358d1f34 /src | |
parent | 1f1af19560054b47935151f298ff06ff2cad5ef9 (diff) | |
download | yuescript-49f44f799b39dcc4ffe69502638108398732f8df.tar.gz yuescript-49f44f799b39dcc4ffe69502638108398732f8df.tar.bz2 yuescript-49f44f799b39dcc4ffe69502638108398732f8df.zip |
adding support for fixing issue #85.
Diffstat (limited to 'src')
-rwxr-xr-x | src/yuescript/yue_compiler.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
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; | |||
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.9"sv; | 63 | const std::string_view version = "0.10.10"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 { |
@@ -5268,7 +5268,7 @@ private: | |||
5268 | if (clsDecl) { | 5268 | if (clsDecl) { |
5269 | std::string clsName; | 5269 | std::string clsName; |
5270 | bool newDefined = false; | 5270 | bool newDefined = false; |
5271 | std::tie(clsName,newDefined) = defineClassVariable(clsDecl->name); | 5271 | std::tie(clsName, newDefined) = defineClassVariable(clsDecl->name); |
5272 | if (newDefined) varDefs.push_back(clsName); | 5272 | if (newDefined) varDefs.push_back(clsName); |
5273 | } | 5273 | } |
5274 | } | 5274 | } |
@@ -5337,17 +5337,17 @@ private: | |||
5337 | } else { | 5337 | } else { |
5338 | temp.back() += "{ }"s + nll(classDecl); | 5338 | temp.back() += "{ }"s + nll(classDecl); |
5339 | } | 5339 | } |
5340 | transformAssignment(toAst<ExpListAssign_t>(baseVar + ".__index ?\?= "s + baseVar, classDecl), temp); | ||
5340 | if (classDecl->mixes) { | 5341 | if (classDecl->mixes) { |
5341 | auto mixin = getUnusedName("_mixin_"); | 5342 | auto mixin = getUnusedName("_mixin_"sv); |
5342 | auto key = getUnusedName("_key_"); | 5343 | auto key = getUnusedName("_key_"sv); |
5343 | auto val = getUnusedName("_val_"); | 5344 | auto val = getUnusedName("_val_"sv); |
5344 | auto mixins = _parser.toString(classDecl->mixes); | 5345 | auto mixins = _parser.toString(classDecl->mixes); |
5345 | _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; | 5346 | _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; |
5346 | _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__base\n"sv; | 5347 | _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__base\n"sv; |
5347 | _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if not "sv << key << "\\match\"^__\" and "sv << baseVar << '[' << key << "] == nil"sv; | 5348 | _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if "sv << key << "~=\"__class\""sv; |
5348 | transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common); | 5349 | transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common); |
5349 | } | 5350 | } |
5350 | temp.push_back(indent() + baseVar + ".__index = "s + baseVar + nll(classDecl)); | ||
5351 | str_list tmp; | 5351 | str_list tmp; |
5352 | if (usage == ExpUsage::Assignment) { | 5352 | if (usage == ExpUsage::Assignment) { |
5353 | auto assign = x->new_ptr<Assign_t>(); | 5353 | auto assign = x->new_ptr<Assign_t>(); |
@@ -5366,7 +5366,7 @@ private: | |||
5366 | } else { | 5366 | } else { |
5367 | if (extend) { | 5367 | if (extend) { |
5368 | _buf << indent(1) << "__init = function(self, ...)"sv << nll(classDecl); | 5368 | _buf << indent(1) << "__init = function(self, ...)"sv << nll(classDecl); |
5369 | _buf << indent(2) << "return _class_0.__parent.__init(self, ...)"sv << nll(classDecl); | 5369 | _buf << indent(2) << "return "sv << classVar << ".__parent.__init(self, ...)"sv << nll(classDecl); |
5370 | _buf << indent(1) << "end,"sv << nll(classDecl); | 5370 | _buf << indent(1) << "end,"sv << nll(classDecl); |
5371 | } else { | 5371 | } else { |
5372 | _buf << indent(1) << "__init = function() end,"sv << nll(classDecl); | 5372 | _buf << indent(1) << "__init = function() end,"sv << nll(classDecl); |