CLRs tail opcode

Jomo Fisher demonstrates how tail call works in CLR using mutual recursion in F# as an example:


let rec f1 n =
    f2 (n+1)
and f2 n =
    f1 (n+1)

f1 1

.method public static !!T f1(int32 n) cil managed
{
    .maxstack 4
    L_0000: ldarg.0
    L_0001: ldc.i4.1
    L_0002: add
    L_0003: tail
    L_0005: call !!0 Test::f2< !!T>(int32)
    L_000a: ret
}

Comments are closed.