protected override void Loop(LoopStatement loop, Statement initilization, Expression condition, Expression increment, Statement body, bool isDoWhile) { PushLocation(loop); var loopBegin = _ilGen.DefineLabel(); var loopIncrement = _ilGen.DefineLabel(); var loopCheck = _ilGen.DefineLabel(); var loopEnd = _ilGen.DefineLabel(); _labelInfos.PushLoop(loop, loopEnd, loopIncrement); VisitNode(initilization); ++_loopNestLevel; if (!isDoWhile) _ilGen.Br(loopCheck); _ilGen.MarkLabel(loopBegin); VisitNode(body); _ilGen.MarkLabel(loopIncrement); if (increment != null) { var stackState = _localVars.GetTemporaryStackState(); VisitNode(increment); AsVoid(); _localVars.PopTemporariesAfter(stackState); } _ilGen.MarkLabel(loopCheck); if (condition != null) { VisitNode(condition); AsBoolean(); _ilGen.Brtrue(loopBegin); } else _ilGen.Br(loopBegin); _ilGen.MarkLabel(loopEnd); --_loopNestLevel; _labelInfos.PopLoop(loop); PopLocation(); }
protected override void Visit(LoopStatement node) { Visit((Statement)node); }
protected override void Loop(LoopStatement loop, Statement initilization, Expression condition, Expression increment, Statement body, bool isDoWhile) { PushLocation(loop); VisitNode(initilization); ++_loopNestLevel; var breakIndexes = new LinkedList<int>(); var continueIndexes = new LinkedList<int>(); _labelInfos.PushLoop(loop, breakIndexes, continueIndexes); var gotoLoopCheckIndex = -1; if (!isDoWhile) gotoLoopCheckIndex = ReserveNewICIndex(); //Reserver a place and will generate the goto later var loopBeginIndex = GetCurrentICIndex() + 1; VisitNode(body); var loopIncrementIndex = GetCurrentICIndex() + 1; UpdateJumps(loopIncrementIndex, continueIndexes); if (increment != null) { VisitNode(increment); AsVoid(); } if (gotoLoopCheckIndex != -1) { BeginICMethod("GotoLoopCheck"); Br(GetCurrentICIndex() + 1); EndICMethod(gotoLoopCheckIndex); } if (condition != null) { VisitNode(condition); _stackModel.Pop(1); BeginICMethod("GotoLoopBegin"); Brtrue(_stackModel.StackPointer, loopBeginIndex); EndICMethod(); } else { BeginICMethod("GotoLoopBegin"); Br(loopBeginIndex); EndICMethod(); } UpdateJumps(GetCurrentICIndex() + 1, breakIndexes); --_loopNestLevel; _labelInfos.PopLoop(loop); PopLocation(); }
protected virtual void Visit(LoopStatement node) { }
protected virtual void Loop(LoopStatement loop, Statement initilization, Expression condition, Expression increment, Statement body, bool isDoWhile) { throw new NotImplementedException(); }