Mercurial > emacs
comparison lisp/emacs-lisp/byte-opt.el @ 83676:27d11c1d4e46
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 857-862)
- Update from CVS
- Merge from emacs--rel--22
- Update from CVS: lisp/emacs-lisp/avl-tree.el: New file.
* emacs--rel--22 (patch 97-100)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 246-247)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--multi-tty--0--patch-38
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 27 Aug 2007 09:21:49 +0000 |
parents | 92ccd83174e6 |
children | d18b96e2d51f b83d0dadb2a7 |
comparison
equal
deleted
inserted
replaced
83675:67601f702028 | 83676:27d11c1d4e46 |
---|---|
29 | 29 |
30 ;; ======================================================================== | 30 ;; ======================================================================== |
31 ;; "No matter how hard you try, you can't make a racehorse out of a pig. | 31 ;; "No matter how hard you try, you can't make a racehorse out of a pig. |
32 ;; You can, however, make a faster pig." | 32 ;; You can, however, make a faster pig." |
33 ;; | 33 ;; |
34 ;; Or, to put it another way, the emacs byte compiler is a VW Bug. This code | 34 ;; Or, to put it another way, the Emacs byte compiler is a VW Bug. This code |
35 ;; makes it be a VW Bug with fuel injection and a turbocharger... You're | 35 ;; makes it be a VW Bug with fuel injection and a turbocharger... You're |
36 ;; still not going to make it go faster than 70 mph, but it might be easier | 36 ;; still not going to make it go faster than 70 mph, but it might be easier |
37 ;; to get it there. | 37 ;; to get it there. |
38 ;; | 38 ;; |
39 | 39 |
1012 (cons (car form) (cdr (cdr form))))) | 1012 (cons (car form) (cdr (cdr form))))) |
1013 form)) | 1013 form)) |
1014 form)) | 1014 form)) |
1015 | 1015 |
1016 (defun byte-optimize-if (form) | 1016 (defun byte-optimize-if (form) |
1017 ;; (if (progn <insts> <test>) <rest>) ==> (progn <insts> (if <test> <rest>)) | |
1017 ;; (if <true-constant> <then> <else...>) ==> <then> | 1018 ;; (if <true-constant> <then> <else...>) ==> <then> |
1018 ;; (if <false-constant> <then> <else...>) ==> (progn <else...>) | 1019 ;; (if <false-constant> <then> <else...>) ==> (progn <else...>) |
1019 ;; (if <test> nil <else...>) ==> (if (not <test>) (progn <else...>)) | 1020 ;; (if <test> nil <else...>) ==> (if (not <test>) (progn <else...>)) |
1020 ;; (if <test> <then> nil) ==> (if <test> <then>) | 1021 ;; (if <test> <then> nil) ==> (if <test> <then>) |
1021 (let ((clause (nth 1 form))) | 1022 (let ((clause (nth 1 form))) |
1022 (cond ((byte-compile-trueconstp clause) | 1023 (cond ((and (eq (car-safe clause) 'progn) |
1024 ;; `clause' is a proper list. | |
1025 (null (cdr (last clause)))) | |
1026 (if (null (cddr clause)) | |
1027 ;; A trivial `progn'. | |
1028 (byte-optimize-if `(if ,(cadr clause) ,@(nthcdr 2 form))) | |
1029 (nconc (butlast clause) | |
1030 (list | |
1031 (byte-optimize-if | |
1032 `(if ,(car (last clause)) ,@(nthcdr 2 form))))))) | |
1033 ((byte-compile-trueconstp clause) | |
1023 (nth 2 form)) | 1034 (nth 2 form)) |
1024 ((null clause) | 1035 ((null clause) |
1025 (if (nthcdr 4 form) | 1036 (if (nthcdr 4 form) |
1026 (cons 'progn (nthcdr 3 form)) | 1037 (cons 'progn (nthcdr 3 form)) |
1027 (nth 3 form))) | 1038 (nth 3 form))) |
1133 ;; optimize string-as-unibyte, string-as-multibyte, string-make-unibyte, | 1144 ;; optimize string-as-unibyte, string-as-multibyte, string-make-unibyte, |
1134 ;; string-make-multibyte for constant args. | 1145 ;; string-make-multibyte for constant args. |
1135 | 1146 |
1136 (put 'featurep 'byte-optimizer 'byte-optimize-featurep) | 1147 (put 'featurep 'byte-optimizer 'byte-optimize-featurep) |
1137 (defun byte-optimize-featurep (form) | 1148 (defun byte-optimize-featurep (form) |
1138 ;; Emacs-21's byte-code doesn't run under XEmacs anyway, so we can | 1149 ;; Emacs-21's byte-code doesn't run under XEmacs or SXEmacs anyway, so we |
1139 ;; safely optimize away this test. | 1150 ;; can safely optimize away this test. |
1140 (if (equal '((quote xemacs)) (cdr-safe form)) | 1151 (if (member (cdr-safe form) '((quote xemacs) (quote sxemacs))) |
1141 nil | 1152 nil |
1142 form)) | 1153 form)) |
1143 | 1154 |
1144 (put 'set 'byte-optimizer 'byte-optimize-set) | 1155 (put 'set 'byte-optimizer 'byte-optimize-set) |
1145 (defun byte-optimize-set (form) | 1156 (defun byte-optimize-set (form) |
1324 ;; and by the disassembler. | 1335 ;; and by the disassembler. |
1325 ;; | 1336 ;; |
1326 ;; This list contains numbers, which are pc values, | 1337 ;; This list contains numbers, which are pc values, |
1327 ;; before each instruction. | 1338 ;; before each instruction. |
1328 (defun byte-decompile-bytecode (bytes constvec) | 1339 (defun byte-decompile-bytecode (bytes constvec) |
1329 "Turns BYTECODE into lapcode, referring to CONSTVEC." | 1340 "Turn BYTECODE into lapcode, referring to CONSTVEC." |
1330 (let ((byte-compile-constants nil) | 1341 (let ((byte-compile-constants nil) |
1331 (byte-compile-variables nil) | 1342 (byte-compile-variables nil) |
1332 (byte-compile-tag-number 0)) | 1343 (byte-compile-tag-number 0)) |
1333 (byte-decompile-bytecode-1 bytes constvec))) | 1344 (byte-decompile-bytecode-1 bytes constvec))) |
1334 | 1345 |