annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ShortCircuitTest.java @ 21742:2e850dbf82ae

Truffle-DSL: fix NPE in getImplicitCastType if an implicitely casted type is short circuited. (reported-by: Mohaned Qunaibit)
author Christian Humer <christian.humer@gmail.com>
date Fri, 05 Jun 2015 14:12:49 +0200
parents 08aa0372dad4
children
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
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 import static org.junit.Assert.*;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 import org.junit.*;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29 import com.oracle.truffle.api.*;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 import com.oracle.truffle.api.dsl.*;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 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
32 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
33 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
34 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
35 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
36 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
37
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 public class ShortCircuitTest {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 public void testSingleChild1() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 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
43 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
44 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
45 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
46 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
47 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 public void testSingleChild2() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 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
52 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
53 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
54 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
55 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
56 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 @NodeChild("child0")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 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
60
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 static boolean needsChild;
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 @ShortCircuit("child0")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 boolean needsChild0() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 return needsChild;
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
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68 @Specialization
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 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
70 assert hasChild0 == needsChild0();
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 return child0;
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 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 public void testDoubleChild1() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 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
79 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
80 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
81 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
82 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
83 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 public void testDoubleChild2() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 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
88 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
89 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
90 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
91 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
92 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 @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
95 @SuppressWarnings("unused")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 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
97
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98 @ShortCircuit("child1")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 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
100 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
101 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 @Specialization
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 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
105 return child1;
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 }
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
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
110 @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
111 @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
112 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
113
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
114 @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
115 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
116 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
117 }
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
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 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
120 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
121 }
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
19283
08aa0372dad4 Truffle-DSL: implement new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 16906
diff changeset
123 @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
124 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
125 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
126 }
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 }
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
129
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
130 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
131 public void testVarArgs1() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
132 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
133 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
134 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
135 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
136 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
137 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
138
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139 @Test
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 public void testVarArgs2() {
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 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
142 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
143 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
144 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
145 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
146 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 @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
149 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
150
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151 @ShortCircuit("children[1]")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
152 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
153 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
154 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
156 @Specialization
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 @SuppressWarnings("unused")
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158 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
159 return child1;
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 }
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
163
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
164 @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
165 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
166 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
167 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
168 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
169 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
170 }
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
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 @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
173 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
174
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 @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
176 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
177 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
178 }
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
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
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 @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
183 @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
184 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
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 @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
187 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
188 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
189 }
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
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 @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
192 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
193 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
194 }
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
13527
25ecb47a6d0e Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198 }