*** empty log message ***
[bpt/guile.git] / ice-9 / slib.scm
CommitLineData
0f2d19dd
JB
1;;; installed-scm-file
2(define-module #/ice-9/slib)
3
4\f
5
6(define (eval-load <filename> evl)
7 (if (not (file-exists? <filename>))
8 (set! <filename> (string-append <filename> (scheme-file-suffix))))
9 (call-with-input-file <filename>
10 (lambda (port)
11 (let ((old-load-pathname *load-pathname*))
12 (set! *load-pathname* <filename>)
75a97b92 13 (do ((o (read port) (read port)))
0f2d19dd
JB
14 ((eof-object? o))
15 (evl o))
16 (set! *load-pathname* old-load-pathname)))))
17
18\f
19
20(define slib:exit quit)
21(define slib:error error)
22(define slib:eval eval)
23(define defmacro:eval eval)
24(define logical:logand logand)
25(define logical:logior logior)
26(define logical:logxor logxor)
27(define logical:lognot lognot)
28(define logical:ash ash)
29(define logical:logcount logcount)
30(define logical:integer-length integer-length)
31(define logical:bit-extract bit-extract)
32(define logical:integer-expt integer-expt)
33(define logical:ipow-by-squaring ipow-by-squaring)
34(define slib:eval-load eval-load)
35(define slib:tab #\tab)
36(define slib:form-feed #\page)
37
ed218d98
MV
38(define slib-module (current-module))
39
40(define (defined? symbol)
41 (module-defined? slib-module symbol))
42
0f2d19dd
JB
43(define slib:features
44 (append '(source
45 eval
46 abort
47 alist
48 defmacro
49 delay
50 dynamic-wind
51 full-continuation
52 hash
53 hash-table
54 line-i/o
55 logical
56 multiarg/and-
57 multiarg-apply
58 promise
59 rev2-procedures
60 rev4-optional-procedures
61 string-port
62 with-file)
63
b1818df3 64 (if (defined? 'getenv)
0f2d19dd
JB
65 '(getenv)
66 '())
67
b1818df3 68 (if (defined? 'current-time)
0f2d19dd
JB
69 '(current-time)
70 '())
71
b1818df3 72 (if (defined? 'system)
0f2d19dd
JB
73 '(system)
74 '())
75
b1818df3 76 (if (defined? 'array?)
0f2d19dd
JB
77 '(array)
78 '())
79
b1818df3 80 (if (defined? 'char-ready?)
0f2d19dd
JB
81 '(char-ready?)
82 '())
83
b1818df3 84 (if (defined? 'array-for-each)
0f2d19dd
JB
85 '(array-for-each)
86 '())
87
88 (if (and (string->number "0.0") (inexact? (string->number "0.0")))
89 '(inexact)
90 '())
91
92 (if (rational? (string->number "1/19"))
93 '(rational)
94 '())
95
96 (if (real? (string->number "0.0"))
97 '(real)
98 ())
99
100 (if (complex? (string->number "1+i"))
101 '(complex)
102 '())
103
104 (let ((n (string->number "9999999999999999999999999999999")))
105 (if (and n (exact? n))
106 '(bignum)
107 '()))))
108
109
0f2d19dd
JB
110(define (slib:load name)
111 (save-module-excursion
112 (lambda ()
113 (set-current-module slib-module)
c51bfd81
MD
114 (let* ((errinfo (catch 'system-error
115 (lambda ()
e37e4bca 116 (primitive-load-path name)
c51bfd81
MD
117 #f)
118 (lambda args args)))
119 (errinfo (and errinfo
120 (catch 'system-error
121 (lambda ()
e37e4bca
JB
122 (primitive-load-path
123 (string-append name ".scm"))
c51bfd81
MD
124 #f)
125 (lambda args args)))))
126 (if errinfo
127 (apply throw errinfo))))))
0f2d19dd
JB
128
129(define slib:load-source slib:load)
130(define defmacro:load slib:load)
131
c51bfd81
MD
132(define slib-parent-dir
133 (let* ((path (%search-load-path "slib/require.scm")))
00f06035
GH
134 (if path
135 (make-shared-substring path 0 (- (string-length path) 17))
136 (error "Could not find slib/require.scm in " %load-path))))
c51bfd81
MD
137
138(define-public (implementation-vicinity)
139 (string-append slib-parent-dir "/"))
140(define (library-vicinity)
141 (string-append (implementation-vicinity) "slib/"))
0f2d19dd
JB
142(define (scheme-implementation-type) 'guile)
143(define (scheme-implementation-version) "")
144
145(define (output-port-width . arg) 80)
146(define (output-port-height . arg) 24)
147
4b0d6055
JB
148(define (identity x) x)
149
0f2d19dd
JB
150;;; {Time}
151;;;
152
153(define difftime -)
154(define offset-time +)
155
156\f
157(define %system-define define)
158
159(define define
160 (procedure->memoizing-macro
161 (lambda (exp env)
162 (if (= (length env) 1)
163 `(define-public ,@(cdr exp))
164 `(%system-define ,@(cdr exp))))))
165
166(define (software-type) 'UNIX)
167
c51bfd81 168(slib:load (in-vicinity (library-vicinity) "require.scm"))
0f2d19dd
JB
169
170(define-public require require:require)
c51bfd81
MD
171
172;; {Extensions to the require system so that the user can add new
173;; require modules easily.}
174
175(define *vicinity-table*
176 (list
177 (cons 'implementation (implementation-vicinity))
178 (cons 'library (library-vicinity))))
179
180(define (install-require-vicinity name vicinity)
181 (let ((entry (assq name *vicinity-table*)))
182 (if entry
183 (set-cdr! entry vicinity)
184 (set! *vicinity-table*
185 (acons name vicinity *vicinity-table*)))))
186
187(define (install-require-module name vicinity-name file-name)
188 (let ((entry (assq name *catalog*))
189 (vicinity (cdr (assq vicinity-name *vicinity-table*))))
190 (let ((path-name (in-vicinity vicinity file-name)))
191 (if entry
192 (set-cdr! entry path-name)
193 (set! *catalog*
194 (acons name path-name *catalog*))))))