Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/GuardsTest.java @ 16748:10ee18bf7e1a
Truffle: -G:+TraceTruffleCompilationPolymorphism now prints the compact tree of the polymorphic node.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:53:04 +0200 |
parents | 5a0c694ef735 |
children |
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 */ |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.dsl.test; |
79041ab43660
Truffle-DSL: 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 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import static org.junit.Assert.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import org.junit.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.api.dsl.*; |
79041ab43660
Truffle-DSL: 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 com.oracle.truffle.api.dsl.test.GuardsTestFactory.GlobalFlagGuardFactory; |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
32 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.GuardWithBaseClassFactory; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
33 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.GuardWithBaseInterfaceFactory; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
34 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.GuardWithBoxedPrimitiveFactory; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
35 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.GuardWithObjectFactory; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.InvocationGuardFactory; |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
37 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.TestAbstractGuard1Factory; |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
38 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.TestGuardResolve1Factory; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
39 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.TestGuardResolve2Factory; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
40 import com.oracle.truffle.api.dsl.test.GuardsTestFactory.TestGuardResolve3Factory; |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
41 import com.oracle.truffle.api.dsl.test.TypeSystemTest.Abstract; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
42 import com.oracle.truffle.api.dsl.test.TypeSystemTest.BExtendsAbstract; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
43 import com.oracle.truffle.api.dsl.test.TypeSystemTest.CExtendsAbstract; |
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
|
44 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
47 @SuppressWarnings("unused") |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 public class GuardsTest { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 private static final Object NULL = new Object(); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 @Test |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 public void testGuardInvocations() { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 TestRootNode<InvocationGuard> root = createRoot(InvocationGuardFactory.getInstance()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 assertEquals(Integer.MAX_VALUE, executeWith(root, Integer.MAX_VALUE - 1, 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
|
57 assertEquals(1, InvocationGuard.specializedInvocations); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
58 assertEquals(0, InvocationGuard.genericInvocations); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
59 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
60 assertEquals(42, executeWith(root, Integer.MAX_VALUE, 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
|
61 assertEquals(1, InvocationGuard.specializedInvocations); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
62 assertEquals(1, InvocationGuard.genericInvocations); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
63 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
64 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
65 @NodeChildren({@NodeChild("value0"), @NodeChild("value1")}) |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
66 public abstract static class InvocationGuard extends ValueNode { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
67 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
68 static int specializedInvocations = 0; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
69 static int genericInvocations = 0; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
70 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
71 boolean guard(int value0, int value1) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
72 return value0 != Integer.MAX_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
|
73 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
74 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
75 @Specialization(guards = "guard") |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
76 int doSpecialized(int value0, int value1) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
77 specializedInvocations++; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
78 return value0 + value1; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
79 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
80 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 @Generic |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
82 int doGeneric(Object value0, Object value1) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
83 genericInvocations++; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
84 return 42; // the generic answer to all 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
|
85 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
86 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
87 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
88 @Test |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
89 public void testGuardGlobal() { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 TestRootNode<GlobalFlagGuard> root = createRoot(GlobalFlagGuardFactory.getInstance()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
91 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
92 assertEquals(42, executeWith(root, 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
|
93 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
94 GlobalFlagGuard.globalFlag = true; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
95 assertEquals(41, executeWith(root, 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
|
96 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
97 GlobalFlagGuard.globalFlag = false; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
98 assertEquals(42, executeWith(root, 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
|
99 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
100 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
101 @NodeChild("expression") |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
102 public abstract static class GlobalFlagGuard extends ValueNode { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
103 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
104 static boolean globalFlag = false; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
105 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
106 static boolean globalFlagGuard() { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
107 return globalFlag; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
108 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
109 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 @Specialization(guards = "globalFlagGuard") |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 int doSpecialized(Object value0) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 return 41; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
113 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
114 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 @Generic |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 int doGeneric(Object value0) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
117 return 42; // the generic answer to all 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
|
118 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
121 @Test |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
122 public void testGuardWithBaseClass() { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
123 TestRootNode<?> root = createRoot(GuardWithBaseClassFactory.getInstance()); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
124 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
125 assertEquals(42, executeWith(root, new BExtendsAbstract())); |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
126 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
127 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
128 @NodeChild("expression") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
129 public abstract static class GuardWithBaseClass extends ValueNode { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
130 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
131 boolean baseGuard(Abstract base) { |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
132 return true; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
133 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
134 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
135 @Specialization(guards = "baseGuard") |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
136 int doSpecialized(BExtendsAbstract value0) { |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
137 return 42; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
138 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
139 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
140 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
141 @Test |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
142 public void testGuardWithBaseInterface() { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
143 TestRootNode<?> root = createRoot(GuardWithBaseInterfaceFactory.getInstance()); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
144 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
145 assertEquals(42, executeWith(root, "anything")); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
146 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
147 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
148 @NodeChild("expression") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
149 public abstract static class GuardWithBaseInterface extends ValueNode { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
150 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
151 boolean baseGuard(CharSequence base) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
152 return true; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
153 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
154 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
155 @Specialization(guards = "baseGuard") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
156 int doSpecialized(String value0) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
157 return 42; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
158 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
159 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
160 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
161 @Test |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
162 public void testGuardWithPrimitive() { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
163 TestRootNode<?> root = createRoot(GuardWithBoxedPrimitiveFactory.getInstance()); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
164 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
165 assertEquals(42, executeWith(root, 42)); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
166 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
167 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
168 @NodeChild("expression") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
169 public abstract static class GuardWithBoxedPrimitive extends ValueNode { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
170 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
171 boolean baseGuard(Integer primitive) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
172 return true; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
173 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
174 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
175 @Specialization(guards = "baseGuard") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
176 int doSpecialized(int value0) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
177 return value0; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
178 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
179 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
180 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
181 @Test |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
182 public void testGuardWithObject() { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
183 TestRootNode<?> root = createRoot(GuardWithObjectFactory.getInstance()); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
184 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
185 assertEquals(42, executeWith(root, 42)); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
186 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
187 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
188 @NodeChild("expression") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
189 public abstract static class GuardWithObject extends ValueNode { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
190 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
191 boolean baseGuard(Object primitive) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
192 return true; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
193 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
194 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
195 @Specialization(guards = "baseGuard") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
196 int doSpecialized(int value0) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
197 return value0; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
198 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
199 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
200 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
201 @Test |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
202 public void testGuardResolve1() { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
203 TestRootNode<?> root = createRoot(TestGuardResolve1Factory.getInstance()); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
204 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
205 assertEquals(42, executeWith(root, 42)); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
206 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
207 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
208 @NodeChild("expression") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
209 public abstract static class TestGuardResolve1 extends ValueNode { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
210 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
211 boolean guard(Object primitive) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
212 return false; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
213 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
214 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
215 boolean guard(int primitive) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
216 return true; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
217 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
218 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
219 @Specialization(guards = "guard") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
220 int doSpecialized(int value0) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
221 return value0; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
222 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
223 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
224 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
225 @Test |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
226 public void testGuardResolve2() { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
227 TestRootNode<?> root = createRoot(TestGuardResolve2Factory.getInstance()); |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
228 assertEquals(42, executeWith(root, new BExtendsAbstract())); |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
229 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
230 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
231 @NodeChild("expression") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
232 public abstract static class TestGuardResolve2 extends ValueNode { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
233 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
234 boolean guard(Object primitive) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
235 return false; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
236 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
237 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
238 boolean guard(Abstract primitive) { |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
239 return true; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
240 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
241 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
242 @Specialization(guards = "guard") |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
243 int doSpecialized(BExtendsAbstract value0) { |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
244 return 42; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
245 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
246 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
247 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
248 @Test |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
249 public void testGuardResolve3() { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
250 TestRootNode<?> root = createRoot(TestGuardResolve3Factory.getInstance()); |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
251 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
252 assertEquals(42, executeWith(root, new BExtendsAbstract())); |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
253 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
254 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
255 @NodeChild("expression") |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
256 public abstract static class TestGuardResolve3 extends ValueNode { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
257 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
258 boolean guard(Object primitive) { |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
259 return false; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
260 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
261 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
262 boolean guard(Abstract primitive) { |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
263 return false; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
264 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
265 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
266 boolean guard(BExtendsAbstract primitive) { |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
267 return true; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
268 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
269 |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
270 @Specialization(guards = "guard") |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
271 int doSpecialized(BExtendsAbstract value0) { |
11439
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
272 return 42; |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
273 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
274 } |
efe58aa92f86
Truffle-DSL: guards can now be declared using any base type or interface of the target value type.
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
275 |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
276 @NodeChild("expression") |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
277 public abstract static class TestGuardResolve4 extends ValueNode { |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
278 |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
279 boolean guard(Abstract primitive) { |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
280 return false; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
281 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
282 |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
283 @Specialization(guards = "guard") |
13528
5a0c694ef735
Truffle-DSL: Removed API classes NodeId, NodeContainer and SpecializationListener.
Christian Humer <christian.humer@gmail.com>
parents:
11507
diff
changeset
|
284 int doSpecialized(BExtendsAbstract value0) { |
11507
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
285 return 42; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
286 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
287 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
288 |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
289 @Test |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
290 public void testAbstractGuard1() { |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
291 TestRootNode<?> root = createRoot(TestAbstractGuard1Factory.getInstance()); |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
292 |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
293 assertEquals(BExtendsAbstract.INSTANCE, executeWith(root, BExtendsAbstract.INSTANCE)); |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
294 assertEquals(CExtendsAbstract.INSTANCE, executeWith(root, CExtendsAbstract.INSTANCE)); |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
295 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
296 |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
297 @NodeChild("expression") |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
298 public abstract static class TestAbstractGuard1 extends ValueNode { |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
299 |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
300 boolean guard(Abstract value0) { |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
301 return true; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
302 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
303 |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
304 @Specialization(order = 1, guards = "guard") |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
305 BExtendsAbstract doSpecialized1(BExtendsAbstract value0) { |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
306 return value0; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
307 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
308 |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
309 @Specialization(order = 2, guards = "guard") |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
310 CExtendsAbstract doSpecialized2(CExtendsAbstract value0) { |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
311 return value0; |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
312 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
313 } |
d6a5ab791b0d
Truffle-DSL: fixed a bug in grouping of abstract guards.
Christian Humer <christian.humer@gmail.com>
parents:
11439
diff
changeset
|
314 |
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
|
315 } |