Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.codegen.test/src/com/oracle/truffle/api/codegen/test/TypeSystemTest.java @ 8596:6ef9fc7375c7
Updated codegen tests for guards and builtins.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 01 Apr 2013 21:43:39 +0200 |
parents | a80bf36c6a1e |
children | 5f7f0d3e3638 |
comparison
equal
deleted
inserted
replaced
8595:8a1115c92271 | 8596:6ef9fc7375c7 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. | 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. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
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 com.oracle.truffle.api.*; | |
25 import com.oracle.truffle.api.codegen.*; | 26 import com.oracle.truffle.api.codegen.*; |
26 import com.oracle.truffle.api.codegen.test.RuntimeStringTest.RuntimeString; | 27 import com.oracle.truffle.api.codegen.test.BuiltinTest.Str; |
27 import com.oracle.truffle.api.frame.*; | 28 import com.oracle.truffle.api.frame.*; |
28 import com.oracle.truffle.api.nodes.*; | 29 import com.oracle.truffle.api.nodes.*; |
29 | 30 |
30 public class TypeSystemTest { | 31 public class TypeSystemTest { |
31 | 32 |
32 @TypeSystem({int.class, RuntimeString.class}) | 33 @TypeSystem({int.class, Str.class}) |
33 static class SimpleTypes { | 34 static class SimpleTypes { |
34 } | 35 } |
35 | 36 |
36 @TypeSystemReference(SimpleTypes.class) | 37 @TypeSystemReference(SimpleTypes.class) |
37 abstract static class ValueNode extends Node { | 38 abstract static class ValueNode extends Node { |
38 | 39 |
39 int executeInt() throws UnexpectedResultException { | 40 int executeInt(VirtualFrame frame) throws UnexpectedResultException { |
40 return SimpleTypesGen.SIMPLETYPES.expectInteger(execute()); | 41 return SimpleTypesGen.SIMPLETYPES.expectInteger(execute(frame)); |
41 } | 42 } |
42 | 43 |
43 RuntimeString executeString() { | 44 Str executeStr(VirtualFrame frame) throws UnexpectedResultException { |
44 return new RuntimeString(execute().toString()); | 45 return SimpleTypesGen.SIMPLETYPES.expectStr(execute(frame)); |
45 } | 46 } |
46 | 47 |
47 @SuppressWarnings("static-method") | 48 abstract Object execute(VirtualFrame frame); |
48 final long executeSpecial() { | |
49 return 42L; | |
50 } | |
51 | |
52 abstract Object execute(); | |
53 } | 49 } |
54 | 50 |
55 @TypeSystemReference(SimpleTypes.class) | 51 @TypeSystemReference(SimpleTypes.class) |
56 static class TestRootNode extends RootNode { | 52 abstract static class ChildrenNode extends ValueNode { |
57 | 53 |
58 @Child private ValueNode node; | 54 @Children protected ValueNode[] children; |
59 | 55 |
60 public TestRootNode(ValueNode node) { | 56 public ChildrenNode(ValueNode... children) { |
57 this.children = adoptChildren(children); | |
58 } | |
59 | |
60 public ChildrenNode(ChildrenNode node) { | |
61 this(node.children); | |
62 } | |
63 | |
64 } | |
65 | |
66 @TypeSystemReference(SimpleTypes.class) | |
67 static class TestRootNode<E extends ValueNode> extends RootNode { | |
68 | |
69 @Child private E node; | |
70 | |
71 public TestRootNode(E node) { | |
61 this.node = adoptChild(node); | 72 this.node = adoptChild(node); |
62 } | 73 } |
63 | 74 |
64 @Override | 75 @Override |
65 public Object execute(VirtualFrame frame) { | 76 public Object execute(VirtualFrame frame) { |
66 return node.execute(); | 77 return node.execute(frame); |
78 } | |
79 | |
80 public E getNode() { | |
81 return node; | |
67 } | 82 } |
68 } | 83 } |
69 | 84 |
85 static class TestArguments extends Arguments { | |
86 | |
87 private final Object[] values; | |
88 | |
89 public TestArguments(Object... values) { | |
90 this.values = values; | |
91 } | |
92 | |
93 public Object[] getValues() { | |
94 return values; | |
95 } | |
96 | |
97 public Object get(int index) { | |
98 return values[index]; | |
99 } | |
100 | |
101 } | |
102 | |
103 static class ArgumentNode extends ValueNode { | |
104 | |
105 final int index; | |
106 | |
107 public ArgumentNode(int index) { | |
108 this.index = index; | |
109 } | |
110 | |
111 @Override | |
112 Object execute(VirtualFrame frame) { | |
113 return ((TestArguments) frame.getArguments()).get(index); | |
114 } | |
115 | |
116 } | |
117 | |
70 } | 118 } |