Integrated new types, tests still work, not used yet
authorChristian Femers <femers@in.tum.de>
Mon, 20 May 2019 15:11:13 +0000 (17:11 +0200)
committerChristian Femers <femers@in.tum.de>
Mon, 20 May 2019 15:11:13 +0000 (17:11 +0200)
most changes are just imports

20 files changed:
era.mi/src/era/mi/logic/Bit.java [deleted file]
era.mi/src/era/mi/logic/Util.java
era.mi/src/era/mi/logic/components/BasicComponent.java
era.mi/src/era/mi/logic/components/BitDisplay.java
era.mi/src/era/mi/logic/components/Clock.java
era.mi/src/era/mi/logic/components/Connector.java
era.mi/src/era/mi/logic/components/ManualSwitch.java
era.mi/src/era/mi/logic/components/Merger.java
era.mi/src/era/mi/logic/components/Splitter.java
era.mi/src/era/mi/logic/components/TriStateBuffer.java
era.mi/src/era/mi/logic/components/gates/MultiInputGate.java
era.mi/src/era/mi/logic/tests/ComponentTest.java
era.mi/src/era/mi/logic/tests/TestBitDisplay.java
era.mi/src/era/mi/logic/types/Bit.java [new file with mode: 0644]
era.mi/src/era/mi/logic/types/BitVector.java [new file with mode: 0644]
era.mi/src/era/mi/logic/types/LogicType.java [new file with mode: 0644]
era.mi/src/era/mi/logic/types/MutationOperation.java [new file with mode: 0644]
era.mi/src/era/mi/logic/types/StrictLogicType.java [new file with mode: 0644]
era.mi/src/era/mi/logic/wires/Wire.java
era.mi/src/era/mi/logic/wires/WireObserver.java

diff --git a/era.mi/src/era/mi/logic/Bit.java b/era.mi/src/era/mi/logic/Bit.java
deleted file mode 100644 (file)
index da9a227..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-package era.mi.logic;
-
-import java.util.Arrays;
-
-/**
- * stdlogic according to IEEE 1164
- */
-public enum Bit
-{
-       U, X, ZERO, ONE, Z;
-
-       public static Bit and(Bit a, Bit b)
-       {
-               return a.and(b);
-       }
-
-       public Bit and(Bit other)
-       {
-               return fromTable(AND_TABLE, this, other);
-       }
-
-       public static Bit or(Bit a, Bit b)
-       {
-               return a.or(b);
-       }
-
-       public Bit or(Bit other)
-       {
-               return fromTable(OR_TABLE, this, other);
-       }
-
-       public static Bit xor(Bit a, Bit b)
-       {
-               return a.xor(b);
-       }
-
-       public Bit xor(Bit other)
-       {
-               return fromTable(XOR_TABLE, this, other);
-       }
-
-       public Bit not()
-       {
-               switch (this)
-               {
-               case U:
-                       return U;
-               case ONE:
-                       return ZERO;
-               case ZERO:
-                       return ONE;
-               default:
-                       return X;
-               }
-       }
-
-       public Bit[] makeArray(int length)
-       {
-               Bit[] bits = new Bit[length];
-               Arrays.fill(bits, this);
-               return bits;
-       }
-
-       public Bit combineWith(Bit other)
-       {
-               return fromTable(JOIN_TABLE, this, other);
-       }
-
-       public static Bit combine(Bit a, Bit b)
-       {
-               return a.combineWith(b);
-       }
-
-       private static Bit fromTable(Bit[][] table, Bit a, Bit b)
-       {
-               return table[a.ordinal()][b.ordinal()];
-       }
-
-       // @formatter:off
-       private static Bit[][] JOIN_TABLE = 
-               { { U, U, U,    U,   U    }, 
-                 { U, X, X,    X,   X    }, 
-                 { U, X, ZERO, X,   ZERO },
-                 { U, X, X,    ONE, ONE  }, 
-                 { U, X, ZERO, ONE, Z    } };
-
-       private static Bit[][] AND_TABLE = 
-               { { U,    U,    ZERO, U,    U    }, 
-                 { U,    X,    ZERO, X,    X    },
-                 { ZERO, ZERO, ZERO, ZERO, ZERO }, 
-                 { U,    X,    ZERO, ONE,  X    }, 
-                 { U,    X,    ZERO, X,    X    } };
-
-       private static Bit[][] OR_TABLE =
-       { { U,   U,   U,    ONE, U    },    
-         { U,   X,   X,    ONE, X    },    
-         { U,   X,   ZERO, ONE, X    },    
-         { ONE, ONE, ONE,  ONE, ONE  },    
-         { U,   X,   X,    ONE, X    } };
-       
-       private static Bit[][] XOR_TABLE =
-       { { U, U, U,    U,    U },    
-         { U, X, X,    X,    X },    
-         { U, X, ZERO, ONE,  X },    
-         { U, X, ONE,  ZERO, X },    
-         { U, X, X,    X,    X } }; 
-       // @formatter:on
-}
\ No newline at end of file
index b7402c2..d621a44 100644 (file)
@@ -2,6 +2,8 @@ package era.mi.logic;
 
 import java.util.Arrays;
 
