Skip to content

Commit

Permalink
Removed useless do block in with.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Sep 28, 2024
1 parent 7575fe0 commit d6d29a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ bin
tup/*.lua
tup/t/*.lua
Yuescript.vcxproj.user
spec/generated
spec/generated
.release_time
40 changes: 21 additions & 19 deletions src/yuescript/yue_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = {
"close"s // Lua 5.4
};

const std::string_view version = "0.25.2"sv;
const std::string_view version = "0.25.3"sv;
const std::string_view extension = "yue"sv;

class CompileError : public std::logic_error {
Expand Down Expand Up @@ -9154,33 +9154,35 @@ class YueCompilerImpl {
transformIf(ifNode, temp, ExpUsage::Common);
} else {
bool transformed = false;
if (auto block = with->body.as<Block_t>()) {
if (!block->statements.empty()) {
Statement_t* stmt = static_cast<Statement_t*>(block->statements.back());
if (assignList || returnValue) {
if (auto block = with->body.as<Block_t>()) {
if (!block->statements.empty()) {
Statement_t* stmt = static_cast<Statement_t*>(block->statements.back());
if (stmt->content.is<Return_t>()) {
auto newBlock = with->body->new_ptr<Block_t>();
newBlock->statements.dup(block->statements);
newBlock->statements.pop_back();
transform_plain_body(newBlock, temp, ExpUsage::Common);
auto newBody = stmt->new_ptr<Body_t>();
newBody->content.set(stmt);
auto doNode = stmt->new_ptr<Do_t>();
doNode->body.set(newBody);
transformDo(doNode, temp, ExpUsage::Common);
transformed = true;
}
}
} else {
auto stmt = with->body.to<Statement_t>();
if (stmt->content.is<Return_t>()) {
auto newBlock = with->body->new_ptr<Block_t>();
newBlock->statements.dup(block->statements);
newBlock->statements.pop_back();
transform_plain_body(newBlock, temp, ExpUsage::Common);
auto newBody = stmt->new_ptr<Body_t>();
newBody->content.set(stmt);
auto doNode = stmt->new_ptr<Do_t>();
doNode->body.set(newBody);
transformDo(doNode, temp, ExpUsage::Common);
temp.back().insert(0, indent());
transformed = true;
}
}
} else {
auto stmt = with->body.to<Statement_t>();
if (stmt->content.is<Return_t>()) {
auto newBody = stmt->new_ptr<Body_t>();
newBody->content.set(stmt);
auto doNode = stmt->new_ptr<Do_t>();
doNode->body.set(newBody);
transformDo(doNode, temp, ExpUsage::Common);
temp.back().insert(0, indent());
transformed = true;
}
}
if (!transformed) {
transform_plain_body(with->body, temp, ExpUsage::Common);
Expand Down

0 comments on commit d6d29a4

Please sign in to comment.