Esempio n. 1
0
 public override WamReferenceTarget Clone()
 {
     var result = new WamVariable(Generation);
     if (Target != null)
     {
         result.Target = Target.Clone();
     }
     return result;
 }
Esempio n. 2
0
        public override WamReferenceTarget Clone()
        {
            var result = new WamVariable(Generation);

            if (Target != null)
            {
                result.Target = Target.Clone();
            }
            return(result);
        }
Esempio n. 3
0
        void Trail(WamVariable variable)
        {
            if (ChoicePoint == null)
            {
                return;
            }

            if (variable.Generation <= ChoicePoint.Generation)
            {
                ChoicePoint.Trail.Add(variable);
            }
        }
        public CodeVariable Lookup(WamVariable wamVariable)
        {
            if (wamVariable == null)
            {
                throw new ArgumentNullException("wamVariable");
            }

            CodeVariable codeVariable;
            if (!_variables.TryGetValue(wamVariable, out codeVariable))
            {
                ++_count;
                codeVariable = new CodeVariable(string.Format("V{0}", _count));
                _variables.Add(wamVariable, codeVariable);
            }
            return codeVariable;
        }
Esempio n. 5
0
        public CodeVariable Lookup(WamVariable wamVariable)
        {
            if (wamVariable == null)
            {
                throw new ArgumentNullException("wamVariable");
            }

            CodeVariable codeVariable;

            if (!_variables.TryGetValue(wamVariable, out codeVariable))
            {
                ++_count;
                codeVariable = new CodeVariable(string.Format("V{0}", _count));
                _variables.Add(wamVariable, codeVariable);
            }
            return(codeVariable);
        }
Esempio n. 6
0
        public static bool FindAll(WamMachine machine, WamReferenceTarget[] arguments)
        {
            Debug.Assert(arguments.Length == 3);

            WamReferenceTarget arg0 = arguments[0].Dereference();
            WamReferenceTarget arg1 = arguments[1].Dereference();
            WamReferenceTarget arg2 = arguments[2].Dereference();

            WamVariable variable = arg0 as WamVariable;

            if (variable == null)
            {
                return(false);
            }

            WamCompoundTerm goal = arg1 as WamCompoundTerm;

            if (goal == null)
            {
                return(false);
            }

            WamVariable result = arg2 as WamVariable;

            if (result == null)
            {
                return(false);
            }

            WamInstructionStreamBuilder builder = new WamInstructionStreamBuilder();

            builder.Write(new WamInstruction(WamInstructionOpCodes.Allocate));
            for (int idx = 0; idx < goal.Functor.Arity; ++idx)
            {
                builder.Write(new WamInstruction(
                                  WamInstructionOpCodes.PutValue,
                                  goal.Children[idx],
                                  new WamInstructionRegister(WamInstructionRegisterTypes.Argument, (byte)idx)));
            }
            builder.Write(new WamInstruction(WamInstructionOpCodes.Call, goal.Functor));
            builder.Write(new WamInstruction(WamInstructionOpCodes.Success));

            machine.PushContext(builder.ToInstructionStream());

            List <WamReferenceTarget> values = new List <WamReferenceTarget>();

            try
            {
                ExecutionResults results = machine.RunToSuccess();
                while (results == ExecutionResults.Success)
                {
                    WamReferenceTarget value = variable.Clone();
                    values.Add(value);

                    results = machine.RunToSuccess();
                }
            }
            finally
            {
                machine.PopContext(true);
            }

            // Unbind the variable from the last results found by the goal.
            //
            variable.Unbind();

            // Unify the output variable with the list of values.
            //
            return(machine.Unify(result, WamReferenceTarget.Create(values)));
        }
Esempio n. 7
0
 private void Trail(WamVariable variable)
 {
     if (ChoicePoint != null)
     {
         if (variable.Generation <= ChoicePoint.Generation)
         {
             ChoicePoint.Trail.Add(variable);
         }
     }
 }
Esempio n. 8
0
 private void Bind(WamVariable variable, WamReferenceTarget target)
 {
     variable.Bind(target);
     Trail(variable);
 }
Esempio n. 9
0
 void Bind(WamVariable variable, WamReferenceTarget target)
 {
     variable.Bind(target);
     Trail(variable);
 }
Esempio n. 10
0
        void Trail(WamVariable variable)
        {
            if (ChoicePoint == null) return;

            if (variable.Generation <= ChoicePoint.Generation)
            {
                ChoicePoint.Trail.Add(variable);
            }
        }