Make the comma after assert warn/fail/fatal optional (#2160)

Co-authored-by: Eldred Habert <[email protected]>
This commit is contained in:
RangiandEldred Habert authored and GitHub committed 2026-09-26 19:55:35 +02:00
1 parent e8422c1c88
commit f1e530ac39
5 files changed
+101 -7

No files matched your search

+11 -4
View File
@@ -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
+3 -3
View File
@@ -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;
}
;
+24
View File
@@ -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
+42
View File
@@ -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)
+21
View File
@@ -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...