mirror of
https://github.com/anoma/juvix.git
synced 2024-12-12 14:28:08 +03:00
8e5f45f16f
This makes the syntax more uniform. It was especially confusing with nested branching, where some closing braces had to and others couldn't be followed by a semicolon. Now all have to be followed by a semicolon (except function ending braces).
72 lines
988 B
Plaintext
72 lines
988 B
Plaintext
-- fast exponentiation
|
|
|
|
function power'(integer, integer, integer) : integer {
|
|
push arg[1];
|
|
push 0;
|
|
eq;
|
|
br {
|
|
true: {
|
|
push arg[2];
|
|
ret;
|
|
};
|
|
false: {
|
|
push 2;
|
|
push arg[1];
|
|
mod;
|
|
push 0;
|
|
eq;
|
|
br {
|
|
true: {
|
|
push arg[2];
|
|
push 2;
|
|
push arg[1];
|
|
div;
|
|
push arg[0];
|
|
push $;
|
|
mul;
|
|
tcall power';
|
|
};
|
|
false: {
|
|
push arg[2];
|
|
push arg[0];
|
|
mul;
|
|
push 2;
|
|
push arg[1];
|
|
div;
|
|
push arg[0];
|
|
push $;
|
|
mul;
|
|
tcall power';
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|
|
|
|
function power(integer, integer) : integer {
|
|
push 1;
|
|
push arg[1];
|
|
push arg[0];
|
|
tcall power';
|
|
}
|
|
|
|
function main() {
|
|
push 3;
|
|
push 2;
|
|
call power;
|
|
trace;
|
|
pop;
|
|
push 7;
|
|
push 3;
|
|
call power;
|
|
trace;
|
|
pop;
|
|
push 11;
|
|
push 5;
|
|
call power;
|
|
trace;
|
|
pop;
|
|
push void;
|
|
ret;
|
|
}
|