From 82629867c1285f597f539a3172efa20e1a3c3dfc Mon Sep 17 00:00:00 2001 From: alex-eg Date: Fri, 9 Oct 2026 15:56:32 +0300 Subject: [PATCH] spell an array bound as an expression It went to fmt-c unwalked, so a bound named CHUNK-AREA kept its dash while the same name in an expression became CHUNK_AREA. Fixes #50. --- fmt-c-writer.scm | 2 +- tests/codegen.scm | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fmt-c-writer.scm b/fmt-c-writer.scm index 0ded714..cd8545f 100644 --- a/fmt-c-writer.scm +++ b/fmt-c-writer.scm @@ -316,7 +316,7 @@ forms, and what remains." (match form (('¤ . array-type) (if (array-bound? form) - `(%array ,(walk-type (array-element-type form)) ,(last array-type)) + `(%array ,(walk-type (array-element-type form)) ,(walk-expr (last array-type))) ;; sugar for pointer... Do we really need it? Guess why not, ;; it's a strong semantic cue `(%array ,(walk-type (array-element-type form))))) diff --git a/tests/codegen.scm b/tests/codegen.scm index 2a1edd3..67d7fb1 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -678,6 +678,11 @@ compiles." (emits? "(define N 4) (struct s ((a (¤ char (* 2 N)))))" "char a[2 * N]")) (test-assert "an integer bound still works" (emits? "(struct s ((a (¤ int 4))))" "int a[4]")) + ;; ...and it is spelled the way the same name is in an expression + (test-assert "a bound's name is converted" + (emits? (in-fn "(var xs (¤ u16 CHUNK-AREA))") "u16 xs[CHUNK_AREA]")) + (test-assert "so is one inside an expression bound" + (emits? (in-fn "(var xs (¤ u16 (* 2 CHUNK-AREA)))") "u16 xs[2 * CHUNK_AREA]")) ;; a multi-word type is keywords all the way down, so a trailing ;; keyword belongs to the type and leaves the array unsized (test-assert "a multi-word type is not a bound"