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; }
internal Function(LibraryMethodList container, Functor functor, FunctionDelegate functionDelegate) : base(container, functor, true) { if (functionDelegate == null) { throw new ArgumentNullException("functionDelegate"); } m_functionDelegate = functionDelegate; }
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; }
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]; } }
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)); }
public bool Contains(Functor functor) { if (functor == null) { throw new ArgumentNullException("functor"); } if (Methods.Contains(functor)) { return true; } return false; }
public static bool Paste(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.V);
public static bool Screenshot(Functor check) => check.All.Key(KeyCode.F12);
public static bool Union(Functor check) => check.Any.Key(KeyCode.LeftShift, KeyCode.RightShift);
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; }
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; }
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(); }
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; } }
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; }
private WamCompoundTerm CreateCompoundTerm(Functor functor) { WamCompoundTerm value = WamCompoundTerm.Create(functor); CurrentStructure = value; CurrentStructureIndex = -1; return value; }
public LibraryMethod this[Functor functor] { get { if (functor == null) { throw new ArgumentNullException("functor"); } return Methods[functor]; } }
public DeterministicExecutor(Functor end) : this(null, end) { }
public static bool LeftShift(Functor check) => check.All.Key(KeyCode.LeftShift);
private void RetryMeElse(Functor functor, int index) { InstructionStreamBuilder.Write(new WamInstruction(WamInstructionOpCodes.RetryMeElse, functor, index)); }
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; }
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; }
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; }
public static bool Undo(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.Z);
public static bool Cancel(Functor check) => check.All.Key(KeyCode.Escape);
public static bool Copy(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.C);
public static bool CameraBackward(Functor check) => check.All.Key(KeyCode.S);
public static bool OpenScene(Functor check) => Modifier.Ctrl && check.All.Key(KeyCode.O);
public static bool CameraRight(Functor check) => check.All.Key(KeyCode.D);
public static bool Help(Functor check) => check.All.Key(KeyCode.F1);
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; }
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; }
public static bool CameraLeft(Functor check) => check.All.Key(KeyCode.A);
public static void Rule(Functor lhs, Atom atom) { lhs.Name = atom.Text; }
public static bool CameraFlight(Functor check) => Mouse.Button.Get.Right;
public static void Queue(WaitCallback functor) => Enqueue(Functor.Of(functor));
public static bool Enter(Functor check) => check.All.Key(KeyCode.Return);
public MRUStrategy(CacheGeometry cacheGeometry) : base(cacheGeometry, Functor.Greater <long>()) { }
public static bool Apple(Functor check) => check.Any.Key(KeyCode.LeftApple, KeyCode.RightApple, KeyCode.LeftWindows, KeyCode.RightWindows);
public static bool Win(Functor check) => Apple(check);
protected Verifier(Functor functor) { Functor = functor; }
public static bool Alt(Functor check) => check.Any.Key(KeyCode.LeftAlt, KeyCode.RightAlt);
public override bool Key(KeyCode first, params KeyCode[] other) => other.Aggregate(Functor.func(first), (working, next) => working || Functor.func(next));
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; }
public FunctionDescriptor(string theName, FunctionGroup theGroup, string[] theAlternates, Functor theFunctor, string description) { Name = theName; Group = theGroup; Alternates = theAlternates; Functor = theFunctor; Description = description; }
public static void Queue(WaitCallback functor, object argument) => Enqueue(Functor.Of(functor, argument));