public void Program04()

in Iris/FrontEndTest/SamplePrograms.cs [211:397]


        public void Program04()
        {
            string input =
@"
program Shuffle;

var
    a : array[0..9] of integer;

procedure Swap(
    var a : integer;
    var b : integer);
var
    temp : integer;
begin
    temp := a;
    a := b;
    b := temp;
end

procedure Shuffle(
    a : array of integer;
    length : integer);
var
    random : integer;
    i : integer;
begin
    while i < length do
    begin
        random := rand % length;
        if i <> random then
            Swap(a[i], a[random]);
        i := i + 1;
    end;
end

procedure Fill(
    a : array of integer;
    length : integer);
var
    i : integer;
begin
    while i < length do
    begin
        a[i] := i;
        i := i + 1;
    end;
end

begin
    Fill(a, 10);
    Shuffle(a, 10);
end.
";
            string output = TestHelpers.TestCompileProgram(input, true);
            string expected = FixupBaseline(
@"
.assembly SYSTEM-ASSEMBLIES-HERE { }
.assembly extern IrisRuntime { }
.assembly Shuffle { }
.class public Shuffle
{
   .field public static int32[] a
   .method public hidebysig static void Swap(int32& a, int32& b) cil managed
   {
      .locals init ([0] int32 temp)
      .language '{3456107b-a1f4-4d47-8e18-7cf2c54559ae}', '{5e176682-93da-497a-a5f0-f1aee5e18cce}', '{5a869d0b-6611-11d3-bd2a-0000f80849bd}'
      .line 12,12 : 1,6 'FakeFile.iris'
      nop
      .line 13,13 : 5,14 ''
      ldarg.0
      ldind.i4
      stloc.s 0
      .line 14,14 : 5,11 ''
      ldarg.0
      ldarg.1
      ldind.i4
      stind.i4
      .line 15,15 : 5,14 ''
      ldarg.1
      ldloc.0
      stind.i4
      .line 16,16 : 1,4 ''
      nop
      ret
   }
   .method public hidebysig static void Shuffle(int32[] a, int32 length) cil managed
   {
      .locals init ([0] int32 random, [1] int32 i)
      .language '{3456107b-a1f4-4d47-8e18-7cf2c54559ae}', '{5e176682-93da-497a-a5f0-f1aee5e18cce}', '{5a869d0b-6611-11d3-bd2a-0000f80849bd}'
      .line 24,24 : 1,6 'FakeFile.iris'
      nop
      .line 25,25 : 5,24 ''
L0:
      ldloc.1
      ldarg.1
      bge L1
      .line 26,26 : 5,10 ''
      nop
      .line 27,27 : 9,32 ''
      call int32 [IrisRuntime]IrisRuntime.CompilerServices::Rand()
      ldarg.1
      rem
      stloc.s 0
      .line 28,28 : 9,28 ''
      ldloc.1
      ldloc.0
      beq L2
      .line 29,29 : 13,34 ''
      ldarg.0
      ldloc.1
      ldelema int32
      ldarg.0
      ldloc.0
      ldelema int32
      call void Shuffle::Swap(int32&,int32&)
      .line 30,30 : 9,19 ''
L2:
      ldloc.1
      ldc.i4.1
      add
      stloc.s 1
      .line 31,31 : 5,8 ''
      nop
      br L0
L1:
      .line 32,32 : 1,4 ''
      nop
      ret
   }
   .method public hidebysig static void Fill(int32[] a, int32 length) cil managed
   {
      .locals init ([0] int32 i)
      .language '{3456107b-a1f4-4d47-8e18-7cf2c54559ae}', '{5e176682-93da-497a-a5f0-f1aee5e18cce}', '{5a869d0b-6611-11d3-bd2a-0000f80849bd}'
      .line 39,39 : 1,6 'FakeFile.iris'
      nop
      .line 40,40 : 5,24 ''
L3:
      ldloc.0
      ldarg.1
      bge L4
      .line 41,41 : 5,10 ''
      nop
      .line 42,42 : 9,18 ''
      ldarg.0
      ldloc.0
      dup
      stelem.i4
      .line 43,43 : 9,19 ''
      ldloc.0
      ldc.i4.1
      add
      stloc.s 0
      .line 44,44 : 5,8 ''
      nop
      br L3
L4:
      .line 45,45 : 1,4 ''
      nop
      ret
   }
   .method public hidebysig static void $.main() cil managed
   {
      .entrypoint
      .language '{3456107b-a1f4-4d47-8e18-7cf2c54559ae}', '{5e176682-93da-497a-a5f0-f1aee5e18cce}', '{5a869d0b-6611-11d3-bd2a-0000f80849bd}'
      .line 47,47 : 1,6 'FakeFile.iris'
      nop
      ldc.i4.s 10
      newarr int32
      stsfld int32[] Shuffle::a
      .line 48,48 : 5,16 ''
      ldsfld int32[] Shuffle::a
      ldc.i4.s 10
      call void Shuffle::Fill(int32[],int32)
      .line 49,49 : 5,19 ''
      ldsfld int32[] Shuffle::a
      ldc.i4.s 10
      call void Shuffle::Shuffle(int32[],int32)
      .line 50,50 : 1,4 ''
      nop
      ret
   }
}
");

            Assert.AreEqual(expected, output);
        }