diff options
author | Rangi <remy.oukaour+rangi42@gmail.com> | 2021-03-03 22:22:41 -0500 |
---|---|---|
committer | Rangi <remy.oukaour+rangi42@gmail.com> | 2021-03-04 00:15:03 -0500 |
commit | 40902ffe244544d638567642e4e01b9c5801db23 (patch) | |
tree | 4abf9ac20786fdf66bb298b3ec7935cef2c71d07 /macros/asserts.asm | |
parent | 9c17fb14c8068d6662b9ca1cb048ed206b6770ee (diff) |
Verify data table sizes with table_width and assert_table_length macros
This was discussed in #706
It also uncovered some off-by-one issues with defining some constants.
A few structs now use rsreset/_RS to define their offset constants, as discussed in #739
Diffstat (limited to 'macros/asserts.asm')
-rw-r--r-- | macros/asserts.asm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/macros/asserts.asm b/macros/asserts.asm new file mode 100644 index 000000000..e045e2f56 --- /dev/null +++ b/macros/asserts.asm @@ -0,0 +1,20 @@ +; Macros to verify assumptions about the data or code + +table_width: MACRO +CURRENT_TABLE_WIDTH = \1 +if DEF(CURRENT_TABLE_START) +PURGE CURRENT_TABLE_START +endc +if _NARG == 2 +CURRENT_TABLE_START EQUS "\2" +else +CURRENT_TABLE_START EQUS "._table_width\@" +CURRENT_TABLE_START: +endc +ENDM + +assert_table_length: MACRO +x = \1 + assert x * CURRENT_TABLE_WIDTH == @ - CURRENT_TABLE_START, \ + "{CURRENT_TABLE_START}: expected {d:x} entries, each {d:CURRENT_TABLE_WIDTH} bytes" +ENDM |