flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > preprocessor error?

Author
Thread Post new topic Reply to topic
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl
hi.

my apologies if this question is in the wrong section.

i have this macro-instruction:
Code:
macro name#.Attach context \{

             Font.bits equ context#.canvas.bits
          Font.window equ context
     \}
    

which is in another which accepts "name".

when i run it through fasmpre.exe with name="Text", the output is
Code:
;Text.Attach Main
      
    ;Font.bits equ context.canvas.bits
  ;Font.window equ Main
    

the output is "context.canvas.bits" and should be "Main.canvas.bits"
yet the other name was replaced. what gives?

thanks in advance.
karl.

ps. running latest fasm, 1.67.27. fasmpre is older but get same error with just fasm


Last edited by karl on 28 Sep 2008, 12:16; edited 1 time in total
Post 23 Sep 2008, 23:08
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Try with "Font.bits equ context\#.canvas.bits" (note the slash I added)
Post 23 Sep 2008, 23:32
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl
Smile

thanks, ya, that works. so the # tells the preprocessor the it must replace the scanned word with it's macro value. but if there was no "context" value, why wasn't there an error? does the # just split up the string, and the preprocessor just checks if there is a replace for both "context" and ".canvas.bits", otherwise it moves on?
Post 23 Sep 2008, 23:49
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl
the backslash isn't working in another part of the code.
Code:
mov edx,[Font.window]
cmp ecx,Font.window \#.height*Font.window \#.width*3
    

becomes
Code:
mov edx,[Win.canvas]
cmp ecx,Font.window.height*Font.window.width*3
    

if I put in another slash I get
Code:
mov edx,[Win.canvas]
cmp ecx,Win.canvas#.height*Win.canvas#.width*3
    

which gives the error "extra characters on line".

this preprocessor stuff melts my brain.
thanks again.


Last edited by karl on 28 Sep 2008, 12:27; edited 1 time in total
Post 24 Sep 2008, 00:35
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Yes, it used to do the same to my brain but I found the cure, it is called Understanding flat assembler, that article clearly explains how the slash thing works and some other interesting things that maybe are not well covered in the manual.

BTW, I will move this thread to Macroinstructions forum since it belongs to there.
Post 24 Sep 2008, 01:25
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl
hey. ya, i read that doc. still melts my brain. i do understand, the slash tells the processor to skip the symbol. i'm gonna try read the doc again, more slowly. sorry for the lazy questions. was a late night.

thanks, once again.
Post 24 Sep 2008, 18:18
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
If you can't get it work post your complete macro code and the intended behavior so I can try to fix it.
Post 24 Sep 2008, 18:25
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl
Very Happy that's very kind of you.
Post 25 Sep 2008, 15:53
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl
ok well can't get this error to work so here goes

this is the main program that I send to fasm:

Code:

; Font experiment
; by karl penzhorn, 12 September 2008
  
        include 'Library\Font\App.txt'
        include 'Library\Font\Window.txt'

                Window Win
                Win.Size 300,300
                Win.Clear 0xAA

        include 'Library\Font\Font.txt'

                Font Text
                Text.Path 'FASM.exe'
                Text.Attach Win
                Text.Centre
                Text.Blit 'Hi there!'
        
        Win.EventLoop
        App.Start
    


and this is the Font.txt include:

Code:


; by karl penzhorn, 12 september 2008

  include 'Memory.txt'
  include 'File.txt'

  macro Font name {

        macro name#.Path path \{

                File    font.file
                String  name,path
                Memory  font.data,10000

                font.file.Path          name
                font.file.ReadBytes     font.data,10000
        \}

        macro name#.Attach context \{

                Font.bits equ context\#.canvas.bits
                Font.window equ context
        \}

        macro name#.Centre \{\}
        macro name#.Blit text \{

                local loop

                mov edx,[\#Font.bits\#]

                mov ecx,0
                loop:
                mov al,[\#font.data\#+ecx]
                mov byte[edx+ecx],al
                inc ecx
                cmp ecx,10000
                jne loop

                Font.window\#.Flush

        \}

  }

    


fasm is giving the error 'illegal instruction' saying 'Font.window.Flush'. So it's not replacing Font.window with Win.

does it make sense what i'm doing with the code? when i call 'Text.Attach Win', it assigns Font.window to Win. but it's not replacing it when I try to call Win.Flush.

thanks in advance. again.
Post 27 Sep 2008, 16:17
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
mmmh, it should be expanded with what "context" was, right? Try this too see what happens
Code:
        macro name#.Blit text \{

                local loop

                mov edx,[\#Font.bits\#]

                mov ecx,0
                loop:
                mov al,[\#font.data\#+ecx]
                mov byte[edx+ecx],al
                inc ecx
                cmp ecx,10000
                jne loop

; "match" to get actual value of Font.window equate
                match window, Font.window \\{window\\#.Flush\\} 

        \}    
Post 27 Sep 2008, 17:06
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl
ok yes that works.

why did it work with the equates before (ie. Font.bits) but not Font.window?
Post 27 Sep 2008, 17:11
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Because font.bits is not used as a macroinstruction call so it is converted to its actual value before passing it to the assembler layer.

BTW, using "mov edx,[Font.bits]" instead of "mov edx,[\#Font.bits\#]" doesn't work? Note that it should since the # are for concatenation of symbols but you are not concatenating nothing there (because "[" and "]" are symbol separators so the # has no effect here actually and is not needed anyway).
Post 27 Sep 2008, 18:30
View user's profile Send private message Reply with quote
karl



Joined: 07 Feb 2006
Posts: 63
Location: South Africa
karl
ok what about if I do this

Code:
macro name#.Attach context \{

                name#.Window equ context

        \}

        macro name#.Centre \{\}

        macro name#.Blit text \{

                local loop

                mov edx,[name#.Window\#.canvas.bits]

                mov ecx,0
                loop:
                mov al,[name#.data+ecx]
                mov byte[edx+ecx],al
                inc ecx
                cmp ecx,10000
                jne loop

               match window, name#.Window \\{window\\#.Flush\\}

        \}
    


"mov edx,[name#.Window\#.canvas.bits]" is replaced with "mov edx,[Text.Window.canvas.bits]"

but "mov edx,[name#.Window]" is replaced with "mov edx,[Win]". what gives?
Post 27 Sep 2008, 19:19
View user's profile Send private message 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. Also on YouTube, Twitter.

Website powered by rwasa.