示例#1
0
 public DeterministicExecutor(Functor start, Functor end)
 {
     if (end == null)
         throw new NullReferenceException("No point in using a DeterminsticExecutor unless you supply both a start delegate and an end delegate");
     Start = start;
     _end = end;
 }
示例#2
0
        private WamReferenceTarget m_referenceTarget; // 4 bytes

        #endregion

        #region Constructors

        public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister sourceRegister, Functor functor, int index, WamInstructionRegister targetRegister)
        {
            if (sourceRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "sourceRegister");
            }
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (index < 0)
            {
                throw new ArgumentException("Invalid index.", "index");
            }
            if (targetRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "targetRegister");
            }

            m_opCode = opCode;
            m_sourceRegister = sourceRegister;
            m_functor = functor;
            m_index = index;
            m_targetRegister = targetRegister;
            m_referenceTarget = null;
        }
示例#3
0
 public WamInstruction(WamInstructionOpCodes opCode)
 {
     m_opCode = opCode;
     m_sourceRegister = WamInstructionRegister.Unused;
     m_functor = null;
     m_index = -1;
     m_targetRegister = WamInstructionRegister.Unused;
     m_referenceTarget = null;
 }
 internal BacktrackingPredicate(LibraryMethodList container, Functor functor, BacktrackingPredicateDelegate backtrackingPredicateDelegate)
     : base(container, functor, false)
 {
     if (backtrackingPredicateDelegate == null)
     {
         throw new ArgumentNullException("backtrackingPredicateDelegate");
     }
     _backtrackingPredicateDelegate = backtrackingPredicateDelegate;
 }
示例#5
0
        internal Function(LibraryMethodList container, Functor functor, FunctionDelegate functionDelegate)
            : base(container, functor, true)
        {
            if (functionDelegate == null)
            {
                throw new ArgumentNullException("functionDelegate");
            }

            m_functionDelegate = functionDelegate;
        }
示例#6
0
        internal Predicate(LibraryMethodList container, Functor functor, PredicateDelegate predicateDelegate, bool canEvaluate)
            : base(container, functor, canEvaluate)
        {
            if (predicateDelegate == null)
            {
                throw new ArgumentNullException("predicateDelegate");
            }

            m_predicateDelegate = predicateDelegate;
        }
        public void verify_unary_functor_behavior()
        {
            var func = new Functor<int, string>(a => a.ToString());

            var output = func.fmap(new[] {1, 2}).ToList();

            Assert.That(output.Count(), Is.EqualTo(2));
            Assert.That(output[0], Is.EqualTo("1"));
            Assert.That(output[1], Is.EqualTo("2"));
        }
        private WamCompoundTerm(Functor functor)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }

            Functor = functor;
            Children = functor.Arity == 0 ? s_emptyList : new WamReferenceTarget[functor.Arity];
        }
示例#9
0
        internal CodePredicate(LibraryMethodList container, Functor functor, CodePredicateDelegate codePredicateDelegate)
            : base(container, functor, false)
        {
            if (codePredicateDelegate == null)
            {
                throw new ArgumentNullException("codePredicateDelegate");
            }

            m_codePredicateDelegate = codePredicateDelegate;
        }
示例#10
0
 internal Procedure(ProgramProcedureList container, Functor functor)
 {
     if (container == null)
     {
         throw new ArgumentNullException("container");
     }
     if (functor == null)
     {
         throw new ArgumentNullException("functor");
     }
     Container = container;
     Functor = functor;
     Clauses = new ProcedureClauseList(this, new ObservableCollection<Clause>());
 }
示例#11
0
        internal LibraryMethod(LibraryMethodList container, Functor functor, bool canEvaluate)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }

            m_container = container;
            m_functor = functor;
            m_canEvaluate = canEvaluate;
        }
示例#12
0
 public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister sourceRegister, Functor functor)
 {
     if (functor == null)
     {
         throw new ArgumentNullException("functor");
     }
     if (sourceRegister.IsUnused)
     {
         throw new ArgumentException("Invalid value.", "sourceRegister");
     }
     _opCode = opCode;
     _sourceRegister = sourceRegister;
     _functor = functor;
     _index = -1;
     _targetRegister = WamInstructionRegister.Unused;
     _referenceTarget = null;
 }
