Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeCodeGenerator.java @ 18726:8153d8cf264c
Added unit test for StampFactoryTest.createParameterStamps.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 19 Dec 2014 14:58:50 +0100 |
parents | 58eb9bbb60c4 |
children | 1acaa69ff61b |
rev | line source |
---|---|
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.generator; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
24 |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
25 import static com.oracle.truffle.dsl.processor.java.ElementUtils.*; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static javax.lang.model.element.Modifier.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import java.util.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import javax.lang.model.element.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 import javax.lang.model.type.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 import javax.lang.model.util.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 import com.oracle.truffle.api.dsl.*; |
10741
00a9dbcbe431
Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10695
diff
changeset
|
35 import com.oracle.truffle.api.nodes.*; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.dsl.processor.*; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
37 import com.oracle.truffle.dsl.processor.java.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
38 import com.oracle.truffle.dsl.processor.java.model.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
39 import com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
40 import com.oracle.truffle.dsl.processor.model.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
41 import com.oracle.truffle.dsl.processor.model.NodeChildData.Cardinality; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
42 import com.oracle.truffle.dsl.processor.parser.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
43 import com.oracle.truffle.dsl.processor.parser.SpecializationGroup.TypeGuard; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
44 |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
45 public class NodeCodeGenerator extends AbstractCompilationUnitFactory<NodeData> { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 private static final String THIS_NODE_LOCAL_VAR_NAME = "thisNode"; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
49 private static final String EXECUTE_CHAINED = "executeChained0"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
50 private static final String SPECIALIZE = "specialize0"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
51 private static final String DSLSHARE_REWRITE = "rewrite"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
52 private static final String DSLSHARE_FIND_ROOT = "findRoot"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
53 private static final String DSLSHARE_REWRITE_TO_POLYMORHPIC = "rewriteToPolymorphic"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
54 private static final String EXECUTE_UNINITIALIZED = "executeUninitialized0"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
55 private static final String REWRITE = "rewrite0"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
56 private static final String CREATE_INFO = "createInfo0"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
57 private static final String CONTAINS_FALLBACK = "containsFallback"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
58 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
59 private static final String FACTORY_METHOD_NAME = "create0"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
60 private static final String EMPTY_CLASS_ARRAY = "EMPTY_CLASS_ARRAY"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
61 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
62 private static final String METADATA_FIELD_NAME = "METADATA"; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 private TypeMirror getUnexpectedValueException() { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 return getContext().getTruffleTypes().getUnexpectedValueException(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 private static String factoryClassName(NodeData node) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 return node.getNodeId() + "Factory"; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 private static String nodeSpecializationClassName(SpecializationData specialization) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
73 String nodeid = resolveNodeId(specialization.getNode()); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
74 String name = ElementUtils.firstLetterUpperCase(nodeid); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
75 name += ElementUtils.firstLetterUpperCase(specialization.getId()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 name += "Node"; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 return name; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
80 private static String nodePolymorphicClassName(NodeData node) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
81 return ElementUtils.firstLetterUpperCase(resolveNodeId(node)) + "PolymorphicNode"; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
84 private static String resolveNodeId(NodeData node) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
85 String nodeid = node.getNodeId(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
86 if (nodeid.endsWith("Node") && !nodeid.equals("Node")) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
87 nodeid = nodeid.substring(0, nodeid.length() - 4); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
88 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
89 return nodeid; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
90 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
91 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
92 private static String valueNameEvaluated(Parameter targetParameter) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
93 return valueName(targetParameter) + "Evaluated"; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
95 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
96 private static String implicitTypeName(Parameter param) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
97 return param.getLocalName() + "ImplicitType"; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
98 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
99 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
100 private static String polymorphicTypeName(NodeExecutionData param) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
101 return param.getName() + "PolymorphicType"; |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
102 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
103 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
104 private static String valueName(Parameter param) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 return param.getLocalName(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
108 private static CodeTree createAccessChild(NodeExecutionData targetExecution, String thisReference) { |
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
109 String reference = thisReference; |
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
110 if (reference == null) { |
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
111 reference = "this"; |
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
112 } |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
113 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
114 Element accessElement = targetExecution.getChild().getAccessElement(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
115 if (accessElement == null || accessElement.getKind() == ElementKind.METHOD) { |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
116 builder.string(reference).string(".").string(targetExecution.getChild().getName()); |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
117 } else if (accessElement.getKind() == ElementKind.FIELD) { |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
118 builder.string(reference).string(".").string(accessElement.getSimpleName().toString()); |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
119 } else { |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
120 throw new AssertionError(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
121 } |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
122 if (targetExecution.isIndexed()) { |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
123 builder.string("[" + targetExecution.getIndex() + "]"); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
124 } |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
125 return builder.getRoot(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
126 } |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
127 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
128 private static String castValueName(Parameter parameter) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
129 return valueName(parameter) + "Cast"; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
130 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
131 |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
132 private void addInternalValueParameters(CodeExecutableElement method, TemplateMethod specialization, boolean forceFrame, boolean disableFrame, boolean evaluated) { |
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
133 if (forceFrame && !disableFrame && specialization.getSpecification().findParameterSpec("frame") != null) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
134 method.addParameter(new CodeVariableElement(getContext().getTruffleTypes().getFrame(), "frameValue")); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
135 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
136 for (Parameter parameter : specialization.getParameters()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
137 ParameterSpec spec = parameter.getSpecification(); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
138 if ((disableFrame || forceFrame) && spec.getName().equals("frame")) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
139 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 if (spec.isLocal()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
143 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
144 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 String name = valueName(parameter); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 if (evaluated && spec.isSignature()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
147 name = valueNameEvaluated(parameter); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
150 method.addParameter(new CodeVariableElement(parameter.getType(), name)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
151 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
152 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
154 private static void addInternalValueParameterNames(CodeTreeBuilder builder, TemplateMethod source, TemplateMethod specialization, String unexpectedValueName, boolean forceFrame, |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
155 boolean disableFrame, Map<String, String> customNames) { |
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
156 if (forceFrame && !disableFrame && specialization.getSpecification().findParameterSpec("frame") != null) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 builder.string("frameValue"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
158 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
159 for (Parameter parameter : specialization.getParameters()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
160 ParameterSpec spec = parameter.getSpecification(); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
161 if ((disableFrame || forceFrame) && spec.getName().equals("frame")) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
162 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
163 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
164 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
165 if (parameter.getSpecification().isLocal()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
166 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
167 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
168 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
169 Parameter sourceParameter = source.findParameter(parameter.getLocalName()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
170 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
171 if (customNames != null && customNames.containsKey(parameter.getLocalName())) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
172 builder.string(customNames.get(parameter.getLocalName())); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
173 } else if (unexpectedValueName != null && parameter.getLocalName().equals(unexpectedValueName)) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
174 builder.cast(parameter.getType(), CodeTreeBuilder.singleString("ex.getResult()")); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
175 } else if (sourceParameter != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
176 builder.string(valueName(sourceParameter, parameter)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
177 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
178 builder.string(valueName(parameter)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
179 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
180 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
181 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
182 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
183 private static String valueName(Parameter sourceParameter, Parameter targetParameter) { |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
184 if (!sourceParameter.getSpecification().isSignature()) { |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
185 return valueName(targetParameter); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
186 } else if (sourceParameter.getTypeSystemType() != null && targetParameter.getTypeSystemType() != null) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
187 if (sourceParameter.getTypeSystemType().needsCastTo(targetParameter.getTypeSystemType())) { |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
188 return castValueName(targetParameter); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
189 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
190 } |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
191 return valueName(targetParameter); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
192 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
193 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
194 private static CodeTree createTemplateMethodCall(CodeTreeBuilder parent, CodeTree target, TemplateMethod sourceMethod, TemplateMethod targetMethod, String unexpectedValueName, |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
195 String... customSignatureValueNames) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
196 CodeTreeBuilder builder = parent.create(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
197 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
198 boolean castedValues = sourceMethod != targetMethod; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
199 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
200 builder.startGroup(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
201 ExecutableElement method = targetMethod.getMethod(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
202 if (method == null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
203 throw new UnsupportedOperationException(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
204 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
205 TypeElement targetClass = ElementUtils.findNearestEnclosingType(method.getEnclosingElement()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
206 NodeData node = (NodeData) targetMethod.getTemplate(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
207 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
208 if (target == null) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
209 boolean accessible = targetMethod.canBeAccessedByInstanceOf(node.getNodeType()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
210 if (accessible) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
211 if (builder.findMethod().getModifiers().contains(STATIC)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
212 if (method.getModifiers().contains(STATIC)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
213 builder.type(targetClass.asType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
214 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
215 builder.string(THIS_NODE_LOCAL_VAR_NAME); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
216 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
217 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
218 if (targetMethod instanceof ExecutableTypeData) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
219 builder.string("this"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
220 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
221 builder.string("super"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
222 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
223 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
224 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
225 if (method.getModifiers().contains(STATIC)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
226 builder.type(targetClass.asType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
227 } else { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
228 Parameter firstParameter = null; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
229 for (Parameter searchParameter : targetMethod.getParameters()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
230 if (searchParameter.getSpecification().isSignature()) { |
14598
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
231 firstParameter = searchParameter; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
232 break; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
233 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
234 } |
14598
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
235 if (firstParameter == null) { |
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
236 throw new AssertionError(); |
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
237 } |
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
238 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
239 Parameter sourceParameter = sourceMethod.findParameter(firstParameter.getLocalName()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
240 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
241 if (castedValues && sourceParameter != null) { |
14598
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
242 builder.string(valueName(sourceParameter, firstParameter)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
243 } else { |
14598
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
244 builder.string(valueName(firstParameter)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
245 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
246 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
247 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
248 builder.string("."); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
249 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
250 builder.tree(target); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
251 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
252 builder.startCall(method.getSimpleName().toString()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
253 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
254 int signatureIndex = 0; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
255 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
256 for (Parameter targetParameter : targetMethod.getParameters()) { |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
257 Parameter valueParameter = null; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
258 if (sourceMethod != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
259 valueParameter = sourceMethod.findParameter(targetParameter.getLocalName()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
260 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
261 if (valueParameter == null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
262 valueParameter = targetParameter; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
263 } |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
264 TypeMirror targetType = targetParameter.getType(); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
265 TypeMirror valueType = null; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
266 if (valueParameter != null) { |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
11320
diff
changeset
|
267 valueType = valueParameter.getType(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
268 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
269 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
270 if (signatureIndex < customSignatureValueNames.length && targetParameter.getSpecification().isSignature()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
271 builder.string(customSignatureValueNames[signatureIndex]); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
272 signatureIndex++; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
273 } else if (targetParameter.getSpecification().isLocal()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
274 builder.startGroup(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
275 if (builder.findMethod().getModifiers().contains(Modifier.STATIC)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
276 builder.string(THIS_NODE_LOCAL_VAR_NAME).string("."); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
277 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
278 builder.string("this."); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
279 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
280 builder.string(targetParameter.getSpecification().getName()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
281 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
282 } else if (unexpectedValueName != null && targetParameter.getLocalName().equals(unexpectedValueName)) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
283 builder.cast(targetParameter.getType(), CodeTreeBuilder.singleString("ex.getResult()")); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
284 } else if (!ElementUtils.needsCastTo(valueType, targetType)) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
285 builder.startGroup(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
286 builder.string(valueName(targetParameter)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
287 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
288 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
289 builder.string(castValueName(targetParameter)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
290 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
291 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
292 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
293 builder.end().end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
294 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
295 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
296 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
297 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
298 private static String baseClassName(NodeData node) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
299 String nodeid = resolveNodeId(node); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
300 String name = ElementUtils.firstLetterUpperCase(nodeid); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
301 name += "BaseNode"; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
302 return name; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
303 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
304 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
305 private static CodeTree createCallTypeSystemMethod(CodeTreeBuilder parent, NodeData node, String methodName, CodeTree... args) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
306 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
307 startCallTypeSystemMethod(builder, node.getTypeSystem(), methodName); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
308 for (CodeTree arg : args) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
309 builder.tree(arg); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
310 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
311 builder.end().end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
312 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
313 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
314 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
315 private static void startCallTypeSystemMethod(CodeTreeBuilder body, TypeSystemData typeSystem, String methodName) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
316 GeneratedTypeMirror typeMirror = new GeneratedTypeMirror(ElementUtils.getPackageName(typeSystem.getTemplateType()), TypeSystemCodeGenerator.typeName(typeSystem)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
317 body.startGroup(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
318 body.staticReference(typeMirror, TypeSystemCodeGenerator.singletonName(typeSystem)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
319 body.string(".").startCall(methodName); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
320 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
321 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
322 /** |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
323 * <pre> |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
324 * variant1 $condition != null |
18605
58eb9bbb60c4
Truffle-DSL: fixed several bugs when using arrays as type. added arrays test.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
325 * |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
326 * $type $name = defaultValue($type); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
327 * if ($condition) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
328 * $name = $value; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
329 * } |
18605
58eb9bbb60c4
Truffle-DSL: fixed several bugs when using arrays as type. added arrays test.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
330 * |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
331 * variant2 $condition != null |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
332 * $type $name = $value; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
333 * </pre> |
15459
0dae565d9289
fixed code that ecj had a problem compiling
Doug Simon <doug.simon@oracle.com>
parents:
14642
diff
changeset
|
334 * |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
335 * . |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
336 */ |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
337 private static CodeTree createLazyAssignment(CodeTreeBuilder parent, String name, TypeMirror type, CodeTree condition, CodeTree value) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
338 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
339 if (condition == null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
340 builder.declaration(type, name, value); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
341 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
342 builder.declaration(type, name, new CodeTreeBuilder(parent).defaultValue(type).getRoot()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
343 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
344 builder.startIf().tree(condition).end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
345 builder.startBlock(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
346 builder.startStatement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
347 builder.string(name); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
348 builder.string(" = "); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
349 builder.tree(value); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
350 builder.end(); // statement |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
351 builder.end(); // block |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
352 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
353 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
354 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
355 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
356 private void emitEncounteredSynthetic(CodeTreeBuilder builder, TemplateMethod current) { |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
357 CodeTreeBuilder nodes = builder.create(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
358 CodeTreeBuilder arguments = builder.create(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
359 nodes.startCommaGroup(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
360 arguments.startCommaGroup(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
361 boolean empty = true; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
362 for (Parameter parameter : current.getParameters()) { |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
363 NodeExecutionData executionData = parameter.getSpecification().getExecution(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
364 if (executionData != null) { |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
365 if (executionData.isShortCircuit()) { |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
366 nodes.nullLiteral(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
367 arguments.string(valueName(parameter.getPreviousParameter())); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
368 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
369 nodes.tree(createAccessChild(executionData, "rootNode")); |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
370 arguments.string(valueName(parameter)); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
371 empty = false; |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
372 } |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
373 } |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
374 nodes.end(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
375 arguments.end(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
376 builder.startStatement().startStaticCall(context.getTruffleTypes().getCompilerDirectives(), "transferToInterpreter").end().end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
377 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
378 builder.declaration(baseClassName(getModel()), "rootNode", builder.create().startStaticCall(context.getTruffleTypes().getDslShare(), DSLSHARE_FIND_ROOT).string("this").end()); |
13812
f270f09616da
Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
13536
diff
changeset
|
379 builder.startThrow().startNew(getContext().getType(UnsupportedSpecializationException.class)); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
380 builder.string("rootNode"); |
13861
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
381 builder.startNewArray(getContext().getTruffleTypes().getNodeArray(), null); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
382 builder.tree(nodes.getRoot()); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
383 builder.end(); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
384 if (!empty) { |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
385 builder.tree(arguments.getRoot()); |
28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
Christian Humer <christian.humer@gmail.com>
parents:
13812
diff
changeset
|
386 } |
13812
f270f09616da
Truffle-DSL: implemented specific structured exception for unsupported specializations. (GRAAL-682)
Christian Humer <christian.humer@gmail.com>
parents:
13536
diff
changeset
|
387 builder.end().end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
388 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
389 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
390 private static List<ExecutableElement> findUserConstructors(TypeMirror nodeType) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
391 List<ExecutableElement> constructors = new ArrayList<>(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
392 for (ExecutableElement constructor : ElementFilter.constructorsIn(ElementUtils.fromTypeMirror(nodeType).getEnclosedElements())) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
393 if (constructor.getModifiers().contains(PRIVATE)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
394 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
395 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
396 if (isCopyConstructor(constructor)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
397 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
398 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
399 constructors.add(constructor); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
400 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
401 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
402 if (constructors.isEmpty()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
403 constructors.add(new CodeExecutableElement(null, ElementUtils.getSimpleName(nodeType))); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
404 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
405 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
406 return constructors; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
407 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
408 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
409 private static ExecutableElement findCopyConstructor(TypeMirror type) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
410 for (ExecutableElement constructor : ElementFilter.constructorsIn(ElementUtils.fromTypeMirror(type).getEnclosedElements())) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
411 if (constructor.getModifiers().contains(PRIVATE)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
412 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
413 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
414 if (isCopyConstructor(constructor)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
415 return constructor; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
416 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
417 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
418 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
419 return null; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
420 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
421 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
422 private static boolean isCopyConstructor(ExecutableElement element) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
423 if (element.getParameters().size() != 1) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
424 return false; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
425 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
426 VariableElement var = element.getParameters().get(0); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
427 TypeElement enclosingType = ElementUtils.findNearestEnclosingType(var); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
428 if (ElementUtils.typeEquals(var.asType(), enclosingType.asType())) { |
11180
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
429 return true; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
430 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
431 List<TypeElement> types = ElementUtils.getDirectSuperTypes(enclosingType); |
11180
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
432 for (TypeElement type : types) { |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
433 if (!(type instanceof CodeTypeElement)) { |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
434 // no copy constructors which are not generated types |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
435 return false; |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
436 } |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
437 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
438 if (ElementUtils.typeEquals(var.asType(), type.asType())) { |
11180
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
439 return true; |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
440 } |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
441 } |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
442 return false; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
443 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
444 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
445 @Override |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
446 @SuppressWarnings("unchecked") |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
447 protected void createChildren(NodeData node) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
448 List<CodeTypeElement> casts = new ArrayList<>(getElement().getEnclosedElements()); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
449 getElement().getEnclosedElements().clear(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
450 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
451 Map<NodeData, List<TypeElement>> childTypes = new LinkedHashMap<>(); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
452 for (NodeData nodeChild : node.getEnclosingNodes()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
453 NodeCodeGenerator generator = new NodeCodeGenerator(); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
454 childTypes.put(nodeChild, generator.process(null, nodeChild).getEnclosedElements()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
455 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
456 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
457 if (node.needsFactory() || node.getNodeDeclaringChildren().size() > 0) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
458 NodeFactoryFactory factory = new NodeFactoryFactory(childTypes); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
459 add(factory, node); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
460 factory.getElement().getEnclosedElements().addAll(casts); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
461 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
462 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
463 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
464 private static CodeTree createCastType(TypeSystemData typeSystem, TypeData sourceType, TypeData targetType, boolean expect, CodeTree value) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
465 if (targetType == null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
466 return value; |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
467 } else if (sourceType != null && !sourceType.needsCastTo(targetType)) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
468 return value; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
469 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
470 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
471 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
472 String targetMethodName; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
473 if (expect) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
474 targetMethodName = TypeSystemCodeGenerator.expectTypeMethodName(targetType); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
475 } else { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
476 targetMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
477 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
478 startCallTypeSystemMethod(builder, typeSystem, targetMethodName); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
479 builder.tree(value); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
480 builder.end().end(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
481 return builder.getRoot(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
482 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
483 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
484 private static CodeTree createExpectType(TypeSystemData typeSystem, TypeData sourceType, TypeData targetType, CodeTree expression) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
485 return createCastType(typeSystem, sourceType, targetType, true, expression); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
486 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
487 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
488 private CodeTree createDeoptimize(CodeTreeBuilder parent) { |
13275
bd5c996b5d25
Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents:
13272
diff
changeset
|
489 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
bd5c996b5d25
Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents:
13272
diff
changeset
|
490 builder.startStatement(); |
bd5c996b5d25
Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents:
13272
diff
changeset
|
491 builder.startStaticCall(getContext().getTruffleTypes().getCompilerDirectives(), "transferToInterpreterAndInvalidate").end(); |
bd5c996b5d25
Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents:
13272
diff
changeset
|
492 builder.end(); |
bd5c996b5d25
Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents:
13272
diff
changeset
|
493 return builder.getRoot(); |
bd5c996b5d25
Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents:
13272
diff
changeset
|
494 } |
bd5c996b5d25
Truffle-DSL: fixed wrong transferToInterpreter with transferToInterpreterAndInvalidate.
Christian Humer <christian.humer@gmail.com>
parents:
13272
diff
changeset
|
495 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
496 private class NodeFactoryFactory extends AbstractClassElementFactory<NodeData> { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
497 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
498 private final Map<NodeData, List<TypeElement>> childTypes; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
499 private CodeTypeElement generatedNode; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
500 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
501 public NodeFactoryFactory(Map<NodeData, List<TypeElement>> childElements) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
502 this.childTypes = childElements; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
503 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
504 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
505 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
506 protected CodeTypeElement create(NodeData node) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
507 Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
508 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
509 CodeTypeElement clazz = createClass(node, modifiers(), factoryClassName(node), null, false); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
510 if (visibility != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
511 clazz.getModifiers().add(visibility); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
512 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
513 clazz.getModifiers().add(Modifier.FINAL); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
514 return clazz; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
515 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
516 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
517 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
518 protected void createChildren(NodeData node) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
519 CodeTypeElement clazz = getElement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
520 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
521 Modifier createVisibility = ElementUtils.getVisibility(clazz.getModifiers()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
522 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
523 if (node.needsFactory()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
524 NodeBaseFactory factory = new NodeBaseFactory(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
525 add(factory, node.getGenericSpecialization() == null ? node.getSpecializations().get(0) : node.getGenericSpecialization()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
526 generatedNode = factory.getElement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
527 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
528 createFactoryMethods(node, clazz, createVisibility); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
529 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
530 for (SpecializationData specialization : node.getSpecializations()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
531 if (!specialization.isReachable() || specialization.isGeneric()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
532 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
533 } |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
534 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
535 if (specialization.isPolymorphic() && node.isPolymorphic(context)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
536 PolymorphicNodeFactory polymorphicFactory = new PolymorphicNodeFactory(generatedNode); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
537 add(polymorphicFactory, specialization); |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
538 continue; |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
539 } |
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
540 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
541 add(new SpecializedNodeFactory(generatedNode), specialization); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
542 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
543 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
544 TypeMirror nodeFactory = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(getContext().getTruffleTypes().getNodeFactoryBase()), node.getNodeType()); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
545 clazz.setSuperClass(nodeFactory); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
546 clazz.add(createNodeFactoryConstructor(node)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
547 clazz.add(createCreateNodeMethod(node)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
548 clazz.add(createGetInstanceMethod(node, createVisibility)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
549 clazz.add(createInstanceConstant(node, clazz.asType())); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
550 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
551 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
552 for (NodeData childNode : childTypes.keySet()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
553 if (childNode.getTemplateType().getModifiers().contains(Modifier.PRIVATE)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
554 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
555 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
556 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
557 for (TypeElement type : childTypes.get(childNode)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
558 Set<Modifier> typeModifiers = ((CodeTypeElement) type).getModifiers(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
559 Modifier visibility = ElementUtils.getVisibility(type.getModifiers()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
560 typeModifiers.clear(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
561 if (visibility != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
562 typeModifiers.add(visibility); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
563 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
564 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
565 typeModifiers.add(Modifier.STATIC); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
566 typeModifiers.add(Modifier.FINAL); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
567 clazz.add(type); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
568 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
569 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
570 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
571 List<NodeData> children = node.getNodeDeclaringChildren(); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
572 if (node.getDeclaringNode() == null && children.size() > 0) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
573 clazz.add(createGetFactories(node)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
574 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
575 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
576 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
577 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
578 private Element createNodeFactoryConstructor(NodeData node) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
579 CodeExecutableElement method = new CodeExecutableElement(modifiers(PRIVATE), null, factoryClassName(node)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
580 CodeTreeBuilder builder = method.createBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
581 builder.startStatement(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
582 builder.startCall("super"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
583 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
584 // node type |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
585 builder.typeLiteral(node.getNodeType()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
586 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
587 // execution signature |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
588 builder.startGroup(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
589 if (node.getChildExecutions().isEmpty()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
590 builder.staticReference(context.getTruffleTypes().getDslMetadata(), EMPTY_CLASS_ARRAY); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
591 } else { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
592 builder.startNewArray(new ArrayCodeTypeMirror(context.getType(Class.class)), null); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
593 for (NodeExecutionData execution : node.getChildExecutions()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
594 builder.typeLiteral(execution.getNodeType()); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
595 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
596 builder.end(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
597 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
598 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
599 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
600 // node signatures |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
601 builder.startGroup(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
602 builder.startNewArray(new ArrayCodeTypeMirror(new ArrayCodeTypeMirror(context.getType(Class.class))), null); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
603 List<ExecutableElement> constructors = findUserConstructors(generatedNode.asType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
604 for (ExecutableElement constructor : constructors) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
605 builder.startGroup(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
606 if (constructor.getParameters().isEmpty()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
607 builder.staticReference(context.getTruffleTypes().getDslMetadata(), EMPTY_CLASS_ARRAY); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
608 } else { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
609 builder.startNewArray(new ArrayCodeTypeMirror(context.getType(Class.class)), null); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
610 for (VariableElement var : constructor.getParameters()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
611 builder.typeLiteral(var.asType()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
612 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
613 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
614 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
615 builder.end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
616 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
617 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
618 builder.end(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
619 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
620 builder.end().end().end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
621 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
622 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
623 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
624 private CodeExecutableElement createCreateNodeMethod(NodeData node) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
625 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), node.getNodeType(), "createNode"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
626 CodeVariableElement arguments = new CodeVariableElement(getContext().getType(Object.class), "arguments"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
627 method.setVarArgs(true); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
628 method.addParameter(arguments); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
629 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
630 CodeTreeBuilder builder = method.createBuilder(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
631 List<ExecutableElement> signatures = findUserConstructors(generatedNode.asType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
632 boolean ifStarted = false; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
633 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
634 for (ExecutableElement element : signatures) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
635 ifStarted = builder.startIf(ifStarted); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
636 builder.string("arguments.length == " + element.getParameters().size()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
637 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
638 int index = 0; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
639 for (VariableElement param : element.getParameters()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
640 if (ElementUtils.isObject(param.asType())) { |
11509
dcaf879d4a7e
Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11506
diff
changeset
|
641 continue; |
dcaf879d4a7e
Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11506
diff
changeset
|
642 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
643 builder.string(" && "); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
644 if (!param.asType().getKind().isPrimitive()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
645 builder.string("(arguments[" + index + "] == null || "); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
646 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
647 builder.string("arguments[" + index + "] instanceof "); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
648 builder.type(ElementUtils.boxType(getContext(), param.asType())); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
649 if (!param.asType().getKind().isPrimitive()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
650 builder.string(")"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
651 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
652 index++; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
653 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
654 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
655 builder.startBlock(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
656 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
657 builder.startReturn().startCall("create"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
658 index = 0; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
659 for (VariableElement param : element.getParameters()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
660 builder.startGroup(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
661 if (!ElementUtils.isObject(param.asType())) { |
11509
dcaf879d4a7e
Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11506
diff
changeset
|
662 builder.string("(").type(param.asType()).string(") "); |
dcaf879d4a7e
Truffle-DSL: fixed a compiler warning for fields of type java.lang.Object. (GRAAL-434 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11506
diff
changeset
|
663 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
664 builder.string("arguments[").string(String.valueOf(index)).string("]"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
665 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
666 index++; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
667 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
668 builder.end().end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
669 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
670 builder.end(); // block |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
671 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
672 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
673 builder.startElseBlock(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
674 builder.startThrow().startNew(getContext().getType(IllegalArgumentException.class)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
675 builder.doubleQuote("Invalid create signature."); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
676 builder.end().end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
677 builder.end(); // else block |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
678 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
679 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
680 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
681 private ExecutableElement createGetInstanceMethod(NodeData node, Modifier visibility) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
682 TypeElement nodeFactoryType = ElementUtils.fromTypeMirror(getContext().getType(NodeFactory.class)); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
683 TypeMirror returnType = ElementUtils.getDeclaredType(nodeFactoryType, node.getNodeType()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
684 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
685 CodeExecutableElement method = new CodeExecutableElement(modifiers(), returnType, "getInstance"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
686 if (visibility != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
687 method.getModifiers().add(visibility); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
688 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
689 method.getModifiers().add(Modifier.STATIC); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
690 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
691 String varName = instanceVarName(node); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
692 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
693 CodeTreeBuilder builder = method.createBuilder(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
694 builder.startIf(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
695 builder.string(varName).string(" == null"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
696 builder.end().startBlock(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
697 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
698 builder.startStatement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
699 builder.string(varName); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
700 builder.string(" = "); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
701 builder.startNew(factoryClassName(node)).end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
702 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
703 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
704 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
705 builder.startReturn().string(varName).end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
706 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
707 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
708 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
709 private String instanceVarName(NodeData node) { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
710 if (node.getDeclaringNode() != null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
711 return ElementUtils.firstLetterLowerCase(factoryClassName(node)) + "Instance"; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
712 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
713 return "instance"; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
714 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
715 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
716 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
717 private CodeVariableElement createInstanceConstant(NodeData node, TypeMirror factoryType) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
718 String varName = instanceVarName(node); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
719 CodeVariableElement var = new CodeVariableElement(modifiers(), factoryType, varName); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
720 var.getModifiers().add(Modifier.PRIVATE); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
721 var.getModifiers().add(Modifier.STATIC); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
722 return var; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
723 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
724 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
725 private ExecutableElement createGetFactories(NodeData node) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
726 List<NodeData> children = node.getNodeDeclaringChildren(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
727 if (node.needsFactory()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
728 children.add(node); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
729 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
730 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
731 List<TypeMirror> nodeTypesList = new ArrayList<>(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
732 TypeMirror prev = null; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
733 boolean allSame = true; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
734 for (NodeData child : children) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
735 nodeTypesList.add(child.getNodeType()); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
736 if (prev != null && !ElementUtils.typeEquals(child.getNodeType(), prev)) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
737 allSame = false; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
738 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
739 prev = child.getNodeType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
740 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
741 TypeMirror commonNodeSuperType = ElementUtils.getCommonSuperType(getContext(), nodeTypesList.toArray(new TypeMirror[nodeTypesList.size()])); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
742 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
743 Types types = getContext().getEnvironment().getTypeUtils(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
744 TypeMirror factoryType = getContext().getType(NodeFactory.class); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
745 TypeMirror baseType; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
746 if (allSame) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
747 baseType = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(factoryType), commonNodeSuperType); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
748 } else { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
749 baseType = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(factoryType), types.getWildcardType(commonNodeSuperType, null)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
750 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
751 TypeMirror listType = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(getContext().getType(List.class)), baseType); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
752 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
753 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), listType, "getFactories"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
754 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
755 CodeTreeBuilder builder = method.createBuilder(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
756 builder.startReturn(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
757 builder.startStaticCall(getContext().getType(Arrays.class), "asList"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
758 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
759 for (NodeData child : children) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
760 builder.startGroup(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
761 NodeData childNode = child; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
762 List<NodeData> factories = new ArrayList<>(); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
763 while (childNode.getDeclaringNode() != null) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
764 factories.add(childNode); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
765 childNode = childNode.getDeclaringNode(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
766 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
767 Collections.reverse(factories); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
768 for (NodeData nodeData : factories) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
769 builder.string(factoryClassName(nodeData)).string("."); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
770 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
771 builder.string("getInstance()"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
772 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
773 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
774 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
775 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
776 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
777 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
778 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
779 private void createFactoryMethods(NodeData node, CodeTypeElement clazz, Modifier createVisibility) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
780 List<ExecutableElement> constructors = findUserConstructors(generatedNode.asType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
781 for (ExecutableElement constructor : constructors) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
782 clazz.add(createCreateMethod(node, createVisibility, constructor)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
783 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
784 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
785 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
786 private CodeExecutableElement createCreateMethod(NodeData node, Modifier visibility, ExecutableElement constructor) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
787 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), constructor); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
788 method.setSimpleName(CodeNames.of("create")); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
789 method.getModifiers().clear(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
790 if (visibility != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
791 method.getModifiers().add(visibility); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
792 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
793 method.getModifiers().add(Modifier.STATIC); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
794 method.setReturnType(node.getNodeType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
795 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
796 CodeTreeBuilder body = method.createBuilder(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
797 body.startReturn(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
798 if (node.getSpecializations().isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
799 body.nullLiteral(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
800 } else { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
801 body.startCall(nodeSpecializationClassName(node.getSpecializations().get(0)), FACTORY_METHOD_NAME); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
802 for (VariableElement var : method.getParameters()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
803 body.string(var.getSimpleName().toString()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
804 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
805 body.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
806 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
807 body.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
808 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
809 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
810 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
811 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
812 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
813 private class NodeBaseFactory extends AbstractClassElementFactory<SpecializationData> { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
814 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
815 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
816 protected CodeTypeElement create(SpecializationData specialization) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
817 NodeData node = specialization.getNode(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
818 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, ABSTRACT, STATIC), baseClassName(node), node.getNodeType(), false); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
819 clazz.getImplements().add(context.getTruffleTypes().getDslNode()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
820 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
821 for (NodeChildData child : node.getChildren()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
822 clazz.add(createChildField(child)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
823 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
824 if (child.getAccessElement() != null && child.getAccessElement().getModifiers().contains(Modifier.ABSTRACT)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
825 ExecutableElement getter = (ExecutableElement) child.getAccessElement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
826 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), getter); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
827 method.getModifiers().remove(Modifier.ABSTRACT); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
828 CodeTreeBuilder builder = method.createBuilder(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
829 builder.startReturn().string("this.").string(child.getName()).end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
830 clazz.add(method); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
831 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
832 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
833 |
11187
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
834 for (NodeFieldData field : node.getFields()) { |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
835 if (!field.isGenerated()) { |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
836 continue; |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
837 } |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
838 |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
839 clazz.add(new CodeVariableElement(modifiers(PROTECTED, FINAL), field.getType(), field.getName())); |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
840 if (field.getGetter() != null && field.getGetter().getModifiers().contains(Modifier.ABSTRACT)) { |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
841 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), field.getGetter()); |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
842 method.getModifiers().remove(Modifier.ABSTRACT); |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
843 method.createBuilder().startReturn().string("this.").string(field.getName()).end(); |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
844 clazz.add(method); |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
845 } |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
846 } |
7a8835ec5e7d
Truffle-DSL: Added new @NodeField and @NodeFields annotation. Which can be used to avoid the cumbersome definition of copy constructors.
Christian Humer <christian.humer@gmail.com>
parents:
11186
diff
changeset
|
847 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
848 for (String assumption : node.getAssumptions()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
849 clazz.add(createAssumptionField(assumption)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
850 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
851 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
852 createConstructors(node, clazz); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
853 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
854 return clazz; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
855 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
856 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
857 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
858 protected void createChildren(SpecializationData specialization) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
859 NodeData node = specialization.getNode(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
860 CodeTypeElement clazz = getElement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
861 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
862 SpecializationGroup rootGroup = createSpecializationGroups(node); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
863 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
864 if (node.needsRewrites(context)) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
865 if (node.isPolymorphic(context)) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
866 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
867 CodeVariableElement var = new CodeVariableElement(modifiers(PROTECTED), clazz.asType(), "next0"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
868 var.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getChildAnnotation())); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
869 clazz.add(var); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
870 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
871 CodeExecutableElement genericCachedExecute = createCachedExecute(node, node.getPolymorphicSpecialization()); |
10600
e93efe3ba5f4
Truffle-DSL: rewritten polymorphic optimization for simpler generated code.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
872 clazz.add(genericCachedExecute); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
873 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
874 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
875 |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
876 for (CodeExecutableElement method : createImplicitChildrenAccessors()) { |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
877 clazz.add(method); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
878 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
879 clazz.add(createInfoMessage(node)); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
880 clazz.add(createMonomorphicRewrite()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
881 clazz.add(createCreateSpecializationMethod(node, rootGroup)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
882 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
883 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
884 clazz.add(createAdoptChildren0()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
885 clazz.add(createGetMetadata0(true)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
886 clazz.add(createUpdateTypes0()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
887 clazz.add(createGetNext()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
888 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
889 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
890 private Element createGetNext() { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
891 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), context.getType(Node.class), "getNext0"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
892 CodeTreeBuilder builder = method.createBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
893 NodeData node = getModel().getNode(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
894 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
895 if (node.isPolymorphic(context)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
896 builder.startReturn().string("next0").end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
897 } else { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
898 builder.returnNull(); |
12567
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
899 } |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
900 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
901 return method; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
902 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
903 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
904 protected final CodeExecutableElement createUpdateTypes0() { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
905 ArrayType classArray = new ArrayCodeTypeMirror(context.getType(Class.class)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
906 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getType(void.class), "updateTypes0"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
907 method.getParameters().add(new CodeVariableElement(classArray, "types")); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
908 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
909 if (getModel().isPolymorphic()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
910 CodeTreeBuilder builder = method.createBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
911 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
912 int index = 0; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
913 for (NodeExecutionData execution : getModel().getNode().getChildExecutions()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
914 String fieldName = polymorphicTypeName(execution); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
915 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
916 builder.startStatement(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
917 builder.string(fieldName).string(" = ").string("types[").string(String.valueOf(index)).string("]"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
918 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
919 index++; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
920 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
921 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
922 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
923 return method; |
12567
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
924 } |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
925 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
926 protected final CodeExecutableElement createGetMetadata0(boolean empty) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
927 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getTruffleTypes().getDslMetadata(), "getMetadata0"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
928 if (empty) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
929 method.createBuilder().startReturn().staticReference(context.getTruffleTypes().getDslMetadata(), "NONE").end(); |
12567
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
930 } else { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
931 method.createBuilder().startReturn().string(METADATA_FIELD_NAME).end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
932 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
933 return method; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
934 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
935 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
936 private CodeExecutableElement createAdoptChildren0() { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
937 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, FINAL), context.getType(void.class), "adoptChildren0"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
938 method.getParameters().add(new CodeVariableElement(context.getTruffleTypes().getNode(), "other")); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
939 method.getParameters().add(new CodeVariableElement(context.getTruffleTypes().getNode(), "newNext")); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
940 NodeData node = getModel().getNode(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
941 CodeTreeBuilder builder = method.createBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
942 List<NodeExecutionData> executions = node.getChildExecutions(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
943 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
944 if (executions.size() > 0) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
945 builder.startIf().string("other == null").end().startBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
946 for (NodeExecutionData execution : executions) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
947 builder.startStatement().tree(createAccessChild(execution, "this")).string(" = null").end(); |
12567
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
948 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
949 builder.end().startElseBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
950 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
951 String access; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
952 if (executions.size() > 1) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
953 builder.declaration(baseClassName(node), "otherCast", builder.create().cast(baseClassName(node)).string("other")); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
954 access = "otherCast"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
955 } else { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
956 assert executions.size() == 1; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
957 access = "((" + baseClassName(node) + ") other)"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
958 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
959 for (NodeExecutionData execution : executions) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
960 builder.startStatement().tree(createAccessChild(execution, "this")).string(" = ").tree(createAccessChild(execution, access)).end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
961 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
962 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
963 builder.end(); |
12567
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
964 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
965 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
966 if (getModel().getNode().isPolymorphic(context)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
967 builder.startIf().string("newNext == null").end().startBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
968 builder.statement("this.next0 = null"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
969 builder.end().startElseBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
970 builder.statement("this.next0 = (" + baseClassName(getModel().getNode()) + ") newNext"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
971 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
972 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
973 |
12567
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
974 return method; |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
975 } |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
976 |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
977 private List<CodeExecutableElement> createImplicitChildrenAccessors() { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
978 NodeData node = getModel().getNode(); |
15459
0dae565d9289
fixed code that ecj had a problem compiling
Doug Simon <doug.simon@oracle.com>
parents:
14642
diff
changeset
|
979 List<Set<TypeData>> prototype = Collections.nCopies(node.getGenericSpecialization().getParameters().size(), null); |
0dae565d9289
fixed code that ecj had a problem compiling
Doug Simon <doug.simon@oracle.com>
parents:
14642
diff
changeset
|
980 List<Set<TypeData>> expectTypes = new ArrayList<>(prototype); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
981 |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
982 for (ExecutableTypeData executableType : node.getExecutableTypes()) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
983 for (int i = 0; i < executableType.getEvaluatedCount(); i++) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
984 Parameter parameter = executableType.getSignatureParameter(i); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
985 if (i >= expectTypes.size()) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
986 break; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
987 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
988 Set<TypeData> types = expectTypes.get(i); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
989 if (types == null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
990 types = new TreeSet<>(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
991 expectTypes.set(i, types); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
992 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
993 types.add(parameter.getTypeSystemType()); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
994 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
995 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
996 |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
997 List<CodeExecutableElement> methods = new ArrayList<>(); |
15459
0dae565d9289
fixed code that ecj had a problem compiling
Doug Simon <doug.simon@oracle.com>
parents:
14642
diff
changeset
|
998 List<Set<TypeData>> visitedList = new ArrayList<>(prototype); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
999 for (SpecializationData spec : node.getSpecializations()) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1000 int signatureIndex = -1; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1001 for (Parameter param : spec.getParameters()) { |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1002 if (!param.getSpecification().isSignature()) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1003 continue; |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1004 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1005 signatureIndex++; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1006 Set<TypeData> visitedTypeData = visitedList.get(signatureIndex); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1007 if (visitedTypeData == null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1008 visitedTypeData = new TreeSet<>(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1009 visitedList.set(signatureIndex, visitedTypeData); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1010 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1011 |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1012 if (visitedTypeData.contains(param.getTypeSystemType())) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1013 continue; |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1014 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1015 visitedTypeData.add(param.getTypeSystemType()); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1016 |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1017 Set<TypeData> expect = expectTypes.get(signatureIndex); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1018 if (expect == null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1019 expect = Collections.emptySet(); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1020 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1021 |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1022 methods.addAll(createExecuteChilds(param, expect)); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1023 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1024 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1025 return methods; |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1026 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1027 |
10690
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1028 private CodeTree truffleBooleanOption(CodeTreeBuilder parent, String name) { |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1029 CodeTreeBuilder builder = parent.create(); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1030 builder.staticReference(getContext().getTruffleTypes().getTruffleOptions(), name); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1031 return builder.getRoot(); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1032 } |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1033 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1034 private Element createInfoMessage(NodeData node) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1035 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, STATIC), getContext().getType(String.class), CREATE_INFO); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1036 method.addParameter(new CodeVariableElement(getContext().getType(String.class), "message")); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1037 addInternalValueParameters(method, node.getGenericSpecialization(), false, false, false); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1038 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1039 CodeTreeBuilder builder = method.createBuilder(); |
10690
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1040 |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1041 builder.startIf().tree(truffleBooleanOption(builder, TruffleTypes.OPTION_DETAILED_REWRITE_REASONS)).end(); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1042 builder.startBlock(); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1043 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1044 builder.startStatement().string("StringBuilder builder = new StringBuilder(message)").end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1045 builder.startStatement().startCall("builder", "append").doubleQuote(" (").end().end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1046 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1047 String sep = null; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1048 for (Parameter parameter : node.getGenericSpecialization().getSignatureParameters()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1049 builder.startStatement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1050 builder.string("builder"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1051 if (sep != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1052 builder.startCall(".append").doubleQuote(sep).end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1053 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1054 builder.startCall(".append").doubleQuote(parameter.getLocalName()).end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1055 builder.startCall(".append").doubleQuote(" = ").end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1056 builder.startCall(".append").string(parameter.getLocalName()).end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1057 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1058 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1059 if (!ElementUtils.isPrimitive(parameter.getType())) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1060 builder.startIf().string(parameter.getLocalName() + " != null").end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1061 builder.startBlock(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1062 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1063 builder.startStatement(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1064 if (ElementUtils.isPrimitive(parameter.getType())) { |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1065 builder.startCall("builder.append").doubleQuote(" (" + ElementUtils.getSimpleName(parameter.getType()) + ")").end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1066 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1067 builder.startCall("builder.append").doubleQuote(" (").end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1068 builder.startCall(".append").string(parameter.getLocalName() + ".getClass().getSimpleName()").end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1069 builder.startCall(".append").doubleQuote(")").end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1070 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1071 builder.end(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1072 if (!ElementUtils.isPrimitive(parameter.getType())) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1073 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1074 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1075 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1076 sep = ", "; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1077 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1078 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1079 builder.startStatement().startCall("builder", "append").doubleQuote(")").end().end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1080 builder.startReturn().string("builder.toString()").end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1081 |
10690
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1082 builder.end(); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1083 builder.startElseBlock(); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1084 builder.startReturn().string("message").end(); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1085 builder.end(); |
a0309f88306c
Added truffle option to enable detailed rewrite messages. Disabled by default.
Christian Humer <christian.humer@gmail.com>
parents:
10689
diff
changeset
|
1086 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1087 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1088 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1089 |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1090 private CodeExecutableElement createCachedExecute(NodeData node, SpecializationData polymorph) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1091 CodeExecutableElement cachedExecute = new CodeExecutableElement(modifiers(PROTECTED, ABSTRACT), polymorph.getReturnType().getType(), EXECUTE_CHAINED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1092 addInternalValueParameters(cachedExecute, polymorph, true, false, false); |
10741
00a9dbcbe431
Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10695
diff
changeset
|
1093 |
00a9dbcbe431
Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10695
diff
changeset
|
1094 ExecutableTypeData sourceExecutableType = node.findExecutableType(polymorph.getReturnType().getTypeSystemType(), 0); |
00a9dbcbe431
Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10695
diff
changeset
|
1095 boolean sourceThrowsUnexpected = sourceExecutableType != null && sourceExecutableType.hasUnexpectedValue(getContext()); |
13535
e8ef44830b50
Truffle-DSL: fixed bugs due to previous cleanup. addtional cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13533
diff
changeset
|
1096 if (sourceThrowsUnexpected && sourceExecutableType.getType().equals(node.getGenericSpecialization().getReturnType().getTypeSystemType())) { |
11186
4a9936bb03a4
Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11185
diff
changeset
|
1097 sourceThrowsUnexpected = false; |
4a9936bb03a4
Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11185
diff
changeset
|
1098 } |
10741
00a9dbcbe431
Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10695
diff
changeset
|
1099 if (sourceThrowsUnexpected) { |
00a9dbcbe431
Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10695
diff
changeset
|
1100 cachedExecute.getThrownTypes().add(getContext().getType(UnexpectedResultException.class)); |
00a9dbcbe431
Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10695
diff
changeset
|
1101 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1102 return cachedExecute; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1103 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1104 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1105 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1106 private void createConstructors(NodeData node, CodeTypeElement clazz) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1107 List<ExecutableElement> constructors = findUserConstructors(node.getNodeType()); |
11742
85b846b31690
Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents:
11603
diff
changeset
|
1108 ExecutableElement sourceSectionConstructor = null; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1109 if (constructors.isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1110 clazz.add(createUserConstructor(clazz, null)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1111 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1112 for (ExecutableElement constructor : constructors) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1113 clazz.add(createUserConstructor(clazz, constructor)); |
11742
85b846b31690
Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents:
11603
diff
changeset
|
1114 if (NodeParser.isSourceSectionConstructor(context, constructor)) { |
85b846b31690
Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents:
11603
diff
changeset
|
1115 sourceSectionConstructor = constructor; |
85b846b31690
Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents:
11603
diff
changeset
|
1116 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1117 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1118 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1119 if (node.needsRewrites(getContext())) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1120 ExecutableElement copyConstructor = findCopyConstructor(node.getNodeType()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1121 clazz.add(createCopyConstructor(clazz, copyConstructor, sourceSectionConstructor)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1122 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1123 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1124 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1125 private CodeExecutableElement createUserConstructor(CodeTypeElement type, ExecutableElement superConstructor) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1126 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1127 CodeTreeBuilder builder = method.createBuilder(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1128 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1129 NodeData node = getModel().getNode(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1130 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1131 if (superConstructor != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1132 for (VariableElement param : superConstructor.getParameters()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1133 method.getParameters().add(CodeVariableElement.clone(param)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1134 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1135 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1136 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1137 if (superConstructor != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1138 builder.startStatement().startSuperCall(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1139 for (VariableElement param : superConstructor.getParameters()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1140 builder.string(param.getSimpleName().toString()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1141 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1142 builder.end().end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1143 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1144 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1145 for (VariableElement var : type.getFields()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1146 if (var.getModifiers().contains(STATIC)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1147 continue; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1148 } |
13533
b466199f19e1
Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents:
13532
diff
changeset
|
1149 NodeChildData child = node.findChild(var.getSimpleName().toString()); |
b466199f19e1
Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents:
13532
diff
changeset
|
1150 |
b466199f19e1
Truffle-DSL: fixed bug when using @CreateCast with children arrays.
Christian Humer <christian.humer@gmail.com>
parents:
13532
diff
changeset
|
1151 if (child != null) { |
13536
419b3ea1bdd1
Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
1152 method.getParameters().add(new CodeVariableElement(child.getOriginalType(), child.getName())); |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1153 } else { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1154 method.getParameters().add(new CodeVariableElement(var.asType(), var.getSimpleName().toString())); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1155 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1156 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1157 builder.startStatement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1158 String fieldName = var.getSimpleName().toString(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1159 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1160 CodeTree init = createStaticCast(builder, child, fieldName); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1161 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1162 builder.string("this.").string(fieldName).string(" = ").tree(init); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1163 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1164 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1165 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1166 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1167 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1168 private CodeTree createStaticCast(CodeTreeBuilder parent, NodeChildData child, String fieldName) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1169 NodeData parentNode = getModel().getNode(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1170 if (child != null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1171 CreateCastData createCast = parentNode.findCast(child.getName()); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1172 if (createCast != null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1173 return createTemplateMethodCall(parent, null, parentNode.getGenericSpecialization(), createCast, null, fieldName); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1174 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1175 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1176 return CodeTreeBuilder.singleString(fieldName); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1177 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1178 |
11742
85b846b31690
Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents:
11603
diff
changeset
|
1179 private CodeExecutableElement createCopyConstructor(CodeTypeElement type, ExecutableElement superConstructor, ExecutableElement sourceSectionConstructor) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1180 CodeExecutableElement method = new CodeExecutableElement(null, type.getSimpleName().toString()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1181 CodeTreeBuilder builder = method.createBuilder(); |
11180
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
1182 method.getParameters().add(new CodeVariableElement(type.asType(), "copy")); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1183 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1184 if (superConstructor != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1185 builder.startStatement().startSuperCall().string("copy").end().end(); |
11742
85b846b31690
Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents:
11603
diff
changeset
|
1186 } else if (sourceSectionConstructor != null) { |
85b846b31690
Truffle-DSL: automatically generate copy constructor if super constructor expects only SourceSection parameter.
Andreas Woess <andreas.woess@jku.at>
parents:
11603
diff
changeset
|
1187 builder.startStatement().startSuperCall().string("copy.getSourceSection()").end().end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1188 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1189 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1190 for (VariableElement var : type.getFields()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1191 if (var.getModifiers().contains(STATIC) || !var.getModifiers().contains(FINAL)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1192 continue; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1193 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1194 final String varName = var.getSimpleName().toString(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1195 final TypeMirror varType = var.asType(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1196 if (ElementUtils.isAssignable(varType, getContext().getTruffleTypes().getNodeArray())) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1197 CodeTree size = builder.create().string("copy.", varName, ".length").getRoot(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1198 builder.startStatement().string("this.").string(varName).string(" = ").startNewArray((ArrayType) varType, size).end().end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1199 } else { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1200 builder.startStatement().string("this.", varName, " = copy.", varName).end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1201 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1202 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1203 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1204 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1205 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1206 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1207 private CodeVariableElement createAssumptionField(String assumption) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1208 CodeVariableElement var = new CodeVariableElement(getContext().getTruffleTypes().getAssumption(), assumption); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1209 var.getModifiers().add(Modifier.FINAL); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1210 return var; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1211 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1212 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1213 private CodeVariableElement createChildField(NodeChildData child) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1214 TypeMirror type = child.getNodeType(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1215 CodeVariableElement var = new CodeVariableElement(type, child.getName()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1216 var.getModifiers().add(Modifier.PROTECTED); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1217 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1218 DeclaredType annotationType; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1219 if (child.getCardinality() == Cardinality.MANY) { |
10602
b8fe1fe004ec
Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10600
diff
changeset
|
1220 var.getModifiers().add(Modifier.FINAL); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1221 annotationType = getContext().getTruffleTypes().getChildrenAnnotation(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1222 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1223 annotationType = getContext().getTruffleTypes().getChildAnnotation(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1224 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1225 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1226 var.getAnnotationMirrors().add(new CodeAnnotationMirror(annotationType)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1227 return var; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1228 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1229 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1230 private SpecializationGroup createSpecializationGroups(final NodeData node) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1231 List<SpecializationData> specializations = node.getSpecializations(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1232 List<SpecializationData> filteredSpecializations = new ArrayList<>(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1233 for (SpecializationData current : specializations) { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1234 if (current.isUninitialized() || current.isPolymorphic() || !current.isReachable()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1235 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1236 } |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1237 filteredSpecializations.add(current); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1238 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1239 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1240 return SpecializationGroup.create(filteredSpecializations); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1241 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1242 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1243 protected final CodeExecutableElement createExecuteUninitialized() { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1244 NodeData node = getModel().getNode(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1245 SpecializationData generic = node.getGenericSpecialization(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1246 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED), generic.getReturnType().getType(), EXECUTE_UNINITIALIZED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1247 addInternalValueParameters(method, generic, true, false, false); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1248 CodeTreeBuilder builder = method.createBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1249 |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1250 boolean needsFrame = node.isFrameUsedByAnyGuard(getContext()); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1251 CodeTreeBuilder createSpecializationCall = builder.create(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1252 createSpecializationCall.startCall(SPECIALIZE); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1253 addInternalValueParameterNames(createSpecializationCall, generic, generic, null, needsFrame, !needsFrame, null); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1254 createSpecializationCall.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1255 builder.declaration(baseClassName(node), "newNode", createSpecializationCall); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1256 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1257 if (generic.isReachable()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1258 builder.startIf().string("newNode == null").end().startBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1259 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1260 builder.startIf().startStaticCall(context.getTruffleTypes().getCompilerDirectives(), "inInterpreter").end().end().startBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1261 builder.statement("containsFallback = true"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1262 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1263 builder.tree(createGenericInvoke(builder, generic, generic)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1264 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1265 builder.startElseBlock(); |
16781
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
1266 builder.tree(createDeoptimize(builder)); |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
1267 builder.end(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1268 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1269 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1270 builder.startReturn(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1271 builder.startStaticCall(context.getTruffleTypes().getDslShare(), "rewriteUninitialized").string("this").string("newNode").end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1272 builder.string(".").startCall(EXECUTE_CHAINED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1273 addInternalValueParameterNames(builder, generic, generic, null, true, false, null); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1274 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1275 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1276 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1277 if (generic.isReachable()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1278 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1279 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1280 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1281 return method; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1282 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1283 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1284 private CodeTree createInfoCall(CodeTreeBuilder parent, SpecializationData specialization, String reason) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1285 CodeTreeBuilder builder = parent.create(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1286 builder.startCall(CREATE_INFO).string(reason); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1287 addInternalValueParameterNames(builder, specialization, specialization, null, false, false, null); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1288 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1289 return builder.getRoot(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1290 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1291 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1292 private CodeExecutableElement createMonomorphicRewrite() { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1293 NodeData node = getModel().getNode(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1294 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1295 SpecializationData generic = node.getGenericSpecialization(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1296 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), generic.getReturnType().getType(), REWRITE); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1297 addInternalValueParameters(method, generic, true, false, false); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1298 method.addParameter(new CodeVariableElement(getContext().getType(String.class), "reason")); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1299 |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1300 boolean needsFrame = node.isFrameUsedByAnyGuard(getContext()); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1301 CodeTreeBuilder builder = method.createBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1302 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1303 builder.startStatement().startStaticCall(context.getTruffleTypes().getCompilerAsserts(), "neverPartOfCompilation").end().end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1304 String baseClassName = baseClassName(getModel().getNode()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1305 CodeTreeBuilder createSpecializationCall = builder.create(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1306 createSpecializationCall.startCall(SPECIALIZE); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1307 addInternalValueParameterNames(createSpecializationCall, generic, generic, null, needsFrame, !needsFrame, null); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1308 createSpecializationCall.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1309 builder.declaration(baseClassName, "newNode", createSpecializationCall); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1310 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1311 builder.startIf().string("newNode == null").end().startBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1312 builder.startStatement(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1313 String uninitializedName = nodeSpecializationClassName(node.getUninitializedSpecialization()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1314 builder.string("newNode = ").startNew(uninitializedName).string("this").end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1315 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1316 if (node.isFallbackReachable()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1317 builder.startStatement().string("((", uninitializedName, ") newNode).containsFallback = true").end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1318 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1319 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1320 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1321 builder.startStatement(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1322 builder.type(getContext().getType(String.class)).string(" message = ").tree(createInfoCall(builder, generic, "reason")); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1323 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1324 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1325 builder.declaration(baseClassName, "returnNode", |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1326 builder.create().startStaticCall(context.getTruffleTypes().getDslShare(), DSLSHARE_REWRITE).string("this").string("newNode").string("message").end().getRoot()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1327 builder.startIf().string("returnNode == null").end().startBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1328 builder.tree(createRewritePolymorphic(builder, node, "this")); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1329 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1330 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1331 builder.startReturn(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1332 builder.startCall("returnNode", EXECUTE_CHAINED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1333 addInternalValueParameterNames(builder, node.getGenericSpecialization(), node.getGenericSpecialization(), null, true, false, null); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1334 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1335 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1336 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1337 return method; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1338 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1339 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1340 private CodeTree createRewritePolymorphic(CodeTreeBuilder parent, NodeData node, String currentNode) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1341 String polyClassName = nodePolymorphicClassName(node); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1342 CodeTreeBuilder builder = parent.create(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1343 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1344 builder.startStatement().string("returnNode = "); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1345 builder.startStaticCall(context.getTruffleTypes().getDslShare(), DSLSHARE_REWRITE_TO_POLYMORHPIC); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1346 builder.string("this"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1347 builder.tree(builder.create().startNew(nodeSpecializationClassName(node.getUninitializedSpecialization())).string(currentNode).end().getRoot()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1348 builder.tree(builder.create().startNew(polyClassName).string(currentNode).end().getRoot()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1349 builder.startGroup().cast(baseClassName(node)).startCall("copy").end().end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1350 builder.string("newNode"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1351 builder.string("message"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1352 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1353 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1354 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1355 return builder.getRoot(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1356 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1357 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1358 private CodeExecutableElement createCreateSpecializationMethod(NodeData node, SpecializationGroup group) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1359 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), new GeneratedTypeMirror(ElementUtils.getPackageName(node.getTemplateType()), baseClassName(node)), |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1360 SPECIALIZE); |
17251
6ee7afea175a
Truffle-DSL: Fixed @SlowPath was not applied to certain specialize0 implementations. This will reduce the pressure on the truffle cache.
Christian Humer <christian.humer@gmail.com>
parents:
16909
diff
changeset
|
1361 |
6ee7afea175a
Truffle-DSL: Fixed @SlowPath was not applied to certain specialize0 implementations. This will reduce the pressure on the truffle cache.
Christian Humer <christian.humer@gmail.com>
parents:
16909
diff
changeset
|
1362 final boolean needsFrame = node.isFrameUsedByAnyGuard(getContext()); |
6ee7afea175a
Truffle-DSL: Fixed @SlowPath was not applied to certain specialize0 implementations. This will reduce the pressure on the truffle cache.
Christian Humer <christian.humer@gmail.com>
parents:
16909
diff
changeset
|
1363 |
6ee7afea175a
Truffle-DSL: Fixed @SlowPath was not applied to certain specialize0 implementations. This will reduce the pressure on the truffle cache.
Christian Humer <christian.humer@gmail.com>
parents:
16909
diff
changeset
|
1364 if (!needsFrame) { |
18130
b4e38f4ca414
Truffle: rename @SlowPath to @TruffleBoundary.
Christian Humer <christian.humer@gmail.com>
parents:
17260
diff
changeset
|
1365 method.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getTruffleBoundary())); |
12399
980db6c0bcd3
Truffle-DSL: fixed invalid @SlowPath on generic execute methods. (GRAAL-490 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12398
diff
changeset
|
1366 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1367 |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
1368 addInternalValueParameters(method, node.getGenericSpecialization(), needsFrame, !needsFrame, false); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1369 final CodeTreeBuilder builder = method.createBuilder(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1370 builder.tree(createExecuteTree(builder, node.getGenericSpecialization(), group, new CodeBlock<SpecializationData>() { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1371 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1372 public CodeTree create(CodeTreeBuilder b, SpecializationData current) { |
17251
6ee7afea175a
Truffle-DSL: Fixed @SlowPath was not applied to certain specialize0 implementations. This will reduce the pressure on the truffle cache.
Christian Humer <christian.humer@gmail.com>
parents:
16909
diff
changeset
|
1373 return createCreateSpecializationMethodBody0(builder, current, needsFrame); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1374 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1375 }, null, false, true, false, true)); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1376 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1377 emitUnreachableSpecializations(builder, node); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1378 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1379 return method; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1380 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1381 |
17251
6ee7afea175a
Truffle-DSL: Fixed @SlowPath was not applied to certain specialize0 implementations. This will reduce the pressure on the truffle cache.
Christian Humer <christian.humer@gmail.com>
parents:
16909
diff
changeset
|
1382 protected CodeTree createCreateSpecializationMethodBody0(CodeTreeBuilder parent, SpecializationData current, boolean useDeoptimize) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1383 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1384 if (current.isGeneric()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1385 builder.startReturn().nullLiteral().end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1386 } else { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1387 String className = nodeSpecializationClassName(current); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1388 if (!current.getExcludedBy().isEmpty()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1389 builder.startIf().string("!").startStaticCall(context.getTruffleTypes().getDslShare(), "isExcluded"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1390 builder.string("this").string(nodeSpecializationClassName(current), ".", METADATA_FIELD_NAME).end().end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1391 builder.startBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1392 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1393 |
17251
6ee7afea175a
Truffle-DSL: Fixed @SlowPath was not applied to certain specialize0 implementations. This will reduce the pressure on the truffle cache.
Christian Humer <christian.humer@gmail.com>
parents:
16909
diff
changeset
|
1394 if (current.getNode().getGenericSpecialization().isReachable() && useDeoptimize) { |
16781
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
1395 builder.tree(createDeoptimize(builder)); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1396 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1397 builder.startReturn(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1398 builder.cast(baseClassName(getModel().getNode())); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1399 builder.startGroup().startCall(className, FACTORY_METHOD_NAME).string("this"); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1400 for (Parameter param : current.getSignatureParameters()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1401 NodeChildData child = param.getSpecification().getExecution().getChild(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1402 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1403 if (types.size() > 1) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1404 builder.string(implicitTypeName(param)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1405 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1406 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1407 builder.end().end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1408 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1409 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1410 if (!current.getExcludedBy().isEmpty()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1411 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1412 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1413 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1414 return builder.getRoot(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1415 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1416 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1417 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1418 private void emitUnreachableSpecializations(final CodeTreeBuilder builder, NodeData node) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1419 for (SpecializationData current : node.getSpecializations()) { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
1420 if (current.isReachable()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1421 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1422 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1423 builder.string("// unreachable ").string(current.getId()).newLine(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1424 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1425 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1426 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1427 protected CodeTree createExecuteTree(CodeTreeBuilder outerParent, final SpecializationData source, final SpecializationGroup group, final CodeBlock<SpecializationData> guardedblock, |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1428 final CodeTree elseBlock, boolean forceElse, final boolean emitAssumptions, final boolean typedCasts, final boolean castForGuardsOnly) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1429 return guard(outerParent, source, group, new CodeBlock<Integer>() { |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1430 |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1431 public CodeTree create(CodeTreeBuilder parent, Integer ifCount) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1432 CodeTreeBuilder builder = parent.create(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1433 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1434 if (group.getSpecialization() != null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1435 builder.tree(guardedblock.create(builder, group.getSpecialization())); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1436 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1437 assert group.getChildren().isEmpty() : "missed a specialization"; |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1438 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1439 } else { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1440 for (SpecializationGroup childGroup : group.getChildren()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1441 builder.tree(createExecuteTree(builder, source, childGroup, guardedblock, null, false, emitAssumptions, typedCasts, castForGuardsOnly)); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1442 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1443 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1444 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1445 return builder.getRoot(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1446 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1447 }, elseBlock, forceElse, emitAssumptions, typedCasts, castForGuardsOnly); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1448 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1449 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1450 private CodeTree guard(CodeTreeBuilder parent, SpecializationData source, SpecializationGroup group, CodeBlock<Integer> bodyBlock, CodeTree elseBlock, boolean forceElse, |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1451 boolean emitAssumptions, boolean typedCasts, boolean castForGuardsOnly) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1452 CodeTreeBuilder builder = parent.create(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1453 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1454 int ifCount = emitGuards(builder, source, group, emitAssumptions, typedCasts, castForGuardsOnly); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1455 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1456 if (isReachableGroup(group, ifCount)) { |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1457 builder.tree(bodyBlock.create(builder, ifCount)); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1458 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1459 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1460 builder.end(ifCount); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1461 |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1462 if (elseBlock != null) { |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1463 if (ifCount > 0 || forceElse) { |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1464 builder.tree(elseBlock); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1465 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1466 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1467 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1468 return builder.getRoot(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1469 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1470 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1471 private boolean isReachableGroup(SpecializationGroup group, int ifCount) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1472 if (ifCount != 0) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1473 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1474 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1475 SpecializationGroup previous = group.getPreviousGroup(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1476 if (previous == null || previous.findElseConnectableGuards().isEmpty()) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1477 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1478 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1479 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1480 /* |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1481 * Hacky else case. In this case the specialization is not reachable due to previous |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1482 * else branch. This is only true if the minimum state is not checked. |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1483 */ |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1484 if (previous.getGuards().size() == 1 && previous.getTypeGuards().isEmpty() && previous.getAssumptions().isEmpty() && |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1485 (previous.getParent() == null || previous.getMaxSpecializationIndex() != previous.getParent().getMaxSpecializationIndex())) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1486 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1487 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1488 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1489 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1490 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1491 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1492 private int emitGuards(CodeTreeBuilder builder, SpecializationData source, SpecializationGroup group, boolean emitAssumptions, boolean typedCasts, boolean castForGuardsOnly) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1493 NodeData node = source.getNode(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1494 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1495 CodeTreeBuilder guardsBuilder = builder.create(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1496 CodeTreeBuilder castBuilder = builder.create(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1497 CodeTreeBuilder guardsCastBuilder = builder.create(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1498 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1499 String guardsAnd = ""; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1500 String guardsCastAnd = ""; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1501 |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1502 if (emitAssumptions) { |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1503 for (String assumption : group.getAssumptions()) { |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1504 guardsBuilder.string(guardsAnd); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1505 guardsBuilder.string("this"); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1506 guardsBuilder.string(".").string(assumption).string(".isValid()"); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1507 guardsAnd = " && "; |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1508 } |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1509 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1510 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1511 for (TypeGuard typeGuard : group.getTypeGuards()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1512 Parameter valueParam = source.getSignatureParameter(typeGuard.getSignatureIndex()); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1513 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1514 if (valueParam == null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1515 /* |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1516 * If used inside a execute evaluated method then the value param may not exist. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1517 * In that case we assume that the value is executed generic or of the current |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1518 * specialization. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1519 */ |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1520 if (group.getSpecialization() != null) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1521 valueParam = group.getSpecialization().getSignatureParameter(typeGuard.getSignatureIndex()); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1522 } else { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1523 valueParam = node.getGenericSpecialization().getSignatureParameter(typeGuard.getSignatureIndex()); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1524 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1525 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1526 |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1527 NodeExecutionData execution = valueParam.getSpecification().getExecution(); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1528 CodeTree implicitGuard = createTypeGuard(guardsBuilder, execution, valueParam, typeGuard.getType(), typedCasts); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1529 if (implicitGuard != null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1530 guardsBuilder.string(guardsAnd); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1531 guardsBuilder.tree(implicitGuard); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1532 guardsAnd = " && "; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1533 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1534 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1535 CodeTree implicitGetType = null; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1536 if (castForGuardsOnly) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1537 implicitGetType = createGetImplicitType(builder, execution, valueParam, typeGuard.getType()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1538 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1539 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1540 boolean performCast = true; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1541 if (castForGuardsOnly) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1542 // if cast for guards we just cast if the type guard is used inside a guard. |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1543 performCast = group.isTypeGuardUsedInAnyGuardBelow(context, source, typeGuard); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1544 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1545 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1546 if (performCast) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1547 CodeTree cast = createCast(castBuilder, execution, valueParam, typeGuard.getType(), typedCasts); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1548 if (cast != null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1549 castBuilder.tree(cast); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1550 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1551 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1552 if (implicitGetType != null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1553 castBuilder.tree(implicitGetType); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1554 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1555 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1556 List<GuardExpression> elseGuards = group.findElseConnectableGuards(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1557 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1558 for (GuardExpression guard : group.getGuards()) { |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
1559 if (elseGuards.contains(guard)) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1560 continue; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1561 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1562 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1563 if (needsTypeGuard(source, group, guard)) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1564 guardsCastBuilder.tree(createMethodGuard(builder, guardsCastAnd, source, guard)); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1565 guardsCastAnd = " && "; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1566 } else { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1567 guardsBuilder.tree(createMethodGuard(builder, guardsAnd, source, guard)); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1568 guardsAnd = " && "; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1569 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1570 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1571 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
1572 int ifCount = startGuardIf(builder, guardsBuilder, 0, elseGuards); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1573 builder.tree(castBuilder.getRoot()); |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
1574 ifCount = startGuardIf(builder, guardsCastBuilder, ifCount, elseGuards); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1575 return ifCount; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1576 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1577 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1578 private int startGuardIf(CodeTreeBuilder builder, CodeTreeBuilder conditionBuilder, int ifCount, List<GuardExpression> elseGuard) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1579 int newIfCount = ifCount; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1580 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1581 if (!conditionBuilder.isEmpty()) { |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
1582 if (ifCount == 0 && !elseGuard.isEmpty()) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1583 builder.startElseIf(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1584 } else { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1585 builder.startIf(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1586 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1587 builder.tree(conditionBuilder.getRoot()); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1588 builder.end().startBlock(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1589 newIfCount++; |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
1590 } else if (ifCount == 0 && !elseGuard.isEmpty()) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1591 builder.startElseBlock(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1592 newIfCount++; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1593 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1594 return newIfCount; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1595 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1596 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1597 private boolean needsTypeGuard(SpecializationData source, SpecializationGroup group, GuardExpression guard) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1598 for (Parameter parameter : guard.getResolvedGuard().getParameters()) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1599 if (!parameter.getSpecification().isSignature()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1600 continue; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1601 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1602 |
16851
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16822
diff
changeset
|
1603 int signatureIndex = source.getNode().getChildExecutions().indexOf(parameter.getSpecification().getExecution()); |
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16822
diff
changeset
|
1604 if (signatureIndex == -1) { |
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16822
diff
changeset
|
1605 continue; |
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16822
diff
changeset
|
1606 } |
2db61eddcb97
Truffle-DSL: argument syntax support for guards
Christian Humer <christian.humer@gmail.com>
parents:
16822
diff
changeset
|
1607 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1608 TypeGuard typeGuard = group.findTypeGuard(signatureIndex); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1609 if (typeGuard != null) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11197
diff
changeset
|
1610 TypeData requiredType = typeGuard.getType(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1611 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1612 Parameter sourceParameter = source.findParameter(parameter.getLocalName()); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1613 if (sourceParameter == null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1614 sourceParameter = source.getNode().getGenericSpecialization().findParameter(parameter.getLocalName()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1615 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1616 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1617 if (ElementUtils.needsCastTo(sourceParameter.getType(), requiredType.getPrimitiveType())) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1618 return true; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1619 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1620 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1621 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1622 return false; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1623 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1624 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1625 private CodeTree createTypeGuard(CodeTreeBuilder parent, NodeExecutionData execution, Parameter source, TypeData targetType, boolean typedCasts) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1626 NodeData node = execution.getChild().getNodeData(); |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1627 |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1628 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1629 |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1630 TypeData sourceType = source.getTypeSystemType(); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1631 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1632 if (!sourceType.needsCastTo(targetType)) { |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1633 return null; |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1634 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1635 |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1636 builder.startGroup(); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1637 |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1638 if (execution.isShortCircuit()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1639 Parameter shortCircuit = source.getPreviousParameter(); |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1640 assert shortCircuit != null; |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1641 builder.string("("); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1642 builder.string("!").string(valueName(shortCircuit)); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1643 builder.string(" || "); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1644 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1645 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1646 String castMethodName; |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1647 String castTypeName = null; |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1648 List<TypeData> types = getModel().getNode().getTypeSystem().lookupSourceTypes(targetType); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1649 if (types.size() > 1) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1650 castMethodName = TypeSystemCodeGenerator.isImplicitTypeMethodName(targetType); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1651 if (typedCasts) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1652 castTypeName = implicitTypeName(source); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1653 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1654 } else { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1655 castMethodName = TypeSystemCodeGenerator.isTypeMethodName(targetType); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1656 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1657 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1658 startCallTypeSystemMethod(builder, node.getTypeSystem(), castMethodName); |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1659 builder.string(valueName(source)); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1660 if (castTypeName != null) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1661 builder.string(castTypeName); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1662 } |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1663 builder.end().end(); // call |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1664 |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1665 if (execution.isShortCircuit()) { |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1666 builder.string(")"); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1667 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1668 |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1669 builder.end(); // group |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1670 |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1671 return builder.getRoot(); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1672 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1673 |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1674 // TODO merge redundancies with #createTypeGuard |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1675 private CodeTree createCast(CodeTreeBuilder parent, NodeExecutionData execution, Parameter source, TypeData targetType, boolean typedCasts) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1676 NodeData node = execution.getChild().getNodeData(); |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1677 TypeData sourceType = source.getTypeSystemType(); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1678 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1679 if (!sourceType.needsCastTo(targetType)) { |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1680 return null; |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1681 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1682 |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1683 CodeTree condition = null; |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1684 if (execution.isShortCircuit()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1685 Parameter shortCircuit = source.getPreviousParameter(); |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1686 assert shortCircuit != null; |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1687 condition = CodeTreeBuilder.singleString(valueName(shortCircuit)); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1688 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1689 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1690 String castMethodName; |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1691 String castTypeName = null; |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1692 List<TypeData> types = getModel().getNode().getTypeSystem().lookupSourceTypes(targetType); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1693 if (types.size() > 1) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1694 castMethodName = TypeSystemCodeGenerator.asImplicitTypeMethodName(targetType); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1695 if (typedCasts) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1696 castTypeName = implicitTypeName(source); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1697 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1698 } else { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1699 castMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1700 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1701 |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1702 List<CodeTree> args = new ArrayList<>(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1703 args.add(CodeTreeBuilder.singleString(valueName(source))); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1704 if (castTypeName != null) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1705 args.add(CodeTreeBuilder.singleString(castTypeName)); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1706 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1707 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1708 CodeTree cast = createCallTypeSystemMethod(parent, node, castMethodName, args.toArray(new CodeTree[0])); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1709 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1710 CodeTreeBuilder builder = parent.create(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1711 builder.tree(createLazyAssignment(parent, castValueName(source), targetType.getPrimitiveType(), condition, cast)); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1712 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1713 return builder.getRoot(); |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1714 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
1715 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1716 private CodeTree createGetImplicitType(CodeTreeBuilder parent, NodeExecutionData execution, Parameter source, TypeData targetType) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1717 CodeTree condition = null; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1718 if (execution.isShortCircuit()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1719 Parameter shortCircuit = source.getPreviousParameter(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1720 assert shortCircuit != null; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1721 condition = CodeTreeBuilder.singleString(valueName(shortCircuit)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1722 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1723 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1724 CodeTreeBuilder builder = parent.create(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1725 List<TypeData> types = getModel().getNode().getTypeSystem().lookupSourceTypes(targetType); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1726 if (types.size() > 1) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1727 CodeTree castType = createCallTypeSystemMethod(parent, execution.getChild().getNodeData(), TypeSystemCodeGenerator.getImplicitClass(targetType), |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1728 CodeTreeBuilder.singleString(valueName(source))); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1729 builder.tree(createLazyAssignment(builder, implicitTypeName(source), getContext().getType(Class.class), condition, castType)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1730 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1731 return builder.getRoot(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1732 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1733 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1734 private CodeTree createMethodGuard(CodeTreeBuilder parent, String prefix, SpecializationData source, GuardExpression guard) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1735 CodeTreeBuilder builder = parent.create(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1736 builder.string(prefix); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1737 if (guard.isNegated()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1738 builder.string("!"); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1739 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1740 builder.tree(createTemplateMethodCall(builder, null, source, guard.getResolvedGuard(), null)); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1741 return builder.getRoot(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1742 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1743 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1744 protected CodeTree createGenericInvoke(CodeTreeBuilder parent, SpecializationData source, SpecializationData current) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1745 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1746 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1747 if (current.getMethod() == null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1748 emitEncounteredSynthetic(builder, current); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1749 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1750 builder.startReturn().tree(createTemplateMethodCall(builder, null, source, current, null)).end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1751 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1752 |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1753 return encloseThrowsWithFallThrough(parent, current, builder.getRoot()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1754 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1755 |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1756 private CodeTree encloseThrowsWithFallThrough(CodeTreeBuilder parent, SpecializationData current, CodeTree tree) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1757 if (current.getExceptions().isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1758 return tree; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1759 } |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1760 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1761 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1762 builder.startTryBlock(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1763 builder.tree(tree); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1764 for (SpecializationThrowsData exception : current.getExceptions()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1765 builder.end().startCatchBlock(exception.getJavaClass(), "rewriteEx"); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1766 builder.tree(createDeoptimize(builder)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1767 builder.tree(createCallRewriteMonomorphic(builder, false, current.getNode().getGenericSpecialization().getReturnType().getTypeSystemType(), current, null, |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1768 "Thrown " + ElementUtils.getSimpleName(exception.getJavaClass()))); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
1769 } |
11186
4a9936bb03a4
Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11185
diff
changeset
|
1770 builder.end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1771 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1772 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1773 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1774 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1775 protected CodeTree createCastingExecute(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData executable, ExecutableTypeData castExecutable) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1776 TypeData type = executable.getType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1777 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1778 NodeData node = specialization.getNode(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1779 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1780 TypeData primaryType = castExecutable.getType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1781 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1782 boolean needsTry = castExecutable.hasUnexpectedValue(getContext()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1783 boolean returnVoid = type.isVoid(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1784 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1785 List<Parameter> executeParameters = new ArrayList<>(); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1786 for (Parameter sourceParameter : executable.getSignatureParameters()) { |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1787 Parameter targetParameter = castExecutable.findParameter(sourceParameter.getLocalName()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1788 if (targetParameter != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1789 executeParameters.add(targetParameter); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1790 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1791 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1792 |
11445
5fbd1ba4a5f3
Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
1793 // execute names are enforced no cast |
5fbd1ba4a5f3
Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
1794 String[] executeParameterNames = new String[executeParameters.size()]; |
5fbd1ba4a5f3
Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
1795 for (int i = 0; i < executeParameterNames.length; i++) { |
5fbd1ba4a5f3
Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
1796 executeParameterNames[i] = valueName(executeParameters.get(i)); |
5fbd1ba4a5f3
Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
1797 } |
5fbd1ba4a5f3
Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
1798 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1799 builder.tree(createExecuteChildren(builder, executable, specialization, executeParameters, null)); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1800 boolean hasUnexpected = executable.hasUnexpectedValue(getContext()); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1801 |
11445
5fbd1ba4a5f3
Truffle-DSL: execute evaluated methods can now be declared using any type in the typesystem as parameters.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
1802 CodeTree primaryExecuteCall = createTemplateMethodCall(builder, null, executable, castExecutable, null, executeParameterNames); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1803 if (needsTry) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1804 if (!returnVoid) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1805 builder.declaration(primaryType.getPrimitiveType(), "value"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1806 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1807 builder.startTryBlock(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1808 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1809 if (returnVoid) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1810 builder.statement(primaryExecuteCall); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1811 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1812 builder.startStatement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1813 builder.string("value = "); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1814 builder.tree(primaryExecuteCall); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1815 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1816 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1817 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1818 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1819 if (returnVoid) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1820 builder.string("// ignore").newLine(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1821 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1822 builder.startReturn(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1823 builder.tree(createExpectExecutableType(node, specialization.getNode().getTypeSystem().getGenericTypeData(), hasUnexpected, executable.getType(), |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1824 CodeTreeBuilder.singleString("ex.getResult()"))); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1825 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1826 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1827 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1828 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1829 if (!returnVoid) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1830 builder.startReturn(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1831 builder.tree(createExpectExecutableType(node, castExecutable.getReturnType().getTypeSystemType(), hasUnexpected, executable.getType(), CodeTreeBuilder.singleString("value"))); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1832 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1833 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1834 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1835 if (returnVoid) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1836 builder.statement(primaryExecuteCall); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1837 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1838 builder.startReturn(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1839 builder.tree(createExpectExecutableType(node, castExecutable.getReturnType().getTypeSystemType(), hasUnexpected, executable.getType(), primaryExecuteCall)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1840 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1841 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1842 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1843 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1844 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1845 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1846 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1847 protected CodeTree createExpectExecutableType(NodeData node, TypeData sourceType, boolean hasUnexpected, TypeData exepctedType, CodeTree value) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
1848 return createCastType(node.getTypeSystem(), sourceType, exepctedType, hasUnexpected, value); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1849 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1850 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1851 protected CodeTree createExecuteChildren(CodeTreeBuilder parent, ExecutableTypeData sourceExecutable, SpecializationData specialization, List<Parameter> targetParameters, |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1852 Parameter unexpectedParameter) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1853 CodeTreeBuilder builder = parent.create(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1854 for (Parameter targetParameter : targetParameters) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1855 if (!targetParameter.getSpecification().isSignature()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1856 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1857 } |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1858 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1859 CodeTree executionExpressions = createExecuteChild(builder, execution, sourceExecutable, targetParameter, unexpectedParameter); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1860 CodeTree unexpectedTree = createCatchUnexpectedTree(builder, executionExpressions, specialization, sourceExecutable, targetParameter, execution.isShortCircuit(), unexpectedParameter); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1861 CodeTree shortCircuitTree = createShortCircuitTree(builder, unexpectedTree, specialization, targetParameter, unexpectedParameter); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1862 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1863 if (shortCircuitTree == executionExpressions) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1864 if (containsNewLine(executionExpressions)) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1865 builder.declaration(targetParameter.getType(), valueName(targetParameter)); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1866 builder.tree(shortCircuitTree); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1867 } else { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1868 builder.startStatement().type(targetParameter.getType()).string(" ").tree(shortCircuitTree).end(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1869 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1870 } else { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1871 builder.tree(shortCircuitTree); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1872 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1873 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1874 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1875 return builder.getRoot(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1876 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1877 |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1878 private ExecutableTypeData resolveExecutableType(NodeExecutionData execution, TypeData type) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1879 ExecutableTypeData targetExecutable = execution.getChild().findExecutableType(getContext(), type); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1880 if (targetExecutable == null) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1881 targetExecutable = execution.getChild().findAnyGenericExecutableType(getContext()); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1882 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1883 return targetExecutable; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1884 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1885 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1886 private CodeTree createExecuteChild(CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData sourceExecutable, Parameter targetParameter, Parameter unexpectedParameter) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1887 SpecializationData specialization = getModel(); |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1888 if (specialization.isPolymorphic() && targetParameter.getTypeSystemType().isGeneric() && unexpectedParameter == null) { |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1889 List<TypeData> possiblePolymorphicTypes = lookupPolymorphicTargetTypes(targetParameter); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1890 if (possiblePolymorphicTypes.size() > 1) { |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1891 CodeTreeBuilder builder = parent.create(); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1892 |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1893 boolean elseIf = false; |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1894 for (TypeData possiblePolymoprhicType : possiblePolymorphicTypes) { |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1895 if (possiblePolymoprhicType.isGeneric()) { |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1896 continue; |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1897 } |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1898 elseIf = builder.startIf(elseIf); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1899 |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1900 Parameter sourceParameter = sourceExecutable.findParameter(targetParameter.getLocalName()); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1901 TypeData sourceType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null; |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1902 builder.string(polymorphicTypeName(targetParameter.getSpecification().getExecution())).string(" == ").typeLiteral(possiblePolymoprhicType.getPrimitiveType()); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1903 builder.end().startBlock(); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1904 builder.startStatement(); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1905 builder.tree(createExecuteChildExpression(parent, execution, sourceType, new Parameter(targetParameter, possiblePolymoprhicType), unexpectedParameter, null)); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1906 builder.end(); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1907 builder.end(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1908 } |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1909 |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1910 builder.startElseBlock(); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1911 builder.startStatement().tree(createExecuteChildImplicit(parent, execution, sourceExecutable, targetParameter, unexpectedParameter)).end(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1912 builder.end(); |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1913 |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1914 return builder.getRoot(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1915 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1916 } |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1917 return createExecuteChildImplicit(parent, execution, sourceExecutable, targetParameter, unexpectedParameter); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1918 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1919 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1920 protected final List<Parameter> getImplicitTypeParameters(SpecializationData model) { |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1921 List<Parameter> parameter = new ArrayList<>(); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1922 for (Parameter param : model.getSignatureParameters()) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1923 NodeChildData child = param.getSpecification().getExecution().getChild(); |
12567
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
1924 List<TypeData> types = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
1925 if (types.size() > 1) { |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
1926 parameter.add(param); |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
1927 } |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
1928 } |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
1929 return parameter; |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
1930 } |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
1931 |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1932 protected final List<TypeData> lookupPolymorphicTargetTypes(Parameter param) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1933 SpecializationData specialization = getModel(); |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1934 Set<TypeData> possiblePolymorphicTypes = new HashSet<>(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1935 for (SpecializationData otherSpecialization : specialization.getNode().getSpecializations()) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1936 if (!otherSpecialization.isSpecialized()) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1937 continue; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1938 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1939 Parameter otherParameter = otherSpecialization.findParameter(param.getLocalName()); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1940 if (otherParameter != null) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1941 possiblePolymorphicTypes.add(otherParameter.getTypeSystemType()); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1942 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1943 } |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1944 List<TypeData> types = new ArrayList<>(possiblePolymorphicTypes); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1945 Collections.sort(types); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
1946 return types; |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1947 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1948 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1949 private CodeTree createExecuteChildImplicit(CodeTreeBuilder parent, NodeExecutionData execution, ExecutableTypeData sourceExecutable, Parameter param, Parameter unexpectedParameter) { |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1950 CodeTreeBuilder builder = parent.create(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1951 Parameter sourceParameter = sourceExecutable.findParameter(param.getLocalName()); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1952 String childExecuteName = createExecuteChildMethodName(param, sourceParameter != null); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1953 if (childExecuteName != null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1954 builder.string(valueName(param)); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1955 builder.string(" = "); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1956 builder.startCall(childExecuteName); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1957 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1958 for (Parameter parameters : sourceExecutable.getParameters()) { |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1959 if (parameters.getSpecification().isSignature()) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1960 continue; |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1961 } |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1962 builder.string(parameters.getLocalName()); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1963 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1964 |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1965 if (sourceParameter != null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1966 builder.string(valueNameEvaluated(sourceParameter)); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1967 } |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1968 |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1969 builder.string(implicitTypeName(param)); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1970 |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1971 builder.end(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
1972 } else { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1973 List<TypeData> sourceTypes = execution.getChild().getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1974 TypeData expectType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null; |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
1975 if (sourceTypes.size() > 1) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
1976 builder.tree(createExecuteChildImplicitExpressions(parent, param, expectType)); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
1977 } else { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1978 builder.tree(createExecuteChildExpression(parent, execution, expectType, param, unexpectedParameter, null)); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
1979 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1980 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1981 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1982 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1983 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1984 private String createExecuteChildMethodName(Parameter param, boolean expect) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1985 NodeExecutionData execution = param.getSpecification().getExecution(); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1986 NodeChildData child = execution.getChild(); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
1987 if (child.getExecuteWith().size() > 0) { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
1988 return null; |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
1989 } |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1990 List<TypeData> sourceTypes = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType()); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1991 if (sourceTypes.size() <= 1) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1992 return null; |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1993 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1994 String prefix = expect ? "expect" : "execute"; |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
1995 String suffix = execution.getIndex() > -1 ? String.valueOf(execution.getIndex()) : ""; |
18605
58eb9bbb60c4
Truffle-DSL: fixed several bugs when using arrays as type. added arrays test.
Christian Humer <christian.humer@gmail.com>
parents:
18163
diff
changeset
|
1996 return prefix + ElementUtils.firstLetterUpperCase(child.getName()) + ElementUtils.firstLetterUpperCase(ElementUtils.getTypeId(param.getType())) + suffix; |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1997 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
1998 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
1999 private List<CodeExecutableElement> createExecuteChilds(Parameter param, Set<TypeData> expectTypes) { |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2000 CodeExecutableElement executeMethod = createExecuteChild(param, null); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2001 if (executeMethod == null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2002 return Collections.emptyList(); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2003 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2004 List<CodeExecutableElement> childs = new ArrayList<>(); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2005 childs.add(executeMethod); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2006 |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2007 for (TypeData expectType : expectTypes) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2008 CodeExecutableElement method = createExecuteChild(param, expectType); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2009 if (method != null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2010 childs.add(method); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2011 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2012 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2013 return childs; |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2014 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2015 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2016 private CodeExecutableElement createExecuteChild(Parameter param, TypeData expectType) { |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2017 String childExecuteName = createExecuteChildMethodName(param, expectType != null); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2018 if (childExecuteName == null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2019 return null; |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2020 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2021 |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2022 CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, expectType != null ? STATIC : FINAL), param.getType(), childExecuteName); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2023 method.getThrownTypes().add(getContext().getTruffleTypes().getUnexpectedValueException()); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2024 method.addParameter(new CodeVariableElement(getContext().getTruffleTypes().getFrame(), "frameValue")); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2025 if (expectType != null) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2026 method.addParameter(new CodeVariableElement(expectType.getPrimitiveType(), valueNameEvaluated(param))); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2027 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2028 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), implicitTypeName(param))); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2029 |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2030 CodeTreeBuilder builder = method.createBuilder(); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2031 builder.declaration(param.getType(), valueName(param)); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2032 builder.tree(createExecuteChildImplicitExpressions(builder, param, expectType)); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2033 builder.startReturn().string(valueName(param)).end(); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2034 |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2035 return method; |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2036 } |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2037 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2038 private CodeTree createExecuteChildImplicitExpressions(CodeTreeBuilder parent, Parameter targetParameter, TypeData expectType) { |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2039 CodeTreeBuilder builder = parent.create(); |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2040 NodeData node = getModel().getNode(); |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2041 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2042 List<TypeData> sourceTypes = node.getTypeSystem().lookupSourceTypes(targetParameter.getTypeSystemType()); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2043 boolean elseIf = false; |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2044 int index = 0; |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2045 for (TypeData sourceType : sourceTypes) { |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2046 if (index < sourceTypes.size() - 1) { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2047 elseIf = builder.startIf(elseIf); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2048 builder.string(implicitTypeName(targetParameter)).string(" == ").typeLiteral(sourceType.getPrimitiveType()); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2049 builder.end(); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2050 builder.startBlock(); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2051 } else { |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2052 builder.startElseBlock(); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2053 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2054 |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2055 ExecutableTypeData implictExecutableTypeData = execution.getChild().findExecutableType(getContext(), sourceType); |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2056 if (implictExecutableTypeData == null) { |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2057 /* |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2058 * For children with executeWith.size() > 0 an executable type may not exist so |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2059 * use the generic executable type which is guaranteed to exist. An expect call |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2060 * is inserted automatically by #createExecuteExpression. |
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2061 */ |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2062 implictExecutableTypeData = execution.getChild().getNodeData().findExecutableType(node.getTypeSystem().getGenericTypeData(), execution.getChild().getExecuteWith().size()); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2063 } |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2064 |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2065 ImplicitCastData cast = execution.getChild().getNodeData().getTypeSystem().lookupCast(sourceType, targetParameter.getTypeSystemType()); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2066 CodeTree execute = createExecuteChildExpression(builder, execution, expectType, targetParameter, null, cast); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2067 builder.statement(execute); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2068 builder.end(); |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2069 index++; |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2070 } |
12392
4e26955b6da2
Truffle-DSL: new implicit cast code generation layout supports now executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
12391
diff
changeset
|
2071 return builder.getRoot(); |
12391
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2072 } |
7aa2a8c69ba3
TruffleDSL: improved code generation layout for implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11743
diff
changeset
|
2073 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2074 private CodeTree createExecuteChildExpression(CodeTreeBuilder parent, NodeExecutionData execution, TypeData sourceParameterType, Parameter targetParameter, Parameter unexpectedParameter, |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2075 ImplicitCastData cast) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2076 // assignments: targetType <- castTargetType <- castSourceType <- sourceType |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2077 TypeData sourceType = sourceParameterType; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2078 TypeData targetType = targetParameter.getTypeSystemType(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2079 TypeData castSourceType = targetType; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2080 TypeData castTargetType = targetType; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2081 |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2082 if (cast != null) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2083 castSourceType = cast.getSourceType(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2084 castTargetType = cast.getTargetType(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2085 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2086 |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2087 CodeTree expression; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2088 if (sourceType == null) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2089 ExecutableTypeData targetExecutable = resolveExecutableType(execution, castSourceType); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2090 expression = createExecuteChildExpression(parent, execution, targetExecutable, unexpectedParameter); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2091 sourceType = targetExecutable.getType(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2092 } else { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2093 expression = CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter)); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2094 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2095 |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2096 // target = expectTargetType(implicitCast(expectCastSourceType(source))) |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2097 TypeSystemData typeSystem = execution.getChild().getNodeData().getTypeSystem(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2098 expression = createExpectType(typeSystem, sourceType, castSourceType, expression); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2099 expression = createImplicitCast(parent, typeSystem, cast, expression); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2100 expression = createExpectType(typeSystem, castTargetType, targetType, expression); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2101 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2102 CodeTreeBuilder builder = parent.create(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2103 builder.string(valueName(targetParameter)); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2104 builder.string(" = "); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2105 builder.tree(expression); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2106 return builder.getRoot(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2107 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2108 |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2109 private CodeTree createImplicitCast(CodeTreeBuilder parent, TypeSystemData typeSystem, ImplicitCastData cast, CodeTree expression) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2110 if (cast == null) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2111 return expression; |
11554
5d5007c9a5aa
Truffle-DSL: fixed a if bug target parameters and executes accidently do not match.
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
2112 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2113 CodeTreeBuilder builder = parent.create(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2114 startCallTypeSystemMethod(builder, typeSystem, cast.getMethodName()); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2115 builder.tree(expression); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2116 builder.end().end(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2117 return builder.getRoot(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2118 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2119 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2120 private boolean containsNewLine(CodeTree tree) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2121 if (tree.getCodeKind() == CodeTreeKind.NEW_LINE) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2122 return true; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2123 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2124 |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
2125 List<CodeTree> enclosing = tree.getEnclosedElements(); |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
2126 if (enclosing != null) { |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
2127 for (CodeTree codeTree : enclosing) { |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
2128 if (containsNewLine(codeTree)) { |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
2129 return true; |
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
2130 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2131 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2132 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2133 return false; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2134 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2135 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2136 private boolean hasUnexpected(Parameter sourceParameter, Parameter targetParameter, Parameter unexpectedParameter) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2137 NodeExecutionData execution = targetParameter.getSpecification().getExecution(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2138 |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2139 if (getModel().isPolymorphic() && targetParameter.getTypeSystemType().isGeneric() && unexpectedParameter == null) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2140 // check for other polymorphic types |
16909
62cfffca9be2
Truffle-DSL: some more performance optimizations.
Christian Humer <christian.humer@gmail.com>
parents:
16851
diff
changeset
|
2141 List<TypeData> polymorphicTargetTypes = lookupPolymorphicTargetTypes(targetParameter); |
12398
c78612fb0120
Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents:
12395
diff
changeset
|
2142 if (polymorphicTargetTypes.size() > 1) { |
c78612fb0120
Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents:
12395
diff
changeset
|
2143 for (TypeData polymorphicTargetType : polymorphicTargetTypes) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2144 if (hasUnexpectedType(execution, sourceParameter, polymorphicTargetType)) { |
12398
c78612fb0120
Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents:
12395
diff
changeset
|
2145 return true; |
c78612fb0120
Truffle-DSL. fixed some issues with new generation strategy.
Christian Humer <christian.humer@gmail.com>
parents:
12395
diff
changeset
|
2146 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2147 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2148 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2149 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2150 |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2151 if (hasUnexpectedType(execution, sourceParameter, targetParameter.getTypeSystemType())) { |
11554
5d5007c9a5aa
Truffle-DSL: fixed a if bug target parameters and executes accidently do not match.
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
2152 return true; |
5d5007c9a5aa
Truffle-DSL: fixed a if bug target parameters and executes accidently do not match.
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
2153 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2154 return false; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2155 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2156 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2157 private boolean hasUnexpectedType(NodeExecutionData execution, Parameter sourceParameter, TypeData targetType) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2158 List<TypeData> implicitSourceTypes = getModel().getNode().getTypeSystem().lookupSourceTypes(targetType); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2159 |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2160 for (TypeData implicitSourceType : implicitSourceTypes) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2161 TypeData sourceType; |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2162 ExecutableTypeData targetExecutable = resolveExecutableType(execution, implicitSourceType); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2163 if (sourceParameter != null) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2164 sourceType = sourceParameter.getTypeSystemType(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2165 } else { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2166 if (targetExecutable.hasUnexpectedValue(getContext())) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2167 return true; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2168 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2169 sourceType = targetExecutable.getType(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2170 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2171 |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2172 ImplicitCastData cast = getModel().getNode().getTypeSystem().lookupCast(implicitSourceType, targetType); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2173 if (cast != null) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2174 if (cast.getSourceType().needsCastTo(targetType)) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2175 return true; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2176 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2177 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2178 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2179 if (sourceType.needsCastTo(targetType)) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2180 return true; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2181 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2182 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2183 return false; |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2184 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2185 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2186 private CodeTree createCatchUnexpectedTree(CodeTreeBuilder parent, CodeTree body, SpecializationData specialization, ExecutableTypeData currentExecutable, Parameter param, |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2187 boolean shortCircuit, Parameter unexpectedParameter) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2188 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2189 Parameter sourceParameter = currentExecutable.findParameter(param.getLocalName()); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2190 boolean unexpected = hasUnexpected(sourceParameter, param, unexpectedParameter); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2191 if (!unexpected) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2192 return body; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2193 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2194 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2195 if (!shortCircuit) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2196 builder.declaration(param.getType(), valueName(param)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2197 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2198 builder.startTryBlock(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2199 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2200 if (containsNewLine(body)) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2201 builder.tree(body); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2202 } else { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2203 builder.statement(body); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2204 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2205 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2206 builder.end().startCatchBlock(getUnexpectedValueException(), "ex"); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2207 SpecializationData generic = specialization.getNode().getGenericSpecialization(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2208 Parameter genericParameter = generic.findParameter(param.getLocalName()); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2209 |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2210 List<Parameter> genericParameters = generic.getParametersAfter(genericParameter); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2211 builder.tree(createExecuteChildren(parent, currentExecutable, generic, genericParameters, genericParameter)); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2212 if (specialization.isPolymorphic()) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2213 builder.tree(createReturnOptimizeTypes(builder, currentExecutable, specialization, param)); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2214 } else { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2215 builder.tree(createCallRewriteMonomorphic(builder, currentExecutable.hasUnexpectedValue(context), currentExecutable.getType(), specialization, param, |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2216 "Expected " + param.getLocalName() + " instanceof " + ElementUtils.getSimpleName(param.getType()))); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2217 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2218 builder.end(); // catch block |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2219 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2220 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2221 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2222 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2223 private CodeTree createReturnOptimizeTypes(CodeTreeBuilder parent, ExecutableTypeData currentExecutable, SpecializationData specialization, Parameter param) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2224 NodeData node = specialization.getNode(); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
2225 SpecializationData polymorphic = node.getPolymorphicSpecialization(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2226 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2227 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2228 builder.startStatement().string(polymorphicTypeName(param.getSpecification().getExecution())).string(" = ").typeLiteral(getContext().getType(Object.class)).end(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2229 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2230 builder.startReturn(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2231 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2232 CodeTreeBuilder execute = new CodeTreeBuilder(builder); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2233 execute.startCall("next0", EXECUTE_CHAINED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
2234 addInternalValueParameterNames(execute, specialization, polymorphic, param.getLocalName(), true, false, null); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2235 execute.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2236 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
2237 TypeData sourceType = polymorphic.getReturnType().getTypeSystemType(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2238 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2239 builder.tree(createExpectExecutableType(node, sourceType, currentExecutable.hasUnexpectedValue(context), currentExecutable.getType(), execute.getRoot())); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2240 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2241 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2242 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2243 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2244 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2245 private CodeTree createExecuteChildExpression(CodeTreeBuilder parent, NodeExecutionData targetExecution, ExecutableTypeData targetExecutable, Parameter unexpectedParameter) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2246 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2247 if (targetExecution != null) { |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
2248 builder.tree(createAccessChild(targetExecution, null)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2249 builder.string("."); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2250 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2251 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2252 builder.startCall(targetExecutable.getMethodName()); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2253 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2254 // TODO this should be merged with #createTemplateMethodCall |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2255 int index = 0; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2256 for (Parameter parameter : targetExecutable.getParameters()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2257 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2258 if (!parameter.getSpecification().isSignature()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2259 builder.string(parameter.getLocalName()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2260 } else { |
10602
b8fe1fe004ec
Truffle-DSL: fixed bugs in the generated polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10600
diff
changeset
|
2261 |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2262 if (index < targetExecution.getChild().getExecuteWith().size()) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2263 NodeChildData child = targetExecution.getChild().getExecuteWith().get(index); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2264 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2265 ParameterSpec spec = getModel().getSpecification().findParameterSpec(child.getName()); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2266 List<Parameter> specializationParams = getModel().findParameters(spec); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2267 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2268 if (specializationParams.isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2269 builder.defaultValue(parameter.getType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2270 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2271 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2272 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2273 Parameter specializationParam = specializationParams.get(0); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2274 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2275 TypeData targetType = parameter.getTypeSystemType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2276 TypeData sourceType = specializationParam.getTypeSystemType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2277 String localName = specializationParam.getLocalName(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2278 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2279 if (unexpectedParameter != null && unexpectedParameter.getLocalName().equals(specializationParam.getLocalName())) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2280 localName = "ex.getResult()"; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2281 sourceType = getModel().getNode().getTypeSystem().getGenericTypeData(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2282 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2283 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2284 CodeTree value = CodeTreeBuilder.singleString(localName); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2285 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2286 if (sourceType.needsCastTo(targetType)) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2287 value = createCallTypeSystemMethod(builder, getModel().getNode(), TypeSystemCodeGenerator.asTypeMethodName(targetType), value); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2288 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2289 builder.tree(value); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2290 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2291 builder.defaultValue(parameter.getType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2292 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2293 index++; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2294 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2295 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2296 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2297 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2298 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2299 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2300 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2301 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2302 private CodeTree createShortCircuitTree(CodeTreeBuilder parent, CodeTree body, SpecializationData specialization, Parameter parameter, Parameter exceptionParam) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2303 NodeExecutionData execution = parameter.getSpecification().getExecution(); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2304 if (execution == null || !execution.isShortCircuit()) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2305 return body; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2306 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2307 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2308 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2309 Parameter shortCircuitParam = specialization.getPreviousParam(parameter); |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2310 builder.tree(createShortCircuitValue(builder, specialization, execution, shortCircuitParam, exceptionParam)); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2311 builder.declaration(parameter.getType(), valueName(parameter), CodeTreeBuilder.createBuilder().defaultValue(parameter.getType())); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2312 builder.startIf().string(shortCircuitParam.getLocalName()).end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2313 builder.startBlock(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2314 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2315 if (containsNewLine(body)) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2316 builder.tree(body); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2317 } else { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2318 builder.statement(body); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2319 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2320 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2321 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2322 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2323 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2324 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2325 private CodeTree createShortCircuitValue(CodeTreeBuilder parent, SpecializationData specialization, NodeExecutionData execution, Parameter shortCircuitParam, Parameter exceptionParam) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2326 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2327 int shortCircuitIndex = 0; |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2328 for (NodeExecutionData otherExectuion : specialization.getNode().getChildExecutions()) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2329 if (otherExectuion.isShortCircuit()) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2330 if (otherExectuion == execution) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2331 break; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2332 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2333 shortCircuitIndex++; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2334 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2335 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2336 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2337 builder.startStatement().type(shortCircuitParam.getType()).string(" ").string(valueName(shortCircuitParam)).string(" = "); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2338 ShortCircuitData shortCircuitData = specialization.getShortCircuits().get(shortCircuitIndex); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2339 builder.tree(createTemplateMethodCall(builder, null, specialization, shortCircuitData, exceptionParam != null ? exceptionParam.getLocalName() : null)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2340 builder.end(); // statement |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2341 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2342 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2343 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2344 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2345 protected CodeTree createCallRewriteMonomorphic(CodeTreeBuilder parent, boolean hasUnexpected, TypeData returnType, SpecializationData current, Parameter exceptionParam, String reason) { |
11186
4a9936bb03a4
Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11185
diff
changeset
|
2346 NodeData node = current.getNode(); |
11185
5daaa0821406
Truffle-DSL: Changed executeAndSpecialize to use an int as minimumState instead of a class.
Christian Humer <christian.humer@gmail.com>
parents:
11180
diff
changeset
|
2347 SpecializationData generic = node.getGenericSpecialization(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2348 CodeTreeBuilder specializeCall = new CodeTreeBuilder(parent); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2349 specializeCall.startCall(REWRITE); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
2350 addInternalValueParameterNames(specializeCall, generic, node.getGenericSpecialization(), exceptionParam != null ? exceptionParam.getLocalName() : null, true, false, null); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2351 specializeCall.doubleQuote(reason); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2352 specializeCall.end().end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2353 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2354 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2355 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2356 builder.startReturn(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2357 builder.tree(createExpectExecutableType(node, generic.getReturnType().getTypeSystemType(), hasUnexpected, returnType, specializeCall.getRoot())); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2358 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2359 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2360 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2361 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2362 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2363 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2364 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2365 private class PolymorphicNodeFactory extends SpecializedNodeFactory { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2366 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2367 public PolymorphicNodeFactory(CodeTypeElement nodeGen) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2368 super(nodeGen); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2369 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2370 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2371 @Override |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2372 public CodeTypeElement create(SpecializationData polymorph) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2373 NodeData node = polymorph.getNode(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2374 TypeMirror baseType = node.getNodeType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2375 if (nodeGen != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2376 baseType = nodeGen.asType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2377 } |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
2378 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodePolymorphicClassName(node), baseType, false); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2379 |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
2380 clazz.getAnnotationMirrors().add(createNodeInfo(node, NodeCost.POLYMORPHIC)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2381 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2382 for (Parameter polymorphParameter : polymorph.getSignatureParameters()) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2383 if (!polymorphParameter.getTypeSystemType().isGeneric()) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2384 continue; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2385 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2386 Set<TypeData> types = new HashSet<>(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2387 for (SpecializationData specialization : node.getSpecializations()) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2388 if (!specialization.isSpecialized()) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2389 continue; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2390 } |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2391 Parameter parameter = specialization.findParameter(polymorphParameter.getLocalName()); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2392 assert parameter != null; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2393 types.add(parameter.getTypeSystemType()); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2394 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2395 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2396 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2397 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2398 for (NodeExecutionData execution : getModel().getNode().getChildExecutions()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2399 String fieldName = polymorphicTypeName(execution); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2400 CodeVariableElement var = new CodeVariableElement(modifiers(PRIVATE), getContext().getType(Class.class), fieldName); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2401 var.getAnnotationMirrors().add(new CodeAnnotationMirror(getContext().getTruffleTypes().getCompilationFinal())); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2402 clazz.add(var); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2403 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2404 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2405 return clazz; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2406 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2407 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2408 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2409 protected void createChildren(SpecializationData specialization) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2410 CodeTypeElement clazz = getElement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2411 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2412 createConstructors(clazz); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2413 createExecuteMethods(specialization); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2414 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2415 clazz.add(createUpdateTypes0()); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2416 createCachedExecuteMethods(specialization); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2417 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2418 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2419 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2420 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2421 private class SpecializedNodeFactory extends NodeBaseFactory { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2422 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2423 protected final CodeTypeElement nodeGen; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2424 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2425 public SpecializedNodeFactory(CodeTypeElement nodeGen) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2426 this.nodeGen = nodeGen; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2427 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2428 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2429 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2430 public CodeTypeElement create(SpecializationData specialization) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2431 NodeData node = specialization.getNode(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2432 TypeMirror baseType = node.getNodeType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2433 if (nodeGen != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2434 baseType = nodeGen.asType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2435 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2436 CodeTypeElement clazz = createClass(node, modifiers(PRIVATE, STATIC, FINAL), nodeSpecializationClassName(specialization), baseType, false); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2437 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2438 if (specialization.isSpecialized() || specialization.isUninitialized()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2439 clazz.add(createGetMetadata0(false)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2440 clazz.add(createMetadataLiteral()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2441 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2442 |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2443 NodeCost cost; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2444 if (specialization.isGeneric()) { |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2445 cost = NodeCost.MEGAMORPHIC; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2446 } else if (specialization.isUninitialized()) { |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2447 cost = NodeCost.UNINITIALIZED; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
2448 } else if (specialization.isPolymorphic()) { |
14641
f0bb82ebe30c
Truffle-DSL: some fixes and optimizations to the generated code.
Christian Humer <christian.humer@gmail.com>
parents:
14628
diff
changeset
|
2449 cost = NodeCost.POLYMORPHIC; |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
2450 } else if (specialization.isSpecialized()) { |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2451 cost = NodeCost.MONOMORPHIC; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2452 } else { |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
2453 throw new AssertionError(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2454 } |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2455 clazz.getAnnotationMirrors().add(createNodeInfo(node, cost)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2456 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2457 if (specialization.isUninitialized() && node.getGenericSpecialization().isReachable()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2458 clazz.add(createUninitializedGetCostOverride()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2459 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2460 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2461 return clazz; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2462 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2463 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2464 private Element createUninitializedGetCostOverride() { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2465 TypeMirror returnType = context.getTruffleTypes().getNodeCost(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2466 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2467 CodeTreeBuilder builder = method.createBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2468 builder.startIf().string(CONTAINS_FALLBACK).end().startBlock(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2469 builder.startReturn().staticReference(returnType, "MONOMORPHIC").end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2470 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2471 builder.startReturn().string("super.getCost()").end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2472 return method; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2473 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2474 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2475 private CodeVariableElement createMetadataLiteral() { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2476 CodeVariableElement includes = new CodeVariableElement(modifiers(PRIVATE, STATIC, FINAL), context.getTruffleTypes().getDslMetadata(), METADATA_FIELD_NAME); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2477 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2478 CodeTreeBuilder builder = includes.createInitBuilder(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2479 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2480 SpecializationData specialization = getModel(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2481 NodeData node = specialization.getNode(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2482 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2483 Set<SpecializationData> contains = specialization.getContains(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2484 if (specialization.isUninitialized()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2485 contains = new HashSet<>(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2486 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2487 SpecializationData polymorphic = node.getPolymorphicSpecialization(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2488 if (polymorphic != null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2489 contains.addAll(polymorphic.getContains()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2490 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2491 SpecializationData generic = node.getGenericSpecialization(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2492 if (generic != null) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2493 contains.addAll(generic.getContains()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2494 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2495 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2496 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2497 builder.startNew(context.getTruffleTypes().getDslMetadata()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2498 builder.startGroup().string(nodeSpecializationClassName(getModel()), ".class").end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2499 builder.tree(createSpecializationListLiteral(builder, contains)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2500 builder.tree(createSpecializationListLiteral(builder, getModel().getExcludedBy())); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2501 builder.tree(createSpecializationTypeLiteral(builder, SpecializationData.getSignatureTypes(getModel()))); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2502 builder.string("0").string("0"); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2503 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2504 return includes; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2505 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2506 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2507 private CodeTree createSpecializationTypeLiteral(CodeTreeBuilder parent, List<TypeMirror> list) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2508 ArrayType classArray = new ArrayCodeTypeMirror(context.getType(Class.class)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2509 CodeTreeBuilder builder = parent.create(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2510 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2511 if (list.isEmpty()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2512 builder.staticReference(context.getTruffleTypes().getDslMetadata(), EMPTY_CLASS_ARRAY); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2513 } else { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2514 builder.startNewArray(classArray, null); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2515 for (TypeMirror type : list) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2516 builder.typeLiteral(type); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2517 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2518 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2519 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2520 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2521 return builder.getRoot(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2522 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2523 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2524 private CodeTree createSpecializationListLiteral(CodeTreeBuilder parent, Set<SpecializationData> list) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2525 ArrayType classArray = new ArrayCodeTypeMirror(context.getType(Class.class)); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2526 CodeTreeBuilder builder = parent.create(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2527 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2528 if (list.isEmpty()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2529 builder.staticReference(context.getTruffleTypes().getDslMetadata(), EMPTY_CLASS_ARRAY); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2530 } else { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2531 builder.startNewArray(classArray, null); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2532 for (SpecializationData specialization : list) { |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18130
diff
changeset
|
2533 SpecializationData s = specialization; |
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18130
diff
changeset
|
2534 if (s.isGeneric() || s.isPolymorphic()) { |
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18130
diff
changeset
|
2535 s = getModel().getNode().getUninitializedSpecialization(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2536 } |
18163
c88ab4f1f04a
re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents:
18130
diff
changeset
|
2537 builder.startGroup().string(nodeSpecializationClassName(s)).string(".class").end(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2538 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2539 builder.end(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2540 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2541 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2542 return builder.getRoot(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2543 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2544 |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2545 protected CodeAnnotationMirror createNodeInfo(NodeData node, NodeCost cost) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2546 String shortName = node.getShortName(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2547 CodeAnnotationMirror nodeInfoMirror = new CodeAnnotationMirror(getContext().getTruffleTypes().getNodeInfoAnnotation()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2548 if (shortName != null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2549 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("shortName"), new CodeAnnotationValue(shortName)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2550 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2551 |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2552 DeclaredType nodeinfoCost = getContext().getTruffleTypes().getNodeCost(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2553 VariableElement varKind = ElementUtils.findVariableElement(nodeinfoCost, cost.name()); |
14564
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2554 |
5d1308c78ddc
Truffle: Introduced NodeCost as a replacement for NodeInfo.Kind.
Christian Humer <christian.humer@gmail.com>
parents:
14077
diff
changeset
|
2555 nodeInfoMirror.setElementValue(nodeInfoMirror.findExecutableElement("cost"), new CodeAnnotationValue(varKind)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2556 return nodeInfoMirror; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2557 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2558 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2559 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2560 protected void createChildren(SpecializationData specialization) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2561 CodeTypeElement clazz = getElement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2562 createConstructors(clazz); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2563 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2564 createExecuteMethods(specialization); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2565 createCachedExecuteMethods(specialization); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2566 |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2567 if (specialization.isUninitialized()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2568 if (specialization.getNode().isFallbackReachable()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2569 CodeVariableElement var = new CodeVariableElement(modifiers(Modifier.PRIVATE), context.getType(boolean.class), CONTAINS_FALLBACK); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2570 var.addAnnotationMirror(new CodeAnnotationMirror(context.getTruffleTypes().getCompilationFinal())); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2571 clazz.add(var); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2572 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2573 clazz.add(createExecuteUninitialized()); |
14077
3ea5f337cc0d
Truffle-DSL: generate better implementations for getKind()
Christian Humer <christian.humer@gmail.com>
parents:
14042
diff
changeset
|
2574 } |
15475
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2575 |
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2576 if (!specialization.isUninitialized() && specialization.getNode().needsRewrites(context)) { |
15476
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2577 clazz.add(createCopyConstructorFactoryMethod(nodeGen.asType(), specialization)); |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2578 } else { |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2579 for (ExecutableElement constructor : ElementFilter.constructorsIn(clazz.getEnclosedElements())) { |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2580 if (constructor.getParameters().size() == 1 && ((CodeVariableElement) constructor.getParameters().get(0)).getType().equals(nodeGen.asType())) { |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2581 // skip copy constructor - not used |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2582 continue; |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2583 } |
15477
fd18fa50a8e0
TruffleDSL: NodeCodeGenerator: avoid referencing BaseNode class in factory
Andreas Woess <andreas.woess@jku.at>
parents:
15476
diff
changeset
|
2584 clazz.add(createConstructorFactoryMethod(specialization, constructor)); |
15476
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2585 } |
15475
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2586 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2587 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2588 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2589 protected void createConstructors(CodeTypeElement clazz) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2590 TypeElement superTypeElement = ElementUtils.fromTypeMirror(clazz.getSuperclass()); |
11180
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2591 SpecializationData specialization = getModel(); |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2592 NodeData node = specialization.getNode(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2593 for (ExecutableElement constructor : ElementFilter.constructorsIn(superTypeElement.getEnclosedElements())) { |
11180
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2594 if (specialization.isUninitialized()) { |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2595 // ignore copy constructors for uninitialized if not polymorphic |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2596 if (isCopyConstructor(constructor) && !node.isPolymorphic(context)) { |
11180
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2597 continue; |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2598 } |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2599 } else if (node.getUninitializedSpecialization() != null) { |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2600 // ignore others than copy constructors for specialized nodes |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2601 if (!isCopyConstructor(constructor)) { |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2602 continue; |
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2603 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2604 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2605 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2606 CodeExecutableElement superConstructor = createSuperConstructor(clazz, constructor); |
14598
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
2607 if (superConstructor == null) { |
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
2608 continue; |
40eedef0a586
Truffle-DSL: fixed some findbugs errors for (CR-2223)
Christian Humer <christian.humer@gmail.com>
parents:
14567
diff
changeset
|
2609 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2610 CodeTree body = superConstructor.getBodyTree(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2611 CodeTreeBuilder builder = superConstructor.createBuilder(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2612 builder.tree(body); |
11180
a9cb98ff8fd9
Truffle-DSL: Fixed compile error for nodes with no children and empty constructor.
Christian Humer <christian.humer@gmail.com>
parents:
10859
diff
changeset
|
2613 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2614 if (superConstructor != null) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2615 for (Parameter param : getImplicitTypeParameters(getModel())) { |
12567
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
2616 clazz.add(new CodeVariableElement(modifiers(PRIVATE, FINAL), getContext().getType(Class.class), implicitTypeName(param))); |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
2617 superConstructor.getParameters().add(new CodeVariableElement(getContext().getType(Class.class), implicitTypeName(param))); |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
2618 |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
2619 builder.startStatement(); |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
2620 builder.string("this.").string(implicitTypeName(param)).string(" = ").string(implicitTypeName(param)); |
0d3e4d940925
Truffle-DSL: fixed recursive rewrite problem for transitions from monomorphic to polymorphic. (GRAAL-560 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
12503
diff
changeset
|
2621 builder.end(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2622 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2623 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2624 clazz.add(superConstructor); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2625 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2626 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2627 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2628 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2629 protected void createExecuteMethods(SpecializationData specialization) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2630 NodeData node = specialization.getNode(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2631 CodeTypeElement clazz = getElement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2632 |
16821
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2633 List<ExecutableTypeData> primaryExecutes = null; |
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2634 int lastEvaluatedCount = -1; |
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2635 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2636 for (ExecutableTypeData execType : node.getExecutableTypes()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2637 if (execType.isFinal()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2638 continue; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2639 } |
16821
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2640 if (execType.getEvaluatedCount() != lastEvaluatedCount) { |
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2641 lastEvaluatedCount = execType.getEvaluatedCount(); |
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2642 primaryExecutes = findFunctionalExecutableType(specialization, lastEvaluatedCount); |
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2643 } |
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2644 |
16822
84f1c44b5e9b
Truffle-DSL: fixed resolve of executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
16821
diff
changeset
|
2645 CodeExecutableElement executeMethod = createExecutableTypeOverride(execType, true); |
84f1c44b5e9b
Truffle-DSL: fixed resolve of executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
16821
diff
changeset
|
2646 clazz.add(executeMethod); |
84f1c44b5e9b
Truffle-DSL: fixed resolve of executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
16821
diff
changeset
|
2647 CodeTreeBuilder builder = executeMethod.getBuilder(); |
16821
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2648 CodeTree result = createExecuteBody(builder, specialization, execType, primaryExecutes); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2649 if (result != null) { |
16822
84f1c44b5e9b
Truffle-DSL: fixed resolve of executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
16821
diff
changeset
|
2650 builder.tree(result); |
84f1c44b5e9b
Truffle-DSL: fixed resolve of executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
16821
diff
changeset
|
2651 } else { |
84f1c44b5e9b
Truffle-DSL: fixed resolve of executeWith.
Christian Humer <christian.humer@gmail.com>
parents:
16821
diff
changeset
|
2652 clazz.remove(executeMethod); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2653 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2654 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2655 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2656 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2657 protected void createCachedExecuteMethods(SpecializationData specialization) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2658 NodeData node = specialization.getNode(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2659 if (!node.isPolymorphic(context)) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2660 return; |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2661 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2662 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2663 CodeTypeElement clazz = getElement(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2664 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
2665 final SpecializationData polymorphic = node.getPolymorphicSpecialization(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2666 ExecutableElement executeCached = nodeGen.getMethod(EXECUTE_CHAINED); |
13530
0576e9a0358e
Truffle-DSL: minor cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13528
diff
changeset
|
2667 CodeExecutableElement executeMethod = CodeExecutableElement.clone(getContext().getEnvironment(), executeCached); |
0576e9a0358e
Truffle-DSL: minor cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13528
diff
changeset
|
2668 executeMethod.getModifiers().remove(Modifier.ABSTRACT); |
0576e9a0358e
Truffle-DSL: minor cleanup.
Christian Humer <christian.humer@gmail.com>
parents:
13528
diff
changeset
|
2669 CodeTreeBuilder builder = executeMethod.createBuilder(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2670 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2671 if (specialization.isPolymorphic()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2672 builder.startReturn().startCall("this.next0", EXECUTE_CHAINED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
2673 addInternalValueParameterNames(builder, polymorphic, polymorphic, null, true, false, null); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2674 builder.end().end(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2675 } else if (specialization.isUninitialized()) { |
16781
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2676 builder.tree(createDeoptimizeUninitialized(node, builder)); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2677 builder.startReturn().startCall("this", EXECUTE_UNINITIALIZED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
2678 addInternalValueParameterNames(builder, polymorphic, polymorphic, null, true, false, null); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2679 builder.end().end(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2680 } else { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2681 CodeTreeBuilder elseBuilder = new CodeTreeBuilder(builder); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2682 elseBuilder.startReturn().startCall("this.next0", EXECUTE_CHAINED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
2683 addInternalValueParameterNames(elseBuilder, polymorphic, polymorphic, null, true, false, null); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2684 elseBuilder.end().end(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2685 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2686 builder.tree(createExecuteTree(builder, polymorphic, SpecializationGroup.create(specialization), new CodeBlock<SpecializationData>() { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2687 |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2688 public CodeTree create(CodeTreeBuilder b, SpecializationData current) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2689 return createGenericInvoke(b, polymorphic, current); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2690 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2691 }, elseBuilder.getRoot(), false, true, true, false)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2692 } |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
12392
diff
changeset
|
2693 clazz.add(executeMethod); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2694 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2695 |
16781
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2696 private CodeTree createDeoptimizeUninitialized(NodeData node, CodeTreeBuilder parent) { |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2697 CodeTreeBuilder builder = parent.create(); |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2698 if (node.getGenericSpecialization().isReachable()) { |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2699 builder.startIf().string("!containsFallback").end().startBlock(); |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2700 builder.tree(createDeoptimize(builder)); |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2701 builder.end(); |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2702 } else { |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2703 builder.tree(createDeoptimize(builder)); |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2704 } |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2705 return builder.getRoot(); |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2706 } |
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2707 |
16821
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2708 private CodeTree createExecuteBody(CodeTreeBuilder parent, SpecializationData specialization, ExecutableTypeData execType, List<ExecutableTypeData> primaryExecutes) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2709 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2710 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2711 if (primaryExecutes.contains(execType) || primaryExecutes.isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2712 builder.tree(createFunctionalExecute(builder, specialization, execType)); |
11506
e6645c18d154
Truffle-DSL: reduced generated code size by not generating primarily unused primitive type execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
11445
diff
changeset
|
2713 } else if (needsCastingExecuteMethod(execType)) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2714 assert !primaryExecutes.isEmpty(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2715 builder.tree(createCastingExecute(builder, specialization, execType, primaryExecutes.get(0))); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2716 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2717 return null; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2718 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2719 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2720 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2721 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2722 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2723 private CodeExecutableElement createExecutableTypeOverride(ExecutableTypeData execType, boolean evaluated) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2724 CodeExecutableElement method = CodeExecutableElement.clone(getContext().getEnvironment(), execType.getMethod()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2725 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2726 method.getAnnotationMirrors().clear(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2727 for (VariableElement variable : method.getParameters()) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2728 variable.getAnnotationMirrors().clear(); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2729 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2730 |
13271
2b9fcffd6f36
Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents:
12637
diff
changeset
|
2731 CodeTreeBuilder builder = method.createBuilder(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2732 int i = 0; |
13271
2b9fcffd6f36
Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents:
12637
diff
changeset
|
2733 int signatureIndex = -1; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2734 for (VariableElement param : method.getParameters()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2735 CodeVariableElement var = CodeVariableElement.clone(param); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2736 Parameter actualParameter = i < execType.getParameters().size() ? execType.getParameters().get(i) : null; |
13271
2b9fcffd6f36
Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents:
12637
diff
changeset
|
2737 String name; |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2738 if (actualParameter != null) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2739 if (actualParameter.getSpecification().isSignature()) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2740 signatureIndex++; |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2741 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2742 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2743 if (evaluated && actualParameter.getSpecification().isSignature()) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2744 name = valueNameEvaluated(actualParameter); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2745 } else { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2746 name = valueName(actualParameter); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2747 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2748 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2749 int varArgCount = getModel().getSignatureSize() - signatureIndex; |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2750 if (evaluated && actualParameter.isTypeVarArgs()) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2751 Parameter baseVarArgs = actualParameter; |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2752 name = valueName(baseVarArgs) + "Args"; |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2753 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2754 builder.startAssert().string(name).string(" != null").end(); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2755 builder.startAssert().string(name).string(".length == ").string(String.valueOf(varArgCount)).end(); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2756 if (varArgCount > 0) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2757 List<Parameter> varArgsParameter = execType.getParameters().subList(i, execType.getParameters().size()); |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2758 for (Parameter varArg : varArgsParameter) { |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2759 if (varArgCount <= 0) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2760 break; |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2761 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2762 TypeMirror type = baseVarArgs.getType(); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2763 if (type.getKind() == TypeKind.ARRAY) { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2764 type = ((ArrayType) type).getComponentType(); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2765 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2766 builder.declaration(type, valueNameEvaluated(varArg), name + "[" + varArg.getTypeVarArgsIndex() + "]"); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2767 varArgCount--; |
13272
0b8335a4fb13
Truffle-DSL: more testing for generating execute methods with varargs.
Christian Humer <christian.humer@gmail.com>
parents:
13271
diff
changeset
|
2768 } |
13271
2b9fcffd6f36
Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents:
12637
diff
changeset
|
2769 } |
2b9fcffd6f36
Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents:
12637
diff
changeset
|
2770 } |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2771 } else { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
2772 name = "arg" + i; |
13271
2b9fcffd6f36
Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents:
12637
diff
changeset
|
2773 } |
2b9fcffd6f36
Truffle-DSL: added support for generating execute methods with java varargs.
Christian Humer <christian.humer@gmail.com>
parents:
12637
diff
changeset
|
2774 var.setName(name); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2775 method.getParameters().set(i, var); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2776 i++; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2777 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2778 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2779 method.getAnnotationMirrors().clear(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2780 method.getModifiers().remove(Modifier.ABSTRACT); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2781 return method; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2782 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2783 |
11506
e6645c18d154
Truffle-DSL: reduced generated code size by not generating primarily unused primitive type execute methods.
Christian Humer <christian.humer@gmail.com>
parents:
11445
diff
changeset
|
2784 private boolean needsCastingExecuteMethod(ExecutableTypeData execType) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2785 if (execType.isAbstract()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2786 return true; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2787 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2788 if (execType.getType().isGeneric()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2789 return true; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2790 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2791 return false; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2792 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2793 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2794 private List<ExecutableTypeData> findFunctionalExecutableType(SpecializationData specialization, int evaluatedCount) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2795 TypeData primaryType = specialization.getReturnType().getTypeSystemType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2796 List<ExecutableTypeData> otherTypes = specialization.getNode().getExecutableTypes(evaluatedCount); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2797 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2798 List<ExecutableTypeData> filteredTypes = new ArrayList<>(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2799 for (ExecutableTypeData compareType : otherTypes) { |
16821
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2800 if (ElementUtils.typeEquals(compareType.getType().getPrimitiveType(), primaryType.getPrimitiveType())) { |
224a89858453
Truffle-DSL: cache primary executes
Christian Humer <christian.humer@gmail.com>
parents:
16781
diff
changeset
|
2801 filteredTypes.add(compareType); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2802 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2803 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2804 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2805 // no direct matches found use generic where the type is Object |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2806 if (filteredTypes.isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2807 for (ExecutableTypeData compareType : otherTypes) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2808 if (compareType.getType().isGeneric() && !compareType.hasUnexpectedValue(getContext())) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2809 filteredTypes.add(compareType); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2810 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2811 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2812 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2813 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2814 if (filteredTypes.isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2815 for (ExecutableTypeData compareType : otherTypes) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2816 if (compareType.getType().isGeneric()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2817 filteredTypes.add(compareType); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2818 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2819 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2820 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2821 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2822 return filteredTypes; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2823 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2824 |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
2825 private CodeTree createFunctionalExecute(CodeTreeBuilder parent, final SpecializationData specialization, final ExecutableTypeData executable) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2826 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
16781
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2827 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2828 if (specialization.isUninitialized()) { |
16781
e2ebaf1e1b74
Truffle-DSL: fixed uninitialized triggered a deopt even if fallback was set to true.
Christian Humer <christian.humer@gmail.com>
parents:
16763
diff
changeset
|
2829 builder.tree(createDeoptimizeUninitialized(specialization.getNode(), builder)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2830 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2831 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11509
diff
changeset
|
2832 builder.tree(createExecuteChildren(builder, executable, specialization, specialization.getParameters(), null)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2833 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2834 CodeTree returnSpecialized = null; |
11186
4a9936bb03a4
Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11185
diff
changeset
|
2835 |
4a9936bb03a4
Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11185
diff
changeset
|
2836 if (specialization.findNextSpecialization() != null) { |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2837 CodeTreeBuilder returnBuilder = new CodeTreeBuilder(builder); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2838 returnBuilder.tree(createDeoptimize(builder)); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2839 returnBuilder.tree(createCallRewriteMonomorphic(builder, executable.hasUnexpectedValue(context), executable.getType(), specialization, null, |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2840 "One of guards " + specialization.getGuards() + " failed")); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2841 returnSpecialized = returnBuilder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2842 } |
11186
4a9936bb03a4
Truffle-DSL: Fixed executeAndSpecialize layout to always call specialization methods on the correct node. (GRAAL-379 #resolve)
Christian Humer <christian.humer@gmail.com>
parents:
11185
diff
changeset
|
2843 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2844 builder.tree(createExecuteTree(builder, specialization, SpecializationGroup.create(specialization), new CodeBlock<SpecializationData>() { |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
2845 |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
2846 public CodeTree create(CodeTreeBuilder b, SpecializationData current) { |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
2847 return createExecute(b, executable, specialization); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
2848 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2849 }, returnSpecialized, false, false, false, false)); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2850 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2851 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2852 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2853 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2854 private CodeTree createExecute(CodeTreeBuilder parent, ExecutableTypeData executable, SpecializationData specialization) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2855 NodeData node = specialization.getNode(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2856 CodeTreeBuilder builder = new CodeTreeBuilder(parent); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2857 if (!specialization.getExceptions().isEmpty() || !specialization.getAssumptions().isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2858 builder.startTryBlock(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2859 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2860 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2861 for (String assumption : specialization.getAssumptions()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2862 builder.startStatement(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2863 builder.string("this.").string(assumption).string(".check()"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2864 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2865 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2866 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2867 CodeTreeBuilder returnBuilder = new CodeTreeBuilder(parent); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2868 if (specialization.isPolymorphic()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2869 returnBuilder.startCall("next0", EXECUTE_CHAINED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
2870 addInternalValueParameterNames(returnBuilder, specialization, specialization, null, true, false, null); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2871 returnBuilder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2872 } else if (specialization.isUninitialized()) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2873 returnBuilder.startCall(EXECUTE_UNINITIALIZED); |
17260
222b60e248ba
Truffle-DSL: fixed regression with @SlowPath on specialize0.
Christian Humer <christian.humer@gmail.com>
parents:
17251
diff
changeset
|
2874 addInternalValueParameterNames(returnBuilder, specialization, specialization, null, true, false, null); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2875 returnBuilder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2876 } else if (specialization.getMethod() == null && !node.needsRewrites(context)) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2877 emitEncounteredSynthetic(builder, specialization); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2878 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2879 returnBuilder.tree(createTemplateMethodCall(returnBuilder, null, specialization, specialization, null)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2880 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2881 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2882 if (!returnBuilder.isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2883 TypeData targetType = node.getTypeSystem().findTypeData(builder.findMethod().getReturnType()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2884 TypeData sourceType = specialization.getReturnType().getTypeSystemType(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2885 |
10741
00a9dbcbe431
Truffle-DSL: Fixed a bug in polymorphic code generation.
Christian Humer <christian.humer@gmail.com>
parents:
10695
diff
changeset
|
2886 builder.startReturn(); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2887 if (targetType == null || sourceType == null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2888 builder.tree(returnBuilder.getRoot()); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2889 } else if (sourceType.needsCastTo(targetType)) { |
13536
419b3ea1bdd1
Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
2890 String castMethodName = TypeSystemCodeGenerator.expectTypeMethodName(targetType); |
419b3ea1bdd1
Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
2891 if (!executable.hasUnexpectedValue(context)) { |
419b3ea1bdd1
Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
2892 castMethodName = TypeSystemCodeGenerator.asTypeMethodName(targetType); |
419b3ea1bdd1
Truffle-DSL: removed try-catch hack for polymorphic invocations.
Christian Humer <christian.humer@gmail.com>
parents:
13535
diff
changeset
|
2893 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2894 builder.tree(createCallTypeSystemMethod(parent, node, castMethodName, returnBuilder.getRoot())); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2895 } else { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2896 builder.tree(returnBuilder.getRoot()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2897 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2898 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2899 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2900 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2901 if (!specialization.getExceptions().isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2902 for (SpecializationThrowsData exception : specialization.getExceptions()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2903 builder.end().startCatchBlock(exception.getJavaClass(), "ex"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2904 builder.tree(createDeoptimize(builder)); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2905 builder.tree(createCallRewriteMonomorphic(parent, executable.hasUnexpectedValue(context), executable.getType(), specialization, null, |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2906 "Thrown " + ElementUtils.getSimpleName(exception.getJavaClass()))); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2907 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2908 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2909 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2910 if (!specialization.getAssumptions().isEmpty()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2911 builder.end().startCatchBlock(getContext().getTruffleTypes().getInvalidAssumption(), "ex"); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2912 builder.tree(createCallRewriteMonomorphic(parent, executable.hasUnexpectedValue(context), executable.getType(), specialization, null, "Assumption failed")); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2913 builder.end(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2914 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2915 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2916 return builder.getRoot(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2917 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2918 |
15476
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2919 protected CodeExecutableElement createCopyConstructorFactoryMethod(TypeMirror baseType, SpecializationData specialization) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2920 List<Parameter> implicitTypeParams = getImplicitTypeParameters(specialization); |
15475
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2921 String baseName = "current"; |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2922 CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), specialization.getNode().getNodeType(), FACTORY_METHOD_NAME); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2923 method.addParameter(new CodeVariableElement(specialization.getNode().getNodeType(), baseName)); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2924 for (Parameter implicitTypeParam : implicitTypeParams) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2925 method.addParameter(new CodeVariableElement(getContext().getType(Class.class), implicitTypeName(implicitTypeParam))); |
15475
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2926 } |
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2927 CodeTreeBuilder builder = method.createBuilder(); |
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2928 builder.startReturn(); |
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2929 builder.startNew(getElement().asType()); |
15477
fd18fa50a8e0
TruffleDSL: NodeCodeGenerator: avoid referencing BaseNode class in factory
Andreas Woess <andreas.woess@jku.at>
parents:
15476
diff
changeset
|
2930 builder.startGroup().cast(baseType, CodeTreeBuilder.singleString(baseName)).end(); |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
2931 for (Parameter param : implicitTypeParams) { |
15475
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2932 builder.string(implicitTypeName(param)); |
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2933 } |
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2934 builder.end().end(); |
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2935 return method; |
42f4d703bf0b
TruffleDSL: NodeCodeGenerator: add copy constructor factory method
Andreas Woess <andreas.woess@jku.at>
parents:
15459
diff
changeset
|
2936 } |
15476
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2937 |
15477
fd18fa50a8e0
TruffleDSL: NodeCodeGenerator: avoid referencing BaseNode class in factory
Andreas Woess <andreas.woess@jku.at>
parents:
15476
diff
changeset
|
2938 protected CodeExecutableElement createConstructorFactoryMethod(SpecializationData specialization, ExecutableElement constructor) { |
15476
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2939 List<? extends VariableElement> parameters = constructor.getParameters(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
15479
diff
changeset
|
2940 CodeExecutableElement method = new CodeExecutableElement(modifiers(STATIC), specialization.getNode().getNodeType(), FACTORY_METHOD_NAME, |
15477
fd18fa50a8e0
TruffleDSL: NodeCodeGenerator: avoid referencing BaseNode class in factory
Andreas Woess <andreas.woess@jku.at>
parents:
15476
diff
changeset
|
2941 parameters.toArray(new CodeVariableElement[parameters.size()])); |
15476
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2942 CodeTreeBuilder builder = method.createBuilder(); |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2943 builder.startReturn(); |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2944 builder.startNew(getElement().asType()); |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2945 for (VariableElement param : parameters) { |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2946 builder.string(((CodeVariableElement) param).getName()); |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2947 } |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2948 builder.end().end(); |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2949 return method; |
97ee50d15882
TruffleDSL: NodeCodeGenerator: add constructor factory method for uninitialized/default node
Andreas Woess <andreas.woess@jku.at>
parents:
15475
diff
changeset
|
2950 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2951 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2952 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
2953 private interface CodeBlock<T> { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
2954 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
2955 CodeTree create(CodeTreeBuilder parent, T value); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
2956 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
11190
diff
changeset
|
2957 } |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2958 } |