From 1084b7d266e4c6c278d7f08469010fce545bdf4d Mon Sep 17 00:00:00 2001 From: alex-eg Date: Tue, 29 Sep 2026 21:05:52 +0300 Subject: [PATCH] add static-assert to sex Expands to C11 _Static_assert keyword --- fmt-c-writer.scm | 1 + tests/codegen.scm | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fmt-c-writer.scm b/fmt-c-writer.scm index c881ae0..570ec0d 100644 --- a/fmt-c-writer.scm +++ b/fmt-c-writer.scm @@ -114,6 +114,7 @@ forms, and what remains." ((attribute) '%attribute) ((ยค) 'vector-ref) ((include) '%include) + ((static-assert) '_Static_assert) ;; a `|' inside a symbol has to be escaped to be written in ;; a Scheme source, so we just rename it in fmt-c compatible ;; way diff --git a/tests/codegen.scm b/tests/codegen.scm index 2b94fe4..f43a255 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -259,4 +259,15 @@ compiles." "/* A 2D point. */")) (test-assert "and an enum docstring too" (emits? "(enum color \"RGB.\" (red green blue))" - "/* RGB. */")))) + "/* RGB. */"))) + + ;; `static-assert' is the keyword rather than the macro, so + ;; a static assertion costs no include. Mapped in `atom-to-fmt-c' + ;; because `unkebabify' alone would spell it `static_assert'. + (test-group "static-assert" + (test-assert "emits the C11 keyword" + (emits? (in-fn "(static-assert (== (sizeof int) 4) \"int is four bytes\")") + "_Static_assert(sizeof(int) == 4, \"int is four bytes\")")) + (test-assert "and not the header macro" + (not (emits? (in-fn "(static-assert (== (sizeof int) 4) \"x\")") + "static_assert(")))))