comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java @ 12645:60c32ab6eb39

add FrameUtil.get<Type>Safe methods that do not throw checked exceptions.
author Andreas Woess <andreas.woess@jku.at>
date Wed, 30 Oct 2013 19:50:11 +0100
parents 139b84d713bc
children 0046afcda972
comparison
equal deleted inserted replaced
12644:e122dc0436be 12645:60c32ab6eb39
107 * @param value the new value of the local variable 107 * @param value the new value of the local variable
108 */ 108 */
109 public static void setDoubleSafe(Frame frame, FrameSlot slot, double value) { 109 public static void setDoubleSafe(Frame frame, FrameSlot slot, double value) {
110 frame.setDouble(slot, value); 110 frame.setDouble(slot, value);
111 } 111 }
112
113 /**
114 * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by
115 * a guard or statically known).
116 *
117 * @param frameSlot the slot of the variable
118 * @throws IllegalStateException if the slot kind does not match
119 * @see Frame#getObject(FrameSlot)
120 */
121 public static Object getObjectSafe(Frame frame, FrameSlot frameSlot) {
122 try {
123 return frame.getObject(frameSlot);
124 } catch (FrameSlotTypeException e) {
125 throw new IllegalStateException();
126 }
127 }
128
129 /**
130 * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by
131 * a guard or statically known).
132 *
133 * @param frameSlot the slot of the variable
134 * @throws IllegalStateException if the slot kind does not match
135 * @see Frame#getByte(FrameSlot)
136 */
137 public static byte getByteSafe(Frame frame, FrameSlot frameSlot) {
138 try {
139 return frame.getByte(frameSlot);
140 } catch (FrameSlotTypeException e) {
141 throw new IllegalStateException();
142 }
143 }
144
145 /**
146 * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by
147 * a guard or statically known).
148 *
149 * @param frameSlot the slot of the variable
150 * @throws IllegalStateException if the slot kind does not match
151 * @see Frame#getBoolean(FrameSlot)
152 */
153 public static boolean getBooleanSafe(Frame frame, FrameSlot frameSlot) {
154 try {
155 return frame.getBoolean(frameSlot);
156 } catch (FrameSlotTypeException e) {
157 throw new IllegalStateException();
158 }
159 }
160
161 /**
162 * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by
163 * a guard or statically known).
164 *
165 * @param frameSlot the slot of the variable
166 * @throws IllegalStateException if the slot kind does not match
167 * @see Frame#getInt(FrameSlot)
168 */
169 public static int getIntSafe(Frame frame, FrameSlot frameSlot) {
170 try {
171 return frame.getInt(frameSlot);
172 } catch (FrameSlotTypeException e) {
173 throw new IllegalStateException();
174 }
175 }
176
177 /**
178 * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by
179 * a guard or statically known).
180 *
181 * @param frameSlot the slot of the variable
182 * @throws IllegalStateException if the slot kind does not match
183 * @see Frame#getLong(FrameSlot)
184 */
185 public static long getLongSafe(Frame frame, FrameSlot frameSlot) {
186 try {
187 return frame.getLong(frameSlot);
188 } catch (FrameSlotTypeException e) {
189 throw new IllegalStateException();
190 }
191 }
192
193 /**
194 * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by
195 * a guard or statically known).
196 *
197 * @param frameSlot the slot of the variable
198 * @throws IllegalStateException if the slot kind does not match
199 * @see Frame#getDouble(FrameSlot)
200 */
201 public static double getDoubleSafe(Frame frame, FrameSlot frameSlot) {
202 try {
203 return frame.getDouble(frameSlot);
204 } catch (FrameSlotTypeException e) {
205 throw new IllegalStateException();
206 }
207 }
208
209 /**
210 * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by
211 * a guard or statically known).
212 *
213 * @param frameSlot the slot of the variable
214 * @throws IllegalStateException if the slot kind does not match
215 * @see Frame#getFloat(FrameSlot)
216 */
217 public static float getFloatSafe(Frame frame, FrameSlot frameSlot) {
218 try {
219 return frame.getFloat(frameSlot);
220 } catch (FrameSlotTypeException e) {
221 throw new IllegalStateException();
222 }
223 }
112 } 224 }