asar icon indicating copy to clipboard operation
asar copied to clipboard

show user function calls in error call stacks

Open exodustx0 opened this issue 8 months ago • 4 comments

asar 1.90

arch 65816
lorom

org $008000

skip 1234
END:

org $00FFC0 ; header

function HeaderSizeByte(size) = ceil(log2((size>>10)+notequal(size&$3FF)))

db "foobar foobar foobar "
db $20
db $00
db HeaderSizeByte(snestopc(END))

This outputs test.asm:18: error: (Erequire_parameter): Missing required function parameter [db HeaderSizeByte(snestopc(END))]. Yes, there is a missing required function parameter, but it's not on line 18 in the calling of HeaderSizeByte; rather, notequal needed a second one. It fails to inform the user of this, and redirects them elsewhere; the redirection would be especially annoying with nested functions.

current_user_function_name can easily be used to report which function is not used right. And a new static variable current_user_function_thisline could be backed up and set before the function call and reset to the backup after the function call, to make the reported line number right; only need to figure out what to do with thisblock for that.

exodustx0 avatar Mar 14 '25 07:03 exodustx0

asar2 has much more robust error location handling, i think this could be implemented there. i don't think i want to bother with backporting it to 1.9 though...

trillllian avatar Mar 14 '25 09:03 trillllian

My idea was to change the error message (in 1.9) to "Missing required parameter for function '%s'" and then using current_user_function_name as the argument. That is trivial and much more useful than what we have now. But I don't know if you're interested in an interim solution.

exodustx0 avatar Mar 14 '25 14:03 exodustx0

well, in your case, that'd print "missing required parameter for notequal", not the current_user_function_name (using current_user_function_name would require thinking of some trickery with thisblock, or modifying every math error to include an optional "in user function %s" variant).

but still an improvement over the status quo i guess.

trillllian avatar Mar 14 '25 14:03 trillllian

Oh, I just realised the issue with using current_user_function_name as I suggested: it gets changed when calling a function, not when exiting one, so it wouldn't work with function calls containing function calls (i.e. if the example notequal() contained a function call as first argument, that function's name would be reported). But then, that could simply be changed with a local backup variable that sets it back after the function is exited.

exodustx0 avatar Mar 14 '25 15:03 exodustx0