Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java @ 17382:e1da729b3e4e
make Truffle Node source section @CompilationFinal
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Wed, 08 Oct 2014 10:50:18 +0200 |
parents | f8998c828bed |
children | 763a34f283f9 |
rev | line source |
---|---|
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
11535
8f0fb0ade839
Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11279
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
11279
494b818b527c
Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10862
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
494b818b527c
Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10862
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
494b818b527c
Adding "Classpath" exception to the classes in the com.oracle.truffle.api and the com.oracle.truffle.api.dsl package.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
10862
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
23 * questions. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.nodes; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
27 import java.lang.annotation.*; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 import java.util.*; |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
29 import java.util.concurrent.*; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
31 import com.oracle.truffle.api.*; |
17382
e1da729b3e4e
make Truffle Node source section @CompilationFinal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16912
diff
changeset
|
32 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; |
16067
915ebb306fcc
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15775
diff
changeset
|
33 import com.oracle.truffle.api.source.*; |
16151
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
34 import com.oracle.truffle.api.utilities.*; |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
35 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 * Abstract base class for all Truffle nodes. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
38 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
39 public abstract class Node implements Cloneable { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
40 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 private Node parent; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 |
17382
e1da729b3e4e
make Truffle Node source section @CompilationFinal
Lukas Stadler <lukas.stadler@oracle.com>
parents:
16912
diff
changeset
|
43 @CompilationFinal private SourceSection sourceSection; |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
44 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
45 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
46 * Marks array fields that are children of this node. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
47 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
48 @Retention(RetentionPolicy.RUNTIME) |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
49 @Target({ElementType.FIELD}) |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 public @interface Children { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
52 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
53 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 * Marks fields that represent child nodes of this node. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
55 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 @Retention(RetentionPolicy.RUNTIME) |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
57 @Target({ElementType.FIELD}) |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 public @interface Child { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
59 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
60 |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
61 protected Node() { |
16151
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
62 this(null); |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
63 } |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
64 |
11535
8f0fb0ade839
Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11279
diff
changeset
|
65 protected Node(SourceSection sourceSection) { |
8f0fb0ade839
Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11279
diff
changeset
|
66 CompilerAsserts.neverPartOfCompilation(); |
8f0fb0ade839
Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11279
diff
changeset
|
67 this.sourceSection = sourceSection; |
16151
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
68 if (TruffleOptions.TraceASTJSON) { |
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
69 JSONHelper.dumpNewNode(this); |
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
70 } |
11535
8f0fb0ade839
Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11279
diff
changeset
|
71 } |
8f0fb0ade839
Truffle: add alternate Node/RootNode constructors with SourceSection argument.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
11279
diff
changeset
|
72 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
73 /** |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
74 * Assigns a link to a guest language source section to this node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
75 * |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
76 * @param section the object representing a section in guest language source code |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
77 */ |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
78 public final void assignSourceSection(SourceSection section) { |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
79 if (sourceSection != null) { |
11610
5f532ea846fb
applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents:
11535
diff
changeset
|
80 // Patch this test during the transition to constructor-based |
5f532ea846fb
applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents:
11535
diff
changeset
|
81 // source attribution, which would otherwise trigger this |
5f532ea846fb
applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents:
11535
diff
changeset
|
82 // exception. This method will eventually be deprecated. |
5f532ea846fb
applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents:
11535
diff
changeset
|
83 if (getSourceSection() != section) { |
11648
4ab1f371adc8
Do not assign new source section if replacing node already has source section assigned.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
11610
diff
changeset
|
84 throw new IllegalStateException("Source section is already assigned. Old: " + getSourceSection() + ", new: " + section); |
11610
5f532ea846fb
applied changes to basic-graal that were made in a downstream repo
Doug Simon <doug.simon@oracle.com>
parents:
11535
diff
changeset
|
85 } |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
86 } |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
87 this.sourceSection = section; |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
88 } |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
89 |
14566
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
90 /** |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
91 * Returns a rough estimate for the cost of this {@link Node}. This estimate can be used by |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
92 * runtime systems or guest languages to implement heuristics based on Truffle ASTs. This method |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
93 * is intended to be overridden by subclasses. The default implementation returns the value of |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
94 * {@link NodeInfo#cost()} of the {@link NodeInfo} annotation declared at the subclass. If no |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
95 * {@link NodeInfo} annotation is declared the method returns {@link NodeCost#MONOMORPHIC} as a |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
96 * default value. |
6681b9eb3f4c
Truffle: API cleanup and javadoc for CallNodes.
Christian Humer <christian.humer@gmail.com>
parents:
14564
diff
changeset
|
97 */ |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14073
diff
changeset
|
98 public NodeCost getCost() { |
13994
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
99 NodeInfo info = getClass().getAnnotation(NodeInfo.class); |
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
100 if (info != null) { |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14073
diff
changeset
|
101 return info.cost(); |
13994
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
102 } |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14073
diff
changeset
|
103 return NodeCost.MONOMORPHIC; |
13994
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
104 } |
989f58d6a0ca
Truffle: Added API for Node.getKind().
Christian Humer <christian.humer@gmail.com>
parents:
13983
diff
changeset
|
105 |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
106 /** |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
107 * Clears any previously assigned guest language source code from this node. |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
108 */ |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
109 public final void clearSourceSection() { |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
110 this.sourceSection = null; |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
111 } |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
112 |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
113 /** |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
114 * Retrieves the guest language source code section that is currently assigned to this node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
115 * |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
116 * @return the assigned source code section |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
117 */ |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
118 public final SourceSection getSourceSection() { |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
119 return sourceSection; |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
120 } |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
121 |
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
122 /** |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
123 * Retrieves the guest language source code section that is currently assigned to this node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
124 * |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
125 * @return the assigned source code section |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
126 */ |
11818
793743715dc1
put Node.getEncapsulatedSourceSection() on slow path
Michael Haupt <michael.haupt@oracle.com>
parents:
11648
diff
changeset
|
127 @CompilerDirectives.SlowPath |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
128 public final SourceSection getEncapsulatingSourceSection() { |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
129 if (sourceSection == null && getParent() != null) { |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
130 return getParent().getEncapsulatingSourceSection(); |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
131 } |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
132 return sourceSection; |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
133 } |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
134 |
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
135 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
136 * Method that updates the link to the parent in the array of specified new child nodes to this |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
137 * node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
138 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
139 * @param newChildren the array of new children whose parent should be updated |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
140 * @return the array of new children |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
141 */ |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
142 protected final <T extends Node> T[] insert(final T[] newChildren) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
143 CompilerDirectives.transferToInterpreterAndInvalidate(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
144 assert newChildren != null; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
145 for (Node newChild : newChildren) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
146 adoptHelper(newChild); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
147 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
148 return newChildren; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
149 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
150 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
151 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
152 * Method that updates the link to the parent in the specified new child node to this node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
153 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
154 * @param newChild the new child whose parent should be updated |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
155 * @return the new child |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
156 */ |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
157 protected final <T extends Node> T insert(final T newChild) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
158 CompilerDirectives.transferToInterpreterAndInvalidate(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
159 assert newChild != null; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
160 adoptHelper(newChild); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
161 return newChild; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
162 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
163 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
164 public final void adoptChildren() { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
165 CompilerDirectives.transferToInterpreterAndInvalidate(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
166 adoptHelper(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
167 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
168 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
169 private void adoptHelper(final Node newChild) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
170 assert newChild != null; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
171 if (newChild == this) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
172 throw new IllegalStateException("The parent of a node can never be the node itself."); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
173 } |
15346
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
174 boolean isInserted = newChild.parent == null; |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
175 newChild.parent = this; |
16151
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
176 if (TruffleOptions.TraceASTJSON) { |
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
177 JSONHelper.dumpNewChild(this, newChild); |
76895499bc88
Add facility to create JSON dump of AST creation/rewriting
Christian Wirth <christian.wirth@oracle.com>
parents:
16067
diff
changeset
|
178 } |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
179 newChild.adoptHelper(); |
15346
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
180 if (isInserted) { |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
181 newChild.onAdopt(); |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
182 } |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
183 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
184 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
185 private void adoptHelper() { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
186 Iterable<Node> children = this.getChildren(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
187 for (Node child : children) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
188 if (child != null && child.getParent() != this) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
189 this.adoptHelper(child); |
10481
29e9a5d18c70
Clean up.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9782
diff
changeset
|
190 } |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
191 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
192 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
193 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
194 private void adoptUnadoptedHelper(final Node newChild) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
195 assert newChild != null; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
196 if (newChild == this) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
197 throw new IllegalStateException("The parent of a node can never be the node itself."); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
198 } |
15346
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
199 boolean isInserted = newChild.parent == null; |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
200 newChild.parent = this; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
201 newChild.adoptUnadoptedHelper(); |
15346
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
202 if (isInserted) { |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
203 newChild.onAdopt(); |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
204 } |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
205 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
206 |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
207 private void adoptUnadoptedHelper() { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
208 Iterable<Node> children = this.getChildren(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
209 for (Node child : children) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
210 if (child != null && child.getParent() == null) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
211 this.adoptUnadoptedHelper(child); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
212 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
213 } |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
214 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
215 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
216 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
217 * Returns properties of this node interesting for debugging and can be overwritten by |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
218 * subclasses to add their own custom properties. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
219 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
220 * @return the properties as a key/value hash map |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
221 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
222 public Map<String, Object> getDebugProperties() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
223 Map<String, Object> properties = new HashMap<>(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
224 return properties; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
225 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
226 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
227 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
228 * The current parent node of this node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
229 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
230 * @return the parent node |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
231 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
232 public final Node getParent() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
233 return parent; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
234 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
235 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
236 /** |
9256
9640bb930327
Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9255
diff
changeset
|
237 * Replaces this node with another node. If there is a source section (see |
9640bb930327
Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9255
diff
changeset
|
238 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
239 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
240 * @param newNode the new node that is the replacement |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
241 * @param reason a description of the reason for the replacement |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
242 * @return the new node |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
243 */ |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
244 public final <T extends Node> T replace(final T newNode, final CharSequence reason) { |
13915
d6b340b757a2
Truffle: refactorings
Andreas Woess <andreas.woess@jku.at>
parents:
13811
diff
changeset
|
245 CompilerDirectives.transferToInterpreterAndInvalidate(); |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
246 atomic(new Runnable() { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
247 public void run() { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
248 replaceHelper(newNode, reason); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
249 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
250 }); |
12494
57b8a41c0e18
Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents:
11951
diff
changeset
|
251 return newNode; |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
252 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
253 |
12494
57b8a41c0e18
Truffle: fix possible node rewrite failures after recursive calls.
Andreas Woess <andreas.woess@jku.at>
parents:
11951
diff
changeset
|
254 /** |
9256
9640bb930327
Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9255
diff
changeset
|
255 * Replaces this node with another node. If there is a source section (see |
9640bb930327
Preserve the source section during node rewrites.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
9255
diff
changeset
|
256 * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
257 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
258 * @param newNode the new node that is the replacement |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
259 * @return the new node |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
260 */ |
9254
4497235516df
New API for representing Source objects and SourceSection objects. SourceSection objects can be associated with Truffle interpreter nodes.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
261 public final <T extends Node> T replace(T newNode) { |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
262 return replace(newNode, ""); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
263 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
264 |
14628
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
265 private void replaceHelper(Node newNode, CharSequence reason) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
266 CompilerAsserts.neverPartOfCompilation(); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
267 if (this.getParent() == null) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
268 throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
269 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
270 if (sourceSection != null && newNode.getSourceSection() == null) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
271 // Pass on the source section to the new node. |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
272 newNode.assignSourceSection(sourceSection); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
273 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
274 // (aw) need to set parent *before* replace, so that (unsynchronized) getRootNode() |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
275 // will always find the root node |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
276 newNode.parent = this.parent; |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
277 if (NodeUtil.replaceChild(this.parent, this, newNode)) { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
278 this.parent.adoptHelper(newNode); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
279 } else { |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
280 this.parent.adoptUnadoptedHelper(newNode); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
281 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
282 reportReplace(this, newNode, reason); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
283 onReplace(newNode, reason); |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
284 } |
a08b8694f556
Truffle: Node API changes
Andreas Woess <andreas.woess@jku.at>
parents:
14584
diff
changeset
|
285 |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
286 /** |
10846
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
287 * Checks if this node is properly adopted by a parent and can be replaced. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
288 * |
10846
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
289 * @return {@code true} if it is safe to replace this node. |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
290 */ |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
291 public final boolean isReplaceable() { |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
292 if (getParent() != null) { |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
293 for (Node sibling : getParent().getChildren()) { |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
294 if (sibling == this) { |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
295 return true; |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
296 } |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
297 } |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
298 } |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
299 return false; |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
300 } |
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
301 |
14584
6189c1983cd3
Truffle: make Node#replace accept any CharSequence as reason
Andreas Woess <andreas.woess@jku.at>
parents:
14566
diff
changeset
|
302 private void reportReplace(Node oldNode, Node newNode, CharSequence reason) { |
16912
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
303 Node node = this; |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
304 while (node != null) { |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
305 if (node instanceof ReplaceObserver) { |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
306 ((ReplaceObserver) node).nodeReplaced(oldNode, newNode, reason); |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
307 } else if (node instanceof RootNode) { |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
308 CallTarget target = ((RootNode) node).getCallTarget(); |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
309 if (target instanceof ReplaceObserver) { |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
310 ((ReplaceObserver) target).nodeReplaced(oldNode, newNode, reason); |
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
311 } |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
312 } |
16912
f8998c828bed
Truffle: replaces are now reported to all ReplaceObservers in the node hierarchy.
Christian Humer <christian.humer@gmail.com>
parents:
16467
diff
changeset
|
313 node = node.getParent(); |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
314 } |
16464
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
315 if (TruffleOptions.TraceRewrites) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
316 NodeUtil.traceRewrite(this, newNode, reason); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
317 } |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
318 if (TruffleOptions.TraceASTJSON) { |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
319 JSONHelper.dumpReplaceChild(this, newNode, reason); |
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
320 } |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
321 } |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
322 |
10846
e87d56a51047
Truffle: add Node.isReplaceable()
Andreas Woess <andreas.woess@jku.at>
parents:
10843
diff
changeset
|
323 /** |
9782
ba02d19dd3cc
Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents:
9256
diff
changeset
|
324 * Intended to be implemented by subclasses of {@link Node} to receive a notification when the |
ba02d19dd3cc
Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents:
9256
diff
changeset
|
325 * node is rewritten. This method is invoked before the actual replace has happened. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
326 * |
9782
ba02d19dd3cc
Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents:
9256
diff
changeset
|
327 * @param newNode the replacement node |
ba02d19dd3cc
Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents:
9256
diff
changeset
|
328 * @param reason the reason the replace supplied |
ba02d19dd3cc
Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents:
9256
diff
changeset
|
329 */ |
14584
6189c1983cd3
Truffle: make Node#replace accept any CharSequence as reason
Andreas Woess <andreas.woess@jku.at>
parents:
14566
diff
changeset
|
330 protected void onReplace(Node newNode, CharSequence reason) { |
16464
76081918079d
Truffle: move TraceRewrites code to NodeUtil
Andreas Woess <andreas.woess@jku.at>
parents:
16151
diff
changeset
|
331 // empty default |
10590
6eb8d63cea34
Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents:
10481
diff
changeset
|
332 } |
6eb8d63cea34
Added a feature to trace rewrites of truffle nodes.
Christian Humer <christian.humer@gmail.com>
parents:
10481
diff
changeset
|
333 |
15346
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
334 /** |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
335 * Subclasses of {@link Node} can implement this method to execute extra functionality when a |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
336 * node is effectively inserted into the AST. The {@code onAdopt} callback is called after the |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
337 * node has been effectively inserted, and it is guaranteed to be called only once for any given |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
338 * node. |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
339 */ |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
340 protected void onAdopt() { |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
341 // empty default |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
342 } |
1cd02b4d90d1
onAdopt callback for ASTs
Michael Haupt <michael.haupt@oracle.com>
parents:
14991
diff
changeset
|
343 |
9782
ba02d19dd3cc
Added an onReplace method to Node to provide a way for a guest language implementation to use replace tracing.
Christian Humer <christian.humer@gmail.com>
parents:
9256
diff
changeset
|
344 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
345 * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
346 * child nodes. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
347 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
348 * @param nodeVisitor the visitor |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
349 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
350 public final void accept(NodeVisitor nodeVisitor) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
351 if (nodeVisitor.visit(this)) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
352 for (Node child : this.getChildren()) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
353 if (child != null) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
354 child.accept(nodeVisitor); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
355 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
356 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
357 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
358 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
359 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
360 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
361 * Iterator over the children of this node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
362 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
363 * @return the iterator |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
364 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
365 public final Iterable<Node> getChildren() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
366 return new Iterable<Node>() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
367 public Iterator<Node> iterator() { |
16467
17f7331dcc4f
Truffle: move iterator to NodeClass
Andreas Woess <andreas.woess@jku.at>
parents:
16464
diff
changeset
|
368 return NodeUtil.makeIterator(Node.this); |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
369 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
370 }; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
371 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
372 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
373 /** |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
374 * Creates a shallow copy of this node. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
375 * |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
376 * @return the new copy |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
377 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
378 public Node copy() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
379 try { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
380 return (Node) super.clone(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
381 } catch (CloneNotSupportedException e) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
382 return null; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
383 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
384 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
385 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
386 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
387 * This method must never be called. It enforces that {@link Object#clone} is not directly |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
388 * called by subclasses. Use the {@link #copy()} method instead. |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
389 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
390 @Override |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
391 @Deprecated |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
392 protected final Object clone() throws CloneNotSupportedException { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
393 throw new IllegalStateException("This method should never be called, use the copy method instead!"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
394 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
395 |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
396 /** |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
397 * Get the root node of the tree a node belongs to. |
14991
64dcb92ee75a
Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
14629
diff
changeset
|
398 * |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
399 * @return the {@link RootNode} or {@code null} if there is none. |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
400 */ |
13983
f46cab39a9a2
Truffle: Updated inlining API. Pushed inlining implementation to the Truffle runtime.
Christian Humer <christian.humer@gmail.com>
parents:
13915
diff
changeset
|
401 public final RootNode getRootNode() { |
12692
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
402 Node rootNode = this; |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
403 while (rootNode.getParent() != null) { |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
404 assert !(rootNode instanceof RootNode) : "root node must not have a parent"; |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
405 rootNode = rootNode.getParent(); |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
406 } |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
407 if (rootNode instanceof RootNode) { |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
408 return (RootNode) rootNode; |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
409 } |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
410 return null; |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
411 } |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
412 |
ffd4b6b4ae68
Truffle Node class refactoring.
Andreas Woess <andreas.woess@jku.at>
parents:
12495
diff
changeset
|
413 /** |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
414 * Converts this node to a textual representation useful for debugging. |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
415 */ |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
416 @Override |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
417 public String toString() { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
418 StringBuilder sb = new StringBuilder(getClass().getSimpleName()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
419 Map<String, Object> properties = getDebugProperties(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
420 boolean hasProperties = false; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
421 for (Map.Entry<String, Object> entry : properties.entrySet()) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
422 sb.append(hasProperties ? "," : "<"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
423 hasProperties = true; |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
424 sb.append(entry.getKey()).append("=").append(entry.getValue()); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
425 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
426 if (hasProperties) { |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
427 sb.append(">"); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
428 } |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
429 sb.append("@").append(Integer.toHexString(hashCode())); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
430 return sb.toString(); |
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
431 } |
14629
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
432 |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
433 public final void atomic(Runnable closure) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
434 RootNode rootNode = getRootNode(); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
435 if (rootNode != null) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
436 synchronized (rootNode) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
437 closure.run(); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
438 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
439 } else { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
440 closure.run(); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
441 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
442 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
443 |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
444 public final <T> T atomic(Callable<T> closure) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
445 try { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
446 RootNode rootNode = getRootNode(); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
447 if (rootNode != null) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
448 synchronized (rootNode) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
449 return closure.call(); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
450 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
451 } else { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
452 return closure.call(); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
453 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
454 } catch (RuntimeException e) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
455 throw e; |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
456 } catch (Exception e) { |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
457 throw new RuntimeException(e); |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
458 } |
ba52fbec5b6c
Truffle: atomic node rewriting
Andreas Woess <andreas.woess@jku.at>
parents:
14628
diff
changeset
|
459 } |
15775
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
460 |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
461 /** |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
462 * Returns a user-readable description of the purpose of the Node, or "" if no description is |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
463 * available. |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
464 */ |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
465 public String getDescription() { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
466 NodeInfo info = getClass().getAnnotation(NodeInfo.class); |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
467 if (info != null) { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
468 return info.description(); |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
469 } |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
470 return ""; |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
471 } |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
472 |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
473 /** |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
474 * Returns a string representing the language this node has been implemented for. If the |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
475 * language is unknown, returns "". |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
476 */ |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
477 public String getLanguage() { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
478 NodeInfo info = getClass().getAnnotation(NodeInfo.class); |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
479 if (info != null && info.language() != null && info.language().length() > 0) { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
480 return info.language(); |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
481 } |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
482 if (parent != null) { |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
483 return parent.getLanguage(); |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
484 } |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
485 return ""; |
4293efaaab76
Add description and language to the NodeInfo annotation
Christian Wirth <christian.wirth@oracle.com>
parents:
15474
diff
changeset
|
486 } |
7267
a4b84ba6dc2e
Introduction of the Truffle API for efficient implementation of dynamic languages on top of the Graal VM. New projects com.oracle.truffle.api for the API definition and com.oracle.truffle.api.test for API tests and documentation.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
487 } |