[nasm:master] Make istruc "at" support struc local labels

"nasm-bot for Sławomir Bocheński" <lkslawek at gmail.com>" at zytor.com "nasm-bot for Sławomir Bocheński" <lkslawek at gmail.com>" at zytor.com
Mon Nov 7 17:12:29 PST 2022

Commit-ID:  5b9bcacebb2e5a99b776bb2b3abb472e3c57cb33
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=5b9bcacebb2e5a99b776bb2b3abb472e3c57cb33
Author:     Sławomir Bocheński <lkslawek at gmail.com>
AuthorDate: Thu, 8 Sep 2022 20:37:53 +0200
Committer:  Sławomir Bocheński <lkslawek at gmail.com>
CommitDate: Fri, 9 Sep 2022 00:30:06 +0200

Make istruc "at" support struc local labels

istruc currently does not work very well with passing local labels to
"at" macro, as the labels are inserted literally. E.g. considering the
example from test/struc.asm:

	struc teststruc1
	  .long: resd 1
	  .word: resw 1
	  .byte: resb 1
	  .str:  resb 32
	; ...
	istruc teststruc1
	 at .word, db 5

if one were to put a global label before istruc to refer to its
instance, the code would fail to compile, due to ".word" being unknown
in that scope. Of course one could then use full form after "at", i.e.
"teststruc1.word", but this seems rather tedious.

This also makes istruc use with local labels fail for anything but the
last declared struc.

The change automatically prepends struc name to the label if the label
given to "at" starts with a dot.

Signed-off-by: Sławomir Bocheński <lkslawek at gmail.com>

 macros/standard.mac | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/macros/standard.mac b/macros/standard.mac
index a2ab4fc1..f2e5d7f1 100644
--- a/macros/standard.mac
+++ b/macros/standard.mac
@@ -99,7 +99,13 @@ STD: nasm
 %imacro at 1-2+.nolist
-    times (%1-%$strucname)-($-%$strucstart) db 0
+    %defstr %$member %1
+    %substr %$member1 %$member 1
+    %ifidn %$member1, '.'
+        times (%$strucname%1-%$strucname)-($-%$strucstart) db 0
+    %else
+        times (%1-%$strucname)-($-%$strucstart) db 0
+    %endif

More information about the Nasm-commits mailing list