Mercurial > hg > truffle
changeset 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 | e122dc0436be |
children | 0046afcda972 |
files | graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java |
diffstat | 1 files changed, 112 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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(); + } + } }