private void PrintFor(ForNode p_node) { Console.WriteLine(identString + "[FOR "); if (p_node.Initializer != null) { IdentPlus(); Console.WriteLine(identString + "[INITIALIZER"); IdentPlus(); Print(p_node.Initializer); IdentMinus(); Console.WriteLine(identString + "]"); IdentMinus(); } if (p_node.Condition != null) { IdentPlus(); Console.Write(identString + "[CONDITION "); Print(p_node.Condition); Console.WriteLine("]"); IdentMinus(); } if (p_node.Finalizer != null) { IdentPlus(); Console.Write(identString + "[FINALIZER "); Print(p_node.Finalizer); Console.WriteLine("]"); IdentMinus(); } if (p_node.Body != null) { IdentPlus(); Console.WriteLine(identString + "[BODY"); IdentPlus(); Print(p_node.Body); IdentMinus(); Console.WriteLine(identString + "]"); IdentMinus(); } Console.WriteLine(identString + "]"); }
private void ChunkFor(ForNode p_node) { Add(OpCode.OPEN_ENV, p_node.PositionData); env.Add(new List <string>()); ChunkIt(p_node.Initializer); int condition_address = instructionCounter; ChunkIt(p_node.Condition); int start_address = instructionCounter; Add(OpCode.JUMP_IF_NOT_TRUE, 0, p_node.PositionData); if (p_node.Body != null) { ChunkIt(p_node.Body); } if (p_node.Finalizer != null) { ChunkIt(p_node.Finalizer); Add(OpCode.POP, p_node.PositionData); } int go_back_address = instructionCounter; Add(OpCode.JUMP_BACK, 0, p_node.PositionData); int exit_address = instructionCounter; Add(OpCode.CLOSE_ENV, p_node.PositionData); env.RemoveAt(env.Count - 1); chunk.FixInstruction(start_address, null, (Operand)(exit_address - start_address), null, null); chunk.FixInstruction(go_back_address, null, (Operand)(go_back_address - condition_address), null, null); }