Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/TypeSystemTest.java @ 10597:79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Jul 2013 20:58:32 +0200 |
parents | |
children | 4f52b08bd2f9 |
comparison
equal
deleted
inserted
replaced
10596:f43eb2f1bbbc | 10597:79041ab43660 |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.dsl.test; | |
24 | |
25 import com.oracle.truffle.api.*; | |
26 import com.oracle.truffle.api.dsl.*; | |
27 import com.oracle.truffle.api.dsl.test.NodeContainerTest.Str; | |
28 import com.oracle.truffle.api.frame.*; | |
29 import com.oracle.truffle.api.nodes.*; | |
30 | |
31 public class TypeSystemTest { | |
32 | |
33 @TypeSystem({int.class, boolean.class, String.class, Str.class, CallTarget.class, Object[].class}) | |
34 static class SimpleTypes { | |
35 } | |
36 | |
37 @TypeSystemReference(SimpleTypes.class) | |
38 public abstract static class ValueNode extends Node { | |
39 | |
40 public int executeInt(VirtualFrame frame) throws UnexpectedResultException { | |
41 return SimpleTypesGen.SIMPLETYPES.expectInteger(execute(frame)); | |
42 } | |
43 | |
44 public Str executeStr(VirtualFrame frame) throws UnexpectedResultException { | |
45 return SimpleTypesGen.SIMPLETYPES.expectStr(execute(frame)); | |
46 } | |
47 | |
48 public String executeString(VirtualFrame frame) throws UnexpectedResultException { | |
49 return SimpleTypesGen.SIMPLETYPES.expectString(execute(frame)); | |
50 } | |
51 | |
52 public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException { | |
53 return SimpleTypesGen.SIMPLETYPES.expectBoolean(execute(frame)); | |
54 } | |
55 | |
56 public Object[] executeIntArray(VirtualFrame frame) throws UnexpectedResultException { | |
57 return SimpleTypesGen.SIMPLETYPES.expectObjectArray(execute(frame)); | |
58 } | |
59 | |
60 public abstract Object execute(VirtualFrame frame); | |
61 | |
62 @Override | |
63 public ValueNode copy() { | |
64 return (ValueNode) super.copy(); | |
65 } | |
66 } | |
67 | |
68 @NodeChild(value = "children", type = ValueNode[].class) | |
69 public abstract static class ChildrenNode extends ValueNode { | |
70 | |
71 } | |
72 | |
73 @TypeSystemReference(SimpleTypes.class) | |
74 public static class TestRootNode<E extends ValueNode> extends RootNode { | |
75 | |
76 @Child private E node; | |
77 | |
78 public TestRootNode(E node) { | |
79 this.node = adoptChild(node); | |
80 } | |
81 | |
82 @Override | |
83 public Object execute(VirtualFrame frame) { | |
84 return node.execute(frame); | |
85 } | |
86 | |
87 public E getNode() { | |
88 return node; | |
89 } | |
90 } | |
91 | |
92 public static class TestArguments extends Arguments { | |
93 | |
94 private final Object[] values; | |
95 | |
96 public TestArguments(Object... values) { | |
97 this.values = values; | |
98 } | |
99 | |
100 public Object[] getValues() { | |
101 return values; | |
102 } | |
103 | |
104 public Object get(int index) { | |
105 return values[index]; | |
106 } | |
107 | |
108 } | |
109 | |
110 public static class ArgumentNode extends ValueNode { | |
111 | |
112 private int invocationCount; | |
113 final int index; | |
114 | |
115 public ArgumentNode(int index) { | |
116 this.index = index; | |
117 } | |
118 | |
119 public int getInvocationCount() { | |
120 return invocationCount; | |
121 } | |
122 | |
123 @Override | |
124 public Object execute(VirtualFrame frame) { | |
125 invocationCount++; | |
126 return frame.getArguments(TestArguments.class).get(index); | |
127 } | |
128 | |
129 } | |
130 | |
131 } |