write number literals the way C reads them

A C suffix was no number to string->number, so 1u and 1.5f became
symbols, and C got them inside the |pipes| CHICKEN writes those with.
They read now into a literal that prints its C spelling and is typed by
its suffix: an integer in decimal, so 0b101u needs no C23, and a float
in the digits it was written with, since through a double 0.1f could
round to another float and 0.1L would lose what it has over one.

Scheme also reads numbers C has none of. 1/2 reached C as integer
division and +inf.0 as no C at all; those, and integers past 64 bits,
are read errors now. An integer is typed by size as well, so 4000000000
is no longer an int, and one past long long gets the u C would
otherwise only warn about.
This commit is contained in:
2026-10-16 14:40:26 +03:00
parent 5df6adc4ff
commit 92f676d4b5
5 changed files with 203 additions and 5 deletions

View File

@@ -759,6 +759,22 @@
(test-assert "sixteen when that is enough"
(emits? (in-fn "(var d double 0.9871465422297019)") "d = 0.9871465422297019;")))
;; A suffix is C's, and reached C inside |pipes|, the way CHICKEN
;; writes a symbol that starts with a digit
(test-group "suffixed literals"
(test-assert "an integer keeps its suffix"
(emits? (in-fn "(var n (unsigned long long) 1ULL)") "n = 1ULL;"))
(test-assert "and is written in decimal, which C11 has a suffix for"
(emits? (in-fn "(var n (unsigned int) 0b101u)") "n = 5u;"))
(test-assert "a float keeps its digits, which a double would round"
(emits? (in-fn "(var x (long double) 3.14159265358979323846264338327950288L)")
"x = 3.14159265358979323846264338327950288L;"))
(test-assert "a minus is C's own"
(emits? (in-fn "(var n (unsigned int) -1u)") "n = -1u;"))
(test-assert "a number too wide for long long is unsigned, and says so"
(emits? (in-fn "(var n (unsigned long long) 0xFFFFFFFFFFFFFFFF)")
"n = 18446744073709551615u;")))
;; A define's body was pasted unwalked, and unparenthesised: `cast'
;; stayed a call, and (* x D) regrouped with D's own operator
(test-group "defines"