From c483b81f1c2334dece5f0bb989506b5394998cc2 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Thu, 30 Oct 2025 12:24:38 +0300 Subject: [PATCH] replace fold-right append with flatten in type-convert-to-c They are not equivalent, but it'll be allright in this case. Probably. Passes tests at least. --- fmt-c-writer.scm | 6 +++--- tests/fmt-c-writer.scm | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/fmt-c-writer.scm b/fmt-c-writer.scm index 6f3feb9..a9abd9b 100644 --- a/fmt-c-writer.scm +++ b/fmt-c-writer.scm @@ -145,9 +145,9 @@ (if (atom? type) (atom-to-fmt-c type) (flatten (tree-map atom-to-fmt-c - (fold-right append (list) - (list-join (reverse (list-split type '*)) - '(*))))))) + (flatten + (list-join (reverse (list-split type '*)) + '(*))))))) (define (walk-fn-def form) (match form diff --git a/tests/fmt-c-writer.scm b/tests/fmt-c-writer.scm index f606276..ba103c1 100644 --- a/tests/fmt-c-writer.scm +++ b/tests/fmt-c-writer.scm @@ -47,6 +47,27 @@ '(%fun void ((int) (%array float) (%array (struct what * const)))) (walk-type '(fn ((int) (¤ float) (¤ (const * struct what))) void))) + (test + '(%array (%fun void ((int) (%array float) (%array (struct what * const))))) + (walk-type '(¤ (fn ((int) (¤ float) (¤ (const * struct what))) void)))) + + ;; Type convert to C + (test + '(int) + (type-convert-to-c '(int))) + + (test + '(* int) + (type-convert-to-c '(int *))) + + (test + '(* const int) + (type-convert-to-c '(const int *))) + + (test + '(const * const char) + (type-convert-to-c '(const char * const))) + ;;; Variable defs (test '(%var (%array float 8) a)