1
0
forked from alex-eg/sex

tell an array's bound by the shape of its type

Whether a trailing name was the bound hinged on the word before it
being a typedef Sex had seen, which a header's pthread_t never is, and
a grouped (* T) never is either: [pthread-t N] became a two-word type.

Fixes #56, #60.
This commit is contained in:
2026-10-09 15:55:33 +03:00
parent 8bc27cba26
commit dfdca46e1e
5 changed files with 41 additions and 23 deletions

View File

@@ -5,6 +5,7 @@
"through a pointer: 55"
"unsized of a typedef: 1 2"
"unsized of a pointer: 5"
"named bound: 2 4 b"
"unnamed parameters: 7 -1 2")
(return 0)
@@ -22,6 +23,8 @@
(typedef small int)
(define CAP 2)
;;; a parameter that names nothing is a type, however many words it
;;; takes: `(unsigned int)' is one of them, not a `unsigned' called
;;; `int'
@@ -65,6 +68,13 @@
(var w _ (¤ sizes 0))
(printf "unsized of a pointer: %d\n" (cast (* w) int))
;; ...but after a whole type, a name is: `size-t' is a typedef only C
;; knows of, and `(* const char)' a type grouped into one element
(var ws (¤ size-t CAP) #(3 4))
(var gs (¤ (* const char) CAP) #("a" "b"))
(printf "named bound: %zu %zu %s\n"
(/ (sizeof ws) (sizeof (¤ ws 0))) (¤ ws 1) (¤ gs 1))
;; the same question in type position: `(fn ((unsigned int)) int)'
;; takes one parameter, not two
(var fp (fn ((unsigned int)) int) width)