Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NodeChildNoNameTest.java @ 11183:0f5ff66a949d
Truffle-DSL: Fixed a bug with anonymous children (GRAAL-321 #resolve)
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 29 Jul 2013 18:46:43 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11182:fa65fc74eb76 | 11183:0f5ff66a949d |
---|---|
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.dsl.*; | |
28 import com.oracle.truffle.api.dsl.test.NodeChildNoNameTestFactory.OneArgNoNameFactory; | |
29 import com.oracle.truffle.api.dsl.test.NodeChildNoNameTestFactory.ThreeArgsNoNameFactory; | |
30 import com.oracle.truffle.api.dsl.test.NodeChildNoNameTestFactory.TwoArgsNoNameFactory; | |
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode; | |
32 import com.oracle.truffle.api.frame.*; | |
33 | |
34 public class NodeChildNoNameTest { | |
35 | |
36 @Test | |
37 public void testOneArg() { | |
38 ValueNode node = new ConstantNode(); | |
39 OneArgNoName arg = OneArgNoNameFactory.create(node); | |
40 Assert.assertEquals(node, arg.getChild0()); | |
41 Assert.assertEquals(43, TestHelper.createCallTarget(arg).call()); | |
42 } | |
43 | |
44 @Test | |
45 public void testTwoArg() { | |
46 ValueNode node1 = new ConstantNode(); | |
47 ValueNode node2 = new ConstantNode(); | |
48 TwoArgsNoName arg = TwoArgsNoNameFactory.create(node1, node2); | |
49 Assert.assertEquals(node1, arg.getChild0()); | |
50 Assert.assertEquals(node2, arg.getChild1()); | |
51 Assert.assertEquals(84, TestHelper.createCallTarget(arg).call()); | |
52 } | |
53 | |
54 @Test | |
55 public void testThreeArg() { | |
56 ValueNode node1 = new ConstantNode(); | |
57 ValueNode node2 = new ConstantNode(); | |
58 ValueNode node3 = new ConstantNode(); | |
59 ThreeArgsNoName arg = ThreeArgsNoNameFactory.create(node1, node2, node3); | |
60 Assert.assertEquals(node1, arg.getChild0()); | |
61 Assert.assertEquals(node2, arg.getChild1()); | |
62 Assert.assertEquals(node3, arg.getChild2()); | |
63 Assert.assertEquals(126, TestHelper.createCallTarget(arg).call()); | |
64 } | |
65 | |
66 private static class ConstantNode extends ValueNode { | |
67 | |
68 @Override | |
69 public Object execute(VirtualFrame frame) { | |
70 return 42; | |
71 } | |
72 } | |
73 | |
74 @NodeChild | |
75 abstract static class OneArgNoName extends ValueNode { | |
76 | |
77 public abstract ValueNode getChild0(); | |
78 | |
79 @Specialization | |
80 int doIt(int exp) { | |
81 return exp + 1; | |
82 } | |
83 | |
84 } | |
85 | |
86 @NodeChildren({@NodeChild, @NodeChild}) | |
87 abstract static class TwoArgsNoName extends ValueNode { | |
88 | |
89 public abstract ValueNode getChild0(); | |
90 | |
91 public abstract ValueNode getChild1(); | |
92 | |
93 @Specialization | |
94 int doIt(int exp0, int exp1) { | |
95 return exp0 + exp1; | |
96 } | |
97 } | |
98 | |
99 @NodeChildren({@NodeChild, @NodeChild, @NodeChild}) | |
100 abstract static class ThreeArgsNoName extends ValueNode { | |
101 | |
102 public abstract ValueNode getChild0(); | |
103 | |
104 public abstract ValueNode getChild1(); | |
105 | |
106 public abstract ValueNode getChild2(); | |
107 | |
108 @Specialization | |
109 int doIt(int exp0, int exp1, int exp2) { | |
110 return exp0 + exp1 + exp2; | |
111 } | |
112 } | |
113 | |
114 } |