enable lambda expressions

This commit is contained in:
Volker Berlin 2021-01-24 18:57:00 +01:00
parent 740b7a8c19
commit bb97efa1f5
3 changed files with 19 additions and 20 deletions

View File

@ -874,7 +874,6 @@ public abstract class WasmCodeBuilder {
StructType interfaceType = (StructType)parser.next();
StructType type = types.lambdaType( typeName, interfaceType, name, interfaceMethodName );
addStructInstruction( StructOperator.NEW_DEFAULT, typeName, null, javaCodePos, lineNumber );
throw new WasmException( "InvokeDynamic/Lambda is not supported.", lineNumber );
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2017 - 2020 Volker Berlin (i-net software)
* Copyright 2017 - 2021 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,9 +19,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -97,19 +95,4 @@ public class RuntimeErrors {
@Export
native static float function();
}
@Test
public void lambdas() throws IOException {
compileErrorTest( "InvokeDynamic/Lambda is not supported.", LambdaMethod.class );
}
static class LambdaMethod {
private static int counter;
@Export
static void runnable() {
Runnable run = () -> counter++;
run.run();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018 - 2020 Volker Berlin (i-net software)
* Copyright 2018 - 2021 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,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.function.IntSupplier;
import java.util.function.IntUnaryOperator;
import org.junit.ClassRule;
import org.junit.runners.Parameterized.Parameters;
@ -66,6 +68,9 @@ public class StructsNonGC extends AbstractBaseTest {
addParam( list, script, "intClassName" );
addParam( list, script, "getComponentType" );
addParam( list, script, "branchWithObjectResult" );
addParam( list, script, "callParameterFromCondition" );
addParam( list, script, "lambda0" );
addParam( list, script, "lambda1" );
}
rule.setTestParameters( list );
return list;
@ -243,6 +248,18 @@ public class StructsNonGC extends AbstractBaseTest {
Abc abc = new Abc();
return abc.add( 42, abc == null ? 7 : 13 );
}
@Export
static int lambda0() {
IntSupplier val = () -> 42;
return val.getAsInt();
}
@Export
static int lambda1() {
IntUnaryOperator val = (x) -> x;
return val.applyAsInt( 13 );
}
}
interface TestDefault {