Merge from origin/emacs-24
[emacs.git] / lisp / emacs-lisp / cl-preloaded.el
blob401d34b449e56cb5ff81a4d80a0a37a9a97b266b
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 (eval-when-compile (require 'cl-lib))
33 (defun cl-struct-define (name docstring parent type named slots children-sym
34 tag print-auto)
35 (cl-assert (or type (equal '(cl-tag-slot) (car slots))))
36 (cl-assert (or type (not named)))
37 (if (boundp children-sym)
38 (add-to-list children-sym tag)
39 (set children-sym (list tag)))
40 (let* ((parent-class parent))
41 (while parent-class
42 (add-to-list (intern (format "cl-struct-%s-tags" parent-class)) tag)
43 (setq parent-class (get parent-class 'cl-struct-include))))
44 ;; If the cl-generic support, we need to be able to check
45 ;; if a vector is a cl-struct object, without knowing its particular type.
46 ;; So we use the (otherwise) unused function slots of the tag symbol
47 ;; to put a special witness value, to make the check easy and reliable.
48 (unless named (fset tag :quick-object-witness-check))
49 (put name 'cl-struct-slots slots)
50 (put name 'cl-struct-type (list type named))
51 (if parent (put name 'cl-struct-include parent))
52 (if print-auto (put name 'cl-struct-print print-auto))
53 (if docstring (put name 'structure-documentation docstring)))
55 ;; The `assert' macro from the cl package signals
56 ;; `cl-assertion-failed' at runtime so always define it.
57 (define-error 'cl-assertion-failed (purecopy "Assertion failed"))
59 (defun cl--assertion-failed (form &optional string sargs args)
60 (if debug-on-error
61 (debug `(cl-assertion-failed ,form ,string ,@sargs))
62 (if string
63 (apply #'error string (append sargs args))
64 (signal 'cl-assertion-failed `(,form ,@sargs)))))
66 ;; Make sure functions defined with cl-defsubst can be inlined even in
67 ;; packages which do not require CL. We don't put an autoload cookie
68 ;; directly on that function, since those cookies only go to cl-loaddefs.
69 (autoload 'cl--defsubst-expand "cl-macs")
70 ;; Autoload, so autoload.el and font-lock can use it even when CL
71 ;; is not loaded.
72 (put 'cl-defun 'doc-string-elt 3)
73 (put 'cl-defmacro 'doc-string-elt 3)
74 (put 'cl-defsubst 'doc-string-elt 3)
75 (put 'cl-defstruct 'doc-string-elt 2)
77 (provide 'cl-preloaded)
78 ;;; cl-preloaded.el ends here