emacs-lisp/package.el: Move the compatibility-table building logic.
[emacs.git] / lisp / emacs-lisp / cl-preloaded.el
blob03045de509aa4ee371190613be125094ecb06425
1 ;;; cl-preloaded.el --- Preloaded part of the CL library -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2015 Free Software Foundation, Inc
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; The expectation is that structs defined with cl-defstruct do not
25 ;; need cl-lib at run-time, but we'd like to hide the details of the
26 ;; cl-struct metadata behind the cl-struct-define function, so we put
27 ;; it in this pre-loaded file.
29 ;;; Code:
31 (defun cl-struct-define (name docstring parent type named slots children-sym
32 tag print-auto)
33 (if (boundp children-sym)
34 (add-to-list children-sym tag)
35 (set children-sym (list tag)))
36 (let* ((parent-class parent))
37 (while parent-class
38 (add-to-list (intern (format "cl-struct-%s-tags" parent-class)) tag)
39 (setq parent-class (get parent-class 'cl-struct-include))))
40 ;; If the cl-generic support, we need to be able to check
41 ;; if a vector is a cl-struct object, without knowing its particular type.
42 ;; So we use the (otherwise) unused function slots of the tag symbol
43 ;; to put a special witness value, to make the check easy and reliable.
44 (unless named (fset tag :quick-object-witness-check))
45 (put name 'cl-struct-slots slots)
46 (put name 'cl-struct-type (list type named))
47 (if parent (put name 'cl-struct-include parent))
48 (if print-auto (put name 'cl-struct-print print-auto))
49 (if docstring (put name 'structure-documentation docstring)))
51 ;; The `assert' macro from the cl package signals
52 ;; `cl-assertion-failed' at runtime so always define it.
53 (define-error 'cl-assertion-failed (purecopy "Assertion failed"))
55 (defun cl--assertion-failed (form &optional string sargs args)
56 (if debug-on-error
57 (debug `(cl-assertion-failed ,form ,string ,@sargs))
58 (if string
59 (apply #'error string (append sargs args))
60 (signal 'cl-assertion-failed `(,form ,@sargs)))))
62 ;; Make sure functions defined with cl-defsubst can be inlined even in
63 ;; packages which do not require CL. We don't put an autoload cookie
64 ;; directly on that function, since those cookies only go to cl-loaddefs.
65 (autoload 'cl--defsubst-expand "cl-macs")
66 ;; Autoload, so autoload.el and font-lock can use it even when CL
67 ;; is not loaded.
68 (put 'cl-defun 'doc-string-elt 3)
69 (put 'cl-defmacro 'doc-string-elt 3)
70 (put 'cl-defsubst 'doc-string-elt 3)
71 (put 'cl-defstruct 'doc-string-elt 2)
73 (provide 'cl-preloaded)
74 ;;; cl-preloaded.el ends here