2 (in-package :cl-x86-asm
)
4 ;; -- convienence ---------------------------------------------------------------
6 ;;(defun dump-x86-asm-core ()
7 ;; (save-lisp-and-die (merge-pathnames (make-pathname :name "sbcl.x86asm" :type ".core"))))
10 ;; if form is nil, body is evaluated and value returned, otherwise
11 ;; result of evaluating form is returned. Form is evaluated only once
13 (defmacro eval-unless
(form &rest body
)
14 (let ((form-symbol (gensym)))
15 `(let ((,form-symbol
,form
))
20 ;; given a numeric value, potentially > 256,
21 ;; decompose it to a list of values 0 > v > 256
22 (defun decompose-to-bytes (value)
23 (assert (numberp value
))
26 for x
= value then
(ash x -
8)
28 collect
(logand x
#XFF
))))
30 ;; given a numeric value, potentially > 256,
31 ;; decompose it to a list of values 0 > v > 256
32 (defun decompose-to-n-bytes (value byte-count
)
33 (assert (numberp value
))
36 for x
= value then
(ash x -
8)
37 for i from
0 below byte-count
38 collect
(logand x
#XFF
))))
41 ;; seemed like a good idea at the time..don't think I need
43 (defmacro predicated-bind
((symbols-and-predicates)
44 value-form
&body form
)
45 "(predicated-bind ((symbol predicate ..)) value-form body)
46 If the nth element of value-form satisfies the nth predicate, bind it to
47 the nth symbol, else bind it to nil, then evaluate body"
50 for
(symbol predicate
) in symbols-and-predicates
54 (let ((val-sym (gensym)))
55 `(let ((,val-sym
,val
))
56 (when (funcall ,predicate
,val-sym
)
60 (defun symbol-is-in-package (sym package-name
)
61 "(symbol-is-in-package sym package-name) simple predicate to test what it says"
62 (eq (symbol-package sym
) (find-package package-name
)))
64 (defmacro zero-when-null
(sym)
69 (if (null ,sym-sym
) 0 ,sym-sym
))))
72 "Make into list if atom"
73 (if (listp obj
) obj
(list obj
)))
75 (defun map-and-remove-nils (fn lst
)
76 "Map a list by function, eliminate elements where fn returns nil"
78 (dolist (x lst
(nreverse acc
))
79 (let ((val (funcall fn x
)))
80 (when val
(push val acc
))))))
82 (defun filter (fn lst
)
83 "Filter a list by function, eliminate elements where fn returns nil"
85 (dolist (x lst
(nreverse acc
))
90 "Flatten a list with sublists, and remove nils."
91 (cond ((atom lis
) lis
)
93 (append (flatten (car lis
)) (flatten (cdr lis
))))
94 (t (append (list (car lis
)) (flatten (cdr lis
))))))
97 (defun contains-keyword (keywords list
)
98 "Test to see if list contains one of the keywors in the list"
99 (mapcar #'(lambda (k) (member k list
)) keywords
))