Commit | Line | Data |
---|---|---|
7ebe6c76 JB |
1 | ;;;; slib.scm --- definitions needed to get SLIB to work with Guile |
2 | ;;;; | |
9630e974 | 3 | ;;;; Copyright (C) 1997, 1998 Free Software Foundation, Inc. |
7ebe6c76 JB |
4 | ;;;; |
5 | ;;;; This file is part of GUILE. | |
6 | ;;;; | |
7 | ;;;; GUILE is free software; you can redistribute it and/or modify | |
8 | ;;;; it under the terms of the GNU General Public License as | |
9 | ;;;; published by the Free Software Foundation; either version 2, or | |
10 | ;;;; (at your option) any later version. | |
11 | ;;;; | |
12 | ;;;; GUILE is distributed in the hope that it will be useful, but | |
13 | ;;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;;;; GNU General Public License for more details. | |
16 | ;;;; | |
17 | ;;;; You should have received a copy of the GNU General Public | |
18 | ;;;; License along with GUILE; see the file COPYING. If not, write | |
19 | ;;;; to the Free Software Foundation, Inc., 59 Temple Place, Suite | |
20 | ;;;; 330, Boston, MA 02111-1307 USA | |
21 | ;;;; | |
8bb7330c | 22 | (define-module (ice-9 slib)) |
0f2d19dd JB |
23 | |
24 | \f | |
25 | ||
26 | (define (eval-load <filename> evl) | |
27 | (if (not (file-exists? <filename>)) | |
28 | (set! <filename> (string-append <filename> (scheme-file-suffix)))) | |
29 | (call-with-input-file <filename> | |
30 | (lambda (port) | |
31 | (let ((old-load-pathname *load-pathname*)) | |
32 | (set! *load-pathname* <filename>) | |
75a97b92 | 33 | (do ((o (read port) (read port))) |
0f2d19dd JB |
34 | ((eof-object? o)) |
35 | (evl o)) | |
36 | (set! *load-pathname* old-load-pathname))))) | |
37 | ||
38 | \f | |
39 | ||
40 | (define slib:exit quit) | |
41 | (define slib:error error) | |
7ed9feb0 | 42 | (define slib:warn warn) |
841d28d7 | 43 | (define slib:eval (lambda (x) (eval-in-module x slib-module))) |
0f2d19dd JB |
44 | (define defmacro:eval eval) |
45 | (define logical:logand logand) | |
46 | (define logical:logior logior) | |
47 | (define logical:logxor logxor) | |
48 | (define logical:lognot lognot) | |
49 | (define logical:ash ash) | |
50 | (define logical:logcount logcount) | |
51 | (define logical:integer-length integer-length) | |
52 | (define logical:bit-extract bit-extract) | |
53 | (define logical:integer-expt integer-expt) | |
54 | (define logical:ipow-by-squaring ipow-by-squaring) | |
55 | (define slib:eval-load eval-load) | |
56 | (define slib:tab #\tab) | |
57 | (define slib:form-feed #\page) | |
58 | ||
ed218d98 MV |
59 | (define slib-module (current-module)) |
60 | ||
61 | (define (defined? symbol) | |
62 | (module-defined? slib-module symbol)) | |
63 | ||
0f2d19dd JB |
64 | (define slib:features |
65 | (append '(source | |
66 | eval | |
67 | abort | |
68 | alist | |
69 | defmacro | |
70 | delay | |
71 | dynamic-wind | |
72 | full-continuation | |
73 | hash | |
74 | hash-table | |
75 | line-i/o | |
76 | logical | |
77 | multiarg/and- | |
78 | multiarg-apply | |
79 | promise | |
80 | rev2-procedures | |
81 | rev4-optional-procedures | |
82 | string-port | |
83 | with-file) | |
84 | ||
b1818df3 | 85 | (if (defined? 'getenv) |
0f2d19dd JB |
86 | '(getenv) |
87 | '()) | |
88 | ||
b1818df3 | 89 | (if (defined? 'current-time) |
0f2d19dd JB |
90 | '(current-time) |
91 | '()) | |
92 | ||
b1818df3 | 93 | (if (defined? 'system) |
0f2d19dd JB |
94 | '(system) |
95 | '()) | |
96 | ||
b1818df3 | 97 | (if (defined? 'array?) |
0f2d19dd JB |
98 | '(array) |
99 | '()) | |
100 | ||
b1818df3 | 101 | (if (defined? 'char-ready?) |
0f2d19dd JB |
102 | '(char-ready?) |
103 | '()) | |
104 | ||
b1818df3 | 105 | (if (defined? 'array-for-each) |
0f2d19dd JB |
106 | '(array-for-each) |
107 | '()) | |
108 | ||
109 | (if (and (string->number "0.0") (inexact? (string->number "0.0"))) | |
110 | '(inexact) | |
111 | '()) | |
112 | ||
113 | (if (rational? (string->number "1/19")) | |
114 | '(rational) | |
115 | '()) | |
116 | ||
117 | (if (real? (string->number "0.0")) | |
118 | '(real) | |
119 | ()) | |
120 | ||
121 | (if (complex? (string->number "1+i")) | |
122 | '(complex) | |
123 | '()) | |
124 | ||
125 | (let ((n (string->number "9999999999999999999999999999999"))) | |
126 | (if (and n (exact? n)) | |
127 | '(bignum) | |
128 | '())))) | |
129 | ||
130 | ||
9b345f6c | 131 | ;;; FIXME: Because uers want require to search the path, this uses |
096d5f90 | 132 | ;;; load-from-path, which probably isn't a hot idea. slib |
9b345f6c JB |
133 | ;;; doesn't expect this function to search a path, so I expect to get |
134 | ;;; bug reports at some point complaining that the wrong file gets | |
135 | ;;; loaded when something accidentally appears in the path before | |
136 | ;;; slib, etc. ad nauseum. However, the right fix seems to involve | |
137 | ;;; changing catalog:get in slib/require.scm, and I don't expect | |
138 | ;;; Aubrey will integrate such a change. So I'm just going to punt | |
139 | ;;; for the time being. | |
534a0099 | 140 | (define-public (slib:load name) |
0f2d19dd JB |
141 | (save-module-excursion |
142 | (lambda () | |
143 | (set-current-module slib-module) | |
d1005e3c MD |
144 | (let ((errinfo (catch 'system-error |
145 | (lambda () | |
146 | (load-from-path name) | |
147 | #f) | |
148 | (lambda args args)))) | |
149 | (if (and errinfo | |
150 | (catch 'system-error | |
151 | (lambda () | |
152 | (load-from-path | |
153 | (string-append name ".scm")) | |
154 | #f) | |
155 | (lambda args args))) | |
c51bfd81 | 156 | (apply throw errinfo)))))) |
0f2d19dd JB |
157 | |
158 | (define slib:load-source slib:load) | |
159 | (define defmacro:load slib:load) | |
160 | ||
c51bfd81 MD |
161 | (define slib-parent-dir |
162 | (let* ((path (%search-load-path "slib/require.scm"))) | |
00f06035 GH |
163 | (if path |
164 | (make-shared-substring path 0 (- (string-length path) 17)) | |
165 | (error "Could not find slib/require.scm in " %load-path)))) | |
c51bfd81 MD |
166 | |
167 | (define-public (implementation-vicinity) | |
168 | (string-append slib-parent-dir "/")) | |
169 | (define (library-vicinity) | |
170 | (string-append (implementation-vicinity) "slib/")) | |
ad76c8d9 TP |
171 | (define home-vicinity |
172 | (let ((home-path (getenv "HOME"))) | |
173 | (lambda () home-path))) | |
0f2d19dd JB |
174 | (define (scheme-implementation-type) 'guile) |
175 | (define (scheme-implementation-version) "") | |
176 | ||
177 | (define (output-port-width . arg) 80) | |
178 | (define (output-port-height . arg) 24) | |
841d28d7 | 179 | (define (identity x) x) |
4b0d6055 | 180 | |
0f2d19dd JB |
181 | ;;; {Time} |
182 | ;;; | |
183 | ||
184 | (define difftime -) | |
185 | (define offset-time +) | |
186 | ||
187 | \f | |
188 | (define %system-define define) | |
189 | ||
190 | (define define | |
191 | (procedure->memoizing-macro | |
192 | (lambda (exp env) | |
193 | (if (= (length env) 1) | |
194 | `(define-public ,@(cdr exp)) | |
195 | `(%system-define ,@(cdr exp)))))) | |
196 | ||
7a0ff2f8 MD |
197 | ;;; Hack to make syncase macros work in the slib module |
198 | (if (nested-ref the-root-module '(app modules ice-9 syncase)) | |
199 | (set-object-property! (module-local-variable (current-module) 'define) | |
200 | '*sc-expander* | |
201 | '(define))) | |
202 | ||
0f2d19dd JB |
203 | (define (software-type) 'UNIX) |
204 | ||
c51bfd81 | 205 | (slib:load (in-vicinity (library-vicinity) "require.scm")) |
0f2d19dd JB |
206 | |
207 | (define-public require require:require) | |
c51bfd81 MD |
208 | |
209 | ;; {Extensions to the require system so that the user can add new | |
210 | ;; require modules easily.} | |
211 | ||
212 | (define *vicinity-table* | |
213 | (list | |
214 | (cons 'implementation (implementation-vicinity)) | |
215 | (cons 'library (library-vicinity)))) | |
216 | ||
217 | (define (install-require-vicinity name vicinity) | |
218 | (let ((entry (assq name *vicinity-table*))) | |
219 | (if entry | |
220 | (set-cdr! entry vicinity) | |
221 | (set! *vicinity-table* | |
222 | (acons name vicinity *vicinity-table*))))) | |
223 | ||
224 | (define (install-require-module name vicinity-name file-name) | |
12ed431d MD |
225 | (if (not *catalog*) ;Fix which loads catalog in slib |
226 | (catalog:get 'random)) ;(doesn't load the feature 'random) | |
c51bfd81 MD |
227 | (let ((entry (assq name *catalog*)) |
228 | (vicinity (cdr (assq vicinity-name *vicinity-table*)))) | |
229 | (let ((path-name (in-vicinity vicinity file-name))) | |
230 | (if entry | |
231 | (set-cdr! entry path-name) | |
232 | (set! *catalog* | |
233 | (acons name path-name *catalog*)))))) |