protected override CodeTerm GetCodeTermBase(WamDeferenceTypes dereferenceType, WamReferenceTargetMapping mapping)
        {
            switch (dereferenceType)
            {
            case WamDeferenceTypes.AllVariables:
            {
                if (m_target == null)
                {
                    return(new CodeValueObject(null));
                }

                return(m_target.GetCodeTerm(dereferenceType, mapping));
            }

            case WamDeferenceTypes.BoundVariables:
            {
                if (m_target == null)
                {
                    return(mapping.Lookup(this));
                }

                return(m_target.GetCodeTerm(dereferenceType, mapping));
            }

            case WamDeferenceTypes.None:
            {
                return(mapping.Lookup(this));
            }

            default:
                throw new InvalidOperationException(string.Format("Unknown dereferenceType {0}.", dereferenceType));
            }
        }
Beispiel #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);
        }
        public static bool Assert(WamMachine machine, WamReferenceTarget[] arguments)
        {
            Debug.Assert(arguments.Length == 1);

            WamReferenceTarget expression = machine.Evaluate(arguments[0]);

            CodeTerm codeTerm = expression.GetCodeTerm();

            if (codeTerm != null)
            {
                CodeValue codeValue = codeTerm as CodeValue;
                if (codeValue != null)
                {
                    return(Convert.ToBoolean(codeValue.Object));
                }
            }

            return(false);
        }