Commit | Line | Data |
---|---|---|
0ea72faa | 1 | ;;;; Copyright (C) 2003, 2005, 2006, 2009, 2010 Free Software Foundation, Inc. |
5d3af6f2 | 2 | ;;;; |
73be1d9e MV |
3 | ;;;; This library is free software; you can redistribute it and/or |
4 | ;;;; modify it under the terms of the GNU Lesser General Public | |
5 | ;;;; License as published by the Free Software Foundation; either | |
53befeb7 | 6 | ;;;; version 3 of the License, or (at your option) any later version. |
73be1d9e MV |
7 | ;;;; |
8 | ;;;; This library is distributed in the hope that it will be useful, | |
5d3af6f2 | 9 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
10 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | ;;;; Lesser General Public License for more details. | |
12 | ;;;; | |
13 | ;;;; You should have received a copy of the GNU Lesser General Public | |
14 | ;;;; License along with this library; if not, write to the Free Software | |
92205699 | 15 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
5d3af6f2 MV |
16 | ;;;; |
17 | ||
0ea72faa LC |
18 | (define-module (ice-9 deprecated) |
19 | #:export (substring-move-left! substring-move-right! | |
20 | dynamic-maybe-call dynamic-maybe-link | |
21 | try-module-linked try-module-dynamic-link | |
e63dda67 | 22 | list* feature? eval-case unmemoize-expr |
0ea72faa LC |
23 | $asinh |
24 | $acosh | |
25 | $atanh | |
26 | $sqrt | |
27 | $abs | |
28 | $exp | |
29 | $log | |
30 | $sin | |
31 | $cos | |
32 | $tan | |
33 | $asin | |
34 | $acos | |
35 | $atan | |
36 | $sinh | |
37 | $cosh | |
38 | $tanh | |
0abc2109 AW |
39 | closure? |
40 | %nil | |
f6a5308b AW |
41 | @bind) |
42 | ||
43 | #:replace (module-ref-submodule module-define-submodule!)) | |
635a8b36 | 44 | |
0ea72faa | 45 | |
5d3af6f2 MV |
46 | ;;;; Deprecated definitions. |
47 | ||
5b943a3f MV |
48 | (define substring-move-left! substring-move!) |
49 | (define substring-move-right! substring-move!) | |
50 | ||
0ea72faa | 51 | \f |
5d3af6f2 | 52 | ;; This method of dynamically linking Guile Extensions is deprecated. |
877f06c3 | 53 | ;; Use `load-extension' explicitly from Scheme code instead. |
5d3af6f2 MV |
54 | |
55 | (define (split-c-module-name str) | |
56 | (let loop ((rev '()) | |
57 | (start 0) | |
58 | (pos 0) | |
59 | (end (string-length str))) | |
60 | (cond | |
61 | ((= pos end) | |
62 | (reverse (cons (string->symbol (substring str start pos)) rev))) | |
63 | ((eq? (string-ref str pos) #\space) | |
64 | (loop (cons (string->symbol (substring str start pos)) rev) | |
65 | (+ pos 1) | |
66 | (+ pos 1) | |
67 | end)) | |
68 | (else | |
69 | (loop rev start (+ pos 1) end))))) | |
70 | ||
71 | (define (convert-c-registered-modules dynobj) | |
72 | (let ((res (map (lambda (c) | |
73 | (list (split-c-module-name (car c)) (cdr c) dynobj)) | |
74 | (c-registered-modules)))) | |
75 | (c-clear-registered-modules) | |
76 | res)) | |
77 | ||
78 | (define registered-modules '()) | |
79 | ||
80 | (define (register-modules dynobj) | |
81 | (set! registered-modules | |
82 | (append! (convert-c-registered-modules dynobj) | |
83 | registered-modules))) | |
84 | ||
85 | (define (warn-autoload-deprecation modname) | |
86 | (issue-deprecation-warning | |
87 | "Autoloading of compiled code modules is deprecated." | |
88 | "Write a Scheme file instead that uses `load-extension'.") | |
89 | (issue-deprecation-warning | |
90 | (simple-format #f "(You just autoloaded module ~S.)" modname))) | |
91 | ||
92 | (define (init-dynamic-module modname) | |
93 | ;; Register any linked modules which have been registered on the C level | |
94 | (register-modules #f) | |
95 | (or-map (lambda (modinfo) | |
96 | (if (equal? (car modinfo) modname) | |
97 | (begin | |
98 | (warn-autoload-deprecation modname) | |
99 | (set! registered-modules (delq! modinfo registered-modules)) | |
100 | (let ((mod (resolve-module modname #f))) | |
101 | (save-module-excursion | |
102 | (lambda () | |
103 | (set-current-module mod) | |
104 | (set-module-public-interface! mod mod) | |
105 | (dynamic-call (cadr modinfo) (caddr modinfo)) | |
106 | )) | |
107 | #t)) | |
108 | #f)) | |
109 | registered-modules)) | |
110 | ||
111 | (define (dynamic-maybe-call name dynobj) | |
112 | (catch #t ; could use false-if-exception here | |
113 | (lambda () | |
114 | (dynamic-call name dynobj)) | |
115 | (lambda args | |
116 | #f))) | |
117 | ||
118 | (define (dynamic-maybe-link filename) | |
119 | (catch #t ; could use false-if-exception here | |
120 | (lambda () | |
121 | (dynamic-link filename)) | |
122 | (lambda args | |
123 | #f))) | |
124 | ||
125 | (define (find-and-link-dynamic-module module-name) | |
126 | (define (make-init-name mod-name) | |
127 | (string-append "scm_init" | |
128 | (list->string (map (lambda (c) | |
129 | (if (or (char-alphabetic? c) | |
130 | (char-numeric? c)) | |
131 | c | |
132 | #\_)) | |
133 | (string->list mod-name))) | |
134 | "_module")) | |
135 | ||
136 | ;; Put the subdirectory for this module in the car of SUBDIR-AND-LIBNAME, | |
137 | ;; and the `libname' (the name of the module prepended by `lib') in the cdr | |
138 | ;; field. For example, if MODULE-NAME is the list (inet tcp-ip udp), then | |
139 | ;; SUBDIR-AND-LIBNAME will be the pair ("inet/tcp-ip" . "libudp"). | |
140 | (let ((subdir-and-libname | |
141 | (let loop ((dirs "") | |
142 | (syms module-name)) | |
143 | (if (null? (cdr syms)) | |
144 | (cons dirs (string-append "lib" (symbol->string (car syms)))) | |
145 | (loop (string-append dirs (symbol->string (car syms)) "/") | |
146 | (cdr syms))))) | |
147 | (init (make-init-name (apply string-append | |
148 | (map (lambda (s) | |
149 | (string-append "_" | |
150 | (symbol->string s))) | |
151 | module-name))))) | |
152 | (let ((subdir (car subdir-and-libname)) | |
153 | (libname (cdr subdir-and-libname))) | |
154 | ||
155 | ;; Now look in each dir in %LOAD-PATH for `subdir/libfoo.la'. If that | |
156 | ;; file exists, fetch the dlname from that file and attempt to link | |
157 | ;; against it. If `subdir/libfoo.la' does not exist, or does not seem | |
158 | ;; to name any shared library, look for `subdir/libfoo.so' instead and | |
159 | ;; link against that. | |
160 | (let check-dirs ((dir-list %load-path)) | |
161 | (if (null? dir-list) | |
162 | #f | |
163 | (let* ((dir (in-vicinity (car dir-list) subdir)) | |
164 | (sharlib-full | |
165 | (or (try-using-libtool-name dir libname) | |
166 | (try-using-sharlib-name dir libname)))) | |
167 | (if (and sharlib-full (file-exists? sharlib-full)) | |
168 | (link-dynamic-module sharlib-full init) | |
169 | (check-dirs (cdr dir-list))))))))) | |
170 | ||
171 | (define (try-using-libtool-name libdir libname) | |
172 | (let ((libtool-filename (in-vicinity libdir | |
173 | (string-append libname ".la")))) | |
174 | (and (file-exists? libtool-filename) | |
175 | libtool-filename))) | |
176 | ||
177 | (define (try-using-sharlib-name libdir libname) | |
178 | (in-vicinity libdir (string-append libname ".so"))) | |
179 | ||
180 | (define (link-dynamic-module filename initname) | |
181 | ;; Register any linked modules which have been registered on the C level | |
182 | (register-modules #f) | |
183 | (let ((dynobj (dynamic-link filename))) | |
184 | (dynamic-call initname dynobj) | |
185 | (register-modules dynobj))) | |
186 | ||
187 | (define (try-module-linked module-name) | |
188 | (init-dynamic-module module-name)) | |
189 | ||
190 | (define (try-module-dynamic-link module-name) | |
191 | (and (find-and-link-dynamic-module module-name) | |
192 | (init-dynamic-module module-name))) | |
726571e0 | 193 | |
0ea72faa | 194 | \f |
726571e0 MV |
195 | (define (list* . args) |
196 | (issue-deprecation-warning "'list*' is deprecated. Use 'cons*' instead.") | |
197 | (apply cons* args)) | |
2042e178 | 198 | |
e63dda67 LC |
199 | (define (feature? sym) |
200 | (issue-deprecation-warning | |
201 | "`feature?' is deprecated. Use `provided?' instead.") | |
202 | (provided? sym)) | |
203 | ||
b15dea68 AW |
204 | (define-macro (eval-case . clauses) |
205 | (issue-deprecation-warning | |
206 | "`eval-case' is deprecated. Use `eval-when' instead.") | |
207 | ;; Practically speaking, eval-case only had load-toplevel and else as | |
208 | ;; conditions. | |
209 | (cond | |
210 | ((assoc-ref clauses '(load-toplevel)) | |
211 | => (lambda (exps) | |
212 | ;; the *unspecified so that non-toplevel definitions will be | |
213 | ;; caught | |
214 | `(begin *unspecified* . ,exps))) | |
215 | ((assoc-ref clauses 'else) | |
216 | => (lambda (exps) | |
217 | `(begin *unspecified* . ,exps))) | |
218 | (else | |
219 | `(begin)))) | |
10fab724 | 220 | |
0ea72faa LC |
221 | ;; The strange prototype system for uniform arrays has been |
222 | ;; deprecated. | |
10fab724 AW |
223 | (read-hash-extend |
224 | #\y | |
225 | (lambda (c port) | |
226 | (issue-deprecation-warning | |
b0fae4ec | 227 | "The `#y' bitvector syntax is deprecated. Use `#*' instead.") |
10fab724 AW |
228 | (let ((x (read port))) |
229 | (cond | |
230 | ((list? x) | |
231 | (list->bitvector | |
232 | (map (lambda (x) | |
233 | (cond ((zero? x) #f) | |
234 | ((eqv? x 1) #t) | |
235 | (else (error "invalid #y element" x)))) | |
236 | x))) | |
237 | (else | |
238 | (error "#y needs to be followed by a list" x)))))) | |
b7742c6b AW |
239 | |
240 | (define (unmemoize-expr . args) | |
241 | (issue-deprecation-warning | |
242 | "`unmemoize-expr' is deprecated. Use `unmemoize-expression' instead.") | |
243 | (apply unmemoize-expression args)) | |
ad79736c AW |
244 | |
245 | (define ($asinh z) (asinh z)) | |
246 | (define ($acosh z) (acosh z)) | |
247 | (define ($atanh z) (atanh z)) | |
248 | (define ($sqrt z) (sqrt z)) | |
249 | (define ($abs z) (abs z)) | |
250 | (define ($exp z) (exp z)) | |
251 | (define ($log z) (log z)) | |
252 | (define ($sin z) (sin z)) | |
253 | (define ($cos z) (cos z)) | |
254 | (define ($tan z) (tan z)) | |
255 | (define ($asin z) (asin z)) | |
256 | (define ($acos z) (acos z)) | |
257 | (define ($atan z) (atan z)) | |
258 | (define ($sinh z) (sinh z)) | |
259 | (define ($cosh z) (cosh z)) | |
260 | (define ($tanh z) (tanh z)) | |
0ea72faa | 261 | |
314b8716 AW |
262 | (define (closure? x) |
263 | (issue-deprecation-warning | |
264 | "`closure?' is deprecated. Use `procedure?' instead.") | |
265 | (procedure? x)) | |
cd038da5 AW |
266 | |
267 | (define %nil #nil) | |
0abc2109 AW |
268 | |
269 | ;;; @bind is used by the old elisp code as a dynamic scoping mechanism. | |
270 | ;;; Please let the Guile developers know if you are using this macro. | |
271 | ;;; | |
272 | (define-syntax @bind | |
273 | (lambda (x) | |
274 | (define (bound-member id ids) | |
275 | (cond ((null? ids) #f) | |
276 | ((bound-identifier=? id (car ids)) #t) | |
277 | ((bound-member (car ids) (cdr ids))))) | |
278 | ||
279 | (issue-deprecation-warning | |
280 | "`@bind' is deprecated. Use `with-fluids' instead.") | |
281 | ||
282 | (syntax-case x () | |
283 | ((_ () b0 b1 ...) | |
284 | #'(let () b0 b1 ...)) | |
285 | ((_ ((id val) ...) b0 b1 ...) | |
286 | (and-map identifier? #'(id ...)) | |
287 | (if (let lp ((ids #'(id ...))) | |
288 | (cond ((null? ids) #f) | |
289 | ((bound-member (car ids) (cdr ids)) #t) | |
290 | (else (lp (cdr ids))))) | |
291 | (syntax-violation '@bind "duplicate bound identifier" x) | |
292 | (with-syntax (((old-v ...) (generate-temporaries #'(id ...))) | |
293 | ((v ...) (generate-temporaries #'(id ...)))) | |
294 | #'(let ((old-v id) ... | |
295 | (v val) ...) | |
296 | (dynamic-wind | |
297 | (lambda () | |
298 | (set! id v) ...) | |
299 | (lambda () b0 b1 ...) | |
300 | (lambda () | |
301 | (set! id old-v) ...))))))))) | |
c9904ab0 | 302 | |
f6a5308b AW |
303 | (define (module-ref-submodule module name) |
304 | (or (hashq-ref (module-submodules module) name) | |
81fc66cf AW |
305 | (and (module-submodule-binder module) |
306 | ((module-submodule-binder module) module name)) | |
f6a5308b AW |
307 | (let ((var (module-local-variable module name))) |
308 | (and (variable-bound? var) | |
309 | (module? (variable-ref var)) | |
310 | (begin | |
311 | (warn "module" module "not in submodules table") | |
312 | (variable-ref var)))))) | |
313 | ||
314 | (define (module-define-submodule! module name submodule) | |
315 | (let ((var (module-local-variable module name))) | |
316 | (if (and var (variable-bound? var) (not (module? (variable-ref var)))) | |
317 | (warn "defining module" module ": not overriding local definition" var) | |
318 | (module-define! module name submodule))) | |
319 | (hashq-set! (module-submodules module) name submodule)) | |
320 | ||
635a8b36 AW |
321 | ;; Define (%app) and (%app modules), and have (app) alias (%app). This |
322 | ;; side-effects the-root-module, both to the submodules table and (through | |
323 | ;; module-define-submodule! above) the obarray. | |
324 | ;; | |
325 | (let ((%app (make-module 31))) | |
326 | (set-module-name! %app '(%app)) | |
327 | (module-define-submodule! the-root-module '%app %app) | |
328 | (module-define-submodule! the-root-module 'app %app) | |
329 | (module-define-submodule! %app 'modules (resolve-module '() #f))) |