Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WriteLocalNode.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 | aa9ffb3a715e |
children | 8cf939b349dd |
comparison
equal
deleted
inserted
replaced
9257:542712a4732a | 9258:07f8d136a05e |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.sl.nodes; | 23 package com.oracle.truffle.sl.nodes; |
24 | 24 |
25 import java.math.*; | |
26 | |
27 import com.oracle.truffle.api.codegen.*; | 25 import com.oracle.truffle.api.codegen.*; |
28 import com.oracle.truffle.api.frame.*; | 26 import com.oracle.truffle.api.frame.*; |
29 | 27 |
30 @NodeChild(value = "rightNode", type = TypedNode.class) | 28 @NodeChild(value = "rightNode", type = TypedNode.class) |
31 public abstract class WriteLocalNode extends FrameSlotNode { | 29 public abstract class WriteLocalNode extends FrameSlotNode { |
36 | 34 |
37 public WriteLocalNode(WriteLocalNode node) { | 35 public WriteLocalNode(WriteLocalNode node) { |
38 this(node.slot); | 36 this(node.slot); |
39 } | 37 } |
40 | 38 |
41 @Specialization | 39 @Specialization(rewriteOn = FrameSlotTypeException.class) |
42 public int write(VirtualFrame frame, int right) { | 40 public int write(VirtualFrame frame, int right) throws FrameSlotTypeException { |
43 frame.setInt(slot, right); | 41 try { |
42 frame.setInt(slot, right); | |
43 } catch (FrameSlotTypeException e) { | |
44 if (slot.getType() == null) { | |
45 FrameUtil.setIntSafe(frame, slot, right); | |
46 } else { | |
47 throw e; | |
48 } | |
49 } | |
44 return right; | 50 return right; |
45 } | 51 } |
46 | 52 |
47 @Specialization | 53 @Specialization(rewriteOn = FrameSlotTypeException.class) |
48 public BigInteger write(VirtualFrame frame, BigInteger right) { | 54 public boolean write(VirtualFrame frame, boolean right) throws FrameSlotTypeException { |
49 frame.setObject(slot, right); | 55 try { |
50 return right; | 56 frame.setBoolean(slot, right); |
51 } | 57 } catch (FrameSlotTypeException e) { |
52 | 58 if (slot.getType() == null) { |
53 @Specialization | 59 FrameUtil.setBooleanSafe(frame, slot, right); |
54 public boolean write(VirtualFrame frame, boolean right) { | 60 } else { |
55 frame.setBoolean(slot, right); | 61 throw e; |
56 return right; | 62 } |
57 } | 63 } |
58 | |
59 @Specialization | |
60 public String write(VirtualFrame frame, String right) { | |
61 frame.setObject(slot, right); | |
62 return right; | 64 return right; |
63 } | 65 } |
64 | 66 |
65 @Generic(useSpecializations = false) | 67 @Generic(useSpecializations = false) |
66 public Object writeGeneric(VirtualFrame frame, Object right) { | 68 public Object writeGeneric(VirtualFrame frame, Object right) { |
67 frame.setObject(slot, right); | 69 try { |
70 frame.setObject(slot, right); | |
71 } catch (FrameSlotTypeException e) { | |
72 FrameUtil.setObjectSafe(frame, slot, right); | |
73 } | |
68 return right; | 74 return right; |
69 } | |
70 | |
71 @SpecializationListener | |
72 protected void onSpecialize(VirtualFrame frame, Object value) { | |
73 slot.setType(value.getClass()); | |
74 frame.updateToLatestVersion(); | |
75 } | 75 } |
76 | 76 |
77 @Override | 77 @Override |
78 protected FrameSlotNode specialize(Class<?> clazz) { | 78 protected FrameSlotNode specialize(Class<?> clazz) { |
79 return WriteLocalNodeFactory.createSpecialized(this, clazz); | 79 return WriteLocalNodeFactory.createSpecialized(this, clazz); |