aboutsummaryrefslogtreecommitdiff
path: root/src/MoonP/moon_compiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MoonP/moon_compiler.cpp')
-rw-r--r--src/MoonP/moon_compiler.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp
index c9d9c78..f79df07 100644
--- a/src/MoonP/moon_compiler.cpp
+++ b/src/MoonP/moon_compiler.cpp
@@ -43,7 +43,7 @@ inline std::string s(std::string_view sv) {
43} 43}
44 44
45const std::string_view version() { 45const std::string_view version() {
46 return "0.3.10"sv; 46 return "0.3.11"sv;
47} 47}
48 48
49// name of table stored in lua registry 49// name of table stored in lua registry
@@ -741,6 +741,7 @@ private:
741 switch (content->getId()) { 741 switch (content->getId()) {
742 case id<Import_t>(): transformImport(static_cast<Import_t*>(content), out); break; 742 case id<Import_t>(): transformImport(static_cast<Import_t*>(content), out); break;
743 case id<While_t>(): transformWhile(static_cast<While_t*>(content), out); break; 743 case id<While_t>(): transformWhile(static_cast<While_t*>(content), out); break;
744 case id<Repeat_t>(): transformRepeat(static_cast<Repeat_t*>(content), out); break;
744 case id<For_t>(): transformFor(static_cast<For_t*>(content), out); break; 745 case id<For_t>(): transformFor(static_cast<For_t*>(content), out); break;
745 case id<ForEach_t>(): transformForEach(static_cast<ForEach_t*>(content), out); break; 746 case id<ForEach_t>(): transformForEach(static_cast<ForEach_t*>(content), out); break;
746 case id<Return_t>(): transformReturn(static_cast<Return_t*>(content), out); break; 747 case id<Return_t>(): transformReturn(static_cast<Return_t*>(content), out); break;
@@ -4251,7 +4252,7 @@ private:
4251 transformAssignment(assignment, temp); 4252 transformAssignment(assignment, temp);
4252 } 4253 }
4253 } 4254 }
4254 if (!scoped && !returnValue) { 4255 if (!with->eop && !scoped && !returnValue) {
4255 pushScope(); 4256 pushScope();
4256 scoped = traversal::Stop == with->body->traverse([&](ast_node* node) { 4257 scoped = traversal::Stop == with->body->traverse([&](ast_node* node) {
4257 if (auto statement = ast_cast<Statement_t>(node)) { 4258 if (auto statement = ast_cast<Statement_t>(node)) {
@@ -4297,7 +4298,14 @@ private:
4297 } 4298 }
4298 } 4299 }
4299 _withVars.push(withVar); 4300 _withVars.push(withVar);
4300 transformBody(with->body, temp, ExpUsage::Common); 4301 if (with->eop) {
4302 auto ifNode = x->new_ptr<If_t>();
4303 ifNode->nodes.push_back(toAst<IfCond_t>(withVar + s("~=nil"sv), x));
4304 ifNode->nodes.push_back(with->body);
4305 transformIf(ifNode, temp, ExpUsage::Common);
4306 } else {
4307 transformBody(with->body, temp, ExpUsage::Common);
4308 }
4301 _withVars.pop(); 4309 _withVars.pop();
4302 if (assignList) { 4310 if (assignList) {
4303 auto assignment = x->new_ptr<ExpListAssign_t>(); 4311 auto assignment = x->new_ptr<ExpListAssign_t>();
@@ -4914,6 +4922,18 @@ private:
4914 out.push_back(clearBuf()); 4922 out.push_back(clearBuf());
4915 } 4923 }
4916 4924
4925 void transformRepeat(Repeat_t* repeat, str_list& out) {
4926 str_list temp;
4927 pushScope();
4928 transformLoopBody(repeat->body, temp, Empty, ExpUsage::Common);
4929 transformExp(repeat->condition, temp, ExpUsage::Closure);
4930 popScope();
4931 _buf << indent() << "repeat"sv << nll(repeat);
4932 _buf << temp.front();
4933 _buf << indent() << "until "sv << temp.back() << nlr(repeat);
4934 out.push_back(clearBuf());
4935 }
4936
4917 void transformSwitch(Switch_t* switchNode, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) { 4937 void transformSwitch(Switch_t* switchNode, str_list& out, ExpUsage usage, ExpList_t* assignList = nullptr) {
4918 str_list temp; 4938 str_list temp;
4919 if (usage == ExpUsage::Closure) { 4939 if (usage == ExpUsage::Closure) {