TraceOutput() public method

Prints trace information.
public TraceOutput ( string format, object arg ) : void
format string
arg object
return void
Beispiel #1
0
        IEnumerable <CutState> CallPrimitive(Symbol functor, PrologPrimitives.PrimitiveImplementation handler, object[] args, PrologContext context)
        {
            if (Trace)
            {
                context.TraceOutput("Goal: {0}", new Structure(functor, args));
            }
            foreach (var state in handler(args, context))
            {
                if (Trace)
                {
                    context.TraceOutput((state == CutState.Continue) ? "Succeed: {0}" : "Cut: {0}", new Structure(functor, args));
                }
                yield return(state);

                if (Trace)
                {
                    context.TraceOutput("Retry: {0}", new Structure(functor, args));
                }
            }
            if (Trace)
            {
                context.TraceOutput("Fail: {0}", new Structure(functor, args));
            }
            context.PopGoalStack();
        }
Beispiel #2
0
        /// <summary>
        /// Tests clauses in a randomized order (but still exhaustively).
        /// Uses Shuffler to generate a random permutation.
        /// </summary>
        IEnumerable <CutState> TestShuffledClauses(object[] args, PrologContext context, ushort myFrame)
        {
            entriesListUsed = true;
            var mark        = context.MarkTrace();
            var shuffler    = new Shuffler((ushort)Entries.Count);
            var argIndexers = PredicateArgumentIndexer.ArglistIndexers(args);

            while (!shuffler.Done)
            {
                var entry = Entries[shuffler.Next()];
                if (entry.Prematch(argIndexers))
                {
                    // This shouldn't be here...
                    //context.PushGoalStack(Name, args, myFrame);
                    context.SetCurrentRule(entry);
                    foreach (var cutState in entry.Prove(args, context, myFrame))
                    {
                        if (cutState == CutState.ForceFail)
                        {
                            if (KnowledgeBase.Trace || Trace)
                            {
                                context.TraceOutput("Cut: {0}", new Structure(Name, args));
                            }
                            goto fail;
                        }
                        if (KnowledgeBase.Trace || Trace)
                        {
                            context.TraceOutput("Succeed: {0}", new Structure(Name, args));
                        }
                        yield return(CutState.Continue);

                        if (KnowledgeBase.Trace || Trace)
                        {
                            context.TraceOutput("Retry: {0}", new Structure(Name, args));
                        }
                    }
                }
            }
fail:
            context.RestoreVariables(mark);
            if (KnowledgeBase.Trace || Trace)
            {
                context.TraceOutput("Fail: {0}", new Structure(Name, args));
            }
            //context.UnwindStack(Name, args);
            context.UnwindStack(myFrame);
        }
Beispiel #3
0
        /// <summary>
        /// Tests clauses in the order they appear in the database.
        /// </summary>
        IEnumerable <CutState> TestClausesInOrder(object[] args, PrologContext context, ushort myFrame)
        {
            var mark        = context.MarkTrace();
            var argIndexers = PredicateArgumentIndexer.ArglistIndexers(args);

            entriesListUsed = true;
            foreach (var entry in Entries)
            {
                if (entry.Prematch(argIndexers))
                {
                    context.SetCurrentRule(entry);
                    foreach (var cutState in entry.Prove(args, context, myFrame))
                    {
                        if (cutState == CutState.ForceFail)
                        {
                            if (KnowledgeBase.Trace || Trace)
                            {
                                context.TraceOutput("Cut: {0}", new Structure(Name, args));
                            }
                            goto fail;
                        }
                        if (KnowledgeBase.Trace || Trace)
                        {
                            context.TraceOutput("Succeed: {0}", new Structure(Name, args));
                        }
                        yield return(CutState.Continue);

                        if (KnowledgeBase.Trace || Trace)
                        {
                            context.TraceOutput("Retry: {0}", new Structure(Name, args));
                        }
                    }
                }
            }
fail:
            context.RestoreVariables(mark);
            if (KnowledgeBase.Trace || Trace)
            {
                context.TraceOutput("Fail: {0}", new Structure(Name, args));
            }
            //context.UnwindStack(Name, args);
            context.UnwindStack(myFrame);
        }
