Пример #1
0
        private Tuple<Action<FunctionContext>, Type> CompileTrap(TrapStatementAst trap)
        {
            var compiler = new Compiler(_sequencePoints) { _compilingTrap = true };
            string funcName = _currentFunctionName + "<trap>";
            if (trap.TrapType != null)
            {
                funcName += "<" + trap.TrapType.TypeName.Name + ">";
            }

            // We generate code as though we're dotting the trap, but in reality we don't dot it,
            // a new scope is always created.  The code gen for dotting means we can avoid passing
            // around the array of local variable names.  We assume traps don't need to perform well,
            // and that they rarely if ever actually create any local variables.  We still do the
            // variable analysis though because we must mark automatic variables like $_.
            var analysis = VariableAnalysis.AnalyzeTrap(trap);

            compiler.LocalVariablesTupleType = analysis.Item1;
            compiler.LocalVariablesParameter = Expression.Variable(compiler.LocalVariablesTupleType, "locals");

            var lambda = compiler.CompileSingleLambda(trap.Body.Statements, trap.Body.Traps, funcName, null, null, null);
            return Tuple.Create(lambda.Compile(), compiler.LocalVariablesTupleType);
        }
Пример #2
0
 private Tuple<Action<FunctionContext>, Type> CompileTrap(TrapStatementAst trap)
 {
     Compiler compiler = new Compiler(this._sequencePoints) {
         _compilingTrap = true
     };
     string funcName = this._currentFunctionName + "<trap>";
     if (trap.TrapType != null)
     {
         funcName = funcName + "<" + trap.TrapType.TypeName.Name + ">";
     }
     Tuple<Type, Dictionary<string, int>> tuple = VariableAnalysis.AnalyzeTrap(trap);
     compiler.LocalVariablesTupleType = tuple.Item1;
     compiler.LocalVariablesParameter = Expression.Variable(compiler.LocalVariablesTupleType, "locals");
     Expression<Action<FunctionContext>> expression = compiler.CompileSingleLambda(trap.Body.Statements, trap.Body.Traps, funcName, null, null);
     return Tuple.Create<Action<FunctionContext>, Type>(expression.Compile(), compiler.LocalVariablesTupleType);
 }