Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/AssumptionsTest.java @ 10597:79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Jul 2013 20:58:32 +0200 |
parents | |
children | 5148aab962af |
comparison
equal
deleted
inserted
replaced
10596:f43eb2f1bbbc | 10597:79041ab43660 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.dsl.test; | |
24 | |
25 import org.junit.*; | |
26 | |
27 import com.oracle.truffle.api.*; | |
28 import com.oracle.truffle.api.dsl.*; | |
29 import com.oracle.truffle.api.dsl.test.AssumptionsTestFactory.DerivedAssumptionNodeFactory; | |
30 import com.oracle.truffle.api.dsl.test.AssumptionsTestFactory.DerivedAssumptionRedeclaredNodeFactory; | |
31 import com.oracle.truffle.api.dsl.test.AssumptionsTestFactory.MultipleAssumptionsNodeFactory; | |
32 import com.oracle.truffle.api.dsl.test.AssumptionsTestFactory.SingleAssumptionNodeFactory; | |
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; | |
34 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | |
35 | |
36 public class AssumptionsTest { | |
37 | |
38 @Test | |
39 public void testSingleAssumption() { | |
40 Assumption assumption = Truffle.getRuntime().createAssumption(); | |
41 TestRootNode<?> root = TestHelper.createRoot(SingleAssumptionNodeFactory.getInstance(), assumption); | |
42 | |
43 Assert.assertEquals(42, TestHelper.executeWith(root)); | |
44 assumption.invalidate(); | |
45 Assert.assertEquals("42", TestHelper.executeWith(root)); | |
46 } | |
47 | |
48 @NodeAssumptions("assumption") | |
49 abstract static class SingleAssumptionNode extends ValueNode { | |
50 | |
51 @Specialization(order = 0, assumptions = "assumption") | |
52 int doInt() { | |
53 return 42; | |
54 } | |
55 | |
56 @Specialization | |
57 Object doObject() { | |
58 return "42"; | |
59 } | |
60 } | |
61 | |
62 @Test | |
63 public void testMultipleAssumption() { | |
64 Assumption assumption1 = Truffle.getRuntime().createAssumption(); | |
65 Assumption assumption2 = Truffle.getRuntime().createAssumption(); | |
66 TestRootNode<?> root = TestHelper.createRoot(MultipleAssumptionsNodeFactory.getInstance(), assumption1, assumption2); | |
67 | |
68 Assert.assertEquals(42, TestHelper.executeWith(root)); | |
69 assumption2.invalidate(); | |
70 Assert.assertEquals("42", TestHelper.executeWith(root)); | |
71 assumption1.invalidate(); | |
72 Assert.assertEquals("43", TestHelper.executeWith(root)); | |
73 } | |
74 | |
75 @NodeAssumptions({"assumption1", "assumption2"}) | |
76 abstract static class MultipleAssumptionsNode extends ValueNode { | |
77 | |
78 @Specialization(assumptions = {"assumption1", "assumption2"}) | |
79 int doInt() { | |
80 return 42; | |
81 } | |
82 | |
83 @Specialization(assumptions = "assumption1") | |
84 Object doObject() { | |
85 return "42"; | |
86 } | |
87 | |
88 @Generic | |
89 Object doGeneric() { | |
90 return "43"; | |
91 } | |
92 } | |
93 | |
94 @Test | |
95 public void testDerivedAssumption() { | |
96 Assumption additionalAssumption = Truffle.getRuntime().createAssumption(); | |
97 Assumption assumption = Truffle.getRuntime().createAssumption(); | |
98 TestRootNode<?> root = TestHelper.createRoot(DerivedAssumptionNodeFactory.getInstance(), assumption, additionalAssumption); | |
99 | |
100 Assert.assertEquals(42, TestHelper.executeWith(root)); | |
101 assumption.invalidate(); | |
102 Assert.assertEquals(43, TestHelper.executeWith(root)); | |
103 additionalAssumption.invalidate(); | |
104 Assert.assertEquals("42", TestHelper.executeWith(root)); | |
105 } | |
106 | |
107 @NodeAssumptions({"additionalAssumption"}) | |
108 abstract static class DerivedAssumptionNode extends SingleAssumptionNode { | |
109 | |
110 @Specialization(order = 1, assumptions = "additionalAssumption") | |
111 int doIntDerived() { | |
112 return 43; | |
113 } | |
114 } | |
115 | |
116 @Test | |
117 public void testDerivedAssumptionRedeclared() { | |
118 Assumption additionalAssumption = Truffle.getRuntime().createAssumption(); | |
119 Assumption assumption = Truffle.getRuntime().createAssumption(); | |
120 TestRootNode<?> root = TestHelper.createRoot(DerivedAssumptionRedeclaredNodeFactory.getInstance(), additionalAssumption, assumption); | |
121 | |
122 Assert.assertEquals(42, TestHelper.executeWith(root)); | |
123 assumption.invalidate(); | |
124 Assert.assertEquals(43, TestHelper.executeWith(root)); | |
125 additionalAssumption.invalidate(); | |
126 Assert.assertEquals("42", TestHelper.executeWith(root)); | |
127 } | |
128 | |
129 @NodeAssumptions({"additionalAssumption", "assumption"}) | |
130 abstract static class DerivedAssumptionRedeclaredNode extends SingleAssumptionNode { | |
131 | |
132 @Specialization(order = 1, assumptions = "additionalAssumption") | |
133 int doIntDerived() { | |
134 return 43; | |
135 } | |
136 | |
137 } | |
138 | |
139 } |