flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > [solved]conditional include | self-include once |
Author |
|
macomics 02 Aug 2022, 19:30
main.asm
Code: format binary as "txt" define __MAIN__ ".\test.asm" include __MAIN__ test.asm Code: db "Test string",13,10 match any, __MAIN__ { define __MAIN__ ".\stub.asm" include any } stub.asm Code: ; empty result Code: fasm -m 1024 ./main.asm flat assembler version 1.73.30 (1024 kilobytes memory) 1 passes, 26 bytes. hd -C ./main.txt 00000000 54 65 73 74 20 73 74 72 69 6e 67 0d 0a 54 65 73 |Test string..Tes| 00000010 74 20 73 74 72 69 6e 67 0d 0a |t string..| 0000001a |
|||
02 Aug 2022, 19:30 |
|
macomics 02 Aug 2022, 19:46
main.asm
Code: match , __MAIN__ { format binary as "txt" define __MAIN__ ".\main.asm" } db "Test string ", 13, 10 match any, __MAIN__ { define __MAIN__ ".\stub.asm" include any } stub.asm Code: ; empty result Code: fasm -m 1024 ./main.asm -d __MAIN__= flat assembler version 1.73.30 (1024 kilobytes memory) 1 passes, 32 bytes. hd -C ./main.txt 00000000 54 65 73 74 20 73 74 72 69 6e 67 20 20 20 0d 0a |Test string ..| 00000010 54 65 73 74 20 73 74 72 69 6e 67 20 20 20 0d 0a |Test string ..| 00000020 |
|||
02 Aug 2022, 19:46 |
|
ProMiNick 02 Aug 2022, 20:06
may be this:
TEST24.ASM Code: match =%include, include { display 'successed include',13,10 macro %include any& \{ \} } match =include, include { macro %include any& \{ include any \} } include fix %include ;macro skip any& {} match file,__file__ { display 'try include ',`file,13,10 } include 'test24.asm' include fix include ; after that point includes operated as usual include 'test23.asm' db 2 TEST23.ASM Code:
db 2 output Code: 1 passes, 4 bytes try include C:\fasmpack\TESTS\TEST24.ASM successed include try include C:\fasmpack\TESTS\test24.asm each test23 & test24 produce by 1 byte, test24 nested once - in summary 4 bytes |
|||
02 Aug 2022, 20:06 |
|
ProMiNick 02 Aug 2022, 20:37
more clear variant (in first case "match =include, include" was always true - so it additional delay to preprocessor, more tricker match fix that)
TEST24.ASM Code: match first =%include rest, :include %include : { match :,first \{ display 'include once',13,10 macro %include any& \\{ \\} \} match :,rest \{ display 'prepare include once',13,10 macro %include any& \\{ include any \\} \} } include fix %include include 'test24.asm' include fix include include 'test23.asm' db 2 TEST23.ASM Code:
db 2 output Code: 1 passes, 4 bytes prepare include once include once |
|||
02 Aug 2022, 20:37 |
|
bitRAKE 02 Aug 2022, 22:09
In fasmg there is the sneeky:
Code: if __source__=__file__ display "main",9,__file__,10 eval 'include "',__file__,' "' ; note: extra trailing space else display "inc",9,__file__,10 end if _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
02 Aug 2022, 22:09 |
|
Overclick 03 Aug 2022, 21:45
Thanks for good tips but no one fill my needs yet.
Extra file and -d parameter is bad idea. Touching 'Include' not allowed by fasm or I doing something wrong. And I don't want to use FasmG. I trying a lot of different combo and fixing other issues at the moment but first of all I found this to pass first run only: Code: match any,skip { define skip ... } |
|||
03 Aug 2022, 21:45 |
|
macomics 03 Aug 2022, 22:28
Overclick wrote: Touching 'Include' not allowed by fasm or I doing something wrong. You are definitely doing something wrong. ./main.asm Code: format binary as "txt" match text, __file__ { db `text, 13, 10 } define __MAIN__ "./test.asm" ; This constant must be defined outside of the self-included file. If you need to set it for the main file, then I used the -d key include "./self.asm" match text, __file__ { db `text, 13, 10 } include "./test.asm" match text, __file__ { db `text, 13, 10 } ./test.asm Code: match text, __file__ { db `text, 13, 10 } match any, __MAIN__ { define __MAIN__ include any } ./self.asm Code: match text, __file__ { db `text, 13, 10 } match f=%include r, :include %include : { match :,f \{ macro %include any& \\{ \\} \} match :,r \{ macro %include any& \\{ include any \\} \} } include fix %include include "./self.asm" include fix include include "./test.asm" result Code: fasm -m 1024 ./main.asm flat assembler version 1.73.30 (1024 kilobytes memory) 1 passes, 134 bytes. output: ./main.txt Code: ./main.asm ; ./main.asm [2] ././self.asm ; ./main.asm [4] -> ./self.asm [1] ./././self.asm ; ./main.asm [4] -> ./self.asm [7] -> ./self.asm [1] ././././test.asm ; ./main.asm [4] -> ./self.asm [7] -> ./self.asm [9] -> ./test.asm [1] ./././././test.asm ; ./main.asm [4] -> ./self.asm [7] -> ./self.asm [9] -> ./test.asm [3] -> ./test.asm [1] ./././test.asm ; ./main.asm [4] -> ./self.asm [9] -> ./test.asm [1] ./main.asm ; ./main.asm [5] ././test.asm ; ./main.asm [6] -> ./test.asm [1] ./main.asm ; ./main.asm [7] I added comments to the result to make it clearer from which file which line generated the corresponding entry (if you can't decipher the tree of leading points). |
|||
03 Aug 2022, 22:28 |
|
Overclick 03 Aug 2022, 23:01
As I said I don't need extra files.
Also I already done it by macro: main.asm Code: match ,skip { macro runinclude params& \{ \} } match any,skip { define skip macro runinclude params& \{ params \} } runinclude include 'main.asm' |
|||
03 Aug 2022, 23:01 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.