Open Wolvereness opened 2 years ago
Thats not really a bug, it's more like a missing feature.
The compiler can not reliably determine the length of a "goto
But the compiler needs to know a maximum length for that goto-statement, to figure out if lines can be merged (which happens way before the actual line-numbers are known). So currently it just assumes the goto will stay as long as it originally is.
I know this is bad, because it could result in errorneous "line-too-long" errors, but I haven't really found a proper solution for this.
Solving this 100% correctly would require trial, error and backtracking during compilation, which would be en enormous amount of work and also make compile-times longer.
Perhaps as a stopgap use a change of assumption to reduce variables and labels down to 2 characters? That would help, but there's still an edge case of 1 character.
That would probably be an improvement, and also relatively simple to do.
But that doesnt just leave the 1-character edge-case: Any expression that can be pre-computed at compile time (x=1+1 -> x=2), will be precomputed. Depending on what exact value the jump-label in the expression has, the resulting expression could be much shorter.
foo>
goto foo-10
Could result in things like "goto -10", "goto 0", "goto 10", while the heuristic would assume that it's gonne be "goto XX-20", which is quite a bit longer then the possible actual results.
The next best thing would be to insert any value from 1 to 20 for every jump-label in the expression, optimize the resulting expression and then use the length of the largest of the outcomes as an estimate.
Another consideration, that would address this particular issue: throw the error later in the process by assuming the line (using semicolons) would fit, and only when the final result fails does the error get thrown. That would work 100% of cases where the developer is smarter than the compiler trying to do what I wanted to do. This particular example has a label before (no combining upward), a label after (no combining downward), and semicolons (no breaking apart).
That might be a possibility. It doesn't solve the underlying issue, but would at least work in some specific cases.
Perhaps as a stopgap use a change of assumption to reduce variables and labels down to 2 characters? That would help, but there's still an edge case of 1 character.
That's what I have done now. Every jump-label will now be treated as having a lenght of 2. That's still not perfect, but it's an improvement and I am currently lacking the time for a perfect solution.
I will rename this issue and keep it open for now, to serve as a todo.
Describe the bug
To Reproduce
Expected behavior
Platform:
Additional context The code in question would preferably be like this:
and compile to
If I replace
mode_check
andmode_swap
with2
and3
respectively, it works. An alternative solution I had in mind would necessitate a different feature (see #108).