changeset 9278:8cf939b349dd

Frame API: automatically change frame slot type for uninitialized slots
author Andreas Woess <andreas.woess@jku.at>
date Wed, 24 Apr 2013 14:14:22 +0200
parents 1fcaf6edc69d
children c62bf8be5caf
files graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WriteLocalNode.java
diffstat 4 files changed, 16 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java	Wed Apr 24 13:35:14 2013 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/DefaultVirtualFrame.java	Wed Apr 24 14:14:22 2013 +0200
@@ -156,8 +156,13 @@
     }
 
     private void verifySet(FrameSlot slot, Class accessType) throws FrameSlotTypeException {
-        if (slot.getType() != accessType) {
-            throw new FrameSlotTypeException();
+        Class<?> slotType = slot.getType();
+        if (slotType != accessType) {
+            if (slotType == null) {
+                slot.setType(accessType);
+            } else {
+                throw new FrameSlotTypeException();
+            }
         }
         int slotIndex = slot.getIndex();
         if (slotIndex >= tags.length) {
@@ -168,25 +173,21 @@
 
     private void verifyGet(FrameSlot slot, Class accessType) throws FrameSlotTypeException {
         Class<?> slotType = slot.getType();
-        int slotIndex = slot.getIndex();
         if (slotType != accessType) {
-            if (slotType == null) {
+            if (slotType == null && accessType == Object.class) {
                 slot.setType(Object.class);
                 this.setObject(slot, descriptor.getTypeConversion().getDefaultValue());
-                if (accessType != Object.class) {
-                    throw new FrameSlotTypeException();
-                }
             } else {
                 throw new FrameSlotTypeException();
             }
         }
+        int slotIndex = slot.getIndex();
         if (slotIndex >= tags.length) {
             resize();
         }
-        Class tag = tags[slotIndex];
-        if (tag != slotType) {
+        if (tags[slotIndex] != accessType) {
             descriptor.getTypeConversion().updateFrameSlot(this, slot, getValue(slot));
-            if (tags[slotIndex] != slotType) {
+            if (tags[slotIndex] != accessType) {
                 throw new FrameSlotTypeException();
             }
         }
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java	Wed Apr 24 13:35:14 2013 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java	Wed Apr 24 14:14:22 2013 +0200
@@ -100,9 +100,6 @@
             this.parentOffset = parentOffsetTemp;
         }
 
-        /**
-         * (db) getters added to support AST cloning for parallel execution.
-         */
         public long getParentOffset() {
             return parentOffset;
         }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java	Wed Apr 24 13:35:14 2013 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java	Wed Apr 24 14:14:22 2013 +0200
@@ -59,7 +59,7 @@
     }
 
     public TypedNode createLocal(String name) {
-        return ReadLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, Integer.class));
+        return ReadLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, int.class));
     }
 
     public TypedNode createStringLiteral(String value) {
@@ -67,7 +67,7 @@
     }
 
     public StatementNode createAssignment(String name, TypedNode right) {
-        return WriteLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, Integer.class), right);
+        return WriteLocalNodeFactory.create(frameDescriptor.findOrAddFrameSlot(name, int.class), right);
     }
 
     public StatementNode createPrint(List<TypedNode> expressions) {
@@ -123,7 +123,7 @@
     }
 
     public StatementNode createReturn(TypedNode value) {
-        FrameSlot slot = frameDescriptor.findOrAddFrameSlot("<retval>", Integer.class);
+        FrameSlot slot = frameDescriptor.findOrAddFrameSlot("<retval>", int.class);
         if (returnValue == null) {
             returnValue = ReadLocalNodeFactory.create(slot);
         }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WriteLocalNode.java	Wed Apr 24 13:35:14 2013 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/WriteLocalNode.java	Wed Apr 24 14:14:22 2013 +0200
@@ -38,29 +38,13 @@
 
     @Specialization(rewriteOn = FrameSlotTypeException.class)
     public int write(VirtualFrame frame, int right) throws FrameSlotTypeException {
-        try {
-            frame.setInt(slot, right);
-        } catch (FrameSlotTypeException e) {
-            if (slot.getType() == null) {
-                FrameUtil.setIntSafe(frame, slot, right);
-            } else {
-                throw e;
-            }
-        }
+        frame.setInt(slot, right);
         return right;
     }
 
     @Specialization(rewriteOn = FrameSlotTypeException.class)
     public boolean write(VirtualFrame frame, boolean right) throws FrameSlotTypeException {
-        try {
-            frame.setBoolean(slot, right);
-        } catch (FrameSlotTypeException e) {
-            if (slot.getType() == null) {
-                FrameUtil.setBooleanSafe(frame, slot, right);
-            } else {
-                throw e;
-            }
-        }
+        frame.setBoolean(slot, right);
         return right;
     }