X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2Fgates%2FMultiInputGate.java;h=dd8a6d6ff153de1eeab673923519207109124cce;hb=b7ce41467a2cbd9f45554982730741810e99feaa;hp=7a6d4388e44ef570dda6393b014f0d6732d60e4a;hpb=c1d0ddc342c482051fa6c455bb286617135bd3c3;p=Mograsim.git 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 7a6d4388..dd8a6d6f 100644 --- a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java +++ b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java @@ -1,21 +1,21 @@ package era.mi.logic.components.gates; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import era.mi.logic.Bit; import era.mi.logic.components.BasicComponent; -import era.mi.logic.wires.Wire.WireEnd; +import era.mi.logic.types.BitVector.BitVectorMutator; +import era.mi.logic.types.MutationOperation; +import era.mi.logic.wires.Wire.ReadEnd; +import era.mi.logic.wires.Wire.ReadWriteEnd; public abstract class MultiInputGate extends BasicComponent { - protected WireEnd[] in; - protected WireEnd out; + protected ReadEnd[] in; + protected ReadWriteEnd out; protected final int length; - protected Operation op; + protected MutationOperation op; - protected MultiInputGate(int processTime, Operation op, WireEnd out, WireEnd... in) + protected MultiInputGate(int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in) { super(processTime); this.op = op; @@ -23,7 +23,7 @@ public abstract class MultiInputGate extends BasicComponent this.in = in.clone(); if (in.length < 1) throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length)); - for (WireEnd w : in) + for (ReadEnd w : in) { if (w.length() != length) throw new IllegalArgumentException("All wires connected to the gate must be of uniform length."); @@ -33,27 +33,23 @@ public abstract class MultiInputGate extends BasicComponent } @Override - public List getAllInputs() + public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(in)); + return List.of(in); } @Override - public List getAllOutputs() + public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(out)); + return List.of(out); } + @Override protected void compute() { - Bit[] result = in[0].getValues(); - for (int i = 1; i < in.length; i++) - result = op.execute(result, in[i].getValues()); - out.feedSignals(result); - } - - protected interface Operation - { - public Bit[] execute(Bit[] a, Bit[] b); + BitVectorMutator mutator = BitVectorMutator.empty(); + for (ReadEnd w : in) + op.apply(mutator, w.getValues()); + out.feedSignals(mutator.get()); } }