Mercurial > emacs
comparison lisp/emacs-lisp/cl-macs.el @ 111405:942097a71997
Silence cl-macs.el compilation.
* lisp/emacs-lisp/cl-macs.el (loop): Give local variable args a prefix.
(cl-parse-loop-clause, cl-loop-handle-accum): Update for above change.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 05 Nov 2010 00:34:45 -0700 |
parents | c403c2e0a620 |
children | 7094295b2a61 |
comparison
equal
deleted
inserted
replaced
111404:b8abad9fb36c | 111405:942097a71997 |
---|---|
637 (list 'cl-block-throw (list 'quote name2) result))) | 637 (list 'cl-block-throw (list 'quote name2) result))) |
638 | 638 |
639 | 639 |
640 ;;; The "loop" macro. | 640 ;;; The "loop" macro. |
641 | 641 |
642 (defvar args) (defvar loop-accum-var) (defvar loop-accum-vars) | 642 (defvar loop-args) (defvar loop-accum-var) (defvar loop-accum-vars) |
643 (defvar loop-bindings) (defvar loop-body) (defvar loop-destr-temps) | 643 (defvar loop-bindings) (defvar loop-body) (defvar loop-destr-temps) |
644 (defvar loop-finally) (defvar loop-finish-flag) (defvar loop-first-flag) | 644 (defvar loop-finally) (defvar loop-finish-flag) (defvar loop-first-flag) |
645 (defvar loop-initially) (defvar loop-map-form) (defvar loop-name) | 645 (defvar loop-initially) (defvar loop-map-form) (defvar loop-name) |
646 (defvar loop-result) (defvar loop-result-explicit) | 646 (defvar loop-result) (defvar loop-result-explicit) |
647 (defvar loop-result-var) (defvar loop-steps) (defvar loop-symbol-macs) | 647 (defvar loop-result-var) (defvar loop-steps) (defvar loop-symbol-macs) |
648 | 648 |
649 ;;;###autoload | 649 ;;;###autoload |
650 (defmacro loop (&rest args) | 650 (defmacro loop (&rest loop-args) |
651 "The Common Lisp `loop' macro. | 651 "The Common Lisp `loop' macro. |
652 Valid clauses are: | 652 Valid clauses are: |
653 for VAR from/upfrom/downfrom NUM to/upto/downto/above/below NUM by NUM, | 653 for VAR from/upfrom/downfrom NUM to/upto/downto/above/below NUM by NUM, |
654 for VAR in LIST by FUNC, for VAR on LIST by FUNC, for VAR = INIT then EXPR, | 654 for VAR in LIST by FUNC, for VAR on LIST by FUNC, for VAR = INIT then EXPR, |
655 for VAR across ARRAY, repeat NUM, with VAR = INIT, while COND, until COND, | 655 for VAR across ARRAY, repeat NUM, with VAR = INIT, while COND, until COND, |
660 unless COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...], | 660 unless COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...], |
661 do EXPRS..., initially EXPRS..., finally EXPRS..., return EXPR, | 661 do EXPRS..., initially EXPRS..., finally EXPRS..., return EXPR, |
662 finally return EXPR, named NAME. | 662 finally return EXPR, named NAME. |
663 | 663 |
664 \(fn CLAUSE...)" | 664 \(fn CLAUSE...)" |
665 (if (not (memq t (mapcar 'symbolp (delq nil (delq t (copy-list args)))))) | 665 (if (not (memq t (mapcar 'symbolp (delq nil (delq t (copy-list loop-args)))))) |
666 (list 'block nil (list* 'while t args)) | 666 (list 'block nil (list* 'while t loop-args)) |
667 (let ((loop-name nil) (loop-bindings nil) | 667 (let ((loop-name nil) (loop-bindings nil) |
668 (loop-body nil) (loop-steps nil) | 668 (loop-body nil) (loop-steps nil) |
669 (loop-result nil) (loop-result-explicit nil) | 669 (loop-result nil) (loop-result-explicit nil) |
670 (loop-result-var nil) (loop-finish-flag nil) | 670 (loop-result-var nil) (loop-finish-flag nil) |
671 (loop-accum-var nil) (loop-accum-vars nil) | 671 (loop-accum-var nil) (loop-accum-vars nil) |
672 (loop-initially nil) (loop-finally nil) | 672 (loop-initially nil) (loop-finally nil) |
673 (loop-map-form nil) (loop-first-flag nil) | 673 (loop-map-form nil) (loop-first-flag nil) |
674 (loop-destr-temps nil) (loop-symbol-macs nil)) | 674 (loop-destr-temps nil) (loop-symbol-macs nil)) |
675 (setq args (append args '(cl-end-loop))) | 675 (setq loop-args (append loop-args '(cl-end-loop))) |
676 (while (not (eq (car args) 'cl-end-loop)) (cl-parse-loop-clause)) | 676 (while (not (eq (car loop-args) 'cl-end-loop)) (cl-parse-loop-clause)) |
677 (if loop-finish-flag | 677 (if loop-finish-flag |
678 (push `((,loop-finish-flag t)) loop-bindings)) | 678 (push `((,loop-finish-flag t)) loop-bindings)) |
679 (if loop-first-flag | 679 (if loop-first-flag |
680 (progn (push `((,loop-first-flag t)) loop-bindings) | 680 (progn (push `((,loop-first-flag t)) loop-bindings) |
681 (push `(setq ,loop-first-flag nil) loop-steps))) | 681 (push `(setq ,loop-first-flag nil) loop-steps))) |
711 (setq body (list (cl-loop-let lets body nil)))))) | 711 (setq body (list (cl-loop-let lets body nil)))))) |
712 (if loop-symbol-macs | 712 (if loop-symbol-macs |
713 (setq body (list (list* 'symbol-macrolet loop-symbol-macs body)))) | 713 (setq body (list (list* 'symbol-macrolet loop-symbol-macs body)))) |
714 (list* 'block loop-name body))))) | 714 (list* 'block loop-name body))))) |
715 | 715 |
716 (defun cl-parse-loop-clause () ; uses args, loop-* | 716 (defun cl-parse-loop-clause () ; uses loop-* |
717 (let ((word (pop args)) | 717 (let ((word (pop loop-args)) |
718 (hash-types '(hash-key hash-keys hash-value hash-values)) | 718 (hash-types '(hash-key hash-keys hash-value hash-values)) |
719 (key-types '(key-code key-codes key-seq key-seqs | 719 (key-types '(key-code key-codes key-seq key-seqs |
720 key-binding key-bindings))) | 720 key-binding key-bindings))) |
721 (cond | 721 (cond |
722 | 722 |
723 ((null args) | 723 ((null loop-args) |
724 (error "Malformed `loop' macro")) | 724 (error "Malformed `loop' macro")) |
725 | 725 |
726 ((eq word 'named) | 726 ((eq word 'named) |
727 (setq loop-name (pop args))) | 727 (setq loop-name (pop loop-args))) |
728 | 728 |
729 ((eq word 'initially) | 729 ((eq word 'initially) |
730 (if (memq (car args) '(do doing)) (pop args)) | 730 (if (memq (car loop-args) '(do doing)) (pop loop-args)) |
731 (or (consp (car args)) (error "Syntax error on `initially' clause")) | 731 (or (consp (car loop-args)) (error "Syntax error on `initially' clause")) |
732 (while (consp (car args)) | 732 (while (consp (car loop-args)) |
733 (push (pop args) loop-initially))) | 733 (push (pop loop-args) loop-initially))) |
734 | 734 |
735 ((eq word 'finally) | 735 ((eq word 'finally) |
736 (if (eq (car args) 'return) | 736 (if (eq (car loop-args) 'return) |
737 (setq loop-result-explicit (or (cl-pop2 args) '(quote nil))) | 737 (setq loop-result-explicit (or (cl-pop2 loop-args) '(quote nil))) |
738 (if (memq (car args) '(do doing)) (pop args)) | 738 (if (memq (car loop-args) '(do doing)) (pop loop-args)) |
739 (or (consp (car args)) (error "Syntax error on `finally' clause")) | 739 (or (consp (car loop-args)) (error "Syntax error on `finally' clause")) |
740 (if (and (eq (caar args) 'return) (null loop-name)) | 740 (if (and (eq (caar loop-args) 'return) (null loop-name)) |
741 (setq loop-result-explicit (or (nth 1 (pop args)) '(quote nil))) | 741 (setq loop-result-explicit (or (nth 1 (pop loop-args)) '(quote nil))) |
742 (while (consp (car args)) | 742 (while (consp (car loop-args)) |
743 (push (pop args) loop-finally))))) | 743 (push (pop loop-args) loop-finally))))) |
744 | 744 |
745 ((memq word '(for as)) | 745 ((memq word '(for as)) |
746 (let ((loop-for-bindings nil) (loop-for-sets nil) (loop-for-steps nil) | 746 (let ((loop-for-bindings nil) (loop-for-sets nil) (loop-for-steps nil) |
747 (ands nil)) | 747 (ands nil)) |
748 (while | 748 (while |
749 ;; Use `gensym' rather than `make-symbol'. It's important that | 749 ;; Use `gensym' rather than `make-symbol'. It's important that |
750 ;; (not (eq (symbol-name var1) (symbol-name var2))) because | 750 ;; (not (eq (symbol-name var1) (symbol-name var2))) because |
751 ;; these vars get added to the cl-macro-environment. | 751 ;; these vars get added to the cl-macro-environment. |
752 (let ((var (or (pop args) (gensym "--cl-var--")))) | 752 (let ((var (or (pop loop-args) (gensym "--cl-var--")))) |
753 (setq word (pop args)) | 753 (setq word (pop loop-args)) |
754 (if (eq word 'being) (setq word (pop args))) | 754 (if (eq word 'being) (setq word (pop loop-args))) |
755 (if (memq word '(the each)) (setq word (pop args))) | 755 (if (memq word '(the each)) (setq word (pop loop-args))) |
756 (if (memq word '(buffer buffers)) | 756 (if (memq word '(buffer buffers)) |
757 (setq word 'in args (cons '(buffer-list) args))) | 757 (setq word 'in loop-args (cons '(buffer-list) loop-args))) |
758 (cond | 758 (cond |
759 | 759 |
760 ((memq word '(from downfrom upfrom to downto upto | 760 ((memq word '(from downfrom upfrom to downto upto |
761 above below by)) | 761 above below by)) |
762 (push word args) | 762 (push word loop-args) |
763 (if (memq (car args) '(downto above)) | 763 (if (memq (car loop-args) '(downto above)) |
764 (error "Must specify `from' value for downward loop")) | 764 (error "Must specify `from' value for downward loop")) |
765 (let* ((down (or (eq (car args) 'downfrom) | 765 (let* ((down (or (eq (car loop-args) 'downfrom) |
766 (memq (caddr args) '(downto above)))) | 766 (memq (caddr loop-args) '(downto above)))) |
767 (excl (or (memq (car args) '(above below)) | 767 (excl (or (memq (car loop-args) '(above below)) |
768 (memq (caddr args) '(above below)))) | 768 (memq (caddr loop-args) '(above below)))) |
769 (start (and (memq (car args) '(from upfrom downfrom)) | 769 (start (and (memq (car loop-args) '(from upfrom downfrom)) |
770 (cl-pop2 args))) | 770 (cl-pop2 loop-args))) |
771 (end (and (memq (car args) | 771 (end (and (memq (car loop-args) |
772 '(to upto downto above below)) | 772 '(to upto downto above below)) |
773 (cl-pop2 args))) | 773 (cl-pop2 loop-args))) |
774 (step (and (eq (car args) 'by) (cl-pop2 args))) | 774 (step (and (eq (car loop-args) 'by) (cl-pop2 loop-args))) |
775 (end-var (and (not (cl-const-expr-p end)) | 775 (end-var (and (not (cl-const-expr-p end)) |
776 (make-symbol "--cl-var--"))) | 776 (make-symbol "--cl-var--"))) |
777 (step-var (and (not (cl-const-expr-p step)) | 777 (step-var (and (not (cl-const-expr-p step)) |
778 (make-symbol "--cl-var--")))) | 778 (make-symbol "--cl-var--")))) |
779 (and step (numberp step) (<= step 0) | 779 (and step (numberp step) (<= step 0) |
792 | 792 |
793 ((memq word '(in in-ref on)) | 793 ((memq word '(in in-ref on)) |
794 (let* ((on (eq word 'on)) | 794 (let* ((on (eq word 'on)) |
795 (temp (if (and on (symbolp var)) | 795 (temp (if (and on (symbolp var)) |
796 var (make-symbol "--cl-var--")))) | 796 var (make-symbol "--cl-var--")))) |
797 (push (list temp (pop args)) loop-for-bindings) | 797 (push (list temp (pop loop-args)) loop-for-bindings) |
798 (push (list 'consp temp) loop-body) | 798 (push (list 'consp temp) loop-body) |
799 (if (eq word 'in-ref) | 799 (if (eq word 'in-ref) |
800 (push (list var (list 'car temp)) loop-symbol-macs) | 800 (push (list var (list 'car temp)) loop-symbol-macs) |
801 (or (eq temp var) | 801 (or (eq temp var) |
802 (progn | 802 (progn |
803 (push (list var nil) loop-for-bindings) | 803 (push (list var nil) loop-for-bindings) |
804 (push (list var (if on temp (list 'car temp))) | 804 (push (list var (if on temp (list 'car temp))) |
805 loop-for-sets)))) | 805 loop-for-sets)))) |
806 (push (list temp | 806 (push (list temp |
807 (if (eq (car args) 'by) | 807 (if (eq (car loop-args) 'by) |
808 (let ((step (cl-pop2 args))) | 808 (let ((step (cl-pop2 loop-args))) |
809 (if (and (memq (car-safe step) | 809 (if (and (memq (car-safe step) |
810 '(quote function | 810 '(quote function |
811 function*)) | 811 function*)) |
812 (symbolp (nth 1 step))) | 812 (symbolp (nth 1 step))) |
813 (list (nth 1 step) temp) | 813 (list (nth 1 step) temp) |
814 (list 'funcall step temp))) | 814 (list 'funcall step temp))) |
815 (list 'cdr temp))) | 815 (list 'cdr temp))) |
816 loop-for-steps))) | 816 loop-for-steps))) |
817 | 817 |
818 ((eq word '=) | 818 ((eq word '=) |
819 (let* ((start (pop args)) | 819 (let* ((start (pop loop-args)) |
820 (then (if (eq (car args) 'then) (cl-pop2 args) start))) | 820 (then (if (eq (car loop-args) 'then) (cl-pop2 loop-args) start))) |
821 (push (list var nil) loop-for-bindings) | 821 (push (list var nil) loop-for-bindings) |
822 (if (or ands (eq (car args) 'and)) | 822 (if (or ands (eq (car loop-args) 'and)) |
823 (progn | 823 (progn |
824 (push `(,var | 824 (push `(,var |
825 (if ,(or loop-first-flag | 825 (if ,(or loop-first-flag |
826 (setq loop-first-flag | 826 (setq loop-first-flag |
827 (make-symbol "--cl-var--"))) | 827 (make-symbol "--cl-var--"))) |
837 loop-for-sets)))) | 837 loop-for-sets)))) |
838 | 838 |
839 ((memq word '(across across-ref)) | 839 ((memq word '(across across-ref)) |
840 (let ((temp-vec (make-symbol "--cl-vec--")) | 840 (let ((temp-vec (make-symbol "--cl-vec--")) |
841 (temp-idx (make-symbol "--cl-idx--"))) | 841 (temp-idx (make-symbol "--cl-idx--"))) |
842 (push (list temp-vec (pop args)) loop-for-bindings) | 842 (push (list temp-vec (pop loop-args)) loop-for-bindings) |
843 (push (list temp-idx -1) loop-for-bindings) | 843 (push (list temp-idx -1) loop-for-bindings) |
844 (push (list '< (list 'setq temp-idx (list '1+ temp-idx)) | 844 (push (list '< (list 'setq temp-idx (list '1+ temp-idx)) |
845 (list 'length temp-vec)) loop-body) | 845 (list 'length temp-vec)) loop-body) |
846 (if (eq word 'across-ref) | 846 (if (eq word 'across-ref) |
847 (push (list var (list 'aref temp-vec temp-idx)) | 847 (push (list var (list 'aref temp-vec temp-idx)) |
849 (push (list var nil) loop-for-bindings) | 849 (push (list var nil) loop-for-bindings) |
850 (push (list var (list 'aref temp-vec temp-idx)) | 850 (push (list var (list 'aref temp-vec temp-idx)) |
851 loop-for-sets)))) | 851 loop-for-sets)))) |
852 | 852 |
853 ((memq word '(element elements)) | 853 ((memq word '(element elements)) |
854 (let ((ref (or (memq (car args) '(in-ref of-ref)) | 854 (let ((ref (or (memq (car loop-args) '(in-ref of-ref)) |
855 (and (not (memq (car args) '(in of))) | 855 (and (not (memq (car loop-args) '(in of))) |
856 (error "Expected `of'")))) | 856 (error "Expected `of'")))) |
857 (seq (cl-pop2 args)) | 857 (seq (cl-pop2 loop-args)) |
858 (temp-seq (make-symbol "--cl-seq--")) | 858 (temp-seq (make-symbol "--cl-seq--")) |
859 (temp-idx (if (eq (car args) 'using) | 859 (temp-idx (if (eq (car loop-args) 'using) |
860 (if (and (= (length (cadr args)) 2) | 860 (if (and (= (length (cadr loop-args)) 2) |
861 (eq (caadr args) 'index)) | 861 (eq (caadr loop-args) 'index)) |
862 (cadr (cl-pop2 args)) | 862 (cadr (cl-pop2 loop-args)) |
863 (error "Bad `using' clause")) | 863 (error "Bad `using' clause")) |
864 (make-symbol "--cl-idx--")))) | 864 (make-symbol "--cl-idx--")))) |
865 (push (list temp-seq seq) loop-for-bindings) | 865 (push (list temp-seq seq) loop-for-bindings) |
866 (push (list temp-idx 0) loop-for-bindings) | 866 (push (list temp-idx 0) loop-for-bindings) |
867 (if ref | 867 (if ref |
883 loop-for-sets)) | 883 loop-for-sets)) |
884 (push (list temp-idx (list '1+ temp-idx)) | 884 (push (list temp-idx (list '1+ temp-idx)) |
885 loop-for-steps))) | 885 loop-for-steps))) |
886 | 886 |
887 ((memq word hash-types) | 887 ((memq word hash-types) |
888 (or (memq (car args) '(in of)) (error "Expected `of'")) | 888 (or (memq (car loop-args) '(in of)) (error "Expected `of'")) |
889 (let* ((table (cl-pop2 args)) | 889 (let* ((table (cl-pop2 loop-args)) |
890 (other (if (eq (car args) 'using) | 890 (other (if (eq (car loop-args) 'using) |
891 (if (and (= (length (cadr args)) 2) | 891 (if (and (= (length (cadr loop-args)) 2) |
892 (memq (caadr args) hash-types) | 892 (memq (caadr loop-args) hash-types) |
893 (not (eq (caadr args) word))) | 893 (not (eq (caadr loop-args) word))) |
894 (cadr (cl-pop2 args)) | 894 (cadr (cl-pop2 loop-args)) |
895 (error "Bad `using' clause")) | 895 (error "Bad `using' clause")) |
896 (make-symbol "--cl-var--")))) | 896 (make-symbol "--cl-var--")))) |
897 (if (memq word '(hash-value hash-values)) | 897 (if (memq word '(hash-value hash-values)) |
898 (setq var (prog1 other (setq other var)))) | 898 (setq var (prog1 other (setq other var)))) |
899 (setq loop-map-form | 899 (setq loop-map-form |
900 `(maphash (lambda (,var ,other) . --cl-map) ,table)))) | 900 `(maphash (lambda (,var ,other) . --cl-map) ,table)))) |
901 | 901 |
902 ((memq word '(symbol present-symbol external-symbol | 902 ((memq word '(symbol present-symbol external-symbol |
903 symbols present-symbols external-symbols)) | 903 symbols present-symbols external-symbols)) |
904 (let ((ob (and (memq (car args) '(in of)) (cl-pop2 args)))) | 904 (let ((ob (and (memq (car loop-args) '(in of)) (cl-pop2 loop-args)))) |
905 (setq loop-map-form | 905 (setq loop-map-form |
906 `(mapatoms (lambda (,var) . --cl-map) ,ob)))) | 906 `(mapatoms (lambda (,var) . --cl-map) ,ob)))) |
907 | 907 |
908 ((memq word '(overlay overlays extent extents)) | 908 ((memq word '(overlay overlays extent extents)) |
909 (let ((buf nil) (from nil) (to nil)) | 909 (let ((buf nil) (from nil) (to nil)) |
910 (while (memq (car args) '(in of from to)) | 910 (while (memq (car loop-args) '(in of from to)) |
911 (cond ((eq (car args) 'from) (setq from (cl-pop2 args))) | 911 (cond ((eq (car loop-args) 'from) (setq from (cl-pop2 loop-args))) |
912 ((eq (car args) 'to) (setq to (cl-pop2 args))) | 912 ((eq (car loop-args) 'to) (setq to (cl-pop2 loop-args))) |
913 (t (setq buf (cl-pop2 args))))) | 913 (t (setq buf (cl-pop2 loop-args))))) |
914 (setq loop-map-form | 914 (setq loop-map-form |
915 `(cl-map-extents | 915 `(cl-map-extents |
916 (lambda (,var ,(make-symbol "--cl-var--")) | 916 (lambda (,var ,(make-symbol "--cl-var--")) |
917 (progn . --cl-map) nil) | 917 (progn . --cl-map) nil) |
918 ,buf ,from ,to)))) | 918 ,buf ,from ,to)))) |
919 | 919 |
920 ((memq word '(interval intervals)) | 920 ((memq word '(interval intervals)) |
921 (let ((buf nil) (prop nil) (from nil) (to nil) | 921 (let ((buf nil) (prop nil) (from nil) (to nil) |
922 (var1 (make-symbol "--cl-var1--")) | 922 (var1 (make-symbol "--cl-var1--")) |
923 (var2 (make-symbol "--cl-var2--"))) | 923 (var2 (make-symbol "--cl-var2--"))) |
924 (while (memq (car args) '(in of property from to)) | 924 (while (memq (car loop-args) '(in of property from to)) |
925 (cond ((eq (car args) 'from) (setq from (cl-pop2 args))) | 925 (cond ((eq (car loop-args) 'from) (setq from (cl-pop2 loop-args))) |
926 ((eq (car args) 'to) (setq to (cl-pop2 args))) | 926 ((eq (car loop-args) 'to) (setq to (cl-pop2 loop-args))) |
927 ((eq (car args) 'property) | 927 ((eq (car loop-args) 'property) |
928 (setq prop (cl-pop2 args))) | 928 (setq prop (cl-pop2 loop-args))) |
929 (t (setq buf (cl-pop2 args))))) | 929 (t (setq buf (cl-pop2 loop-args))))) |
930 (if (and (consp var) (symbolp (car var)) (symbolp (cdr var))) | 930 (if (and (consp var) (symbolp (car var)) (symbolp (cdr var))) |
931 (setq var1 (car var) var2 (cdr var)) | 931 (setq var1 (car var) var2 (cdr var)) |
932 (push (list var (list 'cons var1 var2)) loop-for-sets)) | 932 (push (list var (list 'cons var1 var2)) loop-for-sets)) |
933 (setq loop-map-form | 933 (setq loop-map-form |
934 `(cl-map-intervals | 934 `(cl-map-intervals |
935 (lambda (,var1 ,var2) . --cl-map) | 935 (lambda (,var1 ,var2) . --cl-map) |
936 ,buf ,prop ,from ,to)))) | 936 ,buf ,prop ,from ,to)))) |
937 | 937 |
938 ((memq word key-types) | 938 ((memq word key-types) |
939 (or (memq (car args) '(in of)) (error "Expected `of'")) | 939 (or (memq (car loop-args) '(in of)) (error "Expected `of'")) |
940 (let ((map (cl-pop2 args)) | 940 (let ((map (cl-pop2 loop-args)) |
941 (other (if (eq (car args) 'using) | 941 (other (if (eq (car loop-args) 'using) |
942 (if (and (= (length (cadr args)) 2) | 942 (if (and (= (length (cadr loop-args)) 2) |
943 (memq (caadr args) key-types) | 943 (memq (caadr loop-args) key-types) |
944 (not (eq (caadr args) word))) | 944 (not (eq (caadr loop-args) word))) |
945 (cadr (cl-pop2 args)) | 945 (cadr (cl-pop2 loop-args)) |
946 (error "Bad `using' clause")) | 946 (error "Bad `using' clause")) |
947 (make-symbol "--cl-var--")))) | 947 (make-symbol "--cl-var--")))) |
948 (if (memq word '(key-binding key-bindings)) | 948 (if (memq word '(key-binding key-bindings)) |
949 (setq var (prog1 other (setq other var)))) | 949 (setq var (prog1 other (setq other var)))) |
950 (setq loop-map-form | 950 (setq loop-map-form |
962 loop-body) | 962 loop-body) |
963 (push (list var (list 'next-frame var)) | 963 (push (list var (list 'next-frame var)) |
964 loop-for-steps))) | 964 loop-for-steps))) |
965 | 965 |
966 ((memq word '(window windows)) | 966 ((memq word '(window windows)) |
967 (let ((scr (and (memq (car args) '(in of)) (cl-pop2 args))) | 967 (let ((scr (and (memq (car loop-args) '(in of)) (cl-pop2 loop-args))) |
968 (temp (make-symbol "--cl-var--"))) | 968 (temp (make-symbol "--cl-var--"))) |
969 (push (list var (if scr | 969 (push (list var (if scr |
970 (list 'frame-selected-window scr) | 970 (list 'frame-selected-window scr) |
971 '(selected-window))) | 971 '(selected-window))) |
972 loop-for-bindings) | 972 loop-for-bindings) |
980 (let ((handler (and (symbolp word) | 980 (let ((handler (and (symbolp word) |
981 (get word 'cl-loop-for-handler)))) | 981 (get word 'cl-loop-for-handler)))) |
982 (if handler | 982 (if handler |
983 (funcall handler var) | 983 (funcall handler var) |
984 (error "Expected a `for' preposition, found %s" word))))) | 984 (error "Expected a `for' preposition, found %s" word))))) |
985 (eq (car args) 'and)) | 985 (eq (car loop-args) 'and)) |
986 (setq ands t) | 986 (setq ands t) |
987 (pop args)) | 987 (pop loop-args)) |
988 (if (and ands loop-for-bindings) | 988 (if (and ands loop-for-bindings) |
989 (push (nreverse loop-for-bindings) loop-bindings) | 989 (push (nreverse loop-for-bindings) loop-bindings) |
990 (setq loop-bindings (nconc (mapcar 'list loop-for-bindings) | 990 (setq loop-bindings (nconc (mapcar 'list loop-for-bindings) |
991 loop-bindings))) | 991 loop-bindings))) |
992 (if loop-for-sets | 992 (if loop-for-sets |
998 (apply 'append (nreverse loop-for-steps))) | 998 (apply 'append (nreverse loop-for-steps))) |
999 loop-steps)))) | 999 loop-steps)))) |
1000 | 1000 |
1001 ((eq word 'repeat) | 1001 ((eq word 'repeat) |
1002 (let ((temp (make-symbol "--cl-var--"))) | 1002 (let ((temp (make-symbol "--cl-var--"))) |
1003 (push (list (list temp (pop args))) loop-bindings) | 1003 (push (list (list temp (pop loop-args))) loop-bindings) |
1004 (push (list '>= (list 'setq temp (list '1- temp)) 0) loop-body))) | 1004 (push (list '>= (list 'setq temp (list '1- temp)) 0) loop-body))) |
1005 | 1005 |
1006 ((memq word '(collect collecting)) | 1006 ((memq word '(collect collecting)) |
1007 (let ((what (pop args)) | 1007 (let ((what (pop loop-args)) |
1008 (var (cl-loop-handle-accum nil 'nreverse))) | 1008 (var (cl-loop-handle-accum nil 'nreverse))) |
1009 (if (eq var loop-accum-var) | 1009 (if (eq var loop-accum-var) |
1010 (push (list 'progn (list 'push what var) t) loop-body) | 1010 (push (list 'progn (list 'push what var) t) loop-body) |
1011 (push (list 'progn | 1011 (push (list 'progn |
1012 (list 'setq var (list 'nconc var (list 'list what))) | 1012 (list 'setq var (list 'nconc var (list 'list what))) |
1013 t) loop-body)))) | 1013 t) loop-body)))) |
1014 | 1014 |
1015 ((memq word '(nconc nconcing append appending)) | 1015 ((memq word '(nconc nconcing append appending)) |
1016 (let ((what (pop args)) | 1016 (let ((what (pop loop-args)) |
1017 (var (cl-loop-handle-accum nil 'nreverse))) | 1017 (var (cl-loop-handle-accum nil 'nreverse))) |
1018 (push (list 'progn | 1018 (push (list 'progn |
1019 (list 'setq var | 1019 (list 'setq var |
1020 (if (eq var loop-accum-var) | 1020 (if (eq var loop-accum-var) |
1021 (list 'nconc | 1021 (list 'nconc |
1026 (list (if (memq word '(nconc nconcing)) | 1026 (list (if (memq word '(nconc nconcing)) |
1027 'nconc 'append) | 1027 'nconc 'append) |
1028 var what))) t) loop-body))) | 1028 var what))) t) loop-body))) |
1029 | 1029 |
1030 ((memq word '(concat concating)) | 1030 ((memq word '(concat concating)) |
1031 (let ((what (pop args)) | 1031 (let ((what (pop loop-args)) |
1032 (var (cl-loop-handle-accum ""))) | 1032 (var (cl-loop-handle-accum ""))) |
1033 (push (list 'progn (list 'callf 'concat var what) t) loop-body))) | 1033 (push (list 'progn (list 'callf 'concat var what) t) loop-body))) |
1034 | 1034 |
1035 ((memq word '(vconcat vconcating)) | 1035 ((memq word '(vconcat vconcating)) |
1036 (let ((what (pop args)) | 1036 (let ((what (pop loop-args)) |
1037 (var (cl-loop-handle-accum []))) | 1037 (var (cl-loop-handle-accum []))) |
1038 (push (list 'progn (list 'callf 'vconcat var what) t) loop-body))) | 1038 (push (list 'progn (list 'callf 'vconcat var what) t) loop-body))) |
1039 | 1039 |
1040 ((memq word '(sum summing)) | 1040 ((memq word '(sum summing)) |
1041 (let ((what (pop args)) | 1041 (let ((what (pop loop-args)) |
1042 (var (cl-loop-handle-accum 0))) | 1042 (var (cl-loop-handle-accum 0))) |
1043 (push (list 'progn (list 'incf var what) t) loop-body))) | 1043 (push (list 'progn (list 'incf var what) t) loop-body))) |
1044 | 1044 |
1045 ((memq word '(count counting)) | 1045 ((memq word '(count counting)) |
1046 (let ((what (pop args)) | 1046 (let ((what (pop loop-args)) |
1047 (var (cl-loop-handle-accum 0))) | 1047 (var (cl-loop-handle-accum 0))) |
1048 (push (list 'progn (list 'if what (list 'incf var)) t) loop-body))) | 1048 (push (list 'progn (list 'if what (list 'incf var)) t) loop-body))) |
1049 | 1049 |
1050 ((memq word '(minimize minimizing maximize maximizing)) | 1050 ((memq word '(minimize minimizing maximize maximizing)) |
1051 (let* ((what (pop args)) | 1051 (let* ((what (pop loop-args)) |
1052 (temp (if (cl-simple-expr-p what) what (make-symbol "--cl-var--"))) | 1052 (temp (if (cl-simple-expr-p what) what (make-symbol "--cl-var--"))) |
1053 (var (cl-loop-handle-accum nil)) | 1053 (var (cl-loop-handle-accum nil)) |
1054 (func (intern (substring (symbol-name word) 0 3))) | 1054 (func (intern (substring (symbol-name word) 0 3))) |
1055 (set (list 'setq var (list 'if var (list func var temp) temp)))) | 1055 (set (list 'setq var (list 'if var (list func var temp) temp)))) |
1056 (push (list 'progn (if (eq temp what) set | 1056 (push (list 'progn (if (eq temp what) set |
1057 (list 'let (list (list temp what)) set)) | 1057 (list 'let (list (list temp what)) set)) |
1058 t) loop-body))) | 1058 t) loop-body))) |
1059 | 1059 |
1060 ((eq word 'with) | 1060 ((eq word 'with) |
1061 (let ((bindings nil)) | 1061 (let ((bindings nil)) |
1062 (while (progn (push (list (pop args) | 1062 (while (progn (push (list (pop loop-args) |
1063 (and (eq (car args) '=) (cl-pop2 args))) | 1063 (and (eq (car loop-args) '=) (cl-pop2 loop-args))) |
1064 bindings) | 1064 bindings) |
1065 (eq (car args) 'and)) | 1065 (eq (car loop-args) 'and)) |
1066 (pop args)) | 1066 (pop loop-args)) |
1067 (push (nreverse bindings) loop-bindings))) | 1067 (push (nreverse bindings) loop-bindings))) |
1068 | 1068 |
1069 ((eq word 'while) | 1069 ((eq word 'while) |
1070 (push (pop args) loop-body)) | 1070 (push (pop loop-args) loop-body)) |
1071 | 1071 |
1072 ((eq word 'until) | 1072 ((eq word 'until) |
1073 (push (list 'not (pop args)) loop-body)) | 1073 (push (list 'not (pop loop-args)) loop-body)) |
1074 | 1074 |
1075 ((eq word 'always) | 1075 ((eq word 'always) |
1076 (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--"))) | 1076 (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--"))) |
1077 (push (list 'setq loop-finish-flag (pop args)) loop-body) | 1077 (push (list 'setq loop-finish-flag (pop loop-args)) loop-body) |
1078 (setq loop-result t)) | 1078 (setq loop-result t)) |
1079 | 1079 |
1080 ((eq word 'never) | 1080 ((eq word 'never) |
1081 (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--"))) | 1081 (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--"))) |
1082 (push (list 'setq loop-finish-flag (list 'not (pop args))) | 1082 (push (list 'setq loop-finish-flag (list 'not (pop loop-args))) |
1083 loop-body) | 1083 loop-body) |
1084 (setq loop-result t)) | 1084 (setq loop-result t)) |
1085 | 1085 |
1086 ((eq word 'thereis) | 1086 ((eq word 'thereis) |
1087 (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--"))) | 1087 (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--"))) |
1088 (or loop-result-var (setq loop-result-var (make-symbol "--cl-var--"))) | 1088 (or loop-result-var (setq loop-result-var (make-symbol "--cl-var--"))) |
1089 (push (list 'setq loop-finish-flag | 1089 (push (list 'setq loop-finish-flag |
1090 (list 'not (list 'setq loop-result-var (pop args)))) | 1090 (list 'not (list 'setq loop-result-var (pop loop-args)))) |
1091 loop-body)) | 1091 loop-body)) |
1092 | 1092 |
1093 ((memq word '(if when unless)) | 1093 ((memq word '(if when unless)) |
1094 (let* ((cond (pop args)) | 1094 (let* ((cond (pop loop-args)) |
1095 (then (let ((loop-body nil)) | 1095 (then (let ((loop-body nil)) |
1096 (cl-parse-loop-clause) | 1096 (cl-parse-loop-clause) |
1097 (cl-loop-build-ands (nreverse loop-body)))) | 1097 (cl-loop-build-ands (nreverse loop-body)))) |
1098 (else (let ((loop-body nil)) | 1098 (else (let ((loop-body nil)) |
1099 (if (eq (car args) 'else) | 1099 (if (eq (car loop-args) 'else) |
1100 (progn (pop args) (cl-parse-loop-clause))) | 1100 (progn (pop loop-args) (cl-parse-loop-clause))) |
1101 (cl-loop-build-ands (nreverse loop-body)))) | 1101 (cl-loop-build-ands (nreverse loop-body)))) |
1102 (simple (and (eq (car then) t) (eq (car else) t)))) | 1102 (simple (and (eq (car then) t) (eq (car else) t)))) |
1103 (if (eq (car args) 'end) (pop args)) | 1103 (if (eq (car loop-args) 'end) (pop loop-args)) |
1104 (if (eq word 'unless) (setq then (prog1 else (setq else then)))) | 1104 (if (eq word 'unless) (setq then (prog1 else (setq else then)))) |
1105 (let ((form (cons (if simple (cons 'progn (nth 1 then)) (nth 2 then)) | 1105 (let ((form (cons (if simple (cons 'progn (nth 1 then)) (nth 2 then)) |
1106 (if simple (nth 1 else) (list (nth 2 else)))))) | 1106 (if simple (nth 1 else) (list (nth 2 else)))))) |
1107 (if (cl-expr-contains form 'it) | 1107 (if (cl-expr-contains form 'it) |
1108 (let ((temp (make-symbol "--cl-var--"))) | 1108 (let ((temp (make-symbol "--cl-var--"))) |
1112 (setq form (list* 'if cond form))) | 1112 (setq form (list* 'if cond form))) |
1113 (push (if simple (list 'progn form t) form) loop-body)))) | 1113 (push (if simple (list 'progn form t) form) loop-body)))) |
1114 | 1114 |
1115 ((memq word '(do doing)) | 1115 ((memq word '(do doing)) |
1116 (let ((body nil)) | 1116 (let ((body nil)) |
1117 (or (consp (car args)) (error "Syntax error on `do' clause")) | 1117 (or (consp (car loop-args)) (error "Syntax error on `do' clause")) |
1118 (while (consp (car args)) (push (pop args) body)) | 1118 (while (consp (car loop-args)) (push (pop loop-args) body)) |
1119 (push (cons 'progn (nreverse (cons t body))) loop-body))) | 1119 (push (cons 'progn (nreverse (cons t body))) loop-body))) |
1120 | 1120 |
1121 ((eq word 'return) | 1121 ((eq word 'return) |
1122 (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-var--"))) | 1122 (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-var--"))) |
1123 (or loop-result-var (setq loop-result-var (make-symbol "--cl-var--"))) | 1123 (or loop-result-var (setq loop-result-var (make-symbol "--cl-var--"))) |
1124 (push (list 'setq loop-result-var (pop args) | 1124 (push (list 'setq loop-result-var (pop loop-args) |
1125 loop-finish-flag nil) loop-body)) | 1125 loop-finish-flag nil) loop-body)) |
1126 | 1126 |
1127 (t | 1127 (t |
1128 (let ((handler (and (symbolp word) (get word 'cl-loop-handler)))) | 1128 (let ((handler (and (symbolp word) (get word 'cl-loop-handler)))) |
1129 (or handler (error "Expected a loop keyword, found %s" word)) | 1129 (or handler (error "Expected a loop keyword, found %s" word)) |
1130 (funcall handler)))) | 1130 (funcall handler)))) |
1131 (if (eq (car args) 'and) | 1131 (if (eq (car loop-args) 'and) |
1132 (progn (pop args) (cl-parse-loop-clause))))) | 1132 (progn (pop loop-args) (cl-parse-loop-clause))))) |
1133 | 1133 |
1134 (defun cl-loop-let (specs body par) ; uses loop-* | 1134 (defun cl-loop-let (specs body par) ; uses loop-* |
1135 (let ((p specs) (temps nil) (new nil)) | 1135 (let ((p specs) (temps nil) (new nil)) |
1136 (while (and p (or (symbolp (car-safe (car p))) (null (cadar p)))) | 1136 (while (and p (or (symbolp (car-safe (car p))) (null (cadar p)))) |
1137 (setq p (cdr p))) | 1137 (setq p (cdr p))) |
1163 (let ((set (cons (if par 'psetq 'setq) (apply 'nconc (nreverse new))))) | 1163 (let ((set (cons (if par 'psetq 'setq) (apply 'nconc (nreverse new))))) |
1164 (if temps (list 'let* (nreverse temps) set) set)) | 1164 (if temps (list 'let* (nreverse temps) set) set)) |
1165 (list* (if par 'let 'let*) | 1165 (list* (if par 'let 'let*) |
1166 (nconc (nreverse temps) (nreverse new)) body)))) | 1166 (nconc (nreverse temps) (nreverse new)) body)))) |
1167 | 1167 |
1168 (defun cl-loop-handle-accum (def &optional func) ; uses args, loop-* | 1168 (defun cl-loop-handle-accum (def &optional func) ; uses loop-* |
1169 (if (eq (car args) 'into) | 1169 (if (eq (car loop-args) 'into) |
1170 (let ((var (cl-pop2 args))) | 1170 (let ((var (cl-pop2 loop-args))) |
1171 (or (memq var loop-accum-vars) | 1171 (or (memq var loop-accum-vars) |
1172 (progn (push (list (list var def)) loop-bindings) | 1172 (progn (push (list (list var def)) loop-bindings) |
1173 (push var loop-accum-vars))) | 1173 (push var loop-accum-vars))) |
1174 var) | 1174 var) |
1175 (or loop-accum-var | 1175 (or loop-accum-var |
2789 ;; byte-compile-dynamic: t | 2789 ;; byte-compile-dynamic: t |
2790 ;; byte-compile-warnings: (not cl-functions) | 2790 ;; byte-compile-warnings: (not cl-functions) |
2791 ;; generated-autoload-file: "cl-loaddefs.el" | 2791 ;; generated-autoload-file: "cl-loaddefs.el" |
2792 ;; End: | 2792 ;; End: |
2793 | 2793 |
2794 ;; arch-tag: afd947a6-b553-4df1-bba5-000be6388f46 | |
2795 ;;; cl-macs.el ends here | 2794 ;;; cl-macs.el ends here |