flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Strange local labels...

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 30 Oct 2012, 06:47
Here is an example of some local label definitions. The last two lines looks illogically for me.
Tomasz, is it intentional or simply a bug?

Code:
struc s1 {
  .f1 db 1
  .f2 db 1
}

n1  db 1

.p1 db 1

n2  s1

.p2 db 1
        x = n1
        x = n1.p1
        x = n2
        x = n2.f1
        x = n2.f2

        x = n2.f2.p2  ; pass?
        x = n2.p2     ; fails!
    

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 30 Oct 2012, 06:47
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 30 Oct 2012, 10:48
There are two different mechanisms mixed here, the dotted label in "struc" definition is processed by preprocessor and so it's a completely separate thing. Look at the preprocessed source (with PREPSRC tools from the official package, for example) to see what's going on here.
Post 30 Oct 2012, 10:48
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 30 Oct 2012, 11:21
Yes, I understand what happens and checked it in the preprocessed source. But is it normal? I mean one probably would expect .p2 to be defined as a local label of n2, not of n2.f2;
Now the preprocessor creates following:
Code:
n2:
n2.f1 db 1
n2.f2 db 1
.p2 db 1    


What if the preprocessor does not put the name of the structure at the front of its members. This way, there will be:
Code:
n2:
.f1 db 1
.f2 db 1

.p2 db 1    


Do you think some incompatibility can be introduced this way? Or other problems... Confused
Post 30 Oct 2012, 11:21
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 30 Oct 2012, 16:05
JohnFound wrote:
Do you think some incompatibility can be introduced this way? Or other problems... Confused
Of course, it would be very incompatible with what "struc" does currently. As a simple example: the nesting of structures would no longer work - the NASM-like locals mechanism that is used by fasm's parser is a very simple one and has no way of maintaining multiple levels like the "struc".
Post 30 Oct 2012, 16:05
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 30 Oct 2012, 16:32
I see. IMHO, this behavior of the structures should be documented somehow. Of course conflicts as described above are very uncommon.

Regards
Post 30 Oct 2012, 16:32
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 30 Oct 2012, 18:46
This is just another case where it is important to understand the separation of the preprocessor's language from the later stages. I planned to elaborate on this in the Understanding fasm article, nevertheless the manual already covers it all quite completely (though in compact form). It may only need cleaning up of terminology in a few places (for example, it often uses "symbol" or "name" meaning the same thing that I now usually call "token").
Post 30 Oct 2012, 18:46
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.