1 ;;;; functions from classic CMU CL src/compiler/main.lisp which are
2 ;;;; needed only (and which may make sense only) on the
3 ;;;; cross-compilation target, not the cross-compilation host
5 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
16 ;;;; COMPILE and UNCOMPILE
18 (defun get-lambda-to-compile (definition)
19 (if (consp definition)
21 (multiple-value-bind (def env-p)
22 (function-lambda-expression definition)
24 (error "~S was defined in a non-null environment." definition))
26 (error "Can't find a definition for ~S." definition))
29 ;;; Find the function that is being compiled by COMPILE and bash its name to
30 ;;; NAME. We also substitute for any references to name so that recursive
31 ;;; calls will be compiled direct. Lambda is the top-level lambda for the
32 ;;; compilation. A REF for the real function is the only thing in the
33 ;;; top-level lambda other than the bind and return, so it isn't too hard to
35 (defun compile-fix-function-name (lambda name)
36 (declare (type clambda lambda) (type (or symbol cons) name))
40 (node-cont (lambda-bind lambda))))))
41 (setf (leaf-name fun) name)
42 (let ((old (gethash name *free-functions*)))
43 (when old (substitute-leaf fun old)))
46 (defun compile (name &optional (definition (fdefinition name)))
48 "Compiles the function whose name is Name. If Definition is supplied,
49 it should be a lambda expression that is compiled and then placed in the
50 function cell of Name. If Name is Nil, the compiled code object is
52 (with-compilation-values
53 (sb!xc:with-compilation-unit ()
54 (let* ((*info-environment* (or *backend-info-environment*
56 (*lexenv* (make-null-lexenv))
57 (form `#',(get-lambda-to-compile definition))
58 (*source-info* (make-lisp-source-info form))
59 (*top-level-lambdas* ())
60 (*converting-for-interpreter* nil)
62 (*compiler-error-bailout*
65 "~2&fatal error, aborting compilation~%")
66 (return-from compile (values nil t nil))))
68 (*last-source-context* nil)
69 (*last-original-source* nil)
70 (*last-source-form* nil)
71 (*last-format-string* nil)
72 (*last-format-args* nil)
73 (*last-message-count* 0)
74 (*compile-object* (make-core-object))
76 ;; FIXME: ANSI doesn't say anything about CL:COMPILE
77 ;; interacting with these variables, so we shouldn't. As
78 ;; of SBCL 0.6.7, COMPILE-FILE controls its verbosity by
79 ;; binding these variables, so as a quick hack we do so
80 ;; too. But a proper implementation would have verbosity
81 ;; controlled by function arguments and lexical variables.
82 (*compile-verbose* nil)
83 (*compile-print* nil))
85 (find-source-paths form 0)
86 (let ((lambda (ir1-top-level form '(original-source-start 0 0) t)))
88 (compile-fix-function-name lambda name)
90 (block-component (node-block (lambda-bind lambda))))
91 (*all-components* (list component)))
92 (local-call-analyze component))
94 (multiple-value-bind (components top-components)
95 (find-initial-dfo (list lambda))
96 (let ((*all-components* (append components top-components)))
97 (dolist (component *all-components*)
98 (compile-component component))))
100 (let* ((res1 (core-call-top-level-lambda lambda *compile-object*))
101 (result (or name res1)))
102 (fix-core-source-info *source-info* *compile-object* res1)
104 (setf (fdefinition name) res1))