diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-24 10:34:30 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-24 10:34:30 +0100 |
commit | 9ac2848be66c39acdc291dc3b48b91178acc1a05 (patch) | |
tree | ec4c1805bbd45e3d59e2aa4a89605756c28914aa /src/jcgp/backend/function | |
parent | 6769419bea279935c4a3a84616d45ee7d4a6345c (diff) |
Refactored parsers and parameters, had to install e(fx)clipse to deploy application.
Diffstat (limited to 'src/jcgp/backend/function')
-rw-r--r-- | src/jcgp/backend/function/BitwiseLogic.java | 173 |
1 files changed, 140 insertions, 33 deletions
diff --git a/src/jcgp/backend/function/BitwiseLogic.java b/src/jcgp/backend/function/BitwiseLogic.java index a4c2737..2466f36 100644 --- a/src/jcgp/backend/function/BitwiseLogic.java +++ b/src/jcgp/backend/function/BitwiseLogic.java @@ -22,9 +22,12 @@ public class BitwiseLogic extends FunctionSet { new Or(), new OrNotA(), new OrNotB(), - new Nand()}; - - // TODO muxes + new Nand() +// new Mux1(), +// new Mux2(), +// new Mux3(), +// new Mux4() + }; enableAll(); } @@ -153,9 +156,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = arg1.get() & arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = in0.get() & in1.get(); return new UnsignedInteger(result); } @@ -178,9 +181,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = ~(arg1.get()) & arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = ~(in0.get()) & in1.get(); return new UnsignedInteger(result); } @@ -203,9 +206,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = arg1.get() & ~(arg2.get()); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = in0.get() & ~(in1.get()); return new UnsignedInteger(result); } @@ -228,9 +231,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = arg1.get() | arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = in0.get() | in1.get(); return new UnsignedInteger(~result); } @@ -253,9 +256,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = arg1.get() ^ arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = in0.get() ^ in1.get(); return new UnsignedInteger(result); } @@ -278,9 +281,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = arg1.get() ^ arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = in0.get() ^ in1.get(); return new UnsignedInteger(~result); } @@ -303,9 +306,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = arg1.get() | arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = in0.get() | in1.get(); return new UnsignedInteger(result); } @@ -328,9 +331,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = ~arg1.get() | arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = ~in0.get() | in1.get(); return new UnsignedInteger(result); } @@ -353,9 +356,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = arg1.get() | ~arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = in0.get() | ~in1.get(); return new UnsignedInteger(result); } @@ -378,9 +381,9 @@ public class BitwiseLogic extends FunctionSet { if (connections.length < getArity()) { throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); } else { - UnsignedInteger arg1 = ((UnsignedInteger) connections[0].getValue()); - UnsignedInteger arg2 = ((UnsignedInteger) connections[1].getValue()); - Integer result = arg1.get() & arg2.get(); + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + Integer result = in0.get() & in1.get(); return new UnsignedInteger(~result); } @@ -396,4 +399,108 @@ public class BitwiseLogic extends FunctionSet { return "Nand"; } } + + public static class Mux1 extends Function { + @Override + public UnsignedInteger run(Connection... connections) { + if (connections.length < getArity()) { + throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); + } else { + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + UnsignedInteger in2 = ((UnsignedInteger) connections[2].getValue()); + Integer result = ((in0.get() & ~in2.get()) | (in1.get() & in2.get())); + + return new UnsignedInteger(result); + } + } + + @Override + public int getArity() { + return 3; + } + + @Override + public String getName() { + return "Mux1"; + } + } + + public static class Mux2 extends Function { + @Override + public UnsignedInteger run(Connection... connections) { + if (connections.length < getArity()) { + throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); + } else { + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + UnsignedInteger in2 = ((UnsignedInteger) connections[2].getValue()); + Integer result = ((in0.get() & ~in2.get()) | (~in1.get() & in2.get())); + + return new UnsignedInteger(result); + } + } + + @Override + public int getArity() { + return 3; + } + + @Override + public String getName() { + return "Mux2"; + } + } + + public static class Mux3 extends Function { + @Override + public UnsignedInteger run(Connection... connections) { + if (connections.length < getArity()) { + throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); + } else { + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + UnsignedInteger in2 = ((UnsignedInteger) connections[2].getValue()); + Integer result = ((~in0.get() & ~in2.get()) | (in1.get() & in2.get())); + + return new UnsignedInteger(result); + } + } + + @Override + public int getArity() { + return 3; + } + + @Override + public String getName() { + return "Mux3"; + } + } + + public static class Mux4 extends Function { + @Override + public UnsignedInteger run(Connection... connections) { + if (connections.length < getArity()) { + throw new IllegalArgumentException(getName() + " received " + connections.length + " connections but arity is " + getArity() + "."); + } else { + UnsignedInteger in0 = ((UnsignedInteger) connections[0].getValue()); + UnsignedInteger in1 = ((UnsignedInteger) connections[1].getValue()); + UnsignedInteger in2 = ((UnsignedInteger) connections[2].getValue()); + Integer result = ((~in0.get() & ~in2.get()) | (~in1.get() & in2.get())); + + return new UnsignedInteger(result); + } + } + + @Override + public int getArity() { + return 3; + } + + @Override + public String getName() { + return "Mux4"; + } + } } |