diff options
| author | Dave Love | 2002-11-27 12:25:11 +0000 |
|---|---|---|
| committer | Dave Love | 2002-11-27 12:25:11 +0000 |
| commit | b7b95a1e50e5f8699a35f7c035e5e9bdd3592ddf (patch) | |
| tree | 83be3b533d811932cfe3b7d85509bce01df15680 | |
| parent | 5ba511bddffbc625bec5b9a373edb030a1dc672f (diff) | |
| download | emacs-b7b95a1e50e5f8699a35f7c035e5e9bdd3592ddf.tar.gz emacs-b7b95a1e50e5f8699a35f7c035e5e9bdd3592ddf.zip | |
Move `predicates for analyzing Lisp
forms' block to top (before uses).
(help-fns): Don't require at top level. (Recursively.)
(cl-transform-lambda): Require help-fns.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 170 |
2 files changed, 91 insertions, 86 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a95d0aa6eeb..82c220c7d53 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2002-11-27 Dave Love <fx@gnu.org> | ||
| 2 | |||
| 3 | * emacs-lisp/cl-macs.el: Move `predicates for analyzing Lisp | ||
| 4 | forms' block to top (before uses). | ||
| 5 | (help-fns): Don't require at top level. (Recursively.) | ||
| 6 | (cl-transform-lambda): Require help-fns. | ||
| 7 | |||
| 1 | 2002-11-26 Dave Love <fx@gnu.org> | 8 | 2002-11-26 Dave Love <fx@gnu.org> |
| 2 | 9 | ||
| 3 | * language/european.el (encode-mac-roman): Deal with unencodable | 10 | * language/european.el (encode-mac-roman): Deal with unencodable |
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index ce5055ba087..ddc0572ad52 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el | |||
| @@ -44,8 +44,6 @@ | |||
| 44 | 44 | ||
| 45 | ;;; Code: | 45 | ;;; Code: |
| 46 | 46 | ||
| 47 | (require 'help-fns) ;For help-add-fundoc-usage. | ||
| 48 | |||
| 49 | (or (memq 'cl-19 features) | 47 | (or (memq 'cl-19 features) |
| 50 | (error "Tried to load `cl-macs' before `cl'!")) | 48 | (error "Tried to load `cl-macs' before `cl'!")) |
| 51 | 49 | ||
| @@ -80,6 +78,89 @@ | |||
| 80 | (run-hooks 'cl-hack-bytecomp-hook)) | 78 | (run-hooks 'cl-hack-bytecomp-hook)) |
| 81 | 79 | ||
| 82 | 80 | ||
| 81 | ;;; Some predicates for analyzing Lisp forms. These are used by various | ||
| 82 | ;;; macro expanders to optimize the results in certain common cases. | ||
| 83 | |||
| 84 | (defconst cl-simple-funcs '(car cdr nth aref elt if and or + - 1+ 1- min max | ||
| 85 | car-safe cdr-safe progn prog1 prog2)) | ||
| 86 | (defconst cl-safe-funcs '(* / % length memq list vector vectorp | ||
| 87 | < > <= >= = error)) | ||
| 88 | |||
| 89 | ;;; Check if no side effects, and executes quickly. | ||
| 90 | (defun cl-simple-expr-p (x &optional size) | ||
| 91 | (or size (setq size 10)) | ||
| 92 | (if (and (consp x) (not (memq (car x) '(quote function function*)))) | ||
| 93 | (and (symbolp (car x)) | ||
| 94 | (or (memq (car x) cl-simple-funcs) | ||
| 95 | (get (car x) 'side-effect-free)) | ||
| 96 | (progn | ||
| 97 | (setq size (1- size)) | ||
| 98 | (while (and (setq x (cdr x)) | ||
| 99 | (setq size (cl-simple-expr-p (car x) size)))) | ||
| 100 | (and (null x) (>= size 0) size))) | ||
| 101 | (and (> size 0) (1- size)))) | ||
| 102 | |||
| 103 | (defun cl-simple-exprs-p (xs) | ||
| 104 | (while (and xs (cl-simple-expr-p (car xs))) | ||
| 105 | (setq xs (cdr xs))) | ||
| 106 | (not xs)) | ||
| 107 | |||
| 108 | ;;; Check if no side effects. | ||
| 109 | (defun cl-safe-expr-p (x) | ||
| 110 | (or (not (and (consp x) (not (memq (car x) '(quote function function*))))) | ||
| 111 | (and (symbolp (car x)) | ||
| 112 | (or (memq (car x) cl-simple-funcs) | ||
| 113 | (memq (car x) cl-safe-funcs) | ||
| 114 | (get (car x) 'side-effect-free)) | ||
| 115 | (progn | ||
| 116 | (while (and (setq x (cdr x)) (cl-safe-expr-p (car x)))) | ||
| 117 | (null x))))) | ||
| 118 | |||
| 119 | ;;; Check if constant (i.e., no side effects or dependencies). | ||
| 120 | (defun cl-const-expr-p (x) | ||
| 121 | (cond ((consp x) | ||
| 122 | (or (eq (car x) 'quote) | ||
| 123 | (and (memq (car x) '(function function*)) | ||
| 124 | (or (symbolp (nth 1 x)) | ||
| 125 | (and (eq (car-safe (nth 1 x)) 'lambda) 'func))))) | ||
| 126 | ((symbolp x) (and (memq x '(nil t)) t)) | ||
| 127 | (t t))) | ||
| 128 | |||
| 129 | (defun cl-const-exprs-p (xs) | ||
| 130 | (while (and xs (cl-const-expr-p (car xs))) | ||
| 131 | (setq xs (cdr xs))) | ||
| 132 | (not xs)) | ||
| 133 | |||
| 134 | (defun cl-const-expr-val (x) | ||
| 135 | (and (eq (cl-const-expr-p x) t) (if (consp x) (nth 1 x) x))) | ||
| 136 | |||
| 137 | (defun cl-expr-access-order (x v) | ||
| 138 | (if (cl-const-expr-p x) v | ||
| 139 | (if (consp x) | ||
| 140 | (progn | ||
| 141 | (while (setq x (cdr x)) (setq v (cl-expr-access-order (car x) v))) | ||
| 142 | v) | ||
| 143 | (if (eq x (car v)) (cdr v) '(t))))) | ||
| 144 | |||
| 145 | ;;; Count number of times X refers to Y. Return nil for 0 times. | ||
| 146 | (defun cl-expr-contains (x y) | ||
| 147 | (cond ((equal y x) 1) | ||
| 148 | ((and (consp x) (not (memq (car-safe x) '(quote function function*)))) | ||
| 149 | (let ((sum 0)) | ||
| 150 | (while x | ||
| 151 | (setq sum (+ sum (or (cl-expr-contains (pop x) y) 0)))) | ||
| 152 | (and (> sum 0) sum))) | ||
| 153 | (t nil))) | ||
| 154 | |||
| 155 | (defun cl-expr-contains-any (x y) | ||
| 156 | (while (and y (not (cl-expr-contains x (car y)))) (pop y)) | ||
| 157 | y) | ||
| 158 | |||
| 159 | ;;; Check whether X may depend on any of the symbols in Y. | ||
| 160 | (defun cl-expr-depends-p (x y) | ||
| 161 | (and (not (cl-const-expr-p x)) | ||
| 162 | (or (not (cl-safe-expr-p x)) (cl-expr-contains-any x y)))) | ||
| 163 | |||
| 83 | ;;; Symbols. | 164 | ;;; Symbols. |
| 84 | 165 | ||
| 85 | (defvar *gensym-counter*) | 166 | (defvar *gensym-counter*) |
| @@ -183,6 +264,7 @@ ARGLIST allows full Common Lisp conventions." | |||
| 183 | (nconc (nreverse simple-args) | 264 | (nconc (nreverse simple-args) |
| 184 | (list '&rest (car (pop bind-lets)))) | 265 | (list '&rest (car (pop bind-lets)))) |
| 185 | (nconc (let ((hdr (nreverse header))) | 266 | (nconc (let ((hdr (nreverse header))) |
| 267 | (require 'help-fns) | ||
| 186 | (cons (help-add-fundoc-usage | 268 | (cons (help-add-fundoc-usage |
| 187 | (if (stringp (car hdr)) (pop hdr)) orig-args) | 269 | (if (stringp (car hdr)) (pop hdr)) orig-args) |
| 188 | hdr)) | 270 | hdr)) |
| @@ -2357,90 +2439,6 @@ Otherwise, return result of last FORM." | |||
| 2357 | `(condition-case nil (progn ,@body) (error nil))) | 2439 | `(condition-case nil (progn ,@body) (error nil))) |
| 2358 | 2440 | ||
| 2359 | 2441 | ||
| 2360 | ;;; Some predicates for analyzing Lisp forms. These are used by various | ||
| 2361 | ;;; macro expanders to optimize the results in certain common cases. | ||
| 2362 | |||
| 2363 | (defconst cl-simple-funcs '(car cdr nth aref elt if and or + - 1+ 1- min max | ||
| 2364 | car-safe cdr-safe progn prog1 prog2)) | ||
| 2365 | (defconst cl-safe-funcs '(* / % length memq list vector vectorp | ||
| 2366 | < > <= >= = error)) | ||
| 2367 | |||
| 2368 | ;;; Check if no side effects, and executes quickly. | ||
| 2369 | (defun cl-simple-expr-p (x &optional size) | ||
| 2370 | (or size (setq size 10)) | ||
| 2371 | (if (and (consp x) (not (memq (car x) '(quote function function*)))) | ||
| 2372 | (and (symbolp (car x)) | ||
| 2373 | (or (memq (car x) cl-simple-funcs) | ||
| 2374 | (get (car x) 'side-effect-free)) | ||
| 2375 | (progn | ||
| 2376 | (setq size (1- size)) | ||
| 2377 | (while (and (setq x (cdr x)) | ||
| 2378 | (setq size (cl-simple-expr-p (car x) size)))) | ||
| 2379 | (and (null x) (>= size 0) size))) | ||
| 2380 | (and (> size 0) (1- size)))) | ||
| 2381 | |||
| 2382 | (defun cl-simple-exprs-p (xs) | ||
| 2383 | (while (and xs (cl-simple-expr-p (car xs))) | ||
| 2384 | (setq xs (cdr xs))) | ||
| 2385 | (not xs)) | ||
| 2386 | |||
| 2387 | ;;; Check if no side effects. | ||
| 2388 | (defun cl-safe-expr-p (x) | ||
| 2389 | (or (not (and (consp x) (not (memq (car x) '(quote function function*))))) | ||
| 2390 | (and (symbolp (car x)) | ||
| 2391 | (or (memq (car x) cl-simple-funcs) | ||
| 2392 | (memq (car x) cl-safe-funcs) | ||
| 2393 | (get (car x) 'side-effect-free)) | ||
| 2394 | (progn | ||
| 2395 | (while (and (setq x (cdr x)) (cl-safe-expr-p (car x)))) | ||
| 2396 | (null x))))) | ||
| 2397 | |||
| 2398 | ;;; Check if constant (i.e., no side effects or dependencies). | ||
| 2399 | (defun cl-const-expr-p (x) | ||
| 2400 | (cond ((consp x) | ||
| 2401 | (or (eq (car x) 'quote) | ||
| 2402 | (and (memq (car x) '(function function*)) | ||
| 2403 | (or (symbolp (nth 1 x)) | ||
| 2404 | (and (eq (car-safe (nth 1 x)) 'lambda) 'func))))) | ||
| 2405 | ((symbolp x) (and (memq x '(nil t)) t)) | ||
| 2406 | (t t))) | ||
| 2407 | |||
| 2408 | (defun cl-const-exprs-p (xs) | ||
| 2409 | (while (and xs (cl-const-expr-p (car xs))) | ||
| 2410 | (setq xs (cdr xs))) | ||
| 2411 | (not xs)) | ||
| 2412 | |||
| 2413 | (defun cl-const-expr-val (x) | ||
| 2414 | (and (eq (cl-const-expr-p x) t) (if (consp x) (nth 1 x) x))) | ||
| 2415 | |||
| 2416 | (defun cl-expr-access-order (x v) | ||
| 2417 | (if (cl-const-expr-p x) v | ||
| 2418 | (if (consp x) | ||
| 2419 | (progn | ||
| 2420 | (while (setq x (cdr x)) (setq v (cl-expr-access-order (car x) v))) | ||
| 2421 | v) | ||
| 2422 | (if (eq x (car v)) (cdr v) '(t))))) | ||
| 2423 | |||
| 2424 | ;;; Count number of times X refers to Y. Return nil for 0 times. | ||
| 2425 | (defun cl-expr-contains (x y) | ||
| 2426 | (cond ((equal y x) 1) | ||
| 2427 | ((and (consp x) (not (memq (car-safe x) '(quote function function*)))) | ||
| 2428 | (let ((sum 0)) | ||
| 2429 | (while x | ||
| 2430 | (setq sum (+ sum (or (cl-expr-contains (pop x) y) 0)))) | ||
| 2431 | (and (> sum 0) sum))) | ||
| 2432 | (t nil))) | ||
| 2433 | |||
| 2434 | (defun cl-expr-contains-any (x y) | ||
| 2435 | (while (and y (not (cl-expr-contains x (car y)))) (pop y)) | ||
| 2436 | y) | ||
| 2437 | |||
| 2438 | ;;; Check whether X may depend on any of the symbols in Y. | ||
| 2439 | (defun cl-expr-depends-p (x y) | ||
| 2440 | (and (not (cl-const-expr-p x)) | ||
| 2441 | (or (not (cl-safe-expr-p x)) (cl-expr-contains-any x y)))) | ||
| 2442 | |||
| 2443 | |||
| 2444 | ;;; Compiler macros. | 2442 | ;;; Compiler macros. |
| 2445 | 2443 | ||
| 2446 | (defmacro define-compiler-macro (func args &rest body) | 2444 | (defmacro define-compiler-macro (func args &rest body) |