Initial revision
[sbcl.git] / src / cold / ansify.lisp
1 ;;;; patches to hide some implementation idiosyncrasies in our
2 ;;;; cross-compilation host
3
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
12
13 ;;;; $Header$
14
15 #+clisp
16 (locally
17
18   (in-package "COMMON-LISP")
19
20   ;; no longer needed in CLISP 1999-01-08, hurrah!
21   #|
22   ;; ANSI specifies that package LISP defines the type BOOLEAN, and the CMU CL
23   ;; compiler uses it a lot. This should be trivial to patch in CLISP, except
24   ;; that CLISP defines FFI:BOOLEAN, which conflicts. Gads.. Here we try to fix
25   ;; it with some package hacking. (Please do not take this as an example of
26   ;; good package hacking, I just messed with it until it seemed to work well
27   ;; enough to bootstrap CMU CL, because I'm highly unmotivated to make elegant
28   ;; fixes for nonstandard behavior. -- WHN)
29   (shadow 'ffi:boolean "FFI")
30   (deftype cl::boolean () '(member t nil))
31   (export 'boolean "LISP")
32   |#
33
34   ;; I gave up on using CLISP-1999-01-08 as a cross-compilation host because of
35   ;; problems that I don't have workarounds for:
36   (error "can't use CLISP -- no MAKE-LOAD-FORM")
37   (error "can't use CLISP -- no (FUNCTION (SETF SYMBOL-FUNCTION))")
38   )
39
40 ;;; CMU CL, at least as of 18b, doesn't support PRINT-OBJECT. In particular, it
41 ;;; refuses to compile :PRINT-OBJECT options to DEFSTRUCT, so we need to
42 ;;; conditionalize such options on the :NO-ANSI-PRINT-OBJECT feature in order
43 ;;; to get the code to compile. (It also fails to do anything useful with
44 ;;; DEFMETHOD PRINT-OBJECT, but that doesn't matter much, since it doesn't stop
45 ;;; the cross-compiler from working.)
46 ;;;
47 ;;; FIXME: SBCL 0.5.0 doesn't support PRINT-OBJECT either. SBCL 0.6.0 will,
48 ;;; at which time this conditional should go away.
49 #+cmu
50 (progn
51   (warn "CMU CL doesn't support the :PRINT-OBJECT option to DEFSTRUCT.~%")
52   (pushnew :no-ansi-print-object *features*))
53
54 ;;; KLUDGE: In CMU CL, at least as of 18b, READ-SEQUENCE is somewhat
55 ;;; dain-bramaged. Running
56 ;;;   (defvar *buffer* (make-array (expt 10 6) :element-type 'character))
57 ;;;   (with-open-file (s "/tmp/long-file.tmp")
58 ;;;     (/show (read-sequence *buffer* s :start 0 :end 3000))
59 ;;;     (/show (read-sequence *buffer* s :start 0 :end 15000))
60 ;;;     (/show (read-sequence *buffer* s :start 0 :end 15000)))
61 ;;; on a large test file gives
62 ;;; /(READ-SEQUENCE *BUFFER* S :START 0 :END 3000)=3000
63 ;;; /(READ-SEQUENCE *BUFFER* S :START 0 :END 15000)=1096
64 ;;; /(READ-SEQUENCE *BUFFER* S :START 0 :END 15000)=0
65 #+cmu ; FIXME: Remove SBCL once we've patched READ-SEQUENCE.
66 (progn
67   (warn "CMU CL has a broken implementation of READ-SEQUENCE.")
68   (pushnew :no-ansi-read-sequence *features*))
69
70 ;;; Do the exports of COMMON-LISP conform to the standard? If not, try to make
71 ;;; them conform. (Of course, ANSI says that bashing symbols in the COMMON-LISP
72 ;;; package like this is undefined, but then if the host Common Lisp were ANSI,
73 ;;; we wouldn't be doing this, now would we? "One dirty unportable hack
74 ;;; deserves another.":-)
75 (let ((standard-ht (make-hash-table :test 'equal))
76       (host-ht     (make-hash-table :test 'equal))
77       (cl         (find-package "COMMON-LISP")))
78   (do-external-symbols (i cl)
79     (setf (gethash (symbol-name i) host-ht) t))
80   (dolist (i (read-from-file "common-lisp-exports.lisp-expr"))
81     (setf (gethash i standard-ht) t))
82   (maphash (lambda (key value)
83              (declare (ignore value))
84              (unless (gethash key standard-ht)
85                (warn "removing non-ANSI export from package CL: ~S" key)
86                (unexport (intern key cl) cl)))
87            host-ht)
88   (maphash (lambda (key value)
89              (declare (ignore value))
90              (unless (gethash key host-ht)
91                (warn "adding required-by-ANSI export to package CL: ~S" key)
92                (export (intern key cl) cl))
93              ;; FIXME: My righteous indignation below was misplaced. ANSI sez
94              ;; (in 11.1.2.1, "The COMMON-LISP Package") that it's OK for
95              ;; COMMON-LISP things to have their home packages elsewhere.
96              ;; For now, the hack below works, but it's not good to rely
97              ;; on this nonstandardness. Ergo, I should fix things so that even
98              ;; when the cross-compilation host COMMON-LISP package has
99              ;; symbols with home packages elsewhere, genesis dumps out
100              ;; the correct stuff. (For each symbol dumped, check whether it's
101              ;; exported from COMMON-LISP, and if so, dump it as though its
102              ;; home package is COMMON-LISP regardless of whether it actually
103              ;; is. I think..)
104              ;;
105              ;; X CMU CL, at least the Debian versions ca. 2.4.9 that I'm
106              ;; X using as I write this, plays a sneaky trick on us by
107              ;; X putting DEBUG and FLOATING-POINT-INEXACT in the
108              ;; X EXTENSIONS package, then IMPORTing them into
109              ;; X COMMON-LISP, then reEXPORTing them from COMMON-LISP.
110              ;; X This leaves their home packages bogusly set to
111              ;; X EXTENSIONS, which confuses genesis into thinking that
112              ;; X the CMU CL EXTENSIONS package has to be dumped into the
113              ;; X target SBCL. (perhaps a last-ditch survival strategy
114              ;; X for the CMU CL "nooo! don't bootstrap from scratch!"
115              ;; X meme?) As far as I can see, there's no even slightly
116              ;; X portable way to undo the damage, so we'll play the "one
117              ;; X dirty unportable hack deserves another" game, only even
118              ;; X dirtierly and more unportably than before..
119              #+cmu
120              (let ((symbol (intern key cl)))
121                (unless (eq (symbol-package symbol) cl)
122                  (warn "using low-level hack to move ~S from ~S to ~S"
123                        symbol
124                        (symbol-package symbol)
125                        cl)
126                  (kernel:%set-symbol-package symbol cl))))
127            standard-ht))