-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve length-calculation of expressions containing labels #107
Comments
Thats not really a bug, it's more like a missing feature. 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.
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. |
That's what I have done now. Every jump-label will now be treated as having a lenght of 2. 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).The text was updated successfully, but these errors were encountered: