Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/FrameTest.java @ 13875:042a2d972174
support frame slot removal
author | Michael Haupt <michael.haupt@oracle.com> |
---|---|
date | Wed, 05 Feb 2014 11:40:13 +0100 |
parents | 193e3917dc07 |
children | a08b8694f556 |
comparison
equal
deleted
inserted
replaced
13870:d04be74665fb | 13875:042a2d972174 |
---|---|
35 * The frame is the preferred data structure for passing values between nodes. It can in particular | 35 * The frame is the preferred data structure for passing values between nodes. It can in particular |
36 * be used for storing the values of local variables of the guest language. The | 36 * be used for storing the values of local variables of the guest language. The |
37 * {@link FrameDescriptor} represents the current structure of the frame. The method | 37 * {@link FrameDescriptor} represents the current structure of the frame. The method |
38 * {@link FrameDescriptor#addFrameSlot(Object, FrameSlotKind)} can be used to create predefined | 38 * {@link FrameDescriptor#addFrameSlot(Object, FrameSlotKind)} can be used to create predefined |
39 * frame slots. The setter and getter methods in the {@link Frame} class can be used to access the | 39 * frame slots. The setter and getter methods in the {@link Frame} class can be used to access the |
40 * current value of a particular frame slot. | 40 * current value of a particular frame slot. Values can be removed from a frame via the |
41 * {@link FrameDescriptor#removeFrameSlot(Object)} method. | |
41 * </p> | 42 * </p> |
42 * | 43 * |
43 * <p> | 44 * <p> |
44 * There are five primitive types for slots available: {@link java.lang.Boolean}, | 45 * There are five primitive types for slots available: {@link java.lang.Boolean}, |
45 * {@link java.lang.Integer}, {@link java.lang.Long}, {@link java.lang.Float}, and | 46 * {@link java.lang.Integer}, {@link java.lang.Long}, {@link java.lang.Float}, and |
62 | 63 |
63 @Test | 64 @Test |
64 public void test() { | 65 public void test() { |
65 TruffleRuntime runtime = Truffle.getRuntime(); | 66 TruffleRuntime runtime = Truffle.getRuntime(); |
66 FrameDescriptor frameDescriptor = new FrameDescriptor(); | 67 FrameDescriptor frameDescriptor = new FrameDescriptor(); |
67 FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int); | 68 String varName = "localVar"; |
69 FrameSlot slot = frameDescriptor.addFrameSlot(varName, FrameSlotKind.Int); | |
68 TestRootNode rootNode = new TestRootNode(frameDescriptor, new AssignLocal(slot), new ReadLocal(slot)); | 70 TestRootNode rootNode = new TestRootNode(frameDescriptor, new AssignLocal(slot), new ReadLocal(slot)); |
69 CallTarget target = runtime.createCallTarget(rootNode); | 71 CallTarget target = runtime.createCallTarget(rootNode); |
70 Object result = target.call(); | 72 Object result = target.call(); |
71 Assert.assertEquals(42, result); | 73 Assert.assertEquals(42, result); |
74 frameDescriptor.removeFrameSlot(varName); | |
75 boolean slotMissing = false; | |
76 try { | |
77 result = target.call(); | |
78 } catch (IllegalArgumentException iae) { | |
79 slotMissing = true; | |
80 } | |
81 Assert.assertTrue(slotMissing); | |
72 } | 82 } |
73 | 83 |
74 class TestRootNode extends RootNode { | 84 class TestRootNode extends RootNode { |
75 | 85 |
76 @Child TestChildNode left; | 86 @Child TestChildNode left; |