hexaredecimal / ML

A small general purpose programming language for programming on the JVM. Package manager: https://smllregister.github.io
https://smllang.gitbook.io
Apache License 2.0
11 stars 1 forks source link

If expressions in If expression #5

Open hexaredecimal opened 2 months ago

hexaredecimal commented 2 months ago

Currently the compiler emits invalid Java code when another if expression is used in the body of the if expression. So the following code passes on the compiler but generates the wrong code.

if true then {
   1
} else (* body of the else *)
   if true then { 2 } else { 3 }
hexaredecimal commented 2 months ago

A solution that I have in mind is to keep track of how deep are we with if statements because it ALWAYS has else. if the count > root then generate expressions and store the results in local variables. Unwind the recursion and emit a unary checking and returning different expressions and the locals created. This is one solution that I'm going to implement right now.