From dcbba0b189fd37135adc4487f1b8b645e7045bc4 Mon Sep 17 00:00:00 2001 From: Christian Femers Date: Mon, 20 May 2019 17:11:13 +0200 Subject: [PATCH] Integrated new types, tests still work, not used yet most changes are just imports --- era.mi/src/era/mi/logic/Util.java | 10 +- .../mi/logic/components/BasicComponent.java | 2 +- .../era/mi/logic/components/BitDisplay.java | 2 +- era.mi/src/era/mi/logic/components/Clock.java | 2 +- .../era/mi/logic/components/Connector.java | 2 +- .../era/mi/logic/components/ManualSwitch.java | 2 +- .../src/era/mi/logic/components/Merger.java | 2 +- .../src/era/mi/logic/components/Splitter.java | 2 +- .../mi/logic/components/TriStateBuffer.java | 2 +- .../components/gates/MultiInputGate.java | 2 +- .../src/era/mi/logic/tests/ComponentTest.java | 7 +- .../era/mi/logic/tests/TestBitDisplay.java | 2 +- era.mi/src/era/mi/logic/{ => types}/Bit.java | 68 ++-- era.mi/src/era/mi/logic/types/BitVector.java | 316 ++++++++++++++++++ era.mi/src/era/mi/logic/types/LogicType.java | 130 +++++++ .../era/mi/logic/types/MutationOperation.java | 11 + .../era/mi/logic/types/StrictLogicType.java | 14 + era.mi/src/era/mi/logic/wires/Wire.java | 4 +- .../src/era/mi/logic/wires/WireObserver.java | 2 +- 19 files changed, 538 insertions(+), 44 deletions(-) rename era.mi/src/era/mi/logic/{ => types}/Bit.java (58%) create mode 100644 era.mi/src/era/mi/logic/types/BitVector.java create mode 100644 era.mi/src/era/mi/logic/types/LogicType.java create mode 100644 era.mi/src/era/mi/logic/types/MutationOperation.java create mode 100644 era.mi/src/era/mi/logic/types/StrictLogicType.java diff --git a/era.mi/src/era/mi/logic/Util.java b/era.mi/src/era/mi/logic/Util.java index b7402c26..d621a44c 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 7cebc606..0a22950f 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 88a10531..3da693b2 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 d6386172..07419b46 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 19ece81a..0ad4a76c 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 613d5239..ca441bac 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 be8be820..09321f17 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 920c2ec0..c0dd76e8 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 0a9340c8..2b0a5292 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 f6d801fd..cb2195ed 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 0d976594..a07125d7 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/Bit.java b/era.mi/src/era/mi/logic/types/Bit.java similarity index 58% rename from era.mi/src/era/mi/logic/Bit.java rename to era.mi/src/era/mi/logic/types/Bit.java index da9a227f..6674f9a7 100644 --- a/era.mi/src/era/mi/logic/Bit.java +++ b/era.mi/src/era/mi/logic/types/Bit.java @@ -1,44 +1,42 @@ -package era.mi.logic; +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 +public enum Bit implements StrictLogicType { - U, X, ZERO, ONE, Z; + U("U"), X("X"), ZERO("0"), ONE("1"), Z("Z"); - public static Bit and(Bit a, Bit b) + private final String symbol; + + private Bit(String symbol) { - return a.and(b); + this.symbol = symbol; } + @Override public Bit and(Bit other) { return fromTable(AND_TABLE, this, other); } - public static Bit or(Bit a, Bit b) - { - return a.or(b); - } - + @Override public Bit or(Bit other) { return fromTable(OR_TABLE, this, other); } - public static Bit xor(Bit a, Bit b) - { - return a.xor(b); - } - + @Override public Bit xor(Bit other) { return fromTable(XOR_TABLE, this, other); } + @Override public Bit not() { switch (this) @@ -61,14 +59,38 @@ public enum Bit return bits; } - public Bit combineWith(Bit other) + public BitVector toVector(int length) + { + return BitVector.of(this, length); + } + + @Override + public Bit join(Bit other) { return fromTable(JOIN_TABLE, this, other); } - public static Bit combine(Bit a, Bit b) + @Override + public String toString() { - return a.combineWith(b); + 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) @@ -76,29 +98,31 @@ public enum Bit 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 Bit[][] JOIN_TABLE = + 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 Bit[][] AND_TABLE = + 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 Bit[][] OR_TABLE = + 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 Bit[][] XOR_TABLE = + private static final Bit[][] XOR_TABLE = { { U, U, U, U, U }, { U, X, X, X, X }, { U, X, ZERO, ONE, X }, 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 { -- 2.17.1