Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TckLanguage.java @ 22499:9bba3a7b34be
Check foreign arguments when accessing ComplexNumber/Sequence objects
author | Matthias Grimmer <grimmer@ssw.jku.at> |
---|---|
date | Mon, 14 Dec 2015 15:07:19 +0100 |
parents | fb607f23d1eb |
children |
comparison
equal
deleted
inserted
replaced
22498:ec40768d77a6 | 22499:9bba3a7b34be |
---|---|
23 * questions. | 23 * questions. |
24 */ | 24 */ |
25 package com.oracle.truffle.tck; | 25 package com.oracle.truffle.tck; |
26 | 26 |
27 import com.oracle.truffle.api.CallTarget; | 27 import com.oracle.truffle.api.CallTarget; |
28 import com.oracle.truffle.api.CompilerDirectives; | |
28 import com.oracle.truffle.api.Truffle; | 29 import com.oracle.truffle.api.Truffle; |
29 import com.oracle.truffle.api.TruffleLanguage; | 30 import com.oracle.truffle.api.TruffleLanguage; |
30 import com.oracle.truffle.api.TruffleLanguage.Env; | 31 import com.oracle.truffle.api.TruffleLanguage.Env; |
31 import com.oracle.truffle.api.frame.MaterializedFrame; | 32 import com.oracle.truffle.api.frame.MaterializedFrame; |
32 import com.oracle.truffle.api.frame.VirtualFrame; | 33 import com.oracle.truffle.api.frame.VirtualFrame; |
36 import com.oracle.truffle.api.interop.Message; | 37 import com.oracle.truffle.api.interop.Message; |
37 import com.oracle.truffle.api.interop.TruffleObject; | 38 import com.oracle.truffle.api.interop.TruffleObject; |
38 import com.oracle.truffle.api.nodes.Node; | 39 import com.oracle.truffle.api.nodes.Node; |
39 import com.oracle.truffle.api.nodes.RootNode; | 40 import com.oracle.truffle.api.nodes.RootNode; |
40 import com.oracle.truffle.api.source.Source; | 41 import com.oracle.truffle.api.source.Source; |
42 | |
41 import java.io.IOException; | 43 import java.io.IOException; |
42 | 44 |
43 @TruffleLanguage.Registration(mimeType = "application/x-tck", name = "TCK", version = "1.0") | 45 @TruffleLanguage.Registration(mimeType = "application/x-tck", name = "TCK", version = "1.0") |
44 public final class TckLanguage extends TruffleLanguage<Env> { | 46 public final class TckLanguage extends TruffleLanguage<Env> { |
45 public static final TckLanguage INSTANCE = new TckLanguage(); | 47 public static final TckLanguage INSTANCE = new TckLanguage(); |
142 throw new IllegalArgumentException("" + tree); | 144 throw new IllegalArgumentException("" + tree); |
143 } | 145 } |
144 } | 146 } |
145 | 147 |
146 } | 148 } |
149 | |
150 public static Number expectNumber(Object o) { | |
151 if (o instanceof Number) { | |
152 return (Number) o; | |
153 } | |
154 CompilerDirectives.transferToInterpreter(); | |
155 throw new IllegalArgumentException(o + " not a Number"); | |
156 } | |
157 | |
158 public static String expectString(Object o) { | |
159 if (o instanceof String) { | |
160 return (String) o; | |
161 } | |
162 CompilerDirectives.transferToInterpreter(); | |
163 throw new IllegalArgumentException(o + " not a String"); | |
164 } | |
165 | |
166 public static TruffleObject expectTruffleObject(Object o) { | |
167 if (o instanceof TruffleObject) { | |
168 return (TruffleObject) o; | |
169 } | |
170 CompilerDirectives.transferToInterpreter(); | |
171 throw new IllegalArgumentException(o + " not a TruffleObject"); | |
172 } | |
173 | |
174 public static int checkBounds(int idx, int size) { | |
175 if (idx < 0 || idx >= size) { | |
176 CompilerDirectives.transferToInterpreter(); | |
177 throw new IndexOutOfBoundsException("Index: " + idx + " Size: " + size); | |
178 } | |
179 return idx; | |
180 } | |
181 | |
147 } | 182 } |