Beispiel #4
0
        internal IEnumerable <CutState> Prove(object[] args, PrologContext context)
        {
            var myFrame = context.CurrentFrame;

            if (KnowledgeBase.Trace || Trace)
            {
                context.TraceOutput("Goal: {0}", new Structure(Name, args));
            }
            if (Compiled)
            {
                context.PushArguments(args);
                return(StackCall(context));
            }
            if (context.Randomize && Randomizable && Entries.Count > 1)
            {
                return(TestShuffledClauses(args, context, myFrame));
            }
            return(TestClausesInOrder(args, context, myFrame));
        }
 IEnumerable<CutState> CallPrimitive(Symbol functor, PrologPrimitives.PrimitiveImplementation handler, object[] args, PrologContext context)
 {
     if (Trace)
         context.TraceOutput("Goal: {0}", new Structure(functor, args));
     foreach (var state in handler(args, context))
     {
         if (Trace)
         context.TraceOutput((state == CutState.Continue) ? "Succeed: {0}" : "Cut: {0}", new Structure(functor, args));
         yield return state;
         if (Trace)
             context.TraceOutput("Retry: {0}", new Structure(functor, args));
     }
     if (Trace)
         context.TraceOutput("Fail: {0}", new Structure(functor, args));
     context.PopGoalStack();
 }
Beispiel #6
0
 /// <summary>
 /// Tests clauses in a randomized order (but still exhaustively).
 /// Uses Shuffler to generate a random permutation.
 /// </summary>
 IEnumerable<CutState> TestShuffledClauses(object[] args, PrologContext context, ushort myFrame)
 {
     entriesListUsed = true;
     var mark = context.MarkTrace();
     var shuffler = new Shuffler((ushort)Entries.Count);
     var argIndexers = PredicateArgumentIndexer.ArglistIndexers(args);
     while (!shuffler.Done)
     {
         var entry = Entries[shuffler.Next()];
         if (entry.Prematch(argIndexers))
         {
             // This shouldn't be here...
             //context.PushGoalStack(Name, args, myFrame);
             context.SetCurrentRule(entry);
             foreach (var cutState in entry.Prove(args, context, myFrame))
             {
                 if (cutState == CutState.ForceFail)
                 {
                     if (KnowledgeBase.Trace || Trace)
                         context.TraceOutput("Cut: {0}", new Structure(Name, args));
                     goto fail;
                 }
                 if (KnowledgeBase.Trace || Trace)
                     context.TraceOutput("Succeed: {0}", new Structure(Name, args));
                 yield return CutState.Continue;
                 if (KnowledgeBase.Trace || Trace)
                     context.TraceOutput("Retry: {0}", new Structure(Name, args));
             }
         }
     }
     fail:
     context.RestoreVariables(mark);
     if (KnowledgeBase.Trace || Trace)
         context.TraceOutput("Fail: {0}", new Structure(Name, args));
     //context.UnwindStack(Name, args);
     context.UnwindStack(myFrame);
 }
Beispiel #7
0
 /// <summary>
 /// Tests clauses in the order they appear in the database.
 /// </summary>
 IEnumerable<CutState> TestClausesInOrder(object[] args, PrologContext context, ushort myFrame)
 {
     var mark = context.MarkTrace();
     var argIndexers = PredicateArgumentIndexer.ArglistIndexers(args);
     entriesListUsed = true;
     foreach (var entry in Entries)
     {
         if (entry.Prematch(argIndexers))
         {
             context.SetCurrentRule(entry);
             foreach (var cutState in entry.Prove(args, context, myFrame))
             {
                 if (cutState == CutState.ForceFail)
                 {
                     if (KnowledgeBase.Trace || Trace)
                         context.TraceOutput("Cut: {0}", new Structure(Name, args));
                     goto fail;
                 }
                 if (KnowledgeBase.Trace || Trace)
                     context.TraceOutput("Succeed: {0}", new Structure(Name, args));
                 yield return CutState.Continue;
                 if (KnowledgeBase.Trace || Trace)
                     context.TraceOutput("Retry: {0}", new Structure(Name, args));
             }
         }
     }
     fail:
     context.RestoreVariables(mark);
     if (KnowledgeBase.Trace || Trace)
         context.TraceOutput("Fail: {0}", new Structure(Name, args));
     //context.UnwindStack(Name, args);
     context.UnwindStack(myFrame);
 }
Beispiel #8
0
 internal IEnumerable<CutState> Prove(object[] args, PrologContext context)
 {
     var myFrame = context.CurrentFrame;
     if (KnowledgeBase.Trace || Trace)
         context.TraceOutput("Goal: {0}", new Structure(Name, args));
     if (Compiled)
     {
         context.PushArguments(args);
         return StackCall(context);
     }
     if (context.Randomize && Randomizable && Entries.Count > 1)
         return TestShuffledClauses(args, context, myFrame);
     return TestClausesInOrder(args, context, myFrame);
 }