コード例 #1
0
ファイル: EnterLoopInstruction.cs プロジェクト: nickchal/pash
 internal EnterLoopInstruction(PowerShellLoopExpression loop, LocalVariables locals, int compilationThreshold, int instructionIndex)
 {
     this._loop = loop;
     this._variables = locals.CopyLocals();
     this._closureVariables = locals.ClosureVariables;
     this._compilationThreshold = compilationThreshold;
     this._instructionIndex = instructionIndex;
 }
コード例 #2
0
ファイル: EnterLoopInstruction.cs プロジェクト: nickchal/pash
 private void Compile(object frameObj)
 {
     if (!this.Compiled)
     {
         lock (this)
         {
             if (!this.Compiled)
             {
                 InterpretedFrame frame = (InterpretedFrame) frameObj;
                 LoopCompiler compiler = new LoopCompiler(this._loop, frame.Interpreter.LabelMapping, this._variables, this._closureVariables, this._instructionIndex, this._loopEnd);
                 frame.Interpreter.Instructions.Instructions[this._instructionIndex] = new CompiledLoopInstruction(compiler.CreateDelegate());
                 this._loop = null;
                 this._variables = null;
                 this._closureVariables = null;
             }
         }
     }
 }
コード例 #3
0
        private void Compile(object frameObj)
        {
            if (Compiled)
            {
                return;
            }

            lock (this)
            {
                if (Compiled)
                {
                    return;
                }

                //PerfTrack.NoteEvent(PerfTrack.Categories.Compiler, "Interpreted loop compiled");

                InterpretedFrame frame = (InterpretedFrame)frameObj;
                var compiler = new LoopCompiler(_loop, frame.Interpreter.LabelMapping, _variables, _closureVariables, _instructionIndex, _loopEnd);
                var instructions = frame.Interpreter.Instructions.Instructions;

                // replace this instruction with an optimized one:
                instructions[_instructionIndex] = new CompiledLoopInstruction(compiler.CreateDelegate());

                // invalidate this instruction, some threads may still hold on it:
                _loop = null;
                _variables = null;
                _closureVariables = null;
            }
        }
コード例 #4
0
ファイル: Compiler.cs プロジェクト: nickchal/pash
 private Expression GenerateWhileLoop(string loopLabel, Func<Expression> generateCondition, Action<List<Expression>, LabelTarget, LabelTarget> generateLoopBody, PipelineBaseAst continueAst = null)
 {
     string str;
     string str1;
     string str2;
     LabelTarget labelTarget;
     int num = this._stmtCount;
     List<Expression> expressions = new List<Expression>();
     if (!string.IsNullOrEmpty(loopLabel))
     {
         str = string.Concat(loopLabel, "Continue");
     }
     else
     {
         str = "continue";
     }
     LabelTarget labelTarget1 = Expression.Label(str);
     if (!string.IsNullOrEmpty(loopLabel))
     {
         str1 = string.Concat(loopLabel, "Break");
     }
     else
     {
         str1 = "break";
     }
     LabelTarget labelTarget2 = Expression.Label(str1);
     EnterLoopExpression enterLoopExpression = new EnterLoopExpression();
     if (continueAst != null)
     {
         if (!string.IsNullOrEmpty(loopLabel))
         {
             str2 = string.Concat(loopLabel, "LoopTop");
         }
         else
         {
             str2 = "looptop";
         }
         labelTarget = Expression.Label(str2);
     }
     else
     {
         labelTarget = labelTarget1;
     }
     LabelTarget labelTarget3 = labelTarget;
     expressions.Add(Expression.Label(labelTarget3));
     expressions.Add(enterLoopExpression);
     List<Expression> expressions1 = new List<Expression>();
     expressions1.Add(Compiler._callCheckForInterrupts);
     List<Compiler.LoopGotoTargets> loopGotoTargets = this._loopTargets;
     string str3 = loopLabel;
     string str4 = str3;
     if (str3 == null)
     {
         str4 = "";
     }
     loopGotoTargets.Add(new Compiler.LoopGotoTargets(str4, labelTarget2, labelTarget1));
     generateLoopBody(expressions1, labelTarget2, labelTarget1);
     if (continueAst == null)
     {
         expressions1.Add(Expression.Goto(labelTarget3));
     }
     this._loopTargets.RemoveAt(this._loopTargets.Count - 1);
     Expression expression = Expression.TryCatch(Expression.Block(expressions1), Compiler.GenerateLoopBreakContinueCatchBlocks(loopLabel, labelTarget2, labelTarget1));
     if (continueAst != null)
     {
         List<Expression> expressions2 = new List<Expression>();
         expressions2.Add(expression);
         expressions2.Add(Expression.Label(labelTarget1));
         if (continueAst.GetPureExpression() != null)
         {
             expressions2.Add(this.UpdatePosition(continueAst));
         }
         expressions2.Add(this.CaptureStatementResults(continueAst, Compiler.CaptureAstContext.Assignment, null));
         expressions2.Add(Expression.Goto(labelTarget3));
         expression = Expression.Block(expressions2);
     }
     if (generateCondition == null)
     {
         expressions.Add(expression);
     }
     else
     {
         expressions.Add(Expression.IfThen(generateCondition().Convert(typeof(bool)), expression));
     }
     expressions.Add(Expression.Label(labelTarget2));
     enterLoopExpression.LoopStatementCount = this._stmtCount - num;
     PowerShellLoopExpression powerShellLoopExpression = new PowerShellLoopExpression(expressions);
     PowerShellLoopExpression powerShellLoopExpression1 = powerShellLoopExpression;
     enterLoopExpression.Loop = powerShellLoopExpression;
     return powerShellLoopExpression1;
 }