Macro:
Code:
Usage:
Code:
NAME can be ommitted to put the enumerators in the global namespace.
Code:
macro enum? enumeration
local next
next = 0
match any, enumeration
struc (enumerator) ? value := next, empty
assert ~lengthof `empty
namespace enumeration
enumerator :value
next = enumerator + 1
enumeration equ enumerator
end namespace
end struc
else
struc ? value := next, empty
assert ~lengthof `empty
. :value
next = . + 1
end struc
end match
macro end?.enum?!
restruc ?
purge end?.enum?
end macro
end macro
Usage:
Code:
enum NAME
VALUE0
VALUE1
VALUE3 = 3
VALUE4
VAL1 = VALUE1
end enum
db NAME.VALUE0, NAME.VALUE1, NAME.VALUE3, NAME.VALUE4, NAME.VAL1 ; same as db 0, 1, 3, 4, 1
irpv each, NAME
db `each, each
end irpv ; same as db 'VALUE0', 0, 'VALUE1', 1, 'VALUE3', 3, 'VALUE4', 4, 'VAL1', 1
NAME can be ommitted to put the enumerators in the global namespace.