Bug 176 - SET and Fixups
Summary: SET and Fixups
Status: RESOLVED FIXED
Alias: None
Product: RMAC
Classification: Unclassified
Component: Core (show other bugs)
Version: unspecified
Hardware: All All
: Normal normal
Assignee: Shamus Hammons
URL:
Depends on:
Blocks:
 
Reported: 2020-10-11 14:51 CDT by ggn
Modified: 2021-06-08 19:28 CDT (History)
1 user (show)

See Also:


Attachments
Behold! (2.79 KB, patch)
2020-10-12 05:19 CDT, ggn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ggn 2020-10-11 14:51:34 CDT
New users, new issues, hooray! So, this code does bad things:

delay set 9
 .print "delay=" delay
 jsr EndNopTable-(2*(delay-9))

delay set delay-9
 .print "delay=" delay
 jsr EndNopTable-(2*delay)
 jsr EndNopTable-(delay*2)
 jsr EndNopTable-delay-delay

delay set (delay*2)
 .print "delay=" delay
 jsr EndNopTable-delay

 jsr EndNopTable-0

 jsr EndNopTable


; jsr abs.l => 20/5 cycles 
; jsr EndNopTable + rts = 5+4=9 nops
NopTable:
 dcb.w 100,$4e71    ; 4/1   x100
EndNopTable: 
 rts				; 16/4


Basically, "EndNopTable" is unknown when the expression evaluator reaches the jsrs. So the expressions are recorded so they can be passed to evexpr() during fixups.... except that "delay" has changed during the assembly pass, so the fixups go haywire.

Yeah so.... really weird case there. I classified it as a bug because the user gets 0 feedback about this. They expect the code to be assembled correctly.

I can think of 2 ways to fix this

a) Somehow keep track that the symbol has been SET'd more than once and emit a warning during fixups. (a bit meh)
b) During the recording of the expression, actually sit down and evaluate all defined symbols instead of blindingly copying/marking them (I can't remember right now what happens)

I think (b) is the way to go - this will increase robustness in general and probably shouldn't be too hard to implement. I'll take a look at it tomorrow as I fear I'll do something really bad if I check it out now :)
Comment 1 ggn 2020-10-12 05:19:46 CDT
Created attachment 154 [details]
Behold!

Ok, here's the proposed fix. It certainly cures the above problems.

It also uncovered an issue in the regression tester: Drone is also generating tables that hit a similar issue. But those tables are never used, so the issue went unnoticed all these years!

This convinced me even more that this fix is needed.
Comment 2 Shamus Hammons 2021-06-08 19:28:16 CDT
Thanks for the patch!  :-)