ExecutionResults OnLibraryCallBacktrackingPredicate(WamInstruction instruction, BacktrackingPredicate predicate) { var arguments = new WamReferenceTarget[instruction.Functor.Arity]; for (var index = 0; index < instruction.Functor.Arity; ++index) { arguments[index] = ArgumentRegisters[index]; } IEnumerable <bool> enumerable; try { enumerable = predicate.BacktrackingPredicateDelegate(this, arguments); } catch { // Backtrack on exception. // return(ExecutionResults.Backtrack); } var enumerator = enumerable.GetEnumerator(); ChoicePoint = new WamChoicePoint(ChoicePoint, Environment, StackIndex, ReturnInstructionPointer, ArgumentRegisters, CutChoicePoint) { BacktrackInstructionPointer = InstructionPointer.GetNext(), PredicateEnumerator = enumerator }; InstructionPointer = ChoicePoint.BacktrackInstructionPointer; PredicateEnumerator = ChoicePoint.PredicateEnumerator; return(ExecutionResults.None); }
ExecutionResults OnTryMeElse(WamInstruction instruction) { var instructionPointer = GetInstructionPointer(instruction.Functor, instruction.Index); if (instructionPointer == WamInstructionPointer.Undefined) { return(ExecutionResults.Failure); } ChoicePoint = new WamChoicePoint(ChoicePoint, Environment, StackIndex, ReturnInstructionPointer, ArgumentRegisters, CutChoicePoint) { BacktrackInstructionPointer = instructionPointer }; InstructionPointer = InstructionPointer.GetNext(); return(ExecutionResults.None); }
public WamChoicePoint(WamChoicePoint predecessor, WamEnvironment environment, int stackIndex, WamInstructionPointer returnInstructionPointer, IEnumerable <WamReferenceTarget> argumentRegisters, WamChoicePoint cutChoicePoint) { Generation = NextGeneration++; Predecessor = predecessor; Environment = environment; StackIndex = stackIndex; ReturnInstructionPointer = returnInstructionPointer; ArgumentRegisters = new WamReferenceTargetList(argumentRegisters); CutChoicePoint = cutChoicePoint; BacktrackInstructionPointer = WamInstructionPointer.Undefined; PredicateEnumerator = null; Trail = new List <WamVariable>(); }
public WamChoicePoint(WamChoicePoint predecessor, WamEnvironment environment, int stackIndex, WamInstructionPointer returnInstructionPointer, IEnumerable<WamReferenceTarget> argumentRegisters, WamChoicePoint cutChoicePoint) { m_generation = s_nextGeneration++; m_predecessor = predecessor; m_environment = environment; m_stackIndex = stackIndex; m_returnInstructionPointer = returnInstructionPointer; m_argumentRegisters = new WamReferenceTargetList(argumentRegisters); m_cutChoicePoint = cutChoicePoint; m_backtrackInstructionPointer = WamInstructionPointer.Undefined; m_predicateEnumerator = null; m_trail = new List<WamVariable>(); }
public WamChoicePoint(WamChoicePoint predecessor, WamEnvironment environment, int stackIndex, WamInstructionPointer returnInstructionPointer, IEnumerable<WamReferenceTarget> argumentRegisters, WamChoicePoint cutChoicePoint) { Generation = NextGeneration++; Predecessor = predecessor; Environment = environment; StackIndex = stackIndex; ReturnInstructionPointer = returnInstructionPointer; ArgumentRegisters = new WamReferenceTargetList(argumentRegisters); CutChoicePoint = cutChoicePoint; BacktrackInstructionPointer = WamInstructionPointer.Undefined; PredicateEnumerator = null; Trail = new List<WamVariable>(); }
public WamChoicePoint(WamChoicePoint predecessor, WamEnvironment environment, int stackIndex, WamInstructionPointer returnInstructionPointer, IEnumerable <WamReferenceTarget> argumentRegisters, WamChoicePoint cutChoicePoint) { m_generation = s_nextGeneration++; m_predecessor = predecessor; m_environment = environment; m_stackIndex = stackIndex; m_returnInstructionPointer = returnInstructionPointer; m_argumentRegisters = new WamReferenceTargetList(argumentRegisters); m_cutChoicePoint = cutChoicePoint; m_backtrackInstructionPointer = WamInstructionPointer.Undefined; m_predicateEnumerator = null; m_trail = new List <WamVariable>(); }
private ExecutionResults OnTryMeElse(WamInstruction instruction) { WamInstructionPointer instructionPointer = GetInstructionPointer(instruction.Functor, instruction.Index); if (instructionPointer == WamInstructionPointer.Undefined) { return ExecutionResults.Failure; } ChoicePoint = new WamChoicePoint(ChoicePoint, Environment, StackIndex, ReturnInstructionPointer, ArgumentRegisters, CutChoicePoint); ChoicePoint.BacktrackInstructionPointer = instructionPointer; InstructionPointer = InstructionPointer.GetNext(); return ExecutionResults.None; }
private ExecutionResults OnLibraryCallBacktrackingPredicate(WamInstruction instruction, BacktrackingPredicate predicate) { WamReferenceTarget[] arguments = new WamReferenceTarget[instruction.Functor.Arity]; for (int index = 0; index < instruction.Functor.Arity; ++index) { arguments[index] = ArgumentRegisters[index]; } IEnumerable<bool> enumerable; try { enumerable = predicate.BacktrackingPredicateDelegate(this, arguments); } catch { // Backtrack on exception. // return ExecutionResults.Backtrack; } IEnumerator<bool> enumerator = enumerable.GetEnumerator(); ChoicePoint = new WamChoicePoint(ChoicePoint, Environment, StackIndex, ReturnInstructionPointer, ArgumentRegisters, CutChoicePoint); ChoicePoint.BacktrackInstructionPointer = InstructionPointer.GetNext(); ChoicePoint.PredicateEnumerator = enumerator; InstructionPointer = ChoicePoint.BacktrackInstructionPointer; PredicateEnumerator = ChoicePoint.PredicateEnumerator; return ExecutionResults.None; }