0.8alpha.0.13:
[sbcl.git] / src / cold / ansify.lisp
1 ;;;; patches to work around 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 \f
13 ;;;; CLISP issues
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   ;; apparently fixed sometime in 2001, hurray!
35   #| (error "can't use CLISP -- no MAKE-LOAD-FORM") |#
36
37   ;; CLISP is still unsupported as a cross-compilation host because of
38   ;; these known problems:
39   (flet ((clisp-ouch (s) (error "can't bootstrap with CLISP: ~A" s)))
40     ;; These problems don't seem deep, and could probably be worked
41     ;; around.
42     #+nil (clisp-ouch "no (DOCUMENTATION X) when X is a PACKAGE")
43     #+nil (clisp-ouch "no (FUNCTION (SETF SYMBOL-FUNCTION))"))
44   
45   (ext:without-package-lock ("SYSTEM")
46     (setf system::*inhibit-floating-point-underflow* t)))
47 \f
48 ;;;; CMU CL issues
49
50 ;;; CMU CL, at least as of 18b, doesn't support PRINT-OBJECT. In
51 ;;; particular, it refuses to compile :PRINT-OBJECT options to
52 ;;; DEFSTRUCT, so we need to conditionalize such options on the
53 ;;; :NO-ANSI-PRINT-OBJECT feature in order to get the code to compile.
54 ;;; (It also fails to do anything useful with DEFMETHOD PRINT-OBJECT,
55 ;;; but that doesn't matter much, since it doesn't stop the
56 ;;; cross-compiler from working.)
57 #+cmu
58 (progn
59   (warn "CMU CL doesn't support the :PRINT-OBJECT option to DEFSTRUCT.~%")
60   (pushnew :no-ansi-print-object *features*))
61
62 ;;; KLUDGE: In CMU CL, at least as of 18b, READ-SEQUENCE is somewhat
63 ;;; dain-bramaged. Running
64 ;;;   (defvar *buffer* (make-array (expt 10 6) :element-type 'character))
65 ;;;   (with-open-file (s "/tmp/long-file.tmp")
66 ;;;     (/show (read-sequence *buffer* s :start 0 :end 3000))
67 ;;;     (/show (read-sequence *buffer* s :start 0 :end 15000))
68 ;;;     (/show (read-sequence *buffer* s :start 0 :end 15000)))
69 ;;; on a large test file gives
70 ;;; /(READ-SEQUENCE *BUFFER* S :START 0 :END 3000)=3000
71 ;;; /(READ-SEQUENCE *BUFFER* S :START 0 :END 15000)=1096
72 ;;; /(READ-SEQUENCE *BUFFER* S :START 0 :END 15000)=0
73 #+cmu
74 (progn
75   (warn "CMU CL has a broken implementation of READ-SEQUENCE.")
76   (pushnew :no-ansi-read-sequence *features*))
77
78 #+(and cmu alpha)
79 (unless (ignore-errors (read-from-string "1.0l0"))
80   (error "CMUCL on Alpha can't read floats in the format \"1.0l0\".  Patch your core file~%~%"))
81 \f
82 ;;;; general non-ANSI-ness
83
84 (in-package :sb-cold)
85
86 (defmacro munging-cl-package (&body body)
87   #-clisp `(progn ,@body)
88   #+clisp `(ext:without-package-lock ("CL")
89              ,@body))
90
91 ;;; Do the exports of COMMON-LISP conform to the standard? If not, try
92 ;;; to make them conform. (Of course, ANSI says that bashing symbols
93 ;;; in the COMMON-LISP package like this is undefined, but then if the
94 ;;; host Common Lisp were ANSI, we wouldn't be doing this, now would
95 ;;; we? "One dirty unportable hack deserves another.":-)
96 (let ((standard-ht (make-hash-table :test 'equal))
97       (host-ht     (make-hash-table :test 'equal))
98       (cl         (find-package "COMMON-LISP")))
99   (do-external-symbols (i cl)
100     (setf (gethash (symbol-name i) host-ht) t))
101   (dolist (i (read-from-file "common-lisp-exports.lisp-expr"))
102     (setf (gethash i standard-ht) t))
103   (maphash (lambda (key value)
104              (declare (ignore value))
105              (unless (gethash key standard-ht)
106                (warn "removing non-ANSI export from package CL: ~S" key)
107                (munging-cl-package
108                 (unexport (intern key cl) cl))))
109            host-ht)
110   (maphash (lambda (key value)
111              (declare (ignore value))
112              (unless (gethash key host-ht)
113                (warn "adding required-by-ANSI export to package CL: ~S" key)
114                (munging-cl-package 
115                 (export (intern key cl) cl)))
116              
117              ;; FIXME: My righteous indignation below was misplaced. ANSI sez
118              ;; (in 11.1.2.1, "The COMMON-LISP Package") that it's OK for
119              ;; COMMON-LISP things to have their home packages elsewhere.
120              ;; For now, the hack below works, but it's not good to rely
121              ;; on this nonstandardness. Ergo, I should fix things so that even
122              ;; when the cross-compilation host COMMON-LISP package has
123              ;; symbols with home packages elsewhere, genesis dumps out
124              ;; the correct stuff. (For each symbol dumped, check whether it's
125              ;; exported from COMMON-LISP, and if so, dump it as though its
126              ;; home package is COMMON-LISP regardless of whether it actually
127              ;; is. I think..)
128              ;;
129              ;; X CMU CL, at least the Debian versions ca. 2.4.9 that I'm
130              ;; X using as I write this, plays a sneaky trick on us by
131              ;; X putting DEBUG and FLOATING-POINT-INEXACT in the
132              ;; X EXTENSIONS package, then IMPORTing them into
133              ;; X COMMON-LISP, then reEXPORTing them from COMMON-LISP.
134              ;; X This leaves their home packages bogusly set to
135              ;; X EXTENSIONS, which confuses genesis into thinking that
136              ;; X the CMU CL EXTENSIONS package has to be dumped into the
137              ;; X target SBCL. (perhaps a last-ditch survival strategy
138              ;; X for the CMU CL "nooo! don't bootstrap from scratch!"
139              ;; X meme?) As far as I can see, there's no even slightly
140              ;; X portable way to undo the damage, so we'll play the "one
141              ;; X dirty unportable hack deserves another" game, only even
142              ;; X dirtierly and more unportably than before..
143              #+cmu
144              (let ((symbol (intern key cl)))
145                (unless (eq (symbol-package symbol) cl)
146                  (warn "using low-level hack to move ~S from ~S to ~S"
147                        symbol
148                        (symbol-package symbol)
149                        cl)
150                  (kernel:%set-symbol-package symbol cl))))
151            standard-ht))