flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > When do FIX start working?

Thread Post new topic Reply to topic

Joined: 15 Jan 2015
Posts: 674
l4m2 24 Jan 2019, 08:00
match =0,0 {
  include "a.asm"
; a.asm
P fix display "LOL"    
P in the match doesn't work but outside is fine. How FIX do on this case?
Post 24 Jan 2019, 08:00
View user's profile Send private message Reply with quote

Joined: 24 Mar 2012
Posts: 789
Location: Russian Federation, Sochi
ProMiNick 24 Jan 2019, 08:33
Stupid post removed.
I knew that Tomasz will explain this better then I.

Last edited by ProMiNick on 24 Jan 2019, 20:31; edited 1 time in total
Post 24 Jan 2019, 08:33
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 24 Jan 2019, 18:45
As mentioned in Understanding fasm article, fasm's preprocessor has two different "line makers" - engines that prepare line of source to be further preprocessed. Any tokenized line that is preprocessed comes from one of these engines. There is a "source reader" and "macro processor", and each of them has a set of additional commands that can alter the text of tokenized line that is then passed to preprocessing.

The commands of "macro processor" are things like concatenation with # (this is why you cannot use # outside of macros). And interpretation of FIX and replacements defined with FIX are done by "source reader" - therefore they are not applied to lines produced by "macro processor".

Any block that uses { } syntax in fasm's preprocessor is a macro. Directives like REPT or IRP are so called "instantaneous-use macros", they do not have a name and are used immediately after they are defined. MATCH is also such kind of macro, it is a "single-use macro", defined and then immediately called or not (depending whether the expression is matched).

So when you have a code that looks like this:
match =0,0 {
  include "a.asm"
first thing that is done by preprocessor is the definition of this anonymous single-use macro. The lines that make the definition come directly from the source text, so before they are preprocessed they are tokenized by "source reader" and if you had "P" defined with FIX earlier, it would get replaced at this stage. But in your case "P fix" has not yet been defined - at this stage macro is getting defined, but not yet used.

After a single-use macro has been defined, it is evaluated - if the MATCH condition is fulfilled. The macro then generates a new set of lines for preprocessing, this time these lines are created by "macro processor" and not "source reader". And "macro processor" does not process things like FIX and related replacements, it only cares about things like #.
Post 24 Jan 2019, 18:45
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.