private JSProgram CreateProgramWithWhileStatement(int whileTimes) { JSProgram program = new JSProgram(); program.Render = true; program.AddInputBlock("a", 1); program.AddHeaterDeclarationBlock("z"); string times = program.AddConstantBlock(whileTimes); string zero = program.AddConstantBlock(whileTimes); string logicCheck = program.AddBoolOPBlock(BoolOPTypes.EQ, times, zero); string scopeName = program.GetUniqueName(); program.AddScope(scopeName); program.SetScope(scopeName); string guardedBlock = AddFluidBlock(program, "a", "k"); program.SetScope(JSProgram.DEFAULT_SCOPE_NAME); program.AddRepeatSegment(times, guardedBlock); AddFluidBlock(program, "k", "k"); program.Finish(); return(program); }
private void nestRepeats(JSProgram program, string prevScopeName, Queue <int> repeatTimes, string from, string to) { string times = program.AddConstantBlock(repeatTimes.Dequeue()); string scopeName = program.GetUniqueName(); program.AddScope(scopeName); program.SetScope(scopeName); string guardedBlock = AddFluidBlock(program, from, to); if (repeatTimes.Count > 0) { nestRepeats(program, scopeName, repeatTimes, to, to); } program.SetScope(prevScopeName); program.AddRepeatSegment(times, guardedBlock); AddFluidBlock(program, to, to); }