Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/interpreter/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,12 @@ RamDomain Engine::execute(const Node* node, Context& ctxt) {
ESAC(False)

CASE(Conjunction)
return execute(shadow.getLhs(), ctxt) && execute(shadow.getRhs(), ctxt);
for (const auto& child : shadow.getChildren()) {
if (!execute(child.get(), ctxt)) {
return false;
}
}
return true;
ESAC(Conjunction)

CASE(Negation)
Expand Down
16 changes: 15 additions & 1 deletion src/interpreter/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,21 @@ NodePtr NodeGenerator::visit_(type_identity<ram::False>, const ram::False& lfals
}

NodePtr NodeGenerator::visit_(type_identity<ram::Conjunction>, const ram::Conjunction& conj) {
return mk<Conjunction>(I_Conjunction, &conj, dispatch(conj.getLHS()), dispatch(conj.getRHS()));
NodePtrVec children;
std::stack<const ram::Node*> dfs;
dfs.push(&conj.getRHS());
dfs.push(&conj.getLHS());
while (!dfs.empty()) {
const ram::Node* term = dfs.top();
dfs.pop();
if (const ram::Conjunction* subconj = as<ram::Conjunction>(term)) {
dfs.push(&subconj->getRHS());
dfs.push(&subconj->getLHS());
} else {
children.emplace_back(std::move(dispatch(*term)));
}
}
return mk<Conjunction>(I_Conjunction, &conj, std::move(children));
}

NodePtr NodeGenerator::visit_(type_identity<ram::Negation>, const ram::Negation& neg) {
Expand Down
7 changes: 5 additions & 2 deletions src/interpreter/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,12 @@ class False : public Node {

/**
* @class Conjunction
*
* It's a compound node so that conjunctions with hundreds of terms
* do not overflow the engine stack with left/right recursion.
*/
class Conjunction : public BinaryNode {
using BinaryNode::BinaryNode;
class Conjunction : public CompoundNode {
using CompoundNode::CompoundNode;
};

/**
Expand Down