# HG changeset patch # User Andreas Woess # Date 1383159011 -3600 # Node ID 60c32ab6eb39cb369f2b45da6684b257c11f940e # Parent e122dc0436be2d4a9d0d2049b6220574f0733350 add FrameUtil.getSafe methods that do not throw checked exceptions. diff -r e122dc0436be -r 60c32ab6eb39 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java Wed Oct 30 19:05:29 2013 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java Wed Oct 30 19:50:11 2013 +0100 @@ -109,4 +109,116 @@ public static void setDoubleSafe(Frame frame, FrameSlot slot, double value) { frame.setDouble(slot, value); } + + /** + * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by + * a guard or statically known). + * + * @param frameSlot the slot of the variable + * @throws IllegalStateException if the slot kind does not match + * @see Frame#getObject(FrameSlot) + */ + public static Object getObjectSafe(Frame frame, FrameSlot frameSlot) { + try { + return frame.getObject(frameSlot); + } catch (FrameSlotTypeException e) { + throw new IllegalStateException(); + } + } + + /** + * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by + * a guard or statically known). + * + * @param frameSlot the slot of the variable + * @throws IllegalStateException if the slot kind does not match + * @see Frame#getByte(FrameSlot) + */ + public static byte getByteSafe(Frame frame, FrameSlot frameSlot) { + try { + return frame.getByte(frameSlot); + } catch (FrameSlotTypeException e) { + throw new IllegalStateException(); + } + } + + /** + * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by + * a guard or statically known). + * + * @param frameSlot the slot of the variable + * @throws IllegalStateException if the slot kind does not match + * @see Frame#getBoolean(FrameSlot) + */ + public static boolean getBooleanSafe(Frame frame, FrameSlot frameSlot) { + try { + return frame.getBoolean(frameSlot); + } catch (FrameSlotTypeException e) { + throw new IllegalStateException(); + } + } + + /** + * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by + * a guard or statically known). + * + * @param frameSlot the slot of the variable + * @throws IllegalStateException if the slot kind does not match + * @see Frame#getInt(FrameSlot) + */ + public static int getIntSafe(Frame frame, FrameSlot frameSlot) { + try { + return frame.getInt(frameSlot); + } catch (FrameSlotTypeException e) { + throw new IllegalStateException(); + } + } + + /** + * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by + * a guard or statically known). + * + * @param frameSlot the slot of the variable + * @throws IllegalStateException if the slot kind does not match + * @see Frame#getLong(FrameSlot) + */ + public static long getLongSafe(Frame frame, FrameSlot frameSlot) { + try { + return frame.getLong(frameSlot); + } catch (FrameSlotTypeException e) { + throw new IllegalStateException(); + } + } + + /** + * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by + * a guard or statically known). + * + * @param frameSlot the slot of the variable + * @throws IllegalStateException if the slot kind does not match + * @see Frame#getDouble(FrameSlot) + */ + public static double getDoubleSafe(Frame frame, FrameSlot frameSlot) { + try { + return frame.getDouble(frameSlot); + } catch (FrameSlotTypeException e) { + throw new IllegalStateException(); + } + } + + /** + * Read a frame slot that is guaranteed to be of the desired kind (either previously checked by + * a guard or statically known). + * + * @param frameSlot the slot of the variable + * @throws IllegalStateException if the slot kind does not match + * @see Frame#getFloat(FrameSlot) + */ + public static float getFloatSafe(Frame frame, FrameSlot frameSlot) { + try { + return frame.getFloat(frameSlot); + } catch (FrameSlotTypeException e) { + throw new IllegalStateException(); + } + } }