annotate truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ShortCircuitTest.java @ 22232:526de3af756d

Merge with 0480c4873a4a8a71250c9570b702cea98ab1c7bc
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Mon, 21 Sep 2015 12:15:38 -0700
parents dc83cc1f94f2
children 14e6dfb1ef05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.dsl.test;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
22232
526de3af756d Merge with 0480c4873a4a8a71250c9570b702cea98ab1c7bc
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
25 import static org.junit.Assert.assertEquals;
526de3af756d Merge with 0480c4873a4a8a71250c9570b702cea98ab1c7bc
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
26
526de3af756d Merge with 0480c4873a4a8a71250c9570b702cea98ab1c7bc
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
27 import org.junit.Test;
526de3af756d Merge with 0480c4873a4a8a71250c9570b702cea98ab1c7bc
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 22157
diff changeset
28
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
29 import com.oracle.truffle.api.CallTarget;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
30 import com.oracle.truffle.api.dsl.ImplicitCast;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
31 import com.oracle.truffle.api.dsl.NodeChild;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
32 import com.oracle.truffle.api.dsl.NodeChildren;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
33 import com.oracle.truffle.api.dsl.ShortCircuit;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
34 import com.oracle.truffle.api.dsl.Specialization;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
35 import com.oracle.truffle.api.dsl.TypeSystem;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
36 import com.oracle.truffle.api.dsl.TypeSystemReference;
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 import com.oracle.truffle.api.dsl.test.ShortCircuitTestFactory.DoubleChildNodeFactory;
21742
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
38 import com.oracle.truffle.api.dsl.test.ShortCircuitTestFactory.ShortCircuitWithImplicitCastNodeFactory;
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 import com.oracle.truffle.api.dsl.test.ShortCircuitTestFactory.SingleChildNodeFactory;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 import com.oracle.truffle.api.dsl.test.ShortCircuitTestFactory.VarArgsNodeFactory;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ArgumentNode;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 public class ShortCircuitTest {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 public void testSingleChild1() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 ArgumentNode arg0 = new ArgumentNode(0);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 CallTarget callTarget = TestHelper.createCallTarget(SingleChildNodeFactory.create(arg0));
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 SingleChildNode.needsChild = true;
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13527
diff changeset
51 assertEquals(42, callTarget.call(new Object[]{42}));
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 assertEquals(1, arg0.getInvocationCount());
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 public void testSingleChild2() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 ArgumentNode arg0 = new ArgumentNode(0);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 CallTarget callTarget = TestHelper.createCallTarget(SingleChildNodeFactory.create(arg0));
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 SingleChildNode.needsChild = false;
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13527
diff changeset
60 assertEquals(0, callTarget.call(new Object[]{42}));
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 assertEquals(0, arg0.getInvocationCount());
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 @NodeChild("child0")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 abstract static class SingleChildNode extends ValueNode {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 static boolean needsChild;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 @ShortCircuit("child0")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 boolean needsChild0() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 return needsChild;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 @Specialization
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 int doIt(boolean hasChild0, int child0) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 assert hasChild0 == needsChild0();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 return child0;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 public void testDoubleChild1() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 ArgumentNode arg0 = new ArgumentNode(0);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 ArgumentNode arg1 = new ArgumentNode(1);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 CallTarget callTarget = TestHelper.createCallTarget(DoubleChildNodeFactory.create(arg0, arg1));
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13527
diff changeset
87 assertEquals(42, callTarget.call(new Object[]{41, 42}));
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88 assertEquals(1, arg1.getInvocationCount());
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 public void testDoubleChild2() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93 ArgumentNode arg0 = new ArgumentNode(0);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 ArgumentNode arg1 = new ArgumentNode(1);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 CallTarget callTarget = TestHelper.createCallTarget(DoubleChildNodeFactory.create(arg0, arg1));
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13527
diff changeset
96 assertEquals(0, callTarget.call(new Object[]{42, 42}));
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 assertEquals(0, arg1.getInvocationCount());
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 @NodeChildren({@NodeChild("child0"), @NodeChild("child1")})
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 @SuppressWarnings("unused")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 abstract static class DoubleChildNode extends ValueNode {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 @ShortCircuit("child1")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 boolean needsChild1(Object leftValue) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 return leftValue.equals(41);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 @Specialization
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
110 int doIt(int child0, boolean hasChild1, int child1) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111 return child1;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
114 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115
16906
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
116 @NodeChildren({@NodeChild("child0"), @NodeChild("child1")})
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
117 @SuppressWarnings("unused")
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
118 abstract static class GuardChildNode extends ValueNode {
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
119
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
120 @ShortCircuit("child1")
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
121 boolean needsChild1(Object a) {
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
122 return a.equals(new Integer(42));
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
123 }
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
124
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
125 static boolean guard(int a, boolean hasB, int b) {
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
126 return false;
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
127 }
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
128
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16906
diff changeset
129 @Specialization(guards = "guard(a, hasB, b)")
16906
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
130 int doIt(int a, boolean hasB, int b) {
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
131 return a + b;
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
132 }
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
133
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
134 }
8eca9a00aaba Truffle-DSL: Fixed guard matching for operations that use short circuits without boolean in the type system.
Christian Humer <christian.humer@gmail.com>
parents: 14991
diff changeset
135
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
136 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
137 public void testVarArgs1() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
138 ArgumentNode arg0 = new ArgumentNode(0);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139 ArgumentNode arg1 = new ArgumentNode(1);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 CallTarget callTarget = TestHelper.createCallTarget(VarArgsNodeFactory.create(new ValueNode[]{arg0, arg1}));
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13527
diff changeset
141 assertEquals(42, callTarget.call(new Object[]{41, 42}));
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 assertEquals(1, arg1.getInvocationCount());
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
144
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146 public void testVarArgs2() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147 ArgumentNode arg0 = new ArgumentNode(0);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 ArgumentNode arg1 = new ArgumentNode(1);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149 CallTarget callTarget = TestHelper.createCallTarget(VarArgsNodeFactory.create(new ValueNode[]{arg0, arg1}));
14991
64dcb92ee75a Truffle: Change signature for Truffle calls from (PackedFrame, Arguments) to (Object[]).
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 13527
diff changeset
150 assertEquals(0, callTarget.call(new Object[]{42, 42}));
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151 assertEquals(0, arg1.getInvocationCount());
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
152 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
154 @NodeChild(value = "children", type = ValueNode[].class)
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155 abstract static class VarArgsNode extends ValueNode {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 @ShortCircuit("children[1]")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158 boolean needsChild1(Object leftValue) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159 return leftValue.equals(41);
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
160 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
161
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
162 @Specialization
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
163 @SuppressWarnings("unused")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
164 int doIt(int child0, boolean hasChild1, int child1) {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
165 return child1;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
166 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
167
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
168 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
169
21742
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
170 @Test
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
171 public void testShortCircuitWithImplicitCastNode() {
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
172 ArgumentNode arg0 = new ArgumentNode(0);
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
173 ArgumentNode arg1 = new ArgumentNode(1);
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
174 CallTarget callTarget = TestHelper.createCallTarget(ShortCircuitWithImplicitCastNodeFactory.create(new ValueNode[]{arg0, arg1}));
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
175 assertEquals(42, callTarget.call(new Object[]{42, 41}));
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
176 }
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
177
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
178 @TypeSystem(int.class)
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
179 abstract static class ShortCircuitWithImplicitCastTypes {
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
180
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
181 @ImplicitCast
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
182 public static int doAnImplicitCast(String foo) {
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
183 return Integer.parseInt(foo);
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
184 }
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
185
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
186 }
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
187
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
188 @NodeChild(value = "children", type = ValueNode[].class)
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
189 @TypeSystemReference(ShortCircuitWithImplicitCastTypes.class)
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
190 abstract static class ShortCircuitWithImplicitCastNode extends ValueNode {
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
191
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
192 @ShortCircuit("children[1]")
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
193 public boolean needsRightNode(Object left) {
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
194 return (int) left == 41;
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
195 }
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
196
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
197 @Specialization
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
198 public int doInteger(int left, boolean needsRight, int right) {
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
199 return needsRight ? right : left;
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
200 }
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
201
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
202 }
2e850dbf82ae Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
Christian Humer <christian.humer@gmail.com>
parents: 19283
diff changeset
203
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
204 }