Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/TruffleVM.java @ 22165:67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 21 Sep 2015 12:36:30 +0200 |
parents | dc83cc1f94f2 |
children | 0480c4873a4a |
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 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
27 import com.oracle.truffle.api.CallTarget; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
28 import com.oracle.truffle.api.TruffleLanguage; |
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
|
29 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
|
30 import com.oracle.truffle.api.TruffleLanguage.Registration; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
31 import com.oracle.truffle.api.debug.DebugSupportProvider; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
32 import com.oracle.truffle.api.debug.Debugger; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
33 import com.oracle.truffle.api.debug.ExecutionEvent; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
34 import com.oracle.truffle.api.debug.SuspendedEvent; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
35 import com.oracle.truffle.api.impl.Accessor; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
36 import com.oracle.truffle.api.instrument.Probe; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
37 import com.oracle.truffle.api.instrument.ToolSupportProvider; |
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
|
38 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
|
39 import com.oracle.truffle.api.interop.java.JavaInterop; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
40 import com.oracle.truffle.api.source.Source; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
41 import java.io.Closeable; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
42 import java.io.File; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
43 import java.io.IOException; |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
44 import java.io.InputStream; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
45 import java.io.InterruptedIOException; |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
46 import java.io.OutputStream; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
47 import java.io.Reader; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
48 import java.io.Writer; |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
49 import java.lang.reflect.InvocationHandler; |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
50 import java.lang.reflect.Method; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
51 import java.net.URI; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
52 import java.net.URL; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
53 import java.net.URLConnection; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
54 import java.nio.file.Files; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
55 import java.util.ArrayList; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
56 import java.util.Arrays; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
57 import java.util.Collections; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
58 import java.util.HashMap; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
59 import java.util.LinkedHashSet; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
60 import java.util.List; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
61 import java.util.Map; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
62 import java.util.Set; |
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
|
63 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
|
64 import java.util.concurrent.Executor; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
65 import java.util.logging.Level; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22141
diff
changeset
|
66 import java.util.logging.Logger; |
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
|
67 |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating 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 * <em>Virtual machine</em> for Truffle based languages. Term virtual machine is a bit overloaded, |
f879b1fe3773
Separating 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 * so don't think of <em>Java virtual machine</em> here - while we are running and using |
f879b1fe3773
Separating 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 * {@link TruffleVM} inside of a <em>JVM</em> there can be multiple instances (some would say |
f879b1fe3773
Separating 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 * tenants) of {@link TruffleVM} running next to each other in a single <em>JVM</em> with a complete |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
73 * mutual isolation. There is 1:N mapping between <em>JVM</em> and {@link TruffleVM}. |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
74 * <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
|
75 * It would not be correct to think of a {@link TruffleVM} as a runtime for a single Truffle |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
76 * language (Ruby, Python, R, C, JavaScript, etc.) either. {@link TruffleVM} can host as many of |
f879b1fe3773
Separating 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 * Truffle languages as {@link Registration registered on a class path} of your <em>JVM</em> |
f879b1fe3773
Separating 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 * application. {@link TruffleVM} orchestrates these languages, manages exchange of objects 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
|
79 * calls among them. While it may happen that there is just one activated language inside of 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
|
80 * {@link TruffleVM}, the greatest strength of {@link TruffleVM} is in interoperability between all |
f879b1fe3773
Separating 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 * Truffle languages. There is 1:N mapping between {@link TruffleVM} and {@link TruffleLanguage |
f879b1fe3773
Separating 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 * Truffle language implementations}. |
f879b1fe3773
Separating 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 * <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
|
84 * Use {@link #newVM()} to create new isolated virtual machine ready for execution of various |
f879b1fe3773
Separating 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 * languages. All the languages in a single virtual machine see each other exported global symbols |
f879b1fe3773
Separating 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 * and can cooperate. Use {@link #newVM()} multiple times to create different, isolated virtual |
f879b1fe3773
Separating 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 * machines completely separated from each other. |
f879b1fe3773
Separating 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 * <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
|
89 * 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
|
90 * 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
|
91 * 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
|
92 * 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
|
93 * 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
|
94 * <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
|
95 * The <code>TruffleVM</code> is single-threaded and tries to enforce that. It records the thread 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
|
96 * has been {@link Builder#build() created} by and checks that all subsequent calls are coming from |
f879b1fe3773
Separating 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 * the same thread. There is 1:1 mapping between {@link TruffleVM} and a thread that can tell 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
|
98 * what to do. |
f879b1fe3773
Separating 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 */ |
f879b1fe3773
Separating 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 @SuppressWarnings("rawtypes") |
f879b1fe3773
Separating 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 public final class TruffleVM { |
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
|
102 static final Logger LOG = Logger.getLogger(TruffleVM.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
|
103 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
|
104 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
|
105 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
|
106 private final Map<String, Language> langs; |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
107 private final InputStream in; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
108 private final OutputStream err; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
109 private final OutputStream 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
|
110 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
|
111 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
|
112 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
|
113 |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating 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 * 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
|
116 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
117 private TruffleVM() { |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 } |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
129 * 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
|
130 */ |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
131 private TruffleVM(Executor executor, Map<String, Object> globals, OutputStream out, OutputStream err, InputStream 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 for (Map.Entry<String, LanguageCache> en : LanguageCache.languages().entrySet()) { |
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
|
141 map.put(en.getKey(), new Language(en.getValue())); |
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
|
142 } |
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
|
143 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
|
144 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
145 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
146 /** |
f879b1fe3773
Separating 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 * 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
|
148 * 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
|
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 * <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
|
151 * {@link TruffleVM} vm = {@link TruffleVM}.{@link TruffleVM#newVM() newVM()} |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
152 * .{@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
|
153 * .{@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
|
154 * .{@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
|
155 * .{@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
|
156 * </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
|
157 * |
f879b1fe3773
Separating 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 * 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
|
159 * 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
|
160 * {@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
|
161 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
162 * @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
|
163 */ |
f879b1fe3773
Separating 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 public static TruffleVM.Builder newVM() { |
f879b1fe3773
Separating 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 // 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
|
166 // nasty trick to avoid the Builder class to appear |
f879b1fe3773
Separating 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 // in Javadoc next to TruffleVM 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
|
168 TruffleVM vm = new TruffleVM(); |
f879b1fe3773
Separating 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 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
|
170 } |
f879b1fe3773
Separating 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 * Builder for a new {@link TruffleVM}. Call various configuration methods in a chain and at 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
|
174 * end create new {@link TruffleVM 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
|
175 * |
f879b1fe3773
Separating 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 * <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
|
177 * {@link TruffleVM} vm = {@link TruffleVM}.{@link TruffleVM#newVM() newVM()} |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
178 * .{@link Builder#setOut(java.io.Writer) setOut}({@link OutputStream yourOutput}) |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
179 * .{@link Builder#setErr(java.io.Writer) setrr}({@link OutputStream yourOutput}) |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
180 * .{@link Builder#setIn(java.io.Reader) setIn}({@link InputStream yourInput}) |
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
|
181 * .{@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
|
182 * </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
|
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 public final class Builder { |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
185 private OutputStream out; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
186 private OutputStream err; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
187 private InputStream 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
|
188 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
|
189 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
|
190 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
|
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 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
|
193 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 * Changes the default output for languages running in <em>to be created</em> |
f879b1fe3773
Separating 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 * {@link TruffleVM virtual machine}. The default is to use {@link 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
|
198 * |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
199 * @param os the stream to use as output |
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 * @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
|
201 */ |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
202 public Builder setOut(OutputStream os) { |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
203 out = os; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
204 return this; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
205 } |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
206 |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
207 /** |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
208 * @deprecated does nothing |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
209 */ |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
210 @Deprecated |
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
|
211 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
|
212 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
|
213 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 * Changes the error output for languages running in <em>to be created</em> |
f879b1fe3773
Separating 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 * {@link TruffleVM virtual machine}. The default is to use {@link 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
|
218 * |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
219 * @param os the stream to use as output |
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
|
220 * @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
|
221 */ |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
222 public Builder setErr(OutputStream os) { |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
223 err = os; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
224 return this; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
225 } |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
226 |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
227 /** |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
228 * @deprecated does nothing |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
229 */ |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
230 @Deprecated |
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
|
231 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
|
232 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
|
233 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
234 |
f879b1fe3773
Separating 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 * Changes the default input for languages running in <em>to be created</em> |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
237 * {@link TruffleVM virtual machine}. The default is to use {@link System#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
|
238 * |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
239 * @param is the stream to use as input |
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
|
240 * @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
|
241 */ |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
242 public Builder setIn(InputStream is) { |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
243 in = is; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
244 return this; |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
245 } |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
246 |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
247 /** |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
248 * @deprecated does nothing |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
249 */ |
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
250 @Deprecated |
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
|
251 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
|
252 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
|
253 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 * Registers another instance of {@link EventConsumer} into the to be created |
f879b1fe3773
Separating 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 * {@link TruffleVM}. |
f879b1fe3773
Separating 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 * |
f879b1fe3773
Separating 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 * @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
|
260 * @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
|
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 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
|
263 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
|
264 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
|
265 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
|
266 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
268 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
269 * Adds global named symbol into the configuration of to-be-built {@link TruffleVM}. 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
|
270 * symbol will be accessible to all languages via {@link Env#importSymbol(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
|
271 * and will take precedence over {@link TruffleLanguage#findExportedSymbol symbols exported |
f879b1fe3773
Separating 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 * by languages itself}. Repeated use of <code>globalSymbol</code> is possible; later |
f879b1fe3773
Separating 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 * definition of the same name overrides the previous one. |
f879b1fe3773
Separating 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 * |
f879b1fe3773
Separating 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 * @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
|
276 * @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
|
277 * <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
|
278 * @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
|
279 * @see TruffleVM#findGlobalSymbol(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
|
280 */ |
f879b1fe3773
Separating 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 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
|
282 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
|
283 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
|
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 |
f879b1fe3773
Separating 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 * Provides own executor for running {@link TruffleVM} scripts. By default |
f879b1fe3773
Separating 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 * {@link TruffleVM#eval(com.oracle.truffle.api.source.Source)} 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
|
289 * {@link Symbol#invoke(java.lang.Object, java.lang.Object...)} are executed synchronously |
f879b1fe3773
Separating 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 * in the calling thread. Sometimes, however it is more beneficial to run them |
f879b1fe3773
Separating 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 * asynchronously - the easiest way to do so is to provide own executor when configuring 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
|
292 * { {@link #executor(java.util.concurrent.Executor) the builder}. The executor is expected |
f879b1fe3773
Separating 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 * to execute all {@link Runnable runnables} passed into its |
f879b1fe3773
Separating 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 * {@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
|
295 * 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
|
296 * |
f879b1fe3773
Separating 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 * @param executor the executor to use for internal execution inside the {@link #build() to |
f879b1fe3773
Separating 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 * be created} {@link TruffleVM} |
f879b1fe3773
Separating 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 * @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
|
300 */ |
f879b1fe3773
Separating 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 @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
|
302 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
|
303 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
|
304 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
|
305 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating 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 * Creates the {@link TruffleVM Truffle virtual machine}. The configuration is taken from |
f879b1fe3773
Separating 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 * values passed into configuration methods in this 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
|
310 * |
f879b1fe3773
Separating 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 * @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
|
312 */ |
f879b1fe3773
Separating 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 public TruffleVM 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
|
314 if (out == null) { |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
315 out = 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
|
316 } |
f879b1fe3773
Separating 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 if (err == null) { |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
318 err = 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
|
319 } |
f879b1fe3773
Separating 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 if (in == null) { |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
321 in = System.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
|
322 } |
f879b1fe3773
Separating 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 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
|
324 @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
|
325 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
|
326 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
|
327 } |
f879b1fe3773
Separating 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 }; |
f879b1fe3773
Separating 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 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
|
330 } |
f879b1fe3773
Separating 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 } |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating 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 * 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
|
335 * |
f879b1fe3773
Separating 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 * @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
|
337 * 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
|
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 public Map<String, Language> getLanguages() { |
f879b1fe3773
Separating 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 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
|
341 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 * 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
|
345 * 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
|
346 * 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
|
347 * |
f879b1fe3773
Separating 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 * @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
|
349 * @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
|
350 * @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
|
351 * 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
|
352 * @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
|
353 */ |
f879b1fe3773
Separating 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 @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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 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
|
364 } 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
|
365 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
|
366 } 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
|
367 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
|
368 } 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
|
369 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
|
370 } |
f879b1fe3773
Separating 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 } 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
|
372 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
|
373 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
|
374 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
|
375 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
|
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 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
|
378 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
|
379 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
|
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 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
|
382 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 * 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
|
386 * {@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
|
387 * |
f879b1fe3773
Separating 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 * @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
|
389 * @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
|
390 * @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
|
391 * @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
|
392 * @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
|
393 */ |
f879b1fe3773
Separating 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 @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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 } |
f879b1fe3773
Separating 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 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
|
402 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating 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 * 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
|
406 * {@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
|
407 * |
f879b1fe3773
Separating 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 * @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
|
409 * @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
|
410 * @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
|
411 * @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
|
412 * @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
|
413 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
414 @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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
421 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
|
422 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
423 |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
425 * 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
|
426 * {@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
|
427 * 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
|
428 * |
f879b1fe3773
Separating 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 * @param source 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
|
430 * @return a {@link Symbol} object that holds result of an execution, never <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
|
431 * @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
|
432 */ |
f879b1fe3773
Separating 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 public Symbol eval(Source source) 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
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 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
|
441 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 private Symbol eval(final Language l, final 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 @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
|
450 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
|
451 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
|
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 }); |
f879b1fe3773
Separating 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 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
|
455 return new Symbol(lang[0], result, 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
|
456 } |
f879b1fe3773
Separating 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 |
22132
19205292b0c7
Suppressing "try" lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22129
diff
changeset
|
458 @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
|
459 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
|
460 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
|
461 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
|
462 fillLang[0] = langImpl; |
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
463 TruffleVM.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
|
464 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
|
465 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
|
466 } |
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
|
467 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
|
468 } 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
|
469 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
|
470 } 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
|
471 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
|
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 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
476 * 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
|
477 * 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
|
478 * 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
|
479 * <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
|
480 * 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
|
481 * 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
|
482 * <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
|
483 * <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
|
484 * <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
|
485 * </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
|
486 * 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
|
487 * 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
|
488 * |
f879b1fe3773
Separating 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 * @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
|
490 * @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
|
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 public Symbol findGlobalSymbol(final String 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 @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
|
500 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
|
501 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
|
502 } |
f879b1fe3773
Separating 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 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
|
505 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
|
506 } 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
|
507 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
|
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 } 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
|
510 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
|
511 } |
f879b1fe3773
Separating 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 return obj[0] == null ? null : new Symbol(lang[0], obj, 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
|
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 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
|
516 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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 } |
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
|
522 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
|
523 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
|
524 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
|
525 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
|
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 } |
f879b1fe3773
Separating 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 } |
f879b1fe3773
Separating 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 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 } |
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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 } |
f879b1fe3773
Separating 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 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
|
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 |
f879b1fe3773
Separating 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 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
|
546 if (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
|
547 throw new IllegalStateException("TruffleVM created on " + initThread.getName() + " but used on " + Thread.currentThread().getName()); |
f879b1fe3773
Separating 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 } |
f879b1fe3773
Separating 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 } |
f879b1fe3773
Separating 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 @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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
557 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
|
558 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
|
559 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
560 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
|
561 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
562 |
f879b1fe3773
Separating 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 @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
|
564 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
|
565 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 @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
|
568 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
|
569 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
570 |
f879b1fe3773
Separating 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 @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
|
572 <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
|
573 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
|
574 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
|
575 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
|
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 } |
f879b1fe3773
Separating 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 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 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
|
581 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
|
582 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
|
583 } |
f879b1fe3773
Separating 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 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
|
585 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
|
586 } |
f879b1fe3773
Separating 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 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 * Represents {@link TruffleVM#findGlobalSymbol(java.lang.String) global symbol} provided by one |
f879b1fe3773
Separating 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 * of the initialized languages in {@link TruffleVM 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
|
592 */ |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
593 public class 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
|
594 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
|
595 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
|
596 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
|
597 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
|
598 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
599 Symbol(TruffleLanguage<?> language, Object[] result, 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
|
600 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
|
601 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
|
602 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
|
603 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
604 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
605 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
606 * 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
|
607 * 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
|
608 * {@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
|
609 * 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
|
610 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
611 * @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
|
612 * @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
|
613 */ |
f879b1fe3773
Separating 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 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
|
615 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
|
616 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
|
617 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
|
618 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 /** |
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
|
621 * 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
|
622 * 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
|
623 * {@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
|
624 * 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
|
625 * |
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
|
626 * @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
|
627 * @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
|
628 * @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
|
629 * @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
|
630 * @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
|
631 */ |
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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 } |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
637 T wrapper = JavaInterop.asJavaObject(representation, (TruffleObject) obj); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
638 return JavaWrapper.create(representation, wrapper, this); |
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
|
639 } |
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
|
640 |
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
|
641 /** |
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 * 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
|
643 * 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
|
644 * 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
|
645 * 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
|
646 * |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
647 * @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
|
648 * 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
|
649 * @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
|
650 * @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
|
651 * <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
|
652 * @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
|
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 public Symbol invoke(final Object thiz, final Object... args) 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
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 @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
|
661 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
|
662 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
|
663 } |
f879b1fe3773
Separating 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 exceptionCheck(res); |
f879b1fe3773
Separating 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 return new Symbol(language, 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
|
667 } |
f879b1fe3773
Separating 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 |
22132
19205292b0c7
Suppressing "try" lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22129
diff
changeset
|
669 @SuppressWarnings("try") |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
670 final Symbol invokeProxy(final InvocationHandler chain, final Object wrapper, final Method method, final Object[] args) throws IOException { |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
671 final Debugger[] fillIn = {debugger}; |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
672 final CountDownLatch done = new CountDownLatch(1); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
673 final Object[] res = {null, null}; |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
674 executor.execute(new Runnable() { |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
675 @Override |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
676 public void run() { |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
677 try (final Closeable c = SPI.executionStart(TruffleVM.this, fillIn, null)) { |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
678 if (debugger == null) { |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
679 debugger = fillIn[0]; |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
680 } |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
681 res[0] = chain.invoke(wrapper, method, args); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
682 } catch (IOException ex) { |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
683 res[1] = ex; |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
684 } catch (Throwable ex) { |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
685 res[1] = ex; |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
686 } finally { |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
687 done.countDown(); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
688 } |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
689 } |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
690 }); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
691 exceptionCheck(res); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
692 return new Symbol(language, res, done); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
693 } |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
694 |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22137
diff
changeset
|
695 @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
|
696 private void invokeImpl(Debugger[] fillIn, Object thiz, Object[] args, Object[] res, CountDownLatch 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
|
697 try (final Closeable c = SPI.executionStart(TruffleVM.this, fillIn, 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
|
698 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
|
699 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
|
700 } |
f879b1fe3773
Separating 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 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
|
702 if (thiz == null && language != 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
|
703 Object global = SPI.languageGlobal(SPI.findLanguage(TruffleVM.this, language.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
|
704 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
|
705 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
|
706 } |
f879b1fe3773
Separating 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 } 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
|
708 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
|
709 } |
f879b1fe3773
Separating 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 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
|
711 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
|
712 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
|
713 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
|
714 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
|
715 } |
f879b1fe3773
Separating 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 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
|
717 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
|
718 } 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
|
719 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
|
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 } 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
|
723 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
|
724 } 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
|
725 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
|
726 } 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
|
727 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
|
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 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
|
732 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
|
733 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
|
734 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
|
735 } 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
|
736 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
|
737 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
738 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
739 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
740 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
741 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
742 * Description of a language registered in {@link TruffleVM Truffle virtual machine}. 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
|
743 * are registered by {@link Registration} annotation which stores necessary information into 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
|
744 * descriptor inside of the language's JAR file. When a new {@link TruffleVM} is created, 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
|
745 * reads all available descriptors and creates {@link Language} objects to represent them. One |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
746 * can obtain a {@link #getName() name} or list of supported {@link #getMimeTypes() 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
|
747 * for each language. The actual language implementation is not initialized until |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
748 * {@link TruffleVM#eval(java.lang.String, java.lang.String) a code is evaluated} in 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
|
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 public final 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
|
751 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
|
752 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
|
753 |
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
|
754 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
|
755 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
|
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 /** |
f879b1fe3773
Separating 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 * 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
|
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 * @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
|
762 */ |
f879b1fe3773
Separating 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 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
|
764 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
|
765 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
766 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
767 /** |
f879b1fe3773
Separating 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 * 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
|
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 * @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
|
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 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
|
773 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
|
774 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
776 /** |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
777 * 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
|
778 * |
f879b1fe3773
Separating 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 * @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
|
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 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
|
782 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
|
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 |
f879b1fe3773
Separating 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 /** |
f879b1fe3773
Separating 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 * 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
|
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 * @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
|
789 */ |
f879b1fe3773
Separating 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 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
|
791 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
|
792 } |
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
793 |
c334865b9d42
Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22132
diff
changeset
|
794 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
|
795 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
|
796 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
|
797 } |
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 |
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 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
|
800 if (env == null && 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
|
801 env = SPI.attachEnv(TruffleVM.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
|
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 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
|
804 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 @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
|
807 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
|
808 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
|
809 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
810 } // 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
|
811 |
f879b1fe3773
Separating 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 // |
f879b1fe3773
Separating 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 // 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
|
814 // |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating 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 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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
824 } |
f879b1fe3773
Separating 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 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
|
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 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 } |
f879b1fe3773
Separating 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 } |
f879b1fe3773
Separating 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 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
|
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 |
f879b1fe3773
Separating 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 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
|
840 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
|
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 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
|
844 @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
|
845 public Object importSymbol(Object vmObj, TruffleLanguage<?> ownLang, String 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
|
846 TruffleVM vm = (TruffleVM) vmObj; |
f879b1fe3773
Separating 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 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
|
848 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
|
849 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
|
850 } |
f879b1fe3773
Separating 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 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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 } |
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
|
858 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
|
859 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
|
860 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
|
861 } |
f879b1fe3773
Separating 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 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
|
864 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
|
865 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
|
866 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
|
867 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
|
868 } |
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
|
869 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
|
870 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
|
871 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
|
872 } |
f879b1fe3773
Separating 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 } |
f879b1fe3773
Separating 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 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
|
875 } |
f879b1fe3773
Separating 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 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
877 @Override |
22165
67f75f61c974
Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22157
diff
changeset
|
878 protected Env attachEnv(Object obj, TruffleLanguage<?> language, OutputStream stdOut, OutputStream stdErr, InputStream stdIn) { |
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
|
879 TruffleVM vm = (TruffleVM) 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
|
880 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
|
881 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
882 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
883 @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
|
884 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
|
885 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
|
886 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
887 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
888 @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
|
889 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
|
890 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
|
891 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
892 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
893 @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
|
894 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
|
895 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
|
896 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
897 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
898 @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
|
899 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
|
900 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
|
901 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
902 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
903 @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
|
904 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
|
905 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
|
906 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
907 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
908 @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
|
909 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
|
910 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
|
911 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
912 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
913 @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
|
914 protected Env findLanguage(Object obj, Class<? extends TruffleLanguage> 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
|
915 TruffleVM vm = (TruffleVM) 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
|
916 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
|
917 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
918 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
919 @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
|
920 protected Closeable executionStart(Object obj, Debugger[] fillIn, 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
|
921 TruffleVM vm = (TruffleVM) 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
|
922 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
|
923 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
924 |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
925 @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
|
926 protected void dispatchEvent(Object obj, Object 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
|
927 TruffleVM vm = (TruffleVM) 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
|
928 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
|
929 } |
f879b1fe3773
Separating the TruffleVM into its own project makes it possible to cleanup various system parts interations
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
930 } // 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
|
931 } |