예제 #1
0
        public static WamReferenceTarget Create(IEnumerable <WamReferenceTarget> items)
        {
            WamCompoundTerm result = null;

            // Iterate through collection and add each item to the list.
            //
            WamCompoundTerm currentListItem = null;

            foreach (var item in items)
            {
                if (currentListItem == null)
                {
                    result          = WamCompoundTerm.Create(Functor.ListFunctor);
                    currentListItem = result;
                }
                else
                {
                    currentListItem.Children[1] = WamCompoundTerm.Create(Functor.ListFunctor);
                    currentListItem             = (WamCompoundTerm)(currentListItem.Children[1]);
                }
                currentListItem.Children[0] = item;
            }
            if (currentListItem != null)
            {
                currentListItem.Children[1] = WamCompoundTerm.Create(Functor.NilFunctor);
            }

            // If there were no items, create a nil list.
            //
            return(result ?? WamCompoundTerm.Create(Functor.NilFunctor));
        }
예제 #2
0
        ExecutionResults OnGetStructure(WamInstruction instruction)
        {
            var sourceReference    = GetRegister(instruction.SourceRegister).Dereference();
            var sourceVariable     = sourceReference as WamVariable;
            var sourceCompoundTerm = sourceReference as WamCompoundTerm;

            // Ensure target is either a variable or compound term.
            //
            Debug.Assert(sourceVariable != null || sourceCompoundTerm != null);

            if (sourceVariable != null)
            {
                var compoundTerm = WamCompoundTerm.Create(instruction.Functor);
                Bind(sourceVariable, compoundTerm);

                CurrentStructure      = compoundTerm;
                CurrentStructureIndex = -1;
                CurrentUnifyMode      = UnifyModes.Write;
            }
            else // targetCompoundTerm != null
            {
                if (sourceCompoundTerm.Functor != instruction.Functor)
                {
                    return(ExecutionResults.Backtrack);
                }

                CurrentStructure      = sourceCompoundTerm;
                CurrentStructureIndex = -1;
                CurrentUnifyMode      = UnifyModes.Read;
            }
            InstructionPointer = InstructionPointer.GetNext();
            return(ExecutionResults.None);
        }
예제 #3
0
        WamCompoundTerm CreateCompoundTerm(Functor functor)
        {
            var value = WamCompoundTerm.Create(functor);

            CurrentStructure      = value;
            CurrentStructureIndex = -1;
            return(value);
        }
예제 #4
0
        public static WamCompoundTerm Create(CodeCompoundTerm codeCompoundTerm)
        {
            var functor = Functor.Create(codeCompoundTerm.Functor);
            var result  = WamCompoundTerm.Create(functor);

            for (var index = 0; index < functor.Arity; ++index)
            {
                result.Children[index] = WamReferenceTarget.Create(codeCompoundTerm.Children[index]);
            }
            return(result);
        }
예제 #5
0
        public static WamReferenceTarget Create(CodeTerm codeTerm)
        {
            if (codeTerm == null)
            {
                throw new ArgumentNullException("codeTerm");
            }
            var codeValue = codeTerm as CodeValue;

            if (codeValue != null)
            {
                return(WamValue.Create(codeValue));
            }
            var codeCompoundTerm = codeTerm as CodeCompoundTerm;

            if (codeCompoundTerm != null)
            {
                return(WamCompoundTerm.Create(codeCompoundTerm));
            }
            throw new ArgumentException("Invalid CodeTerm type.");
        }