Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/SpecializationGroup.java @ 19283:08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 23 Jan 2015 02:55:23 +0100 |
parents | ae81dd154fb6 |
children | 62c43fcf5be2 |
rev | line source |
---|---|
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
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.parser; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import java.util.*; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
27 import com.oracle.truffle.dsl.processor.generator.*; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
28 import com.oracle.truffle.dsl.processor.model.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
29 import com.oracle.truffle.dsl.processor.model.TemplateMethod.TypeSignature; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 /** |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 * Class creates groups of specializations to optimize the layout of generated executeAndSpecialize |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 * and generic execute methods. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 */ |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 public final class SpecializationGroup { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 private final List<String> assumptions; |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
38 private final List<TypeGuard> typeGuards; |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
39 private final List<GuardExpression> guards; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
41 private final NodeData node; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 private final SpecializationData specialization; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 private final List<SpecializationGroup> children = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 private SpecializationGroup parent; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 private SpecializationGroup(SpecializationData data) { |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
48 this.node = data.getNode(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 this.assumptions = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 this.typeGuards = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 this.guards = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 this.specialization = data; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 this.assumptions.addAll(data.getAssumptions()); |
13527
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
12401
diff
changeset
|
55 TypeSignature sig = data.getTypeSignature(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 for (int i = 1; i < sig.size(); i++) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
57 typeGuards.add(new TypeGuard(sig.get(i), i - 1)); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 this.guards.addAll(data.getGuards()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
61 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
62 public SpecializationGroup(List<SpecializationGroup> children, List<String> assumptionMatches, List<TypeGuard> typeGuardsMatches, List<GuardExpression> guardMatches) { |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
63 assert !children.isEmpty() : "children must not be empty"; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 this.assumptions = assumptionMatches; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 this.typeGuards = typeGuardsMatches; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 this.guards = guardMatches; |
11471
5d72a3f5a31d
Truffle-DSL: fixed a bug in else connections for specialization grouping.
Christian Humer <christian.humer@gmail.com>
parents:
11443
diff
changeset
|
67 this.node = children.get(0).node; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 this.specialization = null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 updateChildren(children); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
72 public List<TypeGuard> getAllGuards() { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
73 List<TypeGuard> collectedGuards = new ArrayList<>(); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
74 collectedGuards.addAll(typeGuards); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
75 if (parent != null) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
76 collectedGuards.addAll(parent.getAllGuards()); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
77 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
78 return collectedGuards; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
79 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
80 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
81 public List<GuardExpression> findElseConnectableGuards() { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
82 if (!getTypeGuards().isEmpty() || !getAssumptions().isEmpty()) { |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
83 return Collections.emptyList(); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
84 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
85 |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
86 if (getGuards().isEmpty()) { |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
87 return Collections.emptyList(); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
88 } |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
89 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
90 List<GuardExpression> elseConnectableGuards = new ArrayList<>(); |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
91 int guardIndex = 0; |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
92 while (guardIndex < getGuards().size() && findNegatedGuardInPrevious(getGuards().get(guardIndex)) != null) { |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
93 elseConnectableGuards.add(getGuards().get(guardIndex)); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
94 guardIndex++; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
95 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
96 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
97 return elseConnectableGuards; |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
98 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
99 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
100 private GuardExpression findNegatedGuardInPrevious(GuardExpression guard) { |
11481
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
101 SpecializationGroup previous = this.getPreviousGroup(); |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
102 if (previous == null) { |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
103 return null; |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
104 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
105 List<GuardExpression> elseConnectedGuards = previous.findElseConnectableGuards(); |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
106 |
11481
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
107 if (previous == null || previous.getGuards().size() != elseConnectedGuards.size() + 1) { |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
108 return null; |
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
109 } |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
110 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
111 if (previous.mayBeExcluded()) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
112 return null; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
113 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
114 |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
115 /* Guard is else branch can be connected in previous specialization. */ |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
116 if (elseConnectedGuards.contains(guard)) { |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
117 return guard; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
118 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11481
diff
changeset
|
119 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
120 GuardExpression previousGuard = previous.getGuards().get(elseConnectedGuards.size()); |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
121 if (guard.equalsNegated(previousGuard)) { |
11481
a317acdd5f2c
Truffle-DSL: fixed a bug in else connections of generic generated methods.
Christian Humer <christian.humer@gmail.com>
parents:
11471
diff
changeset
|
122 return guard; |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
123 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
124 return null; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
125 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
126 |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
127 private boolean mayBeExcluded() { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
128 if (specialization != null) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
129 return NodeGenFactory.mayBeExcluded(specialization); |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
130 } else { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
131 for (SpecializationGroup group : getChildren()) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
132 if (group.mayBeExcluded()) { |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
133 return true; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
134 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
135 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
136 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
137 return false; |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
138 } |
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
139 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 private void updateChildren(List<SpecializationGroup> childs) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 if (!children.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 children.clear(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
143 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
144 this.children.addAll(childs); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
145 for (SpecializationGroup child : childs) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
146 child.parent = this; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
147 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
148 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
149 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
150 public SpecializationGroup getParent() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
151 return parent; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
152 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
153 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
154 public List<String> getAssumptions() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
155 return assumptions; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
156 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
157 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
158 public List<TypeGuard> getTypeGuards() { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
159 return typeGuards; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
160 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
161 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
162 public List<GuardExpression> getGuards() { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
163 return guards; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
164 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
165 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
166 public List<SpecializationGroup> getChildren() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
167 return children; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
168 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
169 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
170 public SpecializationData getSpecialization() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
171 return specialization; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
172 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
173 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
174 private static SpecializationGroup combine(List<SpecializationGroup> groups) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
175 if (groups.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
176 throw new IllegalArgumentException("empty combinations"); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
177 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
178 if (groups.size() == 1) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
179 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
180 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
181 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
182 List<String> assumptionMatches = new ArrayList<>(); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
183 List<TypeGuard> typeGuardsMatches = new ArrayList<>(); |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
184 List<GuardExpression> guardMatches = new ArrayList<>(); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
185 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
186 SpecializationGroup first = groups.get(0); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
187 List<SpecializationGroup> others = groups.subList(1, groups.size()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
188 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
189 outer: for (String assumption : first.assumptions) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
190 for (SpecializationGroup other : others) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
191 if (!other.assumptions.contains(assumption)) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
192 // assumptions can be combined unordered |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
193 continue outer; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
194 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
195 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
196 assumptionMatches.add(assumption); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
197 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
198 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
199 outer: for (TypeGuard typeGuard : first.typeGuards) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
200 for (SpecializationGroup other : others) { |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
201 if (!other.typeGuards.contains(typeGuard)) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
202 // type guards can be combined unordered |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
203 continue outer; |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
204 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
205 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
206 typeGuardsMatches.add(typeGuard); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
207 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
208 |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
209 outer: for (GuardExpression guard : first.guards) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
210 for (SpecializationGroup other : others) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
211 if (!other.guards.contains(guard)) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
212 // we must break here. One guard may depend on the other. |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
213 break outer; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
214 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
215 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
216 guardMatches.add(guard); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
217 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
218 |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
219 // check for guards for required type casts |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
220 for (Iterator<GuardExpression> iterator = guardMatches.iterator(); iterator.hasNext();) { |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
221 GuardExpression guardMatch = iterator.next(); |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
222 if (!guardMatch.getExpression().findBoundVariables().isEmpty()) { |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
223 iterator.remove(); |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
224 } |
19283
08aa0372dad4
Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents:
19282
diff
changeset
|
225 // TODO we need to be smarter here with bound parameters. |
11442
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
226 } |
2868b55001d4
Truffle-DSL: fixed specializationg grouping failed with guards using base types.
Christian Humer <christian.humer@gmail.com>
parents:
11201
diff
changeset
|
227 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
228 if (assumptionMatches.isEmpty() && typeGuardsMatches.isEmpty() && guardMatches.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
229 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
230 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
231 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
232 for (SpecializationGroup group : groups) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
233 group.assumptions.removeAll(assumptionMatches); |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
234 group.typeGuards.removeAll(typeGuardsMatches); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
235 group.guards.removeAll(guardMatches); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
236 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
237 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
238 List<SpecializationGroup> newChildren = new ArrayList<>(groups); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
239 return new SpecializationGroup(newChildren, assumptionMatches, typeGuardsMatches, guardMatches); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
240 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
241 |
11443
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
242 public static SpecializationGroup create(SpecializationData specialization) { |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
243 return new SpecializationGroup(specialization); |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
244 } |
b33783cbd8ce
Truffle-DSL: refactored redundant guard generation code.
Christian Humer <christian.humer@gmail.com>
parents:
11442
diff
changeset
|
245 |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
246 public static SpecializationGroup create(List<SpecializationData> specializations) { |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
247 List<SpecializationGroup> groups = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
248 for (SpecializationData specialization : specializations) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
249 groups.add(new SpecializationGroup(specialization)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
250 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
251 return new SpecializationGroup(createCombinationalGroups(groups), Collections.<String> emptyList(), Collections.<TypeGuard> emptyList(), Collections.<GuardExpression> emptyList()); |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
252 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
253 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
254 @Override |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
255 public String toString() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
256 return "SpecializationGroup [assumptions=" + assumptions + ", typeGuards=" + typeGuards + ", guards=" + guards + "]"; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
257 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
258 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
259 private static List<SpecializationGroup> createCombinationalGroups(List<SpecializationGroup> groups) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
260 if (groups.size() <= 1) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
261 return groups; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
262 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
263 List<SpecializationGroup> newGroups = new ArrayList<>(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
264 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
265 int i = 0; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
266 for (i = 0; i < groups.size();) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
267 SpecializationGroup combined = null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
268 for (int j = groups.size(); j > i + 1; j--) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
269 combined = combine(groups.subList(i, j)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
270 if (combined != null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
271 break; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
272 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
273 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
274 SpecializationGroup newGroup; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
275 if (combined == null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
276 newGroup = groups.get(i); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
277 i++; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
278 } else { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
279 newGroup = combined; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
280 List<SpecializationGroup> originalGroups = new ArrayList<>(combined.children); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
281 combined.updateChildren(createCombinationalGroups(originalGroups)); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
282 i += originalGroups.size(); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
283 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
284 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
285 newGroups.add(newGroup); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
286 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
287 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
288 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
289 return newGroups; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
290 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
291 |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
292 public SpecializationGroup getPreviousGroup() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
293 if (parent == null || parent.children.isEmpty()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
294 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
295 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
296 int index = parent.children.indexOf(this); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
297 if (index <= 0) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
298 return null; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
299 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
300 return parent.children.get(index - 1); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
301 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
302 |
12401
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
303 public int getUncheckedSpecializationIndex() { |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
304 int groupMaxIndex = getMaxSpecializationIndex(); |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
305 |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
306 int genericIndex = node.getSpecializations().indexOf(node.getGenericSpecialization()); |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
307 if (groupMaxIndex >= genericIndex) { |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
308 // no minimum state check for an generic index |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
309 groupMaxIndex = -1; |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
310 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
311 |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
312 if (groupMaxIndex > -1) { |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
313 // no minimum state check if already checked by parent group |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
314 int parentMaxIndex = -1; |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
315 if (getParent() != null) { |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
316 parentMaxIndex = getParent().getMaxSpecializationIndex(); |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
317 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
318 if (groupMaxIndex == parentMaxIndex) { |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
319 groupMaxIndex = -1; |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
320 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
321 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
322 return groupMaxIndex; |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
323 } |
85dcc7f59c34
Truffle-DSL: fixed incorrect else guard connections for executeAndSpecialize.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
324 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
325 public int getMaxSpecializationIndex() { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
326 if (specialization != null) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
327 return specialization.getNode().getSpecializations().indexOf(specialization); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
328 } else { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
329 int max = Integer.MIN_VALUE; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
330 for (SpecializationGroup childGroup : getChildren()) { |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
331 max = Math.max(max, childGroup.getMaxSpecializationIndex()); |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
332 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
333 return max; |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
334 } |
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
335 } |
11201
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
336 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
337 public static final class TypeGuard { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
338 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
339 private final int signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
340 private final TypeData type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
341 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
342 public TypeGuard(TypeData type, int signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
343 this.type = type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
344 this.signatureIndex = signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
345 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
346 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
347 @Override |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
348 public int hashCode() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
349 final int prime = 31; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
350 int result = 1; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
351 result = prime * result + signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
352 result = prime * result + type.hashCode(); |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
353 return result; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
354 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
355 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
356 @Override |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
357 public boolean equals(Object obj) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
358 if (this == obj) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
359 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
360 } else if (obj == null) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
361 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
362 } else if (getClass() != obj.getClass()) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
363 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
364 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
365 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
366 TypeGuard other = (TypeGuard) obj; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
367 if (signatureIndex != other.signatureIndex) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
368 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
369 } else if (!type.equals(other.type)) { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
370 return false; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
371 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
372 return true; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
373 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
374 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
375 public int getSignatureIndex() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
376 return signatureIndex; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
377 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
378 |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
379 public TypeData getType() { |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
380 return type; |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
381 } |
7fc3e1fb3965
Truffle-DSL: specialization group fixes.
Christian Humer <christian.humer@gmail.com>
parents:
11195
diff
changeset
|
382 } |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13527
diff
changeset
|
383 |
11195
4f52b08bd2f9
Truffle-DSL: Implemented specialization grouping for generic cases.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
384 } |