flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > [fasmg] struc ? and struc name

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 489
Location: Belarus
Long story short, having the below definitions, why match type more, def: is not processed for named struc defined from struct macro -- I never reach here! point from struct LINE

Code:
define @mode
@mode = 64

; ---------------------------------------------------

macro struct name*
  local n

  display 'struct ', `name,13,10

  define name
  namespace name
  virtual at 0
  n = 0
  struc (__name__) ? def&
    local m

    display '    ', `__name__,0x20, `def,13,10

    match type more, def:

      display 'here!',13,10

      __name__ def
    end match
  end struc

  macro end?.struct?!
    restruc ?
    end namespace
    sizeof.name = $
    end virtual

    struc (__name__) name def&
      display '>>', `__name__, 0x20, `name,13,10
    end struc

    purge end?.struct?
  end macro
end macro

struct POINT
  x intn
  y intn
end struct

struct LINE
  startpoint POINT
  endpoint POINT
end struct


;------------------ just helpers below -------------


element datatype
element generic:  datatype
element aligned:  datatype
element natural:  datatype

macro align? n*, x:?
  if n > 0
    emit 1: (n - 1) - ($ + n - 1) mod (n) dup (x)
  else if n <> 0
    err 'invalid argument'
  end if
end macro

macro datatypes meta, def&
  irp <name, size>, def
    element name: meta + size
    macro name args:?&
      local m, n
      m = name metadata 1
      n = m scale 0
      if n = 0
        n = @mode / 8
      end if
      if m relativeto aligned | m relativeto natural
        align n
      end if
      match [value], args
        emit n: (0 + value) dup ?
      else
        emit n: args
      end match
    end macro
    struc (__name__) name args:?&
      local m, n
      m = name metadata 1
      n = m scale 0
      if n = 0
        n = @mode / 8
      end if
      if m relativeto aligned | m relativeto natural
        align n
      end if
      label .: n
      match [value], args
        emit n: (0 + value) dup ?
      else
        emit n: args
      end match
      __name__.__size = n
      __name__.__length = $ - .
    end struc
  end irp
end macro

datatypes aligned, int8,1, int16,2, int32,4, int64,8
datatypes natural, intn,0
; ---------------------------------------------------
    
Post 02 Jun 2017, 11:30
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6981
Location: Kraków, Poland
You have POINT expression-class symbol defined as a symbolic variable with empty text. So when you do:
Code:
match type more, POINT:    
the text that is matched becomes simply ":", since the "POINT" is replaced with empty text. You can detect this by replacing your debugging display just above that MATCH with this one:
Code:
    match any, def:
        display ' -  ',`__name__,0x20,`any,13,10
    end match    


To match the text without performing replacements of symbolic variables you can use the old trick from fasm 1:
Code:
    local proxy
    define proxy def:
    match type more, proxy    


PS. Just in case you thought that you could use RAWMATCH to do it without proxy: I would not recommend it, because it also discards any recognition context from the text it matches. RAWMATCH is not a shortcut for the above construction, it is only useful when you're interested in the text as-is and not the values of symbols that the text may represent.
Post 02 Jun 2017, 12:18
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 489
Location: Belarus
Ah, that define thing. Thanks, Tomasz.
If I do
Code:
define name name
    

could there be any problems? This seems to resolve the issue
Post 02 Jun 2017, 12:42
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6981
Location: Kraków, Poland
zhak wrote:
Ah, that define thing. Thanks, Tomasz.
If I do
Code:
define name name
    

could there be any problems? This seems to resolve the issue
That's a clever trick. This would create a circular reference if the symbol was used in an expression, but as this symbol is not intended to be used in an expression anyway, I think it might be even better than defining it with empty value - because when it has empty value you can put it into an expression with no actual effect, and in this case it would at least signal some error (circular reference).
Post 02 Jun 2017, 12:49
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-2018, Tomasz Grysztar.

Powered by rwasa.