示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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>();
        }
示例#4
0
        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>();
        }
示例#5
0
        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>();
        }
示例#7
0
        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;
        }
示例#8
0
        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;
        }