예제 #1
0
        public void PushContext(WamInstructionStream instructionStream)
        {
            if (instructionStream == null)
            {
                throw new ArgumentNullException("instructionStream");
            }

            var context = new WamContext();

            _contextStack.Push(context);
            CurrentContext = context;

            State = WamMachineStates.Run;
            InstructionPointer       = new WamInstructionPointer(instructionStream);
            ReturnInstructionPointer = WamInstructionPointer.Undefined;
            StackIndex = 0;

            Environment = null;
            ChoicePoint = null;
            ArgumentRegisters.Clear();
            TemporaryRegisters.Clear();

            CurrentStructure      = null;
            CurrentStructureIndex = -1;
        }
예제 #2
0
 public WamInstructionPointer(WamInstructionStream instructionStream)
 {
     if (instructionStream == null)
     {
         throw new ArgumentNullException("instructionStream");
     }
     _instructionStream = instructionStream;
     _index             = 0;
 }
예제 #3
0
        internal void InvalidateInstructionStream()
        {
            _wamInstructionStream = null;

            if (_prologInstructionStream != null)
            {
                _prologInstructionStream = null;
                RaisePropertyChanged(new PropertyChangedEventArgs("PrologInstructionStream"));
            }
        }
예제 #4
0
        public void SetInstructionStream(WamInstructionStream instructionStream)
        {
            if (instructionStream == null)
            {
                throw new ArgumentNullException("instructionStream");
            }

            ReturnInstructionPointer = InstructionPointer.GetNext();
            CutChoicePoint           = ChoicePoint;
            TemporaryRegisters.Clear();

            StackIndex        += 1;
            InstructionPointer = new WamInstructionPointer(instructionStream);
        }
        internal PrologInstructionStream(IPrologInstructionStreamContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            m_container = container;

            m_wamInstructionStream = m_container.WamInstructionStream;
            for (int idx = 0; idx < m_wamInstructionStream.Length; ++idx)
            {
                Items.Add(new PrologInstruction(this, idx));
            }
        }
예제 #6
0
        private PrologVariableList GetPermanentVariables(int stackIndex, bool getCodeTerm)
        {
            PrologVariableList result = new PrologVariableList();

            WamEnvironment environment = WamMachine.GetEnvironment(stackIndex);

            if (environment != null)
            {
                // Retrieve register name assignments from instruction stream.
                //
                Dictionary <int, string> variableNames;
                WamInstructionStream     wamInstructionStream = WamMachine.GetInstructionPointer(stackIndex).InstructionStream;
                if (wamInstructionStream != null)
                {
                    variableNames = wamInstructionStream.GetPermanentVariableAssignments();
                }
                else
                {
                    variableNames = new Dictionary <int, string>();
                }

                for (int index = 0; index < environment.PermanentRegisters.Count; ++index)
                {
                    PrologVariable variable = result.Add(string.Format("Y{0}", index));

                    string name;
                    if (variableNames.TryGetValue(index, out name))
                    {
                        variable.Name = name;
                    }

                    WamReferenceTarget referenceTarget = environment.PermanentRegisters[index];
                    if (referenceTarget != null)
                    {
                        if (getCodeTerm)
                        {
                            variable.CodeTerm = referenceTarget.GetCodeTerm();
                        }
                        else
                        {
                            variable.Text = referenceTarget.ToString();
                        }
                    }
                }
            }

            return(result);
        }
예제 #7
0
 public WamInstructionPointer(WamInstructionStream instructionStream, int index)
 {
     _instructionStream = instructionStream;
     _index             = index;
 }