comparison lisp/emacs-lisp/byte-opt.el @ 29580:2f88e6f0d32b

(byte-compile-log-lap-1) (byte-optimize-inline-handler, byte-optimize-form-code-walker) (byte-optimize-apply, end of file): Don't quote lambda.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 12 Jun 2000 05:06:37 +0000
parents 565418f2e425
children 038a08ffb9f8
comparison
equal deleted inserted replaced
29579:05016ef95d0f 29580:2f88e6f0d32b
36 ;; to get it there. 36 ;; to get it there.
37 ;; 37 ;;
38 38
39 ;; TO DO: 39 ;; TO DO:
40 ;; 40 ;;
41 ;; (apply '(lambda (x &rest y) ...) 1 (foo)) 41 ;; (apply (lambda (x &rest y) ...) 1 (foo))
42 ;; 42 ;;
43 ;; maintain a list of functions known not to access any global variables 43 ;; maintain a list of functions known not to access any global variables
44 ;; (actually, give them a 'dynamically-safe property) and then 44 ;; (actually, give them a 'dynamically-safe property) and then
45 ;; (let ( v1 v2 ... vM vN ) <...dynamically-safe...> ) ==> 45 ;; (let ( v1 v2 ... vM vN ) <...dynamically-safe...> ) ==>
46 ;; (let ( v1 v2 ... vM ) vN <...dynamically-safe...> ) 46 ;; (let ( v1 v2 ... vM ) vN <...dynamically-safe...> )
190 (if (aref byte-code-vector 0) 190 (if (aref byte-code-vector 0)
191 (error "The old version of the disassembler is loaded. Reload new-bytecomp as well.")) 191 (error "The old version of the disassembler is loaded. Reload new-bytecomp as well."))
192 (byte-compile-log-1 192 (byte-compile-log-1
193 (apply 'format format 193 (apply 'format format
194 (let (c a) 194 (let (c a)
195 (mapcar '(lambda (arg) 195 (mapcar (lambda (arg)
196 (if (not (consp arg)) 196 (if (not (consp arg))
197 (if (and (symbolp arg) 197 (if (and (symbolp arg)
198 (string-match "^byte-" (symbol-name arg))) 198 (string-match "^byte-" (symbol-name arg)))
199 (intern (substring (symbol-name arg) 5)) 199 (intern (substring (symbol-name arg) 5))
200 arg) 200 arg)
230 230
231 (defun byte-optimize-inline-handler (form) 231 (defun byte-optimize-inline-handler (form)
232 "byte-optimize-handler for the `inline' special-form." 232 "byte-optimize-handler for the `inline' special-form."
233 (cons 'progn 233 (cons 'progn
234 (mapcar 234 (mapcar
235 '(lambda (sexp) 235 (lambda (sexp)
236 (let ((fn (car-safe sexp))) 236 (let ((fn (car-safe sexp)))
237 (if (and (symbolp fn) 237 (if (and (symbolp fn)
238 (or (cdr (assq fn byte-compile-function-environment)) 238 (or (cdr (assq fn byte-compile-function-environment))
239 (and (fboundp fn) 239 (and (fboundp fn)
240 (not (or (cdr (assq fn byte-compile-macro-environment)) 240 (not (or (cdr (assq fn byte-compile-macro-environment))
383 ;; recursively enter the optimizer for the bindings and body 383 ;; recursively enter the optimizer for the bindings and body
384 ;; of a let or let*. This for depth-firstness: forms that 384 ;; of a let or let*. This for depth-firstness: forms that
385 ;; are more deeply nested are optimized first. 385 ;; are more deeply nested are optimized first.
386 (cons fn 386 (cons fn
387 (cons 387 (cons
388 (mapcar '(lambda (binding) 388 (mapcar (lambda (binding)
389 (if (symbolp binding) 389 (if (symbolp binding)
390 binding 390 binding
391 (if (cdr (cdr binding)) 391 (if (cdr (cdr binding))
392 (byte-compile-warn "Malformed let binding: `%s'" 392 (byte-compile-warn "Malformed let binding: `%s'"
393 (prin1-to-string binding))) 393 (prin1-to-string binding)))
395 (byte-optimize-form (nth 1 binding) nil)))) 395 (byte-optimize-form (nth 1 binding) nil))))
396 (nth 1 form)) 396 (nth 1 form))
397 (byte-optimize-body (cdr (cdr form)) for-effect)))) 397 (byte-optimize-body (cdr (cdr form)) for-effect))))
398 ((eq fn 'cond) 398 ((eq fn 'cond)
399 (cons fn 399 (cons fn
400 (mapcar '(lambda (clause) 400 (mapcar (lambda (clause)
401 (if (consp clause) 401 (if (consp clause)
402 (cons 402 (cons
403 (byte-optimize-form (car clause) nil) 403 (byte-optimize-form (car clause) nil)
404 (byte-optimize-body (cdr clause) for-effect)) 404 (byte-optimize-body (cdr clause) for-effect))
405 (byte-compile-warn "Malformed cond form: `%s'" 405 (byte-compile-warn "Malformed cond form: `%s'"
1023 (put 'atom 'byte-optimizer 'byte-compile-negation-optimizer) 1023 (put 'atom 'byte-optimizer 'byte-compile-negation-optimizer)
1024 (put 'nlistp 'byte-optimizer 'byte-compile-negation-optimizer) 1024 (put 'nlistp 'byte-optimizer 'byte-compile-negation-optimizer)
1025 1025
1026 1026
1027 (defun byte-optimize-funcall (form) 1027 (defun byte-optimize-funcall (form)
1028 ;; (funcall '(lambda ...) ...) ==> ((lambda ...) ...) 1028 ;; (funcall (lambda ...) ...) ==> ((lambda ...) ...)
1029 ;; (funcall 'foo ...) ==> (foo ...) 1029 ;; (funcall foo ...) ==> (foo ...)
1030 (let ((fn (nth 1 form))) 1030 (let ((fn (nth 1 form)))
1031 (if (memq (car-safe fn) '(quote function)) 1031 (if (memq (car-safe fn) '(quote function))
1032 (cons (nth 1 fn) (cdr (cdr form))) 1032 (cons (nth 1 fn) (cdr (cdr form)))
1033 form))) 1033 form)))
1034 1034
1040 (or (if (or (null last) 1040 (or (if (or (null last)
1041 (eq (car-safe last) 'quote)) 1041 (eq (car-safe last) 'quote))
1042 (if (listp (nth 1 last)) 1042 (if (listp (nth 1 last))
1043 (let ((butlast (nreverse (cdr (reverse (cdr (cdr form))))))) 1043 (let ((butlast (nreverse (cdr (reverse (cdr (cdr form)))))))
1044 (nconc (list 'funcall fn) butlast 1044 (nconc (list 'funcall fn) butlast
1045 (mapcar '(lambda (x) (list 'quote x)) (nth 1 last)))) 1045 (mapcar (lambda (x) (list 'quote x)) (nth 1 last))))
1046 (byte-compile-warn 1046 (byte-compile-warn
1047 "Last arg to apply can't be a literal atom: `%s'" 1047 "Last arg to apply can't be a literal atom: `%s'"
1048 (prin1-to-string last)) 1048 (prin1-to-string last))
1049 nil)) 1049 nil))
1050 form))) 1050 form)))
1931 (eval-when-compile 1931 (eval-when-compile
1932 (or (byte-code-function-p (symbol-function 'byte-optimize-form)) 1932 (or (byte-code-function-p (symbol-function 'byte-optimize-form))
1933 (assq 'byte-code (symbol-function 'byte-optimize-form)) 1933 (assq 'byte-code (symbol-function 'byte-optimize-form))
1934 (let ((byte-optimize nil) 1934 (let ((byte-optimize nil)
1935 (byte-compile-warnings nil)) 1935 (byte-compile-warnings nil))
1936 (mapcar '(lambda (x) 1936 (mapcar (lambda (x)
1937 (or noninteractive (message "compiling %s..." x)) 1937 (or noninteractive (message "compiling %s..." x))
1938 (byte-compile x) 1938 (byte-compile x)
1939 (or noninteractive (message "compiling %s...done" x))) 1939 (or noninteractive (message "compiling %s...done" x)))
1940 '(byte-optimize-form 1940 '(byte-optimize-form
1941 byte-optimize-body 1941 byte-optimize-body
1942 byte-optimize-predicate 1942 byte-optimize-predicate
1943 byte-optimize-binary-predicate 1943 byte-optimize-binary-predicate
1944 ;; Inserted some more than necessary, to speed it up. 1944 ;; Inserted some more than necessary, to speed it up.