flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > __LINE__ and other useful features?

Author
Thread Post new topic Reply to topic
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
I made some 'debugging' macros to help in some situations for my code, but I don't know how to display line number (no error should be signaled, just message..). In NASM (like C) this is possible via __LINE__, but I would like to tell the line where the macro is called, because having the line in the macro is pointless. Is there a way to do this in Fasm?

Quiz2: I know I asked this before but wouldn't be nice to have Fasm a err directive, just like display, but displays, for example:

Code:
err "Wrong parameters"    

displays
Code:
Error: Wrong parameters    

Using
Code:
display "Wrong parameters"    

displays the message, but it doesn't make it a 'error' message and plus it also displays "Error: illegal instruction". So, why not add such a 'feature', it might look a bit more 'professional', or somesuch? Wink

PS: Error should be signaled at assembly stage (maybe '@err' for preprocessor??)
Post 25 Jan 2006, 20:47
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
http://board.flatassembler.net/topic.php?t=1154
As for the errors, the reason why not add it were already explained in that other thread where you asked about it.
Post 25 Jan 2006, 20:54
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Thanks for the guide. Smile
EDIT: Why not make this official in next Fasm version (%L, etc.)?

about 'err', well, would it be hard to recognize 'err' as a 'valid' instruction that just prints the message as an erroneous message? Instead of telling 'Error: illegal instruction', just display the message? sorry if I'm lost in this area.. i didn't quite understand the other reply.

EDIT2: how to add %L (or other symbol) display the line that invoked the macro? this is what i really need, in fact. thanks

why not add these in fasm? any reason?
Post 25 Jan 2006, 21:01
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
there is "display" for that.

If you meant that "err" should also end assembling at same time, it's imposible because of multi-pass assembling, code like this
Code:
if used x
 err 'a'
end if
x:    
would cause error 'a' anyway in first pass, when it doesn't know that symbol "x" is used.
Post 25 Jan 2006, 21:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
right now, 'err' stops assembly and says "Error: illegal instruction", or something like that.

but, instead of coding:

Code:
if ~ used x
  display 'a'
  err
end if    


why not do
Code:
if ~ used x
  err 'a'
end if    

I know, it can be done via macros, but it will display 'a' as a message, not an error.. and it says 'illegal instruction' because it found 'err'.. i said, wouldn't it be nice to have 'err' do the same as an 'illegal instruction', but replace that message with the specified message? like err 'a' should display the error "Error: a"? okay, this is a minor feature, but it would be nice to have it..

About %L, or whatever, is there any reason why not add it?
thanks vid, you cleared that multi-pass thing a bit now Very Happy
Post 25 Jan 2006, 22:03
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Whoops, i made mistake i meant "if ~ used x". Condition "if ~used x" is false, because symbol x is used later in source, but in first pass it will be predicted as true, so in this case err will stop on code that shouldn't be assembled.
Post 25 Jan 2006, 22:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Smile yeah, I realized that.. that's why I used '~ used' Smile
i get a lot of these errors, too. it happens all the time Wink

EDIT: how does 'used' exactly work? I know only 'defined' that checks if variable is accessible from current position, but 'used'? thx
Post 25 Jan 2006, 22:28
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Same as "defined'. During parsing all symbols (non-reserved words) in source are collected into table. Then during assembling if assembler sees any definition of symbol (a:, label a, load a, ... ) then it marks that symbol has been used in this pass. If it see it used (anything but definition) then it marks it has been used.
Post 25 Jan 2006, 22:34
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
A samples of various error signalizings:
Code:
if ~ defined x
 err 'a'
end if
x:    

this signalizes the error the first time it meets it during assembly - error happens.

Code:
if ~ defined x
 rb -1
end if
x:    

this signalizes the error only when even after resolving the rest of code this one fails - thus you'll get the error only when you remove the "x:".

Code:
if 0
 macro+
end if    

this causes the error during preprocessing.

Adding at least three new directives would cause even more confusion for the newcomers. I try now to write some new article for documentation about the fasm's programming layers, to cover many of such problems and questions.
Post 26 Jan 2006, 07:37
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Tomasz: Do you plan to add %L symbol? or %ML (which is the line that 'invoked' the macro).. maybe in next release? it could be very useful.. any reason for not adding it?

Tomasz Grysztar wrote:
Adding at least three new directives would cause even more confusion for the newcomers.

I don't think it would be that confusing, because these directives can be placed in another section of manual, and newcomers don't need these directives anyway (and these error directives are not really part of standard Fasm syntax, should be pretty easy to read, since they are not used much)... maybe when newcomers get more 'used' to Fasm and start doing some neat macroinstructions Wink
Post 26 Jan 2006, 18:26
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
With my personal experience with newcomers I'd rather be very careful about it - especially when feature seems to be so easy to use.
Post 26 Jan 2006, 18:45
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
As for the %L, I was never convinced it would be actually so useful, when you don't from which file this line came. And file name cannot be handled this way at assembly time, since assembler operates only on numerical values assigned to symbols.
Post 26 Jan 2006, 18:53
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Tomasz Grysztar wrote:
As for the %L, I was never convinced it would be actually so useful, when you don't from which file this line came. And file name cannot be handled this way at assembly time, since assembler operates only on numerical values assigned to symbols.

why not add preprocessor default 'symbols' then? like __LINE__ I suggested, and __FILE__. this helps me alot with some 'debug' macros i wrote.
Post 26 Jan 2006, 18:57
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
Because adding such new class symbols would make another feature interacting with existing ones in a different way, an I'm already tired enough of explaining such interactions in the current already over-grown complexity of various layers in fasm. In initial design such complexity was not planned at all (since I didn't know fasm is going to be so widely used and universal) and therefore this design a bit limits what can be easily done, and what not. As only true solution I was thinking about writing a new assembler from scratch that wouldn't have such limitations, but I'm afraid it would be very much different assembler, and much slower than fasm is.
Post 26 Jan 2006, 19:26
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
if you don't plan on adding __FILE__, it can be done manually in every source:
Code:
define __FILE__ somefile.asm    

but %L or %ML are really needed, it cannot be done easily manually. pls add them

btw: didn't know it can be that complex to add some simple symbolic constants automatically (like __FILE__)
Post 26 Jan 2006, 19:30
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
I just don't like it enough to force myself to implement it. At least at this moment.
Post 26 Jan 2006, 19:38
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
i don't know how i can make my macros display that info and where it occured without %L.. i guess i'll have to figure out anyhow then
Post 26 Jan 2006, 19:43
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
Sorry for that tone, I'm just a bit tired today, after many hours of non assembly-related work now trying to put at least few new lines into planned additions to fasm's documentation...
Post 26 Jan 2006, 19:54
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
just read the new documentation yesterday, and it provided a clear explanation of numerical constants, it will definetely help newcomers (most of them look at examples first anyway Wink I did).
keep up the good work
Post 26 Jan 2006, 20:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
Quote:
I'm just a bit tired today
Yeah, we all feel that way sometimes, perfectly understandable.
Post 27 Jan 2006, 00:44
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.