6 releases

0.2.4 Dec 7, 2023
0.2.3 Dec 6, 2023
0.2.2 Jan 30, 2023
0.2.1 Aug 18, 2022
0.1.1 Sep 23, 2021

#2 in #fibonacci

Download history 2/week @ 2024-02-11 102/week @ 2024-02-18 12/week @ 2024-02-25 14/week @ 2024-03-10 39/week @ 2024-03-31

53 downloads per month

MPL-2.0 license

23KB
635 lines

  • AST
def fibonacci(n: Integer) {
    fibonacci_helper(n, 0, 1)
}

def fibonacci_helper(n, previous, current)
{
    if n == 0 { previous }
    if n == 1 { current }
    fibonacci_helper(n - 1, current, previous + current);
}
  • HIR
function fibonacci
(
    state: small_int,
    %n: auto,
    ^return: auto,
)
{
0: 
   %tmp1 = call fibonacci_helper (%n, 0, 1);
}

function fibonacci_helper
(
    %n: auto,
    %previous: auto,
    %current: auto,
    ^return: auto,
)
{
function.begin:
    %var1 = binary == (%n, 0);
    jump 1 if %var1;
    jump 2;
if1.begin: 
    ^return(%previous);
if1.end:
    %var2 = binary == (%n, 1);
    jump 3 if %var2;
    jump 4;
if2.begin:
    ^return(%current);
if2.end:
    %tmp3 = binary - (%n, 1);
    %tmp4 = binary + (%previous, %current);
    %tmp5 = %n - 1;
    %tmp6 = %current;
    %tmp7 = ninary + (%previous, %current);
    %n = %tmp5;
    %previous = %tmp6;
    %current = %tmp7;
    jump 0;
}

Dependencies

~3.5–5MB
~118K SLoC