haumea-lang / haumea-rs

Haumea is an experimental language designed to be simple and easy to learn and program in.
MIT License
7 stars 2 forks source link

Fix #22? #23

Closed jeandrek closed 7 years ago

jeandrek commented 7 years ago

Now the factorial example compiles to

long factorial(long n) {
    {
        if (n == 0l)
            return 1l;
        else
            return (n * factorial((n - 1l)));
    }
    return 0l;
}

int main() {
    {
        display(factorial(5l));
    }
    return 0l;
}
bates64 commented 7 years ago

Looks like the if outputs one too many spaces, still.

if  (n == 0l) 
  ^^
jeandrek commented 7 years ago

Oh, I didn't notice that.

jeandrek commented 7 years ago

Note: with this then blocks in if/while/for statements aren't special cases, so

to main do
  if 1 = 1 then do        
    display(1) display(2)
  end
end

compiles to

int main() {
    {
        if (1l == 1l)
            {
                display(1l);
                display(2l);
            }
    }
    return 0l;
}

This makes sense to me, but many programmers hate this style of indentation. Should it change?

bates64 commented 7 years ago

..many C programmers hate this style..

Yeah, probably best to use 1TBS, if possible... the best result would be not generating do .. end braces when they aren't needed:

int main()
{
    if (1l == 1l) {
        display(1l);
        display(2l);
    }
    return 0l;
}
jeandrek commented 7 years ago

Okay, so have a procedure called compile_statement_wo_extra_braces or something and have the code generators for if, forever, while and for each output braces call it instead of compile_statement?