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 |
#3 in #valkyrie
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
~5.5MB
~110K SLoC