+slx Posted August 5, 2018 Share Posted August 5, 2018 (edited) My son tried the following in Action! (version 3.7) INT Array x=[-1 -2 -3 -4] This results in an Error 9. The same happens when initializing a single INT to a negative value. Parentheses around the (-1) make no difference. I didn't find anything in the the manual that would prohibit initializing to negative numbers. Any ideas how to work around this or where/how to store values to initialize the array after it has been declared? Edited August 6, 2018 by slx Quote Link to comment Share on other sites More sharing options...
joyfulcoder Posted August 7, 2018 Share Posted August 7, 2018 a work around: INT Array x=[65535 65534 65533 65532] 3 Quote Link to comment Share on other sites More sharing options...
+slx Posted August 10, 2018 Author Share Posted August 10, 2018 Would still be interesting why it doesn't work as documented. Quote Link to comment Share on other sites More sharing options...
Alfred Posted August 11, 2018 Share Posted August 11, 2018 It doesn't work because the =[ ] data storing routine is looking for constants: ; GetConst(token); ---------------gconst ldy #cnserr cmp #$81 bcc adrerr cmp #constt+strt bcs adrerr lda nxtadr ldx nxtadr+1 rts The A register is holding the token for the "-" minus symbol, not the value, and thus it fails the test. There's a few things that would have to be changed to allow for the presence of unary minus, like mnum would have to be updated to invoke part of the expression evaluator to process the constant. I expect he left it this way because it's so much simpler, and can be worked around. Don't forget, the cartridge is really tight for space. 4 Quote Link to comment Share on other sites More sharing options...
+slx Posted August 26, 2018 Author Share Posted August 26, 2018 It doesn't work because the =[ ] data storing routine is looking for constants: Thanks for the detailed explanation. Sorry the thanks come late as I didn't check that subforum for some time. I suppose it works like that because the compiler uses different code for initialization and "normal" assignments to a variable (because it's faster?) Would something else make it unwise to let the initialization routine to use the same logic as the variable assignment routine. Negative numbers probably weren't that high on the list of priorities. The workaround is not extremely intuitive, though Quote Link to comment Share on other sites More sharing options...
Alfred Posted August 26, 2018 Share Posted August 26, 2018 I think it's more likely an unintended consequence of code sharing. The same code that processes code blocks [ ] where you can embed machine language does double duty as the array initializer. You wouldn't want minus signs in the code block, so it doesn't allow for that, and as a result it doesn't allow unary minus as an array initial value either. If he realized it, I'm sure he just wrote it off as a minor issue with a workaround. The only token that it does recognize is $ which is then passed to mnum to extract the hex value. Yes, assignment to a variable is done differently, and takes a lot of work internally and can generate a lot of code. He must have decided early on not to allow expressions in the initializer blocks or code blocks because it simply wasn't possible to fit the code in the cartridge. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.