hydrogen-cpp icon indicating copy to clipboard operation
hydrogen-cpp copied to clipboard

Bug with if/elif

Open joshuawills opened this issue 2 years ago • 2 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.

joshuawills avatar Jan 06 '24 12:01 joshuawills

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)

joshuawills avatar Jan 06 '24 12:01 joshuawills

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

vaelixd avatar Apr 21 '24 07:04 vaelixd