From 343ff7a65e0db0f70e5c1253181e50e0e44986b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 25 Feb 2023 01:50:38 -0300 Subject: Take functions out of the generated code --- cmamut.lisp | 35 ++++++----------------------------- 1 file 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+))) -- cgit v1.2.3