1
;;; CMPUTIL Miscellaneous Functions.
3
;; Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
5
;; This file is part of GNU Common Lisp, herein referred to as GCL
7
;; GCL is free software; you can redistribute it and/or modify it under
8
;; the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
9
;; the Free Software Foundation; either version 2, or (at your option)
12
;; GCL is distributed in the hope that it will be useful, but WITHOUT
13
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15
;; License for more details.
17
;; You should have received a copy of the GNU Library General Public License
18
;; along with GCL; see the file COPYING. If not, write to the Free Software
19
;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
(in-package 'compiler)
24
(export '(*suppress-compiler-warnings*
25
*suppress-compiler-notes*
26
*compiler-break-enable*))
28
(defmacro safe-compile (&rest forms) `(when *safe-compile* ,@forms))
30
(defvar *current-form* '|compiler preprocess|)
31
(defvar *first-error* t)
32
(defvar *error-count* 0)
34
(defconstant *cmperr-tag* (cons nil nil))
36
(defun cmperr (string &rest args &aux (*print-case* :upcase))
39
(apply #'format t string args)
41
(throw *cmperr-tag* '*cmperr-tag*))
43
(defmacro cmpck (condition string &rest args)
44
`(if ,condition (cmperr ,string ,@args)))
46
(defun too-many-args (name upper-bound n &aux (*print-case* :upcase))
49
";;; ~S requires at most ~R argument~:p, ~
50
but ~R ~:*~[were~;was~:;were~] supplied.~%"
55
(throw *cmperr-tag* '*cmperr-tag*))
57
(defun too-few-args (name lower-bound n &aux (*print-case* :upcase))
60
";;; ~S requires at least ~R argument~:p, ~
61
but only ~R ~:*~[were~;was~:;were~] supplied.~%"
66
(throw *cmperr-tag* '*cmperr-tag*))
68
(defvar *suppress-compiler-warnings* nil)
70
(defun cmpwarn (string &rest args &aux (*print-case* :upcase))
71
(unless *suppress-compiler-warnings*
73
(format t ";; Warning: ")
74
(apply #'format t string args)
78
(defvar *suppress-compiler-notes* nil)
80
(defun cmpnote (string &rest args &aux (*print-case* :upcase))
81
(unless *suppress-compiler-notes*
83
(format t ";; Note: ")
84
(apply #'format t string args))
87
(defun print-current-form ()
89
(setq *first-error* nil)
92
((and (consp *current-form*)
93
(eq (car *current-form*) 'si:|#,|))
94
(format t "; #,~s is being compiled.~%" (cdr *current-form*)))
96
(let ((*print-length* 2)
98
(format t "; ~s is being compiled.~%" *current-form*)))))
101
(defun undefined-variable (sym &aux (*print-case* :upcase))
104
";; The variable ~s is undefined.~%~
105
;; The compiler will assume this variable is a global.~%"
109
(defun baboon (&aux (*print-case* :upcase))
111
(format t ";;; A bug was found in the compiler. Contact Taiichi.~%")
114
; (throw *cmperr-tag* '*cmperr-tag*)
117
;;; Internal Macros with type declarations
119
(defmacro dolist* ((v l &optional (val nil)) . body)
120
(let ((temp (gensym)))
121
`(do* ((,temp ,l (cdr ,temp)) (,v (car ,temp) (car ,temp)))
123
(declare (object ,v))
126
(defmacro dolist** ((v l &optional (val nil)) . body)
127
(let ((temp (gensym)))
128
`(do* ((,temp ,l (cdr ,temp)) (,v (car ,temp) (car ,temp)))
130
(declare (object ,temp ,v))
133
(defmacro dotimes* ((v n &optional (val nil)) . body)
134
(let ((temp (gensym)))
135
`(do* ((,temp ,n) (,v 0 (1+ ,v)))
137
(declare (fixnum ,v))
140
(defmacro dotimes** ((v n &optional (val nil)) . body)
141
(let ((temp (gensym)))
142
`(do* ((,temp ,n) (,v 0 (1+ ,v)))
144
(declare (fixnum ,temp ,v))
147
(defun cmp-eval (form)
148
(let ((x (multiple-value-list (cmp-toplevel-eval `(eval ',form)))))
150
(let ((*print-case* :upcase))
154
";;; The form ~s was not evaluated successfully.~%~
155
;;; You are recommended to compile again.~%"
158
(values-list (cdr x)))))
161
;(si::putprop 'setf 'c1setf 'c1special)
163
;;The PLACE may be a local macro, so we must take care to expand it
164
;;before trying to call the macro form of setf, or an error will
166
;(defun c1setf (args &aux fd)
169
; (symbolp (caar args))
170
; (setq fd (cmp-macro-function (caar args))))
171
; (c1expr `(setf ,(cmp-expand-macro fd (caar args) (cdar args))
174
; (c1expr (cmp-expand-macro (macro-function 'setf)
178
(defun cmp-macroexpand (form &aux env)
179
;;Obtain the local macro environment for expansion.
181
(if (consp v) (push (list (car v) 'macro (cadr v)) env)))
182
(if env (setq env (list nil (nreverse env) nil)))
183
(let ((x (multiple-value-list
184
(cmp-toplevel-eval `(macroexpand ',form ',env)))))
186
(let ((*print-case* :upcase))
190
";;; The macro form ~s was not expanded successfully.~%"
192
`(error "Macro-expansion of ~s failed at compile time." ',form))
195
(defun cmp-macroexpand-1 (form &aux env)
197
(if (consp v) (push (list (car v) 'macro (cadr v)) env)))
198
(let ((x (multiple-value-list (cmp-toplevel-eval `(macroexpand-1 ',form
201
(let ((*print-case* :upcase))
205
";;; The macro form ~s was not expanded successfully.~%"
207
`(error "Macro-expansion of ~s failed at compile time." ',form))
210
(defun cmp-expand-macro (fd fname args &aux env)
212
(if (consp v) (push (list (car v) 'macro (cadr v)) env)))
213
(and *record-call-info* (add-macro-callee fname))
214
(if env (setq env (list nil (nreverse env) nil)))
215
(let ((x (multiple-value-list
217
`(funcall *macroexpand-hook* ',fd ',(cons fname args) ',env)))))
219
(let ((*print-case* :upcase))
223
";;; The macro form (~s ...) was not expanded successfully.~%"
225
`(error "Macro-expansion of ~s failed at compile time."
226
',(cons fname args)))
229
(defvar *compiler-break-enable* nil)
231
(defun cmp-toplevel-eval (form)
232
(let* ((si::*ihs-base* si::*ihs-top*)
233
(si::*ihs-top* (1- (si::ihs-top)))
234
(*break-enable* *compiler-break-enable*)
235
(si::*break-hidden-packages*
236
(cons (find-package 'compiler)
237
si::*break-hidden-packages*)))
238
(si:error-set form)))
240
(dolist (v '(si::cdefn lfun inline-safe inline-unsafe
241
inline-always c1conditional c2 c1 c1+ co1
242
si::structure-access co1special
243
top-level-macro t3 t2 t1 package-operation))
244
(si::putprop v t 'compiler-prop ))
246
(defun compiler-def-hook (symbol code) symbol code nil)
248
(defun compiler-clear-compiler-properties (symbol code)
250
(let ((v (symbol-plist symbol)) w)
254
(cond ((and (symbolp w)
255
(get w 'compiler-prop))
259
(t (setq v (cddr v))))
260
(or (null v) (go top)))
261
(compiler-def-hook symbol code)