示例#1
0
 public static void AddRule <T>(CallSite <T> site, CallSiteRule <T> rule) where T : class
 {
     lock (site) {
         if (site.Rules == null)
         {
             site.Rules = rule.RuleSet;
         }
         else
         {
             site.Rules = site.Rules.AddRule(rule);
         }
     }
 }
示例#2
0
        public static CallSiteRule <T> CreateNewRule <T>(CallSite <T> site, CallSiteRule <T> oldRule, CallSiteRule <T> originalRule, object[] args) where T : class
        {
            if (oldRule != null)
            {
                //
                // The rule didn't work and since we optimistically added it into the
                // level 2 cache. Remove it now since the rule is no good.
                //
                site.RuleCache.RemoveRule(args, oldRule);
            }

            Expression binding = site.Binder.Bind(args, CallSiteRule <T> .Parameters, CallSiteRule <T> .ReturnLabel);

            //
            // Check the produced rule
            //
            if (binding == null)
            {
                throw Error.NoOrInvalidRuleProduced();
            }

            var rule = new CallSiteRule <T>(binding);

            if (originalRule != null)
            {
                // compare our new rule and our original monomorphic rule.  If they only differ from constants
                // then we'll want to re-use the code gen if possible.
                rule = AutoRuleTemplate.CopyOrCreateTemplatedRule(originalRule, rule);
            }

            //
            // Add the rule to the level 2 cache. This is an optimistic add so that cache miss
            // on another site can find this existing rule rather than building a new one.  We
            // add the originally added rule, not the templated one, to the global cache.  That
            // allows sites to template on their own.
            //
            site.RuleCache.AddRule(args, rule);

            return(rule);
        }
示例#3
0
 public static void MoveRule <T>(CallSite <T> site, CallSiteRule <T> rule, object [] args) where T : class
 {
     site.RuleCache.MoveRule(rule, args);
 }
示例#4
0
 public static T SetTarget <T>(CallSite <T> site, CallSiteRule <T> rule) where T : class
 {
     return(site.Target = rule.RuleSet.GetTarget());
 }