-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtoolkit.lisp
62 lines (54 loc) · 2.06 KB
/
toolkit.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(in-package #:org.shirakumo.flare.vector)
#+3d-vectors-double-floats (pushnew :3d-vectors-double-floats *features*)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar *float-type*
#+3d-vectors-double-floats 'double-float
#-3d-vectors-double-floats 'single-float))
(deftype float-type ()
'#.*float-type*)
(declaim (inline ensure-float))
(declaim (ftype (function (real) #.*float-type*)))
(defun ensure-float (thing)
(declare (optimize (speed 1)))
(coerce thing '#.*float-type*))
(defun ensure-float-param (val env)
(if (constantp val env)
(typecase val
(real (ensure-float val))
(T `(load-time-value (ensure-float ,val))))
`(locally (declare (optimize (speed 1))) (ensure-float ,val))))
(defmacro define-ofun (name args &body body)
`(progn
#+sbcl (declaim (sb-ext:maybe-inline ,name))
(defun ,name ,args
(declare (optimize (compilation-speed 0) (debug 1) (safety 1) speed))
,@body)))
(defmacro defsetf* (name args values &body body)
#-(or ccl abcl ecl)
`(defsetf ,name ,args ,values ,@body)
#+(or ccl abcl ecl) ;; Compiler bug workarounds, hooray.
(let ((args (loop for arg in args
until (eql arg '&environment)
collect arg))
(env (loop for arg = (pop args)
while arg
do (when (eql arg '&environment)
(return (pop args))))))
`(defsetf ,name ,args ,values
,@(if env
`((let (,env)
,@body))
body))))
(defun intern* (&rest parts)
(let ((*print-case* (readtable-case *readtable*))
(*package* #.*package*))
(intern (format NIL "~{~a~}" parts) #.*package*)))
(defmacro define-ptrfun (name type first-slot)
#+sbcl
(let ((name-addr (intern* name 'addr)))
`(progn
(sb-c::define-structure-slot-addressor ,name-addr :structure ,type :slot ,first-slot)
(declaim (inline ,name))
(declaim (ftype (function (,type) sb-sys:system-area-pointer) ,name))
(defun ,name (vec)
(sb-sys:int-sap (,name-addr vec))))))