From f1e530ac397ece0b21e443a876309eed586fc65f Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Sat, 26 Sep 2026 13:55:35 -0400 Subject: [PATCH] Make the comma after `assert warn/fail/fatal` optional (#2160) Co-authored-by: Eldred Habert --- man/rgbasm.5 | 15 ++++++++++---- src/asm/parser.y | 6 +++--- test/asm/assert-comma.asm | 24 ++++++++++++++++++++++ test/asm/assert-comma.err | 42 +++++++++++++++++++++++++++++++++++++++ test/asm/assert-comma.out | 21 ++++++++++++++++++++ 5 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 test/asm/assert-comma.asm create mode 100644 test/asm/assert-comma.err create mode 100644 test/asm/assert-comma.out diff --git a/man/rgbasm.5 b/man/rgbasm.5 index c601953b..d4531a38 100644 --- a/man/rgbasm.5 +++ b/man/rgbasm.5 @@ -2529,16 +2529,16 @@ assert FirstByte + 1 == SecondByte STATIC_ASSERT .end - Function < 256, "Function is too large!" .Ed .Pp -First, the difference between +An .Ic ASSERT -and +is evaluated by RGBASM if it can, otherwise by RGBLINK; but a .Ic STATIC_ASSERT -is that the former is evaluated by RGBASM if it can, otherwise by RGBLINK; but the latter is only ever evaluated by RGBASM. +that RGBASM cannot evaluate will raise an error. If RGBASM cannot compute the value of the argument to .Ic STATIC_ASSERT , it will produce an error. .Pp -Second, as shown above, a string can be optionally added at the end, to give insight into what the assertion is checking. +As shown above, a message string can be optionally added as the last argument, to give insight into what the assertion is checking. .Pp Finally, you can add one of .Ic WARN , FAIL @@ -2559,6 +2559,13 @@ to be emitted; (the default) will cause a non-fatal error; and .Ic FATAL immediately aborts. +The comma after this argument is optional; so for example, +.Ql ASSERT WARN n == 2 , +.Ql ASSERT WARN, n == 2 , +.Ql ASSERT WARN n == 2, "n != 2" , +and +.Ql ASSERT WARN, n == 2, "n != 2" +are all valid. .Sh MISCELLANEOUS .Ss Changing options while assembling .Ic OPT diff --git a/src/asm/parser.y b/src/asm/parser.y index 44a55d80..16fbe9c2 100644 --- a/src/asm/parser.y +++ b/src/asm/parser.y @@ -752,13 +752,13 @@ assert_type: %empty { $$ = ASSERT_ERROR; } - | POP_WARN COMMA { + | POP_WARN trailing_comma { $$ = ASSERT_WARN; } - | POP_FAIL COMMA { + | POP_FAIL trailing_comma { $$ = ASSERT_ERROR; } - | POP_FATAL COMMA { + | POP_FATAL trailing_comma { $$ = ASSERT_FATAL; } ; diff --git a/test/asm/assert-comma.asm b/test/asm/assert-comma.asm new file mode 100644 index 00000000..4b1756dc --- /dev/null +++ b/test/asm/assert-comma.asm @@ -0,0 +1,24 @@ +def n = 0 +for i_type, 5 + redef type equs strslice(" warn fail warn,fail,", i_type * 5, (i_type + 1) * 5) + for i_message, 2 + redef message equs ", \"hello {d:n}\"" + redef message equs strslice(#message, 0, i_message * strlen(#message)) + for cond, 2 + redef line equs "assert {type} {cond} {message}" + println "[static_]{line}" + {line} + static_{line} + def n += 1 + endr + endr +endr + +println "[static_]assert fatal..." +assert fatal 1 +assert fatal 1, "goodbye 0" +static_assert fatal 1 +static_assert fatal 1, "goodbye 0" + +assert fatal 0 +assert fatal 0, "goodbye 1" ; not reached diff --git a/test/asm/assert-comma.err b/test/asm/assert-comma.err new file mode 100644 index 00000000..f40ab3e7 --- /dev/null +++ b/test/asm/assert-comma.err @@ -0,0 +1,42 @@ +error: Assertion failed + at assert-comma.asm::REPT~1::REPT~1::REPT~1(10) <- assert-comma.asm::REPT~1::REPT~1(7) <- assert-comma.asm::REPT~1(4) <- assert-comma.asm(2) +error: Assertion failed + at assert-comma.asm::REPT~1::REPT~1::REPT~1(11) <- assert-comma.asm::REPT~1::REPT~1(7) <- assert-comma.asm::REPT~1(4) <- assert-comma.asm(2) +error: Assertion failed: hello 2 + at assert-comma.asm::REPT~1::REPT~2::REPT~1(10) <- assert-comma.asm::REPT~1::REPT~2(7) <- assert-comma.asm::REPT~1(4) <- assert-comma.asm(2) +error: Assertion failed: hello 2 + at assert-comma.asm::REPT~1::REPT~2::REPT~1(11) <- assert-comma.asm::REPT~1::REPT~2(7) <- assert-comma.asm::REPT~1(4) <- assert-comma.asm(2) +warning: Assertion failed [-Wassert] + at assert-comma.asm::REPT~2::REPT~1::REPT~1(10) <- assert-comma.asm::REPT~2::REPT~1(7) <- assert-comma.asm::REPT~2(4) <- assert-comma.asm(2) +warning: Assertion failed [-Wassert] + at assert-comma.asm::REPT~2::REPT~1::REPT~1(11) <- assert-comma.asm::REPT~2::REPT~1(7) <- assert-comma.asm::REPT~2(4) <- assert-comma.asm(2) +warning: Assertion failed: hello 6 [-Wassert] + at assert-comma.asm::REPT~2::REPT~2::REPT~1(10) <- assert-comma.asm::REPT~2::REPT~2(7) <- assert-comma.asm::REPT~2(4) <- assert-comma.asm(2) +warning: Assertion failed: hello 6 [-Wassert] + at assert-comma.asm::REPT~2::REPT~2::REPT~1(11) <- assert-comma.asm::REPT~2::REPT~2(7) <- assert-comma.asm::REPT~2(4) <- assert-comma.asm(2) +error: Assertion failed + at assert-comma.asm::REPT~3::REPT~1::REPT~1(10) <- assert-comma.asm::REPT~3::REPT~1(7) <- assert-comma.asm::REPT~3(4) <- assert-comma.asm(2) +error: Assertion failed + at assert-comma.asm::REPT~3::REPT~1::REPT~1(11) <- assert-comma.asm::REPT~3::REPT~1(7) <- assert-comma.asm::REPT~3(4) <- assert-comma.asm(2) +error: Assertion failed: hello 10 + at assert-comma.asm::REPT~3::REPT~2::REPT~1(10) <- assert-comma.asm::REPT~3::REPT~2(7) <- assert-comma.asm::REPT~3(4) <- assert-comma.asm(2) +error: Assertion failed: hello 10 + at assert-comma.asm::REPT~3::REPT~2::REPT~1(11) <- assert-comma.asm::REPT~3::REPT~2(7) <- assert-comma.asm::REPT~3(4) <- assert-comma.asm(2) +warning: Assertion failed [-Wassert] + at assert-comma.asm::REPT~4::REPT~1::REPT~1(10) <- assert-comma.asm::REPT~4::REPT~1(7) <- assert-comma.asm::REPT~4(4) <- assert-comma.asm(2) +warning: Assertion failed [-Wassert] + at assert-comma.asm::REPT~4::REPT~1::REPT~1(11) <- assert-comma.asm::REPT~4::REPT~1(7) <- assert-comma.asm::REPT~4(4) <- assert-comma.asm(2) +warning: Assertion failed: hello 14 [-Wassert] + at assert-comma.asm::REPT~4::REPT~2::REPT~1(10) <- assert-comma.asm::REPT~4::REPT~2(7) <- assert-comma.asm::REPT~4(4) <- assert-comma.asm(2) +warning: Assertion failed: hello 14 [-Wassert] + at assert-comma.asm::REPT~4::REPT~2::REPT~1(11) <- assert-comma.asm::REPT~4::REPT~2(7) <- assert-comma.asm::REPT~4(4) <- assert-comma.asm(2) +error: Assertion failed + at assert-comma.asm::REPT~5::REPT~1::REPT~1(10) <- assert-comma.asm::REPT~5::REPT~1(7) <- assert-comma.asm::REPT~5(4) <- assert-comma.asm(2) +error: Assertion failed + at assert-comma.asm::REPT~5::REPT~1::REPT~1(11) <- assert-comma.asm::REPT~5::REPT~1(7) <- assert-comma.asm::REPT~5(4) <- assert-comma.asm(2) +error: Assertion failed: hello 18 + at assert-comma.asm::REPT~5::REPT~2::REPT~1(10) <- assert-comma.asm::REPT~5::REPT~2(7) <- assert-comma.asm::REPT~5(4) <- assert-comma.asm(2) +error: Assertion failed: hello 18 + at assert-comma.asm::REPT~5::REPT~2::REPT~1(11) <- assert-comma.asm::REPT~5::REPT~2(7) <- assert-comma.asm::REPT~5(4) <- assert-comma.asm(2) +FATAL: Assertion failed + at assert-comma.asm(23) diff --git a/test/asm/assert-comma.out b/test/asm/assert-comma.out new file mode 100644 index 00000000..7ee8d137 --- /dev/null +++ b/test/asm/assert-comma.out @@ -0,0 +1,21 @@ +[static_]assert $0 +[static_]assert $1 +[static_]assert $0 , "hello 2" +[static_]assert $1 , "hello 2" +[static_]assert warn $0 +[static_]assert warn $1 +[static_]assert warn $0 , "hello 6" +[static_]assert warn $1 , "hello 6" +[static_]assert fail $0 +[static_]assert fail $1 +[static_]assert fail $0 , "hello 10" +[static_]assert fail $1 , "hello 10" +[static_]assert warn, $0 +[static_]assert warn, $1 +[static_]assert warn, $0 , "hello 14" +[static_]assert warn, $1 , "hello 14" +[static_]assert fail, $0 +[static_]assert fail, $1 +[static_]assert fail, $0 , "hello 18" +[static_]assert fail, $1 , "hello 18" +[static_]assert fatal...