summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2023-03-12 02:24:50 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2023-03-12 02:24:50 -0300
commit85e222e9699855668e1157f31e3938ebeffec088 (patch)
tree4bede38534e12b24c7c6216aa289997625714728
parent2962e6fc9d7d45441185c6f80fad732f69e408a6 (diff)
downloadcmamut-85e222e9699855668e1157f31e3938ebeffec088.tar.gz
cmamut-85e222e9699855668e1157f31e3938ebeffec088.zip
Fix enum generation
-rw-r--r--cmamut.lisp17
1 files changed, 10 insertions, 7 deletions
diff --git a/cmamut.lisp b/cmamut.lisp
index e37da7d..4f90a37 100644
--- a/cmamut.lisp
+++ b/cmamut.lisp
@@ -2,6 +2,7 @@
(defparameter +target-package+ (gensym))
+; TODO: Handle cases where the header file cannot be found
(defun get-raw-spec (filename)
(sb-ext:run-program "/usr/bin/c2ffi" (list filename
"--macro-file" "defines.h"
@@ -15,6 +16,7 @@
(delete-file "defines.h")
(concatenate `(simple-vector ,(+ (length spec) (length defines))) spec defines)))
+; TODO: Handle different sizes of enum
(defun cook-type (raw-type type-associations)
(let ((tag (gethash "tag" raw-type)))
(cond ((string= tag ":void")
@@ -61,7 +63,7 @@
((string= tag ":union")
(list 'sb-alien:union (intern (gethash "name" raw-type) +target-package+)))
((string= tag ":enum")
- (list 'sb-alien:enum (gethash "name" raw-type)))
+ 'sb-alien:int)
((or (string= tag "struct") (string= tag "union"))
(cook-composite raw-type type-associations))
((string= tag "__builtin_va_list")
@@ -104,7 +106,9 @@
,(gethash "value" raw-const)))
(defun cook-enum (raw-enum enum-references)
- (let ((name (gethash (gethash "id" raw-enum) enum-references))
+ (let ((name (if (> (gethash "id" raw-enum) 0)
+ (gethash (gethash "id" raw-enum) enum-references)
+ (gethash "name" raw-enum)))
(raw-fields (gethash "fields" raw-enum))
(cooked-fields (queue:new)))
(dotimes (j (length raw-fields))
@@ -119,9 +123,10 @@
(defun generate-enum-references (raw-typedefs)
(let ((enum-references (make-hash-table :test #'equal :size 256)))
(dolist (i raw-typedefs)
- (let ((base-type (gethash "type" i)))
- (when (string= (gethash "tag" base-type) ":enum")
- (setf (gethash (gethash "id" base-type) enum-references)
+ (let ((inner-type (gethash "type" i)))
+ (when (string= (gethash "tag" inner-type) ":enum")
+ (setf (gethash "name" inner-type) (gethash "name" i))
+ (setf (gethash (gethash "id" inner-type) enum-references)
(gethash "name" i)))))
enum-references))
@@ -129,8 +134,6 @@
(defun generate-type-associations (raw-typedefs)
(let ((type-associations (make-hash-table :test #'equal :size 256)))
(dolist (i raw-typedefs)
- (when (string= (gethash "tag" (gethash "type" i)) ":enum")
- (setf (gethash "name" (gethash "type" i)) (gethash "name" i)))
(setf (gethash (gethash "name" i) type-associations) (gethash "type" i)))
(labels ((flatten-typedef
(k v)