flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > fasm1 crossarchitecture untyped typization extension

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 26 Feb 2019, 21:46
macro for typization extension
Code:
macro datadefinition [name,ddef,size] {
        local ddf
        macro ddf limit:-1,[arg] \{
         \common
                \local a
                a = $
         \forward
                match any,arg \\{ ddef arg \\}
                match ,arg \\{
                        if limit
                                ddef ?
                        end if \\}
         \common
                if not limit
                        if $>(a+limit*size)
                                Error->syntax cancelled: name [limit],arg
                        else
                                rb a+limit*size-$
                        end if
                end if \}
        sizeof.name = size
        macro name ?p:?,[p]  \{
         \common
                if ~?p eqtype []
                        match any,p \\{ Error->syntax cancelled: name ?p,p \\}
                        ddf 1,?p
                else
                        match []   ,?p \\{ ddf ,p \\}
                        match [dim],?p \\{ ddf dim,p \\}
                end if \}
        struc name ?p:?,[p]  \{ .: name ?p:?,[p] \} }     


architecture dependant
Code:
              ;x86 ASCII        ;x86 Unicode      ;x64 ASCII        ;x64 Unicode      ;ARM 32
datadefinition ACHAR,db,1,\     ;ACHAR,db,1,\     ;ACHAR,db,1,\     ;ACHAR,db,1,\     ;ACHAR,db,1,\
               WCHAR,du,2,\     ;WCHAR,du,2,\     ;WCHAR,du,2,\     ;WCHAR,du,2,\     ;WCHAR,du,2,\
               VOID_8,db,1,\    ;VOID_8,db,1,\    ;VOID_8,db,1,\    ;VOID_8,db,1,\    ;VOID_8,db,1,\
               VOID_16,dw,2,\   ;VOID_16,dw,2,\   ;VOID_16,dw,2,\   ;VOID_16,dw,2,\   ;VOID_16,dh,2,\
               VOID_32,dd,4,\   ;VOID_32,dd,4,\   ;VOID_32,dd,4,\   ;VOID_32,dd,4,\   ;VOID_32,dw,4,\
               VOID_64,dq,8,\   ;VOID_64,dq,8,\   ;VOID_64,dq,8,\   ;VOID_64,dq,8,\   ;VOID_64,dd,8,\
               TCHAR,db,1,\     ;TCHAR,db,2,\     ;TCHAR,db,1,\     ;TCHAR,db,2,\     ;TCHAR,db,2,\
               VOID,dd,4,\      ;VOID,dd,4,\      ;VOID,dd,8,\      ;VOID,dd,8,\      ;VOID,dw,4,\
               HNDL,dd,4,\      ;HNDL,dd,4,\      ;HNDL,dd,8,\      ;HNDL,dd,8,\      ;HNDL,dw,4,\
               PTR,dd,4,\       ;PTR,dd,4,\       ;PTR,dd,8,\       ;PTR,dd,8,\       ;PTR,dw,4,\
               ptr,dd,4         ;ptr,dd,4         ;ptr,dd,8         ;ptr,dd,8         ;ptr,dw,4    


how looks like syntax after this:
Code:
;default syntax
ACHAR ?                         ; passed: no error
ACHAR 1                         ; passed: no error
ACHAR "a"                       ; passed: no error
;ACHAR 1,2                      ; passed: success error

;fixsize syntax
ACHAR [0]                       ; passed: no error
ACHAR [0],                      ; passed: no error
;ACHAR [0],?                    ; passed: success error
;ACHAR [1],1,2                  ; passed: success error
;ACHAR [1],"ab"                 ; passed: success error
WCHAR [8],'hello',13,10,0       ; passed: no error
;WCHAR [7],'hello',13,10,0      ; passed: success error

;unlimit syntax
ACHAR [],,,,,,,,,,,,,,,,8       ; passed: no error
VOID_8 1                                       

usual fasm directives can take as much params as thou pass.
but directives declared this way, will take only 1 parameter, or limit size of them, or unlimit amount of parameters depending on 1st parameter.

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 26 Feb 2019, 21:46
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 27 Feb 2019, 05:39
if base type is structure this modification adds same behavior to it:
Code:
macro datadefinition [name,ddef,size] {
        local ddf
        macro ddf limit:-1,[arg] \{
         \common
                \local a
                a = $
         \forward
                match any,arg \\{ ddef arg \\}
                match ,arg \\{
                        if limit
                                ddef ?
                        end if \\}
         \common
                if not limit
                        if $>(a+limit*size)
                                Error->syntax cancelled: name [limit],arg
                        else
                                rb a+limit*size-$
                        end if
                end if \}
        sizeof.name = size
        macro name ?p:?,[p]  \{
         \common
                if ~?p eqtype []
                        match    ,p \\{ ddf 1,?p \\}
                        match any,p \\{ ddf 1,?p,p \\}
                else
                        match []   ,?p \\{ ddf ,p \\}
                        match [dim],?p \\{ ddf dim,p \\}
                end if \}
        struc name ?p:?,[p]  \{ .: name ?p:?,[p] \} }     
