-
Notifications
You must be signed in to change notification settings - Fork 40
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
For loop countinng down to 0 doesn't work #130
Comments
Just adding a few notes. It's been a while since implementing this, so trying to log a bit of things about behaviour as the bug is still open.
To be honest, I kind of want to improve range literals, so that excluding end bounds is possible, and translating code is easier. I also want to fix for loops to be more usable in general, there's already an issue to allow runtime ranges in for loops too. I'll have to see about that, but at the very least: Anyway, this is the code responsible for most of the logic around wiz/src/wiz/compiler/compiler.cpp Lines 6598 to 6748 in a174205
|
A few other examples (beyond the initially reported bug) that would be useful for runtime for-loops. Allow the initial value to be set by transfer from another register:
rewritten:
Allow the initial value for the loop counter register to be set some arbitrary number of lines earlier, with code in between:
rewritten:
|
Looks more like an optimizer bug, not the loop related. I'd recommend creating an issue for this.
This looks like correct behaviour, unless I'm misunderstanding. You ask compiler not initalize |
I apologize. The comments aren't explained well enough. This isn't an optimizer problem. It is a missing feature in the compiler, that you can't use a variable as one of the loop bounds. I want to write this, but the compiler won't let me:
The compiler lets me write the following code, and I get for-loop syntax, and I get the right range, but emits more code than I'd prefer for this exact scenario:
The problem related to an optimization, but it is a hand-optimization problem, not a compiler automated optimization problem.
Yeah, again a case of my comments being unclear. The compiler doesn't let me write this code either. I get this error.
I am replying to this thread because on the discord @Bananattack asked for some more explicit examples, related to their notes on all the types of runtime for loops people would like supported. So I'm adding some in my project that I currently have to work around with do/while loops. |
I've looked through my code and I could not find any Here are three examples of A common looping pattern in my code is a backwards loop from the last-index to 0 inclusive. (NOTE: this pattern only works if the initial loop variable is <= 0x80 for 8 bit indexes and <= 0x8000 for 16 bit indexes).
I also have a lot of loops that increment or decrement by 2 to access word arrays and structure-of-word-arrays data.
Countdown loops using a zeropage variable.
|
Got it, sorry about that, I did indeed misunderstood. Also I haven't been following up on the Discord lately. Not sure what Bananattack wants, but if I were him, I'd like those to be separate feature requests on Github, it'd be easier to track down, and they could close it if needed too. |
The following code is from the examples in the README.md
Output:
Notes
Original file to reproduce the issue
bugtest.txt
Build from
b25ba2d90288fc8a380d99b3ad08a5b48caaa484
commitBuild with
wiz\wiz.exe src/bugtest.wiz -o bugtest.nes
commandThe text was updated successfully, but these errors were encountered: