示例#1
0
   public InterpreterEvaluationTerm(TrsTermBase root, TrsTermBase subterm, InterpreterTerm cacheSourceTerm, 
 UnificationResult currentUnifier)
       : base(root)
   {
       if (subterm == null) throw new ArgumentException("subterm");
         if (cacheSourceTerm == null) throw new ArgumentException("cacheSourceTerm");
         if (currentUnifier == null) throw new ArgumentException("currentUnifier");
         CurrentSubTerm = subterm;
         CacheSourceTerm = cacheSourceTerm;
         Unifier = currentUnifier;
   }
示例#2
0
        private void ExecuteRewriteForRule(InterpreterEvaluationTerm termToRewrite, TrsReductionRule rule, UnificationResult composedUnifier)
        {
            bool rewritingTookPlaceLocal = false;

            if (composedUnifier.Succeed)
            {
                if (rule.Tail.GetType() == typeof(TrsNativeKeyword))
                {
                    // Replacing term value with a native function generated value
                    var nativeTermInHead = ((TrsTermBase)termToRewrite.CurrentSubTerm.CreateCopy()).ApplySubstitutions(composedUnifier.Unifier);
                    foreach (var native in nativeFunctions)
                    {
                        var processedTerm = native.Evaluate(nativeTermInHead);
                        if (processedTerm == null)
                        {
                            throw new Exception(string.Format("Native function in type {0} returned null", native.GetType().FullName));
                        }
                        // If the rewrite result is the same, no rewriting took place ...
                        if (!nativeTermInHead.Equals(processedTerm))
                        {
                            var newTerm = termToRewrite.RootTerm.CreateCopyAndReplaceSubTerm(termToRewrite.CurrentSubTerm, processedTerm);
                            rewritingTookPlaceLocal = true;
                            var newTermWrapper = new InterpreterTerm(newTerm);
                            newTermWrapper.IsNewTerm = true;
                            executionCache.Add(newTermWrapper);
                        }
                    }
                }
                else
                {
                    // Normal rewriting without native eval functions
                    var replacementTerm = ((TrsTermBase)rule.Tail.CreateCopy()).ApplySubstitutions(composedUnifier.Unifier);
                    if (!termToRewrite.CurrentSubTerm.Equals(replacementTerm))
                    {
                        var newTerm = termToRewrite.RootTerm.CreateCopyAndReplaceSubTerm(termToRewrite.CurrentSubTerm, replacementTerm);
                        rewritingTookPlaceLocal = true;
                        var newTermWrapper = new InterpreterTerm(newTerm);
                        newTermWrapper.IsNewTerm = true;
                        executionCache.Add(newTermWrapper);
                    }
                }
            }
            if (rewritingTookPlaceLocal)
            {
                rewritingTookPlace = true; // stops rewriting on next rewrite step
                termToRewrite.CacheSourceTerm.MustDeletFromCache = true;
            }
        }
 public InterpreterEvaluationTerm(TrsTermBase root, TrsTermBase subterm, InterpreterTerm cacheSourceTerm,
                                  UnificationResult currentUnifier)
     : base(root)
 {
     if (subterm == null)
     {
         throw new ArgumentException("subterm");
     }
     if (cacheSourceTerm == null)
     {
         throw new ArgumentException("cacheSourceTerm");
     }
     if (currentUnifier == null)
     {
         throw new ArgumentException("currentUnifier");
     }
     CurrentSubTerm  = subterm;
     CacheSourceTerm = cacheSourceTerm;
     Unifier         = currentUnifier;
 }
示例#4
0
 private void ExecuteRewriteForRule(InterpreterEvaluationTerm termToRewrite, TrsReductionRule rule, UnificationResult composedUnifier)
 {
     bool rewritingTookPlaceLocal = false;
       if (composedUnifier.Succeed)
       {
     if (rule.Tail.GetType() == typeof(TrsNativeKeyword))
     {
       // Replacing term value with a native function generated value
       var nativeTermInHead = ((TrsTermBase)termToRewrite.CurrentSubTerm.CreateCopy()).ApplySubstitutions(composedUnifier.Unifier);
       foreach (var native in nativeFunctions)
       {
     var processedTerm = native.Evaluate(nativeTermInHead);
     if (processedTerm == null) throw new Exception(string.Format("Native function in type {0} returned null", native.GetType().FullName));
     // If the rewrite result is the same, no rewriting took place ...
     if (!nativeTermInHead.Equals(processedTerm))
     {
       var newTerm = termToRewrite.RootTerm.CreateCopyAndReplaceSubTerm(termToRewrite.CurrentSubTerm, processedTerm);
       rewritingTookPlaceLocal = true;
       var newTermWrapper = new InterpreterTerm(newTerm);
       newTermWrapper.IsNewTerm = true;
       executionCache.Add(newTermWrapper);
     }
       }
     }
     else
     {
       // Normal rewriting without native eval functions
       var replacementTerm = ((TrsTermBase)rule.Tail.CreateCopy()).ApplySubstitutions(composedUnifier.Unifier);
       if (!termToRewrite.CurrentSubTerm.Equals(replacementTerm))
       {
     var newTerm = termToRewrite.RootTerm.CreateCopyAndReplaceSubTerm(termToRewrite.CurrentSubTerm, replacementTerm);
     rewritingTookPlaceLocal = true;
     var newTermWrapper = new InterpreterTerm(newTerm);
     newTermWrapper.IsNewTerm = true;
     executionCache.Add(newTermWrapper);
       }
     }
       }
       if (rewritingTookPlaceLocal)
       {
     rewritingTookPlace = true; // stops rewriting on next rewrite step
     termToRewrite.CacheSourceTerm.MustDeletFromCache = true;
       }
 }