1 ;;; static.el --- tools for static evaluation.
3 ;; Copyright (C) 1999 Tanaka Akira <akr@jaist.ac.jp>
5 ;; Author: Tanaka Akira <akr@jaist.ac.jp>
6 ;; Keywords: byte compile, evaluation
8 ;; This file is part of APEL (A Portable Emacs Library).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 (put 'static-if 'lisp-indent-function 2)
28 (defmacro static-if (cond then &rest else)
29 "Like `if', but evaluate COND at compile time."
32 (` (progn (,@ else)))))
34 (put 'static-when 'lisp-indent-function 1)
35 (defmacro static-when (cond &rest body)
36 "Like `when', but evaluate COND at compile time."
38 (` (progn (,@ body)))))
40 (put 'static-unless 'lisp-indent-function 1)
41 (defmacro static-unless (cond &rest body)
42 "Like `unless', but evaluate COND at compile time."
45 (` (progn (,@ body)))))
47 (put 'static-condition-case 'lisp-indent-function 2)
48 (defmacro static-condition-case (var bodyform &rest handlers)
49 "Like `condition-case', but evaluate BODYFORM at compile time."
50 (eval (` (condition-case (, var)
51 (list (quote quote) (, bodyform))
58 (function (lambda ((, var)) (,@ (cdr h))))
59 (list (quote quote) (, var)))))))
62 (` ((, (car h)) (quote (progn (,@ (cdr h)))))))))
65 (put 'static-defconst 'lisp-indent-function 'defun)
66 (defmacro static-defconst (symbol initvalue &optional docstring)
67 "Like `defconst', but evaluate INITVALUE at compile time.
69 The variable SYMBOL can be referred at both compile time and run time."
70 (let ((value (eval initvalue)))
71 (eval (` (defconst (, symbol) (quote (, value)) (, docstring))))
72 (` (defconst (, symbol) (quote (, value)) (, docstring)))))
74 (defmacro static-cond (&rest clauses)
75 "Like `cond', but evaluate CONDITION part of each clause at compile time."
77 (not (eval (car (car clauses)))))
78 (setq clauses (cdr clauses)))
80 (cons 'progn (cdr (car clauses)))))
87 (product-provide (provide 'static) (require 'apel-ver))
89 ;;; static.el ends here