mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
fix while(true) inside a while(true) loop. #43
This commit is contained in:
parent
f5edb58911
commit
062e2aeb47
@ -202,7 +202,7 @@ class BranchManager {
|
||||
if( loop == null ) {
|
||||
loop = new ParsedBlock( JavaBlockOperator.LOOP, start, 0, start, parsedBlock.lineNumber );
|
||||
loops.put( start, loop );
|
||||
// if a condition form outside of the loop point inside the loop then it must be conditional return and a jump to the loop condition.
|
||||
// if a condition before the loop points to a position within the loop, then it must be a conditional return and a jump to the loop condition.
|
||||
for( int n = b - 1; n >= 0; n-- ) {
|
||||
ParsedBlock prevBlock = parsedOperations.get( n );
|
||||
switch( prevBlock.op ) {
|
||||
@ -221,8 +221,20 @@ class BranchManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
loop.nextPosition = parsedBlock.startPosition; // Jump position for Continue
|
||||
loop.endPosition = parsedBlock.nextPosition;
|
||||
if( loop.endPosition < parsedBlock.nextPosition ) {
|
||||
int nextPosition = parsedBlock.startPosition; // Jump position for Continue
|
||||
int endPosition = parsedBlock.nextPosition;
|
||||
// if a condition behind the loop points to a position inside the loop, the loop must be extended to avoid overlapping blocks.
|
||||
for( int n = b + 1; n < parsedOperations.size(); n++ ) {
|
||||
ParsedBlock block = parsedOperations.get( n );
|
||||
if( block.startPosition > endPosition && endPosition > block.endPosition && block.endPosition > start ) {
|
||||
nextPosition = block.startPosition;
|
||||
endPosition = block.nextPosition;
|
||||
}
|
||||
}
|
||||
loop.nextPosition = nextPosition; // Jump position for Continue
|
||||
loop.endPosition = endPosition;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new WasmException( "Unimplemented loop code operation: " + parsedBlock.op, parsedBlock.lineNumber );
|
||||
|
@ -59,6 +59,7 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
addParam( list, script, "whileLoopInElseAfterReturn" );
|
||||
addParam( list, script, "whileLoopAfterIfWithReturn" );
|
||||
addParam( list, script, "whileLoopInsideLoop" );
|
||||
addParam( list, script, "whileTrueInsideWhileTrue" );
|
||||
addParam( list, script, "forLoop" );
|
||||
addParam( list, script, "conditionalOperator" );
|
||||
addParam( list, script, "conditionalOperator2" );
|
||||
@ -489,6 +490,26 @@ public class ControlFlowOperators extends AbstractBaseTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Export
|
||||
static int whileTrueInsideWhileTrue() {
|
||||
int sw = 1;
|
||||
while( true ) {
|
||||
if( sw != 1 ) {
|
||||
sw++;
|
||||
break;
|
||||
}
|
||||
sub: while( true ) {
|
||||
if( sw == 1 ) {
|
||||
sw = 2;
|
||||
break;
|
||||
} else {
|
||||
sw = 17;
|
||||
}
|
||||
}
|
||||
}
|
||||
return sw;
|
||||
}
|
||||
|
||||
@Export
|
||||
static int forLoop() {
|
||||
int a = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user