Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ShortCircuitTest.java @ 13556:44288fe54352
Ruby: fix some ?break? semantics.
author | Chris Seaton <chris.seaton@oracle.com> |
---|---|
date | Wed, 08 Jan 2014 17:42:10 +0000 |
parents | 25ecb47a6d0e |
children | 64dcb92ee75a |
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; |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 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
|
33 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
|
34 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
|
35 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestArguments; |
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; |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 assertEquals(42, callTarget.call(new TestArguments(42))); |
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; |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 assertEquals(0, callTarget.call(new TestArguments(42))); |
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)); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
81 assertEquals(42, callTarget.call(new TestArguments(41, 42))); |
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)); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
90 assertEquals(0, callTarget.call(new TestArguments(42, 42))); |
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 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
110 @Test |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
111 public void testVarArgs1() { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
112 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
|
113 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
|
114 CallTarget callTarget = TestHelper.createCallTarget(VarArgsNodeFactory.create(new ValueNode[]{arg0, arg1})); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
115 assertEquals(42, callTarget.call(new TestArguments(41, 42))); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
116 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
|
117 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
118 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
119 @Test |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
120 public void testVarArgs2() { |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
121 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
|
122 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
|
123 CallTarget callTarget = TestHelper.createCallTarget(VarArgsNodeFactory.create(new ValueNode[]{arg0, arg1})); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
124 assertEquals(0, callTarget.call(new TestArguments(42, 42))); |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
125 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
|
126 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
127 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
128 @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
|
129 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
|
130 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
131 @ShortCircuit("children[1]") |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
132 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
|
133 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
|
134 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
135 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
136 @Specialization |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
137 @SuppressWarnings("unused") |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
138 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
|
139 return child1; |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
140 } |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
141 |
25ecb47a6d0e
Truffle-DSL: Added support for references to child arrays in @ShortCircuit;
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
142 } |
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 } |