Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/UnsupportedSpecializationTest.java @ 13861:28479abd1a69
Truffle-DSL: implemented support for UnsupportedSpecializationException#getSuppliedNodes().
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 03 Feb 2014 20:59:57 +0100 |
parents | f270f09616da |
children |
comparison
equal
deleted
inserted
replaced
13858:6b91134526a7 | 13861:28479abd1a69 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.api.dsl.test; | 23 package com.oracle.truffle.api.dsl.test; |
24 | 24 |
25 import java.util.*; | |
26 | |
25 import org.junit.*; | 27 import org.junit.*; |
26 | 28 |
27 import com.oracle.truffle.api.dsl.*; | 29 import com.oracle.truffle.api.dsl.*; |
28 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; | 30 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode; |
29 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | 31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; |
30 import com.oracle.truffle.api.dsl.test.UnsupportedSpecializationTestFactory.Undefined1Factory; | 32 import com.oracle.truffle.api.dsl.test.UnsupportedSpecializationTestFactory.Unsupported1Factory; |
33 import com.oracle.truffle.api.dsl.test.UnsupportedSpecializationTestFactory.Unsupported2Factory; | |
34 import com.oracle.truffle.api.nodes.*; | |
31 | 35 |
32 public class UnsupportedSpecializationTest { | 36 public class UnsupportedSpecializationTest { |
33 | 37 |
34 @Test | 38 @Test |
35 public void testUndefined1() { | 39 public void testUnsupported1() { |
36 TestRootNode<Undefined1> root = TestHelper.createRoot(Undefined1Factory.getInstance()); | 40 TestRootNode<Unsupported1> root = TestHelper.createRoot(Unsupported1Factory.getInstance()); |
37 try { | 41 try { |
38 TestHelper.executeWith(root, ""); | 42 TestHelper.executeWith(root, ""); |
39 Assert.fail(); | 43 Assert.fail(); |
40 } catch (UnsupportedSpecializationException e) { | 44 } catch (UnsupportedSpecializationException e) { |
41 Assert.assertNotNull(e.getSuppliedValues()); | 45 Assert.assertNotNull(e.getSuppliedValues()); |
42 Assert.assertEquals(1, e.getSuppliedValues().length); | 46 Assert.assertEquals(1, e.getSuppliedValues().length); |
43 Assert.assertEquals("", e.getSuppliedValues()[0]); | 47 Assert.assertEquals("", e.getSuppliedValues()[0]); |
48 Assert.assertSame(root.getNode().getChildren().iterator().next(), e.getSuppliedNodes()[0]); | |
44 Assert.assertEquals(root.getNode(), e.getNode()); | 49 Assert.assertEquals(root.getNode(), e.getNode()); |
45 } | 50 } |
46 } | 51 } |
47 | 52 |
48 @NodeChild("a") | 53 @NodeChild("a") |
49 abstract static class Undefined1 extends ValueNode { | 54 abstract static class Unsupported1 extends ValueNode { |
50 | 55 |
51 @Specialization | 56 @Specialization |
52 public int doInteger(@SuppressWarnings("unused") int a) { | 57 public int doInteger(@SuppressWarnings("unused") int a) { |
53 throw new AssertionError(); | 58 throw new AssertionError(); |
54 } | 59 } |
55 } | 60 } |
56 | 61 |
57 // TODO more tests required | 62 @Test |
63 public void testUnsupported2() { | |
64 TestRootNode<Unsupported2> root = TestHelper.createRoot(Unsupported2Factory.getInstance()); | |
65 try { | |
66 TestHelper.executeWith(root, "", 1); | |
67 Assert.fail(); | |
68 } catch (UnsupportedSpecializationException e) { | |
69 Assert.assertNotNull(e.getSuppliedValues()); | |
70 Assert.assertNotNull(e.getSuppliedNodes()); | |
71 Assert.assertEquals(3, e.getSuppliedValues().length); | |
72 Assert.assertEquals(3, e.getSuppliedNodes().length); | |
73 Assert.assertEquals("", e.getSuppliedValues()[0]); | |
74 Assert.assertEquals(false, e.getSuppliedValues()[1]); | |
75 Assert.assertEquals(null, e.getSuppliedValues()[2]); | |
76 List<Node> children = NodeUtil.findNodeChildren(root.getNode()); | |
77 Assert.assertSame(children.get(0), e.getSuppliedNodes()[0]); | |
78 Assert.assertNull(e.getSuppliedNodes()[1]); | |
79 Assert.assertSame(children.get(1), e.getSuppliedNodes()[2]); | |
80 Assert.assertEquals(root.getNode(), e.getNode()); | |
81 } | |
82 } | |
83 | |
84 @SuppressWarnings("unused") | |
85 @NodeChildren({@NodeChild("a"), @NodeChild("b")}) | |
86 abstract static class Unsupported2 extends ValueNode { | |
87 | |
88 @ShortCircuit("b") | |
89 public boolean needsB(Object a) { | |
90 return false; | |
91 } | |
92 | |
93 @Specialization | |
94 public int doInteger(int a, boolean hasB, int b) { | |
95 throw new AssertionError(); | |
96 } | |
97 } | |
98 | |
58 } | 99 } |