Mercurial > hg > truffle
annotate graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java @ 10793:6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
author | Andreas Woess <andreas.woess@jku.at> |
---|---|
date | Wed, 17 Jul 2013 13:53:11 +0200 |
parents | 7f6580db1e88 |
children | e9248ebb1d79 |
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 /* |
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
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
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 |
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
|
7 * published by 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
|
8 * |
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
|
9 * 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
|
10 * 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
|
11 * 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
|
12 * 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
|
13 * 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
|
14 * |
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 * 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
|
16 * 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
|
17 * 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
|
18 * |
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 * 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
|
20 * 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
|
21 * 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
|
22 */ |
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 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
|
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 import java.io.*; |
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 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
|
27 import java.lang.reflect.*; |
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.*; |
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
|
29 |
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 import sun.misc.*; |
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
|
31 |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
32 import com.oracle.truffle.api.nodes.Node.Child; |
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
33 import com.oracle.truffle.api.nodes.Node.Children; |
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
34 |
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
|
35 /** |
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 * Utility class that manages the special access methods for node instances. |
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 */ |
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 public class NodeUtil { |
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 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
40 /** |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
41 * Interface that allows the customization of field offsets used for {@link Unsafe} field |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
42 * accesses. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
43 */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
44 public interface FieldOffsetProvider { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
45 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
46 long objectFieldOffset(Field field); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
47 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
48 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
49 private static final FieldOffsetProvider unsafeFieldOffsetProvider = new FieldOffsetProvider() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
50 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
51 @Override |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
52 public long objectFieldOffset(Field field) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
53 return unsafe.objectFieldOffset(field); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
54 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
55 }; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
56 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
57 public static enum NodeFieldKind { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
58 /** The single {@link Node#getParent() parent} field. */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
59 PARENT, |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
60 /** A field annotated with {@link Child}. */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
61 CHILD, |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
62 /** A field annotated with {@link Children}. */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
63 CHILDREN, |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
64 /** A normal non-child data field of the node. */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
65 DATA |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
66 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
67 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
68 /** |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
69 * Information about a field in a {@link Node} class. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
70 */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
71 public static final class NodeField { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
72 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
73 private final NodeFieldKind kind; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
74 private final Class<?> type; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
75 private final String name; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
76 private long offset; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
77 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
78 protected NodeField(NodeFieldKind kind, Class<?> type, String name, long offset) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
79 this.kind = kind; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
80 this.type = type; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
81 this.name = name; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
82 this.offset = offset; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
83 } |
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
|
84 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
85 public NodeFieldKind getKind() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
86 return kind; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
87 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
88 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
89 public Class<?> getType() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
90 return type; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
91 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
92 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
93 public String getName() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
94 return name; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
95 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
96 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
97 public long getOffset() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
98 return offset; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
99 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
100 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
101 public Object loadValue(Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
102 if (type == boolean.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
103 return unsafe.getBoolean(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
104 } else if (type == byte.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
105 return unsafe.getByte(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
106 } else if (type == short.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
107 return unsafe.getShort(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
108 } else if (type == char.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
109 return unsafe.getChar(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
110 } else if (type == int.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
111 return unsafe.getInt(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
112 } else if (type == long.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
113 return unsafe.getLong(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
114 } else if (type == float.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
115 return unsafe.getFloat(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
116 } else if (type == double.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
117 return unsafe.getDouble(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
118 } else { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
119 return unsafe.getObject(node, offset); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
120 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
121 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
122 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
123 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
124 /** |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
125 * Information about a {@link Node} class. A single instance of this class is allocated for |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
126 * every subclass of {@link Node} that is used. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
127 */ |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
128 public static final class NodeClass { |
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
|
129 |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
130 private static final Map<Class<?>, NodeClass> nodeClasses = new IdentityHashMap<>(); |
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
|
131 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
132 // The comprehensive list of all fields. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
133 private final NodeField[] fields; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
134 // Separate arrays for the frequently accessed field offsets. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
135 private final long parentOffset; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
136 private final long[] childOffsets; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
137 private final long[] childrenOffsets; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
138 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
139 public static NodeClass get(Class<? extends Node> clazz) { |
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
|
140 NodeClass nodeClass = nodeClasses.get(clazz); |
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 if (nodeClass == null) { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
142 nodeClass = new NodeClass(clazz, unsafeFieldOffsetProvider); |
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
|
143 nodeClasses.put(clazz, nodeClass); |
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
|
144 } |
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
|
145 return nodeClass; |
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
|
146 } |
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 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
148 public NodeClass(Class<? extends Node> clazz, FieldOffsetProvider fieldOffsetProvider) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
149 List<NodeField> fieldsList = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
150 List<Long> parentOffsetsList = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
151 List<Long> childOffsetsList = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
152 List<Long> childrenOffsetsList = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
153 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
154 for (Field field : getAllFields(clazz)) { |
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
|
155 if (Modifier.isStatic(field.getModifiers()) || field.isSynthetic()) { |
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 continue; |
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
|
157 } |
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
|
158 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
159 NodeFieldKind kind; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
160 if (Node.class.isAssignableFrom(field.getType()) && field.getName().equals("parent") && field.getDeclaringClass() == Node.class) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
161 kind = NodeFieldKind.PARENT; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
162 parentOffsetsList.add(fieldOffsetProvider.objectFieldOffset(field)); |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
163 } else if (Node.class.isAssignableFrom(field.getType()) && field.getAnnotation(Child.class) != null) { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
164 kind = NodeFieldKind.CHILD; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
165 childOffsetsList.add(fieldOffsetProvider.objectFieldOffset(field)); |
10756
7f6580db1e88
Truffle: add assertions to verify the finalness of child fields.
Andreas Woess <andreas.woess@jku.at>
parents:
10755
diff
changeset
|
166 assert !Modifier.isFinal(field.getModifiers()) : "child field must not be final (\"" + field.getName() + "\", " + clazz + ")"; |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
167 } else if (field.getType().isArray() && Node.class.isAssignableFrom(field.getType().getComponentType()) && field.getAnnotation(Children.class) != null) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
168 kind = NodeFieldKind.CHILDREN; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
169 childrenOffsetsList.add(fieldOffsetProvider.objectFieldOffset(field)); |
10756
7f6580db1e88
Truffle: add assertions to verify the finalness of child fields.
Andreas Woess <andreas.woess@jku.at>
parents:
10755
diff
changeset
|
170 assert Modifier.isFinal(field.getModifiers()) : "children array field must be final (\"" + field.getName() + "\", " + clazz + ")"; |
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
|
171 } else { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
172 kind = NodeFieldKind.DATA; |
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
|
173 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
174 fieldsList.add(new NodeField(kind, field.getType(), field.getName(), fieldOffsetProvider.objectFieldOffset(field))); |
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
|
175 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
176 this.fields = fieldsList.toArray(new NodeField[fieldsList.size()]); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
177 assert parentOffsetsList.size() == 1 : "must have exactly one parent field"; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
178 this.parentOffset = parentOffsetsList.get(0); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
179 this.childOffsets = toLongArray(childOffsetsList); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
180 this.childrenOffsets = toLongArray(childrenOffsetsList); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
181 } |
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
|
182 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
183 public NodeField[] getFields() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
184 return fields; |
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
|
185 } |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
186 |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
187 public long getParentOffset() { |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
188 return parentOffset; |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
189 } |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
190 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
191 public long[] getChildOffsets() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
192 return childOffsets; |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
193 } |
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
194 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
195 public long[] getChildrenOffsets() { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
196 return childrenOffsets; |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
197 } |
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 } |
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
|
199 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
200 static class NodeIterator implements Iterator<Node> { |
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
|
201 |
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
|
202 private final Node 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
|
203 private final NodeClass nodeClass; |
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
|
204 private final int childrenCount; |
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
|
205 private int index; |
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
|
206 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
207 protected NodeIterator(Node node) { |
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
|
208 this.node = node; |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
209 this.index = 0; |
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
|
210 this.nodeClass = NodeClass.get(node.getClass()); |
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
|
211 this.childrenCount = childrenCount(); |
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
|
212 } |
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
|
213 |
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 private int childrenCount() { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
215 int nodeCount = nodeClass.childOffsets.length; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
216 for (long fieldOffset : nodeClass.childrenOffsets) { |
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
|
217 Node[] children = ((Node[]) unsafe.getObject(node, fieldOffset)); |
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
|
218 if (children != 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
|
219 nodeCount += children.length; |
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 } |
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 return nodeCount; |
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 } |
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 |
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 private Node nodeAt(int idx) { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
226 int nodeCount = nodeClass.childOffsets.length; |
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
|
227 if (idx < nodeCount) { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
228 return (Node) unsafe.getObject(node, nodeClass.childOffsets[idx]); |
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
|
229 } else { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
230 for (long fieldOffset : nodeClass.childrenOffsets) { |
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
|
231 Node[] nodeArray = (Node[]) unsafe.getObject(node, fieldOffset); |
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 if (idx < nodeCount + nodeArray.length) { |
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 nodeArray[idx - nodeCount]; |
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 nodeCount += nodeArray.length; |
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 } |
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
|
237 } |
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
|
238 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
|
239 } |
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 |
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 private void forward() { |
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 if (index < childrenCount) { |
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 index++; |
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
|
244 } |
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
|
245 } |
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
|
246 |
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
|
247 @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
|
248 public boolean hasNext() { |
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
|
249 return index < childrenCount; |
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
|
250 } |
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
|
251 |
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 @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
|
253 public Node next() { |
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
|
254 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
|
255 return nodeAt(index); |
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
|
256 } finally { |
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
|
257 forward(); |
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 } |
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 } |
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 |
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
|
261 @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
|
262 public void remove() { |
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 throw new UnsupportedOperationException(); |
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 } |
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
|
265 } |
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
|
266 |
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
|
267 private static long[] toLongArray(List<Long> list) { |
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
|
268 long[] array = new long[list.size()]; |
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
|
269 for (int i = 0; i < list.size(); i++) { |
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
|
270 array[i] = list.get(i); |
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
|
271 } |
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
|
272 return array; |
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
|
273 } |
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
|
274 |
9258
07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
7530
diff
changeset
|
275 protected static final Unsafe unsafe = getUnsafe(); |
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
|
276 |
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
|
277 private static Unsafe getUnsafe() { |
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
|
278 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
|
279 return Unsafe.getUnsafe(); |
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
|
280 } catch (SecurityException 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
|
281 } |
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
|
282 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
|
283 Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe"); |
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
|
284 theUnsafeInstance.setAccessible(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
|
285 return (Unsafe) theUnsafeInstance.get(Unsafe.class); |
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 } catch (Exception 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
|
287 throw new RuntimeException("exception while trying to get Unsafe.theUnsafe via reflection:", 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
|
288 } |
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
|
289 } |
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
|
290 |
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
|
291 @SuppressWarnings("unchecked") |
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
|
292 public static <T extends Node> T cloneNode(T orig) { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
293 Class<? extends Node> clazz = orig.getClass(); |
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
|
294 NodeClass nodeClass = NodeClass.get(clazz); |
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
|
295 Node clone = orig.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
|
296 if (clone == 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
|
297 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
|
298 } |
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
|
299 |
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
|
300 unsafe.putObject(clone, nodeClass.parentOffset, 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
|
301 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
302 for (long fieldOffset : nodeClass.childOffsets) { |
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
|
303 Node child = (Node) unsafe.getObject(orig, fieldOffset); |
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
|
304 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
|
305 Node clonedChild = cloneNode(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
|
306 if (clonedChild == 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
|
307 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
|
308 } |
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
|
309 |
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
|
310 unsafe.putObject(clonedChild, nodeClass.parentOffset, 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
|
311 unsafe.putObject(clone, fieldOffset, clonedChild); |
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
|
312 } |
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
|
313 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
314 for (long fieldOffset : nodeClass.childrenOffsets) { |
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
|
315 Node[] children = (Node[]) unsafe.getObject(orig, fieldOffset); |
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
|
316 if (children != null) { |
9486
6678695afc3b
NodeUtil.cloneNode: cloned children array should preserve component type.
Andreas Woess <andreas.woess@jku.at>
parents:
9278
diff
changeset
|
317 Node[] clonedChildren = children.clone(); |
6678695afc3b
NodeUtil.cloneNode: cloned children array should preserve component type.
Andreas Woess <andreas.woess@jku.at>
parents:
9278
diff
changeset
|
318 Arrays.fill(clonedChildren, null); |
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
|
319 for (int i = 0; i < children.length; i++) { |
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
|
320 Node clonedChild = cloneNode(children[i]); |
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
|
321 if (clonedChild == 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
|
322 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
|
323 } |
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
|
324 |
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
|
325 clonedChildren[i] = clonedChild; |
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
|
326 unsafe.putObject(clonedChild, nodeClass.parentOffset, 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
|
327 } |
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
|
328 unsafe.putObject(clone, fieldOffset, clonedChildren); |
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
|
329 } |
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
|
330 } |
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
|
331 return (T) 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
|
332 } |
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
|
333 |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
334 public static List<Node> findNodeChildren(Node node) { |
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
335 List<Node> nodes = new ArrayList<>(); |
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
|
336 NodeClass nodeClass = NodeClass.get(node.getClass()); |
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
|
337 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
338 for (long fieldOffset : nodeClass.childOffsets) { |
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
|
339 Object child = unsafe.getObject(node, fieldOffset); |
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
|
340 if (child != null) { |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
341 nodes.add((Node) child); |
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
|
342 } |
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
|
343 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
344 for (long fieldOffset : nodeClass.childrenOffsets) { |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
345 Node[] children = (Node[]) unsafe.getObject(node, fieldOffset); |
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
|
346 if (children != 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
|
347 nodes.addAll(Arrays.asList(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
|
348 } |
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 |
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 return 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
|
352 } |
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 |
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 public static void replaceChild(Node parent, Node oldChild, Node newChild) { |
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 NodeClass nodeClass = NodeClass.get(parent.getClass()); |
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 |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
357 for (long fieldOffset : nodeClass.getChildOffsets()) { |
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
|
358 if (unsafe.getObject(parent, fieldOffset) == oldChild) { |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
359 assert assertAssignable(nodeClass, fieldOffset, 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
|
360 unsafe.putObject(parent, fieldOffset, newChild); |
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 } |
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
|
362 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
363 |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
364 for (long fieldOffset : nodeClass.getChildrenOffsets()) { |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
365 Object arrayObject = unsafe.getObject(parent, fieldOffset); |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
366 if (arrayObject != null) { |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
367 assert arrayObject instanceof Node[] : "Children array must be instanceof Node[] "; |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
368 Node[] array = (Node[]) arrayObject; |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
369 for (int i = 0; i < array.length; i++) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
370 if (array[i] == oldChild) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
371 assert assertAssignable(nodeClass, fieldOffset, newChild); |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
372 array[i] = 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
|
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 } |
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
|
375 } |
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 } |
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 |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
379 private static boolean assertAssignable(NodeClass clazz, long fieldOffset, Object newValue) { |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
380 if (newValue == null) { |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
381 return true; |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
382 } |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
383 for (NodeField field : clazz.getFields()) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
384 if (field.getOffset() == fieldOffset) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
385 if (field.getKind() == NodeFieldKind.CHILD) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
386 if (field.getType().isAssignableFrom(newValue.getClass())) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
387 return true; |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
388 } else { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
389 assert false : "Child class " + newValue.getClass().getName() + " is not assignable to field \"" + field.getName() + "\" of type " + field.getType().getName(); |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
390 return false; |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
391 } |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
392 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
393 if (field.getType().getComponentType().isAssignableFrom(newValue.getClass())) { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
394 return true; |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
395 } else { |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
396 assert false : "Child class " + newValue.getClass().getName() + " is not assignable to field \"" + field.getName() + "\" of type " + field.getType().getName(); |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
397 return false; |
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
398 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
399 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
400 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
401 } |
10755
b221e31d7b0b
Truffle: revise NodeUtil.replaceChild assertion
Andreas Woess <andreas.woess@jku.at>
parents:
10742
diff
changeset
|
402 throw new IllegalArgumentException(); |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
403 } |
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
404 |
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
|
405 /** Returns all declared fields in the class hierarchy. */ |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
406 private static Field[] getAllFields(Class<? extends Object> clazz) { |
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
|
407 Field[] declaredFields = clazz.getDeclaredFields(); |
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
|
408 if (clazz.getSuperclass() != 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
|
409 return concat(getAllFields(clazz.getSuperclass()), declaredFields); |
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
|
410 } |
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
|
411 return declaredFields; |
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
|
412 } |
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
|
413 |
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 public static <T> T[] concat(T[] first, T[] second) { |
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 T[] result = Arrays.copyOf(first, first.length + second.length); |
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 System.arraycopy(second, 0, result, first.length, second.length); |
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 return result; |
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 } |
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 |
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 /** find annotation in class/interface hierarchy. */ |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
421 public static <T extends Annotation> T findAnnotation(Class<?> clazz, Class<T> annotationClass) { |
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
|
422 if (clazz.getAnnotation(annotationClass) != 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
|
423 return clazz.getAnnotation(annotationClass); |
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 } else { |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
425 for (Class<?> intf : clazz.getInterfaces()) { |
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
|
426 if (intf.getAnnotation(annotationClass) != 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
|
427 return intf.getAnnotation(annotationClass); |
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 } |
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 if (clazz.getSuperclass() != 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
|
431 return findAnnotation(clazz.getSuperclass(), annotationClass); |
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
|
432 } |
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
|
433 } |
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
|
434 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
|
435 } |
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
|
436 |
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
|
437 @SuppressWarnings("unchecked") |
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
|
438 public static <T extends Node> T findParent(final Node start, final Class<T> clazz) { |
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
|
439 assert start != 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
|
440 if (clazz.isInstance(start.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
|
441 return (T) start.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
|
442 } else { |
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
|
443 return start.getParent() != null ? findParent(start.getParent(), clazz) : 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
|
444 } |
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
|
445 } |
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
|
446 |
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
|
447 @SuppressWarnings("unchecked") |
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
|
448 public static <I> I findParentInterface(final Node start, final Class<I> clazz) { |
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
|
449 assert start != 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
|
450 if (clazz.isInstance(start.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
|
451 return (I) start.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
|
452 } else { |
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
|
453 return (start.getParent() != null ? findParentInterface(start.getParent(), clazz) : 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
|
454 } |
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
|
455 } |
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
|
456 |
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
|
457 @SuppressWarnings("unchecked") |
9537
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
458 public static <T> T findFirstNodeInstance(Node root, Class<T> clazz) { |
e2965e5cd474
Fixed Truffle child iterator should only iterate children which are annotated with @Child or @Children.
Christian Humer <christian.humer@gmail.com>
parents:
9487
diff
changeset
|
459 for (Node childNode : findNodeChildren(root)) { |
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
|
460 if (clazz.isInstance(childNode)) { |
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
|
461 return (T) childNode; |
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
|
462 } else { |
9487
0285fbb8b05d
NodeUtil.findFirstNodeInstance bug fix
Andreas Woess <andreas.woess@jku.at>
parents:
9486
diff
changeset
|
463 T node = findFirstNodeInstance(childNode, clazz); |
0285fbb8b05d
NodeUtil.findFirstNodeInstance bug fix
Andreas Woess <andreas.woess@jku.at>
parents:
9486
diff
changeset
|
464 if (node != null) { |
0285fbb8b05d
NodeUtil.findFirstNodeInstance bug fix
Andreas Woess <andreas.woess@jku.at>
parents:
9486
diff
changeset
|
465 return node; |
0285fbb8b05d
NodeUtil.findFirstNodeInstance bug fix
Andreas Woess <andreas.woess@jku.at>
parents:
9486
diff
changeset
|
466 } |
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
|
467 } |
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
|
468 } |
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
|
469 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
|
470 } |
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
|
471 |
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
|
472 public static <T extends Node> List<T> findAllNodeInstances(final Node root, final Class<T> clazz) { |
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
|
473 final List<T> nodeList = new ArrayList<>(); |
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
|
474 root.accept(new 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
|
475 |
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
|
476 @SuppressWarnings("unchecked") |
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
|
477 @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
|
478 public boolean visit(Node 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
|
479 if (clazz.isInstance(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
|
480 nodeList.add((T) 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
|
481 } |
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
|
482 return 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
|
483 } |
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
|
484 }); |
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
|
485 return nodeList; |
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
|
486 } |
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 |
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
|
488 // Don't visit found node instances. |
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
|
489 public static <T extends Node> List<T> findNodeInstancesShallow(final Node root, final Class<T> clazz) { |
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
|
490 final List<T> nodeList = new ArrayList<>(); |
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
|
491 root.accept(new 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
|
492 |
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
|
493 @SuppressWarnings("unchecked") |
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
|
494 @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
|
495 public boolean visit(Node 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
|
496 if (clazz.isInstance(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
|
497 nodeList.add((T) 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
|
498 return 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
|
499 } |
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
|
500 return 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
|
501 } |
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
|
502 }); |
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
|
503 return nodeList; |
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
|
504 } |
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
|
505 |
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
|
506 /** Find node instances within current function only (not in nested functions). */ |
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
|
507 public static <T extends Node> List<T> findNodeInstancesInFunction(final Node root, final Class<T> clazz) { |
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
|
508 final List<T> nodeList = new ArrayList<>(); |
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
|
509 root.accept(new 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
|
510 |
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
|
511 @SuppressWarnings("unchecked") |
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
|
512 @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
|
513 public boolean visit(Node 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
|
514 if (clazz.isInstance(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
|
515 nodeList.add((T) 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
|
516 } else if (node instanceof RootNode && node != root) { |
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
|
517 return 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
|
518 } |
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
|
519 return 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
|
520 } |
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
|
521 }); |
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
|
522 return nodeList; |
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
|
523 } |
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
|
524 |
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
|
525 public static <I> List<I> findNodeInstancesInFunctionInterface(final Node root, final Class<I> clazz) { |
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
|
526 final List<I> nodeList = new ArrayList<>(); |
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
|
527 root.accept(new 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
|
528 |
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
|
529 @SuppressWarnings("unchecked") |
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
|
530 @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
|
531 public boolean visit(Node 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
|
532 if (clazz.isInstance(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
|
533 nodeList.add((I) 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
|
534 } else if (node instanceof RootNode && node != root) { |
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
|
535 return 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
|
536 } |
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
|
537 return 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
|
538 } |
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
|
539 }); |
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
|
540 return nodeList; |
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
|
541 } |
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
|
542 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
543 public static int countNodes(Node root) { |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
544 return countNodes(root, null); |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
545 } |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
546 |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
547 public static int countNodes(Node root, Class<?> clazz) { |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
548 NodeCountVisitor nodeCount = new NodeCountVisitor(clazz); |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
549 root.accept(nodeCount); |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
550 return nodeCount.nodeCount; |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
551 } |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
552 |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
553 private static final class NodeCountVisitor implements NodeVisitor { |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
554 |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
555 private final Class<?> clazz; |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
556 int nodeCount; |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
557 |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
558 private NodeCountVisitor(Class<?> clazz) { |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
559 this.clazz = clazz; |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
560 } |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
561 |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
562 @Override |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
563 public boolean visit(Node node) { |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
564 if (node instanceof RootNode && nodeCount > 0) { |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
565 return false; |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
566 } |
10793
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
567 if (clazz == null || clazz.isInstance(node)) { |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
568 nodeCount++; |
6e12e0ace0d5
Truffle: add NodeUtil.countNodes overload that counts nodes of a specific type
Andreas Woess <andreas.woess@jku.at>
parents:
10756
diff
changeset
|
569 } |
10704
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
570 return true; |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
571 } |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
572 } |
84b944726df2
Truffle: introduce NodeUtil.countNodes
Andreas Woess <andreas.woess@jku.at>
parents:
9754
diff
changeset
|
573 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
574 public static String printCompactTreeToString(Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
575 StringWriter out = new StringWriter(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
576 printCompactTree(new PrintWriter(out), null, node, 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
577 return out.toString(); |
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
|
578 } |
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
|
579 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
580 public static void printCompactTree(OutputStream out, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
581 printCompactTree(new PrintWriter(out), null, node, 1); |
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
|
582 } |
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
|
583 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
584 private static void printCompactTree(PrintWriter p, Node parent, Node node, int level) { |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
585 if (node == null) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
586 return; |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
587 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
588 for (int i = 0; i < level; i++) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
589 p.print(" "); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
590 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
591 if (parent == null) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
592 p.println(node.getClass().getSimpleName()); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
593 } else { |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
594 String fieldName = "unknownField"; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
595 NodeField[] fields = NodeClass.get(parent.getClass()).fields; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
596 for (NodeField field : fields) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
597 Object value = field.loadValue(parent); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
598 if (value == node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
599 fieldName = field.getName(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
600 break; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
601 } else if (value instanceof Node[]) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
602 int index = 0; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
603 for (Node arrayNode : (Node[]) value) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
604 if (arrayNode == node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
605 fieldName = field.getName() + "[" + index + "]"; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
606 break; |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
607 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
608 index++; |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
609 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
610 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
611 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
612 p.print(fieldName); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
613 p.print(" = "); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
614 p.println(node.getClass().getSimpleName()); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
615 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
616 |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
617 for (Node child : node.getChildren()) { |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
618 printCompactTree(p, node, child, level + 1); |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
619 } |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
620 p.flush(); |
9538
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
621 } |
e6fe35d64b71
Implemented a method to produce a compact string representation of the truffle tree which just shows the nodes and their children but no data fields.
Christian Humer <christian.humer@gmail.com>
parents:
9537
diff
changeset
|
622 |
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
|
623 /** |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
624 * Prints a human readable form of a {@link Node} AST to the given {@link PrintStream}. This |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
625 * print method does not check for cycles in the node structure. |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7267
diff
changeset
|
626 * |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
627 * @param out the stream to print to. |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
628 * @param node the root node to write |
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
|
629 */ |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
630 public static void printTree(OutputStream out, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
631 printTree(new PrintWriter(out), node); |
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
|
632 } |
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
|
633 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
634 public static String printTreeToString(Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
635 StringWriter out = new StringWriter(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
636 printTree(new PrintWriter(out), node); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
637 return out.toString(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
638 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
639 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
640 public static void printTree(PrintWriter p, Node node) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
641 printTree(p, node, 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
642 p.println(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
643 p.flush(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
644 } |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
645 |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
646 private static void printTree(PrintWriter p, Node node, int level) { |
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
|
647 if (node == 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
|
648 p.print("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
|
649 return; |
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
|
650 } |
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
|
651 |
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
|
652 p.print(node.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
|
653 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
654 ArrayList<NodeField> childFields = new ArrayList<>(); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
655 String sep = ""; |
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
|
656 p.print("("); |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
657 for (NodeField field : NodeClass.get(node.getClass()).fields) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
658 if (field.getKind() == NodeFieldKind.CHILD || field.getKind() == NodeFieldKind.CHILDREN) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
659 childFields.add(field); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
660 } else if (field.getKind() == NodeFieldKind.DATA) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
661 p.print(sep); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
662 sep = ", "; |
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
|
663 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
664 p.print(field.getName()); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
665 p.print(" = "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
666 p.print(field.loadValue(node)); |
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
|
667 } |
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
|
668 } |
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
|
669 p.print(")"); |
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
|
670 |
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
|
671 if (childFields.size() != 0) { |
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
|
672 p.print(" {"); |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
673 for (NodeField field : childFields) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
674 printNewLine(p, level); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
675 p.print(field.getName()); |
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
|
676 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
677 Object value = field.loadValue(node); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
678 if (value == null) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
679 p.print(" = null "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
680 } else if (field.getKind() == NodeFieldKind.CHILD) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
681 p.print(" = "); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
682 printTree(p, (Node) value, level + 1); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
683 } else if (field.getKind() == NodeFieldKind.CHILDREN) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
684 Node[] children = (Node[]) value; |
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
|
685 p.print(" = ["); |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
686 sep = ""; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
687 for (Node child : children) { |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
688 p.print(sep); |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
689 sep = ", "; |
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
690 printTree(p, child, level + 1); |
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
|
691 } |
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
|
692 p.print("]"); |
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
|
693 } |
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
|
694 } |
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
|
695 printNewLine(p, level - 1); |
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
|
696 p.print("}"); |
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
|
697 } |
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
|
698 } |
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
|
699 |
9754
98b004bf3985
Refactoring of NodeUtil to centralize the use of reflection
Christian Wimmer <christian.wimmer@oracle.com>
parents:
9538
diff
changeset
|
700 private static void printNewLine(PrintWriter p, int level) { |
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
|
701 p.println(); |
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
|
702 for (int i = 0; i < level; i++) { |
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
|
703 p.print(" "); |
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
|
704 } |
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
|
705 } |
10742
99789440ce28
Truffle: Added assertions to replaceChild.
Christian Humer <christian.humer@gmail.com>
parents:
10704
diff
changeset
|
706 |
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
|
707 } |