Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/TypeSystemCodeGenerator.java @ 18788:714f4931b02c
Truffle-DSL: inline specialized node into gen node if single specializable.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 06 Jan 2015 00:43:09 +0100 |
parents | c0fb70634640 |
children | ae81dd154fb6 |
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; |
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
|
24 |
16759
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.*; |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
26 import static com.oracle.truffle.dsl.processor.generator.GeneratorUtils.*; |
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
|
27 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
|
28 |
79041ab43660
Truffle-DSL: 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 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
|
30 |
79041ab43660
Truffle-DSL: 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 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
33 import com.oracle.truffle.api.nodes.*; |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
34 import com.oracle.truffle.dsl.processor.*; |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
35 import com.oracle.truffle.dsl.processor.java.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
36 import com.oracle.truffle.dsl.processor.java.model.*; |
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
37 import com.oracle.truffle.dsl.processor.model.*; |
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
|
38 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
39 public class TypeSystemCodeGenerator extends CodeTypeElementFactory<TypeSystemData> { |
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
|
40 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
41 public static CodeTree cast(TypeData type, String content) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
42 return cast(type, CodeTreeBuilder.singleString(content)); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
43 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
44 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
45 public static CodeTree implicitType(TypeData type, CodeTree value) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
46 if (type.isGeneric()) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
47 return value; |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
48 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
49 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
50 TypeSystemData typeSystem = type.getTypeSystem(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
51 builder.startStaticCall(createTypeSystemGen(typeSystem), getImplicitClass(type)).tree(value); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
52 builder.end(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
53 return builder.build(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
54 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
55 |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
56 public static CodeTree invokeImplicitCast(ImplicitCastData cast, CodeTree expression) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
57 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
58 TypeSystemData typeSystem = cast.getTargetType().getTypeSystem(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
59 builder.startStaticCall(createTypeSystemGen(typeSystem), cast.getMethodName()).tree(expression); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
60 builder.end(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
61 return builder.build(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
62 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
63 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
64 public static CodeTree implicitCheck(TypeData type, CodeTree value, String typeHint) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
65 if (type.isGeneric()) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
66 return value; |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
67 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
68 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
69 TypeSystemData typeSystem = type.getTypeSystem(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
70 builder.startStaticCall(createTypeSystemGen(typeSystem), isImplicitTypeMethodName(type)).tree(value); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
71 if (typeHint != null) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
72 builder.string(typeHint); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
73 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
74 builder.end(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
75 return builder.build(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
76 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
77 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
78 public static CodeTree implicitExpect(TypeData type, CodeTree value, String typeHint) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
79 if (type.isGeneric()) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
80 return value; |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
81 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
82 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
83 TypeSystemData typeSystem = type.getTypeSystem(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
84 builder.startStaticCall(createTypeSystemGen(typeSystem), expectImplicitTypeMethodName(type)).tree(value); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
85 if (typeHint != null) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
86 builder.string(typeHint); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
87 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
88 builder.end(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
89 return builder.build(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
90 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
91 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
92 public static CodeTree implicitCast(TypeData type, CodeTree value, String typeHint) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
93 if (type.isGeneric()) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
94 return value; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
95 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
96 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
97 TypeSystemData typeSystem = type.getTypeSystem(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
98 builder.startStaticCall(createTypeSystemGen(typeSystem), asImplicitTypeMethodName(type)).tree(value); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
99 if (typeHint != null) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
100 builder.string(typeHint); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
101 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
102 builder.end(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
103 return builder.build(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
104 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
105 |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
106 public static CodeTree cast(TypeData type, CodeTree content) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
107 if (type.isGeneric()) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
108 return content; |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
109 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
110 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
111 TypeSystemData typeSystem = type.getTypeSystem(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
112 |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
113 if (type.isDefaultCast()) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
114 builder.cast(type.getPrimitiveType(), content); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
115 } else { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
116 builder.startStaticCall(typeSystem.getTemplateType().asType(), type.getTypeCasts().get(0).getMethodName()).tree(content).end(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
117 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
118 return builder.build(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
119 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
120 |
18776
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
121 public static CodeTree cast(TypeData sourceType, TypeData targetType, CodeTree content) { |
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
122 if (sourceType != null && !sourceType.needsCastTo(targetType)) { |
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
123 return content; |
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
124 } else { |
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
125 return cast(targetType, content); |
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
126 } |
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
127 } |
c0fb70634640
Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents:
18761
diff
changeset
|
128 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
129 public static CodeTree expect(TypeData type, CodeTree content) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
130 if (type.isGeneric() || type.isVoid()) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
131 return content; |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
132 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
133 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
134 TypeSystemData typeSystem = type.getTypeSystem(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
135 builder.startStaticCall(createTypeSystemGen(typeSystem), expectTypeMethodName(type)).tree(content).end(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
136 return builder.build(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
137 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
138 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
139 public static CodeTree expect(TypeData sourceType, TypeData targetType, CodeTree content) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
140 if (sourceType != null && !sourceType.needsCastTo(targetType)) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
141 return content; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
142 } else { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
143 return expect(targetType, content); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
144 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
145 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
146 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
147 public static CodeTypeMirror createTypeSystemGen(TypeSystemData typeSystem) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
148 return new GeneratedTypeMirror(ElementUtils.getPackageName(typeSystem.getTemplateType()), typeName(typeSystem)); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
149 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
150 |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
151 public static CodeTree check(TypeData type, String content) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
152 return check(type, CodeTreeBuilder.singleString(content)); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
153 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
154 |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
155 public static CodeTree check(TypeData type, CodeTree content) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
156 if (type.isGeneric()) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
157 return content; |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
158 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
159 CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
160 TypeSystemData typeSystem = type.getTypeSystem(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
161 |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
162 if (type.isDefaultCheck()) { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
163 builder.instanceOf(content, type.getBoxedType()); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
164 } else { |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
165 builder.startStaticCall(typeSystem.getTemplateType().asType(), type.getTypeChecks().get(0).getMethodName()).tree(content).end(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
166 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
167 return builder.build(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
168 } |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
169 |
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 public static String isTypeMethodName(TypeData type) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
171 return "is" + ElementUtils.getTypeId(type.getBoxedType()); |
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
|
172 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
173 |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
16820
diff
changeset
|
174 static String isImplicitTypeMethodName(TypeData type) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
175 return "isImplicit" + ElementUtils.getTypeId(type.getBoxedType()); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
176 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
177 |
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
|
178 public static String asTypeMethodName(TypeData type) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
179 return "as" + ElementUtils.getTypeId(type.getBoxedType()); |
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
|
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 |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
16820
diff
changeset
|
182 static String asImplicitTypeMethodName(TypeData type) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
183 return "asImplicit" + ElementUtils.getTypeId(type.getBoxedType()); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
184 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
185 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
186 static String expectImplicitTypeMethodName(TypeData type) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
187 return "expectImplicit" + ElementUtils.getTypeId(type.getBoxedType()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
188 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
189 |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
16820
diff
changeset
|
190 static String getImplicitClass(TypeData type) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
191 return "getImplicit" + ElementUtils.getTypeId(type.getBoxedType()) + "Class"; |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
192 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
193 |
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
|
194 public static String expectTypeMethodName(TypeData type) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16755
diff
changeset
|
195 return "expect" + ElementUtils.getTypeId(type.getBoxedType()); |
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
|
196 } |
79041ab43660
Truffle-DSL: 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 |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
16820
diff
changeset
|
198 static String typeName(TypeSystemData typeSystem) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
199 String name = getSimpleName(typeSystem.getTemplateType()); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
200 return name + "Gen"; |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
201 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
202 |
18752
1acaa69ff61b
Truffle-DSL: refactor generator classes
Christian Humer <christian.humer@gmail.com>
parents:
16820
diff
changeset
|
203 static String singletonName(TypeSystemData type) { |
16755
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
204 return createConstantName(getSimpleName(type.getTemplateType().asType())); |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
205 } |
bd28da642eea
Truffle-DSL: Several new features implemented:
Christian Humer <christian.humer@gmail.com>
parents:
13275
diff
changeset
|
206 |
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
|
207 @Override |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
208 public CodeTypeElement create(ProcessorContext context, TypeSystemData typeSystem) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
209 CodeTypeElement clazz = new TypeClassFactory(context, typeSystem).create(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
210 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
211 if (typeSystem.getOptions().useNewLayout()) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
212 clazz.add(new TypeSystemNodeFactory(context, typeSystem).create()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
213 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
214 if (typeSystem.getOptions().implicitCastOptimization().isMergeCasts()) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
215 for (TypeData type : typeSystem.getTypes()) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
216 List<TypeData> sourceTypes = typeSystem.lookupSourceTypes(type); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
217 if (sourceTypes.size() > 1) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
218 clazz.add(new ImplicitCastNodeFactory(context, type).create()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
219 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
220 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
221 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
222 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
223 return clazz; |
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
|
224 } |
79041ab43660
Truffle-DSL: 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 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
226 private static class TypeClassFactory { |
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
|
227 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
228 private static final String LOCAL_VALUE = "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
|
229 |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
230 private final ProcessorContext context; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
231 private final TypeSystemData typeSystem; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
232 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
233 public TypeClassFactory(ProcessorContext context, TypeSystemData typeSystem) { |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
234 this.context = context; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
235 this.typeSystem = typeSystem; |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
236 } |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
237 |
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
238 public CodeTypeElement create() { |
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
|
239 String name = typeName(typeSystem); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
240 CodeTypeElement clazz = GeneratorUtils.createClass(typeSystem, null, modifiers(PUBLIC, FINAL), name, typeSystem.getTemplateType().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
|
241 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
242 clazz.add(GeneratorUtils.createConstructorUsingFields(modifiers(PROTECTED), clazz)); |
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 CodeVariableElement singleton = createSingleton(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
|
244 clazz.add(singleton); |
79041ab43660
Truffle-DSL: 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 for (TypeData type : typeSystem.getTypes()) { |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
247 if (type.isVoid() || type.isGeneric()) { |
16820
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
248 continue; |
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
249 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
250 |
16820
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
251 clazz.addOptional(createIsTypeMethod(type)); |
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
252 clazz.addOptional(createAsTypeMethod(type)); |
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
|
253 |
16820
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
254 for (TypeData sourceType : collectExpectSourceTypes(type)) { |
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
255 clazz.addOptional(createExpectTypeMethod(type, sourceType)); |
0370880ac9ce
Truffle-DSL: better caching for type checks.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
256 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
257 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
258 if (type.hasImplicitSourceTypes()) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
259 clazz.add(createAsImplicitTypeMethod(type, false)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
260 if (typeSystem.getOptions().implicitCastOptimization().isNone()) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
261 clazz.add(createExpectImplicitTypeMethod(type, false)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
262 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
263 clazz.add(createIsImplicitTypeMethod(type, false)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
264 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
265 if (typeSystem.getOptions().implicitCastOptimization().isDuplicateTail()) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
266 clazz.add(createAsImplicitTypeMethod(type, true)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
267 clazz.add(createExpectImplicitTypeMethod(type, true)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
268 clazz.add(createIsImplicitTypeMethod(type, true)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
269 clazz.add(createGetImplicitClass(type)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
270 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
271 } |
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
|
272 } |
79041ab43660
Truffle-DSL: 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 |
79041ab43660
Truffle-DSL: 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 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
|
275 } |
79041ab43660
Truffle-DSL: 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 |
79041ab43660
Truffle-DSL: 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 private static List<TypeData> collectExpectSourceTypes(TypeData 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
|
278 Set<TypeData> sourceTypes = new HashSet<>(); |
79041ab43660
Truffle-DSL: 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 sourceTypes.add(type.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
|
280 for (TypeCastData cast : type.getTypeCasts()) { |
79041ab43660
Truffle-DSL: 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 sourceTypes.add(cast.getSourceType()); |
79041ab43660
Truffle-DSL: 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 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
283 for (TypeCheckData cast : type.getTypeChecks()) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
284 sourceTypes.add(cast.getCheckedType()); |
79041ab43660
Truffle-DSL: 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 } |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
286 sourceTypes.remove(type); |
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
|
287 return new ArrayList<>(sourceTypes); |
79041ab43660
Truffle-DSL: 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 } |
79041ab43660
Truffle-DSL: 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 |
79041ab43660
Truffle-DSL: 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 private CodeVariableElement createSingleton(CodeTypeElement clazz) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
291 CodeVariableElement field = new CodeVariableElement(modifiers(PUBLIC, STATIC, FINAL), clazz.asType(), 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
|
292 field.createInitBuilder().startNew(clazz.asType()).end(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
293 |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
294 CodeAnnotationMirror annotationMirror = new CodeAnnotationMirror((DeclaredType) context.getType(Deprecated.class)); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
295 field.getAnnotationMirrors().add(annotationMirror); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
296 |
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
|
297 return field; |
79041ab43660
Truffle-DSL: 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 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
299 |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
300 private CodeExecutableElement createIsImplicitTypeMethod(TypeData type, boolean typed) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
301 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), context.getType(boolean.class), TypeSystemCodeGenerator.isImplicitTypeMethodName(type)); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
302 method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
303 if (typed) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
304 method.addParameter(new CodeVariableElement(context.getType(Class.class), "typeHint")); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
305 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
306 CodeTreeBuilder builder = method.createBuilder(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
307 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
308 List<TypeData> sourceTypes = typeSystem.lookupSourceTypes(type); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
309 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
310 builder.startReturn(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
311 String sep = ""; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
312 for (TypeData sourceType : sourceTypes) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
313 builder.string(sep); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
314 if (typed) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
315 builder.string("(typeHint == ").typeLiteral(sourceType.getPrimitiveType()).string(" && "); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
316 } |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
317 builder.tree(check(sourceType, LOCAL_VALUE)); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
318 if (typed) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
319 builder.string(")"); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
320 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
321 if (sourceTypes.lastIndexOf(sourceType) != sourceTypes.size() - 1) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
322 builder.newLine(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
323 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
324 if (sep.equals("")) { |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
325 builder.startIndention(); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
326 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
327 sep = " || "; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
328 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
329 builder.end(); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
330 builder.end(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
331 return method; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
332 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
333 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
334 private CodeExecutableElement createAsImplicitTypeMethod(TypeData type, boolean useTypeHint) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
335 String name = asImplicitTypeMethodName(type); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
336 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), type.getPrimitiveType(), name); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
337 method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
338 if (useTypeHint) { |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
339 method.addParameter(new CodeVariableElement(context.getType(Class.class), "typeHint")); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
340 } |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
341 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
342 List<TypeData> sourceTypes = typeSystem.lookupSourceTypes(type); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
343 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
344 CodeTreeBuilder builder = method.createBuilder(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
345 boolean elseIf = false; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
346 for (TypeData sourceType : sourceTypes) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
347 elseIf = builder.startIf(elseIf); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
348 if (useTypeHint) { |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
349 builder.string("typeHint == ").typeLiteral(sourceType.getPrimitiveType()); |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
350 } else { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
351 builder.tree(check(sourceType, LOCAL_VALUE)); |
12395
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
352 } |
8e8347ecabbc
Truffle-DSL: implemented new polymorphic more compact generation strategy
Christian Humer <christian.humer@gmail.com>
parents:
11545
diff
changeset
|
353 |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
354 builder.end().startBlock(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
355 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
356 builder.startReturn(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
357 ImplicitCastData cast = typeSystem.lookupCast(sourceType, type); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
358 if (cast != null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
359 builder.startCall(cast.getMethodName()); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
360 } |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
361 builder.tree(cast(sourceType, LOCAL_VALUE)).end(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
362 if (cast != null) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
363 builder.end(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
364 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
365 builder.end(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
366 builder.end(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
367 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
368 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
369 builder.startElseBlock(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
370 builder.tree(createTransferToInterpreterAndInvalidate()); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
371 builder.startThrow().startNew(context.getType(IllegalArgumentException.class)).doubleQuote("Illegal type ").end().end(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
372 builder.end(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
373 return method; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
374 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
375 |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
376 private CodeExecutableElement createExpectImplicitTypeMethod(TypeData type, boolean useTypeHint) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
377 String name = expectImplicitTypeMethodName(type); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
378 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), type.getPrimitiveType(), name); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
379 method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
380 if (useTypeHint) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
381 method.addParameter(new CodeVariableElement(context.getType(Class.class), "typeHint")); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
382 } |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
383 method.getThrownTypes().add(context.getType(UnexpectedResultException.class)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
384 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
385 List<TypeData> sourceTypes = typeSystem.lookupSourceTypes(type); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
386 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
387 CodeTreeBuilder builder = method.createBuilder(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
388 boolean elseIf = false; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
389 for (TypeData sourceType : sourceTypes) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
390 elseIf = builder.startIf(elseIf); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
391 if (useTypeHint) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
392 builder.string("typeHint == ").typeLiteral(sourceType.getPrimitiveType()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
393 builder.string(" && "); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
394 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
395 builder.tree(check(sourceType, LOCAL_VALUE)); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
396 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
397 builder.end().startBlock(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
398 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
399 builder.startReturn(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
400 ImplicitCastData cast = typeSystem.lookupCast(sourceType, type); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
401 if (cast != null) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
402 builder.startCall(cast.getMethodName()); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
403 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
404 builder.tree(cast(sourceType, LOCAL_VALUE)).end(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
405 if (cast != null) { |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
406 builder.end(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
407 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
408 builder.end(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
409 builder.end(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
410 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
411 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
412 builder.startElseBlock(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
413 builder.startThrow().startNew(context.getType(UnexpectedResultException.class)).string(LOCAL_VALUE).end().end(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
414 builder.end(); |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
415 return method; |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
416 } |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
417 |
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
418 private CodeExecutableElement createGetImplicitClass(TypeData type) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
419 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), context.getType(Class.class), TypeSystemCodeGenerator.getImplicitClass(type)); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
420 method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
421 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
422 List<TypeData> sourceTypes = typeSystem.lookupSourceTypes(type); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
423 CodeTreeBuilder builder = method.createBuilder(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
424 boolean elseIf = false; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
425 for (TypeData sourceType : sourceTypes) { |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
426 elseIf = builder.startIf(elseIf); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
427 builder.tree(check(sourceType, LOCAL_VALUE)).end(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
428 builder.end().startBlock(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
429 builder.startReturn().typeLiteral(sourceType.getPrimitiveType()).end(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
430 builder.end(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
431 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
432 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
433 builder.startElseBlock(); |
18761
a665483c3881
Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
18758
diff
changeset
|
434 builder.tree(createTransferToInterpreterAndInvalidate()); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
435 builder.startThrow().startNew(context.getType(IllegalArgumentException.class)).doubleQuote("Illegal type ").end().end(); |
11545
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
436 builder.end(); |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
437 |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
438 return method; |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
439 } |
2fb276f5e3e9
Truffle-DSL: implemented implicit casts.
Christian Humer <christian.humer@gmail.com>
parents:
11184
diff
changeset
|
440 |
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
|
441 private CodeExecutableElement createIsTypeMethod(TypeData 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
|
442 if (!type.getTypeChecks().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
|
443 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
|
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 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
446 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), context.getType(boolean.class), TypeSystemCodeGenerator.isTypeMethodName(type)); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
447 method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_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
|
448 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
449 CodeTreeBuilder body = method.createBuilder(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
450 body.startReturn().tree(check(type, LOCAL_VALUE)).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
|
451 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
452 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
|
453 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
454 |
79041ab43660
Truffle-DSL: 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 private CodeExecutableElement createAsTypeMethod(TypeData 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
|
456 if (!type.getTypeCasts().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
|
457 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
|
458 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
459 |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
460 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), type.getPrimitiveType(), TypeSystemCodeGenerator.asTypeMethodName(type)); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
461 method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_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
|
462 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
463 CodeTreeBuilder body = method.createBuilder(); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
464 String assertMessage = typeName(typeSystem) + "." + asTypeMethodName(type) + ": " + ElementUtils.getSimpleName(type.getBoxedType()) + " expected"; |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
465 body.startAssert().tree(check(type, LOCAL_VALUE)).string(" : ").doubleQuote(assertMessage).end(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
466 body.startReturn().tree(cast(type, LOCAL_VALUE)).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
|
467 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
468 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
|
469 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
470 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
471 private CodeExecutableElement createExpectTypeMethod(TypeData expectedType, TypeData sourceType) { |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
472 CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), expectedType.getPrimitiveType(), TypeSystemCodeGenerator.expectTypeMethodName(expectedType)); |
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
|
473 method.addParameter(new CodeVariableElement(sourceType.getPrimitiveType(), LOCAL_VALUE)); |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
474 method.addThrownType(context.getTruffleTypes().getUnexpectedValueException()); |
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
|
475 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
476 CodeTreeBuilder body = method.createBuilder(); |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
477 body.startIf().tree(check(expectedType, LOCAL_VALUE)).end().startBlock(); |
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
478 body.startReturn().tree(cast(expectedType, LOCAL_VALUE)).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
|
479 body.end(); // if-block |
18753
f6b8787dc113
Truffle-DSL: replace complex factory system with a much simpler version
Christian Humer <christian.humer@gmail.com>
parents:
18752
diff
changeset
|
480 body.startThrow().startNew(context.getTruffleTypes().getUnexpectedValueException()).string(LOCAL_VALUE).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
|
481 |
79041ab43660
Truffle-DSL: 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 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
|
483 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
484 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
485 } |
18758
3912400fc33a
Truffle-DSL: remove type system singleton
Christian Humer <christian.humer@gmail.com>
parents:
18753
diff
changeset
|
486 |
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
|
487 } |