diff --git a/src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java b/src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java index bef9a1a..2d10e96 100644 --- a/src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java +++ b/src/de/inetsoftware/jwebassembly/module/LocaleVariableManager.java @@ -191,6 +191,9 @@ class LocaleVariableManager { } resetAddVar( null, i ); } + + // in Eclipse for lambda expression only the method parameters has an entry in the variable table. But the not define parameter of the lambda constructor come before. + Arrays.sort( variables, 0, size ); } /** @@ -455,7 +458,7 @@ class LocaleVariableManager { /** * The state of a single local variable slot. */ - private static class Variable { + private static class Variable implements Comparable { private AnyType valueType; @@ -477,5 +480,13 @@ class LocaleVariableManager { public boolean matchCodePosition( int codePosition ) { return startPos <= codePosition && codePosition <= endPos; } + + /** + * {@inheritDoc} + */ + @Override + public int compareTo( Variable o ) { + return Integer.compare( idx, o.idx ); + } } } diff --git a/src/de/inetsoftware/jwebassembly/module/TypeManager.java b/src/de/inetsoftware/jwebassembly/module/TypeManager.java index 7538aaa..380d51a 100644 --- a/src/de/inetsoftware/jwebassembly/module/TypeManager.java +++ b/src/de/inetsoftware/jwebassembly/module/TypeManager.java @@ -1,5 +1,5 @@ /* - Copyright 2018 - 2021 Volker Berlin (i-net software) + Copyright 2018 - 2022 Volker Berlin (i-net software) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -1208,6 +1208,13 @@ public class TypeManager { } watParser.reset( null, null, sig.iterator() ); + // first add the values from the Lambda constructor which is saves in the syntetic class + for( int i = 0; i < paramFields.size(); i++ ) { + codebuilder.addLoadStoreInstruction( LambdaType.this, true, 0, 0, -1 ); + codebuilder.addStructInstruction( StructOperator.GET, name, paramFields.get( i ), 0, -1 ); + } + + // forward the parameter from the current call without the THIS parameter because the call lambda method is static for( int i = 1; i < sig.size(); i++ ) { AnyType anyType = sig.get( i ); if( anyType == null ) { @@ -1216,11 +1223,6 @@ public class TypeManager { codebuilder.addLoadStoreInstruction( anyType, true, i, 0, -1 ); } - for( int i = 0; i < paramFields.size(); i++ ) { - codebuilder.addLoadStoreInstruction( LambdaType.this, true, 0, 0, -1 ); - codebuilder.addStructInstruction( StructOperator.GET, name, paramFields.get( i ), 0, -1 ); - } - codebuilder.addCallInstruction( syntheticLambdaFunctionName, false, 0, -1 ); return watParser; } diff --git a/test/de/inetsoftware/jwebassembly/runtime/StructsNonGC.java b/test/de/inetsoftware/jwebassembly/runtime/StructsNonGC.java index a51f86f..91b50df 100644 --- a/test/de/inetsoftware/jwebassembly/runtime/StructsNonGC.java +++ b/test/de/inetsoftware/jwebassembly/runtime/StructsNonGC.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 - 2021 Volker Berlin (i-net software) + * Copyright 2018 - 2022 Volker Berlin (i-net software) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; +import java.util.function.DoubleUnaryOperator; import java.util.function.IntSupplier; import java.util.function.IntUnaryOperator; @@ -315,11 +316,11 @@ public class StructsNonGC extends AbstractBaseTest { } @Export - static int lambda3() { + static double lambda3() { int v1 = 42; int v2 = 7; - IntUnaryOperator val = (x) -> x + v2 + v1; - return val.applyAsInt( 13 ); + DoubleUnaryOperator val = (x) -> x * v2 + v1; + return val.applyAsDouble( 13 ); } @Export