annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java @ 22325:414e82b9fc35

Release 0.9 is out, let's remove deprecated elements from the API
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Fri, 23 Oct 2015 20:23:00 +0200
parents 518f8ead5d01
children dea950d41ef3 78594d342228 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.OutputStream;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
30 import java.lang.annotation.ElementType;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
31 import java.lang.annotation.Retention;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
32 import java.lang.annotation.RetentionPolicy;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22133
diff changeset
33 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
34 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
35 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
36 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
37
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
38 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
39 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
40 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
41 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
42 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
43 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
44 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
45 import com.oracle.truffle.api.instrument.Instrumenter;
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
46 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
47 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
48 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
49 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
50 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
51 import com.oracle.truffle.api.source.Source;
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
52 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
53
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
54 /**
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
55 * 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
56 * 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
57 * 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
58 * 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
59 * 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
60 * 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
61 * <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
62 * 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
63 * {@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
64 * 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
65 * "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
66 * 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
67 * createContext(Env)}.
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
68 *
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
69 * @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
70 * {@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
71 * 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
72 */
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
73 @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
74 public abstract class TruffleLanguage<C> {
22285
58b0a3e41785 Addressing checkstyle lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22284
diff changeset
75 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
76
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
77 /**
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
78 * 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
79 */
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
80 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
81 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
82
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
83 /**
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
84 * 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
85 * {@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
86 * 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
87 * <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
88 * 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
89 * {@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
90 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
91 @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
92 @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
93 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
94 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
95 * 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
96 * {@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
97 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
98 * @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
99 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
100 String name();
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 /**
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
103 * 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
104 * 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
105 *
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
106 * @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
107 */
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
108 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
109
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 /**
21649
1c76a5662753 Merge with 645f170013a451083414ff695412c465e9d2ebf0
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21557
diff changeset
111 * 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
112 * 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
113 * {@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
114 * 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
115 *
21649
1c76a5662753 Merge with 645f170013a451083414ff695412c465e9d2ebf0
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21557
diff changeset
116 * @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
117 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
118 String[] mimeType();
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
119 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
120
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
121 /**
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
122 * 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
123 * 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
124 * {@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
125 * 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
126 * 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
127 * 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
128 * 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
129 * <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
130 * 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
131 * 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
132 * {@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
133 * 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
134 *
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
135 * 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
136 * 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
137 * 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
138 * {@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
139 * 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
140 * 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
141 * {@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
142 * 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
143 *
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
144 * @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
145 * @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
146 */
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
147 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
148
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
149 /**
22187
5dbc7e24390d Fixing the language. Adding 'the'.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22186
diff changeset
150 * 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
151 * {@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
152 * 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
153 * 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
154 * 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
155 *
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
156 * @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
157 * 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
158 */
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 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
160 }
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
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 /**
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
163 * 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
164 * 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
165 * 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
166 * {@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
167 * 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
168 * {@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
169 * 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
170 *
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 * @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
172 * @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
173 * @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
174 * {@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
175 * @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
176 * 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
177 * @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
178 * 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
179 * {@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
180 */
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 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
182
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
183 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
184 * 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
185 * 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
186 * 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
187 * <p>
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
188 * 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
189 * 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
190 * 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
191 * <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
192 * 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
193 * 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
194 * 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
195 * 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
196 * 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
197 * 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
198 * 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
199 * 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
200 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
201 * @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
202 * @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
203 * 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
204 * @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
205 * 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
206 */
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
207 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
208
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
209 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
210 * 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
211 * <p>
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
212 * 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
213 * 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
214 * {@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
215 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
216 * @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
217 */
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
218 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
219
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
220 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
221 * 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
222 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
223 * @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
224 * @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
225 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
226 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
227
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
228 /**
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
229 * 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
230 */
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
231 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
232
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
233 /**
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
234 * 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
235 * {@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
236 * <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
237 * <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
238 *
22248
6d328e688339 Truffle/Instrumentation: Javadoc cleanup
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22247
diff changeset
239 * @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
240 */
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 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
242
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
243 /**
22247
c1c9c6d79f40 Truffle/Instrumentation: remove method Instrumenter.isInstrumentable()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22244
diff changeset
244 * 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
245 * {@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
246 * <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
247 * <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
248 * <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
249 * <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
250 * </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
251 *
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
252 * @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
253 */
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 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
255
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 /**
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
257 * 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
258 *
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
259 * @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
260 * @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
261 * @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
262 * @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
263 * @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
264 */
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 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
266
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 /**
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
268 * 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
269 * 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
270 * 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
271 * {@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
272 * 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
273 * 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
274 *
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 * @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
276 * @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
277 * {@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
278 * @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
279 */
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 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
281 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
282 }
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
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 /**
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
285 * 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
286 * associated with current execution. The context is created by
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
287 * {@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
288 *
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
289 * @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
290 * 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
291 */
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
292 @SuppressWarnings({"rawtypes", "unchecked"})
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
293 protected final Node createFindContextNode() {
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
294 final Class<? extends TruffleLanguage<?>> c = (Class<? extends TruffleLanguage<?>>) getClass();
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
295 return new FindContextNode(c);
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
296 }
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
297
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
298 /**
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
299 * 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
300 * 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
301 * 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
302 * node all together.
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
303 *
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
304 * @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
305 * @return the context created by
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
306 * {@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
307 * beginning of the language execution
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
308 * @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
309 * {@link #createFindContextNode()} method.
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
310 */
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
311 @SuppressWarnings({"rawtypes", "unchecked"})
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
312 protected final C findContext(Node n) {
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
313 FindContextNode fcn = (FindContextNode) n;
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
314 if (fcn.getLanguageClass() != getClass()) {
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
315 throw new ClassCastException();
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
316 }
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
317 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
318 }
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
319
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
320 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
321 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
322 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
323
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
324 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
325 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
326 // 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
327 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
328 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
329 }
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 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
332 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
333 }
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
334
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 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
336 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
337 }
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
338
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
339 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
340 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
341 }
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
342
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
343 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
344 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
345 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
346 }
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
347 }
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
348
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
349 /**
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
350 * 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
351 * {@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
352 * 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
353 * them.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
354 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
355 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
356 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
357 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
358 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
359 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
360 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
361 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
362 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
363
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
364 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
365 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
366 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
367 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
368 this.out = out;
22109
b5eaddcdf86a Calling Env.importSymbol from TruffleLanguage.createContext should be possible
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
369 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
370 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
371 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
372 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
373
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
374 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
375 * 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
376 * 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
377 * <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
378 * {@link Double}).
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 * @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
381 * @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
382 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
383 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
384 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
385 }
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
386
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
387 /**
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
388 * 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
389 * 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
390 *
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
391 * @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
392 */
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
393 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
394 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
395 }
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
396
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 /**
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
398 * 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
399 * 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
400 *
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
401 * @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
402 */
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
403 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
404 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
405 }
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
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 /**
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
408 * 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
409 * 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
410 *
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
411 * @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
412 */
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
413 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
414 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
415 }
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
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
417 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
418 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
419 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
420 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
421
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
422 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
423
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
424 @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
425 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
426 @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
427 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
428 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
429 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
430 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
431
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
432 @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
433 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
434 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
435 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
436
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
437 @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
438 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
439 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
440 }
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
441
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
442 @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
443 protected Object eval(TruffleLanguage<?> language, Source source) throws IOException {
22285
58b0a3e41785 Addressing checkstyle lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22284
diff changeset
444 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
445 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
446 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
447 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
448 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
449 }
22285
58b0a3e41785 Addressing checkstyle lints
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22284
diff changeset
450 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
451 }
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
452 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
453 return target.call();
22315
518f8ead5d01 Fix thread gets disposed on internal exception in PolyglotEngine.
Christian Humer <christian.humer@oracle.com>
parents: 22294
diff changeset
454 } 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
455 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
456 }
21468
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
22206
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
460 protected Object evalInContext(Object vm, SuspendedEvent ev, String code, FrameInstance frame) throws IOException {
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
461 Node n = frame == null ? ev.getNode() : frame.getCallNode();
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
462 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
463 Class<? extends TruffleLanguage> languageType = findLanguage(rootNode);
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
464 Env env = findLanguage(vm, languageType);
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
465 TruffleLanguage<?> lang = findLanguage(env);
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
466 Source source = Source.fromText(code, "eval in context");
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
467 CallTarget target = lang.parse(source, n);
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
468 return target.call();
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
469 }
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
470
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
471 @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
472 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
473 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
474 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
475
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
476 @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
477 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
478 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
479 }
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
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
481 @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
482 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
483 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
484 }
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
485
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
486 @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
487 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
488 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
489 }
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
490
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
491 @Override
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
492 protected Object findContext(Env env) {
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
493 return env.langCtx.ctx;
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
494 }
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
495
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
496 @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
497 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
498 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
499 }
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
500
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
501 @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
502 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
503 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
504 }
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
505
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
506 @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
507 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
508 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
509 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
510 }
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
511
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
512 @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
513 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
514 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
515 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
516 }
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
517
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
518 }