annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java @ 22446:5b6e15432aae

Truffle/debugging: minor changes to get "eval" working correctly in some cases
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 10 Nov 2015 18:25:30 -0800
parents 2e5ac2d13d84
children 163fdf64587d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
21649
1c76a5662753 Merge with 645f170013a451083414ff695412c465e9d2ebf0
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21557
diff changeset
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation. Oracle designates this
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 * particular file as subject to the "Classpath" exception as provided
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * by Oracle in the LICENSE file that accompanied this code.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * This code is distributed in the hope that it will be useful, but WITHOUT
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 * version 2 for more details (a copy is included in the LICENSE file that
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * accompanied this code).
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License version
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 * 2 along with this work; if not, write to the Free Software Foundation,
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 * or visit www.oracle.com if you need additional information or have any
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
23 * questions.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
25 package com.oracle.truffle.api;
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
26
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
27 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
28 import java.io.InputStream;
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
29 import java.io.InputStreamReader;
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
30 import java.io.OutputStream;
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
31 import java.io.OutputStreamWriter;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
32 import java.io.Reader;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
33 import java.io.Writer;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
34 import java.lang.annotation.ElementType;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
35 import java.lang.annotation.Retention;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
36 import java.lang.annotation.RetentionPolicy;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
37 import java.lang.annotation.Target;
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
38 import java.util.Collections;
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
39 import java.util.Map;
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
40 import java.util.WeakHashMap;
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
41
22261
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
42 import com.oracle.truffle.api.debug.Debugger;
22268
b56fe0d3b560 Merge with acfea340b19199faaa44bd5e103c716c17ea2b21
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22266 22206
diff changeset
43 import com.oracle.truffle.api.debug.SuspendedEvent;
b56fe0d3b560 Merge with acfea340b19199faaa44bd5e103c716c17ea2b21
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22266 22206
diff changeset
44 import com.oracle.truffle.api.frame.FrameInstance;
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
45 import com.oracle.truffle.api.frame.MaterializedFrame;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
46 import com.oracle.truffle.api.impl.Accessor;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
47 import com.oracle.truffle.api.impl.FindContextNode;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
48 import com.oracle.truffle.api.instrument.ASTProber;
22220
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
49 import com.oracle.truffle.api.instrument.Instrumenter;
22443
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
50 import com.oracle.truffle.api.instrument.KillException;
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
51 import com.oracle.truffle.api.instrument.QuitException;
22261
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
52 import com.oracle.truffle.api.instrument.SyntaxTag;
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
53 import com.oracle.truffle.api.instrument.Visualizer;
22226
c896a8e70777 Truffle/Instrumentation:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22220
diff changeset
54 import com.oracle.truffle.api.instrument.WrapperNode;
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
55 import com.oracle.truffle.api.nodes.Node;
22268
b56fe0d3b560 Merge with acfea340b19199faaa44bd5e103c716c17ea2b21
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22266 22206
diff changeset
56 import com.oracle.truffle.api.nodes.RootNode;
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
57 import com.oracle.truffle.api.source.Source;
22443
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
58
22284
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
59 import java.util.Objects;
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
60
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
61 /**
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
62 * An entry point for everyone who wants to implement a Truffle based language. By providing an
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
63 * implementation of this type and registering it using {@link Registration} annotation, your
22172
b31dcacfc8ff Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
64 * language becomes accessible to users of the {@link com.oracle.truffle.api.vm.PolyglotEngine
b31dcacfc8ff Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
65 * polyglot execution engine} - all they will need to do is to include your JAR into their
b31dcacfc8ff Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
66 * application and all the Truffle goodies (multi-language support, multitenant hosting, debugging,
b31dcacfc8ff Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
67 * etc.) will be made available to them.
22261
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
68 * <p>
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
69 * The use of {@linkplain Instrumenter Instrument-based services} requires that the language
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
70 * {@linkplain Instrumenter#registerASTProber(com.oracle.truffle.api.instrument.ASTProber) register}
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
71 * an instance of {@link ASTProber} suitable for the language implementation that can be applied to
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
72 * "mark up" each newly created AST with {@link SyntaxTag "tags"} that identify standard syntactic
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
73 * constructs in order to configure tool behavior. See also {@linkplain #createContext(Env)
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
74 * createContext(Env)}.
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
75 *
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
76 * @param <C> internal state of the language associated with every thread that is executing program
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
77 * {@link #parse(com.oracle.truffle.api.source.Source, com.oracle.truffle.api.nodes.Node, java.lang.String...)
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
78 * parsed} by the language
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
79 */
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: 22110
diff changeset
80 @SuppressWarnings("javadoc")
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
81 public abstract class TruffleLanguage<C> {
22285
58b0a3e41785 Addressing checkstyle lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22284
diff changeset
82 private final Map<Source, CallTarget> compiled = Collections.synchronizedMap(new WeakHashMap<Source, CallTarget>());
22283
bc0c838ba705 Cache the parsed sources par individual language to avoid obtaining CallTarget parsed by a different language.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22270
diff changeset
83
21481
bb51b9a142b3 Enforcing public, one parameter constructor for each TruffleLanguage by annotation processor and required call to super.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
84 /**
bb51b9a142b3 Enforcing public, one parameter constructor for each TruffleLanguage by annotation processor and required call to super.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
85 * Constructor to be called by subclasses.
bb51b9a142b3 Enforcing public, one parameter constructor for each TruffleLanguage by annotation processor and required call to super.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
86 */
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
87 protected TruffleLanguage() {
21481
bb51b9a142b3 Enforcing public, one parameter constructor for each TruffleLanguage by annotation processor and required call to super.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
88 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
89
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
90 /**
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: 22110
diff changeset
91 * The annotation to use to register your language to the
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
92 * {@link com.oracle.truffle.api.vm.PolyglotEngine Truffle} system. By annotating your
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
93 * implementation of {@link TruffleLanguage} by this annotation you are just a
21649
1c76a5662753 Merge with 645f170013a451083414ff695412c465e9d2ebf0
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21557
diff changeset
94 * <em>one JAR drop to the class path</em> away from your users. Once they include your JAR 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: 22110
diff changeset
95 * their application, your language will be available to the
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
96 * {@link com.oracle.truffle.api.vm.PolyglotEngine Truffle virtual machine}.
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
97 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
98 @Retention(RetentionPolicy.SOURCE)
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
99 @Target(ElementType.TYPE)
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
100 public @interface Registration {
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
101 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
102 * Unique name of your language. This name will be exposed to users via the
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
103 * {@link com.oracle.truffle.api.vm.PolyglotEngine.Language#getName()} getter.
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
104 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
105 * @return identifier of your language
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
106 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
107 String name();
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
108
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
109 /**
21889
45083be8a812 Truffle: add a version string to the information provided with Language registration
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21716
diff changeset
110 * Unique string identifying the language version. This name will be exposed to users via
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
111 * the {@link com.oracle.truffle.api.vm.PolyglotEngine.Language#getVersion()} getter.
21889
45083be8a812 Truffle: add a version string to the information provided with Language registration
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21716
diff changeset
112 *
45083be8a812 Truffle: add a version string to the information provided with Language registration
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21716
diff changeset
113 * @return version of your language
45083be8a812 Truffle: add a version string to the information provided with Language registration
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21716
diff changeset
114 */
45083be8a812 Truffle: add a version string to the information provided with Language registration
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21716
diff changeset
115 String version();
45083be8a812 Truffle: add a version string to the information provided with Language registration
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21716
diff changeset
116
45083be8a812 Truffle: add a version string to the information provided with Language registration
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21716
diff changeset
117 /**
21649
1c76a5662753 Merge with 645f170013a451083414ff695412c465e9d2ebf0
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21557
diff changeset
118 * List of MIME types associated with your language. Users will use them (directly or
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: 22110
diff changeset
119 * indirectly) when
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
120 * {@link com.oracle.truffle.api.vm.PolyglotEngine#eval(com.oracle.truffle.api.source.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: 22110
diff changeset
121 * executing} their code snippets or their {@link Source files}.
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
122 *
21649
1c76a5662753 Merge with 645f170013a451083414ff695412c465e9d2ebf0
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21557
diff changeset
123 * @return array of MIME types assigned to your language files
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
124 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
125 String[] mimeType();
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
126 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
127
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
128 /**
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
129 * Creates internal representation of the executing context suitable for given environment. Each
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: 22110
diff changeset
130 * time the {@link TruffleLanguage language} is used by a new
22195
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
131 * {@link com.oracle.truffle.api.vm.PolyglotEngine} or in a new thread, the system calls this
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
132 * method to let the {@link TruffleLanguage language} prepare for <em>execution</em>. The
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
133 * returned execution context is completely language specific; it is however expected it will
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
134 * contain reference to here-in provided <code>env</code> and adjust itself according to
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
135 * parameters provided by the <code>env</code> object.
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
136 * <p>
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
137 * The standard way of accessing the here-in generated context is to create a {@link Node} and
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
138 * insert it into own AST hierarchy - use {@link #createFindContextNode()} to obtain the
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
139 * {@link Node findNode} and later {@link #findContext(com.oracle.truffle.api.nodes.Node)
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
140 * findContext(findNode)} to get back your language context.
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
141 *
22261
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
142 * If it is expected that any {@linkplain Instrumenter Instrumentation Services} or tools that
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
143 * depend on those services (e.g. the {@link Debugger}, then part of the preparation in the new
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
144 * context is to
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
145 * {@linkplain Instrumenter#registerASTProber(com.oracle.truffle.api.instrument.ASTProber)
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
146 * register} a "default" {@link ASTProber} for the language implementation. Instrumentation
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
147 * requires that this be available to "mark up" each newly created AST with
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
148 * {@linkplain SyntaxTag "tags"} that identify standard syntactic constructs in order to
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
149 * configure tool behavior.
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
150 *
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
151 * @param env the environment the language is supposed to operate in
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
152 * @return internal data of the language in given environment
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
153 */
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
154 protected abstract C createContext(Env env);
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
155
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
156 /**
22187
5dbc7e24390d Fixing the language. Adding 'the'.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22186
diff changeset
157 * Disposes the context created by
22183
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
158 * {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)}. A language can be asked
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
159 * by its user to <em>clean-up</em>. In such case the language is supposed to dispose any
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
160 * resources acquired before and <em>dispose</em> the <code>context</code> - e.g. render it
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
161 * useless for any future calls.
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
162 *
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
163 * @param context the context {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
164 * created by the language}
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
165 */
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
166 protected void disposeContext(C context) {
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
167 }
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
168
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
169 /**
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
170 * Parses the provided source and generates appropriate AST. The parsing should execute no user
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
171 * code, it should only create the {@link Node} tree to represent the source. The parsing may be
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
172 * performed in a context (specified as another {@link Node}) or without context. The
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
173 * {@code argumentNames} may contain symbolic names for actual parameters of the call to the
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
174 * returned value. The result should be a call target with method
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
175 * {@link CallTarget#call(java.lang.Object...)} that accepts as many arguments as were provided
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
176 * via the {@code argumentNames} array.
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
177 *
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
178 * @param code source code to parse
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
179 * @param context a {@link Node} defining context for the parsing
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
180 * @param argumentNames symbolic names for parameters of
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
181 * {@link CallTarget#call(java.lang.Object...)}
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
182 * @return a call target to invoke which also keeps in memory the {@link Node} tree representing
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
183 * just parsed <code>code</code>
22081
ff531952a91c Making sure IOException from TruffleLanguage.parse method is correctly propagated to TruffleVM.eval caller.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22070
diff changeset
184 * @throws IOException thrown when I/O or parsing goes wrong. Here-in thrown exception is
ff531952a91c Making sure IOException from TruffleLanguage.parse method is correctly propagated to TruffleVM.eval caller.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22070
diff changeset
185 * propagate to the user who called one of <code>eval</code> methods of
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
186 * {@link com.oracle.truffle.api.vm.PolyglotEngine}
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
187 */
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
188 protected abstract CallTarget parse(Source code, Node context, String... argumentNames) throws IOException;
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
189
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
190 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
191 * Called when some other language is seeking for a global symbol. This method is supposed to do
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
192 * lazy binding, e.g. there is no need to export symbols in advance, it is fine to wait until
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
193 * somebody asks for it (by calling this method).
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
194 * <p>
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
195 * The exported object can either be <code>TruffleObject</code> (e.g. a native object from the
21890
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
196 * other language) to support interoperability between languages, {@link String} or one of Java
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
197 * primitive wrappers ( {@link Integer}, {@link Double}, {@link Short}, {@link Boolean}, etc.).
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
198 * <p>
21890
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
199 * The way a symbol becomes <em>exported</em> is language dependent. In general it is preferred
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
200 * to make the export explicit - e.g. call some function or method to register an object under
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
201 * specific name. Some languages may however decide to support implicit export of symbols (for
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
202 * example from global scope, if they have one). However explicit exports should always be
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
203 * preferred. Implicitly exported object of some name should only be used when there is no
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
204 * explicit export under such <code>globalName</code>. To ensure so the infrastructure first
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
205 * asks all known languages for <code>onlyExplicit</code> symbols and only when none is found,
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
206 * it does one more round with <code>onlyExplicit</code> set to <code>false</code>.
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
207 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
208 * @param globalName the name of the global symbol to find
21716
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
209 * @param onlyExplicit should the language seek for implicitly exported object or only consider
2f9e4d984d16 Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21649
diff changeset
210 * the explicitly exported ones?
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
211 * @return an exported object or <code>null</code>, if the symbol does not represent anything
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
212 * meaningful in this language
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
213 */
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
214 protected abstract Object findExportedSymbol(C context, String globalName, boolean onlyExplicit);
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
215
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
216 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
217 * Returns global object for the language.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
218 * <p>
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
219 * The object is expected to be <code>TruffleObject</code> (e.g. a native object from the other
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
220 * language) but technically it can be one of Java primitive wrappers ({@link Integer},
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
221 * {@link Double}, {@link Short}, etc.).
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
222 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
223 * @return the global object or <code>null</code> if the language does not support such concept
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
224 */
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
225 protected abstract Object getLanguageGlobal(C context);
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
226
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
227 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
228 * Checks whether the object is provided by this language.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
229 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
230 * @param object the object to check
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
231 * @return <code>true</code> if this language can deal with such object in native way
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
232 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
233 protected abstract boolean isObjectOfLanguage(Object object);
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
234
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
235 /**
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
236 * Gets visualization services for language-specific information.
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
237 */
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
238 protected abstract Visualizer getVisualizer();
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
239
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
240 /**
22220
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
241 * Returns {@code true} for a node can be "instrumented" by
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
242 * {@linkplain Instrumenter#probe(Node) probing}.
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
243 * <p>
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
244 * <b>Note:</b> instrumentation requires a appropriate {@link WrapperNode}
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
245 *
22248
6d328e688339 Truffle/Instrumentation: Javadoc cleanup
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22247
diff changeset
246 * @see WrapperNode
22220
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
247 */
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
248 protected abstract boolean isInstrumentable(Node node);
21890
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
249
22220
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
250 /**
22247
c1c9c6d79f40 Truffle/Instrumentation: remove method Instrumenter.isInstrumentable()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22244
diff changeset
251 * For nodes in this language that are <em>instrumentable</em>, this method returns an
c1c9c6d79f40 Truffle/Instrumentation: remove method Instrumenter.isInstrumentable()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22244
diff changeset
252 * {@linkplain Node AST node} that:
22220
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
253 * <ol>
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
254 * <li>implements {@link WrapperNode};</li>
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
255 * <li>has the node argument as it's child; and</li>
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
256 * <li>whose type is safe for replacement of the node in the parent.</li>
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
257 * </ol>
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
258 *
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
259 * @return an appropriately typed {@link WrapperNode}
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
260 */
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
261 protected abstract WrapperNode createWrapperNode(Node node);
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
262
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
263 /**
22214
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
264 * Runs source code in a halted execution context, or at top level.
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
265 *
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
266 * @param source the code to run
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
267 * @param node node where execution halted, {@code null} if no execution context
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
268 * @param mFrame frame where execution halted, {@code null} if no execution context
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
269 * @return result of running the code in the context, or at top level if no execution context.
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
270 * @throws IOException if the evaluation cannot be performed
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
271 */
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
272 protected abstract Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws IOException;
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
273
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
274 /**
22284
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
275 * Generates language specific textual representation of a value. Each language may have special
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
276 * formating conventions - even primitive values may not follow the traditional Java formating
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
277 * rules. As such when
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
278 * {@link com.oracle.truffle.api.vm.PolyglotEngine.Value#as(java.lang.Class)
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
279 * value.as(String.class)} is requested, it consults the language that produced the value by
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
280 * calling this method. By default this method calls {@link Objects#toString(java.lang.Object)}.
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
281 *
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
282 * @param context the execution context for doing the conversion
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
283 * @param value the value to convert. Either primitive type or
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
284 * {@link com.oracle.truffle.api.interop.TruffleObject}
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
285 * @return textual representation of the value in this language
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
286 */
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
287 protected String toString(C context, Object value) {
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
288 return Objects.toString(value);
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
289 }
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
290
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
291 /**
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
292 * Allows a language implementor to create a node that can effectively lookup up the context
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
293 * associated with current execution. The context is created by
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
294 * {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)} method.
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
295 *
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
296 * @return node to be inserted into program to effectively find out current execution context
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
297 * for this language
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
298 */
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
299 @SuppressWarnings({"rawtypes", "unchecked"})
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
300 protected final Node createFindContextNode() {
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
301 final Class<? extends TruffleLanguage<?>> c = (Class<? extends TruffleLanguage<?>>) getClass();
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
302 return new FindContextNode(c);
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
303 }
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
304
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
305 /**
22195
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
306 * Uses the {@link #createFindContextNode()} node to obtain the current context. In case you
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
307 * don't care about performance (e.g. your are on a slow execution path), you can chain the
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
308 * calls directly as <code>findContext({@link #createFindContextNode()})</code> and forget the
09d91119929f Documenting the connection between createContext, createFindContextNode and findContext and a trick how to get to the context on a slow path
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22187
diff changeset
309 * node all together.
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
310 *
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
311 * @param n the node created by this language's {@link #createFindContextNode()}
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
312 * @return the context created by
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
313 * {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)} method at the
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
314 * beginning of the language execution
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
315 * @throws ClassCastException if the node has not been created by <code>this</code>.
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
316 * {@link #createFindContextNode()} method.
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
317 */
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
318 @SuppressWarnings({"rawtypes", "unchecked"})
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
319 protected final C findContext(Node n) {
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
320 FindContextNode fcn = (FindContextNode) n;
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
321 if (fcn.getLanguageClass() != getClass()) {
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
322 throw new ClassCastException();
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
323 }
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
324 return (C) fcn.executeFindContext();
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
325 }
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
326
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
327 private static final class LangCtx<C> {
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
328 final TruffleLanguage<C> lang;
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
329 final C ctx;
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
330
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
331 public LangCtx(TruffleLanguage<C> lang, Env env) {
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
332 this.lang = lang;
22133
c334865b9d42 Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22128
diff changeset
333 // following call verifies that Accessor.CURRENT_VM is provided
c334865b9d42 Make sure TruffleLanguage.createEnv is only called when Accessor.CURRENT_VM is known
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22128
diff changeset
334 assert API.findLanguage(null, null) == null;
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
335 this.ctx = lang.createContext(env);
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
336 }
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
337
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
338 Object findExportedSymbol(String globalName, boolean onlyExplicit) {
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
339 return lang.findExportedSymbol(ctx, globalName, onlyExplicit);
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
340 }
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
341
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
342 Object getLanguageGlobal() {
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
343 return lang.getLanguageGlobal(ctx);
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
344 }
22183
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
345
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
346 void dispose() {
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
347 lang.disposeContext(ctx);
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
348 }
22284
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
349
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
350 String toString(TruffleLanguage<?> language, Object obj) {
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
351 assert lang == language;
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
352 return lang.toString(ctx, obj);
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
353 }
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
354 }
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
355
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
356 /**
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
357 * Represents execution environment of the {@link TruffleLanguage}. Each active
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
358 * {@link TruffleLanguage} receives instance of the environment before any code is executed upon
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
359 * it. The environment has knowledge of all active languages and can exchange symbols between
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
360 * them.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
361 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
362 public static final class 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: 22110
diff changeset
363 private final Object vm;
22109
b5eaddcdf86a Calling Env.importSymbol from TruffleLanguage.createContext should be possible
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
364 private final TruffleLanguage<?> lang;
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
365 private final LangCtx<?> langCtx;
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
366 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
367 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
368 private final OutputStream out;
22237
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
369 private final Instrumenter instrumenter;
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
370
22237
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
371 Env(Object vm, TruffleLanguage<?> lang, OutputStream out, OutputStream err, InputStream in, Instrumenter instrumenter) {
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
372 this.vm = vm;
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
373 this.in = in;
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
374 this.err = err;
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
375 this.out = out;
22109
b5eaddcdf86a Calling Env.importSymbol from TruffleLanguage.createContext should be possible
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
376 this.lang = lang;
22237
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
377 this.instrumenter = instrumenter;
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
378 this.langCtx = new LangCtx<>(lang, this);
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
379 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
380
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
381 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
382 * Asks the environment to go through other registered languages and find whether they
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
383 * export global symbol of specified name. The expected return type is either
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
384 * <code>TruffleObject</code>, or one of wrappers of Java primitive types ({@link Integer},
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
385 * {@link Double}).
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
386 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
387 * @param globalName the name of the symbol to search for
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
388 * @return object representing the symbol or <code>null</code>
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
389 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
390 public Object importSymbol(String globalName) {
22109
b5eaddcdf86a Calling Env.importSymbol from TruffleLanguage.createContext should be possible
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
391 return API.importSymbol(vm, lang, globalName);
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
392 }
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
393
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
394 /**
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
395 * Input associated with {@link com.oracle.truffle.api.vm.PolyglotEngine} this language is
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
396 * being executed in.
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
397 *
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
398 * @return reader, never <code>null</code>
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
399 */
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
400 public 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
401 return 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
402 }
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
403
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
404 @Deprecated
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
405 public Reader stdIn() {
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
406 return new InputStreamReader(in);
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
407 }
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
408
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
409 /**
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
410 * Standard output writer for {@link com.oracle.truffle.api.vm.PolyglotEngine} this language
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
411 * is being executed in.
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
412 *
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
413 * @return writer, never <code>null</code>
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
414 */
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
415 public 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
416 return 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
417 }
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
418
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
419 @Deprecated
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
420 public Writer stdOut() {
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
421 return new OutputStreamWriter(out);
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
422 }
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
423
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
424 /**
22266
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
425 * Standard error writer for {@link com.oracle.truffle.api.vm.PolyglotEngine} this language
0d36601f233e Merge revised Instrumentation framework into the Polyglot API
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22195 22261
diff changeset
426 * is being executed in.
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
427 *
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
428 * @return writer, never <code>null</code>
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
429 */
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
430 public 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
431 return 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
432 }
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
433
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
434 @Deprecated
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
435 public Writer stdErr() {
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
436 return new OutputStreamWriter(err);
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
437 }
22237
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
438
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
439 public Instrumenter instrumenter() {
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
440 return instrumenter;
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
441 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
442 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
443
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
444 private static final AccessAPI API = new AccessAPI();
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
445
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
446 @SuppressWarnings("rawtypes")
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
447 private static final class AccessAPI extends Accessor {
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
448 @Override
22237
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
449 protected Env attachEnv(Object vm, TruffleLanguage<?> language, OutputStream stdOut, OutputStream stdErr, InputStream stdIn, Instrumenter instrumenter) {
c4e7737981d3 Truffle/Instrumentation: make the Instrumenter available to language implementations via Env.getInstrumenter()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22232
diff changeset
450 Env env = new Env(vm, language, stdOut, stdErr, stdIn, instrumenter);
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
451 return env;
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
452 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
453
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
454 @Override
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: 22110
diff changeset
455 protected Object importSymbol(Object vm, TruffleLanguage<?> queryingLang, String globalName) {
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
456 return super.importSymbol(vm, queryingLang, globalName);
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
457 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
458
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
459 @Override
22293
260e3cdf11ec Truffle/Instrumentation: replace (non-functional) AdvancedInstrument kind with new EvalInstrument
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22270
diff changeset
460 protected CallTarget parse(TruffleLanguage<?> truffleLanguage, Source code, Node context, String... argumentNames) throws IOException {
260e3cdf11ec Truffle/Instrumentation: replace (non-functional) AdvancedInstrument kind with new EvalInstrument
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22270
diff changeset
461 return truffleLanguage.parse(code, context, argumentNames);
260e3cdf11ec Truffle/Instrumentation: replace (non-functional) AdvancedInstrument kind with new EvalInstrument
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22270
diff changeset
462 }
260e3cdf11ec Truffle/Instrumentation: replace (non-functional) AdvancedInstrument kind with new EvalInstrument
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22270
diff changeset
463
260e3cdf11ec Truffle/Instrumentation: replace (non-functional) AdvancedInstrument kind with new EvalInstrument
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22270
diff changeset
464 @Override
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
465 protected Object eval(TruffleLanguage<?> language, Source source) throws IOException {
22285
58b0a3e41785 Addressing checkstyle lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22284
diff changeset
466 CallTarget target = language.compiled.get(source);
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
467 if (target == null) {
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
468 target = language.parse(source, null);
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
469 if (target == null) {
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
470 throw new IOException("Parsing has not produced a CallTarget for " + source);
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
471 }
22285
58b0a3e41785 Addressing checkstyle lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22284
diff changeset
472 language.compiled.put(source, target);
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
473 }
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
474 try {
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
475 return target.call();
22443
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
476 } catch (KillException | QuitException ex) {
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
477 throw ex;
22315
518f8ead5d01 Fix thread gets disposed on internal exception in PolyglotEngine.
Christian Humer <christian.humer@oracle.com>
parents: 22294
diff changeset
478 } catch (Throwable ex) {
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
479 throw new IOException(ex);
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
480 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
481 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
482
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
483 @Override
22206
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
484 protected Object evalInContext(Object vm, SuspendedEvent ev, String code, FrameInstance frame) throws IOException {
22446
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
485 Node n = ev.getNode();
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
486 if (n == null && frame != null) {
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
487 n = frame.getCallNode();
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
488 }
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
489 if (n == null) {
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
490 throw new IOException("Can't determine language for text \"" + code + "\"");
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
491 }
22206
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
492 RootNode rootNode = n.getRootNode();
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
493 Class<? extends TruffleLanguage> languageType = findLanguage(rootNode);
22446
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
494 final Env env = findLanguage(vm, languageType);
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
495 final TruffleLanguage<?> lang = findLanguage(env);
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
496 final Source source = Source.fromText(code, "eval in context");
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
497 return lang.evalInContext(source, n, frame.getFrame(null, true).materialize());
22206
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
498 }
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
499
22269
24fe7ae281e5 Truffle/Instrumentation: more adjustments to get tests to pass
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22268
diff changeset
500 @Override
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
501 protected Object findExportedSymbol(TruffleLanguage.Env env, String globalName, boolean onlyExplicit) {
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
502 return env.langCtx.findExportedSymbol(globalName, onlyExplicit);
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
503 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
504
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
505 @Override
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: 22110
diff changeset
506 protected Env findLanguage(Object vm, Class<? extends TruffleLanguage> languageClass) {
22046
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
507 return super.findLanguage(vm, languageClass);
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
508 }
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
509
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
510 @Override
22110
c2cb9f1c8688 Replacing the langClass.newInstance() hack in Debugger with proper way to obtain the language instance
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22109
diff changeset
511 protected TruffleLanguage<?> findLanguage(Env env) {
c2cb9f1c8688 Replacing the langClass.newInstance() hack in Debugger with proper way to obtain the language instance
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22109
diff changeset
512 return env.lang;
c2cb9f1c8688 Replacing the langClass.newInstance() hack in Debugger with proper way to obtain the language instance
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22109
diff changeset
513 }
c2cb9f1c8688 Replacing the langClass.newInstance() hack in Debugger with proper way to obtain the language instance
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22109
diff changeset
514
c2cb9f1c8688 Replacing the langClass.newInstance() hack in Debugger with proper way to obtain the language instance
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22109
diff changeset
515 @Override
22066
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
516 protected Object languageGlobal(TruffleLanguage.Env env) {
78c3d3d8d86e Clearly separating the TruffleLanguage definition from context used during its execution. TruffleLanguage now has to have public static field INSTANCE and override createContext method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22049
diff changeset
517 return env.langCtx.getLanguageGlobal();
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
518 }
21890
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
519
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
520 @Override
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
521 protected Object findContext(Env env) {
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
522 return env.langCtx.ctx;
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
523 }
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
524
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
525 @Override
22220
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
526 protected boolean isInstrumentable(Node node, TruffleLanguage language) {
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
527 return language.isInstrumentable(node);
21890
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
528 }
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
529
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
530 @Override
22220
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
531 protected WrapperNode createWrapperNode(Node node, TruffleLanguage language) {
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
532 return language.createWrapperNode(node);
21890
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
533 }
22183
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
534
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
535 @Override
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
536 protected void dispose(TruffleLanguage<?> impl, Env env) {
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
537 assert impl == env.langCtx.lang;
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
538 env.langCtx.dispose();
1421041175a7 Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22165
diff changeset
539 }
22284
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
540
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
541 @Override
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
542 protected String toString(TruffleLanguage<?> language, Env env, Object obj) {
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
543 return env.langCtx.toString(language, obj);
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
544 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
545 }
21890
894f82515e38 Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21889
diff changeset
546
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
547 }