Skip to content

Commit

Permalink
Add compiler macro utils CONSTANT-FORM-P and CONSTANT-FORM-VALUE
Browse files Browse the repository at this point in the history
  • Loading branch information
sionescu committed Nov 7, 2022
1 parent 88323ad commit d4216a3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,28 @@ set twos-complement bit."
(the fixnum (1+ (the fixnum stop)))
stop))
while stop)))

(defun quoted-form-p (form)
(and (listp form)
(= 2 (length form))
(eql 'quote (car form))))

(defun constant-form-p (form &optional env)
(let ((form (if (symbolp form)
(macroexpand form env)
form)))
(or (quoted-form-p form)
(constantp form env))))

(defun constant-form-value (form &optional env)
(declare (ignorable env))
(cond
((quoted-form-p form)
(second form))
(t
#+clozure
(ccl::eval-constant form)
#+sbcl
(sb-int:constant-form-value form env)
#-(or clozure sbcl)
(eval form))))

0 comments on commit d4216a3

Please sign in to comment.