annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java @ 16702:2a5ec181dad4

SL: Added instrumentation testing
author David Piorkowski <david.piorkowski@oracle.com>
date Tue, 05 Aug 2014 16:34:08 -0700
parents 618d92152d3c
children 7661cc464239
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 *
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
5 * This code is free software; you can redistribute it and/or modify it
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
6 * under the terms of the GNU General Public License version 2 only, as
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
7 * published by the Free Software Foundation.
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
8 *
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
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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
12 * version 2 for more details (a copy is included in the LICENSE file that
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
13 * accompanied this code).
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
14 *
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
15 * You should have received a copy of the GNU General Public License version
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
16 * 2 along with this work; if not, write to the Free Software Foundation,
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
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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
18 *
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
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
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
20 * or visit www.oracle.com if you need additional information or have any
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
21 * questions.
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
22 */
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
23 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
24
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
25 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
26
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
27 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
28 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
29 import com.oracle.truffle.api.frame.*;
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
30 import com.oracle.truffle.api.instrument.*;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
31 import com.oracle.truffle.api.nodes.*;
16595
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
32 import com.oracle.truffle.api.source.*;
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
33 import com.oracle.truffle.sl.*;
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
34 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
35 import com.oracle.truffle.sl.nodes.*;
16595
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
36 import com.oracle.truffle.sl.nodes.instrument.*;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
37 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
38 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
39
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
40 /**
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
41 * 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
42 * 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
43 * 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
44 * builtin functions}.
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
45 * <p>
13882
afd6fa5e8229 SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13836
diff changeset
46 * 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
47 * 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
48 * 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
49 */
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
50 public final class SLContext extends ExecutionContext {
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
51 private final BufferedReader input;
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13455
diff changeset
52 private final PrintStream 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
53 private final SLFunctionRegistry functionRegistry;
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
54 private SourceCallback sourceCallback = null;
16595
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
55 private SLASTProber astProber;
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
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
57 public SLContext(BufferedReader input, PrintStream output) {
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
58 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
59 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
60 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
61 installBuiltins();
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13455
diff changeset
62 }
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13455
diff changeset
63
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
64 @Override
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
65 public String getLanguageShortName() {
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
66 return "Simple";
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
67 }
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
68
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
69 @Override
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
70 public void setSourceCallback(SourceCallback sourceCallback) {
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
71 this.sourceCallback = sourceCallback;
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
72 }
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
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
74 /**
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
75 * 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
76 * 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
77 */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
78 public BufferedReader getInput() {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
79 return input;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
80 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
81
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
82 /**
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
83 * 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
84 * 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
85 */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
86 public PrintStream getOutput() {
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13455
diff changeset
87 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
88 }
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
89
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
90 /**
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
91 * 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
92 */
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
93 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
94 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
95 }
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
96
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
97 public SourceCallback getSourceCallback() {
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
98 return sourceCallback;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
99 }
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 15064
diff changeset
100
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
101 /**
13836
64c77f0577bb More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13821
diff changeset
102 * 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
103 * {@link SLBuiltinNode builtin implementation classes}.
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
104 */
13761
7c418666c6c9 Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13455
diff changeset
105 private void installBuiltins() {
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
106 installBuiltin(SLReadlnBuiltinFactory.getInstance());
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
107 installBuiltin(SLPrintlnBuiltinFactory.getInstance());
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
108 installBuiltin(SLNanoTimeBuiltinFactory.getInstance());
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
109 installBuiltin(SLDefineFunctionBuiltinFactory.getInstance());
15064
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13882
diff changeset
110 installBuiltin(SLStackTraceBuiltinFactory.getInstance());
f675818d9ad0 new getStackTrace and getCurrentFrame functionality in TruffleRuntime
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13882
diff changeset
111 installBuiltin(SLHelloEqualsWorldBuiltinFactory.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
112 }
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
113
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
114 private void installBuiltin(NodeFactory<? extends SLBuiltinNode> factory) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
115 /*
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
116 * 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
117 * 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
118 * methods in the builtin classes.
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
119 */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
120 int argumentCount = factory.getExecutionSignature().size();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
121 SLExpressionNode[] argumentNodes = new SLExpressionNode[argumentCount];
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
122 /*
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
123 * 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
124 * 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
125 * from this array.
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
126 */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
127 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
128 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
129 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
130 /* 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
131 SLBuiltinNode builtinBodyNode = factory.createNode(argumentNodes, this);
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
132 /* The name of the builtin function is specified via an annotation on the node class. */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
133 String name = builtinBodyNode.getClass().getAnnotation(NodeInfo.class).shortName();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
134 /* Wrap the builtin in a RootNode. Truffle requires all AST to start with a RootNode. */
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
135 SLRootNode rootNode = new SLRootNode(new FrameDescriptor(), builtinBodyNode, name);
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
136
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13761
diff changeset
137 /* 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
138 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
139 }
16595
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
140
16702
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
141 /**
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
142 * This function will parse the given source code, parse the code using the {@link Parser}, and
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
143 * then execute the function named main. To use this method with instrumentation,
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
144 * setASTNodeProber must have been already called. There is currently no guard to check if this
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
145 * is the case. <br/>
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
146 * Due to the experimental nature of the instrumentation framework, the parse that happens in
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
147 * this method will remove any previously added instrumentation.
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
148 *
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
149 * @param source The {@link Source} to execute.
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
150 */
16595
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
151 public void executeMain(Source source) {
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
152
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
153 if (sourceCallback != null) {
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
154 sourceCallback.startLoading(source);
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
155 }
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
156
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
157 Parser.parseSL(this, source, astProber);
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
158
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
159 if (sourceCallback != null) {
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
160 sourceCallback.endLoading(source);
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
161 }
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
162
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
163 SLFunction main = getFunctionRegistry().lookup("main");
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
164 if (main.getCallTarget() == null) {
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
165 throw new SLException("No function main() defined in SL source file.");
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
166 }
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
167 main.getCallTarget().call();
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
168 }
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
169
16702
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
170 /**
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
171 * Sets the {@link SLASTProber} for the executeMain method.
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
172 *
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
173 * @param astProber The prober to use for adding instrumentation for this context.
2a5ec181dad4 SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents: 16595
diff changeset
174 */
16595
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
175 public void setASTNodeProber(SLASTProber astProber) {
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
176 this.astProber = astProber;
618d92152d3c SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents: 16512
diff changeset
177 }
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
178 }