Mercurial > hg > xemacs-beta
comparison lisp/byte-optimize.el @ 444:576fb035e263 r21-2-37
Import from CVS: tag r21-2-37
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:36:19 +0200 |
parents | abe6d1db359e |
children | 1ccc32a20af4 |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
21 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
22 ;; along with XEmacs; see the file COPYING. If not, write to the | 22 ;; along with XEmacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
24 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02111-1307, USA. |
25 | 25 |
26 ;;; Synched up with: FSF 19.30. | 26 ;;; Synched up with: FSF 20.7. |
27 | 27 |
28 ;;; Commentary: | 28 ;;; Commentary: |
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. |
175 ;; can increase this way they should be "simple". Compare: | 175 ;; can increase this way they should be "simple". Compare: |
176 | 176 |
177 ;;(disassemble #'(lambda (x) (eq (if (point) 'a 'b) 'c))) | 177 ;;(disassemble #'(lambda (x) (eq (if (point) 'a 'b) 'c))) |
178 ;;(disassemble #'(lambda (x) (if (point) (eq 'a 'c) (eq 'b 'c)))) | 178 ;;(disassemble #'(lambda (x) (if (point) (eq 'a 'c) (eq 'b 'c)))) |
179 | 179 |
180 ;; (car (cons A B)) -> (progn B A) | 180 ;; (car (cons A B)) -> (prog1 A B) |
181 ;;(disassemble #'(lambda (x) (car (cons (foo) 42)))) | 181 ;;(disassemble #'(lambda (x) (car (cons (foo) 42)))) |
182 | 182 |
183 ;; (cdr (cons A B)) -> (progn A B) | 183 ;; (cdr (cons A B)) -> (progn A B) |
184 ;;(disassemble #'(lambda (x) (cdr (cons 42 (foo))))) | 184 ;;(disassemble #'(lambda (x) (cdr (cons 42 (foo))))) |
185 | 185 |
186 ;; (car (list A B ...)) -> (progn B ... A) | 186 ;; (car (list A B ...)) -> (prog1 A ... B) |
187 ;;(disassemble #'(lambda (x) (car (list (foo) 42 (bar))))) | 187 ;;(disassemble #'(lambda (x) (car (list (foo) 42 (bar))))) |
188 | 188 |
189 ;; (cdr (list A B ...)) -> (progn A (list B ...)) | 189 ;; (cdr (list A B ...)) -> (progn A (list B ...)) |
190 ;;(disassemble #'(lambda (x) (cdr (list 42 (foo) (bar))))) | 190 ;;(disassemble #'(lambda (x) (cdr (list 42 (foo) (bar))))) |
191 | 191 |
859 (byte-compile-warn "identity called with %d arg%s, but requires 1" | 859 (byte-compile-warn "identity called with %d arg%s, but requires 1" |
860 (length (cdr form)) | 860 (length (cdr form)) |
861 (if (= 1 (length (cdr form))) "" "s")) | 861 (if (= 1 (length (cdr form))) "" "s")) |
862 form)) | 862 form)) |
863 | 863 |
864 (defun byte-optimize-car (form) | |
865 (let ((arg (cadr form))) | |
866 (cond | |
867 ((and (byte-compile-trueconstp arg) | |
868 (not (and (consp arg) | |
869 (eq (car arg) 'quote) | |
870 (listp (cadr arg))))) | |
871 (byte-compile-warn | |
872 "taking car of a constant: %s" arg) | |
873 form) | |
874 ((and (eq (car-safe arg) 'cons) | |
875 (eq (length arg) 3)) | |
876 `(prog1 ,(nth 1 arg) ,(nth 2 arg))) | |
877 ((eq (car-safe arg) 'list) | |
878 `(prog1 ,@(cdr arg))) | |
879 (t | |
880 (byte-optimize-predicate form))))) | |
881 | |
882 (defun byte-optimize-cdr (form) | |
883 (let ((arg (cadr form))) | |
884 (cond | |
885 ((and (byte-compile-trueconstp arg) | |
886 (not (and (consp arg) | |
887 (eq (car arg) 'quote) | |
888 (listp (cadr arg))))) | |
889 (byte-compile-warn | |
890 "taking cdr of a constant: %s" arg) | |
891 form) | |
892 ((and (eq (car-safe arg) 'cons) | |
893 (eq (length arg) 3)) | |
894 `(progn ,(nth 1 arg) ,(nth 2 arg))) | |
895 ((eq (car-safe arg) 'list) | |
896 (if (> (length arg) 2) | |
897 `(progn ,(cadr arg) (list ,@(cddr arg))) | |
898 (cadr arg))) | |
899 (t | |
900 (byte-optimize-predicate form))))) | |
901 | |
864 (put 'identity 'byte-optimizer 'byte-optimize-identity) | 902 (put 'identity 'byte-optimizer 'byte-optimize-identity) |
865 | 903 |
866 (put '+ 'byte-optimizer 'byte-optimize-plus) | 904 (put '+ 'byte-optimizer 'byte-optimize-plus) |
867 (put '* 'byte-optimizer 'byte-optimize-multiply) | 905 (put '* 'byte-optimizer 'byte-optimize-multiply) |
868 (put '- 'byte-optimizer 'byte-optimize-minus) | 906 (put '- 'byte-optimizer 'byte-optimize-minus) |
897 (put 'logand 'byte-optimizer 'byte-optimize-logmumble) | 935 (put 'logand 'byte-optimizer 'byte-optimize-logmumble) |
898 (put 'logior 'byte-optimizer 'byte-optimize-logmumble) | 936 (put 'logior 'byte-optimizer 'byte-optimize-logmumble) |
899 (put 'logxor 'byte-optimizer 'byte-optimize-logmumble) | 937 (put 'logxor 'byte-optimizer 'byte-optimize-logmumble) |
900 (put 'lognot 'byte-optimizer 'byte-optimize-predicate) | 938 (put 'lognot 'byte-optimizer 'byte-optimize-predicate) |
901 | 939 |
902 (put 'car 'byte-optimizer 'byte-optimize-predicate) | 940 (put 'car 'byte-optimizer 'byte-optimize-car) |
903 (put 'cdr 'byte-optimizer 'byte-optimize-predicate) | 941 (put 'cdr 'byte-optimizer 'byte-optimize-cdr) |
904 (put 'car-safe 'byte-optimizer 'byte-optimize-predicate) | 942 (put 'car-safe 'byte-optimizer 'byte-optimize-predicate) |
905 (put 'cdr-safe 'byte-optimizer 'byte-optimize-predicate) | 943 (put 'cdr-safe 'byte-optimizer 'byte-optimize-predicate) |
906 | 944 |
907 | 945 |
908 ;; I'm not convinced that this is necessary. Doesn't the optimizer loop | 946 ;; I'm not convinced that this is necessary. Doesn't the optimizer loop |
1108 (byte-optimize-predicate form) | 1146 (byte-optimize-predicate form) |
1109 (let ((count (nth 1 form))) | 1147 (let ((count (nth 1 form))) |
1110 (setq form (nth 2 form)) | 1148 (setq form (nth 2 form)) |
1111 (while (>= (setq count (1- count)) 0) | 1149 (while (>= (setq count (1- count)) 0) |
1112 (setq form (list 'cdr form))) | 1150 (setq form (list 'cdr form))) |
1151 form))) | |
1152 | |
1153 (put 'concat 'byte-optimizer 'byte-optimize-concat) | |
1154 (defun byte-optimize-concat (form) | |
1155 (let ((args (cdr form)) | |
1156 (constant t)) | |
1157 (while (and args constant) | |
1158 (or (byte-compile-constp (car args)) | |
1159 (setq constant nil)) | |
1160 (setq args (cdr args))) | |
1161 (if constant | |
1162 (eval form) | |
1113 form))) | 1163 form))) |
1114 | 1164 |
1115 ;;; enumerating those functions which need not be called if the returned | 1165 ;;; enumerating those functions which need not be called if the returned |
1116 ;;; value is not used. That is, something like | 1166 ;;; value is not used. That is, something like |
1117 ;;; (progn (list (something-with-side-effects) (yow)) | 1167 ;;; (progn (list (something-with-side-effects) (yow)) |
1179 extent-live-p floatp framep frame-live-p | 1229 extent-live-p floatp framep frame-live-p |
1180 get-largest-window get-lru-window | 1230 get-largest-window get-lru-window |
1181 hash-table-p | 1231 hash-table-p |
1182 identity ignore integerp integer-or-marker-p interactive-p | 1232 identity ignore integerp integer-or-marker-p interactive-p |
1183 invocation-directory invocation-name | 1233 invocation-directory invocation-name |
1184 ;; keymapp may autoload in XEmacs, so not on this list! | 1234 keymapp list listp |
1185 list listp | |
1186 make-marker mark mark-marker markerp memory-limit minibuffer-window | 1235 make-marker mark mark-marker markerp memory-limit minibuffer-window |
1187 ;; mouse-movement-p not in XEmacs | 1236 ;; mouse-movement-p not in XEmacs |
1188 natnump nlistp not null number-or-marker-p numberp | 1237 natnump nlistp not null number-or-marker-p numberp |
1189 one-window-p ;; overlayp not in XEmacs | 1238 one-window-p ;; overlayp not in XEmacs |
1190 point point-marker point-min point-max processp | 1239 point point-marker point-min point-max processp |
1370 byte-goto-if-not-nil-else-pop)) | 1419 byte-goto-if-not-nil-else-pop)) |
1371 | 1420 |
1372 (defconst byte-after-unbind-ops | 1421 (defconst byte-after-unbind-ops |
1373 '(byte-constant byte-dup | 1422 '(byte-constant byte-dup |
1374 byte-symbolp byte-consp byte-stringp byte-listp byte-numberp byte-integerp | 1423 byte-symbolp byte-consp byte-stringp byte-listp byte-numberp byte-integerp |
1375 byte-eq byte-equal byte-not | 1424 byte-eq byte-not |
1376 byte-cons byte-list1 byte-list2 ; byte-list3 byte-list4 | 1425 byte-cons byte-list1 byte-list2 ; byte-list3 byte-list4 |
1377 byte-interactive-p) | 1426 byte-interactive-p) |
1378 ;; How about other side-effect-free-ops? Is it safe to move an | 1427 ;; How about other side-effect-free-ops? Is it safe to move an |
1379 ;; error invocation (such as from nth) out of an unwind-protect? | 1428 ;; error invocation (such as from nth) out of an unwind-protect? |
1429 ;; No, it is not, because the unwind-protect forms can alter | |
1430 ;; the inside of the object to which nth would apply. | |
1431 ;; For the same reason, byte-equal was deleted from this list. | |
1380 "Byte-codes that can be moved past an unbind.") | 1432 "Byte-codes that can be moved past an unbind.") |
1381 | 1433 |
1382 (defconst byte-compile-side-effect-and-error-free-ops | 1434 (defconst byte-compile-side-effect-and-error-free-ops |
1383 '(byte-constant byte-dup byte-symbolp byte-consp byte-stringp byte-listp | 1435 '(byte-constant byte-dup byte-symbolp byte-consp byte-stringp byte-listp |
1384 byte-integerp byte-numberp byte-eq byte-equal byte-not byte-car-safe | 1436 byte-integerp byte-numberp byte-eq byte-equal byte-not byte-car-safe |