Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/frame/FrameUtil.java @ 9258:07f8d136a05e
Truffle API changes for the Frame API. Introduction of Assumptions class.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 23 Apr 2013 15:34:06 +0200 |
parents | |
children | cd1a1d92b3e3 |
comparison
equal
deleted
inserted
replaced
9257:542712a4732a | 9258:07f8d136a05e |
---|---|
1 /* | |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.frame; | |
24 | |
25 public final class FrameUtil { | |
26 | |
27 /** | |
28 * Write access to a local variable of type {@link Object}. | |
29 * | |
30 * Sets the frame slot type to {@link Object} if it isn't already. | |
31 * | |
32 * @param slot the slot of the local variable | |
33 * @param value the new value of the local variable | |
34 */ | |
35 public static void setObjectSafe(Frame frame, FrameSlot slot, Object value) { | |
36 if (slot.getType() != Object.class) { | |
37 slot.setType(Object.class); | |
38 } | |
39 try { | |
40 frame.setObject(slot, value); | |
41 } catch (FrameSlotTypeException e) { | |
42 throw new IllegalStateException(); | |
43 } | |
44 } | |
45 | |
46 /** | |
47 * Write access to a local variable of type {@code boolean}. | |
48 * | |
49 * Sets the frame slot type to {@code boolean} if it isn't already. | |
50 * | |
51 * @param slot the slot of the local variable | |
52 * @param value the new value of the local variable | |
53 */ | |
54 public static void setBooleanSafe(Frame frame, FrameSlot slot, boolean value) { | |
55 if (slot.getType() != boolean.class) { | |
56 slot.setType(boolean.class); | |
57 } | |
58 try { | |
59 frame.setBoolean(slot, value); | |
60 } catch (FrameSlotTypeException e) { | |
61 throw new IllegalStateException(); | |
62 } | |
63 } | |
64 | |
65 /** | |
66 * Write access to a local variable of type {@code int}. | |
67 * | |
68 * Sets the frame slot type to {@code int} if it isn't already. | |
69 * | |
70 * @param slot the slot of the local variable | |
71 * @param value the new value of the local variable | |
72 */ | |
73 public static void setIntSafe(Frame frame, FrameSlot slot, int value) { | |
74 if (slot.getType() != int.class) { | |
75 slot.setType(int.class); | |
76 } | |
77 try { | |
78 frame.setInt(slot, value); | |
79 } catch (FrameSlotTypeException e) { | |
80 throw new IllegalStateException(); | |
81 } | |
82 } | |
83 | |
84 /** | |
85 * Write access to a local variable of type {@code long}. | |
86 * | |
87 * Sets the frame slot type to {@code long} if it isn't already. | |
88 * | |
89 * @param slot the slot of the local variable | |
90 * @param value the new value of the local variable | |
91 */ | |
92 public static void setLongSafe(Frame frame, FrameSlot slot, long value) { | |
93 if (slot.getType() != long.class) { | |
94 slot.setType(long.class); | |
95 } | |
96 try { | |
97 frame.setLong(slot, value); | |
98 } catch (FrameSlotTypeException e) { | |
99 throw new IllegalStateException(); | |
100 } | |
101 } | |
102 | |
103 /** | |
104 * Write access to a local variable of type {@code float}. | |
105 * | |
106 * Sets the frame slot type to {@code float} if it isn't already. | |
107 * | |
108 * @param slot the slot of the local variable | |
109 * @param value the new value of the local variable | |
110 */ | |
111 public static void setFloatSafe(Frame frame, FrameSlot slot, float value) { | |
112 if (slot.getType() != float.class) { | |
113 slot.setType(float.class); | |
114 } | |
115 try { | |
116 frame.setFloat(slot, value); | |
117 } catch (FrameSlotTypeException e) { | |
118 throw new IllegalStateException(); | |
119 } | |
120 } | |
121 | |
122 /** | |
123 * Write access to a local variable of type {@code double}. | |
124 * | |
125 * Sets the frame slot type to {@code double} if it isn't already. | |
126 * | |
127 * @param slot the slot of the local variable | |
128 * @param value the new value of the local variable | |
129 */ | |
130 public static void setDoubleSafe(Frame frame, FrameSlot slot, double value) { | |
131 if (slot.getType() != double.class) { | |
132 slot.setType(double.class); | |
133 } | |
134 try { | |
135 frame.setDouble(slot, value); | |
136 } catch (FrameSlotTypeException e) { | |
137 throw new IllegalStateException(); | |
138 } | |
139 } | |
140 } |