flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > [solved] dotted notation and __file__ sym variable

Author
Thread Post new topic Reply to topic
MaoKo



Joined: 07 May 2019
Posts: 4
Location: Paris/French
Hi! I've two problems. The first one is that I'm trying to write some M68K macro and I need to handle some names such as "adda.w, sub.l, ...".
When I do:
Code:
iterate <instr,opcode>, and,1100b, add,1101b, eor,1011b ;, ....
  ; instr? equ
  iterate suffix, b,w,l
    macro instr?.suffix?
    end macro
  end iterate
end iterate
    


I can successfully call macro with name and.b but not eor.w.
eor seem to be an undefined symbol, I need to prepend the ? as in eor?.w.
I think it's work for "and" cuz there is a already defined case-insensitive sym.
The second line must be commented-out for work but the original meaning of add,and disappear. I don't understand why chain of case-insensitive symbol (a?.b?.c) need to be separatively declared one by one.
Probably I have don't fully understanded the man.

My second problem is that I need to define the source file name in the object file generated by fasmg for debug purpose. So in a file, I declare a postpone block that db __file__, which is included in source file. But in the output, the name match the file who declare the postpone block cuz file included by "include" are preprocessed first. How I can do this without manually do the db __file__ in each source file.

Sorry for my english.
Have a good day Smile.


Last edited by MaoKo on 12 Oct 2019, 01:34; edited 1 time in total
Post 07 Oct 2019, 00:40
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7372
Location: Kraków, Poland
Thank you for the questions that show me the places in documentation that need some work! Smile

MaoKo wrote:
Hi! I've two problems. The first one is that I'm trying to write some M68K macro and I need to handle some names such as "adda.w, sub.l, ...".
When I do:
Code:
iterate <instr,opcode>, and,1100b, add,1101b, eor,1011b ;, ....
  ; instr? equ
  iterate suffix, b,w,l
    macro instr?.suffix?
    end macro
  end iterate
end iterate
    


I can successfully call macro with name and.b or add.l but not eor.w.
eor seem to be an undefined symbol, I need to prepend the ? as in eor?.w.
I think it's work for "add" and "and" cuz there are already defined case-insensitive sym.
The second line must be commented-out for work but the original meaning of add,and disappear. I don't understand why chain of case-insensitive symbol (a?.b?.c) need to be separatively declared one by one.
Probably I have don't fully understanded the man.
When you define macro like this:
Code:
macro eor?.w?    
only the "w?" is the actual symbol that gets defined (and therefore gets defined as case-insensitive). The "eor?." part is just a prefix that tells in what namespace this symbol resides. This might be more apparent if you rewrite the same definition this way:
Code:
namespace eor?
    macro w?
        ; ...    
which is equivalent.
You can therefore define such macro like this:
Code:
macro eor.w?    
and it is going to automatically find the default namespace for "eor" symbol - and if it finds no expression-class symbol of such name (note that only expression-class symbols serve as namespace tree nodes), it used the default case-sensitive one. To make this namespace-selecting symbol case-insensitive you need to define it, like:
Code:
define eor?
; or:
eor? = 0
; or even:
eor?:    
Any of the above variants is going to make a case-insensitive expression-class symbol as needed.

In other words, when you use a symbol like EOR.W, only the W portion is the name of the macro, EOR portion is the name of the parent symbol of the namespace, which is an expression-class symbol. You need to define them both. And if you also define an EOR macro, it is a completely separate matter (a definition like "macro eor?" does not create an expression-class symbol).

MaoKo wrote:
My second problem is that I need to define the source file name in the object file generated by fasmg for debug purpose. So in a file, I declare a postpone block that db __file__, which is included in source file. But in the output, the name match the file who declare the postpone block cuz file included by "include" are preprocessed first. How I can do this without manually do the db __file__ in each source file.
Any macro is transparent for this purpose: if you use __FILE__ in a macro, it sees the file of the code that called this macro (even if several levels deep). So if you have any macro that is certain to be called by the main source file, you can get the value of __FILE__ there and store it in some variable to access where needed.

If you have no such option, you could perhaps go super-tricky and put something like this at the end of the header file:
Code:
postpone
    display __mainfile__
end postpone

macro ?! line& ; this is a one-shot line interceptor that should catch a line of the outer file
    purge ?
    __mainfile__? = __file__
    outscope line
end macro ; make sure that this is the last line of file, with no line break after it    
But if you simply have any macro that you know that is going to be called some way (even indirectly through another macro) from the main file, just use that.

PS. I have updated the manual.
I could also add another built-in variable just for the purpose of getting the name of main file. It's quite easy to add if we decide that it's needed.
Post 07 Oct 2019, 06:45
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7372
Location: Kraków, Poland
I have added new symbol, __SOURCE__, to refer to the main source file. I concluded that this is something that should not really be so tricky to do. You get it starting with version "ip7v4".
Post 07 Oct 2019, 21:42
View user's profile Send private message Visit poster's website Reply with quote
MaoKo



Joined: 07 May 2019
Posts: 4
Location: Paris/French
Hello. Thx to reply for my problems Smile. For my first problem, visualizing thing such as namespace help a lot.
So a better code is:
Code:
iterate <instr,opcode>, and,1100b, add,1101b, eor,1011b ;, ....
  restore instr? ; prevent forward-referencing
  if ~ (definite instr)
    define instr?
  end if
  iterate suffix, b,w,l
    macro instr?.suffix?
      ; ...
    end macro
  end iterate
end iterate
    

Hopefully definite/defined op work only on expression class sym Smile.
For the __file__ sym, macro ?! work fine but, yeah, I think __source__ is more lisible.
Thx.
Post 07 Oct 2019, 22:45
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7372
Location: Kraków, Poland
MaoKo wrote:
Code:
  restore instr? ; prevent forward-referencing
  if ~ (definite instr)
    define instr?
  end if    
This piece is a bit strange. RESTORE here does not really prevent forward-referencing, because you use DEFINITE, which never forward-references things anyway. But, because you use RESTORE unconditionally, you are in fact removing previous definition of the symbol and likely forcing DEFINITE condition to become true anyway.

Another thing to note is that DEFINITE does not allow an expression to be empty, while DEFINE does. So when you make an empty symbolic definition with line like "define instr?", then "defined instr" becomes a valid condition, while "definite instr" becomes invalid expression.

I would suggest using either of the following variants instead:
Code:
  if ~ defined instr
    restore instr? ; prevent forward-referencing
    define instr?
  end if    
Code:
  if ~ definite instr
    instr? := 1  ; you can also use a definition like "element instr?" here
  end if    
Post 08 Oct 2019, 06:19
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-2019, Tomasz Grysztar.

Powered by rwasa.