comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/PolymorphicTest2.java @ 10743:ff6eb563a2e2

Truffle-DSL: Added additional test case for polymporphic generation.
author Christian Humer <christian.humer@gmail.com>
date Sat, 13 Jul 2013 17:21:58 +0200
parents
children 5d1308c78ddc
comparison
equal deleted inserted replaced
10742:99789440ce28 10743:ff6eb563a2e2
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 static com.oracle.truffle.api.dsl.test.TestHelper.*;
26 import static org.junit.Assert.*;
27
28 import org.junit.*;
29
30 import com.oracle.truffle.api.dsl.*;
31 import com.oracle.truffle.api.dsl.test.BinaryNodeTest.BinaryNode;
32 import com.oracle.truffle.api.dsl.test.PolymorphicTest2Factory.Node1Factory;
33 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
34 import com.oracle.truffle.api.nodes.*;
35 import com.oracle.truffle.api.nodes.NodeInfo.Kind;
36
37 public class PolymorphicTest2 {
38
39 @Test
40 public void testMultipleTypes() {
41 /* Tests the unexpected polymorphic case. */
42 TestRootNode<Node1> node = TestHelper.createRoot(Node1Factory.getInstance());
43 assertEquals(21, executeWith(node, false, false));
44 assertEquals(42, executeWith(node, 21, 21));
45 assertEquals("(boolean,int)", executeWith(node, false, 42));
46 assertEquals(Kind.POLYMORPHIC, node.getNode().getClass().getAnnotation(NodeInfo.class).kind());
47 }
48
49 @SuppressWarnings("unused")
50 @PolymorphicLimit(3)
51 abstract static class Node1 extends BinaryNode {
52
53 @Specialization(order = 1)
54 int add(int left, int right) {
55 return 42;
56 }
57
58 @Specialization(order = 2)
59 int add(boolean left, boolean right) {
60 return 21;
61 }
62
63 @Specialization(order = 4)
64 String add(boolean left, int right) {
65 return "(boolean,int)";
66 }
67
68 }
69
70 }