diff --git a/fmt-c-writer.scm b/fmt-c-writer.scm index 56ad82d0..d787e176 100644 --- a/fmt-c-writer.scm +++ b/fmt-c-writer.scm @@ -492,6 +492,9 @@ forms, and what remains." ((or ('struct . _) ('union . _)) (walk-struct form)) (('enum . _) (walk-enum form)) + ;; A target is a filename and not an identifier: GL/gl.h is a path, + ;; and unkebabify would spell it GLːgl.h + (('include target) (list '%include target)) (('define name . rest) `(%define ,(atom-to-fmt-c name) ,@rest)) (else (walk-expr form)))) diff --git a/tests/codegen.scm b/tests/codegen.scm index fdb3412d..a456674c 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -394,6 +394,16 @@ compiles." (fn f ((c (closure ((int)) int))) int (return (g c)))" "g(c)"))) + ;; An include target is a path, so none of the identifier mangling + ;; applies to it: GL/gl.h is a file and GLːgl.h is not. + (test-group "include targets are paths" + (test-assert "a slash survives" + (emits? "(include SDL3/SDL.h)" "#include ")) + (test-assert "and so does a dash" + (emits? "(include my-header.h)" "#include ")) + (test-assert "pub include emits the same" + (emits? "(pub include GL/gl.h)" "#include "))) + ;; The walker offered WALK-FN the cdr of every form as well as the ;; form, so the tail (t) of (fn g () t) read as a call to a macro ;; named t, and any function returning a type that shared a name