annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/GlobalSymbolTest.java @ 22425:b39b603e2a1e

Organize imports after rename.
author Christian Humer <christian.humer@oracle.com>
date Wed, 02 Dec 2015 15:21:01 +0100
parents fec62e298245
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
21948
f0fe6f0cbccc Chris pointed out the copyright should reflect the year of file's creation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21890
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 *
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 *
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 *
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * questions.
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 */
22424
fec62e298245 Rename package truffle.api.test to truffle.api to enable package-protected API access for testing.
Christian Humer <christian.humer@oracle.com>
parents: 22335
diff changeset
23 package com.oracle.truffle.api.vm;
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24
22424
fec62e298245 Rename package truffle.api.test to truffle.api to enable package-protected API access for testing.
Christian Humer <christian.humer@oracle.com>
parents: 22335
diff changeset
25 import static com.oracle.truffle.api.vm.ImplicitExplicitExportTest.L3;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
26 import static org.junit.Assert.assertEquals;
22196
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
27 import static org.junit.Assert.assertFalse;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
28 import static org.junit.Assert.assertNotNull;
22196
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
29 import static org.junit.Assert.assertTrue;
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
30
22425
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
31 import java.io.IOException;
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
32 import java.util.List;
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
33
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
34 import org.junit.After;
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
35 import org.junit.Before;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22121
diff changeset
36 import org.junit.Test;
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
37
22425
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
38 import com.oracle.truffle.api.interop.TruffleObject;
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
39 import com.oracle.truffle.api.source.Source;
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
40 import com.oracle.truffle.api.utilities.InstrumentationTestMode;
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
41
22095
643d53cb3147 TruffleVM.Builder.globalSymbol for a way to pass initial configuration parameters to languages
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22070
diff changeset
42 public class GlobalSymbolTest {
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
43
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
44 @Before
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
45 public void before() {
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
46 InstrumentationTestMode.set(true);
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
47 }
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
48
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
49 @After
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
50 public void after() {
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
51 InstrumentationTestMode.set(false);
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
52 }
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22196
diff changeset
53
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
54 @Test
22095
643d53cb3147 TruffleVM.Builder.globalSymbol for a way to pass initial configuration parameters to languages
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22070
diff changeset
55 public void globalSymbolFoundByLanguage() throws IOException {
22312
8322a904a472 Verifying the Truffle/Java interop works OK also in asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22266
diff changeset
56 PolyglotEngine vm = createEngineBuilder().globalSymbol("ahoj", "42").build();
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
57 // @formatter:off
22104
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22096
diff changeset
58 Object ret = vm.eval(
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22096
diff changeset
59 Source.fromText("return=ahoj", "Return").withMimeType(L3)
22121
d045a505c2b3 Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
60 ).get();
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
61 // @formatter:on
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
62 assertEquals("42", ret);
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
63 }
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
64
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
65 @Test
22095
643d53cb3147 TruffleVM.Builder.globalSymbol for a way to pass initial configuration parameters to languages
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22070
diff changeset
66 public void globalSymbolFoundByVMUser() throws IOException {
22312
8322a904a472 Verifying the Truffle/Java interop works OK also in asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22266
diff changeset
67 PolyglotEngine vm = createEngineBuilder().globalSymbol("ahoj", "42").build();
22170
796f0fef110e Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22168
diff changeset
68 PolyglotEngine.Value ret = vm.findGlobalSymbol("ahoj");
22095
643d53cb3147 TruffleVM.Builder.globalSymbol for a way to pass initial configuration parameters to languages
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22070
diff changeset
69 assertNotNull("Symbol found", ret);
22121
d045a505c2b3 Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
70 assertEquals("42", ret.get());
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22046
diff changeset
71 }
22196
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
72
22312
8322a904a472 Verifying the Truffle/Java interop works OK also in asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22266
diff changeset
73 protected PolyglotEngine.Builder createEngineBuilder() {
22335
906a5f6e07cc Giving the PolyglotEngine builder factory method more sensible name.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22313
diff changeset
74 return PolyglotEngine.newBuilder();
22312
8322a904a472 Verifying the Truffle/Java interop works OK also in asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22266
diff changeset
75 }
8322a904a472 Verifying the Truffle/Java interop works OK also in asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22266
diff changeset
76
22196
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
77 @Test
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
78 public void passingArray() throws IOException {
22312
8322a904a472 Verifying the Truffle/Java interop works OK also in asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22266
diff changeset
79 PolyglotEngine vm = createEngineBuilder().globalSymbol("arguments", new Object[]{"one", "two", "three"}).build();
22196
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
80 PolyglotEngine.Value value = vm.findGlobalSymbol("arguments");
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
81 assertFalse("Not instance of array", value.get() instanceof Object[]);
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
82 assertTrue("Instance of TruffleObject", value.get() instanceof TruffleObject);
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
83 List<?> args = value.as(List.class);
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
84 assertNotNull("Can be converted to List", args);
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
85 assertEquals("Three items", 3, args.size());
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
86 assertEquals("one", args.get(0));
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
87 assertEquals("two", args.get(1));
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
88 assertEquals("three", args.get(2));
22313
06c5171e44c8 More tests executed in synchronous and asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22312
diff changeset
89 String[] arr = args.toArray(new String[0]);
06c5171e44c8 More tests executed in synchronous and asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22312
diff changeset
90 assertEquals("Three items in array", 3, arr.length);
06c5171e44c8 More tests executed in synchronous and asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22312
diff changeset
91 assertEquals("one", arr[0]);
06c5171e44c8 More tests executed in synchronous and asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22312
diff changeset
92 assertEquals("two", arr[1]);
06c5171e44c8 More tests executed in synchronous and asynchronous mode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22312
diff changeset
93 assertEquals("three", arr[2]);
22196
364e3f024643 Java objects passed into globalSymbol should be converted into something that Truffle languages can understand - e.g. TruffleObject instances.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
94 }
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
95 }