Skip to content

Commit

Permalink
Add macro FCASE
Browse files Browse the repository at this point in the history
FCASE is a feature case a bit easier to use than long chains of #+ and #-
  • Loading branch information
sionescu committed Nov 15, 2015
1 parent a6e4ff4 commit b1956ba
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion iolib.asd
Expand Up @@ -87,7 +87,7 @@
:licence "MIT"
:version (:read-file-form "version.lisp-expr")
:defsystem-depends-on (:iolib/asdf :iolib/conf)
:depends-on (:iolib/asdf :iolib/conf
:depends-on (:iolib/asdf :iolib/base :iolib/conf
:alexandria :split-sequence #+allegro (:require "osi") :cffi :uiop)
:around-compile "iolib/asdf:compile-wrapper"
:encoding :utf-8
Expand Down
1 change: 1 addition & 0 deletions src/base/pkgdcl.lisp
Expand Up @@ -55,6 +55,7 @@
#:define-literal-reader
#:enable-literal-reader #:enable-literal-reader*
#:unknown-literal-syntax #:unknown-literal-syntax-name
#:fcase
;; Misc
#:function-name #:function-name-p
#:check-bounds #:join #:join* #:shrink-vector #:full-string
Expand Down
7 changes: 7 additions & 0 deletions src/base/reader.lisp
Expand Up @@ -41,3 +41,10 @@
(defmacro define-literal-reader (name (stream) &body body)
`(setf (getf (symbol-plist ',name) 'read-literal-fn)
(lambda (,stream) ,@body)))

(defmacro fcase (&body clauses)
`(cond
,@(loop :for c :in clauses
:for test := (car c)
:for forms := (cdr c)
:collect `((featurep ',test) ,@forms))))
49 changes: 27 additions & 22 deletions src/grovel/grovel.lisp
Expand Up @@ -242,7 +242,10 @@ int main(int argc, char**argv) {
(write-string *postscript* out)))))
c-file))

(defparameter *exe-extension* #-windows nil #+windows "exe")
(defparameter *exe-extension*
(fcase
(:windows "exe")
(t nil)))

(defun exe-filename (defaults)
(let ((path (make-pathname :type *exe-extension*
Expand All @@ -265,37 +268,39 @@ int main(int argc, char**argv) {
(name :string))


(defun parse-command-line (s)
(split-sequence #\Space s :remove-empty-subseqs t))

(defparameter *cxx*
#+freebsd "clang++"
#+(or cygwin (not windows freebsd)) "g++"
#+(and windows (not cygwin)) "c:/msys/1.0/bin/g++.exe")
(fcase
(:freebsd "clang++")
((or :cygwin (not (or :windows :freebsd))) "g++")
((and :windows (not :cygwin)) "c:/msys/1.0/bin/g++.exe")))

(defparameter *cc-flags*
(append
(list "-Wno-write-strings")
;; For MacPorts
#+darwin (list "-I" "/opt/local/include/")
#-darwin nil
;; ECL internal flags
#+ecl (split-sequence:split-sequence #\space c::*cc-flags*
:remove-empty-subseqs t)
;; FreeBSD non-base header files
;; DragonFly Dports install software in /usr/local
;; And what about pkgsrc?
#+(or freebsd dragonfly)
(list "-I" "/usr/local/include/")))
#+ecl (parse-command-line c::*cc-flags*)
(fcase
;; For MacPorts
(:darwin '("-I" "/opt/local/include/"))
;; FreeBSD non-base header files
;; DragonFly Dports install software in /usr/local
;; And what about pkgsrc?
((or :freebsd :dragonfly) '("-I" "/usr/local/include/"))
(t '()))))

;;; FIXME: is there a better way to detect whether these flags
;;; are necessary?
(defparameter *cpu-word-size-flags*
#-(or arm x86 x86-64 sparc sparc64)
'()
#+arm
(list "-marm")
#+(or x86 x86-64 sparc sparc64)
(ecase (cffi:foreign-type-size :pointer)
(4 (list "-m32"))
(8 (list "-m64"))))
(fcase
((or :x86 :x86-64 :sparc :sparc64)
(ecase (cffi:foreign-type-size :pointer)
(4 (list "-m32"))
(8 (list "-m64"))))
(:arm '("-marm"))
(t '())))

(defparameter *platform-library-flags*
(list #+darwin "-bundle"
Expand Down
2 changes: 1 addition & 1 deletion src/grovel/package.lisp
Expand Up @@ -25,7 +25,7 @@

(defpackage :iolib-grovel
(:nicknames :iolib/grovel)
(:use #:common-lisp #:alexandria)
(:use #:alexandria #:iolib/base)
(:import-from #:cffi-sys #:native-namestring)
(:export
;; Class name
Expand Down

0 comments on commit b1956ba

Please sign in to comment.