Roman
Joined: 21 Apr 2012
Posts: 1997
|
For fast writing code. I create macro basic fasmw 1.73.
My variant simple basic:
macro _nxt r,lb, rest=0{ dec r
jnz lb
If rest >0
restore lb
end if
}
macro _nxtp r,lb, rest=0{pop r
dec r
jnz lb
If rest >0
restore lb
end if
}
macro mBasic [args] { common
macro mGetArg af*,base*,[arg] \{ \common
;match any,GetBufr \\{ define GetBufr any+af
mov base,[GetBufr+af]
GetReg equ base
;\\}
\forward match =+ x, arg \\{ add base, x \\}
match =- x, arg \\{ sub base, x \\}
;match =:=~ x, arg \\{ shl base, x \\}
match "(", arg \\{ push base \\}
match ")", arg \\{ pop base \\}
match "{(", arg \\{ local .lb
.lb: push base
get_lb equ .lb
display "{"
\\}
match ")}", arg \\{ pop base
dec base
;test base, base
jnz get_lb
restore get_lb
display "}"
\\}
match "{", arg \\{ local .lb
.lb:
get_lb equ .lb
display "{"
\\}
match "}", arg \\{ test base, base
jnz get_lb
restore get_lb
display "}"
\\}
match "vec4" x, arg \\{ irpEqsVec4 equ x
x\\#\\_type equ 'vec4'
;display x_type
\\}
match "ivec" x, arg \\{ irpEqsIVec equ x
x\\#\\_type equ 'int'
;display x_type
\\}
match ">" x, arg \\{ display '>'
shr base, x \\}
match "<" x, arg \\{ shl base, x \\}
match ":" x, arg \\{ x: x\\#\\_type equ 'label' \\}
match "!0": x, arg \\{ test base, base
jz x \\}
match "!0", arg \\{ test base, base
jz @f \\}
match "!>0": x, arg \\{ test base, base
jnz x \\}
match "to", arg \\{ ;display 'to;'
mov [GetBufr+af],base \\}
match "to": x, arg \\{ ;display 'to2;'
mov x,base \\}
match #:x , arg \\{ x equ base \\}
match : , arg \\{ mov base, [base] \\}
match '(do)' , arg \\{ push base
call base
pop base
\\}
match '(do)': x, arg \\{ push base
call dword x
pop base
\\}
match 'do' , arg \\{ call base \\}
match 'do': x, arg \\{ call dword x \\}
match 'ptR'x:z, arg \\{ mov x,[z]
add z,GetptrR
\\}
match 'ptW'x:z, arg \\{ mov [z],x
add z,GetptrW
\\}
match 'ptR_'x:z, arg \\{ mov x,[z] \\}
match 'ptW_'x:z, arg \\{ mov [z],x \\}
match =* x , arg \\{ x base \\}
\}
if ~ args eq
forward mGetArg args
common end if
purge mGetArg
@@:
}
macro mBasic_ [args] { common
macro mGetArg base*,[arg] \{ \common
;match any,GetBufr \\{ define GetBufr any+af
;mov base,[GetBufr+af]
GetReg equ base
;\\}
\forward match =+ x, arg \\{ add base, x \\}
match =- x, arg \\{ sub base, x \\}
;match =:=~ x, arg \\{ shl base, x \\}
match "(", arg \\{ push base \\}
match ")", arg \\{ pop base \\}
match "{(", arg \\{ local .lb
.lb: push base
get_lb equ .lb
display "{"
\\}
match ")}", arg \\{ pop base
dec base
;test base, base
jnz get_lb
restore get_lb
display "}"
\\}
match "{", arg \\{ local .lb
.lb:
get_lb equ .lb
display "{"
\\}
match "}", arg \\{ test base, base
jnz get_lb
restore get_lb
display "}"
\\}
match "vec4" x, arg \\{ irpEqsVec4 equ x
x\\#\\_type equ 'vec4'
;display x_type
\\}
match "ivec" x, arg \\{ irpEqsIVec equ x
x\\#\\_type equ 'int'
;display x_type
\\}
match ">" x, arg \\{ display '>'
shr base, x \\}
match "<" x, arg \\{ shl base, x \\}
match ":" x, arg \\{ x: x\\#\\_type equ 'label' \\}
match "!0": x, arg \\{ test base, base
jz x \\}
match "!0", arg \\{ test base, base
jz @f \\}
match "!>0": x, arg \\{ test base, base
jnz x \\}
match "to", arg \\{ ;display 'to;'
mov [GetBufr],base \\}
match "to": x, arg \\{ ;display 'to2;'
mov x,base \\}
match #:x , arg \\{ x equ base \\}
match : , arg \\{ mov base, [base] \\}
match '(do)' , arg \\{ push base
call base
pop base
\\}
match '(do)': x, arg \\{ push base
call dword x
pop base
\\}
match 'do' , arg \\{ call base \\}
match 'do': x, arg \\{ call dword x \\}
match 'ptR'x:z, arg \\{ mov x,[z]
add z,GetptrR
\\}
match 'ptW'x:z, arg \\{ mov [z],x
add z,GetptrW
\\}
match 'ptR_'x:z, arg \\{ mov x,[z] \\}
match 'ptW_'x:z, arg \\{ mov [z],x \\}
match =* x , arg \\{ x base \\}
\}
if ~ args eq
forward mGetArg args
common end if
purge mGetArg
@@:
}
macro xmops h,c {
if h eqtype 0.0
mov eax,h
movd xmm7,eax
c xmm0,xmm7
end if
if h eqtype [0]
c xmm0,h
end if
if h eqtype 0
c xmm0,xmm#h
end if
}
macro prim xm,a,[op,b] { common
if a eqtype 0.0
mov eax,a
movd xmm0,eax
end if
if a eqtype [0]
movss xmm0,a
end if
forward
match =* ,op \{ xmops b, mulss \}
match =/ ,op \{ xmops b, divss \}
match =- ,op \{ xmops b, subss \}
match =+ ,op \{ xmops b, addss \}
common
if xm > 0
movss xmm#xm,xmm0
end if
}
macro primem xm,a,[reyy] { common
if a eqtype 0.0
mov eax,a
movd xmm0,eax
end if
if a eqtype [0]
movss xmm0,a
end if
forward
match e b , reyy \{
match =* ,e \\{ xmops b, mulss \\}
match =/ ,e \\{ xmops b, divss \\}
match =- ,e \\{ xmops b, subss \\}
match =+ ,e \\{ xmops b, addss \\}
\}
common
match xx== ,xm \{
;display 'hoho;'
movss [xx],xmm0
\}
}
Last edited by Roman on 07 Aug 2025, 05:31; edited 4 times in total
|