orosmatthew / hydrogen-cpp

A hobby programming language 🔥

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug with if/elif

joshuawills opened this issue · comments

**let x = 1;
let y = x + 3;

if (x - 1) {
exit(1);
} elif (x - 1) {
exit(2);
}

exit(y);**

Program crashes in this example. Fixed by adding an empty else statement, but appears to have something to do with label mismatching.

I think a possible solution is in your "elif generation" (Generation.hpp line 141) you need to jump to the endLabel rather than the newly created label, as that newly created label isn't placed (it's within the scope of the predicate existing (line 144)

I tried this for my own compiler and it worked.
141| gen.m_output << " jz " << label << "\n"; ––> 141| gen.m_output << " jz " << end_label << "\n";