Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/PolyglotEngine.java @ 22172:b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 21 Sep 2015 10:55:36 +0200 |
parents | 41c5f430ce37 |
children | dcb70d90c11d |
rev | line source |
---|---|
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1 /* |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
4 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
10 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
16 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
20 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
23 * questions. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
24 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.vm; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
26 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.TruffleLanguage.Env; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
29 import com.oracle.truffle.api.TruffleLanguage.Registration; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.debug.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 import com.oracle.truffle.api.impl.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.truffle.api.instrument.*; |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
33 import com.oracle.truffle.api.interop.TruffleObject; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
34 import com.oracle.truffle.api.interop.java.JavaInterop; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.truffle.api.source.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
36 import java.io.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
37 import java.net.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
38 import java.nio.file.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
39 import java.util.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
40 import java.util.concurrent.CountDownLatch; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
41 import java.util.concurrent.Executor; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
42 import java.util.logging.*; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
43 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
44 /** |
22171
41c5f430ce37
Using buildNew as that more directly indicates the use of Builder pattern
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
45 * Gate way into the world of {@link TruffleLanguage Truffle languages}. {@link #buildNew() |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
46 * Instantiate} your own portal into the isolated, multi language system with all the registered |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
47 * languages ready for your use. A {@link PolyglotEngine} runs inside of a <em>JVM</em>, there can |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
48 * however be multiple instances (some would say tenants) of {@link PolyglotEngine} running next to |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
49 * each other in a single <em>JVM</em> with a complete mutual isolation. There is 1:N mapping |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
50 * between <em>JVM</em> and {@link PolyglotEngine}. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
51 * <p> |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
52 * It would not be correct to think of a {@link PolyglotEngine} as a runtime for a single |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
53 * {@link TruffleLanguage Truffle language} (Ruby, Python, R, C, JavaScript, etc.) either. |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
54 * {@link PolyglotEngine} can host as many of Truffle languages as {@link Registration registered on |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
55 * a class path} of your <em>JVM</em> application. {@link PolyglotEngine} orchestrates these |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
56 * languages, manages exchange of objects and calls among them. While it may happen that there is |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
57 * just one activated language inside of a {@link PolyglotEngine}, the greatest strength of |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
58 * {@link PolyglotEngine} is in inter-operability between all Truffle languages. There is 1:N |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
59 * mapping between {@link PolyglotEngine} and {@link TruffleLanguage Truffle language |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
60 * implementations}. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
61 * <p> |
22171
41c5f430ce37
Using buildNew as that more directly indicates the use of Builder pattern
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
62 * Use {@link #buildNew()} to create new isolated portal ready for execution of various languages. |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
63 * All the languages in a single portal see each other exported global symbols and can cooperate. |
22171
41c5f430ce37
Using buildNew as that more directly indicates the use of Builder pattern
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
64 * Use {@link #buildNew()} multiple times to create different, isolated portal environment |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
65 * completely separated from each other. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
66 * <p> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
67 * Once instantiated use {@link #eval(java.net.URI)} with a reference to a file or URL or directly |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
68 * pass code snippet into the virtual machine via {@link #eval(java.lang.String, java.lang.String)}. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
69 * Support for individual languages is initialized on demand - e.g. once a file of certain MIME type |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
70 * is about to be processed, its appropriate engine (if found), is initialized. Once an engine gets |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
71 * initialized, it remains so, until the virtual machine isn't garbage collected. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
72 * <p> |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
73 * The engine is single-threaded and tries to enforce that. It records the thread it has been |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
74 * {@link Builder#build() created} by and checks that all subsequent calls are coming from the same |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
75 * thread. There is 1:1 mapping between {@link PolyglotEngine} and a thread that can tell it what to |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
76 * do. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
77 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
78 @SuppressWarnings("rawtypes") |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
79 public class PolyglotEngine { |
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
80 static final Logger LOG = Logger.getLogger(PolyglotEngine.class.getName()); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
81 private static final SPIAccessor SPI = new SPIAccessor(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
82 private final Thread initThread; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
83 private final Executor executor; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
84 private final Map<String, Language> langs; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
85 private final Reader in; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
86 private final Writer err; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
87 private final Writer out; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
88 private final EventConsumer<?>[] handlers; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
89 private final Map<String, Object> globals; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
90 private Debugger debugger; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
91 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
92 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
93 * Private & temporary only constructor. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
94 */ |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
95 PolyglotEngine() { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
96 this.initThread = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
97 this.in = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
98 this.err = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
99 this.out = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
100 this.langs = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
101 this.handlers = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
102 this.globals = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
103 this.executor = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
104 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
105 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
106 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
107 * Real constructor used from the builder. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
108 */ |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
109 PolyglotEngine(Executor executor, Map<String, Object> globals, Writer out, Writer err, Reader in, EventConsumer<?>[] handlers) { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
110 this.executor = executor; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
111 this.out = out; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
112 this.err = err; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
113 this.in = in; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
114 this.handlers = handlers; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
115 this.initThread = Thread.currentThread(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
116 this.globals = new HashMap<>(globals); |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
117 Map<String, Language> map = new HashMap<>(); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
118 for (Map.Entry<String, LanguageCache> en : LanguageCache.languages().entrySet()) { |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
119 map.put(en.getKey(), createLanguage(en)); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
120 } |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
121 this.langs = map; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
122 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
123 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
124 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
125 * Creation of new Truffle virtual machine. Use the {@link Builder} methods to configure your |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
126 * virtual machine and then create one using {@link Builder#build()}: |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
127 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
128 * <pre> |
22171
41c5f430ce37
Using buildNew as that more directly indicates the use of Builder pattern
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
129 * {@link PolyglotEngine} vm = {@link PolyglotEngine}.{@link PolyglotEngine#buildNew() buildNew()} |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
130 * .{@link Builder#stdOut(java.io.Writer) stdOut}({@link Writer yourWriter}) |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
131 * .{@link Builder#stdErr(java.io.Writer) stdErr}({@link Writer yourWriter}) |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
132 * .{@link Builder#stdIn(java.io.Reader) stdIn}({@link Reader yourReader}) |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
133 * .{@link Builder#build() build()}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
134 * </pre> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
135 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
136 * It searches for {@link Registration languages registered} in the system class loader and |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
137 * makes them available for later evaluation via |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
138 * {@link #eval(java.lang.String, java.lang.String)} methods. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
139 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
140 * @return new, isolated virtual machine with pre-registered languages |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
141 */ |
22171
41c5f430ce37
Using buildNew as that more directly indicates the use of Builder pattern
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
142 public static PolyglotEngine.Builder buildNew() { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
143 // making Builder non-static inner class is a |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
144 // nasty trick to avoid the Builder class to appear |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
145 // in Javadoc next to PolyglotEngine class |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
146 PolyglotEngine vm = new PolyglotEngine(); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
147 return vm.new Builder(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
148 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
149 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
150 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
151 * Builder for a new {@link PolyglotEngine}. Call various configuration methods in a chain and |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
152 * at the end create new {@link PolyglotEngine virtual machine}: |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
153 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
154 * <pre> |
22171
41c5f430ce37
Using buildNew as that more directly indicates the use of Builder pattern
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
155 * {@link PolyglotEngine} vm = {@link PolyglotEngine}.{@link PolyglotEngine#buildNew() buildNew()} |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
156 * .{@link Builder#stdOut(java.io.Writer) stdOut}({@link Writer yourWriter}) |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
157 * .{@link Builder#stdErr(java.io.Writer) stdErr}({@link Writer yourWriter}) |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
158 * .{@link Builder#stdIn(java.io.Reader) stdIn}({@link Reader yourReader}) |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
159 * .{@link Builder#build() build()}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
160 * </pre> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
161 */ |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
162 public class Builder { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
163 private Writer out; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
164 private Writer err; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
165 private Reader in; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
166 private final List<EventConsumer<?>> handlers = new ArrayList<>(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
167 private final Map<String, Object> globals = new HashMap<>(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
168 private Executor executor; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
169 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
170 Builder() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
171 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
172 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
173 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
174 * Changes the default output for languages running in <em>to be created</em> |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
175 * {@link PolyglotEngine virtual machine}. The default is to use {@link System#out}. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
176 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
177 * @param w the writer to use as output |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
178 * @return instance of this builder |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
179 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
180 public Builder stdOut(Writer w) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
181 out = w; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
182 return this; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
183 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
184 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
185 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
186 * Changes the error output for languages running in <em>to be created</em> |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
187 * {@link PolyglotEngine virtual machine}. The default is to use {@link System#err}. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
188 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
189 * @param w the writer to use as output |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
190 * @return instance of this builder |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
191 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
192 public Builder stdErr(Writer w) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
193 err = w; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
194 return this; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
195 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
196 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
197 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
198 * Changes the default input for languages running in <em>to be created</em> |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
199 * {@link PolyglotEngine virtual machine}. The default is to use {@link System#out}. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
200 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
201 * @param r the reader to use as input |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
202 * @return instance of this builder |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
203 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
204 public Builder stdIn(Reader r) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
205 in = r; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
206 return this; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
207 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
208 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
209 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
210 * Registers another instance of {@link EventConsumer} into the to be created |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
211 * {@link PolyglotEngine}. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
212 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
213 * @param handler the handler to register |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
214 * @return instance of this builder |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
215 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
216 public Builder onEvent(EventConsumer<?> handler) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
217 handler.getClass(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
218 handlers.add(handler); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
219 return this; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
220 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
221 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
222 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
223 * Adds global named symbol into the configuration of to-be-built {@link PolyglotEngine}. |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
224 * This symbol will be accessible to all languages via |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
225 * {@link Env#importSymbol(java.lang.String)} and will take precedence over |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
226 * {@link TruffleLanguage#findExportedSymbol symbols exported by languages itself}. Repeated |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
227 * use of <code>globalSymbol</code> is possible; later definition of the same name overrides |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
228 * the previous one. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
229 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
230 * @param name name of the symbol to register |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
231 * @param obj value of the object - expected to be primitive wrapper, {@link String} or |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
232 * <code>TruffleObject</code> for mutual inter-operability |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
233 * @return instance of this builder |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
234 * @see PolyglotEngine#findGlobalSymbol(java.lang.String) |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
235 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
236 public Builder globalSymbol(String name, Object obj) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
237 globals.put(name, obj); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
238 return this; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
239 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
240 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
241 /** |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
242 * Provides own executor for running {@link PolyglotEngine} scripts. By default |
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
243 * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source)} and |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
244 * {@link Value#invoke(java.lang.Object, java.lang.Object[])} are executed synchronously in |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
245 * the calling thread. Sometimes, however it is more beneficial to run them asynchronously - |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
246 * the easiest way to do so is to provide own executor when configuring the { |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
247 * {@link #executor(java.util.concurrent.Executor) the builder}. The executor is expected to |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
248 * execute all {@link Runnable runnables} passed into its |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
249 * {@link Executor#execute(java.lang.Runnable)} method in the order they arrive and in a |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
250 * single (yet arbitrary) thread. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
251 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
252 * @param executor the executor to use for internal execution inside the {@link #build() to |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
253 * be created} {@link PolyglotEngine} |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
254 * @return instance of this builder |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
255 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
256 @SuppressWarnings("hiding") |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
257 public Builder executor(Executor executor) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
258 this.executor = executor; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
259 return this; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
260 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
261 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
262 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
263 * Creates the {@link PolyglotEngine Truffle virtual machine}. The configuration is taken |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
264 * from values passed into configuration methods in this class. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
265 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
266 * @return new, isolated virtual machine with pre-registered languages |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
267 */ |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
268 @SuppressWarnings("deprecation") |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
269 public PolyglotEngine build() { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
270 if (out == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
271 out = new OutputStreamWriter(System.out); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
272 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
273 if (err == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
274 err = new OutputStreamWriter(System.err); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
275 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
276 if (in == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
277 in = new InputStreamReader(System.in); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
278 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
279 Executor nonNullExecutor = executor != null ? executor : new Executor() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
280 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
281 public void execute(Runnable command) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
282 command.run(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
283 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
284 }; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
285 return new TruffleVM(nonNullExecutor, globals, out, err, in, handlers.toArray(new EventConsumer[0])); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
286 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
287 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
288 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
289 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
290 * Descriptions of languages supported in this Truffle virtual machine. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
291 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
292 * @return an immutable map with keys being MIME types and values the {@link Language |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
293 * descriptions} of associated languages |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
294 */ |
22169
307a4ed5430e
Two more changes to guarantee better compatibility with TruffleVM
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
295 public Map<String, ? extends Language> getLanguages() { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
296 return Collections.unmodifiableMap(langs); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
297 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
298 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
299 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
300 * Evaluates file located on a given URL. Is equivalent to loading the content of a file and |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
301 * executing it via {@link #eval(java.lang.String, java.lang.String)} with a MIME type guess |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
302 * based on the file's extension and/or content. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
303 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
304 * @param location the location of a file to execute |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
305 * @return result of a processing the file, possibly <code>null</code> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
306 * @throws IOException exception to signal I/O problems or problems with processing the file's |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
307 * content |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
308 * @deprecated use {@link #eval(com.oracle.truffle.api.source.Source)} |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
309 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
310 @Deprecated |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
311 public Object eval(URI location) throws IOException { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
312 checkThread(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
313 Source s; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
314 String mimeType; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
315 if (location.getScheme().equals("file")) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
316 File file = new File(location); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
317 s = Source.fromFileName(file.getPath(), true); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
318 if (file.getName().endsWith(".c")) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
319 mimeType = "text/x-c"; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
320 } else if (file.getName().endsWith(".sl")) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
321 mimeType = "application/x-sl"; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
322 } else if (file.getName().endsWith(".R") || file.getName().endsWith(".r")) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
323 mimeType = "application/x-r"; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
324 } else { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
325 mimeType = Files.probeContentType(file.toPath()); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
326 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
327 } else { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
328 URL url = location.toURL(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
329 s = Source.fromURL(url, location.toString()); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
330 URLConnection conn = url.openConnection(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
331 mimeType = conn.getContentType(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
332 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
333 Language l = langs.get(mimeType); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
334 if (l == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
335 throw new IOException("No language for " + location + " with MIME type " + mimeType + " found. Supported types: " + langs.keySet()); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
336 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
337 return eval(l, s).get(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
338 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
339 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
340 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
341 * Evaluates code snippet. Chooses a language registered for a given MIME type (throws |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
342 * {@link IOException} if there is none). And passes the specified code to it for execution. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
343 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
344 * @param mimeType MIME type of the code snippet - chooses the right language |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
345 * @param reader the source of code snippet to execute |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
346 * @return result of an execution, possibly <code>null</code> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
347 * @throws IOException thrown to signal errors while processing the code |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
348 * @deprecated use {@link #eval(com.oracle.truffle.api.source.Source)} |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
349 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
350 @Deprecated |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
351 public Object eval(String mimeType, Reader reader) throws IOException { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
352 checkThread(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
353 Language l = langs.get(mimeType); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
354 if (l == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
355 throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
356 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
357 return eval(l, Source.fromReader(reader, mimeType)).get(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
358 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
359 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
360 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
361 * Evaluates code snippet. Chooses a language registered for a given MIME type (throws |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
362 * {@link IOException} if there is none). And passes the specified code to it for execution. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
363 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
364 * @param mimeType MIME type of the code snippet - chooses the right language |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
365 * @param code the code snippet to execute |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
366 * @return result of an execution, possibly <code>null</code> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
367 * @throws IOException thrown to signal errors while processing the code |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
368 * @deprecated use {@link #eval(com.oracle.truffle.api.source.Source)} |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
369 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
370 @Deprecated |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
371 public Object eval(String mimeType, String code) throws IOException { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
372 checkThread(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
373 Language l = langs.get(mimeType); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
374 if (l == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
375 throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
376 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
377 return eval(l, Source.fromText(code, mimeType)).get(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
378 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
379 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
380 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
381 * Evaluates provided source. Chooses language registered for a particular |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
382 * {@link Source#getMimeType() MIME type} (throws {@link IOException} if there is none). The |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
383 * language is then allowed to parse and execute the source. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
384 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
385 * @param source code snippet to execute |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
386 * @return a {@link Value} object that holds result of an execution, never <code>null</code> |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
387 * @throws IOException thrown to signal errors while processing the code |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
388 */ |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
389 public Value eval(Source source) throws IOException { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
390 String mimeType = source.getMimeType(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
391 checkThread(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
392 Language l = langs.get(mimeType); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
393 if (l == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
394 throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
395 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
396 return eval(l, source); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
397 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
398 |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
399 private Value eval(final Language l, final Source s) throws IOException { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
400 final Debugger[] fillIn = {debugger}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
401 final Object[] result = {null, null}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
402 final CountDownLatch ready = new CountDownLatch(1); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
403 final TruffleLanguage[] lang = {null}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
404 executor.execute(new Runnable() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
405 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
406 public void run() { |
22133
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
407 evalImpl(fillIn, lang, s, result, l, ready); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
408 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
409 }); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
410 exceptionCheck(result); |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
411 return createValue(lang[0], result, ready); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
412 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
413 |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
414 Value createValue(TruffleLanguage lang, Object[] result, CountDownLatch ready) { |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
415 return new Value(lang, result, ready); |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
416 } |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
417 |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
418 Language createLanguage(Map.Entry<String, LanguageCache> en) { |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
419 return new Language(en.getValue()); |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
420 } |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
421 |
22132
19205292b0c7
Suppressing "try" lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22129
diff
changeset
|
422 @SuppressWarnings("try") |
22133
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
423 private void evalImpl(Debugger[] fillIn, TruffleLanguage<?>[] fillLang, Source s, Object[] result, Language l, CountDownLatch ready) { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
424 try (Closeable d = SPI.executionStart(this, fillIn, s)) { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
425 TruffleLanguage<?> langImpl = l.getImpl(true); |
22133
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
426 fillLang[0] = langImpl; |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
427 PolyglotEngine.findDebuggerSupport(langImpl); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
428 if (debugger == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
429 debugger = fillIn[0]; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
430 } |
22133
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
431 result[0] = SPI.eval(langImpl, s); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
432 } catch (IOException ex) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
433 result[1] = ex; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
434 } finally { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
435 ready.countDown(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
436 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
437 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
438 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
439 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
440 * Looks global symbol provided by one of initialized languages up. First of all execute your |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
441 * program via one of your {@link #eval(java.lang.String, java.lang.String)} and then look |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
442 * expected symbol up using this method. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
443 * <p> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
444 * The names of the symbols are language dependent, but for example the Java language bindings |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
445 * follow the specification for method references: |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
446 * <ul> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
447 * <li>"java.lang.Exception::new" is a reference to constructor of {@link Exception} |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
448 * <li>"java.lang.Integer::valueOf" is a reference to static method in {@link Integer} class |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
449 * </ul> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
450 * Once an symbol is obtained, it remembers values for fast access and is ready for being |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
451 * invoked. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
452 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
453 * @param globalName the name of the symbol to find |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
454 * @return found symbol or <code>null</code> if it has not been found |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
455 */ |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
456 public Value findGlobalSymbol(final String globalName) { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
457 checkThread(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
458 final TruffleLanguage<?>[] lang = {null}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
459 final Object[] obj = {globals.get(globalName), null}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
460 final CountDownLatch ready = new CountDownLatch(1); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
461 if (obj[0] == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
462 executor.execute(new Runnable() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
463 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
464 public void run() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
465 findGlobalSymbolImpl(obj, globalName, lang, ready); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
466 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
467 }); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
468 try { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
469 ready.await(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
470 } catch (InterruptedException ex) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
471 LOG.log(Level.SEVERE, null, ex); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
472 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
473 } else { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
474 ready.countDown(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
475 } |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
476 return obj[0] == null ? null : createValue(lang[0], obj, ready); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
477 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
478 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
479 private void findGlobalSymbolImpl(Object[] obj, String globalName, TruffleLanguage<?>[] lang, CountDownLatch ready) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
480 if (obj[0] == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
481 for (Language dl : langs.values()) { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
482 TruffleLanguage.Env env = dl.getEnv(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
483 if (env == null) { |
22133
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
484 continue; |
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
485 } |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
486 obj[0] = SPI.findExportedSymbol(env, globalName, true); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
487 if (obj[0] != null) { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
488 lang[0] = dl.getImpl(true); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
489 break; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
490 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
491 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
492 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
493 if (obj[0] == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
494 for (Language dl : langs.values()) { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
495 TruffleLanguage.Env env = dl.getEnv(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
496 if (env == null) { |
22133
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
497 continue; |
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
498 } |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
499 obj[0] = SPI.findExportedSymbol(env, globalName, true); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
500 if (obj[0] != null) { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
501 lang[0] = dl.getImpl(true); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
502 break; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
503 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
504 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
505 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
506 ready.countDown(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
507 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
508 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
509 private void checkThread() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
510 if (initThread != Thread.currentThread()) { |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
511 throw new IllegalStateException("PolyglotEngine created on " + initThread.getName() + " but used on " + Thread.currentThread().getName()); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
512 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
513 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
514 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
515 @SuppressWarnings("unchecked") |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
516 void dispatch(Object ev) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
517 Class type = ev.getClass(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
518 if (type == SuspendedEvent.class) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
519 dispatchSuspendedEvent((SuspendedEvent) ev); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
520 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
521 if (type == ExecutionEvent.class) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
522 dispatchExecutionEvent((ExecutionEvent) ev); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
523 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
524 dispatch(type, ev); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
525 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
526 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
527 @SuppressWarnings("unused") |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
528 void dispatchSuspendedEvent(SuspendedEvent event) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
529 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
530 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
531 @SuppressWarnings("unused") |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
532 void dispatchExecutionEvent(ExecutionEvent event) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
533 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
534 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
535 @SuppressWarnings("unchecked") |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
536 <Event> void dispatch(Class<Event> type, Event event) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
537 for (EventConsumer handler : handlers) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
538 if (handler.type == type) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
539 handler.on(event); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
540 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
541 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
542 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
543 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
544 static void exceptionCheck(Object[] result) throws RuntimeException, IOException { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
545 if (result[1] instanceof IOException) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
546 throw (IOException) result[1]; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
547 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
548 if (result[1] instanceof RuntimeException) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
549 throw (RuntimeException) result[1]; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
550 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
551 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
552 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
553 /** |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
554 * A future value wrapper. A user level wrapper around values returned by evaluation of various |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
555 * {@link PolyglotEngine} functions like |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
556 * {@link PolyglotEngine#findGlobalSymbol(java.lang.String)} and |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
557 * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source)} or value returned by |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
558 * {@link #invoke(java.lang.Object, java.lang.Object...) sbbsequent of execution}. In case the |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
559 * {@link PolyglotEngine} has been initialized for |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
560 * {@link Builder#executor(java.util.concurrent.Executor) asynchronous excution}, the |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
561 * {@link Value} represents a future - e.g. it is returned immediately, leaving the execution |
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
562 * running on behind. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
563 */ |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
564 public class Value { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
565 private final TruffleLanguage<?> language; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
566 private final Object[] result; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
567 private final CountDownLatch ready; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
568 private CallTarget target; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
569 |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
570 Value(TruffleLanguage<?> language, Object[] result, CountDownLatch ready) { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
571 this.language = language; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
572 this.result = result; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
573 this.ready = ready; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
574 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
575 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
576 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
577 * Obtains the object represented by this symbol. The <em>raw</em> object can either be a |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
578 * wrapper about primitive type (e.g. {@link Number}, {@link String}, {@link Character}, |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
579 * {@link Boolean}) or a <em>TruffleObject</em> representing more complex object from a |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
580 * language. The method can return <code>null</code>. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
581 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
582 * @return the object or <code>null</code> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
583 * @throws IOException in case it is not possible to obtain the value of the object |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
584 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
585 public Object get() throws IOException { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
586 waitForSymbol(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
587 exceptionCheck(result); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
588 return result[0]; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
589 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
590 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
591 /** |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
592 * Obtains Java view of the object represented by this symbol. The method basically |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
593 * delegates to |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
594 * {@link JavaInterop#asJavaObject(java.lang.Class, com.oracle.truffle.api.interop.TruffleObject)} |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
595 * just handles primitive types as well. |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
596 * |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
597 * @param <T> the type of the view one wants to obtain |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
598 * @param representation the class of the view interface (it has to be an interface) |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
599 * @return instance of the view wrapping the object of this symbol |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
600 * @throws IOException in case it is not possible to obtain the value of the object |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
601 * @throws ClassCastException if the value cannot be converted to desired view |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
602 */ |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
603 public <T> T as(Class<T> representation) throws IOException { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
604 Object obj = get(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
605 if (representation.isInstance(obj)) { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
606 return representation.cast(obj); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
607 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
608 return JavaInterop.asJavaObject(representation, (TruffleObject) obj); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
609 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
610 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22133
diff
changeset
|
611 /** |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
612 * Invokes the symbol. If the symbol represents a function, then it should be invoked with |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
613 * provided arguments. If the symbol represents a field, then first argument (if provided) |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
614 * should set the value to the field; the return value should be the actual value of the |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
615 * field when the <code>invoke</code> method returns. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
616 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
617 * @param thiz this/self in language that support such concept; use <code>null</code> to let |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
618 * the language use default this/self or ignore the value |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
619 * @param args arguments to pass when invoking the symbol |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
620 * @return symbol wrapper around the value returned by invoking the symbol, never |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
621 * <code>null</code> |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
622 * @throws IOException signals problem during execution |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
623 */ |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
624 public Value invoke(final Object thiz, final Object... args) throws IOException { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
625 get(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
626 final Debugger[] fillIn = {debugger}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
627 final CountDownLatch done = new CountDownLatch(1); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
628 final Object[] res = {null, null}; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
629 executor.execute(new Runnable() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
630 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
631 public void run() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
632 invokeImpl(fillIn, thiz, args, res, done); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
633 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
634 }); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
635 exceptionCheck(res); |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
636 return createValue(language, res, done); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
637 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
638 |
22132
19205292b0c7
Suppressing "try" lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22129
diff
changeset
|
639 @SuppressWarnings("try") |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
640 private void invokeImpl(Debugger[] fillIn, Object thiz, Object[] args, Object[] res, CountDownLatch done) { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
641 try (final Closeable c = SPI.executionStart(PolyglotEngine.this, fillIn, null)) { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
642 if (debugger == null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
643 debugger = fillIn[0]; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
644 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
645 List<Object> arr = new ArrayList<>(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
646 if (thiz == null && language != null) { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
647 Object global = SPI.languageGlobal(SPI.findLanguage(PolyglotEngine.this, language.getClass())); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
648 if (global != null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
649 arr.add(global); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
650 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
651 } else { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
652 arr.add(thiz); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
653 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
654 arr.addAll(Arrays.asList(args)); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
655 for (;;) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
656 try { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
657 if (target == null) { |
22129
0589cc5cab30
TruffleVM can now depend on api.interop and thus there is no need for indirection between SymbolInvoker and its Impl. Enough to do direct calls.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22128
diff
changeset
|
658 target = SymbolInvokerImpl.createCallTarget(language, result[0], arr.toArray()); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
659 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
660 res[0] = target.call(arr.toArray()); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
661 break; |
22129
0589cc5cab30
TruffleVM can now depend on api.interop and thus there is no need for indirection between SymbolInvoker and its Impl. Enough to do direct calls.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22128
diff
changeset
|
662 } catch (ArgumentsMishmashException ex) { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
663 target = null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
664 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
665 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
666 } catch (IOException ex) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
667 res[1] = ex; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
668 } catch (RuntimeException ex) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
669 res[1] = ex; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
670 } finally { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
671 done.countDown(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
672 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
673 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
674 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
675 private void waitForSymbol() throws InterruptedIOException { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
676 checkThread(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
677 try { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
678 ready.await(); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
679 } catch (InterruptedException ex) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
680 throw (InterruptedIOException) new InterruptedIOException(ex.getMessage()).initCause(ex); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
681 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
682 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
683 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
684 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
685 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
686 * Description of a language registered in {@link PolyglotEngine Truffle virtual machine}. |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
687 * Languages are registered by {@link Registration} annotation which stores necessary |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
688 * information into a descriptor inside of the language's JAR file. When a new |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
689 * {@link PolyglotEngine} is created, it reads all available descriptors and creates |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
690 * {@link Language} objects to represent them. One can obtain a {@link #getName() name} or list |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
691 * of supported {@link #getMimeTypes() MIME types} for each language. The actual language |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22171
diff
changeset
|
692 * implementation is not initialized until |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
693 * {@link PolyglotEngine#eval(java.lang.String, java.lang.String) a code is evaluated} in it. |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
694 */ |
22168
ffadd23c63c8
Introducing Portaal into the isolated world of each and any TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
695 public class Language { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
696 private final LanguageCache info; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
697 private TruffleLanguage.Env env; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
698 |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
699 Language(LanguageCache info) { |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
700 this.info = info; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
701 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
702 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
703 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
704 * MIME types recognized by the language. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
705 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
706 * @return returns immutable set of recognized MIME types |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
707 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
708 public Set<String> getMimeTypes() { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
709 return info.getMimeTypes(); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
710 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
711 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
712 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
713 * Human readable name of the language. Think of C, Ruby, JS, etc. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
714 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
715 * @return string giving the language a name |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
716 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
717 public String getName() { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
718 return info.getName(); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
719 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
720 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
721 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
722 * Name of the language version. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
723 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
724 * @return string specifying the language version |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
725 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
726 public String getVersion() { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
727 return info.getVersion(); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
728 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
729 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
730 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
731 * Human readable string that identifies the language and version. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
732 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
733 * @return string describing the specific language version |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
734 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
735 public String getShortName() { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
736 return getName() + "(" + getVersion() + ")"; |
22133
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
737 } |
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
738 |
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
739 TruffleLanguage<?> getImpl(boolean create) { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
740 getEnv(create); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
741 return info.getImpl(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
742 } |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
743 |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
744 TruffleLanguage.Env getEnv(boolean create) { |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
745 if (env == null && create) { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
746 env = SPI.attachEnv(PolyglotEngine.this, info.getImpl(true), out, err, in); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
747 } |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
748 return env; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
749 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
750 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
751 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
752 public String toString() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
753 return "[" + getShortName() + " for " + getMimeTypes() + "]"; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
754 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
755 } // end of Language |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
756 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
757 // |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
758 // Accessor helper methods |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
759 // |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
760 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
761 TruffleLanguage<?> findLanguage(Probe probe) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
762 Class<? extends TruffleLanguage> languageClazz = SPI.findLanguage(probe); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
763 for (Map.Entry<String, Language> entrySet : langs.entrySet()) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
764 Language languageDescription = entrySet.getValue(); |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
765 final TruffleLanguage<?> impl = languageDescription.getImpl(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
766 if (languageClazz.isInstance(impl)) { |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
767 return impl; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
768 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
769 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
770 throw new IllegalStateException("Cannot find language " + languageClazz + " among " + langs); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
771 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
772 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
773 Env findEnv(Class<? extends TruffleLanguage> languageClazz) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
774 for (Map.Entry<String, Language> entrySet : langs.entrySet()) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
775 Language languageDescription = entrySet.getValue(); |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
776 Env env = languageDescription.getEnv(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
777 if (env != null && languageClazz.isInstance(languageDescription.getImpl(false))) { |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
778 return env; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
779 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
780 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
781 throw new IllegalStateException("Cannot find language " + languageClazz + " among " + langs); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
782 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
783 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
784 static DebugSupportProvider findDebuggerSupport(TruffleLanguage<?> l) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
785 return SPI.getDebugSupport(l); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
786 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
787 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
788 private static class SPIAccessor extends Accessor { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
789 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
790 public Object importSymbol(Object vmObj, TruffleLanguage<?> ownLang, String globalName) { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
791 PolyglotEngine vm = (PolyglotEngine) vmObj; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
792 Object g = vm.globals.get(globalName); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
793 if (g != null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
794 return g; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
795 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
796 Set<Language> uniqueLang = new LinkedHashSet<>(vm.langs.values()); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
797 for (Language dl : uniqueLang) { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
798 TruffleLanguage<?> l = dl.getImpl(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
799 TruffleLanguage.Env env = dl.getEnv(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
800 if (l == ownLang || l == null || env == null) { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
801 continue; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
802 } |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
803 Object obj = SPI.findExportedSymbol(env, globalName, true); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
804 if (obj != null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
805 return obj; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
806 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
807 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
808 for (Language dl : uniqueLang) { |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
809 TruffleLanguage<?> l = dl.getImpl(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
810 TruffleLanguage.Env env = dl.getEnv(false); |
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
811 if (l == ownLang || l == null || env == null) { |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
812 continue; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
813 } |
22137
1957c49a979d
(Re)Introducing LanguageCache - e.g. data that hold the essential static information about Truffle languages. Pre-initializing the data if AOT property is specified. Use mx -J-Dcom.oracle.truffle.aot=true unittest to validate proper behavior of AOT mode.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
814 Object obj = SPI.findExportedSymbol(env, globalName, false); |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
815 if (obj != null) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
816 return obj; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
817 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
818 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
819 return null; |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
820 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
821 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
822 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
823 public Env attachEnv(Object obj, TruffleLanguage<?> language, Writer stdOut, Writer stdErr, Reader stdIn) { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
824 PolyglotEngine vm = (PolyglotEngine) obj; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
825 return super.attachEnv(vm, language, stdOut, stdErr, stdIn); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
826 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
827 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
828 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
829 public Object eval(TruffleLanguage<?> l, Source s) throws IOException { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
830 return super.eval(l, s); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
831 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
832 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
833 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
834 public Object findExportedSymbol(TruffleLanguage.Env env, String globalName, boolean onlyExplicit) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
835 return super.findExportedSymbol(env, globalName, onlyExplicit); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
836 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
837 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
838 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
839 protected Object languageGlobal(TruffleLanguage.Env env) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
840 return super.languageGlobal(env); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
841 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
842 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
843 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
844 public ToolSupportProvider getToolSupport(TruffleLanguage<?> l) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
845 return super.getToolSupport(l); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
846 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
847 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
848 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
849 public DebugSupportProvider getDebugSupport(TruffleLanguage<?> l) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
850 return super.getDebugSupport(l); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
851 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
852 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
853 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
854 protected Class<? extends TruffleLanguage> findLanguage(Probe probe) { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
855 return super.findLanguage(probe); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
856 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
857 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
858 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
859 protected Env findLanguage(Object obj, Class<? extends TruffleLanguage> languageClass) { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
860 PolyglotEngine vm = (PolyglotEngine) obj; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
861 return vm.findEnv(languageClass); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
862 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
863 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
864 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
865 protected Closeable executionStart(Object obj, Debugger[] fillIn, Source s) { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
866 PolyglotEngine vm = (PolyglotEngine) obj; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
867 return super.executionStart(vm, fillIn, s); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
868 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
869 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
870 @Override |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
871 protected void dispatchEvent(Object obj, Object event) { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22169
diff
changeset
|
872 PolyglotEngine vm = (PolyglotEngine) obj; |
22128
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
873 vm.dispatch(event); |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
874 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
875 } // end of SPIAccessor |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
876 } |