mirror of
https://github.com/anoma/juvix.git
synced 2024-12-26 09:04:18 +03:00
ed15e57d8a
* Closes #2578 * Implements JuvixReg parser and pretty printer. * Adds the `juvix dev reg read file.jvr` command. * Adds the `reg` target to the `compile` commands. * Adds tests for the JuvixReg parser.
75 lines
1.6 KiB
Plaintext
75 lines
1.6 KiB
Plaintext
|
|
function power'(integer, integer, integer) : integer;
|
|
function power(integer, integer) : integer;
|
|
function main() : *;
|
|
|
|
function power'(integer, integer, integer) : integer {
|
|
tmp[0] = arg[1];
|
|
tmp[1] = 0;
|
|
tmp[0] = eq tmp[1] tmp[0];
|
|
br tmp[0] {
|
|
true: {
|
|
tmp[0] = arg[2];
|
|
ret tmp[0];
|
|
};
|
|
false: {
|
|
tmp[0] = 2;
|
|
tmp[1] = arg[1];
|
|
tmp[0] = mod tmp[1] tmp[0];
|
|
tmp[1] = 0;
|
|
tmp[0] = eq tmp[1] tmp[0];
|
|
br tmp[0] {
|
|
true: {
|
|
tmp[0] = arg[2];
|
|
tmp[1] = 2;
|
|
tmp[2] = arg[1];
|
|
tmp[1] = div tmp[2] tmp[1];
|
|
tmp[2] = arg[0];
|
|
tmp[3] = arg[0];
|
|
tmp[2] = mul tmp[3] tmp[2];
|
|
tcall power' (tmp[2], tmp[1], tmp[0]);
|
|
};
|
|
false: {
|
|
tmp[0] = arg[2];
|
|
tmp[1] = arg[0];
|
|
tmp[0] = mul tmp[1] tmp[0];
|
|
tmp[1] = 2;
|
|
tmp[2] = arg[1];
|
|
tmp[1] = div tmp[2] tmp[1];
|
|
tmp[2] = arg[0];
|
|
tmp[3] = arg[0];
|
|
tmp[2] = mul tmp[3] tmp[2];
|
|
tcall power' (tmp[2], tmp[1], tmp[0]);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|
|
|
|
function power(integer, integer) : integer {
|
|
tmp[0] = 1;
|
|
tmp[1] = arg[1];
|
|
tmp[2] = arg[0];
|
|
tcall power' (tmp[2], tmp[1], tmp[0]);
|
|
}
|
|
|
|
function main() : * {
|
|
tmp[0] = 3;
|
|
tmp[1] = 2;
|
|
tmp[0] = call power (tmp[1], tmp[0]);
|
|
trace tmp[0];
|
|
nop;
|
|
tmp[0] = 7;
|
|
tmp[1] = 3;
|
|
tmp[0] = call power (tmp[1], tmp[0]);
|
|
trace tmp[0];
|
|
nop;
|
|
tmp[0] = 11;
|
|
tmp[1] = 5;
|
|
tmp[0] = call power (tmp[1], tmp[0]);
|
|
trace tmp[0];
|
|
nop;
|
|
tmp[0] = void;
|
|
ret tmp[0];
|
|
}
|