Lists as Args

Problems which concern EuroAssembler
ar18
Posts: 29
Joined: 27 Aug 2018 13:38

Lists as Args

Unread postby ar18 » 04 Sep 2018 18:13

Does €ASM support using lists as args? For example,

fake %MACRO arg1,arg2,arg3
____blah, blah, blah
____%ENDMACRO

fake <1,2,3>,<4,5,6>,<7,8,9>
User avatar
vitsoft
Site Admin
Posts: 46
Joined: 04 Nov 2017 20:08
Location: Vítkov, The Czech Republic
Contact:

Re: Lists as Args

Unread postby vitsoft » 04 Sep 2018 19:45

The list of macro arguments is available in %MACRO..%ENDMACRO body as automatic variable %*.
You cannot use automatic variable outside the macro but its contents (the whole list) may be copied to standard user-defined %variable and then used anywhere below the macro.
fake %MACRO arg1,arg2,arg3
%fakeList %SET %*
____blah, blah, blah
____%ENDMACRO

fake 1,2,3
; Variable %fakeList now contains 1,2,3 (five characters including commas).


Ooops, you prabably want to group some arguments and treat them as one ...?
I would make a quoted string from the group, then it will be treated as one argument encapsulated in quotes.
Getting rid of those quotes (first and last character) is trivial. €ASM syntax would be
fake %MACRO arg1,arg2,arg3
%Group1 %SET %arg1[2..%&-1] ; Remove the first and last character (quote).
%Group2 %SET %arg2[2..%&-1]
%Group3 %SET %arg3[2..%&-1]
%arg1ofGroup1 %SET %Group1{1}
%arg2ofGroup1 %SET %Group1{2}
%arg3ofGroup1 %SET %Group1{3}
%arg1ofGroup2 %SET %Group2{1}
%arg2ofGroup2 %SET %Group2{2}
%arg3ofGroup2 %SET %Group2{3}
%arg1ofGroup3 %SET %Group3{1}
%arg2ofGroup3 %SET %Group3{2}
%arg3ofGroup3 %SET %Group3{3}
; Do something with %argXofGroupY
; or use directly %GroupY{X} (and you won't need the previous nine lines).
%ENDMACRO

fake "1,2,3", "4,5,6", "7,8,9" ; Macro fake is expanded with three ordinal operands.
;The digit 1 is now in %arg1ofGroup1 alias %Group1{1},
;the digit 4 is now in %arg1ofGroup2 alias %Group2{1}
;the digit 9 is now in %arg3ofGroup3 alias %Group3{3} and so on.
ar18
Posts: 29
Joined: 27 Aug 2018 13:38

Re: Lists as Args

Unread postby ar18 » 04 Sep 2018 23:09

Perfect!

Who is online

Users browsing this forum: No registered users and 1 guest