Skip to content
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

default values for macro parameters #103

Open
wawa1474 opened this issue May 14, 2020 · 2 comments
Open

default values for macro parameters #103

wawa1474 opened this issue May 14, 2020 · 2 comments
Milestone

Comments

@wawa1474
Copy link

Is your feature request related to a problem?

sjasm allows default values for macro parameters.
sjasmplus does not appear to, unless I've completely overlooked something.

sjasm
macro test var:5
LD C, var
endmacro

test
test 0
would output
LD C, 5
LD C, 0

Describe the suggested solution:

allow for default values for macro parameters.
or tell me how to use them if I've overlooked something.

I'm sorry if I've overlooked something and sjasmplus does allow default values for macro parameters, but I have yet to find out how to use them.

@ped7g
Copy link
Collaborator

ped7g commented May 14, 2020

sjasmplus does not appear to

Yep, no default arguments in current versions.

And also it is not possible to define "overloaded" version of macro. I.e. currently the precise amount of arguments has to be passed. You can create "default" variant with distinct-enough name by creating DEFINE test5 test 5 but as always with macros/defines, too much of these could cause lot of headache (especially if one is not familiar with checking listing files often, as the substitution rules are currently sometimes too powerful and confusing)

I'm not completely sure if I like this idea, because macros/defines are generally a bit fragile if people are not careful enough (for example - your example in this issue overshadows the Z80N instruction test :) ), but if I will ever start the work on v2.x, I will surely reconsider this, it's very tempting idea.

edit: but one thing is obvious.. the colon syntax is impossible in current v1.x sjasmplus, colon is hard line delimiter except when used as end of symbol name. But I guess there should be many other options, without checking for syntax details, maybe even assign would work, like macro test var=5.

@wawa1474
Copy link
Author

I completely forgot about overloading...
but yeah it doesn't have to be a colon, as you said assign would work.

and yeah creating a macro for each needed variant could cause them to become disparate if they go through to many changes, and you forget to update each one, where as having a single macro with some default parameters makes for cleaner and simpler to maintain code.

eg.
MACRO defvar name, namelen, flags, label, initial
defvar "STATE",5,0,STATE,0
would become:
MACRO defvar name, namelen, flags=0, label, initial
defvar "STATE",5,,STATE,0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants