示例#1
0
 internal PrologVariable(PrologVariableList container)
 {
     if (container == null)
     {
         throw new ArgumentNullException("container");
     }
     Container = container;
 }
示例#2
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);
        }
示例#3
0
        PrologVariableList GetTemporaryVariables()
        {
            var result = new PrologVariableList();

            for (var index = 0; index < WamMachine.TemporaryRegisters.Count; ++index)
            {
                var value           = "*";
                var referenceTarget = WamMachine.TemporaryRegisters[index];
                if (referenceTarget != null)
                {
                    value = referenceTarget.ToString();
                }
                result.Add(string.Format("X{0}", index)).Text = value;
            }
            return(result);
        }
示例#4
0
        internal PrologStackFrame(PrologStackFrameList container, int stackIndex)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (stackIndex < 0)
            {
                throw new ArgumentOutOfRangeException("stackIndex");
            }

            m_container  = container;
            m_stackIndex = stackIndex;

            m_instructionStream = null;
            m_variables         = null;
            m_clause            = null;
        }
示例#5
0
        private PrologVariableList GetArgumentVariables()
        {
            PrologVariableList result = new PrologVariableList();

            for (int index = 0; index < WamMachine.ArgumentRegisters.Count; ++index)
            {
                string             value           = "*";
                WamReferenceTarget referenceTarget = WamMachine.ArgumentRegisters[index];
                if (referenceTarget != null)
                {
                    value = referenceTarget.ToString();
                }

                result.Add(string.Format("A{0}", index)).Text = value;
            }

            return(result);
        }
示例#6
0
        internal void Synchronize(PrologVariableList variables)
        {
            HashSet <string> registers = new HashSet <string>();

            foreach (PrologVariable variable in this)
            {
                registers.Add(variable.Register);
            }

            // Add/update variables in specified list.
            //
            foreach (PrologVariable variable in variables)
            {
                PrologVariable thisVariable;
                if (registers.Contains(variable.Register))
                {
                    thisVariable = this[variable.Register];
                    registers.Remove(variable.Register);
                }
                else
                {
                    thisVariable      = Add(variable.Register);
                    thisVariable.Name = variable.Name;
                }

                if (variable.CodeTerm != null)
                {
                    thisVariable.CodeTerm = variable.CodeTerm;
                }
                else
                {
                    thisVariable.Text = variable.Text;
                }
            }

            // Remove variables not in specified list.
            //
            foreach (string register in registers)
            {
                Remove(register);
            }
        }
示例#7
0
        private PrologMachine(Program program, Query query)
        {
            if (program == null)
            {
                throw new ArgumentNullException("program");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            m_wamMachine = WamMachine.Create(program, query);

            StackFrames        = new PrologStackFrameList(this);
            Arguments          = new PrologVariableList(this);
            TemporaryVariables = new PrologVariableList(this);

            Synchronize();

            QueryResults = null;
        }
示例#8
0
 internal PrologQueryResults()
 {
     m_variables = new PrologVariableList(this);
 }