1
0
forked from alex-eg/sex

space toplevel forms the way the source does

Every toplevel form was followed by a blank line whether or not one
was written, so the prelude's run of typedefs arrived at twice the
height. A function had no location of its own to measure from either,
having lost it where its header and body are stitched together.
This commit is contained in:
2026-10-05 02:08:15 +03:00
parent 7f3f22e853
commit 95f39e4b44
8 changed files with 72 additions and 25 deletions

View File

@@ -633,4 +633,18 @@ compiles."
(test-assert "nor is an aggregate tag"
(emits? "(struct t ((z int))) (struct s ((a (¤ struct t))))" "struct t a[]"))
(test-assert "nor one behind a pointer"
(emits? "(struct t ((z int))) (struct s ((a (¤ * struct t))))" "struct t* a[]"))))
(emits? "(struct t ((z int))) (struct s ((a (¤ * struct t))))" "struct t* a[]")))
;; Toplevel forms used to be separated by a blank line unconditionally,
;; which spread a block of adjacent typedefs over twice the lines its
;; author wrote
(test-group "vertical spacing"
(test-assert "adjacent forms stay adjacent"
(emits? "(include a.h)\n(include b.h)" "#include <a.h>\n#include <b.h>"))
(test-assert "a blank line is kept"
(emits? "(include a.h)\n\n(include b.h)" "#include <a.h>\n\n#include <b.h>"))
;; the gap is measured from where the form ended, not where it began
(test-assert "a multi-line form does not invent one"
(emits? "(struct s\n ((x int)))\n(include b.h)" "};\n#include <b.h>"))
(test-assert "nor swallows one"
(emits? "(struct s\n ((x int)))\n\n(include b.h)" "};\n\n#include <b.h>"))))

View File

@@ -97,7 +97,7 @@
(define (compile-to-c source)
"Run reader -> semen -> writer on SOURCE, returning the generated C.
parse-all is called directly rather than through read-raw-forms so the
fixture can be given a file name: a location is (file . line), and the
fixture can be given a file name: a location carries one, and the
file is what makes an imported module report itself rather than the unit
that imported it."
(let ((forms (with-input-from-string source