1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-13 11:16:48 +03:00
juvix/tests/Asm/positive/test035.jva
Łukasz Czajka 8e5f45f16f
Require semicolon to separate case/if branches in JuvixAsm syntax (#2574)
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).
2024-01-11 09:19:36 +00:00

91 lines
1.2 KiB
Plaintext

-- Nested lists
type list {
nil : list;
cons : * -> list -> list;
}
function mklst(integer) : list {
push 0;
push arg[0];
eq;
br {
true: {
alloc nil;
ret;
};
false: {
push 1;
push arg[0];
sub;
call mklst;
push arg[0];
alloc cons;
ret;
};
};
}
function mklst2(integer) : list {
push 0;
push arg[0];
eq;
br {
true: {
alloc nil;
ret;
};
false: {
push 1;
push arg[0];
sub;
call mklst2;
push arg[0];
call mklst;
alloc cons;
ret;
};
};
}
function append(list, list) : list {
push arg[0];
case list {
nil: { pop; push arg[1]; ret; };
cons: {
pop;
push arg[1];
push arg[0].cons[1];
call append;
push arg[0].cons[0];
alloc cons;
ret;
};
};
}
function flatten(list) : list {
push arg[0];
case list {
nil: ret;
cons: {
pop;
push arg[0].cons[1];
call flatten;
push arg[0].cons[0];
tcall append;
};
};
}
function main() {
push 4;
call mklst2;
trace;
call flatten;
trace;
pop;
push void;
ret;
}