Fixed: #2519 AS1/2 avoid multi-level loops in cases where possible

This commit is contained in:
Jindra Petřík
2025-08-22 19:29:04 +02:00
parent fc3b4a378e
commit 4b48b8408a
4 changed files with 94 additions and 1 deletions

View File

@@ -3287,7 +3287,13 @@ public class Graph {
System.err.println("Adding break");
}
makeAllCommands(ret, stack);
ret.add(new BreakItem(dialect, null, localData.lineStartInstruction, el.id));
BreakItem br = new BreakItem(dialect, null, localData.lineStartInstruction, el.id);
if (part.start >= code.size() - 1) {
br.isScriptEnd = true;
}
ret.add(br);
return ret;
}
if (el.loopPreContinue == part) {

View File

@@ -44,6 +44,11 @@ public class BreakItem extends GraphTargetItem {
*/
private boolean labelRequired;
/**
* Is placed at end of the script (or function)
*/
public boolean isScriptEnd = false;
/**
* Constructor.
*
@@ -59,6 +64,10 @@ public class BreakItem extends GraphTargetItem {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
if (isScriptEnd) {
writer.append("return");
return writer;
}
writer.append("break");
if (writer instanceof NulWriter) {
NulWriter nulWriter = (NulWriter) writer;