1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-02 10:47:32 +03:00
juvix/tests/Reg/positive/test035.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

106 lines
2.1 KiB
Plaintext

type list {
nil : list;
cons : (*, list) → list;
}
function mklst(integer) : list;
function mklst2(integer) : list;
function append(list, list) : list;
function flatten(list) : list;
function main() : *;
function mklst(integer) : list {
tmp[0] = 0;
tmp[1] = arg[0];
tmp[0] = eq tmp[1] tmp[0];
br tmp[0] {
true: {
prealloc 1, live: (arg[0]);
tmp[0] = alloc nil ();
ret tmp[0];
};
false: {
tmp[0] = 1;
tmp[1] = arg[0];
tmp[0] = sub tmp[1] tmp[0];
tmp[0] = call mklst (tmp[0]), live: (arg[0]);
prealloc 3, live: (tmp[0], arg[0]);
tmp[1] = arg[0];
tmp[0] = alloc cons (tmp[1], tmp[0]);
ret tmp[0];
};
};
}
function mklst2(integer) : list {
tmp[0] = 0;
tmp[1] = arg[0];
tmp[0] = eq tmp[1] tmp[0];
br tmp[0] {
true: {
prealloc 1, live: (arg[0]);
tmp[0] = alloc nil ();
ret tmp[0];
};
false: {
tmp[0] = 1;
tmp[1] = arg[0];
tmp[0] = sub tmp[1] tmp[0];
tmp[0] = call mklst2 (tmp[0]), live: (arg[0]);
tmp[1] = arg[0];
tmp[1] = call mklst (tmp[1]), live: (tmp[0], arg[0]);
prealloc 3, live: (tmp[0], tmp[1], arg[0]);
tmp[0] = alloc cons (tmp[1], tmp[0]);
ret tmp[0];
};
};
}
function append(list, list) : list {
tmp[0] = arg[0];
case[list] tmp[0] {
nil: {
nop;
tmp[0] = arg[1];
ret tmp[0];
};
cons: {
nop;
tmp[0] = arg[1];
tmp[1] = arg[0].cons[1];
tmp[0] = call append (tmp[1], tmp[0]), live: (arg[0], arg[1]);
prealloc 3, live: (tmp[0], arg[0], arg[1]);
tmp[1] = arg[0].cons[0];
tmp[0] = alloc cons (tmp[1], tmp[0]);
ret tmp[0];
};
};
}
function flatten(list) : list {
tmp[0] = arg[0];
case[list] tmp[0] {
nil: {
ret tmp[0];
};
cons: {
nop;
tmp[0] = arg[0].cons[1];
tmp[0] = call flatten (tmp[0]), live: (arg[0]);
tmp[1] = arg[0].cons[0];
tcall append (tmp[1], tmp[0]);
};
};
}
function main() : * {
tmp[0] = 4;
tmp[0] = call mklst2 (tmp[0]);
trace tmp[0];
tmp[0] = call flatten (tmp[0]);
trace tmp[0];
nop;
tmp[0] = void;
ret tmp[0];
}