internal void Compile(object state) { if (this._compiled == null) { lock (this._compileLock) { if (this._compiled == null) { LambdaExpression lambda = this._lambda as LambdaExpression; if (this._interpreter != null) { this._compiledDelegateType = GetFuncOrAction(lambda); lambda = Expression.Lambda(this._compiledDelegateType, lambda.Body, lambda.Name, lambda.Parameters); } if (this.HasClosure) { this._compiled = LightLambdaClosureVisitor.BindLambda(lambda, this._interpreter.ClosureVariables); } else { this._compiled = lambda.Compile(); } } } } }
/// <summary> /// Create a compiled delegate for the LightLambda, and saves it so /// future calls to Run will execute the compiled code instead of /// interpreting. /// </summary> internal void Compile(object state) { if (_compiled != null) { return; } // Compilation is expensive, we only want to do it once. lock (_compileLock) { if (_compiled != null) { return; } //PerfTrack.NoteEvent(PerfTrack.Categories.Compiler, "Interpreted lambda compiled"); // Interpreter needs a standard delegate type. // So change the lambda's delegate type to Func<...> or // Action<...> so it can be called from the LightLambda.Run // methods. LambdaExpression lambda = (_lambda as LambdaExpression);// ?? (LambdaExpression)((LightLambdaExpression)_lambda).Reduce(); if (_interpreter != null) { _compiledDelegateType = GetFuncOrAction(lambda); lambda = Expression.Lambda(_compiledDelegateType, lambda.Body, lambda.Name, lambda.Parameters); } if (HasClosure) { _compiled = LightLambdaClosureVisitor.BindLambda(lambda, _interpreter.ClosureVariables); } else { _compiled = lambda.Compile(); } } }