Ejemplo n.º 1
0
                public InterpretedRuleHitCheckExpression(Expression /*!*/ test, CachedBindingInfo /*!*/ bindingInfo)
                {
                    Assert.NotNull(test, bindingInfo);

                    _test        = test;
                    _bindingInfo = bindingInfo;
                }
Ejemplo n.º 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));
            }
Ejemplo n.º 3
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);
            }
Ejemplo n.º 4
0
 private T /*!*/ CreateDelegate(DynamicMetaObject /*!*/ binding, CachedBindingInfo <T> /*!*/ bindingInfo)
 {
     return(Compile(binding, bindingInfo).LightCompile(Int32.MaxValue));
 }