added BitVector.setImmutable(), use it in Instruction.Shift()
authoradam <adam@megacz.com>
Wed, 25 Jun 2008 10:25:26 +0000 (11:25 +0100)
committeradam <adam@megacz.com>
Wed, 25 Jun 2008 10:25:26 +0000 (11:25 +0100)
src/edu/berkeley/fleet/api/BitVector.java
src/edu/berkeley/fleet/api/Instruction.java

index e217e6c..e7b3061 100644 (file)
@@ -9,12 +9,15 @@ public class BitVector {
 
     private final boolean[] bits;
 
+    private boolean immutable = false;
+
     public BitVector(int length) {
         this.bits = new boolean[length];
     }
 
-    /** copy the low-order bits of the argument into this BitVector; returns this */
+    /** copy the low-order bits of the argument into this BitVector; returns <tt>this</tt> */
     public BitVector set(long value) {
+        if (immutable) throw new RuntimeException("attempt to modify an immutable BitVector");
         for(int i=0; i<length(); i++)
             set(i, ((value >>> i) & 1L) != 0);
         return this;
@@ -25,6 +28,7 @@ public class BitVector {
     }
     
     public void set(int bit, boolean value) {
+        if (immutable) throw new RuntimeException("attempt to modify an immutable BitVector");
         bits[bit] = value;
     }
 
@@ -40,6 +44,10 @@ public class BitVector {
             ret.append(get(i) ? '1' : '0');
         return ret.toString();
     }
+
+    public void setImmutable() {
+        immutable = true;
+    }
 }
 
 
index f889393..963e57b 100644 (file)
@@ -229,6 +229,7 @@ public abstract class Instruction {
         public Shift(Dock dock, boolean looping, Predicate predicate, BitVector immediate) {
             super(dock, looping, predicate);
             this.immediate = immediate;
+            this.immediate.setImmutable();
         }
         public String toString() { return super.toString()+"shift "+immediate; }
     }