-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstatic.el
88 lines (70 loc) · 2.89 KB
/
static.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
83
84
85
86
87
88
;;; static.el --- tools for static evaluation -*- lexical-binding: t -*-
;; Copyright (C) 1999 Tanaka Akira <[email protected]>
;; Author: Tanaka Akira <[email protected]>
;; Keywords: byte compile, evaluation
;; This file is part of APEL (A Portable Emacs Library).
;; 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 2, 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
(put 'static-if 'lisp-indent-function 2)
(defmacro static-if (cond then &rest else)
"Like `if', but evaluate COND at compile time."
(if (eval cond)
then
`(progn ,@ else)))
(put 'static-when 'lisp-indent-function 1)
(defmacro static-when (cond &rest body)
"Like `when', but evaluate COND at compile time."
(if (eval cond)
`(progn ,@ body)))
(put 'static-unless 'lisp-indent-function 1)
(defmacro static-unless (cond &rest body)
"Like `unless', but evaluate COND at compile time."
(if (eval cond)
nil
`(progn ,@ body)))
(put 'static-condition-case 'lisp-indent-function 2)
(defmacro static-condition-case (var bodyform &rest handlers)
"Like `condition-case', but evaluate BODYFORM at compile time."
(eval `(condition-case ,var
(list (quote quote) ,bodyform)
,@
(mapcar
(if var
(lambda (h)
`(,(car h)
(list (quote funcall)
(lambda (,var) ,@ (cdr h))
(list (quote quote) ,var))))
(lambda (h)
`(,(car h) (quote (progn ,@ (cdr h))))))
handlers))))
(put 'static-defconst 'lisp-indent-function 'defun)
(defmacro static-defconst (symbol initvalue &optional docstring)
"Like `defconst', but evaluate INITVALUE at compile time.
The variable SYMBOL can be referred at both compile time and run time."
(let ((value (eval initvalue)))
(eval `(defconst ,symbol (quote ,value) ,docstring))
`(defconst ,symbol (quote ,value) ,docstring)))
(defmacro static-cond (&rest clauses)
"Like `cond', but evaluate CONDITION part of each clause at compile time."
(while (and clauses
(not (eval (car (car clauses)))))
(setq clauses (cdr clauses)))
(if clauses
(cons 'progn (cdr (car clauses)))))
;;; @ end
;;;
(require 'product)
(product-provide (provide 'static) (require 'apel-ver))
;;; static.el ends here