projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge logic of origin into logic
[Mograsim.git]
/
era.mi
/
src
/
era
/
mi
/
logic
/
components
/
gates
/
MultiInputGate.java
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
f7af52e
..
0a9340c
100644
(file)
--- a/
era.mi/src/era/mi/logic/components/gates/MultiInputGate.java
+++ b/
era.mi/src/era/mi/logic/components/gates/MultiInputGate.java
@@
-1,55
+1,58
@@
package era.mi.logic.components.gates;
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 java.util.List;
import era.mi.logic.Bit;
import era.mi.logic.components.BasicComponent;
-import era.mi.logic.wires.WireArray;
-import era.mi.logic.wires.WireArray.WireArrayInput;
+import era.mi.logic.wires.Wire.WireEnd;
-public abstract class MultiInputGate extends BasicComponent
{
- protected WireArray[] in;
- protected Wire
Array out
;
- protected Wire
ArrayInput outI
;
+public abstract class MultiInputGate extends BasicComponent
+{
+ protected Wire
End[] in
;
+ protected Wire
End out
;
protected final int length;
protected Operation op;
protected final int length;
protected Operation op;
- protected MultiInputGate(int processTime, Operation op, WireArray out, WireArray... in) {
+ protected MultiInputGate(int processTime, Operation op, WireEnd out, WireEnd... in)
+ {
super(processTime);
this.op = op;
super(processTime);
this.op = op;
- length = out.length;
+ length = out.length
()
;
this.in = in.clone();
if (in.length < 1)
throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length));
this.in = in.clone();
if (in.length < 1)
throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length));
- for (WireArray w : in) {
- if (w.length != length)
+ for (WireEnd w : in)
+ {
+ if (w.length() != length)
throw new IllegalArgumentException("All wires connected to the gate must be of uniform length.");
w.addObserver(this);
}
this.out = out;
throw new IllegalArgumentException("All wires connected to the gate must be of uniform length.");
w.addObserver(this);
}
this.out = out;
- outI = out.createInput();
}
@Override
}
@Override
- public List<WireArray> getAllInputs() {
- return Collections.unmodifiableList(Arrays.asList(in));
+ public List<WireEnd> getAllInputs()
+ {
+ return List.of(in);
}
@Override
}
@Override
- public List<WireArray> getAllOutputs() {
- return Collections.unmodifiableList(Arrays.asList(out));
+ public List<WireEnd> getAllOutputs()
+ {
+ return List.of(out);
}
}
- protected void compute() {
+ @Override
+ protected void compute()
+ {
Bit[] result = in[0].getValues();
for (int i = 1; i < in.length; i++)
result = op.execute(result, in[i].getValues());
Bit[] result = in[0].getValues();
for (int i = 1; i < in.length; i++)
result = op.execute(result, in[i].getValues());
- out
I
.feedSignals(result);
+ out.feedSignals(result);
}
}
- protected interface Operation {
+ protected interface Operation
+ {
public Bit[] execute(Bit[] a, Bit[] b);
}
}
public Bit[] execute(Bit[] a, Bit[] b);
}
}