0.7.4.30:
[sbcl.git] / src / cold / defun-load-or-cload-xcompiler.lisp
1 ;;;; This software is part of the SBCL system. See the README file for
2 ;;;; more information.
3 ;;;;
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
9
10 (in-package "SB-COLD")
11
12 ;;; Either load or compile-then-load the cross-compiler into the
13 ;;; cross-compilation host Common Lisp.
14 (defun load-or-cload-xcompiler (load-or-cload-stem)
15
16   ;; The running-in-the-host-Lisp Python cross-compiler defines its
17   ;; own versions of a number of functions which should not overwrite
18   ;; host-Lisp functions. Instead we put them in a special package.
19   ;;
20   ;; The common theme of the functions, macros, constants, and so
21   ;; forth in this package is that they run in the host and affect the
22   ;; compilation of the target.
23   (let ((package-name "SB-XC"))
24     (make-package package-name :use nil :nicknames nil)
25     (dolist (name '(;; the constants (except for T and NIL which have
26                     ;; a specially hacked correspondence between
27                     ;; cross-compilation host Lisp and target Lisp)
28                     "ARRAY-DIMENSION-LIMIT"
29                     "ARRAY-RANK-LIMIT" 
30                     "ARRAY-TOTAL-SIZE-LIMIT" 
31                     "BOOLE-1" 
32                     "BOOLE-2" 
33                     "BOOLE-AND" 
34                     "BOOLE-ANDC1" 
35                     "BOOLE-ANDC2" 
36                     "BOOLE-C1" 
37                     "BOOLE-C2" 
38                     "BOOLE-CLR" 
39                     "BOOLE-EQV" 
40                     "BOOLE-IOR" 
41                     "BOOLE-NAND" 
42                     "BOOLE-NOR" 
43                     "BOOLE-ORC1" 
44                     "BOOLE-ORC2" 
45                     "BOOLE-SET" 
46                     "BOOLE-XOR" 
47                     "CALL-ARGUMENTS-LIMIT" 
48                     "CHAR-CODE-LIMIT" 
49                     "DOUBLE-FLOAT-EPSILON" 
50                     "DOUBLE-FLOAT-NEGATIVE-EPSILON" 
51                     "INTERNAL-TIME-UNITS-PER-SECOND" 
52                     "LAMBDA-LIST-KEYWORDS" 
53                     "LAMBDA-PARAMETERS-LIMIT" 
54                     "LEAST-NEGATIVE-DOUBLE-FLOAT" 
55                     "LEAST-NEGATIVE-LONG-FLOAT" 
56                     "LEAST-NEGATIVE-NORMALIZED-DOUBLE-FLOAT" 
57                     "LEAST-NEGATIVE-NORMALIZED-LONG-FLOAT" 
58                     "LEAST-NEGATIVE-NORMALIZED-SHORT-FLOAT" 
59                     "LEAST-NEGATIVE-NORMALIZED-SINGLE-FLOAT" 
60                     "LEAST-NEGATIVE-SHORT-FLOAT" 
61                     "LEAST-NEGATIVE-SINGLE-FLOAT" 
62                     "LEAST-POSITIVE-DOUBLE-FLOAT" 
63                     "LEAST-POSITIVE-LONG-FLOAT" 
64                     "LEAST-POSITIVE-NORMALIZED-DOUBLE-FLOAT" 
65                     "LEAST-POSITIVE-NORMALIZED-LONG-FLOAT" 
66                     "LEAST-POSITIVE-NORMALIZED-SHORT-FLOAT" 
67                     "LEAST-POSITIVE-NORMALIZED-SINGLE-FLOAT" 
68                     "LEAST-POSITIVE-SHORT-FLOAT" 
69                     "LEAST-POSITIVE-SINGLE-FLOAT" 
70                     "LONG-FLOAT-EPSILON" 
71                     "LONG-FLOAT-NEGATIVE-EPSILON" 
72                     "MOST-NEGATIVE-DOUBLE-FLOAT" 
73                     "MOST-NEGATIVE-FIXNUM" 
74                     "MOST-NEGATIVE-LONG-FLOAT" 
75                     "MOST-NEGATIVE-SHORT-FLOAT" 
76                     "MOST-NEGATIVE-SINGLE-FLOAT" 
77                     "MOST-POSITIVE-DOUBLE-FLOAT" 
78                     "MOST-POSITIVE-FIXNUM" 
79                     "MOST-POSITIVE-LONG-FLOAT" 
80                     "MOST-POSITIVE-SHORT-FLOAT" 
81                     "MOST-POSITIVE-SINGLE-FLOAT" 
82                     "MULTIPLE-VALUES-LIMIT" 
83                     "PI" 
84                     "SHORT-FLOAT-EPSILON" 
85                     "SHORT-FLOAT-NEGATIVE-EPSILON" 
86                     "SINGLE-FLOAT-EPSILON" 
87                     "SINGLE-FLOAT-NEGATIVE-EPSILON" 
88
89                     ;; everything else which needs a separate
90                     ;; existence in xc and target
91                     "BUILT-IN-CLASS"
92                     "BYTE" "BYTE-POSITION" "BYTE-SIZE"
93                     "CLASS" "CLASS-NAME" "CLASS-OF"
94                     "COMPILE-FILE"
95                     "COMPILE-FILE-PATHNAME"
96                     "*COMPILE-FILE-PATHNAME*"
97                     "*COMPILE-FILE-TRUENAME*"
98                     "*COMPILE-PRINT*"
99                     "*COMPILE-VERBOSE*"
100                     "COMPILER-MACRO-FUNCTION"
101                     "CONSTANTP"
102                     "DEFCONSTANT"
103                     "DEFINE-MODIFY-MACRO"
104                     "DEFINE-SETF-EXPANDER"
105                     "DEFMACRO" "DEFSETF" "DEFSTRUCT" "DEFTYPE"
106                     "DEPOSIT-FIELD" "DPB"
107                     "FBOUNDP" "FDEFINITION" "FMAKUNBOUND"
108                     "FIND-CLASS"
109                     "GET-SETF-EXPANSION"
110                     "LDB" "LDB-TEST"
111                     "LISP-IMPLEMENTATION-TYPE" "LISP-IMPLEMENTATION-VERSION"
112                     "MACRO-FUNCTION"
113                     "MACROEXPAND" "MACROEXPAND-1" "*MACROEXPAND-HOOK*"
114                     "MAKE-LOAD-FORM"
115                     "MAKE-LOAD-FORM-SAVING-SLOTS"
116                     "MASK-FIELD"
117                     "PACKAGE" "PACKAGEP"
118                     "PROCLAIM"
119                     "SPECIAL-OPERATOR-P"
120                     "STANDARD-CLASS"
121                     "STRUCTURE-CLASS"
122                     "SUBTYPEP"
123                     "TYPE-OF" "TYPEP"
124                     "WITH-COMPILATION-UNIT"))
125       (export (intern name package-name) package-name)))
126   ;; don't watch:
127   (dolist (package-name '("SB!ALIEN"
128                           "SB!ALIEN-INTERNALS"
129                           "SB!ASSEM"
130                           "SB!BIGNUM"
131                           "SB!C"
132                           "SB!DEBUG"
133                           "SB!DI"
134                           "SB!DISASSEM"
135                           #!+sb-dyncount "SB!DYNCOUNT"
136                           "SB!FASL"
137                           "SB!IMPL"
138                           "SB!EXT"
139                           "SB!FORMAT"
140                           "SB!GRAY"
141                           "SB!INT"
142                           "SB!KERNEL"
143                           "SB!LOOP"
144                           #!+mp "SB!MP"
145                           "SB!PCL"
146                           "SB!PRETTY"
147                           "SB!PROFILE"
148                           "SB!SYS"
149                           "SB!UNIX"
150                           "SB!VM"
151                           "SB!WALKER"))
152     (shadowing-import (mapcar (lambda (name) (find-symbol name "SB-XC"))
153                               '("BYTE" "BYTE-POSITION" "BYTE-SIZE"
154                                 "DPB" "LDB" "LDB-TEST"
155                                 "DEPOSIT-FIELD" "MASK-FIELD"))
156                       package-name))
157
158   ;; Build a version of Python to run in the host Common Lisp, to be
159   ;; used only in cross-compilation.
160   ;;
161   ;; Note that files which are marked :ASSEM, to cause them to be
162   ;; processed with SB!C:ASSEMBLE-FILE when we're running under the
163   ;; cross-compiler or the target lisp, are still processed here, just
164   ;; with the ordinary Lisp compiler, and this is intentional, in
165   ;; order to make the compiler aware of the definitions of assembly
166   ;; routines.
167   (do-stems-and-flags (stem flags)
168     (unless (find :not-host flags)
169       (funcall load-or-cload-stem
170                stem
171                :ignore-failure-p (find :ignore-failure-p flags))
172       #!+sb-show (warn-when-cl-snapshot-diff *cl-snapshot*)))
173
174   ;; If the cross-compilation host is SBCL itself, we can use the
175   ;; PURIFY extension to freeze everything in place, reducing the
176   ;; amount of work done on future GCs. In machines with limited
177   ;; memory, this could help, by reducing the amount of memory which
178   ;; needs to be juggled in a full GC. And it can hardly hurt, since
179   ;; (in the ordinary build procedure anyway) essentially everything
180   ;; which is reachable at this point will remain reachable for the
181   ;; entire run.
182   #+sbcl (sb-ext:purify)
183
184   (values))