bugfixes #66

Merged
pkulev merged 43 commits from bugfixes into main 2026-10-19 21:14:40 +02:00
2 changed files with 34 additions and 9 deletions
Showing only changes of commit 541d9cd610 - Show all commits

View File

@@ -179,6 +179,7 @@
(('pub 'var name type . _) (list type)) (('pub 'var name type . _) (list type))
(_ (list)))) (_ (list))))
(('pub 'typedef name target) (list target)) (('pub 'typedef name target) (list target))
(('pub 'define name . body) body)
(('pub (or 'record 'struct 'union) name . rest) (('pub (or 'record 'struct 'union) name . rest)
(field-types (find list? (remove comment-form? rest)))) (field-types (find list? (remove comment-form? rest))))
(('pub 'sum name (variants ...)) (('pub 'sum name (variants ...))
@@ -218,7 +219,8 @@
(case (car type) (case (car type)
((*) (append-map (lambda (t) (type-uses t #t)) (cdr type))) ((*) (append-map (lambda (t) (type-uses t #t)) (cdr type)))
((¤) (let ((element (array-element-type type))) ((¤) (let ((element (array-element-type type)))
(if element (type-uses element behind?) (list)))) (append (if element (type-uses element behind?) (list))
(if (array-bound? type) (bound-uses (last type)) (list)))))
((fn closure) ((fn closure)
(if (and (pair? (cdr type)) (list? (second type))) (if (and (pair? (cdr type)) (list? (second type)))
(append-map (lambda (t) (type-uses t #t)) (append-map (lambda (t) (type-uses t #t))
@@ -230,21 +232,31 @@
(list))) (list)))
(else (append-map (lambda (t) (type-uses t behind?)) type)))))) (else (append-map (lambda (t) (type-uses t behind?)) type))))))
;;; The types FORMS declare, as (name kind body?): ;;; [int (* 2 N)] needs N, as a value: there is no declaring it
(define (bound-uses bound)
(cond ((symbol? bound) (list (cons bound #f)))
((pair? bound) (append-map bound-uses (cdr bound)))
(else (list))))
;;; The types and constants FORMS declare, as (name kind body?):
;;; ;;;
;;; (pub record tally) -> (tally record #f) ;;; (pub record tally) -> (tally record #f)
;;; (sum colour ((none ()))) -> (colour sum #t) ;;; (sum colour ((none ()))) -> (colour sum #t)
;;; (define (sq x) (* x x)) -> (sq define #t)
(define (declared-types forms) (define (declared-types forms)
(filter-map (filter-map
(lambda (form) (lambda (form)
(and (pair? form) (and (pair? form)
(let ((core (if (pub-form? form) (cdr form) form))) (let* ((core (if (pub-form? form) (cdr form) form))
(and (pair? core) (pair? (cdr core)) (name (and (pair? core) (pair? (cdr core))
(memq (car core) '(record struct union enum sum typedef)) (if (and (eq? (car core) 'define) (pair? (second core)))
(symbol? (second core)) (car (second core))
(list (second core) (second core)))))
(and (memq (car core) '(record struct union enum sum typedef define))
(symbol? name)
(list name
(car core) (car core)
(or (eq? (car core) 'typedef) (or (memq (car core) '(typedef define))
(any list? (remove comment-form? (cddr core))))))))) (any list? (remove comment-form? (cddr core)))))))))
forms)) forms))

View File

@@ -553,4 +553,17 @@ ahead of its pub forms."
"only a handle")) "only a handle"))
(test "which is all it takes" (test "which is all it takes"
'() '()
(interface-of "(pub record h) (record h ((n int))) (pub fn f ((x (* h))) void)")))) (interface-of "(pub record h) (record h ((n int))) (pub fn f ((x (* h))) void)"))
;; A constant has no declaration either, and an array bound or a
;; pub define's body hands its name to importers all the same
(test-assert "a constant sizing a pub record's array"
(interface-reports? "(define N 4) (pub record r ((xs [int N])))"
"this define, and C declares one only by defining it"))
(test-assert "or used by a pub define"
(interface-reports? "(define N 4) (pub define M (* 2 N))" "this define"))
(test "is fine when pub"
'()
(interface-of "(pub define N 4) (pub record r ((xs [int N])))"))
(test "as is a literal bound"
'()
(interface-of "(pub record r ((xs [int 4])))"))))