-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
elsa-declare.el
82 lines (66 loc) · 3.2 KB
/
elsa-declare.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
;;; elsa-declare.el --- Elsa cache declaration macros -*- lexical-binding: t -*-
;; Copyright (C) 2023 Matúš Goljer
;; Author: Matúš Goljer <matus.goljer@gmail.com>
;; Maintainer: Matúš Goljer <matus.goljer@gmail.com>
;; Created: 5th March 2023
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; The macros here are used only in the elsa cache files (stored by
;; default in .elsa in the current directory). They should not be
;; used to declare types in your code, for that, see elsa-macros.el.
;;; Code:
(require 'elsa-state)
(require 'elsa-extension-eieio)
(require 'elsa-type-helpers)
(defmacro elsa-in-file (file)
"Specify the current file for registering new structures."
`(oset elsa-global-state current-file ,file))
(defmacro elsa-declare-defun (name arglist type)
(declare (indent 2))
`(elsa-state-add-method elsa-global-state
(elsa-defun :name ',name :type (elsa-make-type ,type) :arglist ',arglist)))
(defmacro elsa-declare-defgeneric (name arglist type)
(declare (indent 2))
`(elsa-state-add-defun elsa-global-state
(elsa-defun :name ',name
:type (elsa-make-type ,type)
:defun-type 'cl-defgeneric
:defgeneric-type (elsa-make-type ,type)
:arglist ',arglist)))
(defmacro elsa-declare-defvar (name type)
(declare (indent 1))
`(elsa-state-add-defvar elsa-global-state
(elsa-defvar :name ',name :type (elsa-make-type ,type))))
(defmacro elsa-declare-defstruct (name parents slots)
(declare (indent 2))
`(elsa-state-add-defstruct elsa-global-state
(elsa-defstruct :name ',name
:parents ',(or parents `((,name)))
:slots (elsa-eieio--create-slots
(list ,@(mapcar
(lambda (slot)
`(list ',(car slot)
:type (elsa--make-type ',(plist-get (cdr slot) :type))))
slots))))))
(defmacro elsa-declare-defclass (name parents slots)
(declare (indent 2))
`(elsa-state-add-defclass elsa-global-state
(elsa-defclass :name ',name
:parents ',(or parents `((,name)))
:slots (elsa-eieio--create-slots
(list ,@(mapcar
(lambda (slot)
`(list ',(car slot)
:type (elsa--make-type ',(plist-get (cdr slot) :type))))
slots))))))
(provide 'elsa-declare)
;;; elsa-declare.el ends here