示例#13
0
        private WamCompoundTerm(Functor functor)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }

            m_functor = functor;
            if (functor.Arity == 0)
            {
                m_children = s_emptyList;
            }
            else
            {
                m_children = new WamReferenceTarget[functor.Arity];
            }
        }
示例#14
0
        public override object GetValue(ExecutionContext ctx)
        {
            string    functionName = function.GetValue(ctx).ToString();
            Functor   f            = ctx.GetFunction(functionName);
            ArrayList arguments    = new ArrayList();

            if (!emptyArgsList)
            {
                if (args.GetType() == typeof(Sequence <Expression>))
                {
                    Sequence <Expression> seq = (Sequence <Expression>)args;

                    foreach (Expression ex in (Sequence <Expression>)args)
                    {
                        arguments.Add(ex.GetValue(ctx));
                    }
                }
                else
                {
                    arguments.Add(((Expression)args).GetValue(ctx));
                }
            }
            return(f.Execute(arguments.ToArray(), ctx));
        }
示例#15
0
        public bool Contains(Functor functor)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }

            if (Methods.Contains(functor))
            {
                return true;
            }

            return false;
        }
示例#16
0
 public static bool Paste(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.V);
示例#17
0
 public static bool Screenshot(Functor check) => check.All.Key(KeyCode.F12);
示例#18
0
 public static bool Union(Functor check) => check.Any.Key(KeyCode.LeftShift, KeyCode.RightShift);
示例#19
0
 public static bool Save(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.S);
 public WamInstructionStreamClauseAttribute(int index, Functor functor, int clauseIndex)
     : base(index)
 {
     m_functor = functor;
     m_clauseIndex = clauseIndex;
 }
示例#21
0
        internal Predicate Add(Functor functor, PredicateDelegate predicateDelegate, bool canEvaluate)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (predicateDelegate == null)
            {
                throw new ArgumentNullException("predicateDelegate");
            }

            Predicate predicate = Methods.Add(functor, predicateDelegate, canEvaluate);

            return predicate;
        }
示例#22
0
 public WamInstruction(WamInstructionOpCodes opCode, Functor functor, int index)
 {
     if (functor == null)
     {
         throw new ArgumentNullException("functor");
     }
     if (index < 0)
     {
         throw new ArgumentException("Invalid index.", "index");
     }
     _opCode = opCode;
     _sourceRegister = WamInstructionRegister.Unused;
     _functor = functor;
     _index = index;
     _targetRegister = WamInstructionRegister.Unused;
     _referenceTarget = null;
 }
示例#23
0
        public WamInstructionStream Compile(CodeSentence codeSentence, Functor functor, int index, bool isLast, LibraryList libraries, bool optimize)
        {
            Initialize();

            // When true, indicates we are compiling code for a procedure clause.  When false, indicates we
            // are compiling for an ad hoc query.
            //
            bool isClause = (functor != null);

            if (isClause)
            {
                WamInstructionStreamClauseAttribute clauseAttribute = new WamInstructionStreamClauseAttribute(
                    m_instructionStreamBuilder.NextIndex,
                    functor,
                    index);
                m_instructionStreamBuilder.AddAttribute(clauseAttribute);
            }

            if (isClause)
            {
                if (isLast)
                {
                    if (index == 0)
                    {
                        // Procedure only has one clause in it.  No retry logic required.
                    }
                    else
                    {
                        TrustMe();
                    }
                }
                else
                {
                    if (index == 0)
                    {
                        TryMeElse(functor, index + 1);
                    }
                    else
                    {
                        RetryMeElse(functor, index + 1);
                    }
                }
            }

            Allocate();

            if (codeSentence.Head != null)
            {
                for (int idx = 0; idx < codeSentence.Head.Children.Count; ++idx)
                {
                    Get(codeSentence.Head.Children[idx], GetArgumentRegister(idx));
                }
            }

            if (codeSentence.Body.Count > 0)
            {
                for (int idxProcedure = 0; idxProcedure < codeSentence.Body.Count; ++idxProcedure)
                {
                    CodeCompoundTerm codeCompoundTerm = codeSentence.Body[idxProcedure];

                    for (int idxArgument = 0; idxArgument < codeCompoundTerm.Children.Count; ++idxArgument)
                    {
                        Put(codeCompoundTerm.Children[idxArgument], GetArgumentRegister(idxArgument), libraries);
                    }

                    bool isLastCall = (idxProcedure == codeSentence.Body.Count - 1);

                    if (isClause)
                    {
                        if (isLastCall)
                        {
                            if (optimize
                                && !libraries.Contains(Functor.Create(codeCompoundTerm.Functor))
                                && codeCompoundTerm.Functor != CodeFunctor.CutFunctor)
                            {
                                Deallocate();
                                Execute(codeCompoundTerm.Functor);
                            }
                            else
                            {
                                Call(codeCompoundTerm.Functor, libraries);
                                Deallocate();
                                Proceed();
                            }
                        }
                        else
                        {
                            Call(codeCompoundTerm.Functor, libraries);
                        }
                    }
                    else // isQuery
                    {
                        Call(codeCompoundTerm.Functor, libraries);

                        if (isLastCall)
                        {
                            Success();
                        }
                    }
                }
            }
            else // fact
            {
                if (isClause)
                {
                    Deallocate();
                    Proceed();
                }
                else // isQuery
                {
                    // No action required.
                }
            }

            return InstructionStreamBuilder.ToInstructionStream();
        }
