forked from dbetz/xlisp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.lsp
executable file
·46 lines (42 loc) · 1.3 KB
/
compile.lsp
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
(define basic-load load)
(define (file-exists? name)
(let ((f (open-input-file name)))
(when f
(close-port f)
#t)))
(define (load name)
(let ((off (string-search "." name)))
(if off
(let ((ext (substring name off)))
(if (string-ci=? ext ".fsl")
(load-fasl-file name)
(basic-load name)))
(let ((full-name (string-append name ".fsl")))
(if (file-exists? full-name)
(load-fasl-file full-name)
(basic-load (string-append name ".lsp")))))))
(define (compile-file name)
(let* ((iname (string-append name ".lsp"))
(oname (string-append name ".fsl"))
(if (open-input-file iname))
(of (open-output-file oname))
(sts #f))
(when (and if of)
(let loop ((expr (read if)))
(when (not (eof-object? expr))
(let ((compiled-expr (compile expr)))
(fasl-write-procedure compiled-expr of))
(loop (read if))))
(set! sts #t))
(when if (close-port if))
(when of (close-port of))
sts))
(define (load-fasl-file name)
(let ((if (open-input-file name)))
(when if
(let loop ((proc (fasl-read-procedure if)))
(when (not (eof-object? proc))
(proc)
(loop (fasl-read-procedure if))))
(close-port if)
#t)))