diff options
| author | Li Jin <dragon-fly@qq.com> | 2021-10-11 10:59:55 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2021-10-11 10:59:55 +0800 |
| commit | a19b242cbaf53721b20a3163dd06f43e9ef2b487 (patch) | |
| tree | 8d68dd3060ce02b5955b5b8bbbf3cd03bb8a5b6f /src/yuescript/yue_compiler.cpp | |
| parent | b48aa97dd1127ae432ef8d7a4588cee2e1bec12c (diff) | |
| download | yuescript-a19b242cbaf53721b20a3163dd06f43e9ef2b487.tar.gz yuescript-a19b242cbaf53721b20a3163dd06f43e9ef2b487.tar.bz2 yuescript-a19b242cbaf53721b20a3163dd06f43e9ef2b487.zip | |
fix issue #68.
Diffstat (limited to '')
| -rwxr-xr-x | src/yuescript/yue_compiler.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp index 71efa3c..3ff032c 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.8.3"sv; | 63 | const std::string_view version = "0.8.4"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 { |
| @@ -5039,6 +5039,16 @@ private: | |||
| 5039 | } else { | 5039 | } else { |
| 5040 | temp.back() += "{ }"s + nll(classDecl); | 5040 | temp.back() += "{ }"s + nll(classDecl); |
| 5041 | } | 5041 | } |
| 5042 | if (classDecl->mixes) { | ||
| 5043 | auto mixin = getUnusedName("_mixin_"); | ||
| 5044 | auto key = getUnusedName("_key_"); | ||
| 5045 | auto val = getUnusedName("_val_"); | ||
| 5046 | auto mixins = _parser.toString(classDecl->mixes); | ||
| 5047 | _buf << "for "sv << mixin << " in *{"sv << mixins << "}\n"sv; | ||
| 5048 | _buf << "\tfor "sv << key << ',' << val << " in pairs "sv << mixin << ".__base\n"sv; | ||
| 5049 | _buf << "\t\t"sv << baseVar << '[' << key << "]="sv << val << " if not "sv << key << "\\match\"^__\""sv; | ||
| 5050 | transformBlock(toAst<Block_t>(clearBuf(), x), temp, ExpUsage::Common); | ||
| 5051 | } | ||
| 5042 | temp.push_back(indent() + baseVar + ".__index = "s + baseVar + nll(classDecl)); | 5052 | temp.push_back(indent() + baseVar + ".__index = "s + baseVar + nll(classDecl)); |
| 5043 | str_list tmp; | 5053 | str_list tmp; |
| 5044 | if (usage == ExpUsage::Assignment) { | 5054 | if (usage == ExpUsage::Assignment) { |
| @@ -5052,9 +5062,9 @@ private: | |||
| 5052 | if (extend) { | 5062 | if (extend) { |
| 5053 | _buf << indent() << "setmetatable("sv << baseVar << ", "sv << parentVar << ".__base)"sv << nll(classDecl); | 5063 | _buf << indent() << "setmetatable("sv << baseVar << ", "sv << parentVar << ".__base)"sv << nll(classDecl); |
| 5054 | } | 5064 | } |
| 5055 | _buf << indent() << classVar << " = " << globalVar("setmetatable"sv, classDecl) << "({"sv << nll(classDecl); | 5065 | _buf << indent() << classVar << " = "sv << globalVar("setmetatable"sv, classDecl) << "({"sv << nll(classDecl); |
| 5056 | if (!builtins.empty()) { | 5066 | if (!builtins.empty()) { |
| 5057 | _buf << join(builtins) << ","sv << nll(classDecl); | 5067 | _buf << join(builtins) << ',' << nll(classDecl); |
| 5058 | } else { | 5068 | } else { |
| 5059 | if (extend) { | 5069 | if (extend) { |
| 5060 | _buf << indent(1) << "__init = function(self, ...)"sv << nll(classDecl); | 5070 | _buf << indent(1) << "__init = function(self, ...)"sv << nll(classDecl); |
