Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/ExecuteEvaluatedTest.java @ 9287:8e3a1635cc9e
Implemented @NodeChild(executeWith={...}).
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 24 Apr 2013 21:50:03 +0200 |
parents | 76a6e7907b67 |
children |
comparison
equal
deleted
inserted
replaced
9286:39f08ef7b5d8 | 9287:8e3a1635cc9e |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.api.codegen.test; | 23 package com.oracle.truffle.api.codegen.test; |
24 | 24 |
25 import org.junit.*; | |
26 | |
25 import com.oracle.truffle.api.*; | 27 import com.oracle.truffle.api.*; |
26 import com.oracle.truffle.api.codegen.*; | 28 import com.oracle.truffle.api.codegen.*; |
29 import com.oracle.truffle.api.codegen.test.ExecuteEvaluatedTestFactory.DoubleEvaluatedNodeFactory; | |
30 import com.oracle.truffle.api.codegen.test.ExecuteEvaluatedTestFactory.EvaluatedNodeFactory; | |
31 import com.oracle.truffle.api.codegen.test.ExecuteEvaluatedTestFactory.UseDoubleEvaluatedNodeFactory; | |
32 import com.oracle.truffle.api.codegen.test.ExecuteEvaluatedTestFactory.UseEvaluatedNodeFactory; | |
33 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ArgumentNode; | |
34 import com.oracle.truffle.api.codegen.test.TypeSystemTest.TestArguments; | |
27 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode; | 35 import com.oracle.truffle.api.codegen.test.TypeSystemTest.ValueNode; |
28 import com.oracle.truffle.api.frame.*; | 36 import com.oracle.truffle.api.frame.*; |
37 import com.oracle.truffle.api.nodes.*; | |
29 | 38 |
30 public class ExecuteEvaluatedTest { | 39 public class ExecuteEvaluatedTest { |
31 | 40 |
32 /* Represents target[element] */ | 41 @Test |
33 @NodeChildren({@NodeChild("target"), @NodeChild("element")}) | 42 public void testSingleEvaluated() { |
34 abstract static class ReadElementNode extends ValueNode { | 43 ArgumentNode arg0 = new ArgumentNode(0); |
44 CallTarget callTarget = TestHelper.createCallTarget(UseEvaluatedNodeFactory.create(arg0, EvaluatedNodeFactory.create(null))); | |
45 | |
46 Assert.assertEquals(43, callTarget.call(new TestArguments(42))); | |
47 Assert.assertEquals(1, arg0.getInvocationCount()); | |
48 } | |
49 | |
50 @NodeChild("exp") | |
51 abstract static class EvaluatedNode extends ValueNode { | |
35 | 52 |
36 @Specialization | 53 @Specialization |
37 int getInt(Object[] target, int element) { | 54 int doExecuteWith(int exp) { |
38 return (int) target[element]; | 55 return exp + 1; |
39 } | 56 } |
40 | 57 |
41 public abstract Object executeWith(VirtualFrame frame, Object targetValue); | 58 public abstract Object executeEvaluated(VirtualFrame frame, Object targetValue); |
59 | |
60 public abstract int executeIntEvaluated(VirtualFrame frame, Object targetValue) throws UnexpectedResultException; | |
42 } | 61 } |
43 | 62 |
44 /* Represents target[element]() */ | 63 @NodeChildren({@NodeChild("exp0"), @NodeChild(value = "exp1", type = EvaluatedNode.class, executeWith = "exp0")}) |
45 @NodeChildren({@NodeChild("target"), @NodeChild(value = "element", type = ReadElementNode.class, executeWith = "target")}) | 64 abstract static class UseEvaluatedNode extends ValueNode { |
46 abstract static class ElementCallNode extends ValueNode { | |
47 | 65 |
48 @Specialization | 66 @Specialization |
49 Object call(Object receiver, Object callTarget) { | 67 int call(int exp0, int exp1) { |
50 return ((CallTarget) callTarget).call(new TestArguments(receiver)); | 68 Assert.assertEquals(exp0 + 1, exp1); |
69 return exp1; | |
70 } | |
71 } | |
72 | |
73 @Test | |
74 public void testDoubleEvaluated() { | |
75 ArgumentNode arg0 = new ArgumentNode(0); | |
76 ArgumentNode arg1 = new ArgumentNode(1); | |
77 CallTarget callTarget = TestHelper.createCallTarget(UseDoubleEvaluatedNodeFactory.create(arg0, arg1, DoubleEvaluatedNodeFactory.create(null, null))); | |
78 | |
79 Assert.assertEquals(85, callTarget.call(new TestArguments(42, 43))); | |
80 Assert.assertEquals(1, arg0.getInvocationCount()); | |
81 Assert.assertEquals(1, arg1.getInvocationCount()); | |
82 } | |
83 | |
84 @NodeChildren({@NodeChild("exp0"), @NodeChild("exp1")}) | |
85 abstract static class DoubleEvaluatedNode extends ValueNode { | |
86 | |
87 @Specialization | |
88 int doExecuteWith(int exp0, int exp1) { | |
89 return exp0 + exp1; | |
51 } | 90 } |
52 | 91 |
92 public abstract Object executeEvaluated(VirtualFrame frame, Object exp0, Object exp1); | |
93 | |
94 public abstract int executeIntEvaluated(VirtualFrame frame, Object exp0, Object exp1) throws UnexpectedResultException; | |
53 } | 95 } |
54 | 96 |
55 public static class TestArguments extends Arguments { | 97 @NodeChildren({@NodeChild("exp0"), @NodeChild("exp1"), @NodeChild(value = "exp2", type = DoubleEvaluatedNode.class, executeWith = {"exp0", "exp1"})}) |
98 abstract static class UseDoubleEvaluatedNode extends ValueNode { | |
56 | 99 |
57 private final Object receiver; | 100 @Specialization |
58 | 101 int call(int exp0, int exp1, int exp2) { |
59 public TestArguments(Object receiver) { | 102 Assert.assertEquals(exp0 + exp1, exp2); |
60 this.receiver = receiver; | 103 return exp2; |
61 } | 104 } |
62 | |
63 public Object getReceiver() { | |
64 return receiver; | |
65 } | |
66 | |
67 } | 105 } |
68 | 106 |
69 } | 107 } |