+import era.mi.logic.types.Bit;
+
 public final class Util
 {
 
@@ -50,17 +52,17 @@ public final class Util
 
        public static Bit[] and(Bit[] a, Bit[] b)
        {
-               return binBitOp(a, b, (bA, bB) -> Bit.and(bA, bB));
+               return binBitOp(a, b, Bit::and);
        }
 
        public static Bit[] or(Bit[] a, Bit[] b)
        {
-               return binBitOp(a, b, (bA, bB) -> Bit.or(bA, bB));
+               return binBitOp(a, b, Bit::or);
        }
 
        public static Bit[] xor(Bit[] a, Bit[] b)
        {
-               return binBitOp(a, b, (bA, bB) -> Bit.xor(bA, bB));
+               return binBitOp(a, b, Bit::xor);
        }
 
        private static Bit[] binBitOp(Bit[] a, Bit[] b, BitOp op)
@@ -96,7 +98,7 @@ public final class Util
                        throw new IllegalArgumentException("Bit Arrays were not of equal length.");
                for (int i = 0; i < addition.length; i++)
                {
-                       dest[i] = dest[i].combineWith(addition[i]);
+                       dest[i] = dest[i].join(addition[i]);
                }
                return dest;
        }
index 7cebc60..0a22950 100644 (file)
@@ -1,7 +1,7 @@
 package era.mi.logic.components;
 
-import era.mi.logic.Bit;
 import era.mi.logic.Simulation;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire;
 import era.mi.logic.wires.WireObserver;
 
index 88a1053..3da693b 100644 (file)
@@ -3,7 +3,7 @@ package era.mi.logic.components;
 import java.util.Arrays;
 import java.util.List;
 
-import era.mi.logic.Bit;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire.WireEnd;
 
 public class BitDisplay extends BasicComponent
index d638617..07419b4 100644 (file)
@@ -2,10 +2,10 @@ package era.mi.logic.components;
 
 import java.util.List;
 
-import era.mi.logic.Bit;
 import era.mi.logic.Simulation;
 import era.mi.logic.timeline.TimelineEvent;
 import era.mi.logic.timeline.TimelineEventHandler;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire;
 import era.mi.logic.wires.Wire.WireEnd;
 
index 47cf901..aa8c437 100644 (file)
@@ -2,8 +2,8 @@ package era.mi.logic.components;
 
 import java.util.List;
 
-import era.mi.logic.Bit;
 import era.mi.logic.Simulation;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire;
 import era.mi.logic.wires.Wire.WireEnd;
 import era.mi.logic.wires.WireObserver;
index 19ece81..0ad4a76 100644 (file)
@@ -2,7 +2,7 @@ package era.mi.logic.components;
 
 import java.util.List;
 
