1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-14 17:32:00 +03:00
juvix/tests/Asm/positive/test020.jva

42 lines
589 B
Plaintext
Raw Normal View History

2022-09-29 18:44:55 +03:00
-- tail recursion through higher-order functions
function sumb((integer, integer) -> integer, integer, integer) : integer {
push arg[1];
push 0;
eq;
br {
true: {
push arg[2];
ret;
}
false: {
push arg[2];
push 1;
push arg[1];
sub;
push arg[0];
tcall $ 2;
}
};
}
function sum'(integer, integer) : integer {
push arg[1];
push arg[0];
add;
push arg[0];
calloc sum' 0;
tcall sumb;
}
function sum(integer) : integer {
push 0;
push arg[0];
tcall sum';
}
function main() {
push 1000;
tcall sum;
}