Skip to content

Instantly share code, notes, and snippets.

@bitRAKE
Created April 13, 2025 17:10
Show Gist options
  • Save bitRAKE/b4a8b60e63cf09c372fc3a9c94328f31 to your computer and use it in GitHub Desktop.
Save bitRAKE/b4a8b60e63cf09c372fc3a9c94328f31 to your computer and use it in GitHub Desktop.
#pragma once, for fasmg / fasm2:
; We can make a global "#pragma once" mechanism if we assume all files have
; a unique path. Non-cannonical path are fine as long as it's always the same
; form. Be mindful of file organization if you're going to use this.
; Primary benefits:
; + files are not loaded multiple times
; + no change to file needed (i.e. if/endif wrapper)
;macro onetime?: line&
; local name
; match any rest,line
; name equ any
; else match any,line
; name equ any
; else
; err
; end match
;
; repeat 1,N:name
; if ~ definite ONCE.N
; ONCE.N := 1
; include line
; end if
; end repeat
;end macro
calminstruction onetime?: line*&
match name any?,line
jyes go
err 'filename expected'
done: exit
local val,var
go: compute val,+name ; convert string to number
arrange var,=ONETIME.val ; unique variable
check definite var
jyes done
compute val,0
publish var:,val ; constant
arrange line,=include line
assemble line
end calminstruction
@bitRAKE
Copy link
Author

bitRAKE commented Apr 15, 2025

We can replace the include keyword with this feature:

macro include?.enable? chain
	chain
	calminstruction include? file*, head
		local val,var
		compute val,+file		; convert string to number
		arrange var,=INCLUDE.val	; unique variable
		check definite var
		jyes skip

		compute val,0
		publish var:,val		; constant

		arrange line,=include file,=include?.=enable? head
		assemble line
		arrange line,=purge =include?
		assemble line
	skip:
	end calminstruction
end macro
include?.enable?

... based on the fix.inc macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment