1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-30 05:42:26 +03:00
juvix/tests/Reg/positive/test018.jvr
Łukasz Czajka 0f713c7c84
JuvixReg to CASM translation (#2671)
* Closes #2562 

Checklist
---------

- [x] Translation from JuvixReg to CASM
- [x] CASM runtime
- [x] Juvix to CASM pipeline: combine the right transformations and
check prerequisites
- [x] CLI commands: add target `casm` to the `compile` commands
- [x] Tests:
   - [x] Test the translation from JuvixReg to CASM
   - [x] Test the entire pipeline from Juvix to CASM
2024-03-20 12:14:12 +01:00

89 lines
1.9 KiB
Plaintext

function ext_10((integer, integer) → integer) : integer → integer;
function app_0(integer → integer) : integer;
function f((integer, integer) → integer) : integer;
function plus(integer, integer) : integer;
function minus(integer, integer) : integer;
function mult(integer, integer) : integer;
function g(integer, integer, integer, integer) : integer;
function main() : *;
function ext_10((integer, integer) → integer) : integer → integer {
prealloc 6, live: (arg[0]);
tmp[0] = 10;
tmp[1] = arg[0];
tmp[0] = cextend tmp[1] (tmp[0]);
ret tmp[0];
}
function app_0(integer → integer) : integer {
tmp[0] = 1;
tmp[1] = arg[0];
tcall tmp[1] (tmp[0]);
}
function f((integer, integer) → integer) : integer {
tmp[0] = arg[0];
tmp[0] = call ext_10 (tmp[0]), live: (arg[0]);
tcall app_0 (tmp[0]);
}
function plus(integer, integer) : integer {
tmp[0] = arg[1];
tmp[1] = arg[0];
tmp[0] = add tmp[1] tmp[0];
ret tmp[0];
}
function minus(integer, integer) : integer {
tmp[0] = arg[1];
tmp[1] = arg[0];
tmp[0] = sub tmp[1] tmp[0];
ret tmp[0];
}
function mult(integer, integer) : integer {
tmp[0] = arg[1];
tmp[1] = arg[0];
tmp[0] = mul tmp[1] tmp[0];
ret tmp[0];
}
function g(integer, integer, integer, integer) : integer {
tmp[0] = arg[1];
tmp[1] = arg[0];
tmp[0] = sub tmp[1] tmp[0];
tmp[1] = arg[2];
tmp[0] = add tmp[1] tmp[0];
tmp[1] = arg[3];
tmp[0] = mul tmp[1] tmp[0];
ret tmp[0];
}
function main() : * {
prealloc 2;
tmp[0] = calloc plus ();
tmp[0] = call f (tmp[0]);
prealloc 2, live: (tmp[0]);
trace tmp[0];
nop;
tmp[0] = calloc minus ();
tmp[0] = call f (tmp[0]);
prealloc 2, live: (tmp[0]);
trace tmp[0];
nop;
tmp[0] = calloc mult ();
tmp[0] = call f (tmp[0]);
prealloc 4, live: (tmp[0]);
trace tmp[0];
nop;
tmp[0] = 2;
tmp[1] = 3;
tmp[0] = calloc g (tmp[1], tmp[0]);
tmp[0] = call f (tmp[0]);
trace tmp[0];
nop;
tmp[0] = void;
ret tmp[0];
}