1
0
forked from alex-eg/sex
This commit is contained in:
2026-09-18 18:42:52 +03:00
parent ca71ae6e91
commit 78862cfe4f
5 changed files with 217 additions and 56 deletions

View File

@@ -71,6 +71,18 @@
(list)
raw-forms)))
(define (public-fn-interface form)
;; (pub fn name args ret . body) -> prototype, keeping a docstring so
;; the importer can emit it above the declaration
(let ((header (take form 5)))
(let loop ((body (drop form 5)))
(cond
((null? body) header)
((and (pair? (car body)) (eq? (caar body) 'comment))
(loop (cdr body)))
((string? (car body)) (append header (list (car body))))
(else header)))))
;;; TODO: use semen facilities to analyze modules
(define (process-public-interface-form form acc)
(case (car form)
@@ -79,7 +91,7 @@
;; A function is reduced to a prototype and keeps its `pub', so
;; the importing unit declares it with external linkage
((fn)
(cons (copy-form-source! form (take form 5)) acc))
(cons (copy-form-source! form (public-fn-interface form)) acc))
;; A variable becomes an `extern' declaration
((var)
(cons (copy-form-source! form (cons 'extern (take (cdr form) 3))) acc))