Skip to content

Commit

Permalink
Merge pull request #144 from IIIM-IS/evaluate-boolean-guard
Browse files Browse the repository at this point in the history
Boolean operators should return true for successful evaluation
  • Loading branch information
jefft0 authored Mar 18, 2021
2 parents aab5adc + 00ba990 commit 7c3fdea
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions r_exec/hlp_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ inline bool HLPOverlay::evaluate_guards(uint16 guard_set_iptr_index) {
uint16 result_index;
if (!evaluate(guard_set_index + i, result_index))
return false;
if (code_[result_index].isBooleanFalse())
// This is a boolean guard (not an assignment) and it is false.
return false;
}
return true;
}
Expand Down
20 changes: 10 additions & 10 deletions r_exec/operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool equ(const Context &context, uint16 &index) {

bool r = (lhs == rhs);
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -146,7 +146,7 @@ bool neq(const Context &context, uint16 &index) {

bool r = *context.getChild(1) != *context.getChild(2);
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -162,15 +162,15 @@ bool gtr(const Context &context, uint16 &index) {

bool r = lhs[0].asFloat() > rhs[0].asFloat();
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}
} else if (lhs[0].getDescriptor() == Atom::TIMESTAMP) {

if (rhs[0].getDescriptor() == Atom::TIMESTAMP) {

bool r = Utils::GetTimestamp(&lhs[0]) > Utils::GetTimestamp(&rhs[0]);
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}
}

Expand All @@ -191,15 +191,15 @@ bool lsr(const Context &context, uint16 &index) {

bool r = lhs[0].asFloat() < rhs[0].asFloat();
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}
} else if (lhs[0].getDescriptor() == Atom::TIMESTAMP) {

if (rhs[0].getDescriptor() == Atom::TIMESTAMP) {

bool r = Utils::GetTimestamp(&lhs[0]) < Utils::GetTimestamp(&rhs[0]);
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}
}

Expand All @@ -220,15 +220,15 @@ bool gte(const Context &context, uint16 &index) {

bool r = lhs[0].asFloat() >= rhs[0].asFloat();
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}
} else if (lhs[0].getDescriptor() == Atom::TIMESTAMP) {

if (rhs[0].getDescriptor() == Atom::TIMESTAMP) {

bool r = Utils::GetTimestamp(&lhs[0]) >= Utils::GetTimestamp(&rhs[0]);
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}
}

Expand All @@ -249,15 +249,15 @@ bool lse(const Context &context, uint16 &index) {

bool r = lhs[0].asFloat() <= rhs[0].asFloat();
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}
} else if (lhs[0].getDescriptor() == Atom::TIMESTAMP) {

if (rhs[0].getDescriptor() == Atom::TIMESTAMP) {

bool r = Utils::GetTimestamp(&lhs[0]) <= Utils::GetTimestamp(&rhs[0]);
index = context.setAtomicResult(Atom::Boolean(r));
return r;
return true;
}
}

Expand Down
3 changes: 3 additions & 0 deletions r_exec/pgm_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ bool PGMOverlay::check_guards() {
uint16 result_index;
if (!evaluate(guard_set_index + i, result_index))
return false;
if (code_[result_index].isBooleanFalse())
// The boolean guard is false.
return false;
}
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions r_exec/pgm_overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class r_exec_dll PGMOverlay :
uint16 result_index;
if (!evaluate(guard_set_index, result_index))
return FAILURE;
if (code_[result_index].isBooleanFalse())
// The boolean guard is false.
return FAILURE;
return SUCCESS;
}

Expand Down

0 comments on commit 7c3fdea

Please sign in to comment.