keep an array literal a global pointer is set to

At file scope every compound literal was cut down to its braces, right
for a value and not for an array a pointer points at: the address of a
static object is a constant, and its braces alone the pointer's own.
This commit is contained in:
2026-10-17 17:35:48 +03:00
parent 42c76d07e6
commit 32515c0eb8
3 changed files with 75 additions and 12 deletions

View File

@@ -1061,7 +1061,24 @@
(test-assert "ahead of it"
(let ((c (sex->c "(var f (fn ((x int)) int) (lambda ((x int)) int (return x)))")))
(< (string-contains c "static int λ0_f (int x)")
(string-contains c "(*f)(int) = λ0_f")))))
(string-contains c "(*f)(int) = λ0_f"))))
;; every compound literal lost its type at file scope, which is right
;; for a value and not for an array a pointer is set to: that is the
;; address of a static object, and its braces alone the pointer's own
(test-assert "an array a pointer is set to keeps its type"
(emits? "(var gp (* int) #([int 3] : 1 2 3))" "int * gp = (int [3]){1, 2, 3}"))
(test-assert "in a field named for it"
(emits? (string-append "(struct h ((p (* int)) (n int)))"
"(var g (struct h) #(.p #([int 2] : 1 2) .n 3))")
"{.p = (int [2]){1, 2}, .n = 3}"))
(test-assert "or one in its place"
(emits? (string-append "(struct h ((n int) (p (* int))))"
"(var g (struct h) #((struct h) : 3 #([int 2] : 1 2)))")
"{3, (int [2]){1, 2}}"))
(test-assert "while a value is still its braces"
(emits? (string-append "(struct pt ((x int))) (struct h2 ((a (struct pt))))"
"(var g (struct h2) #(#((struct pt) : 1)))")
"h2 g = {{1}}")))
;; fmt-c kept the first star after a tag and dropped what followed it,
;; and took an enum's star for its list of values