1 |
;;; bytecomp.el --- compilation of Lisp code into byte code |
;;; bytecomp.el --- compilation of Lisp code into byte code |
2 |
|
|
3 |
;; Copyright (C) 1985,86,87,92,94,1998,2000,01,02,03,2004 |
;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1998, 2000, 2001, 2002, |
4 |
;; Free Software Foundation, Inc. |
;; 2003, 2004 Free Software Foundation, Inc. |
5 |
|
|
6 |
;; Author: Jamie Zawinski <jwz@lucid.com> |
;; Author: Jamie Zawinski <jwz@lucid.com> |
7 |
;; Hallvard Furuseth <hbf@ulrik.uio.no> |
;; Hallvard Furuseth <hbf@ulrik.uio.no> |
447 |
"Alist of functions defined in the file being compiled. |
"Alist of functions defined in the file being compiled. |
448 |
This is so we can inline them when necessary. |
This is so we can inline them when necessary. |
449 |
Each element looks like (FUNCTIONNAME . DEFINITION). It is |
Each element looks like (FUNCTIONNAME . DEFINITION). It is |
450 |
\(FUNCTIONNAME . nil) when a function is redefined as a macro.") |
\(FUNCTIONNAME . nil) when a function is redefined as a macro. |
451 |
|
It is \(FUNCTIONNAME . t) when all we know is that it was defined, |
452 |
|
and we don't know the definition.") |
453 |
|
|
454 |
(defvar byte-compile-unresolved-functions nil |
(defvar byte-compile-unresolved-functions nil |
455 |
"Alist of undefined functions to which calls have been compiled. |
"Alist of undefined functions to which calls have been compiled. |
1105 |
|
|
1106 |
;;; sanity-checking arglists |
;;; sanity-checking arglists |
1107 |
|
|
1108 |
|
;; If a function has an entry saying (FUNCTION . t). |
1109 |
|
;; that means we know it is defined but we don't know how. |
1110 |
|
;; If a function has an entry saying (FUNCTION . nil), |
1111 |
|
;; that means treat it as not defined. |
1112 |
(defun byte-compile-fdefinition (name macro-p) |
(defun byte-compile-fdefinition (name macro-p) |
1113 |
(let* ((list (if macro-p |
(let* ((list (if macro-p |
1114 |
byte-compile-macro-environment |
byte-compile-macro-environment |
1174 |
(defun byte-compile-callargs-warn (form) |
(defun byte-compile-callargs-warn (form) |
1175 |
(let* ((def (or (byte-compile-fdefinition (car form) nil) |
(let* ((def (or (byte-compile-fdefinition (car form) nil) |
1176 |
(byte-compile-fdefinition (car form) t))) |
(byte-compile-fdefinition (car form) t))) |
1177 |
(sig (if def |
(sig (if (and def (not (eq def t))) |
1178 |
(byte-compile-arglist-signature |
(byte-compile-arglist-signature |
1179 |
(if (eq 'lambda (car-safe def)) |
(if (eq 'lambda (car-safe def)) |
1180 |
(nth 1 def) |
(nth 1 def) |
1204 |
(byte-compile-format-warn form) |
(byte-compile-format-warn form) |
1205 |
;; Check to see if the function will be available at runtime |
;; Check to see if the function will be available at runtime |
1206 |
;; and/or remember its arity if it's unknown. |
;; and/or remember its arity if it's unknown. |
1207 |
(or (and (or sig (fboundp (car form))) ; might be a subr or autoload. |
(or (and (or def (fboundp (car form))) ; might be a subr or autoload. |
1208 |
(not (memq (car form) byte-compile-noruntime-functions))) |
(not (memq (car form) byte-compile-noruntime-functions))) |
1209 |
(eq (car form) byte-compile-current-form) ; ## this doesn't work |
(eq (car form) byte-compile-current-form) ; ## this doesn't work |
1210 |
; with recursion. |
; with recursion. |
1215 |
(if cons |
(if cons |
1216 |
(or (memq n (cdr cons)) |
(or (memq n (cdr cons)) |
1217 |
(setcdr cons (cons n (cdr cons)))) |
(setcdr cons (cons n (cdr cons)))) |
1218 |
(setq byte-compile-unresolved-functions |
(push (list (car form) n) |
1219 |
(cons (list (car form) n) |
byte-compile-unresolved-functions)))))) |
|
byte-compile-unresolved-functions))))))) |
|
1220 |
|
|
1221 |
(defun byte-compile-format-warn (form) |
(defun byte-compile-format-warn (form) |
1222 |
"Warn if FORM is `format'-like with inconsistent args. |
"Warn if FORM is `format'-like with inconsistent args. |
1248 |
;; number of arguments. |
;; number of arguments. |
1249 |
(defun byte-compile-arglist-warn (form macrop) |
(defun byte-compile-arglist-warn (form macrop) |
1250 |
(let ((old (byte-compile-fdefinition (nth 1 form) macrop))) |
(let ((old (byte-compile-fdefinition (nth 1 form) macrop))) |
1251 |
(if old |
(if (and old (not (eq old t))) |
1252 |
(let ((sig1 (byte-compile-arglist-signature |
(let ((sig1 (byte-compile-arglist-signature |
1253 |
(if (eq 'lambda (car-safe old)) |
(if (eq 'lambda (car-safe old)) |
1254 |
(nth 1 old) |
(nth 1 old) |
2128 |
(eq (car (nth 1 form)) 'quote) |
(eq (car (nth 1 form)) 'quote) |
2129 |
(consp (cdr (nth 1 form))) |
(consp (cdr (nth 1 form))) |
2130 |
(symbolp (nth 1 (nth 1 form)))) |
(symbolp (nth 1 (nth 1 form)))) |
2131 |
(add-to-list 'byte-compile-function-environment |
(push (cons (nth 1 (nth 1 form)) |
2132 |
(cons (nth 1 (nth 1 form)) |
(cons 'autoload (cdr (cdr form)))) |
2133 |
(cons 'autoload (cdr (cdr form)))))) |
byte-compile-function-environment)) |
2134 |
(if (stringp (nth 3 form)) |
(if (stringp (nth 3 form)) |
2135 |
form |
form |
2136 |
;; No doc string, so we can compile this as a normal form. |
;; No doc string, so we can compile this as a normal form. |
3615 |
(byte-defop-compiler-1 defconst byte-compile-defvar) |
(byte-defop-compiler-1 defconst byte-compile-defvar) |
3616 |
(byte-defop-compiler-1 autoload) |
(byte-defop-compiler-1 autoload) |
3617 |
(byte-defop-compiler-1 lambda byte-compile-lambda-form) |
(byte-defop-compiler-1 lambda byte-compile-lambda-form) |
|
(byte-defop-compiler-1 defalias) |
|
3618 |
|
|
3619 |
(defun byte-compile-defun (form) |
(defun byte-compile-defun (form) |
3620 |
;; This is not used for file-level defuns with doc strings. |
;; This is not used for file-level defuns with doc strings. |
3716 |
(error "`lambda' used as function name is invalid")) |
(error "`lambda' used as function name is invalid")) |
3717 |
|
|
3718 |
;; Compile normally, but deal with warnings for the function being defined. |
;; Compile normally, but deal with warnings for the function being defined. |
3719 |
(defun byte-compile-defalias (form) |
(put 'defalias 'byte-hunk-handler 'byte-compile-file-form-defalias) |
3720 |
|
(defun byte-compile-file-form-defalias (form) |
3721 |
(if (and (consp (cdr form)) (consp (nth 1 form)) |
(if (and (consp (cdr form)) (consp (nth 1 form)) |
3722 |
(eq (car (nth 1 form)) 'quote) |
(eq (car (nth 1 form)) 'quote) |
3723 |
(consp (cdr (nth 1 form))) |
(consp (cdr (nth 1 form))) |
3724 |
(symbolp (nth 1 (nth 1 form))) |
(symbolp (nth 1 (nth 1 form)))) |
3725 |
(consp (nthcdr 2 form)) |
(let ((constant |
3726 |
(consp (nth 2 form)) |
(and (consp (nthcdr 2 form)) |
3727 |
(eq (car (nth 2 form)) 'quote) |
(consp (nth 2 form)) |
3728 |
(consp (cdr (nth 2 form))) |
(eq (car (nth 2 form)) 'quote) |
3729 |
(symbolp (nth 1 (nth 2 form)))) |
(consp (cdr (nth 2 form))) |
3730 |
(progn |
(symbolp (nth 1 (nth 2 form)))))) |
3731 |
(byte-compile-defalias-warn (nth 1 (nth 1 form))) |
(byte-compile-defalias-warn (nth 1 (nth 1 form))) |
3732 |
(setq byte-compile-function-environment |
(push (cons (nth 1 (nth 1 form)) |
3733 |
(cons (cons (nth 1 (nth 1 form)) |
(if constant (nth 1 (nth 2 form)) t)) |
3734 |
(nth 1 (nth 2 form))) |
byte-compile-function-environment))) |
|
byte-compile-function-environment)))) |
|
3735 |
(byte-compile-normal-call form)) |
(byte-compile-normal-call form)) |
3736 |
|
|
3737 |
;; Turn off warnings about prior calls to the function being defalias'd. |
;; Turn off warnings about prior calls to the function being defalias'd. |
3934 |
(while rest |
(while rest |
3935 |
(or (nth 1 (car rest)) |
(or (nth 1 (car rest)) |
3936 |
(null (setq f (car (car rest)))) |
(null (setq f (car (car rest)))) |
3937 |
(byte-compile-fdefinition f t) |
(functionp (byte-compile-fdefinition f t)) |
3938 |
(commandp (byte-compile-fdefinition f nil)) |
(commandp (byte-compile-fdefinition f nil)) |
3939 |
(setq uncalled (cons f uncalled))) |
(setq uncalled (cons f uncalled))) |
3940 |
(setq rest (cdr rest))) |
(setq rest (cdr rest))) |
4116 |
|
|
4117 |
(run-hooks 'bytecomp-load-hook) |
(run-hooks 'bytecomp-load-hook) |
4118 |
|
|
4119 |
;;; arch-tag: 9c97b0f0-8745-4571-bfc3-8dceb677292a |
;; arch-tag: 9c97b0f0-8745-4571-bfc3-8dceb677292a |
4120 |
;;; bytecomp.el ends here |
;;; bytecomp.el ends here |