in Iris/FrontEndTest/SamplePrograms.cs [78:208]
public void Program03()
{
string input =
@"
program Fibbonacci;
function Fib(i:integer) : integer;
var
a, b : integer;
begin
Fib := 1;
if i > 2 then
begin
a := Fib(i - 1);
b := Fib(i - 2);
Fib := a + b;
end;
end
procedure Test(i:integer);
var
result : integer;
begin
result := Fib(i);
writeln(str(result));
end;
begin
Test(1);
Test(2);
Test(3);
Test(4);
Test(5);
end.
";
string output = TestHelpers.TestCompileProgram(input, true);
string expected = FixupBaseline(
@"
.assembly SYSTEM-ASSEMBLIES-HERE { }
.assembly extern IrisRuntime { }
.assembly Fibbonacci { }
.class public Fibbonacci
{
.method public hidebysig static int32 Fib(int32 i) cil managed
{
.locals init ([0] int32 Fib, [1] int32 a, [2] int32 b)
.language '{3456107b-a1f4-4d47-8e18-7cf2c54559ae}', '{5e176682-93da-497a-a5f0-f1aee5e18cce}', '{5a869d0b-6611-11d3-bd2a-0000f80849bd}'
.line 7,7 : 1,6 'FakeFile.iris'
nop
.line 8,8 : 4,12 ''
ldc.i4.1
stloc.s 0
.line 9,9 : 4,17 ''
ldarg.0
ldc.i4.2
ble L0
.line 10,10 : 4,9 ''
nop
.line 11,11 : 7,22 ''
ldarg.0
ldc.i4.1
sub
call int32 Fibbonacci::Fib(int32)
stloc.s 1
.line 12,12 : 7,22 ''
ldarg.0
ldc.i4.2
sub
call int32 Fibbonacci::Fib(int32)
stloc.s 2
.line 13,13 : 7,19 ''
ldloc.1
ldloc.2
add
stloc.s 0
.line 14,14 : 4,7 ''
nop
L0:
.line 15,15 : 1,4 ''
nop
ldloc.0
ret
}
.method public hidebysig static void Test(int32 i) cil managed
{
.locals init ([0] int32 result)
.language '{3456107b-a1f4-4d47-8e18-7cf2c54559ae}', '{5e176682-93da-497a-a5f0-f1aee5e18cce}', '{5a869d0b-6611-11d3-bd2a-0000f80849bd}'
.line 20,20 : 1,6 'FakeFile.iris'
nop
.line 21,21 : 4,20 ''
ldarg.0
call int32 Fibbonacci::Fib(int32)
stloc.s 0
.line 22,22 : 4,24 ''
ldloca.s 0
call instance string [CoreLib]System.Int32::ToString()
call void [System.Console]System.Console::WriteLine(string)
.line 23,23 : 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 25,25 : 1,6 'FakeFile.iris'
nop
.line 26,26 : 4,11 ''
ldc.i4.1
call void Fibbonacci::Test(int32)
.line 27,27 : 4,11 ''
ldc.i4.2
call void Fibbonacci::Test(int32)
.line 28,28 : 4,11 ''
ldc.i4.3
call void Fibbonacci::Test(int32)
.line 29,29 : 4,11 ''
ldc.i4.4
call void Fibbonacci::Test(int32)
.line 30,30 : 4,11 ''
ldc.i4.5
call void Fibbonacci::Test(int32)
.line 31,31 : 1,4 ''
nop
ret
}
}
");
Assert.AreEqual(expected, output);
}