report a module's macro call failing for other than its own names
Reading a module's interface dropped any toplevel call that raised, not only one asking after a declaration of the module's, which no importer has yet. Lookups now tell which names they missed, and only those failures give importers nothing.
This commit was merged in pull request #72.
This commit is contained in:
@@ -130,10 +130,11 @@
|
||||
;;; macros are the module's own and those its imports give it, lent for
|
||||
;;; the expanding and taken back after, so the importer is left with the
|
||||
;;; pub ones alone. One that reads the type database sees what the
|
||||
;;; importer knows, which a type private to the module is not; a call
|
||||
;;; that cannot expand for that -- (print-struct box), box being the
|
||||
;;; module's -- gives importers nothing, as before, and is the module's
|
||||
;;; own compile's to check
|
||||
;;; importer knows, which no declaration of the module's is yet; a call
|
||||
;;; that fails after asking for one -- (field-count box), box being the
|
||||
;;; module's record -- gives importers nothing, as before, and is the
|
||||
;;; module's own compile's to check. Any other failure is the importer's
|
||||
;;; too: (boom) raising "nope" says so wherever it is read
|
||||
(define +modules-expanded+ (list))
|
||||
|
||||
(define (module-forms raw-forms)
|
||||
@@ -144,7 +145,8 @@
|
||||
forms))))
|
||||
|
||||
(define (expanded raw-forms)
|
||||
(let ((lent (list)))
|
||||
(let ((lent (list))
|
||||
(declared (declared-names raw-forms)))
|
||||
(define (lend! form)
|
||||
(let ((name (macro-name form)))
|
||||
(unless (assq name lent)
|
||||
@@ -154,15 +156,37 @@
|
||||
(cond ((macro-name form) (lend! form) (list form))
|
||||
((splice? form) (append-map expand (cdr form)))
|
||||
((macro? form)
|
||||
(let ((result (handle-exceptions exn #f (apply-macro form))))
|
||||
(let ((result (expand-call form declared)))
|
||||
(cond ((or (not result) (null? result)) (list))
|
||||
(else (stamp-form-source! result (form-source form))
|
||||
(expand result)))))
|
||||
(else (list form))))
|
||||
(for-each lend! (imported-macro-forms raw-forms))
|
||||
(let ((forms (append-map expand raw-forms)))
|
||||
(for-each (lambda (entry) (restore-macro! (car entry) (cdr entry))) lent)
|
||||
forms)))
|
||||
(dynamic-wind
|
||||
void
|
||||
(lambda ()
|
||||
(for-each lend! (imported-macro-forms raw-forms))
|
||||
(append-map expand raw-forms))
|
||||
(lambda ()
|
||||
(for-each (lambda (entry) (restore-macro! (car entry) (cdr entry)))
|
||||
lent)))))
|
||||
|
||||
(define (expand-call form declared)
|
||||
(let ((unknown (list)))
|
||||
(handle-exceptions exn
|
||||
(if (any (lambda (name) (memq name declared)) unknown) #f (abort exn))
|
||||
(parameterize ((unknown-name (lambda (name) (set! unknown (cons name unknown)))))
|
||||
(apply-macro form)))))
|
||||
|
||||
;;; The names FORMS declare, types and all
|
||||
(define (declared-names forms)
|
||||
(append (map car (declared-types forms))
|
||||
(filter-map (lambda (form)
|
||||
(match form
|
||||
((or ('pub (or 'fn 'var) (? symbol? name) . _)
|
||||
((or 'fn 'var) (? symbol? name) . _))
|
||||
name)
|
||||
(_ #f)))
|
||||
forms)))
|
||||
|
||||
(define (splice? form)
|
||||
(and (pair? form) (eq? (car form) '$) (list? form)))
|
||||
|
||||
Reference in New Issue
Block a user