
; push eax, ebx, ecx
%imacro push 1-*
	%rep %0
		push %1
		%rotate 1
	%endrep
%endmacro

; pop off in the same textual order as you pushed on.
; pop eax, ebx, ecx
%imacro pop 1-*
	%rep %0
		%rotate -1
		pop %1
	%endrep
%endmacro

; call my_method, eax, ebx, ecx
%macro ccall 2-*
	%rotate 1
	%rep %0-1
		push %1
		%rotate 1
	%endrep
	call %1
%endmacro

; call my_method, eax, ebx, ecx
%macro pcall 2-*
	%rep %0-1
		%rotate -1
		push %1
	%endrep
	%rotate -1
	call %1
%endmacro

; cret ge
%macro cret 1
	j%-1 %%skip
	ret
	%%skip:
%endmacro

; currently broken - requires passing arguments regardless of " characters
; import idt, isr, irq
%macro import 1-*
	%rep %0
		%ifndef %1
			%define %1
			%include "%{1}.asm"
		%endif
		%rotate 1
	%endrep
%endmacro

; do
%macro do 0
	%push repeat
	align 4
	%$begin:
%endmacro

; credo le
%macro credo 1
	j%-1 %$out
	jmp %$begin
	%$out:
	%pop
%endmacro

; while le
%macro while 1
	%push while
	align 4
	%$begin:
	j%-1 %$out
%endmacro

; if le
%macro if 1
	%push if
	j%-1 %$ifnot
%endmacro

%macro else 0
	%ifctx if
		%repl else
		jmp %$ifend
		%$ifnot:
	%else
		%error "expected 'if' before 'else'"
	%endif
%endmacro

; end an if/else or while block
%imacro end 0
	%ifctx while
		jmp %$begin
		%$out:
		%pop
	%elifctx if
		%$ifnot:
		%pop
	%elifctx else
		%$ifend:
		%pop
	%else
		%error "expected 'if', 'while', or something before 'end'"
	%endif
%endmacro