示例#24
0
 private WamInstructionPointer GetInstructionPointer(Functor functor, int index)
 {
     Procedure procedure;
     if (m_program.Procedures.TryGetProcedure(functor, out procedure))
     {
         if (procedure.Clauses.Count >= index)
         {
             return new WamInstructionPointer(procedure.Clauses[index].WamInstructionStream);
         }
         else
         {
             return WamInstructionPointer.Undefined;
         }
     }
     else
     {
         return WamInstructionPointer.Undefined;
     }
 }
示例#25
0
        internal BacktrackingPredicate Add(Functor functor, BacktrackingPredicateDelegate backtrackingPredicateDelegate)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (backtrackingPredicateDelegate == null)
            {
                throw new ArgumentNullException("backtrackingPredicateDelegate");
            }

            BacktrackingPredicate backtrackingPredicate = Methods.Add(functor, backtrackingPredicateDelegate);

            return backtrackingPredicate;
        }
示例#26
0
        private WamCompoundTerm CreateCompoundTerm(Functor functor)
        {
            WamCompoundTerm value = WamCompoundTerm.Create(functor);

            CurrentStructure = value;
            CurrentStructureIndex = -1;

            return value;
        }
示例#27
0
        public LibraryMethod this[Functor functor]
        {
            get
            {
                if (functor == null)
                {
                    throw new ArgumentNullException("functor");
                }

                return Methods[functor];
            }
        }
示例#28
0
 public DeterministicExecutor(Functor end)
     : this(null, end)
 { }
示例#29
0
 public static bool LeftShift(Functor check) => check.All.Key(KeyCode.LeftShift);
示例#30
0
 private void RetryMeElse(Functor functor, int index)
 {
     InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.RetryMeElse, functor, index));
 }
示例#31
0
 public static bool Group(Functor check) => check.All.Key(KeyCode.G);
示例#32
0
        public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister targetRegister)
        {
            if (targetRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "targetRegister");
            }

            m_opCode = opCode;
            m_sourceRegister = WamInstructionRegister.Unused;
            m_functor = null;
            m_index = -1;
            m_targetRegister = targetRegister;
            m_referenceTarget = null;
        }
示例#33
0
 public AnyVerifier(Functor functor) : base(functor)
 {
 }
示例#34
0
        public WamInstruction(WamInstructionOpCodes opCode, Functor functor)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }

            m_opCode = opCode;
            m_sourceRegister = WamInstructionRegister.Unused;
            m_functor = functor;
            m_index = -1;
            m_targetRegister = WamInstructionRegister.Unused;
            m_referenceTarget = null;
        }
示例#35
0
 public static bool Delete(Functor check) => check.Any.Key(KeyCode.Delete, KeyCode.Backspace);
