-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor conjunction.cpp to handle null cost in compute_cost method
- Loading branch information
1 parent
6e61240
commit ff41369
Showing
1 changed file
with
8 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
#include "conjunction.hpp" | ||
#include "statement.hpp" | ||
#include "core.hpp" | ||
|
||
namespace riddle | ||
{ | ||
conjunction::conjunction(scope &parent, std::shared_ptr<env> ctx, const conjunction_statement &conj) : scope(parent.get_core(), parent), ctx(ctx), conj(conj) {} | ||
|
||
void conjunction::execute() { conj.execute(*this, ctx); } | ||
|
||
std::shared_ptr<arith_item> conjunction::compute_cost() const noexcept { return std::static_pointer_cast<arith_item>(conj.get_cost()->evaluate(*this, ctx)); } | ||
std::shared_ptr<arith_item> conjunction::compute_cost() const noexcept | ||
{ | ||
if (conj.get_cost()) | ||
return std::static_pointer_cast<arith_item>(conj.get_cost()->evaluate(*this, ctx)); | ||
else | ||
return get_core().new_real(utils::rational::one); | ||
} | ||
} // namespace riddle |