-
Notifications
You must be signed in to change notification settings - Fork 8
/
types.lisp
61 lines (52 loc) · 2.21 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
55
56
57
58
59
60
61
;;;; types.lisp -- various useful types
(cl:in-package :binascii)
(deftype index () '(mod #.array-dimension-limit))
(deftype simple-octet-vector (&optional (length '*))
#+(or sbcl cmu ccl) `(simple-array (unsigned-byte 8) (,length))
#-(or sbcl cmu ccl) `(array (unsigned-byte 8) (,length)))
(deftype simple-string ()
#+sbcl '(and cl:simple-string (not (simple-array nil (*))))
#+(or cmu ccl) 'cl:simple-string
#-(or sbcl cmu ccl) 'cl:string)
(defun required-argument ()
(error "Required argument not provided"))
(defstruct (format-descriptor
(:conc-name fd-)
(:copier nil)
(:constructor make-format-descriptor
(encoded-length octets->string
octets->octets/encode
decoded-length
string->octets
octets->octets/decode)))
(encoded-length (required-argument) :type function :read-only t)
(octets->string (required-argument) :type function :read-only t)
(octets->octets/encode (required-argument) :type function :read-only t)
(decoded-length (required-argument) :type function :read-only t)
(string->octets (required-argument) :type function :read-only t)
(octets->octets/decode (required-argument) :type function :read-only t))
(defstruct (state
(:copier nil)
(:predicate nil)
(:constructor nil))
(descriptor (required-argument) :type format-descriptor :read-only t)
;; FINISHED-INPUT-P is either T or NIL depending on whether we have
;; seen all of the input.
(finished-input-p nil)
;; Likewise for FINISHED-OUTPUT-P.
(finished-output-p nil))
(defstruct (encode-state
(:include state)
(:copier nil)
(:predicate nil)
(:constructor nil))
;; LINE-BREAK describes after how many characters we should be
;; inserting newlines into the encoded output. It is zero if we
;; should never insert newlines.
(line-break 0 :type (integer 0 *)))
(defstruct (decode-state
(:include state)
(:copier nil)
(:predicate nil)
(:constructor nil))
)