Example #1
0
        /// <summary>
        /// Allocates a new choice point with the current execution state
        /// </summary>
        public void TryMeElse(int nextClause)
        {
            var argumentValues = _registers.Skip(_environment.Variables.Length).Take(_environment.NumberOfArguments);

            var newChoice = new ChoicePoint(_choicePoint, _environment, argumentValues, new BasicTrail(), nextClause);

            _choicePoint = newChoice;
            _trail       = _choicePoint.Trail;
        }
Example #2
0
        public ChoicePoint(ChoicePoint previousChoice, ByteCodeEnvironment environment, IEnumerable<IReferenceLiteral> arguments, ITrail trail, int nextClause)
        {
            if (arguments == null) throw new ArgumentNullException(nameof(arguments));
            if (trail == null) throw new ArgumentNullException(nameof(trail));

            _previousChoicePoint    = previousChoice;
            _arguments              = arguments.Select(arg => new SimpleReference(arg)).ToArray();
            _trail                  = trail;
            _nextClause             = nextClause;
            _environment            = environment;
        }
Example #3
0
        /// <summary>
        /// Backtracks to the current choice point and discards it
        /// </summary>
        public void TrustMe()
        {
            BacktrackToChoicePoint();
            _programCounter = _choicePoint.NextClause;
            _choicePoint    = _choicePoint.PreviousChoicePoint;

            if (_choicePoint == null)
            {
                _trail = new NoTrail();
            }
            else
            {
                _trail = _choicePoint.Trail;
            }
        }
Example #4
0
        public ChoicePoint(ChoicePoint previousChoice, ByteCodeEnvironment environment, IEnumerable <IReferenceLiteral> arguments, ITrail trail, int nextClause)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }
            if (trail == null)
            {
                throw new ArgumentNullException(nameof(trail));
            }

            _previousChoicePoint = previousChoice;
            _arguments           = arguments.Select(arg => new SimpleReference(arg)).ToArray();
            _trail       = trail;
            _nextClause  = nextClause;
            _environment = environment;
        }
Example #5
0
        /// <summary>
        /// Allocates a new choice point with the current execution state
        /// </summary>
        public void TryMeElse(int nextClause)
        {
            var argumentValues = _registers.Skip(_environment.Variables.Length).Take(_environment.NumberOfArguments);

            var newChoice = new ChoicePoint(_choicePoint, _environment, argumentValues, new BasicTrail(), nextClause);

            _choicePoint = newChoice;
            _trail = _choicePoint.Trail;
        }
Example #6
0
        /// <summary>
        /// Backtracks to the current choice point and discards it
        /// </summary>
        public void TrustMe()
        {
            BacktrackToChoicePoint();
            _programCounter = _choicePoint.NextClause;
            _choicePoint = _choicePoint.PreviousChoicePoint;

            if (_choicePoint == null)
            {
                _trail = new NoTrail();
            }
            else
            {
                _trail = _choicePoint.Trail;
            }
        }