示例#1
0
                public InterpretedRuleHitCheckExpression(Expression /*!*/ test, CachedBindingInfo /*!*/ bindingInfo)
                {
                    Assert.NotNull(test, bindingInfo);

                    _test        = test;
                    _bindingInfo = bindingInfo;
                }
示例#2
0
            public T /*!*/ Bind(DynamicMetaObjectBinder /*!*/ binder, int compilationThreshold, object[] args)
            {
                if (CachedBindingInfo <T> .LastInterpretedFailure != null && CachedBindingInfo <T> .LastInterpretedFailure.Binder == binder)
                {
                    // we failed the rule because we have a compiled target available, return the compiled target
                    Debug.Assert(CachedBindingInfo <T> .LastInterpretedFailure.CompiledTarget != null);
                    var res = CachedBindingInfo <T> .LastInterpretedFailure.CompiledTarget;
                    CachedBindingInfo <T> .LastInterpretedFailure = null;
                    return(res);
                }

                // we haven't produced a rule yet....
                var bindingInfo = new CachedBindingInfo <T>(binder, compilationThreshold);

                var targetMO = DynamicMetaObject.Create(args[0], _parameters[1]); // 1 is skipping CallSite

                DynamicMetaObject[] argsMO = new DynamicMetaObject[args.Length - 1];
                for (int i = 0; i < argsMO.Length; i++)
                {
                    argsMO[i] = DynamicMetaObject.Create(args[i + 1], _parameters[i + 2]);
                }
                var binding = binder.Bind(targetMO, argsMO);

                return(CreateDelegate(binding, bindingInfo));
            }
示例#3
0
        /// <summary>
        /// Provides the test to see if an interpreted call site should switch over to being compiled.
        /// </summary>
        public static bool InterpretedCallSiteTest(bool restrictionResult, object bindingInfo)
        {
            if (restrictionResult)
            {
                CachedBindingInfo bindInfo = (CachedBindingInfo)bindingInfo;
                if (bindInfo.CompilationThreshold >= 0)
                {
                    // still interpreting...
                    bindInfo.CompilationThreshold--;
                    return(true);
                }

                return(bindInfo.CheckCompiled());
            }
            return(false);
        }
示例#4
0
            private Expression <T> /*!*/ Compile(DynamicMetaObject /*!*/ obj, CachedBindingInfo <T> /*!*/ bindingInfo)
            {
                var restrictions = obj.Restrictions.ToExpression();

                var body = Expression.Condition(
                    new InterpretedRuleHitCheckExpression(restrictions, bindingInfo),
                    AstUtils.Convert(obj.Expression, _updateExpression.Type),
                    _updateExpression
                    );

                var res = Expression.Lambda <T>(
                    body,
                    "CallSite.Target",
                    true, // always compile the rules with tail call optimization
                    _parameters
                    );

                bindingInfo.Target = res;
                return(res);
            }
示例#5
0
        /// <summary>
        /// Provides the test to see if an interpreted call site should switch over to being compiled.
        /// </summary>
        public static bool InterpretedCallSiteTest(bool restrictionResult, object bindingInfo)
        {
            if (restrictionResult)
            {
                CachedBindingInfo bindInfo = (CachedBindingInfo)bindingInfo;
                if (bindInfo.CompilationThreshold >= 0)
                {
                    // still interpreting...
                    bindInfo.CompilationThreshold--;
                    return(true);
                }
#if SILVERLIGHT
                if (PlatformAdaptationLayer.IsCompactFramework)
                {
                    bindInfo.CompilationThreshold = Int32.MaxValue;
                    return(true);
                }
#endif
                return(bindInfo.CheckCompiled());
            }
            return(false);
        }
示例#6
0
 private T /*!*/ CreateDelegate(DynamicMetaObject /*!*/ binding, CachedBindingInfo <T> /*!*/ bindingInfo)
 {
     return(Compile(binding, bindingInfo).LightCompile(Int32.MaxValue));
 }