Fix evaluate functions for gates to return an event
This commit is contained in:
parent
1846c25784
commit
2cacfb9dc0
@ -8,17 +8,15 @@ AndGate::AndGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
|
||||
in2 = wire2;
|
||||
out = wire3;
|
||||
}
|
||||
int AndGate::evaluate(int evTime) {
|
||||
Event AndGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(Event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
return Event(-1, 0, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
else if(in1->getValue(evTime) == 1 && in2->getValue(evTime) == 1){
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(Event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
return Event(-1, 1, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,18 +8,16 @@ NandGate::NandGate(int d, Wire * wire1, Wire * wire2, Wire * wire3)
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void NandGate::evaluate(int evTime)
|
||||
Event NandGate::evaluate(int evTime)
|
||||
{
|
||||
if (in1->getValue(evTime) == 0 || in2->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(Event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
return Event(-1, 1, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(Event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
return Event(-1, 0, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,15 @@ NorGate::NorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void NorGate::evaluate(int evTime) {
|
||||
Event NorGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) == 1 || in2->getValue(evTime) == 1) {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(Event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
return Event(-1, 0, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(Event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
return Event(-1, 1, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,17 +8,15 @@ NotGate::NotGate(int d, Wire* wire1, Wire* wire2) {
|
||||
out = wire2;
|
||||
}
|
||||
|
||||
void NotGate::evaluate(int evTime) {
|
||||
Event NotGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(Event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
return Event(-1, 0, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(Event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
return Event(-1, 1, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,15 @@ OrGate::OrGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void OrGate::evaluate(int evTime) {
|
||||
Event OrGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) == 1 || in2->getValue(evTime) == 1) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(Event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
return Event(-1, 1, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
else if (in1->getValue(evTime) == 0 && in2->getValue(evTime) == 0) {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(Event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
return Event(-1, 0, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,18 +9,16 @@ XnorGate::XnorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void XnorGate::evaluate(int evTime) {
|
||||
Event XnorGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) != -1 && in2->getValue(evTime) != -1) {
|
||||
if (in1->getValue(evTime) == in2->getValue(evTime)) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(Event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
return Event(-1, 1, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(Event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
return Event(-1, 0, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,18 +9,16 @@ XorGate::XorGate(int d, Wire* wire1, Wire* wire2, Wire* wire3) {
|
||||
out = wire3;
|
||||
}
|
||||
|
||||
void XorGate::evaluate(int evTime) {
|
||||
Event XorGate::evaluate(int evTime) {
|
||||
if (in1->getValue(evTime) != -1 && in2->getValue(evTime) != -1) {
|
||||
if (in1->getValue(evTime) != in2->getValue(evTime)) {
|
||||
if (out->getValue(evTime + delay) != 1) {
|
||||
e->push(Event(e->size, 1, evTime + delay, out));
|
||||
out->setValue(1, evTime + delay);
|
||||
return Event(-1, 1, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (out->getValue(evTime + delay) != 0) {
|
||||
e->push(Event(e->size, 0, evTime + delay, out));
|
||||
out->setValue(0, evTime + delay);
|
||||
return Event(-1, 0, evTime + delay, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user