public void Visit(ForListBlock s) { Indent(); o.Write("forlist "); bool bFirst = true; foreach (Variable variable in s.UserVariables) { if (!bFirst) { o.Write(", "); } bFirst = false; o.Write(variable.Name); } o.Write(" : "); o.Write(s.Generator.Name); o.Write(", "); o.Write(s.State.Name); o.Write(", "); o.Write(s.Control.Name); o.Write(" : "); o.Write(s.BreakLabel.Name); o.Write(", "); o.Write(s.ContinueLabel.Name); o.WriteLine(); WriteBlock(s); Indent(); o.WriteLine("end"); }
public virtual void Visit(ForListBlock s) { block = new ForListBlock(s.SourceSpan, block, s.Name, s.Generator, s.State, s.Control, s.UserVariables, s.BreakLabel, s.ContinueLabel); TransformBlock(s); result = block; block = block.Parent; }
public void Visit(ForListBlock s) { /* b forlistContinue * forlistLoop: * block * local <variablelist> * ... * end * forlistContinue: * tforloop (for generator), (for state), (for control), <variablelist> forlistLoop * forlistBreak: */ // For index variables should have been allocated sequentially. Allocation allocation = function.Local(s.Generator); int A = allocation; allocation.Release(); // Prologue. function.InstructionAsBx(s.SourceSpan, Opcode.Jmp, 0, s.ContinueLabel); Label forlistLoop = new Label("forlistLoop"); function.Label(forlistLoop); // Enter block. Allocation blockBase = function.Top(); block = new BlockBuilder(block, s, blockBase); blockBase.Release(); for (int variable = 0; variable < s.UserVariables.Count; ++variable) { function.DeclareLocal(s.UserVariables[variable]); } BuildBlock(s); // Epilogue. function.Label(s.ContinueLabel); function.InstructionABC(s.SourceSpan, Opcode.TForLoop, A, 0, s.UserVariables.Count); function.InstructionAsBx(s.SourceSpan, Opcode.Jmp, 0, forlistLoop); function.Label(s.BreakLabel); // End of block. block = block.Parent; }