orosmatthew / hydrogen-cpp

A hobby programming language 🔥
MIT License
391 stars 38 forks source link

Bug with if/elif #19

Open joshuawills opened 10 months ago

joshuawills commented 10 months ago

**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.

joshuawills commented 10 months ago

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)

DoubleDotStudios commented 7 months ago

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";