flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Macro names with dot need escaping when used in struc

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17271
Location: In your JS exploiting you and your system
revolution
Macro names beginning with a dot require escaping when used within structures. e.g.
Code:
macro foo { display 'foo',13,10 }
macro .foo { display '.foo',13,10 }
struc bar1 { \foo }
struc bar2 { foo }
struc bar3 { \.foo }
struc bar4 { .foo }
foo ;Okay
.foo ;Okay
w bar1 ;Okay
x bar2 ;Okay
y bar3 ;Okay
z bar4 ;failed    
Code:
flat assembler  version 1.71.20  (1048576 kilobytes memory)
foo
.foo
foo
foo
.foo
test.asm [12]:
z bar4 ;failed
test.asm [6] bar4 [0]:
struc bar4 { .foo }
error: illegal instruction.    
It might just be my misunderstanding but I think this is a bug. I can't see any reason why the name with a dot is special.

I also noticed this:
Code:
struc bar1 q { .#\.foo = q }
struc bar2 q { .#.foo = q }
x bar1 1
y bar2 2
db x.foo ;Okay
db y.foo ;failed    
Code:
flat assembler  version 1.71.20  (1048576 kilobytes memory)
test.asm [6]:
db y.foo
error: undefined symbol 'y.foo'.    
What label name is defined by "y bar2 2" if it is not "y.foo"? I tried "..foo" and "yyfoo" but it is not either of those.


Last edited by revolution on 25 Mar 2014, 09:43; edited 1 time in total
Post 25 Mar 2014, 02:29
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
I can't see any reason why the name with a dot is special.
The reason is described in the manual:
fasm's manual, section 2.3.4 wrote:
This label will be also attached at the beginning of every name starting with dot in the contents of macroinstruction.
(Note that fasm's manual uses my old notation of "name symbol" for any token that is not a special character nor a quoted string, see section 1.2.1)

revolution wrote:
What label name is defined by "y bar2 2" if it is not "y.foo"?
Not only "." but also ".foo" gets processed by standard STRUC rules before concatenation, therefore the label that gets defined is "yy.foo".
Post 25 Mar 2014, 09:28
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17271
Location: In your JS exploiting you and your system
revolution
Oh, so macro names are not processed first for expansion. The struc processor applies the label prefix before subsequently scanning macro names. So it is not just the contents of the macro but also the macro name itself that gets the label attached. This differs from the normal processing of label attachment outside of a struc:
Code:
macro .foo { .bar db 1 }
lab:
.foo ;assembles "db 1" and doesn't create lab.foo label
x = lab.bar ;Okay
x = lab.foo ;<--- error: undefined symbol 'lab.foo'.    
Post 25 Mar 2014, 09:38
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
This differs from the normal processing of label attachment outside of a struc:
These are two different and unrelated features, as one is a type of macroinstruction evaluation by preprocessor, and the other one is a feature of label processor that is aware of syntactical context (and comes after the preprocessing). Actually I consider this label processor's quirk to be a bit of a legacy feature, but that is a different story.

The processing of dot-prefixed symbols in STRUC is performed by one of the two fasm's "line makers" (as explained in the Understanding fasm), which are the modules that brew the new lines that are then preprocessed using standard rules. All the operations specific to macroinstruction context (like concatenation with #, replacement of local names and macro parameters, etc.) are performed by the macroinstruction processor in order to generate a line that is then preprocessed normally. And thus all these operation are finished before fasm starts to look for the macroinstruction name in the line.
Post 25 Mar 2014, 11:05
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-2020, Tomasz Grysztar.

Powered by rwasa.