; vim: ft=fasm :
macro dup 
{
        sub esi,4
        mov [esi],eax
}
macro drop { lodsd }
macro upsh a
{
	dup
	mov eax, a
}
macro upop a
{
	mov a, eax
	drop
}
; ; Multiple push/pop
; ;	push eax,ebx,ecx...
; ;	pop eax,ebx,ecx...
; 
; %macro push 1-*.nolist
; %rep %0
; 	push dword %1
; %rotate 1
; %endrep
; %endmacro
; 
; %macro pop 1-*.nolist
; %rep %0
; %rotate -1
; 	pop dword %1
; %endrep
; %endmacro
; %macro variable 2
;        call dovar
;        %1 dd %2
; %endmacro
; %macro swap 0
;        xchg eax,[esi]
; %endmacro
; %macro nip 0
;        add esi,byte 4
; %endmacro
; 
; %macro embed 1
;    upsh %%e1
;    upsh [%%e2]
;    call eval	
;    jmp short %%e3
; %%e1 db %1
; %%e2 dd $-%%e1
; %%e3
; %endmacro
macro embed str
{
	local e1,e2,e3
	upsh e1
	upsh [e2]
	call eval
	jmp e3
	e1: db str
	e2: dd ($-e1)
	e3:
}
; 
; 
macro next { ret }
; %macro next 0
;        ret
; %endmacro
; 
; ;-------------------------------------------------------------------------
; ; Dictionary Macros (based on IsForth's)
; 
; %xdefine vlink 0            ;link to previous word in vocabulary
; %xdefine forth_link 0       ;link to previous word in forth vocab
; %xdefine macro_link 0       ;link to previous word in compiler vocab
; %xdefine voc 0              ;currently linking to forth vocabulary

; 
; %macro header 2.nolist
; %%link:
;  dd vlink                   ;link to previous word in vocabulary
;  dd %2                      ;pointer to cfa (in .text section)
;  db (%%name-$-1)            ;name length + flags
;  db %1                      ;name
; %%name:
; %xdefine vlink %%link
; __SECT__
;  forth                      ;Switch back to 'forth' vocab!!!
; %endmacro
macro countedstring str 
{
	local endofstring
	db (endofstring - $)
	db str
	endofstring = ($ - 1)
}


; 
; Usage: code 'forth-name', asm-name
; %macro code 2.nolist
;  header %1,%2               ;create header in head space
; %2:                         ;make label for new coded definition
; %endmacro
vlink equ 0
forth_link equ 0       ;link to previous word in forth vocab
macro_link equ 0       ;link to previous word in forth vocab
voc  equ 0       ;link to previous word in forth vocab

macro code a,b
{
local c
label c
	dd vlink	; link to previous word in vocab
	vlink equ c
	dd b		; ptr to CFA (.text)
	countedstring a
label	b
forth
}
; 
; 
; ; Usage: var 'name',name,value
; %macro var 3.nolist
;  code %1, ?%2
;  call dovar
;  %2 dd %3
; %endmacro
macro var qname,nm,value
{
	local aname
	code qname,aname
	call dovar
	nm dd value
}

macro forth
{
   forth_link equ vlink
   vlink equ forth_link
   voc equ 0
}

macro fmacro
{
   forth_link equ vlink
   vlink equ macro_link
   voc equ 1
}
