Search in sources :

Example 16 with ProxyExecutable

use of org.graalvm.polyglot.proxy.ProxyExecutable in project sulong by graalvm.

the class LLVMInteropTest method test015.

@Test
public void test015() {
    try (Runner runner = new Runner("interop015")) {
        runner.export(new ProxyExecutable() {

            @Override
            public Object execute(Value... t) {
                Assert.assertEquals("argument count", 2, t.length);
                return t[0].asDouble() + t[1].asDouble();
            }
        }, "foreign");
        Assert.assertEquals(42, runner.run(), 0.1);
    }
}
Also used : ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) Value(org.graalvm.polyglot.Value) BoxedTestValue(com.oracle.truffle.llvm.test.interop.values.BoxedTestValue) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) Test(org.junit.Test)

Example 17 with ProxyExecutable

use of org.graalvm.polyglot.proxy.ProxyExecutable in project sulong by graalvm.

the class TypeCheckTest method data.

@Parameters(name = "{0}")
public static Collection<Object[]> data() {
    ArrayList<Object[]> tests = new ArrayList<>();
    tests.add(new Object[] { "boolean", true });
    tests.add(new Object[] { "byte", (byte) 5 });
    tests.add(new Object[] { "short", (short) 5 });
    tests.add(new Object[] { "int", 5 });
    tests.add(new Object[] { "boxedint", new BoxedTestValue(42) });
    tests.add(new Object[] { "long", 5L });
    tests.add(new Object[] { "big_long", Long.MAX_VALUE });
    tests.add(new Object[] { "float", 5.7f });
    tests.add(new Object[] { "small_float", Float.MIN_VALUE });
    tests.add(new Object[] { "big_float", Float.MAX_VALUE });
    tests.add(new Object[] { "double", 5.7 });
    tests.add(new Object[] { "small_double", Double.MIN_VALUE });
    tests.add(new Object[] { "big_double", Double.MAX_VALUE });
    tests.add(new Object[] { "string", "Hello, World!" });
    tests.add(new Object[] { "null", null });
    tests.add(new Object[] { "object", ProxyObject.fromMap(new HashMap<>()) });
    tests.add(new Object[] { "array", ProxyArray.fromArray() });
    tests.add(new Object[] { "executable", new ProxyExecutable() {

        @Override
        public Object execute(Value... arguments) {
            return null;
        }
    } });
    return tests;
}
Also used : ProxyExecutable(org.graalvm.polyglot.proxy.ProxyExecutable) BoxedTestValue(com.oracle.truffle.llvm.test.interop.values.BoxedTestValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Value(org.graalvm.polyglot.Value) BoxedTestValue(com.oracle.truffle.llvm.test.interop.values.BoxedTestValue) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

Value (org.graalvm.polyglot.Value)17 ProxyExecutable (org.graalvm.polyglot.proxy.ProxyExecutable)17 Test (org.junit.Test)14 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)10 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)10 BoxedTestValue (com.oracle.truffle.llvm.test.interop.values.BoxedTestValue)9 Context (org.graalvm.polyglot.Context)6 PolyglotException (org.graalvm.polyglot.PolyglotException)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 StackFrame (org.graalvm.polyglot.PolyglotException.StackFrame)3 List (java.util.List)2 Source (org.graalvm.polyglot.Source)2 After (org.junit.After)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Assert.assertNotSame (org.junit.Assert.assertNotSame)2