-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild-composit.scm
127 lines (112 loc) · 4.02 KB
/
build-composit.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
;;; Copyright (c) 2004-2022 Yoshikatsu Fujita / LittleWing Company Limited.
;;; See LICENSE file for terms and conditions of use.
(library (anonymous)
(export)
;; import everything
(import (core primitives)
(core optimize)
(core parameters)
(core io)
(core files)
(core exceptions)
(core arithmetic)
(core sorting)
(core bytevectors)
(core syntax-case)
(core r5rs)
(core control)
(core optargs)
; (core chkarg)
(core lists)
(core records)
(core conditions)
(core bytevector-transcoders)
(core unicode-assistants)
(core unicode)
(core hashtables)
(core struct)
(core enums))
(define target-file-name (format "~a/../stdlib/core.scm" (current-directory)))
(define libraries
'((core primitives)
(core optimize)
(core parameters)
(core io)
(core files)
(core exceptions)
(core arithmetic)
(core sorting)
(core bytevectors)
(core syntax-case)
(core r5rs)
(core control)
(core optargs)
; (core chkarg)
(core lists)
(core destructuring)
(core records)
(core conditions)
(core bytevector-transcoders)
#;(core unicode-assistants)
(core unicode)
(core hashtables)
(core struct)
(core enums)))
(define exported (make-core-hashtable))
(define library-internal-name
(lambda (name)
(define infix ".")
(define symbol-list->string
(lambda (ref)
(apply string-append
(cdr (let loop ((lst ref))
(cond ((null? lst) '())
((symbol? (car lst))
(cons infix
(cons (symbol->string (car lst))
(loop (cdr lst)))))
(else
(loop (cdr lst)))))))))
(define malformed-name
(lambda ()
(assertion-violation 'library-internal-name "malformed library name" name)))
(if (and (list? name) (not (null? name)))
(if (for-all symbol? name)
(string->symbol (symbol-list->string name))
(let ((body (list-head name (- (length name) 1))))
(if (for-all symbol? body)
(string->symbol (symbol-list->string body))
(malformed-name))))
(malformed-name))))
(define symbol<?
(lambda (e1 e2)
(string<? (symbol->string e1)
(symbol->string e2))))
(begin
(format #t ";; build ~a~!" target-file-name)
(for-each (lambda (lst)
(let ((name (library-internal-name lst)))
(format #t "~%;; processing ~s~!" name)
(cond ((core-hashtable-ref (scheme-library-exports) name #f)
=> (lambda (lst)
(let ((lst (filter (lambda (e) (not (core-hashtable-ref exported e #f)))
(map car lst))))
(for-each (lambda (e) (core-hashtable-set! exported e #t)) lst)
(list-sort symbol<? lst)
)))
(else
(assertion-violation #f "library not imported" name)))))
libraries)
(let ((lst (list-sort symbol<? (map car (core-hashtable->alist exported)))))
(call-with-port
(open-file-output-port target-file-name (file-options no-fail) (buffer-mode block) (native-transcoder))
(lambda (out)
(format out "(library (core)~%")
(format out " (export")
(for-each (lambda (i) (format out "~% ~a" i)) lst)
(format out ")~%")
(format out " (import")
(for-each (lambda (e) (format out "~% ~a" e)) libraries)
(format out "))~%~!")
(format #t "~%~%~!")))))
) ;[end]