mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Lambdas with parameters had one value too many on the stack.
This commit is contained in:
parent
82cf49aa41
commit
50ca777dc3
@ -995,18 +995,22 @@ public abstract class WasmCodeBuilder {
|
|||||||
int idx = StackInspector.findInstructionThatPushValue( instructions, paramCount, javaCodePos ).idx;
|
int idx = StackInspector.findInstructionThatPushValue( instructions, paramCount, javaCodePos ).idx;
|
||||||
int pos = instructions.size();
|
int pos = instructions.size();
|
||||||
addStructInstruction( StructOperator.NEW_DEFAULT, lambdaTypeName, null, javaCodePos, lineNumber );
|
addStructInstruction( StructOperator.NEW_DEFAULT, lambdaTypeName, null, javaCodePos, lineNumber );
|
||||||
if( !options.useGC() ) {
|
boolean extraDup = !options.useGC();
|
||||||
|
if( extraDup ) {
|
||||||
|
// Bringing forward the DUP operation of the parameter loop to get a slot
|
||||||
addDupInstruction( false, javaCodePos, lineNumber );
|
addDupInstruction( false, javaCodePos, lineNumber );
|
||||||
}
|
}
|
||||||
int slot = ((WasmLocalInstruction)findInstructionThatPushValue( 1, javaCodePos )).getSlot();
|
int slot = ((WasmLocalInstruction)findInstructionThatPushValue( 1, javaCodePos )).getSlot();
|
||||||
|
|
||||||
// move the creating of the lambda instance before the parameters on the stack
|
// move the creating of the lambda instance before the parameters on the stack
|
||||||
Collections.rotate( instructions.subList( idx, instructions.size() ), idx - pos );
|
Collections.rotate( instructions.subList( idx, instructions.size() ), idx - pos );
|
||||||
|
|
||||||
for( int i = 0; i < paramCount; i++ ) {
|
for( int i = 0; i < paramCount; i++ ) {
|
||||||
NamedStorageType field = paramFields.get( i );
|
NamedStorageType field = paramFields.get( i );
|
||||||
idx = StackInspector.findInstructionThatPushValue( instructions, paramCount - i, javaCodePos ).idx;
|
if( i > 0 || !extraDup ) {
|
||||||
instructions.add( idx, new WasmLoadStoreInstruction( VariableOperator.get, slot, localVariables, javaCodePos, lineNumber ) );
|
idx = StackInspector.findInstructionThatPushValue( instructions, paramCount - i, javaCodePos ).idx;
|
||||||
|
instructions.add( idx, new WasmLoadStoreInstruction( VariableOperator.get, slot, localVariables, javaCodePos, lineNumber ) );
|
||||||
|
}
|
||||||
pos = instructions.size();
|
pos = instructions.size();
|
||||||
idx = paramCount - i - 1;
|
idx = paramCount - i - 1;
|
||||||
idx = idx == 0 ? pos : StackInspector.findInstructionThatPushValue( instructions, idx, javaCodePos ).idx;
|
idx = idx == 0 ? pos : StackInspector.findInstructionThatPushValue( instructions, idx, javaCodePos ).idx;
|
||||||
|
@ -77,6 +77,7 @@ public class StructsNonGC extends AbstractBaseTest {
|
|||||||
addParam( list, script, "lambda2" );
|
addParam( list, script, "lambda2" );
|
||||||
addParam( list, script, "lambda3" );
|
addParam( list, script, "lambda3" );
|
||||||
addParam( list, script, "lambdaWithInstanceAccess" );
|
addParam( list, script, "lambdaWithInstanceAccess" );
|
||||||
|
addParam( list, script, "lambdaInsideTryCatch" );
|
||||||
addParam( list, script, "simpleName_Object" );
|
addParam( list, script, "simpleName_Object" );
|
||||||
addParam( list, script, "simpleName_Anonymous" );
|
addParam( list, script, "simpleName_Anonymous" );
|
||||||
addParam( list, script, "simpleName_Array" );
|
addParam( list, script, "simpleName_Array" );
|
||||||
@ -349,6 +350,19 @@ public class StructsNonGC extends AbstractBaseTest {
|
|||||||
return val.getAsInt();
|
return val.getAsInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Export
|
||||||
|
public static int lambdaInsideTryCatch() {
|
||||||
|
int result = 17;
|
||||||
|
int field = 13;
|
||||||
|
try {
|
||||||
|
IntSupplier val = () -> field;
|
||||||
|
result = val.getAsInt();
|
||||||
|
} catch( Throwable ex ) {
|
||||||
|
result = 42;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Export
|
@Export
|
||||||
static boolean isPrimitive_int() {
|
static boolean isPrimitive_int() {
|
||||||
return int.class.isPrimitive();
|
return int.class.isPrimitive();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user