diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-25 01:50:38 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-25 01:50:38 -0300 |
commit | 343ff7a65e0db0f70e5c1253181e50e0e44986b2 (patch) | |
tree | 4460499fdfe87106f1ef77383a3813f37290b007 /cmamut.lisp | |
parent | c6ac67db027f3437e47d674a1a20de6512b7d11c (diff) | |
download | cmamut-343ff7a65e0db0f70e5c1253181e50e0e44986b2.tar.gz cmamut-343ff7a65e0db0f70e5c1253181e50e0e44986b2.zip |
Take functions out of the generated code
Diffstat (limited to 'cmamut.lisp')
-rw-r--r-- | cmamut.lisp | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/cmamut.lisp b/cmamut.lisp index 3f94c46..8eac12f 100644 --- a/cmamut.lisp +++ b/cmamut.lisp @@ -65,21 +65,6 @@ (cook-type new-type type-associations) (error "Unknown type: ~a" tag))))))) -(defun cook-function (raw-function type-associations) - (let ((raw-params (gethash "parameters" raw-function)) - (cooked-params (queue:new))) - (dotimes (j (length raw-params)) - (queue:add cooked-params - (list (if (string= (gethash "name" (aref raw-params j)) "") - (gensym) - (intern (gethash "name" (aref raw-params j)) +target-package+)) - (cook-type (gethash "type" (aref raw-params j)) type-associations)))) - `(sb-alien:define-alien-routine - ,(let ((function-name (gethash "name" raw-function))) - (list function-name (intern function-name +target-package+))) - ,(cook-type (gethash "return-type" raw-function) type-associations) - ,@(queue:to-list cooked-params)))) - (defun cook-composite (raw-composite type-associations) (let ((raw-fields (gethash "fields" raw-composite)) (cooked-fields (queue:new))) @@ -138,7 +123,6 @@ (defstruct spec consts - functions typedefs composite enums) @@ -156,10 +140,7 @@ (defun classify-definition (def spec) (let ((tag (gethash "tag" def))) - (cond ((string= tag "function") - (push def (spec-functions spec))) - - ((and (string= tag "const") (gethash "value" def)) + (cond ((and (string= tag "const") (gethash "value" def)) (push def (spec-consts spec))) ((or (string= tag "typedef") @@ -226,7 +207,7 @@ (filter-deps comps-and-deps)) (reverse result))) -(defun codegen (spec function-filter) +(defun codegen (spec) (let ((enum-references (generate-enum-references (spec-typedefs spec))) (type-associations (generate-type-associations (spec-typedefs spec)))) (let ((consts (mapcar #'cook-const (spec-consts spec))) @@ -235,12 +216,8 @@ (composite (mapcar (lambda (x) `(sb-alien:define-alien-type nil ,x)) (sort-composites-by-deps (mapcar (lambda (x) (cook-composite x type-associations)) - (spec-composite spec))))) - (functions (mapcar (lambda (x) (cook-function x type-associations)) - (if function-filter - (remove-if-not function-filter (spec-functions spec)) - (spec-functions spec))))) - (remove-duplicates (concatenate 'list consts enums composite functions) :test #'equal)))) + (spec-composite spec)))))) + (remove-duplicates (concatenate 'list consts enums composite) :test #'equal)))) (defun to-file (code filename) (with-open-file (f filename @@ -253,11 +230,11 @@ (*package* (find-package +target-package+))) (format f "~{~s~&~}" code)))) -(defun run (input output &optional function-filter) +(defun run (input output) (when (not (find-package +target-package+)) (make-package +target-package+)) (let* ((raw-spec (get-raw-spec input)) (spec (classify-definitions raw-spec)) - (code (codegen spec function-filter))) + (code (codegen spec))) (to-file code output)) (delete-package (find-package +target-package+))) |