promote the prelude's integer types like C's own

u8 and i32 are typedefs of <stdint.h> names nothing parses, so they had
no rank: (+ a a) over two u8 200s was a u8 holding 144, and (+ n 1) over
an i32 could not be typed at all.
This commit is contained in:
2026-10-16 13:54:41 +03:00
parent 6d84553652
commit 5cd931cb4e
3 changed files with 25 additions and 3 deletions

View File

@@ -11,6 +11,7 @@
"partial: 1 2.5"
"joined: 43.5 84 49 1"
"promoted: 200 60000 3705032704"
"prelude: 400 6"
"from elements: 4 9 0")
(return 0)
@@ -105,6 +106,14 @@
(var unpromoted _ (+ kept kept))
(printf "promoted: %d %d %u\n" narrow narrower unpromoted)
;; the prelude's widths are C's own types under other names, and
;; promote the way those do
(var b8 u8 200)
(var w32 i32 5)
(var bytes _ (+ b8 b8))
(var next _ (+ w32 1))
(printf "prelude: %d %d\n" bytes next)
;; a brace initializer has no type of its own, but its elements solve
;; the hole in the array type around it -- and the length stays as
;; written, whether or not every slot is initialized

View File

@@ -42,14 +42,17 @@
#f
(get-fields 't-color))
(add-typedef 't-u8 '(typedef t-u8 uint8-t))
(add-typedef 't-u8 '(typedef t-u8 gl-ubyte))
(test "a typedef resolves to its target"
'uint8-t
'gl-ubyte
(get-underlying-type 't-u8))
(add-typedef 't-byte '(typedef t-byte t-u8))
(test "and chains are followed to the end"
'uint8-t
'gl-ubyte
(get-underlying-type 't-byte))
(test "stdint.h's exact-width types are C's own"
'(unsigned char)
(get-underlying-type 'uint8-t))
(test "a struct is not a typedef"
#f
(get-underlying-type 't-point))