aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-10-11 10:59:55 +0800
committerLi Jin <dragon-fly@qq.com>2021-10-11 10:59:55 +0800
commita19b242cbaf53721b20a3163dd06f43e9ef2b487 (patch)
tree8d68dd3060ce02b5955b5b8bbbf3cd03bb8a5b6f
parentb48aa97dd1127ae432ef8d7a4588cee2e1bec12c (diff)
downloadyuescript-a19b242cbaf53721b20a3163dd06f43e9ef2b487.tar.gz
yuescript-a19b242cbaf53721b20a3163dd06f43e9ef2b487.tar.bz2
yuescript-a19b242cbaf53721b20a3163dd06f43e9ef2b487.zip
fix issue #68.
-rw-r--r--spec/inputs/class.yue2
-rwxr-xr-xsrc/yuescript/yue_ast.h3
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp16
-rwxr-xr-xsrc/yuescript/yue_parser.cpp3
4 files changed, 19 insertions, 5 deletions
diff --git a/spec/inputs/class.yue b/spec/inputs/class.yue
index ca8b58c..ea971e1 100644
--- a/spec/inputs/class.yue
+++ b/spec/inputs/class.yue
@@ -229,4 +229,6 @@ do
229class extends lapis.Application 229class extends lapis.Application
230 "/": => json: { status: true } 230 "/": => json: { status: true }
231 231
232class A using B, C, D
233
232nil 234nil
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index 6c9953c..38da1fa 100755
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -623,8 +623,9 @@ AST_END(ClassBlock)
623AST_NODE(ClassDecl) 623AST_NODE(ClassDecl)
624 ast_ptr<false, Assignable_t> name; 624 ast_ptr<false, Assignable_t> name;
625 ast_ptr<false, Exp_t> extend; 625 ast_ptr<false, Exp_t> extend;
626 ast_ptr<false, ExpList_t> mixes;
626 ast_ptr<false, ClassBlock_t> body; 627 ast_ptr<false, ClassBlock_t> body;
627 AST_MEMBER(ClassDecl, &name, &extend, &body) 628 AST_MEMBER(ClassDecl, &name, &extend, &mixes, &body)
628AST_END(ClassDecl) 629AST_END(ClassDecl)
629 630
630AST_NODE(global_values) 631AST_NODE(global_values)
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
61typedef std::list<std::string> str_list; 61typedef std::list<std::string> str_list;
62 62
63const std::string_view version = "0.8.3"sv; 63const std::string_view version = "0.8.4"sv;
64const std::string_view extension = "yue"sv; 64const std::string_view extension = "yue"sv;
65 65
66class YueCompilerImpl { 66class 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);
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp
index 0b7f79e..6ecd369 100755
--- a/src/yuescript/yue_parser.cpp
+++ b/src/yuescript/yue_parser.cpp
@@ -492,7 +492,8 @@ YueParser::YueParser() {
492 ClassDecl = 492 ClassDecl =
493 key("class") >> not_(expr(':')) >> 493 key("class") >> not_(expr(':')) >>
494 -Assignable >> 494 -Assignable >>
495 -(key("extends") >> PreventIndent >> ensure(Exp, PopIndent)) >> 495 -(key("extends") >> PreventIndent >> ensure(Exp, PopIndent)) >>
496 -(key("using") >> PreventIndent >> ensure(ExpList, PopIndent)) >>
496 -ClassBlock; 497 -ClassBlock;
497 498
498 global_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); 499 global_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow));