Exemplo n.º 1
0
 private void EnsureCompiled(bool optimized) {
     //TODO too much duplicated code between these two blocks
     if (optimized) {
         if (_optimizedCode != null) return;
         var rewriter = new LightGlobalRewriter();
         var newLambda = rewriter.RewriteLambda(Code, Code.Name, LanguageContext, optimized);
         _optimizedScope = rewriter.Scope;
         var compiler = new LightCompiler();
         var interpreter = compiler.CompileTop(newLambda);
         _optimizedCode = new LightLambda(interpreter);
     } else {
         if (_code != null) return;
         var rewriter = new LightGlobalRewriter();
         var newLambda = rewriter.RewriteLambda(Code, Code.Name, LanguageContext, optimized);
         var compiler = new LightCompiler();
         var interpreter = compiler.CompileTop(newLambda);
         _code = new LightLambda(interpreter);
     }
 }
Exemplo n.º 2
0
        private void CompileLambdaExpression(Expression expr) {
            var node = (LambdaExpression)expr;
            var compiler = new LightCompiler(this);
            var interpreter = compiler.CompileTop(node);

            int[] closureBoxes = new int[compiler._closureVariables.Count];
            for (int i = 0; i < closureBoxes.Length; i++) {
                var closureVar = compiler._closureVariables[i];
                AddInstruction(GetBoxedVariable(closureVar));
            }
            AddInstruction(new CreateDelegateInstruction(node.Type, interpreter, compiler._closureVariables.Count));
        }