Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java @ 22003:5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Sat, 18 Jul 2015 18:03:36 +0200 |
parents | c07e64ecb528 |
children | e7c2d36daf72 |
rev | line source |
---|---|
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
5 * The Universal Permissive License (UPL), Version 1.0 |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
6 * |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
7 * Subject to the condition set forth below, permission is hereby granted to any |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
8 * person obtaining a copy of this software, associated documentation and/or |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
9 * data (collectively the "Software"), free of charge and under any and all |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
10 * copyright rights in the Software, and any and all patent rights owned or |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
11 * freely licensable by each licensor hereunder covering either (i) the |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
12 * unmodified Software as contributed to or provided by such licensor, or (ii) |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
13 * the Larger Works (as defined below), to deal in both |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
14 * |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
15 * (a) the Software, and |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
16 * |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
17 * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
18 * one is included with the Software each a "Larger Work" to which the Software |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
19 * is contributed by such licensors), |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
20 * |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
21 * without restriction, including without limitation the rights to copy, create |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
22 * derivative works of, display, perform, and distribute the Software and make, |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
23 * use, sell, offer for sale, import, export, have made, and have sold the |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
24 * Software and the Larger Work(s), and to sublicense the foregoing rights on |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
25 * either these or other terms. |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
26 * |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
27 * This license is subject to the following condition: |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
28 * |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
29 * The above copyright notice and either this complete permission notice or at a |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
30 * minimum a reference to the UPL must be included in all copies or substantial |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
31 * portions of the Software. |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
32 * |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
39 * SOFTWARE. |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 */ |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 package com.oracle.truffle.sl.runtime; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 import java.io.*; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
15891
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15064
diff
changeset
|
45 import com.oracle.truffle.api.*; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
46 import com.oracle.truffle.api.dsl.*; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
47 import com.oracle.truffle.api.frame.*; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
48 import com.oracle.truffle.api.nodes.*; |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
49 import com.oracle.truffle.api.object.*; |
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
16512
diff
changeset
|
50 import com.oracle.truffle.api.source.*; |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
51 import com.oracle.truffle.sl.SLLanguage; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 import com.oracle.truffle.sl.builtins.*; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
53 import com.oracle.truffle.sl.nodes.*; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
54 import com.oracle.truffle.sl.nodes.local.*; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
55 import com.oracle.truffle.sl.parser.*; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
57 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
58 * The run-time state of SL during execution. One context is instantiated before any source code is |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
59 * parsed, and this context is passed around to all methods that need access to it. For example, the |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
60 * context is used during {@link SLNodeFactory parsing} and by {@link SLBuiltinNode#getContext() |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
61 * builtin functions}. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
62 * <p> |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13836
diff
changeset
|
63 * It would be an error to have two different context instances during the execution of one script. |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13836
diff
changeset
|
64 * However, if two separate scripts run in one Java VM at the same time, they have a different |
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13836
diff
changeset
|
65 * context. Therefore, the context is not a singleton. |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
66 */ |
15891
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15064
diff
changeset
|
67 public final class SLContext extends ExecutionContext { |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
68 private static final Layout LAYOUT = Layout.createLayout(); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
69 |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
70 private final SLLanguage language; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
71 private final BufferedReader input; |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18762
diff
changeset
|
72 private final PrintWriter output; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
73 private final SLFunctionRegistry functionRegistry; |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
74 private final Shape emptyShape; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
76 public SLContext(SLLanguage language, BufferedReader input, PrintWriter output) { |
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
77 this.language = language; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
78 this.input = input; |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
79 this.output = output; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 this.functionRegistry = new SLFunctionRegistry(); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
81 installBuiltins(); |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
82 |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
83 this.emptyShape = LAYOUT.createShape(new ObjectType()); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
84 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
85 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
86 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
87 * Returns the default input, i.e., the source for the {@link SLReadlnBuiltin}. To allow unit |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
88 * testing, we do not use {@link System#in} directly. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
89 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
90 public BufferedReader getInput() { |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
91 return input; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
92 } |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
93 |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
94 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
95 * The default default, i.e., the output for the {@link SLPrintlnBuiltin}. To allow unit |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
96 * testing, we do not use {@link System#out} directly. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
97 */ |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18762
diff
changeset
|
98 public PrintWriter getOutput() { |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
99 return output; |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
102 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
103 * Returns the registry of all functions that are currently defined. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
104 */ |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 public SLFunctionRegistry getFunctionRegistry() { |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 return functionRegistry; |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 } |
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 |
22003
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
109 public SLLanguage getLanguage() { |
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
110 return language; |
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
111 } |
5bc7f7b867ab
Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21997
diff
changeset
|
112 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
113 /** |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
114 * Adds all builtin functions to the {@link SLFunctionRegistry}. This method lists all |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
115 * {@link SLBuiltinNode builtin implementation classes}. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
116 */ |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
117 private void installBuiltins() { |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
118 installBuiltin(SLReadlnBuiltinFactory.getInstance()); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
119 installBuiltin(SLPrintlnBuiltinFactory.getInstance()); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
120 installBuiltin(SLNanoTimeBuiltinFactory.getInstance()); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
121 installBuiltin(SLDefineFunctionBuiltinFactory.getInstance()); |
15064
f675818d9ad0
new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
13882
diff
changeset
|
122 installBuiltin(SLStackTraceBuiltinFactory.getInstance()); |
f675818d9ad0
new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents:
13882
diff
changeset
|
123 installBuiltin(SLHelloEqualsWorldBuiltinFactory.getInstance()); |
17003
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
16960
diff
changeset
|
124 installBuiltin(SLAssertTrueBuiltinFactory.getInstance()); |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
16960
diff
changeset
|
125 installBuiltin(SLAssertFalseBuiltinFactory.getInstance()); |
18411
dc2e000bed40
SL: add basic support for creating objects and accessing properties
Andreas Woess <andreas.woess@jku.at>
parents:
17003
diff
changeset
|
126 installBuiltin(SLNewObjectBuiltinFactory.getInstance()); |
13455
69d2e4baa215
Truffle: new infrastructure related to instrumentation, and in particular debugging: support for managing Source objects; framework for generalized "instrumentation proxy nodes" (to be inserted into ASTs with no runtime cost when inactive), and "probes" (which can be attached to proxy nodes to receive event notification); a rudimentary interface and abstract implementation for a "debug manager" (mostly a placeholder at this point); and the beginning of a language-agnostic ExecutionContext interface.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
12752
diff
changeset
|
127 } |
69d2e4baa215
Truffle: new infrastructure related to instrumentation, and in particular debugging: support for managing Source objects; framework for generalized "instrumentation proxy nodes" (to be inserted into ASTs with no runtime cost when inactive), and "probes" (which can be attached to proxy nodes to receive event notification); a rudimentary interface and abstract implementation for a "debug manager" (mostly a placeholder at this point); and the beginning of a language-agnostic ExecutionContext interface.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
12752
diff
changeset
|
128 |
17003
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
16960
diff
changeset
|
129 public void installBuiltin(NodeFactory<? extends SLBuiltinNode> factory) { |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
130 /* |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
131 * The builtin node factory is a class that is automatically generated by the Truffle DSL. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
132 * The signature returned by the factory reflects the signature of the @Specialization |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
133 * methods in the builtin classes. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
134 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
135 int argumentCount = factory.getExecutionSignature().size(); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
136 SLExpressionNode[] argumentNodes = new SLExpressionNode[argumentCount]; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
137 /* |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
138 * Builtin functions are like normal functions, i.e., the arguments are passed in as an |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
139 * Object[] array encapsulated in SLArguments. A SLReadArgumentNode extracts a parameter |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
140 * from this array. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
141 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
142 for (int i = 0; i < argumentCount; i++) { |
16512
abe7128ca473
SL: upgrade source attribution
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15891
diff
changeset
|
143 argumentNodes[i] = new SLReadArgumentNode(null, i); |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
144 } |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
145 /* Instantiate the builtin node. This node performs the actual functionality. */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
146 SLBuiltinNode builtinBodyNode = factory.createNode(argumentNodes, this); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
147 /* The name of the builtin function is specified via an annotation on the node class. */ |
18762
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
148 String name = lookupNodeInfo(builtinBodyNode.getClass()).shortName(); |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
149 /* Wrap the builtin in a RootNode. Truffle requires all AST to start with a RootNode. */ |
16958
997899955e72
Instrumentation: removed ExecutionContext parameter from probe method in Instrumentable
David Piorkowski <david.piorkowski@oracle.com>
parents:
16880
diff
changeset
|
150 SLRootNode rootNode = new SLRootNode(this, new FrameDescriptor(), builtinBodyNode, name); |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
151 |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
152 /* Register the builtin function in our function registry. */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
153 getFunctionRegistry().register(name, rootNode); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
154 } |
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
16512
diff
changeset
|
155 |
18762
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
156 public static NodeInfo lookupNodeInfo(Class<?> clazz) { |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
157 if (clazz == null) { |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
158 return null; |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
159 } |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
160 NodeInfo info = clazz.getAnnotation(NodeInfo.class); |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
161 if (info != null) { |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
162 return info; |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
163 } else { |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
164 return lookupNodeInfo(clazz.getSuperclass()); |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
165 } |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
166 } |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
167 |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
16595
diff
changeset
|
168 /** |
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:
21490
diff
changeset
|
169 * Evaluate a source, causing any definitions to be registered (but not executed). |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
16595
diff
changeset
|
170 * |
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:
21490
diff
changeset
|
171 * @param source The {@link Source} to parse. |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
16595
diff
changeset
|
172 */ |
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:
21490
diff
changeset
|
173 public void evalSource(Source source) { |
16880
7661cc464239
Truffle/Instrumentation: Added Instrumentable interface and LineLocationToSourceSections map
David Piorkowski <david.piorkowski@oracle.com>
parents:
16702
diff
changeset
|
174 Parser.parseSL(this, source); |
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
16512
diff
changeset
|
175 } |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
176 |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
177 public DynamicObject createObject() { |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
178 return LAYOUT.newInstance(emptyShape); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
179 } |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
180 |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
181 public static boolean isSLObject(Object value) { |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
182 return LAYOUT.getType().isInstance(value); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
183 } |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
184 |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
185 public static DynamicObject castSLObject(Object value) { |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
186 return LAYOUT.getType().cast(value); |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
187 } |
12752
71991b7a0f14
SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
188 } |