Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.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 | 762dfc692689 |
children |
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 |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22046
diff
changeset
|
6 * |
21997
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 |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22046
diff
changeset
|
14 * |
21997
c07e64ecb528
Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
21951
diff
changeset
|
15 * (a) the Software, and |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22046
diff
changeset
|
16 * |
21997
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), |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22046
diff
changeset
|
20 * |
21997
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. |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22046
diff
changeset
|
26 * |
21997
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: |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22046
diff
changeset
|
28 * |
21997
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. |
22065
503529c65456
Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22046
diff
changeset
|
32 * |
21997
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 |
22408
fecae2501987
SL: refine interop eval, rename to just eval, and add tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
22377
diff
changeset
|
43 import com.oracle.truffle.api.CallTarget; |
22502
d2b4fe945c23
Add missing Truffle boundary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22436
diff
changeset
|
44 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
45 import com.oracle.truffle.api.ExecutionContext; |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22251
diff
changeset
|
46 import com.oracle.truffle.api.TruffleLanguage; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
47 import com.oracle.truffle.api.dsl.NodeFactory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
48 import com.oracle.truffle.api.frame.FrameDescriptor; |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
49 import com.oracle.truffle.api.interop.TruffleObject; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
50 import com.oracle.truffle.api.nodes.NodeInfo; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
51 import com.oracle.truffle.api.object.DynamicObject; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
52 import com.oracle.truffle.api.object.Layout; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
53 import com.oracle.truffle.api.object.Shape; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
54 import com.oracle.truffle.api.source.Source; |
22251
8dddde8b20d4
Truffle/SL: provide an "unavailable" SourceSection for every RootNode, using a newly defined static name that identifies "SL Builtin" RootNodes.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
55 import com.oracle.truffle.api.source.SourceSection; |
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
|
56 import com.oracle.truffle.sl.SLLanguage; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
57 import com.oracle.truffle.sl.builtins.SLAssertFalseBuiltinFactory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
58 import com.oracle.truffle.sl.builtins.SLAssertTrueBuiltinFactory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
59 import com.oracle.truffle.sl.builtins.SLBuiltinNode; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
60 import com.oracle.truffle.sl.builtins.SLDefineFunctionBuiltinFactory; |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22251
diff
changeset
|
61 import com.oracle.truffle.sl.builtins.SLEvalBuiltinFactory; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
62 import com.oracle.truffle.sl.builtins.SLHelloEqualsWorldBuiltinFactory; |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
63 import com.oracle.truffle.sl.builtins.SLImportBuiltinFactory; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
64 import com.oracle.truffle.sl.builtins.SLNanoTimeBuiltinFactory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
65 import com.oracle.truffle.sl.builtins.SLNewObjectBuiltinFactory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
66 import com.oracle.truffle.sl.builtins.SLPrintlnBuiltin; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
67 import com.oracle.truffle.sl.builtins.SLPrintlnBuiltinFactory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
68 import com.oracle.truffle.sl.builtins.SLReadlnBuiltin; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
69 import com.oracle.truffle.sl.builtins.SLReadlnBuiltinFactory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
70 import com.oracle.truffle.sl.builtins.SLStackTraceBuiltinFactory; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
71 import com.oracle.truffle.sl.nodes.SLExpressionNode; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
72 import com.oracle.truffle.sl.nodes.SLRootNode; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
73 import com.oracle.truffle.sl.nodes.local.SLReadArgumentNode; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
74 import com.oracle.truffle.sl.parser.Parser; |
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
75 import com.oracle.truffle.sl.parser.SLNodeFactory; |
22251
8dddde8b20d4
Truffle/SL: provide an "unavailable" SourceSection for every RootNode, using a newly defined static name that identifies "SL Builtin" RootNodes.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
76 |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
77 import java.io.BufferedReader; |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22251
diff
changeset
|
78 import java.io.IOException; |
22157
dc83cc1f94f2
Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
79 import java.io.PrintWriter; |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
80 import java.math.BigInteger; |
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
|
81 |
13821
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 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
|
84 * 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
|
85 * 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
|
86 * builtin functions}. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
87 * <p> |
13882
afd6fa5e8229
SL: Feedback from reviewers
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13836
diff
changeset
|
88 * 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
|
89 * 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
|
90 * 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
|
91 */ |
15891
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15064
diff
changeset
|
92 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
|
93 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
|
94 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
95 private final BufferedReader input; |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18762
diff
changeset
|
96 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
|
97 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
|
98 private final Shape emptyShape; |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22251
diff
changeset
|
99 private final TruffleLanguage.Env env; |
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 |
22539
762dfc692689
SLContext: remove needless language field
Andreas Woess <andreas.woess@oracle.com>
parents:
22538
diff
changeset
|
101 public SLContext(TruffleLanguage.Env env, BufferedReader input, PrintWriter output) { |
762dfc692689
SLContext: remove needless language field
Andreas Woess <andreas.woess@oracle.com>
parents:
22538
diff
changeset
|
102 this(env, input, output, true); |
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:
22003
diff
changeset
|
103 } |
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:
22003
diff
changeset
|
104 |
22539
762dfc692689
SLContext: remove needless language field
Andreas Woess <andreas.woess@oracle.com>
parents:
22538
diff
changeset
|
105 public SLContext() { |
762dfc692689
SLContext: remove needless language field
Andreas Woess <andreas.woess@oracle.com>
parents:
22538
diff
changeset
|
106 this(null, null, null, false); |
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:
22003
diff
changeset
|
107 } |
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:
22003
diff
changeset
|
108 |
22539
762dfc692689
SLContext: remove needless language field
Andreas Woess <andreas.woess@oracle.com>
parents:
22538
diff
changeset
|
109 private SLContext(TruffleLanguage.Env env, BufferedReader input, PrintWriter output, boolean installBuiltins) { |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
110 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
|
111 this.output = output; |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22251
diff
changeset
|
112 this.env = env; |
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
|
113 this.functionRegistry = new SLFunctionRegistry(); |
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:
22003
diff
changeset
|
114 installBuiltins(installBuiltins); |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
115 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22065
diff
changeset
|
116 this.emptyShape = LAYOUT.createShape(new SLObjectType()); |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
117 } |
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
118 |
13821
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 * 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
|
121 * 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
|
122 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
123 public BufferedReader getInput() { |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
124 return input; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
125 } |
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 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
128 * 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
|
129 * 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
|
130 */ |
21469
286aef83a9a7
Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
18762
diff
changeset
|
131 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
|
132 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
|
133 } |
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
|
134 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
135 /** |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
136 * 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
|
137 */ |
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
|
138 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
|
139 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
|
140 } |
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
|
141 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
142 /** |
13836
64c77f0577bb
More documentation and improvements of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13821
diff
changeset
|
143 * 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
|
144 * {@link SLBuiltinNode builtin implementation classes}. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
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:
22003
diff
changeset
|
146 private void installBuiltins(boolean registerRootNodes) { |
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:
22003
diff
changeset
|
147 installBuiltin(SLReadlnBuiltinFactory.getInstance(), registerRootNodes); |
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:
22003
diff
changeset
|
148 installBuiltin(SLPrintlnBuiltinFactory.getInstance(), registerRootNodes); |
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:
22003
diff
changeset
|
149 installBuiltin(SLNanoTimeBuiltinFactory.getInstance(), registerRootNodes); |
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:
22003
diff
changeset
|
150 installBuiltin(SLDefineFunctionBuiltinFactory.getInstance(), registerRootNodes); |
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:
22003
diff
changeset
|
151 installBuiltin(SLStackTraceBuiltinFactory.getInstance(), registerRootNodes); |
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:
22003
diff
changeset
|
152 installBuiltin(SLHelloEqualsWorldBuiltinFactory.getInstance(), registerRootNodes); |
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:
22003
diff
changeset
|
153 installBuiltin(SLAssertTrueBuiltinFactory.getInstance(), registerRootNodes); |
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:
22003
diff
changeset
|
154 installBuiltin(SLAssertFalseBuiltinFactory.getInstance(), registerRootNodes); |
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:
22003
diff
changeset
|
155 installBuiltin(SLNewObjectBuiltinFactory.getInstance(), registerRootNodes); |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22251
diff
changeset
|
156 installBuiltin(SLEvalBuiltinFactory.getInstance(), registerRootNodes); |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
157 installBuiltin(SLImportBuiltinFactory.getInstance(), registerRootNodes); |
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
|
158 } |
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
|
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:
22003
diff
changeset
|
160 public void installBuiltin(NodeFactory<? extends SLBuiltinNode> factory, boolean registerRootNodes) { |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
161 /* |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
162 * 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
|
163 * 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
|
164 * methods in the builtin classes. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
165 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
166 int argumentCount = factory.getExecutionSignature().size(); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
167 SLExpressionNode[] argumentNodes = new SLExpressionNode[argumentCount]; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
168 /* |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
169 * 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
|
170 * 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
|
171 * from this array. |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
172 */ |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
173 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
|
174 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
|
175 } |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
176 /* 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
|
177 SLBuiltinNode builtinBodyNode = factory.createNode(argumentNodes, this); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
178 /* 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
|
179 String name = lookupNodeInfo(builtinBodyNode.getClass()).shortName(); |
22251
8dddde8b20d4
Truffle/SL: provide an "unavailable" SourceSection for every RootNode, using a newly defined static name that identifies "SL Builtin" RootNodes.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
180 |
8dddde8b20d4
Truffle/SL: provide an "unavailable" SourceSection for every RootNode, using a newly defined static name that identifies "SL Builtin" RootNodes.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
181 final SourceSection srcSection = SourceSection.createUnavailable(SLLanguage.builtinKind, name); |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
182 /* Wrap the builtin in a RootNode. Truffle requires all AST to start with a RootNode. */ |
22251
8dddde8b20d4
Truffle/SL: provide an "unavailable" SourceSection for every RootNode, using a newly defined static name that identifies "SL Builtin" RootNodes.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22157
diff
changeset
|
183 SLRootNode rootNode = new SLRootNode(this, new FrameDescriptor(), builtinBodyNode, srcSection, name); |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13761
diff
changeset
|
184 |
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:
22003
diff
changeset
|
185 if (registerRootNodes) { |
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:
22003
diff
changeset
|
186 /* Register the builtin function in our function registry. */ |
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:
22003
diff
changeset
|
187 getFunctionRegistry().register(name, rootNode); |
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:
22003
diff
changeset
|
188 } else { |
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:
22003
diff
changeset
|
189 // make sure the function is known |
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:
22003
diff
changeset
|
190 getFunctionRegistry().lookup(name); |
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:
22003
diff
changeset
|
191 } |
13761
7c418666c6c9
Refactoring and cleanup of Simple Language (more to come soon)
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13455
diff
changeset
|
192 } |
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
16512
diff
changeset
|
193 |
18762
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
194 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
|
195 if (clazz == null) { |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
196 return null; |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
197 } |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
198 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
|
199 if (info != null) { |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
200 return info; |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
201 } else { |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
202 return lookupNodeInfo(clazz.getSuperclass()); |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
203 } |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
204 } |
0ef23ff7d5a1
SL: make lookup of NodeInfo annotation more rebust.
Christian Humer <christian.humer@gmail.com>
parents:
18485
diff
changeset
|
205 |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
16595
diff
changeset
|
206 /** |
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
|
207 * 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
|
208 * |
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
|
209 * @param source The {@link Source} to parse. |
16702
2a5ec181dad4
SL: Added instrumentation testing
David Piorkowski <david.piorkowski@oracle.com>
parents:
16595
diff
changeset
|
210 */ |
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
|
211 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
|
212 Parser.parseSL(this, source); |
16595
618d92152d3c
SL: Added support for instrumentation.
David Piorkowski <david.piorkowski@oracle.com>
parents:
16512
diff
changeset
|
213 } |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
214 |
22538
ae2c10d36bed
SLContext: simplify createObject()
Andreas Woess <andreas.woess@oracle.com>
parents:
22502
diff
changeset
|
215 /** |
ae2c10d36bed
SLContext: simplify createObject()
Andreas Woess <andreas.woess@oracle.com>
parents:
22502
diff
changeset
|
216 * Allocate an empty object. |
ae2c10d36bed
SLContext: simplify createObject()
Andreas Woess <andreas.woess@oracle.com>
parents:
22502
diff
changeset
|
217 */ |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
218 public DynamicObject createObject() { |
22538
ae2c10d36bed
SLContext: simplify createObject()
Andreas Woess <andreas.woess@oracle.com>
parents:
22502
diff
changeset
|
219 return emptyShape.newInstance(); |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
220 } |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
221 |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
222 public static boolean isSLObject(TruffleObject value) { |
22416
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
223 return value instanceof DynamicObject && isSLObject((DynamicObject) value); |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
224 } |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
225 |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
226 public static boolean isSLObject(DynamicObject value) { |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
227 return value.getShape().getObjectType() instanceof SLObjectType; |
18412
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
228 } |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
229 |
997bc9764a9a
SL: use the truffle object storage model to represent SL objects
Andreas Woess <andreas.woess@jku.at>
parents:
18411
diff
changeset
|
230 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
|
231 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
|
232 } |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
233 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
234 public static Object fromForeignValue(Object a) { |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
235 if (a instanceof Long || a instanceof BigInteger || a instanceof String) { |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
236 return a; |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
237 } else if (a instanceof Number) { |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
238 return ((Number) a).longValue(); |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
239 } else if (a instanceof TruffleObject) { |
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
240 return a; |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22417
diff
changeset
|
241 } else if (a instanceof SLContext) { |
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22417
diff
changeset
|
242 return a; |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
243 } |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
244 throw new IllegalStateException(a + " is not a Truffle value"); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
245 } |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22251
diff
changeset
|
246 |
22408
fecae2501987
SL: refine interop eval, rename to just eval, and add tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
22377
diff
changeset
|
247 public CallTarget parse(Source source) throws IOException { |
fecae2501987
SL: refine interop eval, rename to just eval, and add tests.
Chris Seaton <chris.seaton@oracle.com>
parents:
22377
diff
changeset
|
248 return env.parse(source); |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22251
diff
changeset
|
249 } |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
250 |
22416
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
251 /** |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
252 * Goes through the other registered languages to find an exported global symbol of the |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
253 * specified name. The expected return type is either <code>TruffleObject</code>, or one of |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
254 * wrappers of Java primitive types ({@link Integer}, {@link Double}). |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22417
diff
changeset
|
255 * |
22416
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
256 * @param name the name of the symbol to search for |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
257 * @return object representing the symbol or <code>null</code> |
b272920e26b2
Minor changes to interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22415
diff
changeset
|
258 */ |
22502
d2b4fe945c23
Add missing Truffle boundary
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22436
diff
changeset
|
259 @TruffleBoundary |
22415
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
260 public Object importSymbol(String name) { |
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
261 Object object = env.importSymbol(name); |
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
262 Object slValue = fromForeignValue(object); |
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
263 return slValue; |
c1f804ce6cad
Extend interop functionality for SL
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22377
diff
changeset
|
264 } |
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
|
265 } |