comparison lisp/cl-macs.el @ 5574:d4f334808463

Support inlining labels, bytecomp.el. lisp/ChangeLog addition: 2011-10-02 Aidan Kehoe <kehoea@parhasard.net> * bytecomp.el (byte-compile-initial-macro-environment): Add #'declare to this, so it doesn't need to rely on #'cl-compiling file to determine when we're byte-compiling. Update #'labels to support declaring labels inline, as Common Lisp requires. * bytecomp.el (byte-compile-function-form): Don't error if FUNCTION is quoting a non-lambda, non-symbol, just return it. * cl-extra.el (cl-macroexpand-all): If a label name has been quoted, expand to the label placeholder quoted with 'function. This allows the byte compiler to distinguish between uses of the placeholder as data and uses in contexts where it should be inlined. * cl-macs.el: * cl-macs.el (cl-do-proclaim): When proclaming something as inline, if it is bound as a label, don't modify the symbol's plist; instead, treat the first element of its placeholder constant vector as a place to store compile information. * cl-macs.el (declare): Leave processing declarations while compiling to the implementation of #'declare in byte-compile-initial-macro-environment. tests/ChangeLog addition: 2011-10-02 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: * automated/lisp-tests.el (+): Test #'labels and inlining.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 02 Oct 2011 15:32:16 +0100
parents 6c76f5b7e2e3
children a0e81357194e
comparison
equal deleted inserted replaced
5573:f0f1fd0d8486 5574:d4f334808463
1967 (cdr spec)) 1967 (cdr spec))
1968 byte-compile-bound-variables)))) 1968 byte-compile-bound-variables))))
1969 1969
1970 ((eq (car-safe spec) 'inline) 1970 ((eq (car-safe spec) 'inline)
1971 (while (setq spec (cdr spec)) 1971 (while (setq spec (cdr spec))
1972 (or (memq (get (car spec) 'byte-optimizer) 1972 (let ((assq (cdr (assq (car spec) byte-compile-macro-environment))))
1973 '(nil byte-compile-inline-expand)) 1973 (if (and (consp assq) (eq (nth 1 (nth 1 assq)) 'cl-labels-args)
1974 (error "%s already has a byte-optimizer, can't make it inline" 1974 (atom (setq assq (nth 2 (nth 2 assq)))))
1975 (car spec))) 1975 ;; It's a label, and we're using the labels
1976 (put (car spec) 'byte-optimizer 'byte-compile-inline-expand))) 1976 ;; implementation in bytecomp.el. Tell the compiler
1977 1977 ;; to inline it, don't mark the symbol to be inlined
1978 ;; globally.
1979 (setf (getf (aref (compiled-function-constants assq) 0)
1980 'byte-optimizer)
1981 'byte-compile-inline-expand)
1982 (or (memq (get (car spec) 'byte-optimizer)
1983 '(nil byte-compile-inline-expand))
1984 (error
1985 "%s already has a byte-optimizer, can't make it inline"
1986 (car spec)))
1987 (put (car spec) 'byte-optimizer 'byte-compile-inline-expand)))))
1978 ((eq (car-safe spec) 'notinline) 1988 ((eq (car-safe spec) 'notinline)
1979 (while (setq spec (cdr spec)) 1989 (while (setq spec (cdr spec))
1980 (if (eq (get (car spec) 'byte-optimizer) 1990 (let ((assq (cdr (assq (car spec) byte-compile-macro-environment))))
1981 'byte-compile-inline-expand) 1991 (if (and (consp assq) (eq (nth 1 (nth 1 assq)) 'cl-labels-args)
1982 (put (car spec) 'byte-optimizer nil)))) 1992 (atom (setq assq (nth 2 (nth 2 assq)))))
1983 1993 ;; It's a label, and we're using the labels
1994 ;; implementation in bytecomp.el. Tell the compiler
1995 ;; not to inline it.
1996 (if (eq 'byte-compile-inline-expand
1997 (getf (aref (compiled-function-constants assq) 0)
1998 'byte-optimizer))
1999 (remf (aref (compiled-function-constants assq) 0)
2000 'byte-optimizer))
2001 (if (eq (get (car spec) 'byte-optimizer)
2002 'byte-compile-inline-expand)
2003 (put (car spec) 'byte-optimizer nil))))))
1984 ((eq (car-safe spec) 'optimize) 2004 ((eq (car-safe spec) 'optimize)
1985 (let ((speed (assq (nth 1 (assq 'speed (cdr spec))) 2005 (let ((speed (assq (nth 1 (assq 'speed (cdr spec)))
1986 '((0 . nil) (1 . t) (2 . t) (3 . t)))) 2006 '((0 . nil) (1 . t) (2 . t) (3 . t))))
1987 (safety (assq (nth 1 (assq 'safety (cdr spec))) 2007 (safety (assq (nth 1 (assq 'safety (cdr spec)))
1988 '((0 . t) (1 . t) (2 . t) (3 . nil))))) 2008 '((0 . t) (1 . t) (2 . t) (3 . nil)))))
2012 (while p (cl-do-proclaim (pop p) t)) 2032 (while p (cl-do-proclaim (pop p) t))
2013 (setq cl-proclaims-deferred nil)) 2033 (setq cl-proclaims-deferred nil))
2014 2034
2015 ;;;###autoload 2035 ;;;###autoload
2016 (defmacro declare (&rest specs) 2036 (defmacro declare (&rest specs)
2017 (if (cl-compiling-file)
2018 (while specs
2019 (if (listp cl-declare-stack) (push (car specs) cl-declare-stack))
2020 (cl-do-proclaim (pop specs) nil)))
2021 nil) 2037 nil)
2022
2023
2024 2038
2025 ;;; Generalized variables. 2039 ;;; Generalized variables.
2026 2040
2027 ;;;###autoload 2041 ;;;###autoload
2028 (defmacro define-setf-method (name arglist &rest body) 2042 (defmacro define-setf-method (name arglist &rest body)