summaryrefslogtreecommitdiff
path: root/cmamut.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'cmamut.lisp')
-rw-r--r--cmamut.lisp50
1 files changed, 15 insertions, 35 deletions
diff --git a/cmamut.lisp b/cmamut.lisp
index 7e6c23c..dddd512 100644
--- a/cmamut.lisp
+++ b/cmamut.lisp
@@ -58,10 +58,8 @@
(list 'sb-alien:union (intern (gethash "name" raw-type))))
((string= tag ":enum")
(list 'sb-alien:enum (gethash "name" raw-type)))
- ((string= tag "struct")
- (cook-struct raw-type type-associations))
- ((string= tag "union")
- (cook-union raw-type type-associations))
+ ((or (string= tag "struct") (string= tag "union"))
+ (cook-composite raw-type type-associations))
((string= tag "__builtin_va_list")
(list 'sb-alien:* t))
(t (let ((new-type (gethash tag type-associations)))
@@ -84,28 +82,16 @@
,(cook-type (gethash "return-type" raw-function) type-associations)
,@(queue:to-list cooked-params))))
-(defun cook-struct (raw-struct type-associations)
- (let ((raw-fields (gethash "fields" raw-struct))
+(defun cook-composite (raw-composite type-associations)
+ (let ((raw-fields (gethash "fields" raw-composite))
(cooked-fields (queue:new)))
(dotimes (j (length raw-fields))
(queue:add cooked-fields
(list (intern (gethash "name" (aref raw-fields j)))
(cook-type (gethash "type" (aref raw-fields j)) type-associations))))
- `(sb-alien:struct
- ,(when (> (length (gethash "name" raw-struct)) 0)
- (intern (gethash "name" raw-struct)))
- ,@(queue:to-list cooked-fields))))
-
-(defun cook-union (raw-union type-associations)
- (let ((raw-fields (gethash "fields" raw-union))
- (cooked-fields (queue:new)))
- (dotimes (j (length raw-fields))
- (queue:add cooked-fields
- (list (intern (gethash "name" (aref raw-fields j)))
- (cook-type (gethash "type" (aref raw-fields j)) type-associations))))
- `(sb-alien:union
- ,(when (> (length (gethash "name" raw-union)) 0)
- (intern (gethash "name" raw-union)))
+ `(,(intern (string-upcase (gethash "tag" raw-composite)) 'sb-alien)
+ ,(when (> (length (gethash "name" raw-composite)) 0)
+ (intern (gethash "name" raw-composite)))
,@(queue:to-list cooked-fields))))
(defun cook-enum (raw-enum enum-references)
@@ -150,8 +136,7 @@
(defstruct spec
functions
typedefs
- structs
- unions
+ composite
enums)
; This is done so we can separate definition types into stages when generating code.
@@ -179,7 +164,7 @@
(string= internal-tag "union"))
(when (string= (gethash "name" internal-type) "")
(setf (gethash "name" internal-type) (gethash "name" def)))
- (classify-definition internal-type spec)
+ (push internal-type (spec-composite spec))
(setf (gethash "type" def)
(json:obj ("tag" (gethash "tag" internal-type))
("name" (gethash "name" internal-type)))))
@@ -189,12 +174,10 @@
(when (string= tag "typedef")
(push def (spec-typedefs spec)))))
- ((string= tag "struct")
- (push def (spec-structs spec)))
((string= tag "enum")
(push def (spec-enums spec)))
- ((string= tag "union")
- (push def (spec-unions spec)))))
+ ((or (string= tag "struct") (string= tag "union"))
+ (push def (spec-composite spec)))))
spec)
(defun codegen (spec)
@@ -202,15 +185,12 @@
(type-associations (generate-type-associations (spec-typedefs spec))))
(let ((enums (mapcar (lambda (x) (cook-enum x enum-references))
(spec-enums spec)))
- (structs (mapcar (lambda (x)
- `(sb-alien:define-alien-type nil ,(cook-struct x type-associations)))
- (spec-structs spec)))
- (unions (mapcar (lambda (x)
- `(sb-alien:define-alien-type nil ,(cook-union x type-associations)))
- (spec-unions spec)))
+ (composite (mapcar (lambda (x)
+ `(sb-alien:define-alien-type nil ,(cook-composite x type-associations)))
+ (spec-composite spec)))
(functions (mapcar (lambda (x) (cook-function x type-associations))
(spec-functions spec))))
- (remove-duplicates (concatenate 'list enums structs unions functions) :test #'equal))))
+ (remove-duplicates (concatenate 'list enums composite functions) :test #'equal))))
(defun to-file (code filename)
(with-open-file (f filename