Open bates64 opened 8 years ago
Does the readability of output matter?
No, but it'd be nice to output/format code readably anyway :stuck_out_tongue_winking_eye:
Following the discussion in #23, looks like it's worth trying to output 1TBS as it's pretty standard?
long factorial(long n)
{
if (n == 0l) {
return 1l;
} else {
return (n * factorial((n - 1l)));
}
return 0l;
}
int main()
{
display(factorial(5l));
return 0l;
}
It also might be a good idea to output any comments as well, so people could see exactly how their code corresponded to C (in the cases that it did).
Well, right now this is what compiling examples/factorial.hau
produces:
/* Haumea prolog */
#include <stdio.h>
long display(long n) {
printf("%ld\n", n);
return 0;
}
long read() {
printf("Enter an integer: ");
long n;
scanf("%ld", &n);
return n;
}
/* End prolog */
/* Start compiled program */
long factorial(long n) {
{
if (n == 0l)
return 1l;
else
return (n * factorial((n - 1l)));
}
return 0l;
}
int main() {
{
display(factorial(5l));
}
return 0l;
}
/* End compiled program */
Does that mean this issue can be closed?
@TheMonsterFromTheDeep, good idea with the comments.
Does that mean this issue can be closed?
I think this is why @nanalan hasn't closed it yet.
Also @BookOwl we should probably never output block braces if there's only one statement inside.
@nanalan The idea of the 1TBS is that the statements in if/while/for statements are always blocks.
@Jonathan50 derp
You guys can try and make the C prettier if you want, but I don't think y'all should spend too much time on it, considering that the ultimate consumer of the C is a compiler, and that we may not even use C soon (#18).
Being able to output well-formatted code is a good idea though in terms of people moving on from the language :smile:
For example,
examples/factorial.hau
compiles to..