internal CodePredicate Add(Functor functor, CodePredicateDelegate codePredicateDelegate) { if (functor == null) { throw new ArgumentNullException("functor"); } if (codePredicateDelegate == null) { throw new ArgumentNullException("codePredicateDelegate"); } if (Contains(functor)) { throw new ArgumentException("Item already exists.", "functor"); } CodePredicate predicate = new CodePredicate(this, functor, codePredicateDelegate); Items.Add(predicate); Library.Touch(); return(predicate); }
private ExecutionResults OnLibraryCallCodePredicate(WamInstruction instruction, CodePredicate predicate) { WamReferenceTarget[] arguments = new WamReferenceTarget[instruction.Functor.Arity]; for (int index = 0; index < instruction.Functor.Arity; ++index) { arguments[index] = ArgumentRegisters[index]; } try { predicate.CodePredicateDelegate(this, arguments); } catch { // Backtrack on exception. // return ExecutionResults.Backtrack; } return ExecutionResults.None; }