-import era.mi.logic.Bit;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire.WireEnd;
 
 /**
index 613d523..ca441ba 100644 (file)
@@ -2,7 +2,7 @@ package era.mi.logic.components;
 
 import java.util.List;
 
-import era.mi.logic.Bit;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire;
 import era.mi.logic.wires.Wire.WireEnd;
 import era.mi.logic.wires.WireObserver;
index be8be82..09321f1 100644 (file)
@@ -1,6 +1,6 @@
 package era.mi.logic.components;
 
-import era.mi.logic.Bit;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire;
 import era.mi.logic.wires.Wire.WireEnd;
 import era.mi.logic.wires.WireObserver;
index 920c2ec..c0dd76e 100644 (file)
@@ -2,7 +2,7 @@ package era.mi.logic.components;
 
 import java.util.List;
 
-import era.mi.logic.Bit;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire.WireEnd;
 
 public class TriStateBuffer extends BasicComponent
index 0a9340c..2b0a529 100644 (file)
@@ -2,8 +2,8 @@ package era.mi.logic.components.gates;
 
 import java.util.List;
 
-import era.mi.logic.Bit;
 import era.mi.logic.components.BasicComponent;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire.WireEnd;
 
 public abstract class MultiInputGate extends BasicComponent
index f6d801f..cb2195e 100644 (file)
@@ -1,16 +1,12 @@
 package era.mi.logic.tests;
 
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.*;
 
 import java.util.Arrays;
 import java.util.function.LongConsumer;
 
 import org.junit.jupiter.api.Test;
 
-import era.mi.logic.Bit;
 import era.mi.logic.Simulation;
 import era.mi.logic.components.Connector;
 import era.mi.logic.components.Demux;
@@ -22,6 +18,7 @@ import era.mi.logic.components.gates.AndGate;
 import era.mi.logic.components.gates.NotGate;
 import era.mi.logic.components.gates.OrGate;
 import era.mi.logic.components.gates.XorGate;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire;
 import era.mi.logic.wires.Wire.WireEnd;
 
index 0d97659..a07125d 100644 (file)
@@ -5,9 +5,9 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import java.util.Arrays;
 import java.util.function.LongConsumer;
 
-import era.mi.logic.Bit;
 import era.mi.logic.Simulation;
 import era.mi.logic.components.BitDisplay;
+import era.mi.logic.types.Bit;
 import era.mi.logic.wires.Wire.WireEnd;
 
 public final class TestBitDisplay extends BitDisplay
diff --git a/era.mi/src/era/mi/logic/types/Bit.java b/era.mi/src/era/mi/logic/types/Bit.java
new file mode 100644 (file)
index 0000000..6674f9a
--- /dev/null
@@ -0,0 +1,132 @@
+package era.mi.logic.types;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * stdlogic according to IEEE 1164
+ */
+public enum Bit implements StrictLogicType<Bit>
+{
+       U("U"), X("X"), ZERO("0"), ONE("1"), Z("Z");
+
+       private final String symbol;
+
+       private Bit(String symbol)
+       {
+               this.symbol = symbol;
+       }
+
+       @Override
+       public Bit and(Bit other)
+       {
+               return fromTable(AND_TABLE, this, other);
+       }
+
+       @Override
+       public Bit or(Bit other)
+       {
+               return fromTable(OR_TABLE, this, other);
+       }
+
+       @Override
+       public Bit xor(Bit other)
+       {
+               return fromTable(XOR_TABLE, this, other);
+       }
+
+       @Override
+       public Bit not()
+       {
+               switch (this)
+               {
+               case U:
+                       return U;
+               case ONE:
+                       return ZERO;
+               case ZERO:
+                       return ONE;
+               default:
+                       return X;
+               }
+       }
+
+       public Bit[] makeArray(int length)
+       {
+               Bit[] bits = new Bit[length];
+               Arrays.fill(bits, this);
+               return bits;
+       }
+
+       public BitVector toVector(int length)
+       {
+               return BitVector.of(this, length);
+       }
+
+       @Override
+       public Bit join(Bit other)
+       {
+               return fromTable(JOIN_TABLE, this, other);
+       }
+
+       @Override
+       public String toString()
+       {
+               return getSymbol();
+       }
+
+       public String getSymbol()
+       {
+               return symbol;
+       }
+
+       public static Bit parse(String s)
+       {
+               Bit bit = SYMBOL_MAP.get(s);
+               Objects.requireNonNull(bit, "No Bit found for symbol " + s);
+               return bit;
+       }
+
+       public static Bit parse(String s, int symbolPosition)
+       {
+               return parse(s.substring(symbolPosition, symbolPosition + 1));
+       }
+
+       private static Bit fromTable(Bit[][] table, Bit a, Bit b)
+       {
+               return table[a.ordinal()][b.ordinal()];
+       }
+
+       static final Map<String, Bit> SYMBOL_MAP = Map.of(U.symbol, U, X.symbol, X, ZERO.symbol, ZERO, ONE.symbol, ONE, Z.symbol, Z);
+
+       // @formatter:off
+       private static final Bit[][] JOIN_TABLE = 
+               { { U, U, U,    U,   U    }, 
+                 { U, X, X,    X,   X    }, 
+                 { U, X, ZERO, X,   ZERO },
+                 { U, X, X,    ONE, ONE  }, 
+                 { U, X, ZERO, ONE, Z    } };
+
+       private static final Bit[][] AND_TABLE = 
+               { { U,    U,    ZERO, U,    U    }, 
+                 { U,    X,    ZERO, X,    X    },
+                 { ZERO, ZERO, ZERO, ZERO, ZERO }, 
+                 { U,    X,    ZERO, ONE,  X    }, 
+                 { U,    X,    ZERO, X,    X    } };
+
+       private static final Bit[][] OR_TABLE =
+       { { U,   U,   U,    ONE, U    },    
+         { U,   X,   X,    ONE, X    },    
+         { U,   X,   ZERO, ONE, X    },    
+         { ONE, ONE, ONE,  ONE, ONE  },    
+         { U,   X,   X,    ONE, X    } };
+       
+       private static final Bit[][] XOR_TABLE =
+       { { U, U, U,    U,    U },    
+         { U, X, X,    X,    X },    
+         { U, X, ZERO, ONE,  X },    
+         { U, X, ONE,  ZERO, X },    
+         { U, X, X,    X,    X } }; 
+       // @formatter:on
+}
\ No newline at end of file
diff --git a/era.mi/src/era/mi/logic/types/BitVector.java b/era.mi/src/era/mi/logic/types/BitVector.java
new file mode 100644 (file)
index 0000000..51545f7
--- /dev/null
@@ -0,0 +1,316 @@
+package era.mi.logic.types;
+
+import static java.lang.String.format;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Objects;
+import java.util.RandomAccess;
+import java.util.function.BinaryOperator;
+import java.util.function.UnaryOperator;
+
+/**
+ * Immutable class representing a {@link Bit}Vector
+ *
+ *
+ * @author Christian Femers
+ *
+ */
+public final class BitVector implements StrictLogicType<BitVector>, Iterable<Bit>, RandomAccess
+{
+       private final Bit[] bits;
+
+       private BitVector(Bit[] bits)
+       {
+               this.bits = Objects.requireNonNull(bits);
+       }
+
+       public static BitVector of(Bit... bits)
+       {
+               return new BitVector(bits.clone());
+       }
+
+       public static BitVector of(Bit bit, int length)
+       {
+               return new BitVector(bit.makeArray(length));
+       }
+
+       public BitVectorMutator mutator()
+       {
+               return BitVectorMutator.of(this);
+       }
+
+       public Bit getBit(int bitIndex)
+       {
+               return bits[bitIndex];
+       }
+
+       public Bit[] getBits()
+       {
+               return bits.clone();
+       }
+
+       @Override
+       public BitVector join(BitVector t)
+       {
+               checkCompatibility(t);
+               return new BitVector(binOp(bits.clone(), t.bits, Bit::join));
+       }
+
+       @Override
+       public BitVector and(BitVector t)
+       {
+               checkCompatibility(t);
+               return new BitVector(binOp(bits.clone(), t.bits, Bit::and));
+       }
+
+       @Override
+       public BitVector or(BitVector t)
+       {
+               checkCompatibility(t);
+               return new BitVector(binOp(bits.clone(), t.bits, Bit::or));
+       }
+
+       @Override
+       public BitVector xor(BitVector t)
+       {
+               checkCompatibility(t);
+               return new BitVector(binOp(bits.clone(), t.bits, Bit::xor));
+       }
+
+       @Override
+       public BitVector not()
+       {
+               return new BitVector(unOp(bits.clone(), Bit::not));
+       }
+
+       public int length()
+       {
+               return bits.length;
+       }
+
+       public BitVector concat(BitVector other)
+       {
+               Bit[] newBits = Arrays.copyOf(bits, length() + other.length());
+               System.arraycopy(other.bits, 0, newBits, length(), other.length());
+               return new BitVector(newBits);
+       }
+
+       public BitVector subVector(int start)
+       {
+               return new BitVector(Arrays.copyOfRange(bits, start, length()));
+       }
+
+       public BitVector subVector(int start, int end)
+       {
+               return new BitVector(Arrays.copyOfRange(bits, start, end));
+       }
+
+       private void checkCompatibility(BitVector bv)
+       {
+               if (length() != bv.length())
+                       throw new IllegalArgumentException(format("BitVector length does not match: %d and %d", length(), bv.length()));
+       }
+
+       static Bit[] binOp(Bit[] dest, Bit[] second, BinaryOperator<Bit> op)
+       {
+               if (dest == null)
+                       return second.clone();
+               for (int i = 0; i < dest.length; i++)
+               {
+                       dest[i] = op.apply(dest[i], second[i]);
+               }
+               return dest;
+       }
+
+       static Bit[] unOp(Bit[] dest, UnaryOperator<Bit> op)
+       {
+               if (dest == null)
+                       return null;
+               for (int i = 0; i < dest.length; i++)
+               {
+                       dest[i] = op.apply(dest[i]);
+               }
+               return dest;
+       }
+
+       /**
+        * Class for comfortable and efficient manipulation of {@link BitVector}s, similar to {@link StringBuilder}
+        *
+        * @author Christian Femers
+        */
+       @SuppressWarnings("synthetic-access")
+       public static final class BitVectorMutator implements LogicType<BitVectorMutator, BitVector>
+       {
+               private Bit[] bits;
+
+               private BitVectorMutator(Bit[] bits)
+               {
+                       this.bits = bits;
+               }
+
+               static BitVectorMutator of(BitVector bv)
+               {
+                       return new BitVectorMutator(bv.getBits());
+               }
+
+               /**
+                * Returns an empty mutator which has no bits set and will simply copy the values from the first binary operation performed.
+                * 
+                */
+               public static BitVectorMutator empty()
+               {
+                       return new BitVectorMutator(null);
+               }
+
+               /**
+                * Produces the resulting, immutable {@link BitVector}<br>
+                * 
+                * @throws IllegalStateException if the mutator is (still) empty
+                */
+               public BitVector get()
+               {
+                       if (bits == null)
+                               throw new IllegalStateException("cannot create a BitVector from an empty mutator");
+                       return new BitVector(bits);
+               }
+
+               @Override
+               public BitVectorMutator join(BitVector t)
+               {
+                       checkCompatibility(t);
+                       bits = binOp(bits, t.bits, Bit::join);
+                       return this;
+               }
+
+               @Override
+               public BitVectorMutator and(BitVector t)
+               {
+                       checkCompatibility(t);
+                       bits = binOp(bits, t.bits, Bit::and);
+                       return this;
+               }
+
+               @Override
+               public BitVectorMutator or(BitVector t)
+               {
+                       checkCompatibility(t);
+                       bits = binOp(bits, t.bits, Bit::or);
+                       return this;
+               }
+
+               @Override
+               public BitVectorMutator xor(BitVector t)
+               {
+                       checkCompatibility(t);
+                       bits = binOp(bits, t.bits, Bit::xor);
+                       return this;
+               }
+
+               @Override
+               public BitVectorMutator not()
+               {
+                       unOp(bits, Bit::not);
+                       return this;
+               }
+
+               private void checkCompatibility(BitVector bv)
+               {
+                       if (bits != null && bits.length != bv.length())
+                               throw new IllegalArgumentException(format("BitVector length does not match: %d and %d", bits.length, bv.length()));
+               }
+       }
+
+       /**
+        * @see Arrays#hashCode(Object[])
+        */
+       @Override
+       public int hashCode()
+       {
+               return Arrays.hashCode(bits);
+       }
+
+       /**
+        * Does test for equality of values/content
+        * 
+        * @see Object#equals(Object)
+        */
+       @Override
+       public boolean equals(Object obj)
+       {
+               if (this == obj)
+                       return true;
+               if (!(obj instanceof BitVector))
+                       return false;
+               BitVector other = (BitVector) obj;
+               return Arrays.equals(bits, other.bits);
+       }
+
+       /**
+        * Does test for equality of values/content, shifting the other BitVector by <code>offset</code> to the right.<br>
+        * Therefore <code>offset + other.length() <= this.length()</code> needs to be true.
+        * 
+        * @throws ArrayIndexOutOfBoundsException if <code>offset + other.length() > this.length()</code>
+        * 
+        * @see Object#equals(Object)
+        */
+       public boolean equals(BitVector other, int offset)
+       {
+               if (other == null)
+                       return false;
+               return Arrays.equals(bits, offset, offset + other.length(), other.bits, 0, other.length());
+       }
+
+       /**
+        * All {@link Bit}s symbols concatenated together
+        * 
+        * @see #parse(String)
+        */
+       @Override
+       public String toString()
+       {
+               StringBuilder sb = new StringBuilder(bits.length);
+               for (Bit bit : bits)
+                       sb.append(bit);
+               return sb.toString();
+       }
+
+       /**
+        * Parses a String containing solely {@link Bit} symbols
+        * 
+        * @see #toString()
+        */
+       public static BitVector parse(String s)
+       {
+               Bit[] values = new Bit[s.length()];
+               for (int i = 0; i < s.length(); i++)
+               {
+                       values[i] = Bit.parse(s, i);
+               }
+               return new BitVector(values);
+       }
+
+       @Override
+       public Iterator<Bit> iterator()
+       {
+               return new Iterator<>()
+               {
+                       private int pos = 0;
+
+                       @Override
+                       public Bit next()
+                       {
+                               if (!hasNext())
+                                       throw new NoSuchElementException();
+                               return getBit(pos++);
+                       }
+
+                       @Override
+                       public boolean hasNext()
+                       {
+                               return pos != length();
+                       }
+               };
+       }
+}
diff --git a/era.mi/src/era/mi/logic/types/LogicType.java b/era.mi/src/era/mi/logic/types/LogicType.java
new file mode 100644 (file)
index 0000000..9a3180e
--- /dev/null
@@ -0,0 +1,130 @@
+package era.mi.logic.types;
+
+/**
+ * Interface for types that support the basic logic operations
+ *
+ * @author Christian Femers
+ *
+ * @param <T> the logic type itself, to make the operations closed in T
+ * @param <S> the operand type, may be the same as T, see {@link StrictLogicType}
+ */
+public interface LogicType<T extends LogicType<T, S>, S>
+{
+       /**
+        * Determines the result when two signals meet each other directly, also called resolution (IEEE 1164)
+        * 
+        * For example:
+        * 
+        * <pre>
+        * 0 joined 0 == 0
+        * 1 joined 0 == X
+        * 0 joined 1 == X
+        * 1 joined 1 == 1
+        * </pre>
+        * 
+        * @param t the second logic signal
+        * @return the resulting value
+        * @author Christian Femers
+        */
+       T join(S t);
+
+       /**
+        * Classical logic AND
+        * 
+        * For example:
+        * 
+        * <pre>
+        * 0 AND 0 == 0
+        * 1 AND 0 == 0
+        * 0 AND 1 == 0
+        * 1 AND 1 == 1
+        * </pre>
+        * 
+        * @param t the second logic signal
+        * @return the resulting value
+        * @author Christian Femers
+        */
+       T and(S t);
+
+       /**
+        * Classical logic OR
+        *
+        * For example:
+        * 
+        * <pre>
+        * 0 OR 0 == 0
+        * 1 OR 0 == 1
+        * 0 OR 1 == 1
+        * 1 OR 1 == 1
+        * </pre>
+        * 
+        * @param t the second logic signal
+        * @return the resulting value
+        * @author Christian Femers
+        */
+       T or(S t);
+
+       /**
+        * Classical logic XOR (exclusive OR)
+        * 
+        * For example:
+        * 
+        * <pre>
+        * 0 XOR 0 == 0
+        * 1 XOR 0 == 1
+        * 0 XOR 1 == 1
+        * 1 XOR 1 == 0
+        * </pre>
+        * 
+        * @param t the second logic signal
+        * @return the resulting value
+        * @author Christian Femers
+        */
+       T xor(S t);
+
+       /**
+        * Classical logic NOT (logical negation)
+        * 
+        * For example:
+        * 
+        * <pre>
+        * NOT 0 == 1
+        * NOT 1 == 0
+        * </pre>
+        * 
+        * @return the resulting value
+        * @author Christian Femers
+        */
+       T not();
+
+       /**
+        * {@link #and(Object) AND} and then {@link #not() NOT}
+        * 
+        * @author Christian Femers
+        */
+       default T nand(S t)
+       {
+               return and(t).not();
+       }
+
+       /**
+        * {@link #or(Object) OR} and then {@link #not() NOT}
+        * 
+        * @author Christian Femers
+        */
+       default T nor(S t)
+       {
+               return or(t).not();
+       }
+
+       /**
+        * {@link #xor(Object) XOR} and then {@link #not() NOT}<br>
+        * Used to determine equality (alias parity, consistency)
+        * 
+        * @author Christian Femers
+        */
+       default T xnor(S t)
+       {
+               return xor(t).not();
+       }
+}
diff --git a/era.mi/src/era/mi/logic/types/MutationOperation.java b/era.mi/src/era/mi/logic/types/MutationOperation.java
new file mode 100644 (file)
index 0000000..d7a16fc
--- /dev/null
@@ -0,0 +1,11 @@
+package era.mi.logic.types;
+
+import java.util.function.BiFunction;
+
+import era.mi.logic.types.BitVector.BitVectorMutator;
+
+@FunctionalInterface
+public interface MutationOperation extends BiFunction<BitVectorMutator, BitVector, BitVectorMutator>
+{
+
+}
diff --git a/era.mi/src/era/mi/logic/types/StrictLogicType.java b/era.mi/src/era/mi/logic/types/StrictLogicType.java
new file mode 100644 (file)
index 0000000..560bb96
--- /dev/null
@@ -0,0 +1,14 @@
+package era.mi.logic.types;
+
+/**
+ * Interface for types that support the basic logic operations only among themselves, making it mathematically closed
+ * 
+ * @author Christian Femers
+ * @see LogicType
+ *
+ * @param <T> the logic type itself to make the operations closed
+ */
+public interface StrictLogicType<T extends StrictLogicType<T>> extends LogicType<T, T>
+{
+       // this is just a matter of type parameters
+}
index 1b26a15..db93253 100644 (file)
@@ -5,9 +5,9 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
-import era.mi.logic.Bit;
 import era.mi.logic.Simulation;
 import era.mi.logic.Util;
+import era.mi.logic.types.Bit;
 
 /**
  * Represents an array of wires that can store n bits of information.
@@ -60,7 +60,7 @@ public class Wire
                        Bit[] bits = input.getInputValues();
                        for (int i = 0; i < length; i++)
                        {
-                               newValues[i] = newValues[i].combineWith(bits[i]);
+                               newValues[i] = newValues[i].join(bits[i]);
                        }
                }
 
index 6576956..0b52ff8 100644 (file)
@@ -1,6 +1,6 @@
 package era.mi.logic.wires;
 
-import era.mi.logic.Bit;
+import era.mi.logic.types.Bit;
 
 public interface WireObserver
 {