Exemple #1
0
        internal Interpreter(LambdaExpression lambda, LocalVariables locals, Dictionary<LabelTarget, BranchLabel> labelMapping,
            InstructionArray instructions, ExceptionHandler[] handlers, DebugInfo[] debugInfos, int compilationThreshold) {

            _lambda = lambda;
            _locals = locals;
            _boxedLocals = locals.GetBoxed();
                
            _instructions = instructions;
            _objects = instructions.Objects;
            _labels = instructions.Labels;
            _labelMapping = labelMapping;

            _handlers = handlers;
            _debugInfos = debugInfos;
            _compilationThreshold = compilationThreshold;
        }
Exemple #2
0
        internal Interpreter(string name, LocalVariables locals, HybridReferenceDictionary<LabelTarget, BranchLabel> labelMapping,
            InstructionArray instructions, ExceptionHandler[] handlers, DebugInfo[] debugInfos, int compilationThreshold) {

            _name = name;
            _localCount = locals.LocalCount;
            _closureVariables = locals.ClosureVariables;

            _instructions = instructions;
            _objects = instructions.Objects;
            _labels = instructions.Labels;
            _labelMapping = labelMapping;

            _handlers = handlers;
            _debugInfos = debugInfos;
            _compilationThreshold = compilationThreshold;
        }
 internal EnterLoopInstruction(LoopExpression loop, LocalVariables locals, int compilationThreshold, int instructionIndex) {
     _loop = loop;
     _variables = locals.CopyLocals();
     _closureVariables = locals.ClosureVariables;
     _compilationThreshold = compilationThreshold;
     _instructionIndex = instructionIndex;
 }
Exemple #4
0
 internal LoopCompiler(LoopExpression loop, Dictionary <LabelTarget, BranchLabel> labelMapping, LocalVariables locals,
                       int loopStartInstructionIndex, int loopEndInstructionIndex)
 {
     _loop                      = loop;
     _locals                    = locals;
     _frameDataVar              = Expression.Parameter(typeof(object[]));
     _frameClosureVar           = Expression.Parameter(typeof(StrongBox <object>[]));
     _frameVar                  = Expression.Parameter(typeof(InterpretedFrame));
     _loopVariables             = new Dictionary <ParameterExpression, LoopVariable>();
     _returnLabel               = Expression.Label(typeof(int));
     _labelMapping              = labelMapping;
     _loopStartInstructionIndex = loopStartInstructionIndex;
     _loopEndInstructionIndex   = loopEndInstructionIndex;
 }
Exemple #5
0
        /// <summary>
        /// Walks the lambda and produces a higher order function, which can be
        /// used to bind the lambda to a closure array from the interpreter.
        /// </summary>
        /// <param name="lambda">The lambda to bind.</param>
        /// <param name="locals">Local variables.</param>
        /// <returns>A delegate that can be called to produce a delegate bound to the passed in closure array.</returns>
        internal static Func <StrongBox <object>[], Delegate> BindLambda(LambdaExpression lambda, LocalVariables locals)
        {
            // 1. Create rewriter
            var closure = Expression.Parameter(typeof(StrongBox <object>[]), "closure");
            var visitor = new LightLambdaClosureVisitor(locals, closure);

            // 2. Visit the lambda
            lambda = (LambdaExpression)visitor.Visit(lambda);

            // 3. Create a higher-order function which fills in the parameters
            var result = Expression.Lambda <Func <StrongBox <object>[], Delegate> >(lambda, closure);

            // 4. Compile it
            return(result.Compile());
        }
Exemple #6
0
 private LightLambdaClosureVisitor(LocalVariables locals, ParameterExpression closureArray)
 {
     Assert.NotNull(locals, closureArray);
     _closureArray = closureArray;
     _locals       = locals;
 }