adding CFFI just in case. Need to make into a submodule at somepoint.
[CommonLispStat.git] / external / cffi.darcs / src / features.lisp
blobcb62a65fc4fba9513d4f086b61d781d0cc53928a
1 ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
2 ;;;
3 ;;; features.lisp --- CFFI-specific features.
4 ;;;
5 ;;; Copyright (C) 2006-2007, Luis Oliveira <loliveira@common-lisp.net>
6 ;;;
7 ;;; Permission is hereby granted, free of charge, to any person
8 ;;; obtaining a copy of this software and associated documentation
9 ;;; files (the "Software"), to deal in the Software without
10 ;;; restriction, including without limitation the rights to use, copy,
11 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
12 ;;; of the Software, and to permit persons to whom the Software is
13 ;;; furnished to do so, subject to the following conditions:
14 ;;;
15 ;;; The above copyright notice and this permission notice shall be
16 ;;; included in all copies or substantial portions of the Software.
17 ;;;
18 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 ;;; DEALINGS IN THE SOFTWARE.
26 ;;;
28 (in-package #:cl-user)
30 (eval-when (:compile-toplevel :load-toplevel :execute)
31 (pushnew :cffi *features*))
33 ;;; CFFI-SYS backends take care of pushing the appropriate features to
34 ;;; *features*. See each cffi-*.lisp file.
36 (defpackage #:cffi-features
37 (:use #:cl)
38 (:export
39 #:cffi-feature-p
41 ;; Features related to the CFFI-SYS backend. Why no-*? This
42 ;; reflects the hope that these symbols will go away completely
43 ;; meaning that at some point all lisps will support long-longs,
44 ;; the foreign-funcall primitive, etc...
45 #:no-long-long
46 #:no-foreign-funcall
47 #:no-stdcall
48 #:flat-namespace
50 ;; Only SCL supports long-double...
51 ;;#:no-long-double
53 ;; Features related to the operating system.
54 ;; More should be added.
55 #:darwin
56 #:unix
57 #:windows
59 ;; Features related to the processor.
60 ;; More should be added.
61 #:ppc32
62 #:x86
63 #:x86-64
64 #:sparc
65 #:sparc64
66 #:hppa
67 #:hppa64
70 (in-package #:cffi-features)
72 (defun cffi-feature-p (feature-expression)
73 "Matches a FEATURE-EXPRESSION against those symbols in *FEATURES*
74 that belong to the CFFI-FEATURES package."
75 (when (eql feature-expression t)
76 (return-from cffi-feature-p t))
77 (let ((features-package (find-package '#:cffi-features)))
78 (flet ((cffi-feature-eq (name feature-symbol)
79 (and (eq (symbol-package feature-symbol) features-package)
80 (string= name (symbol-name feature-symbol)))))
81 (etypecase feature-expression
82 (symbol
83 (not (null (member (symbol-name feature-expression) *features*
84 :test #'cffi-feature-eq))))
85 (cons
86 (ecase (first feature-expression)
87 (:and (every #'cffi-feature-p (rest feature-expression)))
88 (:or (some #'cffi-feature-p (rest feature-expression)))
89 (:not (not (cffi-feature-p (cadr feature-expression))))))))))