flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [BUG?] Too early evaluation of "defined"

Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Why this code doesn't work?
Code:
macro call_cosh argument
{
local a
; Detect constant
virtual
  db `argument
  load a byte from $$
end virtual

  display '^^', a, '^^', 13, 10

  if a >= '0' & a <= '9' ; It is a constant
    push dword argument ; This needs to be different for better precision

    if argument eqtype 1.0
      fld dword [esp]
    else
      fild dword [esp]
    end if

    add esp, 4
  else ; It is a variable (needs more work as this is not necessarily true)
    display 13, 10, "__VARIABLE__", 13, 10
    if defined argument#.float ; Why is it evaluated so early?
      fld dword [esp]
    else
      fild dword [esp]
    end if
  end if

  call cosh ; Argument passed in ST(0)
}

struc dd [arg]
{
common
  .float:
  dd arg
}

call_cosh 1.0
call_cosh 1
call_cosh alpha
call_cosh beta

alpha dd 1
beta dd 1.0

cosh: ; Not implemented    


This code works and shows that "1.0" nor "1" hits the ELSE body:
Code:
macro call_cosh argument
{
local a
; Detect constant
virtual
  db `argument
  load a byte from $$
end virtual

  display '^^', a, '^^', 13, 10

  if a >= '0' & a <= '9' ; It is a constant
    push dword argument ; This needs to be different for better precision

    if argument eqtype 1.0
      fld dword [esp]
    else
      fild dword [esp]
    end if

    add esp, 4
  else ; It is a variable (needs more work as this is not necessarily true)
    display "__VARIABLE__", 13, 10
    if 1
      fld dword [esp]
    else
      fild dword [esp]
    end if
  end if

  call cosh ; Argument passed in ST(0)
}


struc dd [arg]
{
common
  .float:
  dd arg
}

call_cosh 1.0
call_cosh 1
call_cosh alpha
call_cosh beta

alpha dd 1
beta dd 1.0

cosh: ; Not implemented    
Output wrote:
^^1^^
^^1^^
^^a^^
__VARIABLE__
^^b^^
__VARIABLE__


[edit]It is not "defined" the problem actually, it is the ELSE block itself that gets "speculatively" evaluated when not needed[/edit]
Post 11 Oct 2009, 23:11
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
The correctness of label names is check by parser when it converts the source into intermediate code, which is the processed by assembler. That's why this error is signaled before the actual assembly happens.
I may try to make it work somehow, but I don't promise anything.
Post 11 Oct 2009, 23:33
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Ups, I completely overlooked the parser stage when posting this. If there are no other invalid syntax things that are checked at the assembler stage (and hence, the syntax error is not always signaled), then I think it would be better to leave this as it is now.
Post 11 Oct 2009, 23:58
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 GitHub, YouTube, Twitter.

Website powered by rwasa.