-
Notifications
You must be signed in to change notification settings - Fork 10
/
types.lisp
54 lines (40 loc) · 1.47 KB
/
types.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
;;;; types.lisp -- various useful types
(cl:in-package :nibbles)
(deftype octet ()
'(unsigned-byte 8))
(deftype index ()
'(mod #.array-dimension-limit))
;;; Type `octet-vector' and constructors
;;
(deftype octet-vector (&optional (length '*))
`(array octet (,length)))
(declaim (ftype (function (index
&key
(:initial-element octet))
octet-vector)
make-octet-vector)
(inline make-octet-vector))
(defun make-octet-vector (count
&key
(initial-element 0))
"Make and return an `octet-vector' with COUNT elements.
If supplied, INITIAL-ELEMENT is used to populate the vector. The value
of INITIAL-ELEMENT has to of type `octet'. "
(make-array count
:element-type 'octet
:initial-element initial-element))
(declaim (ftype (function (&rest octet) octet-vector) octet-vector)
(inline octet-vector))
(defun octet-vector (&rest args)
"Make and return an `octet-vector' containing the elements ARGS.
ARGS have to be of type `octet'."
(make-array (length args)
:element-type 'octet
:initial-contents args
:adjustable nil
:fill-pointer nil))
;;; Type `simple-octet-vector'
;;
(deftype simple-octet-vector (&optional (length '*))
#+(or sbcl cmu) `(simple-array octet (,length))
#-(or sbcl cmu) `(array octet (,length)))