From: Christian Femers Date: Mon, 20 May 2019 15:11:13 +0000 (+0200) Subject: Integrated new types, tests still work, not used yet X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=2427bceeaf96fefbd92ea04d7ebbb52606a7b2ff;p=Mograsim.git Integrated new types, tests still work, not used yet most changes are just imports --- diff --git a/era.mi/src/era/mi/logic/Bit.java b/era.mi/src/era/mi/logic/Bit.java deleted file mode 100644 index ff424c79..00000000 --- a/era.mi/src/era/mi/logic/Bit.java +++ /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 diff --git a/era.mi/src/era/mi/logic/Util.java b/era.mi/src/era/mi/logic/Util.java index 88b2393f..05671387 100644 --- a/era.mi/src/era/mi/logic/Util.java +++ b/era.mi/src/era/mi/logic/Util.java @@ -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; } diff --git a/era.mi/src/era/mi/logic/components/BasicComponent.java b/era.mi/src/era/mi/logic/components/BasicComponent.java index 911ea7fa..3da21b9c 100644 --- a/era.mi/src/era/mi/logic/components/BasicComponent.java +++ b/era.mi/src/era/mi/logic/components/BasicComponent.java @@ -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; diff --git a/era.mi/src/era/mi/logic/components/BitDisplay.java b/era.mi/src/era/mi/logic/components/BitDisplay.java index 73052752..52a98699 100644 --- a/era.mi/src/era/mi/logic/components/BitDisplay.java +++ b/era.mi/src/era/mi/logic/components/BitDisplay.java @@ -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 diff --git a/era.mi/src/era/mi/logic/components/Clock.java b/era.mi/src/era/mi/logic/components/Clock.java index 8ad937cf..a31f20c8 100644 --- a/era.mi/src/era/mi/logic/components/Clock.java +++ b/era.mi/src/era/mi/logic/components/Clock.java @@ -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; diff --git a/era.mi/src/era/mi/logic/components/Connector.java b/era.mi/src/era/mi/logic/components/Connector.java index 47cf901f..aa8c4377 100644 --- a/era.mi/src/era/mi/logic/components/Connector.java +++ b/era.mi/src/era/mi/logic/components/Connector.java @@ -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; diff --git a/era.mi/src/era/mi/logic/components/ManualSwitch.java b/era.mi/src/era/mi/logic/components/ManualSwitch.java index 8397e2ba..c4b4ffa3 100644 --- a/era.mi/src/era/mi/logic/components/ManualSwitch.java +++ b/era.mi/src/era/mi/logic/components/ManualSwitch.java @@ -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; /** diff --git a/era.mi/src/era/mi/logic/components/Merger.java b/era.mi/src/era/mi/logic/components/Merger.java index 860c010a..7ef909be 100644 --- a/era.mi/src/era/mi/logic/components/Merger.java +++ b/era.mi/src/era/mi/logic/components/Merger.java @@ -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; diff --git a/era.mi/src/era/mi/logic/components/Splitter.java b/era.mi/src/era/mi/logic/components/Splitter.java index 87c0f60f..760da8fb 100644 --- a/era.mi/src/era/mi/logic/components/Splitter.java +++ b/era.mi/src/era/mi/logic/components/Splitter.java @@ -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; diff --git a/era.mi/src/era/mi/logic/components/TriStateBuffer.java b/era.mi/src/era/mi/logic/components/TriStateBuffer.java index 89a7856d..0ab162f1 100644 --- a/era.mi/src/era/mi/logic/components/TriStateBuffer.java +++ b/era.mi/src/era/mi/logic/components/TriStateBuffer.java @@ -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 diff --git a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java index ea0744c2..7d0e4853 100644 --- a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java +++ b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java @@ -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 diff --git a/era.mi/src/era/mi/logic/tests/ComponentTest.java b/era.mi/src/era/mi/logic/tests/ComponentTest.java index d2ecdbc5..d2be9b75 100644 --- a/era.mi/src/era/mi/logic/tests/ComponentTest.java +++ b/era.mi/src/era/mi/logic/tests/ComponentTest.java @@ -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; diff --git a/era.mi/src/era/mi/logic/tests/TestBitDisplay.java b/era.mi/src/era/mi/logic/tests/TestBitDisplay.java index 690f4a09..9fac0c97 100644 --- a/era.mi/src/era/mi/logic/tests/TestBitDisplay.java +++ b/era.mi/src/era/mi/logic/tests/TestBitDisplay.java @@ -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 index 00000000..6674f9a7 --- /dev/null +++ b/era.mi/src/era/mi/logic/types/Bit.java @@ -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 +{ + 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 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 index 00000000..51545f74 --- /dev/null +++ b/era.mi/src/era/mi/logic/types/BitVector.java @@ -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, Iterable, 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 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 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 + { + 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}
+ * + * @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 offset to the right.
+ * Therefore offset + other.length() <= this.length() needs to be true. + * + * @throws ArrayIndexOutOfBoundsException if offset + other.length() > this.length() + * + * @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 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 index 00000000..9a3180e7 --- /dev/null +++ b/era.mi/src/era/mi/logic/types/LogicType.java @@ -0,0 +1,130 @@ +package era.mi.logic.types; + +/** + * Interface for types that support the basic logic operations + * + * @author Christian Femers + * + * @param the logic type itself, to make the operations closed in T + * @param the operand type, may be the same as T, see {@link StrictLogicType} + */ +public interface LogicType, S> +{ + /** + * Determines the result when two signals meet each other directly, also called resolution (IEEE 1164) + * + * For example: + * + *
+	 * 0 joined 0 == 0
+	 * 1 joined 0 == X
+	 * 0 joined 1 == X
+	 * 1 joined 1 == 1
+	 * 
+ * + * @param t the second logic signal + * @return the resulting value + * @author Christian Femers + */ + T join(S t); + + /** + * Classical logic AND + * + * For example: + * + *
+	 * 0 AND 0 == 0
+	 * 1 AND 0 == 0
+	 * 0 AND 1 == 0
+	 * 1 AND 1 == 1
+	 * 
+ * + * @param t the second logic signal + * @return the resulting value + * @author Christian Femers + */ + T and(S t); + + /** + * Classical logic OR + * + * For example: + * + *
+	 * 0 OR 0 == 0
+	 * 1 OR 0 == 1
+	 * 0 OR 1 == 1
+	 * 1 OR 1 == 1
+	 * 
+ * + * @param t the second logic signal + * @return the resulting value + * @author Christian Femers + */ + T or(S t); + + /** + * Classical logic XOR (exclusive OR) + * + * For example: + * + *
+	 * 0 XOR 0 == 0
+	 * 1 XOR 0 == 1
+	 * 0 XOR 1 == 1
+	 * 1 XOR 1 == 0
+	 * 
+ * + * @param t the second logic signal + * @return the resulting value + * @author Christian Femers + */ + T xor(S t); + + /** + * Classical logic NOT (logical negation) + * + * For example: + * + *
+	 * NOT 0 == 1
+	 * NOT 1 == 0
+	 * 
+ * + * @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}
+ * 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 index 00000000..d7a16fce --- /dev/null +++ b/era.mi/src/era/mi/logic/types/MutationOperation.java @@ -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 +{ + +} 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 index 00000000..560bb96f --- /dev/null +++ b/era.mi/src/era/mi/logic/types/StrictLogicType.java @@ -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 the logic type itself to make the operations closed + */ +public interface StrictLogicType> extends LogicType +{ + // this is just a matter of type parameters +} diff --git a/era.mi/src/era/mi/logic/wires/Wire.java b/era.mi/src/era/mi/logic/wires/Wire.java index 1b26a15d..db932536 100644 --- a/era.mi/src/era/mi/logic/wires/Wire.java +++ b/era.mi/src/era/mi/logic/wires/Wire.java @@ -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]); } } diff --git a/era.mi/src/era/mi/logic/wires/WireObserver.java b/era.mi/src/era/mi/logic/wires/WireObserver.java index 65769565..0b52ff86 100644 --- a/era.mi/src/era/mi/logic/wires/WireObserver.java +++ b/era.mi/src/era/mi/logic/wires/WireObserver.java @@ -1,6 +1,6 @@ package era.mi.logic.wires; -import era.mi.logic.Bit; +import era.mi.logic.types.Bit; public interface WireObserver {