Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed May 29, 2020
1 parent 4868cb1 commit a600f1a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions CSharp.lua/LuaSyntaxNodeTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4599,6 +4599,22 @@ public override LuaSyntaxNode VisitContinueStatement(ContinueStatementSyntax nod
return new LuaContinueAdapterStatementSyntax(isWithinTry);
}

private static bool IsLastBreakStatement(LuaStatementSyntax lastStatement) {
if (lastStatement == LuaBreakStatementSyntax.Instance) {
return true;
}

if (lastStatement is LuaContinueAdapterStatementSyntax) {
return true;
}

if (lastStatement is LuaLabeledStatement labeledStatement && IsLastBreakStatement(labeledStatement.Statement)) {
return true;
}

return false;
}

private void VisitLoopBody(StatementSyntax bodyStatement, LuaBlockSyntax block) {
bool hasContinue = IsContinueExists(bodyStatement);
if (hasContinue) {
Expand All @@ -4608,12 +4624,10 @@ private void VisitLoopBody(StatementSyntax bodyStatement, LuaBlockSyntax block)
LuaRepeatStatementSyntax repeatStatement = new LuaRepeatStatementSyntax(LuaIdentifierNameSyntax.One);
WriteStatementOrBlock(bodyStatement, repeatStatement.Body);
var lastStatement = repeatStatement.Body.Statements.Last();
if (lastStatement is LuaBaseReturnStatementSyntax || (IsLuaClassic && lastStatement == LuaBreakStatementSyntax.Instance)) {
LuaBlockStatementSyntax returnBlock = new LuaBlockStatementSyntax();
returnBlock.Statements.Add(lastStatement);
repeatStatement.Body.Statements[repeatStatement.Body.Statements.Count - 1] = returnBlock;
bool isLastFinal = lastStatement is LuaBaseReturnStatementSyntax || IsLastBreakStatement(lastStatement);
if (!isLastFinal) {
repeatStatement.Body.Statements.Add(continueIdentifier.Assignment(LuaIdentifierNameSyntax.True));
}
repeatStatement.Body.Statements.Add(continueIdentifier.Assignment(LuaIdentifierNameSyntax.True));
block.Statements.Add(repeatStatement);
LuaIfStatementSyntax IfStatement = new LuaIfStatementSyntax(new LuaPrefixUnaryExpressionSyntax(continueIdentifier, LuaSyntaxNode.Tokens.Not));
IfStatement.Body.Statements.Add(LuaBreakStatementSyntax.Instance);
Expand Down
2 changes: 1 addition & 1 deletion test/__bin/Lua/lua/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end
local luaVersions = {
"Lua5.3",
"LuaJIT-2.0.2",
"MoonJIT-2.2.0"
-- "MoonJIT-2.2.0"
}

local function compile(arg)
Expand Down

0 comments on commit a600f1a

Please sign in to comment.