示例#36
0
 public WamInstruction(WamInstructionOpCodes opCode, WamReferenceTarget referenceTarget)
 {
     if (referenceTarget == null)
     {
         throw new ArgumentNullException("referenceTarget");
     }
     _opCode = opCode;
     _sourceRegister = WamInstructionRegister.Unused;
     _functor = null;
     _index = -1;
     _targetRegister = WamInstructionRegister.Unused;
     _referenceTarget = referenceTarget;
 }
示例#37
0
 public static bool Undo(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.Z);
示例#38
0
 public static bool Cancel(Functor check) => check.All.Key(KeyCode.Escape);
示例#39
0
 public static bool Copy(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.C);
示例#40
0
 public static bool CameraBackward(Functor check) => check.All.Key(KeyCode.S);
示例#41
0
 public static bool OpenScene(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.O);
示例#42
0
 public static bool CameraRight(Functor check) => check.All.Key(KeyCode.D);
示例#43
0
 public static bool Help(Functor check) => check.All.Key(KeyCode.F1);
示例#44
0
        internal CodePredicate Add(Functor functor, CodePredicateDelegate codePredicateDelegate)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (codePredicateDelegate == null)
            {
                throw new ArgumentNullException("codePredicateDelegate");
            }

            CodePredicate codePredicate = Methods.Add(functor, codePredicateDelegate);

            return codePredicate;
        }
示例#45
0
 public static bool CameraForward(Functor check) => check.All.Key(KeyCode.W);
示例#46
0
        public WamInstruction(WamInstructionOpCodes opCode, WamInstructionRegister sourceRegister, WamReferenceTarget referenceTarget)
        {
            if (referenceTarget == null)
            {
                throw new ArgumentNullException("referenceTarget");
            }
            if (sourceRegister.IsUnused)
            {
                throw new ArgumentException("Invalid value.", "sourceRegister");
            }

            m_opCode = opCode;
            m_sourceRegister = sourceRegister;
            m_functor = null;
            m_index = -1;
            m_targetRegister = WamInstructionRegister.Unused;
            m_referenceTarget = referenceTarget;
        }
示例#47
0
 public static bool CameraLeft(Functor check) => check.All.Key(KeyCode.A);
示例#48
0
 public static void Rule(Functor lhs, Atom atom)
 {
     lhs.Name = atom.Text;
 }
示例#49
0
 public static bool CameraFlight(Functor check) => Mouse.Button.Get.Right;
示例#50
0
 public static void Queue(WaitCallback functor) => Enqueue(Functor.Of(functor));
示例#51
0
 public static bool Enter(Functor check) => check.All.Key(KeyCode.Return);
示例#52
0
 public MRUStrategy(CacheGeometry cacheGeometry)
     : base(cacheGeometry, Functor.Greater <long>())
 {
 }
示例#53
0
 public static bool Apple(Functor check) =>
 check.Any.Key(KeyCode.LeftApple, KeyCode.RightApple, KeyCode.LeftWindows, KeyCode.RightWindows);
示例#54
0
 public static bool Win(Functor check) => Apple(check);
示例#55
0
 protected Verifier(Functor functor)
 {
     Functor = functor;
 }
示例#56
0
 public static bool Alt(Functor check) => check.Any.Key(KeyCode.LeftAlt, KeyCode.RightAlt);
示例#57
0
 public override bool Key(KeyCode first, params KeyCode[] other) =>
 other.Aggregate(Functor.func(first), (working, next) => working || Functor.func(next));
示例#58
0
        public Function Add(Functor functor, FunctionDelegate functionDelegate)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }
            if (functionDelegate == null)
            {
                throw new ArgumentNullException("functionDelegate");
            }

            Function function = Methods.Add(functor, functionDelegate);

            return function;
        }
示例#59
0
 public FunctionDescriptor(string theName, FunctionGroup theGroup, string[] theAlternates, Functor theFunctor, string description)
 {
     Name        = theName;
     Group       = theGroup;
     Alternates  = theAlternates;
     Functor     = theFunctor;
     Description = description;
 }
示例#60
0
 public static void Queue(WaitCallback functor, object argument) => Enqueue(Functor.Of(functor, argument));