Early work-in-progress.
[sod] / cutting-room-floor.lisp
CommitLineData
abdf50aa
MW
1;;;--------------------------------------------------------------------------
2;;; C types stuff.
3
4(cl:defpackage #:c-types
5 (:use #:common-lisp
6 #+sbcl #:sb-mop
7 #+(or cmu clisp) #:mop
8 #+ecl #:clos)
9 (:export #:c-type
10 #:c-declarator-priority #:maybe-parenthesize
11 #:c-declaration
12 #:c-type-subtype #:compount-type-declaration
13 #:qualifiable-c-type #:c-type-qualifiers #:format-qualifiers
14 #:simple-c-type #:c-type-name
15 #:c-pointer-type
16 #:tagged-c-type #:c-enum-type #:c-struct-type #:c-union-type
17 #:tagged-c-type-kind
18 #:c-array-type #:c-array-dimensions
19 #:make-argument #:argument-name #:argument-type
20 #:c-function-type #:c-function-arguments
21
22 #:define-c-type-syntax #:c-type-alias #:defctype
23 #:print-c-type
24 #:qualifier #:declare-qualifier
25 #:define-simple-c-type
26
27 #:const #:volatile #:static #:restrict
28 #:char #:unsigned-char #:uchar #:signed-char #:schar
29 #:int #:signed #:signed-int #:sint
30 #:unsigned #:unsigned-int #:uint
31 #:short #:signed-short #:short-int #:signed-short-int #:sshort
32 #:unsigned-short #:unsigned-short-int #:ushort
33 #:long #:signed-long #:long-int #:signed-long-int #:slong
34 #:unsigned-long #:unsigned-long-int #:ulong
35 #:float #:double #:long-double
36 #:pointer #:ptr
37 #:[] #:vec
38 #:fun #:func #:fn))
39
40
41;;;--------------------------------------------------------------------------
42;;; Convenient syntax for C types.
43
44;; Basic machinery.
45
46;; Qualifiers. They have hairy syntax and need to be implemented by hand.
47
48;; Simple types.
49
50;; Pointers.
51
52;; Tagged types.
53
54;; Arrays.
55
56;; Functions.
57
58
59(progn
60 (defconstant q-byte (byte 3 0))
61 (defconstant q-const 1)
62 (defconstant q-volatile 2)
63 (defconstant q-restrict 4)
64
65 (defconstant z-byte (byte 3 3))
66 (defconstant z-unspec 0)
67 (defconstant z-short 1)
68 (defconstant z-long 2)
69 (defconstant z-long-long 3)
70 (defconstant z-double 4)
71 (defconstant z-long-double 5)
72
73 (defconstant s-byte (byte 2 6))
74 (defconstant s-unspec 0)
75 (defconstant s-signed 1)
76 (defconstant s-unsigned 2)
77
78 (defconstant t-byte (byte 3 8))
79 (defconstant t-unspec 0)
80 (defconstant t-int 1)
81 (defconstant t-char 2)
82 (defconstant t-float 3)
83 (defconstant t-user 4))
84
85(defun make-type-flags (size sign type &rest quals)
86 (let ((flags 0))
87 (dolist (qual quals)
88 (setf flags (logior flags qual)))
89 (setf (ldb z-byte flags) size
90 (ldb s-byte flags) sign
91 (ldb t-byte flags) type)
92 flags))
93