annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java @ 22548:6b76a24fffbd default tip

Use all variables: a, b, u,v and x, y
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 14 Jan 2016 14:20:57 +0100
parents e4dd15f04c7d
children
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.Map;
22471
a6c162686d81 Truffle/Language&Debugger: reimplement completely how the execution stack is gathered and communicated; change the signature of TruffelLanguage.evalInContext() to comply.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22467
diff changeset
35 import java.util.Objects;
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
36
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
37 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
38 import com.oracle.truffle.api.debug.SuspendedEvent;
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
39 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
40 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
41 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
42 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
43 import com.oracle.truffle.api.instrument.Instrumenter;
22443
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
44 import com.oracle.truffle.api.instrument.KillException;
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
45 import com.oracle.truffle.api.instrument.QuitException;
22261
b73205fe7cf3 Truffle/Instrumentation: remove the abstract method TruffleLanguage.getDefaultASTProber() around issues of timing in the Engine and language startup sequences. TruffleLanguage implementations requiring any Instrumentation services are now required to register (at least) the languages "default" ASTProber for configuring tool behavior; this must be done before any RootNotes are created.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22248
diff changeset
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;
22443
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
52
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
53 /**
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
54 * 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
55 * 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
56 * 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
57 * 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
58 * 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
59 * 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
60 * <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
61 * 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
62 * {@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
63 * 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
64 * "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
65 * 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
66 * createContext(Env)}.
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
67 *
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
68 * @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
69 * {@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
70 * 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
71 */
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
72 @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
73 public abstract class TruffleLanguage<C> {
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
74 /**
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
75 * 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
76 */
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
77 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
78 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
79
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
80 /**
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
81 * 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
82 * {@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
83 * 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
84 * <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
85 * 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
86 * {@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
87 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
88 @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
89 @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
90 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
91 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
92 * 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
93 * {@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
94 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
95 * @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
96 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
97 String name();
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
98
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
99 /**
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
100 * 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
101 * 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
102 *
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 * @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
104 */
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 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
106
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 /**
21649
1c76a5662753 Merge with 645f170013a451083414ff695412c465e9d2ebf0
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21557
diff changeset
108 * 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
109 * 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
110 * {@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
111 * 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
112 *
21649
1c76a5662753 Merge with 645f170013a451083414ff695412c465e9d2ebf0
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 21557
diff changeset
113 * @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
114 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
115 String[] mimeType();
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
116 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
117
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
118 /**
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
119 * 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
120 * 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
121 * {@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
122 * 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
123 * 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
124 * 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
125 * 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
126 * <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
127 * 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
128 * 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
129 * {@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
130 * 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
131 *
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
132 * 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
133 * 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
134 * 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
135 * {@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
136 * 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
137 * 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
138 * {@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
139 * 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
140 *
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
141 * @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
142 * @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
143 */
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 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
145
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
146 /**
22187
5dbc7e24390d Fixing the language. Adding 'the'.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22186
diff changeset
147 * 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
148 * {@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
149 * 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
150 * 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
151 * 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
152 *
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 * @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
154 * 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
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 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
157 }
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 /**
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
160 * Parses the provided source and generates appropriate AST. The parsing should execute no user
22391
5938e5eb3867 Clarify comment of TruffleLanguage.parse() for implementers
Stefan Marr <stefan.marr@jku.at>
parents: 22388
diff changeset
161 * code, it should only create the {@link Node} tree to represent the source. If the provided
5938e5eb3867 Clarify comment of TruffleLanguage.parse() for implementers
Stefan Marr <stefan.marr@jku.at>
parents: 22388
diff changeset
162 * source does not correspond naturally to a call target, the returned call target should create
5938e5eb3867 Clarify comment of TruffleLanguage.parse() for implementers
Stefan Marr <stefan.marr@jku.at>
parents: 22388
diff changeset
163 * and if necessary initialize the corresponding language entity and return it. The parsing may
5938e5eb3867 Clarify comment of TruffleLanguage.parse() for implementers
Stefan Marr <stefan.marr@jku.at>
parents: 22388
diff changeset
164 * be performed in a context (specified as another {@link Node}) or without context. The
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
165 * {@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
166 * 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
167 * {@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
168 * 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
169 *
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 * @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
171 * @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
172 * @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
173 * {@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
174 * @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
175 * 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
176 * @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
177 * 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
178 * {@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
179 */
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 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
181
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 * 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
184 * 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
185 * 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
186 * <p>
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
187 * 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
188 * 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
189 * 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
190 * <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
191 * 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
192 * 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
193 * 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
194 * 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
195 * 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
196 * 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
197 * 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
198 * 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
199 *
22384
2acc64b45848 Documentation for additional arguments
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22383
diff changeset
200 * @param context context to locate the global symbol in
21468
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 *
22384
2acc64b45848 Documentation for additional arguments
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22383
diff changeset
216 * @param context context to find the language global in
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
217 * @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
218 */
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
219 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
220
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
221 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
222 * 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
223 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
224 * @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
225 * @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
226 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
227 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
228
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
229 /**
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
230 * 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
231 */
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 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
233
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
234 /**
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
235 * 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
236 * {@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
237 * <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
238 * <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
239 *
22248
6d328e688339 Truffle/Instrumentation: Javadoc cleanup
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22247
diff changeset
240 * @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
241 */
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
242 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
243
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
244 /**
22247
c1c9c6d79f40 Truffle/Instrumentation: remove method Instrumenter.isInstrumentable()
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22244
diff changeset
245 * 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
246 * {@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
247 * <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
248 * <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
249 * <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
250 * <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
251 * </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
252 *
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 * @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
254 */
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 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
256
20380d1d41f2 Truffle/Instrumentation: second merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22219
diff changeset
257 /**
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
258 * 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
259 *
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 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
261 * @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
262 * @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
263 * @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
264 * @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
265 */
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
266 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
267
3aad794eec0e Truffle/Instrumentation: first large merge of instrumentation code into the TruffleVM framework
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22133
diff changeset
268 /**
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
269 * 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
270 * 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
271 * 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
272 * {@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
273 * 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
274 * 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
275 *
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 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
277 * @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
278 * {@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
279 * @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
280 */
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 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
282 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
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
33d49924a921 PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22283
diff changeset
285 /**
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
286 * 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
287 * associated with current execution. The context is created by
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
288 * {@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
289 *
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
290 * @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
291 * 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
292 */
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
293 @SuppressWarnings({"rawtypes", "unchecked"})
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
294 protected final Node createFindContextNode() {
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
295 final Class<? extends TruffleLanguage<?>> c = (Class<? extends TruffleLanguage<?>>) getClass();
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
296 return new FindContextNode(c);
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
297 }
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
298
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
299 /**
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
300 * 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
301 * 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
302 * 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
303 * node all together.
22094
0058a9461865 Truffle/instrumentation: minor Javadoc fixes
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22081
diff changeset
304 *
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
305 * @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
306 * @return the context created by
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
307 * {@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
308 * beginning of the language execution
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
309 * @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
310 * {@link #createFindContextNode()} method.
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
311 */
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
312 @SuppressWarnings({"rawtypes", "unchecked"})
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
313 protected final C findContext(Node n) {
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
314 FindContextNode fcn = (FindContextNode) n;
22070
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
315 if (fcn.getLanguageClass() != getClass()) {
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
316 throw new ClassCastException();
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
317 }
a7ca9e9a1d51 Removing VirtualFrame parameter. Documenting.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22068
diff changeset
318 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
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
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 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
322 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
323 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
324
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 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
326 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
327 // 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
328 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
329 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
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
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 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
333 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
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
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 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
337 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
338 }
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
339
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 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
341 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
342 }
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
343
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 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
345 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
346 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
347 }
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
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
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
350 /**
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
351 * 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
352 * {@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
353 * 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
354 * them.
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
355 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
356 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
357 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
358 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
359 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
360 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
361 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
362 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
363 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
364
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
365 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
366 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
367 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
368 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
369 this.out = out;
22109
b5eaddcdf86a Calling Env.importSymbol from TruffleLanguage.createContext should be possible
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
370 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
371 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
372 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
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 /**
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
376 * 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
377 * 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
378 * <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
379 * {@link Double}).
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
380 *
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
381 * @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
382 * @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
383 */
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
384 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
385 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
386 }
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
387
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
388 /**
22375
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
389 * Evaluates source of (potentially different) language. The {@link Source#getMimeType()
22383
37fabf84537a Correcting typo in Javadoc
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22382
diff changeset
390 * MIME type} is used to identify the {@link TruffleLanguage} to use to perform the
22382
fb607f23d1eb Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22380
diff changeset
391 * {@link #parse(com.oracle.truffle.api.source.Source, com.oracle.truffle.api.nodes.Node, java.lang.String...)}
fb607f23d1eb Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22380
diff changeset
392 * . The names of arguments are parameters for the resulting {#link CallTarget} that allow
fb607f23d1eb Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22380
diff changeset
393 * the <code>source</code> to reference the actual parameters passed to
fb607f23d1eb Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22380
diff changeset
394 * {@link CallTarget#call(java.lang.Object...)}.
22471
a6c162686d81 Truffle/Language&Debugger: reimplement completely how the execution stack is gathered and communicated; change the signature of TruffelLanguage.evalInContext() to comply.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22467
diff changeset
395 *
22375
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
396 * @param source the source to evaluate
22382
fb607f23d1eb Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22380
diff changeset
397 * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments
fb607f23d1eb Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22380
diff changeset
398 * that can be referenced from the source
22377
a765d165e7ec Give languages a chance to separate (and optimize) parsing and evaluation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22375
diff changeset
399 * @return the call target representing the parsed result
22375
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
400 * @throws IOException if the parsing or evaluation fails for some reason
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
401 */
22378
06bdf4a43126 Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22377
diff changeset
402 public CallTarget parse(Source source, String... argumentNames) throws IOException {
22375
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
403 TruffleLanguage<?> language = API.findLanguageImpl(vm, null, source.getMimeType());
22378
06bdf4a43126 Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22377
diff changeset
404 return language.parse(source, null, argumentNames);
22375
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
405 }
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
406
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
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 * 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
409 * 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 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
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 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
414 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
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
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
417 /**
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
418 * 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
419 * 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
420 *
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
421 * @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
422 */
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
423 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
424 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
425 }
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
426
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21481
diff changeset
427 /**
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
428 * 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
429 * 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
430 *
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
431 * @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
432 */
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
433 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
434 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
435 }
67f75f61c974 Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22157
diff changeset
436
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
437 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
438 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
439 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
440 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
441
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
442 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
443
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
444 @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
445 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
446 @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
447 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
448 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
449 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
450 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
451
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
452 @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
453 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
454 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
455 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
456
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
457 @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
458 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
459 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
460 }
260e3cdf11ec Truffle/Instrumentation: replace (non-functional) AdvancedInstrument kind with new EvalInstrument
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22270
diff changeset
461
260e3cdf11ec Truffle/Instrumentation: replace (non-functional) AdvancedInstrument kind with new EvalInstrument
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22270
diff changeset
462 @Override
22386
086776aa7548 Caching Source -> CallTarget mapping per PolyglotEngine.Language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22384
diff changeset
463 protected Object eval(TruffleLanguage<?> language, Source source, Map<Source, CallTarget> cache) throws IOException {
086776aa7548 Caching Source -> CallTarget mapping per PolyglotEngine.Language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22384
diff changeset
464 CallTarget target = cache.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
465 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
466 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
467 if (target == null) {
e7c2d36daf72 TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
468 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
469 }
22386
086776aa7548 Caching Source -> CallTarget mapping per PolyglotEngine.Language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22384
diff changeset
470 cache.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
471 }
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
472 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
473 return target.call();
22443
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
474 } catch (KillException | QuitException ex) {
2e5ac2d13d84 Truffle/Instrumentation: add missing handling of a debugging-related exception
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22315
diff changeset
475 throw ex;
22315
518f8ead5d01 Fix thread gets disposed on internal exception in PolyglotEngine.
Christian Humer <christian.humer@oracle.com>
parents: 22294
diff changeset
476 } 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
477 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
478 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
479 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
480
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
481 @Override
22471
a6c162686d81 Truffle/Language&Debugger: reimplement completely how the execution stack is gathered and communicated; change the signature of TruffelLanguage.evalInContext() to comply.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22467
diff changeset
482 protected Object evalInContext(Object vm, SuspendedEvent ev, String code, Node node, MaterializedFrame frame) throws IOException {
a6c162686d81 Truffle/Language&Debugger: reimplement completely how the execution stack is gathered and communicated; change the signature of TruffelLanguage.evalInContext() to comply.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22467
diff changeset
483 RootNode rootNode = node.getRootNode();
22206
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
484 Class<? extends TruffleLanguage> languageType = findLanguage(rootNode);
22446
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
485 final Env env = findLanguage(vm, languageType);
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
486 final TruffleLanguage<?> lang = findLanguage(env);
5b6e15432aae Truffle/debugging: minor changes to get "eval" working correctly in some cases
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22443
diff changeset
487 final Source source = Source.fromText(code, "eval in context");
22471
a6c162686d81 Truffle/Language&Debugger: reimplement completely how the execution stack is gathered and communicated; change the signature of TruffelLanguage.evalInContext() to comply.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22467
diff changeset
488 return lang.evalInContext(source, node, frame);
22206
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
489 }
dc91e9ee752e SuspendedEvent.eval to let debugger evaluate variables in currently suspended execution context
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22195
diff changeset
490
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
491 @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
492 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
493 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
494 }
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
495
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
496 @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
497 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
498 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
499 }
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
500
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
501 @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
502 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
503 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
504 }
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
505
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
506 @Override
22375
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
507 protected TruffleLanguage<?> findLanguageImpl(Object known, Class<? extends TruffleLanguage> languageClass, String mimeType) {
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
508 return super.findLanguageImpl(known, languageClass, mimeType);
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
509 }
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
510
78594d342228 Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22325
diff changeset
511 @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
512 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
513 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
514 }
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
515
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
516 @Override
22068
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
517 protected Object findContext(Env env) {
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
518 return env.langCtx.ctx;
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
519 }
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
520
fec8f8a61f6c Introducing FindContextNode
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22066
diff changeset
521 @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
522 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
523 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
524 }
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
525
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
526 @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
527 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
528 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
529 }
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
530
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
531 @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
532 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
533 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
534 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
535 }
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
536
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
537 @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
538 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
539 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
540 }
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
541 }
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
542
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
543 }