read every trailing array bound as a dimension

[m 1 2] lost its second index, and [int 2 3] came out int 2 x[3]. Each
index now subscripts what the one before it gave, and [int 2 3] declares
what it indexes, int[2][3]. An inline struct's fields, once more than
one bound was looked for, were taken for one; their shape tells them apart.
This commit is contained in:
2026-10-16 15:26:05 +03:00
parent ba807fe9ec
commit 08cb8451ff
7 changed files with 102 additions and 14 deletions

View File

@@ -673,6 +673,16 @@
((dot-access) (walk-member-path form env))
;; [m 1 2] is [[m 1] 2], m[1][2]
((¤)
(if (> (length form) 3)
(walk-statement
(copy-form-source!
form
(list '¤ (copy-form-source! form (drop-right form 1)) (last form)))
env)
(walk-parts form env)))
((sizeof)
(if (and (= 2 (length form)) (written-type? (second form) env))
(copy-form-source!
@@ -755,7 +765,7 @@
;;; nothing here can count
(define (array-length type)
(and (array-bound? type)
(let ((bound (last type)))
(let ((bound (array-bound type)))
(cond ((and (integer? bound) (exact? bound)) bound)
((symbol? bound)
(let ((info (get-type-info bound)))
@@ -796,11 +806,14 @@
;;; there that is a type:
;;;
;;; (* char) (* const char) (* size-t) (unsigned int) types
;;; (* p) (* (g)) (¤ xs 0) expressions
;;; (* p) (* (g)) (¤ xs 0) (¤ m 1 2) expressions
(define (written-type? form env)
(and (pair? form)
;; the length a dereference and a subscript have
(if (= (length form) (case (car form) ((*) 2) ((¤) 3) (else -1)))
(if (case (car form)
((*) (= (length form) 2))
((¤) (>= (length form) 3))
(else #f))
(let ((operand (second form)))
(if (symbol? operand)
(not (or (lookup-name env operand) (get-name-type operand)))