Post 27 Feb 2019, 05:39
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 28 Feb 2019, 11:32
little changes: params after brackets follows without preciding comma
Code:
macro make@datadef [name,ddef,size] {
        local ddf
        macro ddf limit:0,[arg:?] \{
         \common
                \local a
                a = $
         \forward
                ddef arg
         \common
                if limit
                        if $>(a+limit*size)
                                Error->syntax cancelled: name [limit],arg
                        else
                                rb a+limit*size-$
                        end if
                end if \}
        sizeof.#name = size
        name#.align = size
        macro name data&  \{
                \local a
                ;define a
                match ,data \\{ ddf \\}
                match [],data \\{ define a \\}
                match [=0],data \\{ define a \\}
                match [] values,data \\{
                        ddf ,values
                        define a \\}
                match [dim] values,data \\{
                        match =0 any,dim values \\\{ Error->syntax cancelled: name data \\\}
                        ddf dim,values
                        define a \\}
                match =a first rest,a data: \\{
                        match any:,rest \\\{ Error->syntax cancelled: name data \\\}
                        ddf 1,first \\} \}
        struc name data  \{ .: name data \}
 common                                                                               ; these 3 lines only if needed to use symblol datadef@directives
        match any,datadef@directives \{ datadef@directives equ datadef@directives, \} ;
        datadef@directives equ datadef@directives name                                ;
}    


Code:
datadef@directives equ                                                                ; this line only if needed to use symblol datadef@directives

              ;x86 ASCII        ;x86 Unicode      ;x64 ASCII        ;x64 Unicode      ;ARM 32           ;AARCH64
make@datadef   ACHAR,db,1,\     ;ACHAR,db,1,\     ;ACHAR,db,1,\     ;ACHAR,db,1,\     ;ACHAR,db,1,\     ;ACHAR,db,1,\
               WCHAR,du,2,\     ;WCHAR,du,2,\     ;WCHAR,du,2,\     ;WCHAR,du,2,\     ;WCHAR,du,2,\     ;WCHAR,du,2,\
               VOID_8,db,1,\    ;VOID_8,db,1,\    ;VOID_8,db,1,\    ;VOID_8,db,1,\    ;VOID_8,db,1,\    ;VOID_8,db,1,\
               VOID_16,dw,2,\   ;VOID_16,dw,2,\   ;VOID_16,dw,2,\   ;VOID_16,dw,2,\   ;VOID_16,dh,2,\   ;VOID_16,dh,2,\
               VOID_32,dd,4,\   ;VOID_32,dd,4,\   ;VOID_32,dd,4,\   ;VOID_32,dd,4,\   ;VOID_32,dw,4,\   ;VOID_32,dw,4,\
               VOID_64,dq,8,\   ;VOID_64,dq,8,\   ;VOID_64,dq,8,\   ;VOID_64,dq,8,\   ;VOID_64,dd,8,\   ;VOID_64,dd,8,\
               TCHAR,db,1,\     ;TCHAR,db,2,\     ;TCHAR,db,1,\     ;TCHAR,db,2,\     ;TCHAR,db,2,\     ;TCHAR,db,2,\
               VOID,dd,4,\      ;VOID,dd,4,\      ;VOID,dd,8,\      ;VOID,dd,8,\      ;VOID,dw,4,\      ;VOID,dd,8,\
               HNDL,dd,4,\      ;HNDL,dd,4,\      ;HNDL,dd,8,\      ;HNDL,dd,8,\      ;HNDL,dw,4,\      ;HNDL,dd,8,\
               PTR,dd,4,\       ;PTR,dd,4,\       ;PTR,dd,8,\       ;PTR,dd,8,\       ;PTR,dw,4,\       ;PTR,dd,8,\
               ptr,dd,4         ;ptr,dd,4         ;ptr,dd,8         ;ptr,dd,8         ;ptr,dw,4         ;ptr,dd,8    


Code:
hellotext VOID_32 [3] "Hell","o wo","rld!"
WCHAR[0]
ACHAR[]
ACHAR
VOID_8[1] 27
VOID_32 [1] 100:100
;VOID_32 100:100 - this cause an error, but it dosn`t matter because long variant in line above support colon separated syntax     


for now this is impossible(possible but not implemented yet) to override structure definitioins in similar manner
Post 28 Feb 2019, 11:32
View user's profile Send private message Send e-mail 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.