forked from alex-eg/sex
check what a module's importers can see of its types
An importer is given the pub forms and nothing else, so a pub form naming a private type, or one from an import without pub, compiled in its module and failed in every importer with `unknown type name'. The pub forms are checked as the module itself is compiled. A record, struct, union or sum behind a pointer needs only declaring, so its bodyless declaration goes out ahead of them -- the opaque handle that (pub record T) already gave by hand. Held by value it needs its body, and a typedef or an enum has no declaration short of its definition: those are errors at the pub form, saying what would do instead. A name Sex has no declaration for is left to C. An importer may now be handed a declaration after the definition it declares, so a bodyless aggregate no longer replaces known fields. Fixes #57, #58.
This commit is contained in:
22
sexc.scm
22
sexc.scm
@@ -180,11 +180,15 @@ status, which is ours to pass on."
|
||||
(delete-file* c-file)
|
||||
(if normal-exit? status 1)))))))
|
||||
|
||||
(define (semantic-process-forms raw-forms input-source)
|
||||
(if (eq? input-source 'stdin)
|
||||
(semen-process raw-forms)
|
||||
(with-directory input-source
|
||||
(semen-process raw-forms))))
|
||||
;;; The unit's own forms are checked for what its importers will need,
|
||||
;;; the prelude's not: every unit has those
|
||||
(define (semantic-process-forms unit-forms input-source)
|
||||
(let ((process (lambda ()
|
||||
(check-public-interface unit-forms)
|
||||
(semen-process (append prelude unit-forms)))))
|
||||
(if (eq? input-source 'stdin)
|
||||
(process)
|
||||
(with-directory input-source (process)))))
|
||||
|
||||
(define prelude
|
||||
(append
|
||||
@@ -228,6 +232,10 @@ status, which is ours to pass on."
|
||||
(platform-features))
|
||||
(cli-features args)))
|
||||
|
||||
;; before the interface too, which asks the modules it imports
|
||||
;; what types they export
|
||||
(load-persistent-module-paths)
|
||||
|
||||
(when (get-arg args 'public-interface #f)
|
||||
(assert (not (eq? input 'stdin)) "Error: --public-interface requires file argument")
|
||||
|
||||
@@ -237,7 +245,6 @@ status, which is ours to pass on."
|
||||
(map pp (reverse
|
||||
(read-public-interface input)))))
|
||||
(return #f))
|
||||
(load-persistent-module-paths)
|
||||
|
||||
;; The file name in a #line directive now comes from the form's
|
||||
;; own recorded location, so imported modules report themselves
|
||||
@@ -247,8 +254,7 @@ status, which is ours to pass on."
|
||||
(not (get-arg args 'line-directives #f)))
|
||||
(sex-line-directives 'none))
|
||||
|
||||
(let* ((raw-forms (append prelude (read-raw-forms input)))
|
||||
(sex-forms (semantic-process-forms raw-forms input)))
|
||||
(let ((sex-forms (semantic-process-forms (read-raw-forms input) input)))
|
||||
(if (or (get-arg args 'macro-expand #f)
|
||||
(get-arg args 'emit-c #f))
|
||||
;; Emit processed and macro-expanded sex code, or emit C code
|
||||
|
||||
Reference in New Issue
Block a user