comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/NodeChildTest.java @ 12752:71991b7a0f14

SL: Enhanced SimpleLanguage with support for if statements, function calls, function caching + inlining and builtins.
author Christian Humer <christian.humer@gmail.com>
date Mon, 11 Nov 2013 21:34:44 +0100
parents
children 18c0f02fa4d2
comparison
equal deleted inserted replaced
12712:882a0aadfed6 12752:71991b7a0f14
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.NodeFieldTestFactory.IntFieldTestNodeFactory;
32 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
33
34 public class NodeChildTest {
35
36 @Test
37 public void testIntField() {
38 assertEquals(42, createCallTarget(IntFieldTestNodeFactory.create(42)).call());
39 }
40
41 @NodeChild("child0")
42 abstract static class Base0Node extends ValueNode {
43
44 }
45
46 @NodeChild(value = "child1", type = ValueNode.class)
47 abstract static class Child0Node extends Base0Node {
48
49 @Specialization
50 int intField(int child0, int child1) {
51 return child0 + child1;
52 }
53 }
54
55 @NodeChildren({@NodeChild("child0")})
56 abstract static class Base1Node extends ValueNode {
57
58 }
59
60 @NodeChildren({@NodeChild(value = "child1", type = ValueNode.class)})
61 abstract static class Child1Node extends Base1Node {
62
63 @Specialization
64 int intField(int child0, int child1) {
65 return child0 + child1;
66 }
67 }
68
69 @NodeChildren({@NodeChild("child0"), @NodeChild("child1")})
70 abstract static class Base2Node extends ValueNode {
71
72 }
73
74 @NodeChildren({@NodeChild(value = "child2", type = ValueNode.class)})
75 abstract static class Child2Node extends Base1Node {
76
77 // TODO this is an error to fix
78 @ExpectError("Method signature (int, int, int) does not match to the expected signature:%")
79 @Specialization
80 int intField(int child0, int child1, int child2) {
81 return child0 + child1 + child2;
82 }
83 }
84
85 @NodeChildren({@NodeChild(value = "receiver", type = ValueNode.class), @NodeChild(value = "arguments", type = ValueNode[].class)})
86 abstract static class BaseNode extends ValueNode {
87 public abstract ValueNode getReceiver();
88
89 public abstract ValueNode[] getArguments();
90 }
91
92 abstract static class UnaryNode extends BaseNode {
93 @Specialization
94 public int doIt(int value) {
95 return value;
96 }
97 }
98
99 abstract static class BinaryNode extends BaseNode {
100 @Specialization
101 public int doIt(int value0, int value1) {
102 return value0 + value1;
103 }
104 }
105
106 abstract static class TernaryNode extends BaseNode {
107 @Specialization
108 public int doIt(int value0, int value1, int value2) {
109 return value0 + value1 + value2;
110 }
111 }
112
113 }