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;
 }
        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;
        }
 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;
 }
Beispiel #5
0
        internal Function(LibraryMethodList container, Functor functor, FunctionDelegate functionDelegate)
            : base(container, functor, true)
        {
            if (functionDelegate == null)
            {
                throw new ArgumentNullException("functionDelegate");
            }

            m_functionDelegate = functionDelegate;
        }
Beispiel #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];
        }
        internal CodePredicate(LibraryMethodList container, Functor functor, CodePredicateDelegate codePredicateDelegate)
            : base(container, functor, false)
        {
            if (codePredicateDelegate == null)
            {
                throw new ArgumentNullException("codePredicateDelegate");
            }

            m_codePredicateDelegate = codePredicateDelegate;
        }
Beispiel #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>());
 }
        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;
        }
 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;
 }
        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];
            }
        }
Beispiel #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));
        }
Beispiel #15
0
        public bool Contains(Functor functor)
        {
            if (functor == null)
            {
                throw new ArgumentNullException("functor");
            }

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

            return false;
        }
Beispiel #16
0
 public static bool Paste(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.V);
Beispiel #17
0
 public static bool Screenshot(Functor check) => check.All.Key(KeyCode.F12);
Beispiel #18
0
 public static bool Union(Functor check) => check.Any.Key(KeyCode.LeftShift, KeyCode.RightShift);
Beispiel #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;
 }
Beispiel #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;
        }
 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;
 }
Beispiel #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();
        }
Beispiel #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;
     }
 }
Beispiel #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;
        }
Beispiel #26
0
        private WamCompoundTerm CreateCompoundTerm(Functor functor)
        {
            WamCompoundTerm value = WamCompoundTerm.Create(functor);

            CurrentStructure = value;
            CurrentStructureIndex = -1;

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

                return Methods[functor];
            }
        }
 public DeterministicExecutor(Functor end)
     : this(null, end)
 { }
Beispiel #29
0
 public static bool LeftShift(Functor check) => check.All.Key(KeyCode.LeftShift);
Beispiel #30
0
 private void RetryMeElse(Functor functor, int index)
 {
     InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.RetryMeElse, functor, index));
 }
Beispiel #31
0
 public static bool Group(Functor check) => check.All.Key(KeyCode.G);
        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;
        }
Beispiel #33
0
 public AnyVerifier(Functor functor) : base(functor)
 {
 }
        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;
        }
Beispiel #35
0
 public static bool Delete(Functor check) => check.Any.Key(KeyCode.Delete, KeyCode.Backspace);
 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;
 }
Beispiel #37
0
 public static bool Undo(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.Z);
Beispiel #38
0
 public static bool Cancel(Functor check) => check.All.Key(KeyCode.Escape);
Beispiel #39
0
 public static bool Copy(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.C);
Beispiel #40
0
 public static bool CameraBackward(Functor check) => check.All.Key(KeyCode.S);
Beispiel #41
0
 public static bool OpenScene(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.O);
Beispiel #42
0
 public static bool CameraRight(Functor check) => check.All.Key(KeyCode.D);
Beispiel #43
0
 public static bool Help(Functor check) => check.All.Key(KeyCode.F1);
Beispiel #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;
        }
Beispiel #45
0
 public static bool CameraForward(Functor check) => check.All.Key(KeyCode.W);
        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;
        }
Beispiel #47
0
 public static bool CameraLeft(Functor check) => check.All.Key(KeyCode.A);
Beispiel #48
0
 public static void Rule(Functor lhs, Atom atom)
 {
     lhs.Name = atom.Text;
 }
Beispiel #49
0
 public static bool CameraFlight(Functor check) => Mouse.Button.Get.Right;
Beispiel #50
0
 public static void Queue(WaitCallback functor) => Enqueue(Functor.Of(functor));
Beispiel #51
0
 public static bool Enter(Functor check) => check.All.Key(KeyCode.Return);
Beispiel #52
0
 public MRUStrategy(CacheGeometry cacheGeometry)
     : base(cacheGeometry, Functor.Greater <long>())
 {
 }
Beispiel #53
0
 public static bool Apple(Functor check) =>
 check.Any.Key(KeyCode.LeftApple, KeyCode.RightApple, KeyCode.LeftWindows, KeyCode.RightWindows);
Beispiel #54
0
 public static bool Win(Functor check) => Apple(check);
Beispiel #55
0
 protected Verifier(Functor functor)
 {
     Functor = functor;
 }
Beispiel #56
0
 public static bool Alt(Functor check) => check.Any.Key(KeyCode.LeftAlt, KeyCode.RightAlt);
Beispiel #57
0
 public override bool Key(KeyCode first, params KeyCode[] other) =>
 other.Aggregate(Functor.func(first), (working, next) => working || Functor.func(next));
Beispiel #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;
        }
Beispiel #59
0
 public FunctionDescriptor(string theName, FunctionGroup theGroup, string[] theAlternates, Functor theFunctor, string description)
 {
     Name        = theName;
     Group       = theGroup;
     Alternates  = theAlternates;
     Functor     = theFunctor;
     Description = description;
 }
Beispiel #60
0
 public static void Queue(WaitCallback functor, object argument) => Enqueue(Functor.Of(functor, argument));