UnifyAndReturnCutState() private method

private UnifyAndReturnCutState ( object v1, object v2 ) : IEnumerable
v1 object
v2 object
return IEnumerable
Ejemplo n.º 1
0
 internal override IEnumerable <CutState> Prove(object[] args, PrologContext context, ushort parentFrame)
 {
     if (args.Length != 1)
     {
         throw new ArgumentCountException("variable", args, new object[] { "Value" });
     }
     return(Term.UnifyAndReturnCutState(CurrentValue, args[0]));
 }
Ejemplo n.º 2
0
        private IEnumerable <CutState> BinaryPrimitiveImplementation(object[] args, PrologContext context)
        {
            if (args.Length != 2)
            {
                throw new ArgumentCountException(Name, args, expectedArguments);
            }
            var arg1 = Term.Deref(args[0]);
            var arg2 = Term.Deref(args[1]);
            var arg1AsLogicVariable = arg1 as LogicVariable;

            if (arg1AsLogicVariable != null)
            {
                var arg2AsLogicVariable = arg2 as LogicVariable;
                if (arg2AsLogicVariable != null)
                {
                    // Enumerating both arguments
                    if (doubleEnumerator == null)
                    {
                        throw new InstantiationException(
                                  arg1AsLogicVariable,
                                  "At least one argument to " + Name + "/2 must be instantiated.");
                    }
                    if (arg1AsLogicVariable == arg2AsLogicVariable)
                    {
                        throw new InvalidOperationException(Name + "(X,X) is not supported.");
                    }
                    return(EnumerateBothDriver(arg1AsLogicVariable, arg2AsLogicVariable, context));
                }
                if (!(arg2 is T2))
                {
                    throw new ArgumentTypeException(this.Name, this.arg2Name, arg1, typeof(T1));
                }

                if (arg1Function != null)
                {
                    // It's left-unique
                    T1 arg1Value;
                    if (arg1Function((T2)arg2, out arg1Value))
                    {
                        return(Term.UnifyAndReturnCutState(arg1, arg1Value));
                    }
                    return(PrologPrimitives.FailImplementation);
                }
                // It's not left-unique
                if (arg1Enumerator == null)
                {
                    throw new InstantiationException(arg1AsLogicVariable, Name + "/2: first argument must be instantiated.");
                }
                return(this.EnumerateArg1Driver(arg1AsLogicVariable, (T2)arg2, context));
            }

            var variable1 = arg2 as LogicVariable;

            if (variable1 != null)
            {
                if (!(arg1 is T1))
                {
                    throw new ArgumentTypeException(this.Name, this.arg1Name, arg1, typeof(T1));
                }

                if (arg2Function != null)
                {
                    // It's right-unique
                    T2 arg2Value;
                    if (arg2Function((T1)arg1, out arg2Value))
                    {
                        return(Term.UnifyAndReturnCutState(arg2, arg2Value));
                    }
                    return(PrologPrimitives.FailImplementation);
                }
                // It's not right-unqiue
                if (arg2Enumerator == null)
                {
                    throw new InstantiationException(variable1, Name + "/2: second argument must be instantiated.");
                }
                return(this.EnumerateArg2Driver((T1)arg1, variable1, context));
            }
            // Filtering
            if (!(arg1 is T1))
            {
                throw new ArgumentTypeException(this.Name, this.arg1Name, arg1, typeof(T1));
            }
            if (!(arg2 is T2))
            {
                throw new ArgumentTypeException(this.Name, this.arg1Name, arg1, typeof(T1));
            }
            if (filter == null)
            {
                throw new InstantiatedVariableException(null, Name + ": at least one argument must be uninstantiated.");
            }
            return(CutStateSequencer.FromBoolean(this.filter((T1)arg1, (T2)arg2)));
        }