1
0
forked from alex-eg/sex

answer where a written type ends in one place

An arglist entry, an array's bound and its element type ask one
question, and disagreed: `(unsigned int)' was a name plus a type, a
trailing typedef a bound, a subscript the type's second word.
This commit is contained in:
2026-09-30 12:54:21 +03:00
parent 9daaa42d6a
commit 2b73fcf1c4
8 changed files with 173 additions and 54 deletions

View File

@@ -276,7 +276,7 @@
;;; through untouched.
(define (fn-type-of fn-form)
`(fn ,(map (lambda (param)
(if (and (pair? param) (= 2 (length param)))
(if (and (pair? param) (= 2 (length param)) (named-arg? param))
(list (second param))
param))
(sex-fn-arglist fn-form))
@@ -550,9 +550,10 @@
(and (symbol? (car expr)) (get-return-type (car expr))))
(else
(case (car expr)
;; subscripting an array gives its element type, and a pointer
;; subscripts the same way
((¤) (let ((base (expression-type (second expr) env)))
(and (list? base) (>= (length base) 2) (eq? '¤ (car base))
(second base))))
(or (array-element-type base) (pointer-target base))))
((&) (and (= 2 (length expr))
(let ((target (expression-type (second expr) env)))
(and target `(* ,target)))))