X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Ftypes%2FLogicType.java;fp=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Ftypes%2FLogicType.java;h=9a3180e75b54db119b514fb9f37f0d8fa2202c34;hb=5606ceefa2c360772194c85ed884e5f8f06f36aa;hp=0000000000000000000000000000000000000000;hpb=002110424653b282ab9c7ea4b12f967d59e5f66a;p=Mograsim.git 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(); + } +}