X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=static.el;h=34d6f1beca3d79c206431c48f58e3ce928971e5e;hb=f4baae0103bf6579576d1a0eaea8dee8ef1118c8;hp=8e97b71a3d0e749e832145b76d2dc5d1f728fb6e;hpb=d28642c06aa145c23476514814ceb1d750ecaae7;p=elisp%2Fapel.git diff --git a/static.el b/static.el index 8e97b71..34d6f1b 100644 --- a/static.el +++ b/static.el @@ -3,7 +3,7 @@ ;; Copyright (C) 1999 Tanaka Akira ;; Author: Tanaka Akira -;; Keywords: emulation, compatibility, incompatibility, Mule +;; Keywords: byte compile, evaluation ;; This file is part of APEL (A Portable Emacs Library). @@ -19,47 +19,71 @@ ;; 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., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; 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)))))))) + (function + (lambda (h) + (` ((, (car h)) + (list (quote funcall) + (function (lambda ((, var)) (,@ (cdr h)))) + (list (quote quote) (, var))))))) + (function + (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 ;;; -(provide 'static) +(require 'product) +(product-provide (provide 'static) (require 'apel-ver)) ;;; static.el ends here