Debian Codegraph @

src/cmp/cmpopt-constant.lsp

raw
1 ;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: C -*-
2 ;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab:
3
4 ;;;;
5 ;;;; Copyright (c) 2010, Juan Jose Garcia-Ripoll.
6 ;;;;
7 ;;;; See file 'LICENSE' for the copyright details.
8
9 ;;;;
10 ;;;; CMPOPT-CONSTANTS Constant expressions.
11 ;;;;
12
13 (in-package "COMPILER")
14
15 (defun constant-expression-p (form &optional (env *cmp-env*))
16 (or (constantp form env)
17 (and (consp form)
18 (let ((head (car form)))
19 (or (member head '(IF OR AND NULL NOT PROGN))
20 (and (si:get-sysprop head 'pure)
21 (inline-possible head))))
22 (loop for c in (rest form)
23 always (constant-expression-p c env)))))
24
25 (defun extract-constant-value (form &optional failure (env *cmp-env*))
26 (if (constant-expression-p form env)
27 (handler-case (cmp-eval form env)
28 (error (c) failure))
29 failure))
30
31 (defun constant-value-p (form &optional (env *cmp-env*))
32 (if (constant-expression-p form env)
33 (handler-case
34 (values t (cmp-eval form env))
35 (error (c) (values nil form)))
36 (values nil form)))