diff --git a/reading_machine/src/Action.cpp b/reading_machine/src/Action.cpp index b24d547362765b7c4ec2f8e0927ff7050da9d750..94bfee7f9cd589734b78b94d2dafad120ab4f74a 100644 --- a/reading_machine/src/Action.cpp +++ b/reading_machine/src/Action.cpp @@ -358,7 +358,30 @@ Action Action::attach(Object governorObject, int governorIndex, Object dependent govLineIndex = config.getStack(governorIndex); } - return addHypothesisRelative(Config::headColName, dependentObject, dependentIndex, std::to_string(govLineIndex)).appliable(config, action); + int depLineIndex = 0; + if (dependentObject == Object::Buffer) + { + depLineIndex = config.getWordIndex() + dependentIndex; + if (!config.has(0, depLineIndex, 0)) + return false; + } + else + { + if (!config.hasStack(dependentIndex)) + return false; + depLineIndex = config.getStack(dependentIndex); + } + + // Check for cycles + while (govLineIndex != depLineIndex) + { + try + { + govLineIndex = std::stoi(config.getLastNotEmptyHypConst(Config::headColName, govLineIndex)); + } catch(std::exception &) {return true;} + } + + return false; }; return {Type::Write, apply, undo, appliable};