1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-30 05:42:26 +03:00
juvix/tests/Reg/positive/test030.jvr
Łukasz Czajka ed15e57d8a
JuvixReg parser and pretty printer (#2617)
* 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.
2024-02-09 12:19:29 +01:00

94 lines
1.8 KiB
Plaintext

function f(integer) : integer;
function g(integer) : integer;
function h(integer) : integer;
function main() : *;
function f(integer) : integer {
tmp[0] = 1;
tmp[1] = arg[0];
tmp[0] = lt tmp[1] tmp[0];
br tmp[0] {
true: {
tmp[0] = 1;
ret tmp[0];
};
false: {
tmp[0] = 268435456;
tmp[1] = 1;
tmp[2] = arg[0];
tmp[1] = sub tmp[2] tmp[1];
tmp[1] = call g (tmp[1]), live: (tmp[0], arg[0]);
tmp[2] = arg[0];
tmp[3] = 2;
tmp[2] = mul tmp[3] tmp[2];
tmp[1] = add tmp[2] tmp[1];
tmp[0] = mod tmp[1] tmp[0];
ret tmp[0];
};
};
}
function g(integer) : integer {
tmp[0] = 1;
tmp[1] = arg[0];
tmp[0] = lt tmp[1] tmp[0];
br tmp[0] {
true: {
tmp[0] = 1;
ret tmp[0];
};
false: {
tmp[0] = 268435456;
tmp[1] = 1;
tmp[2] = arg[0];
tmp[1] = sub tmp[2] tmp[1];
tmp[1] = call h (tmp[1]), live: (tmp[0], arg[0]);
tmp[2] = arg[0];
tmp[1] = add tmp[2] tmp[1];
tmp[0] = mod tmp[1] tmp[0];
ret tmp[0];
};
};
}
function h(integer) : integer {
tmp[0] = 1;
tmp[1] = arg[0];
tmp[0] = lt tmp[1] tmp[0];
br tmp[0] {
true: {
tmp[0] = 1;
ret tmp[0];
};
false: {
tmp[0] = 268435456;
tmp[1] = 1;
tmp[2] = arg[0];
tmp[1] = sub tmp[2] tmp[1];
tmp[1] = call f (tmp[1]), live: (tmp[0], arg[0]);
tmp[2] = arg[0];
tmp[1] = mul tmp[2] tmp[1];
tmp[0] = mod tmp[1] tmp[0];
ret tmp[0];
};
};
}
function main() : * {
tmp[0] = 5;
tmp[0] = call f (tmp[0]);
trace tmp[0];
nop;
tmp[0] = 10;
tmp[0] = call f (tmp[0]);
trace tmp[0];
nop;
tmp[0] = 100;
tmp[0] = call f (tmp[0]);
trace tmp[0];
nop;
tmp[0] = void;
ret tmp[0];
}