From b0f56c30ff10f66cb76cfed39a329739bafe1d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 23 Jul 2023 20:25:36 -0300 Subject: Add the directory of the header file to the search dirs by default --- cmamut.lisp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'cmamut.lisp') diff --git a/cmamut.lisp b/cmamut.lisp index 68c40ee..4ecfda6 100644 --- a/cmamut.lisp +++ b/cmamut.lisp @@ -2,7 +2,6 @@ (defparameter +target-package+ (gensym)) -; TODO: Handle cases where the header file cannot be found VERY IMPORTANT (defun get-raw-spec (filename search-directories) (sb-ext:run-program "/usr/bin/c2ffi" (list filename "--macro-file" "defines.h" @@ -161,7 +160,7 @@ enums) ; This is done so we can separate definition types into stages when generating code. -; Some crazy shit is happening when processing typedefs so we can identify nested composite types and put them into the right buckets. +; When processing typedefs we need to identify nested composite types and put them into the right buckets. ; What's left on the typedefs are references to said composite types. ; This allows for a comfier type resolution stage by letting us flatten typedefs. ; Composite types cause problems because they can't be redefined. @@ -273,11 +272,6 @@ (*package* (find-package +target-package+))) (format f "~{~s~&~}" code)))) -(defun file-name (path) - (subseq path - (1+ (or (position #\/ path :from-end t) -1)) - (position #\. path))) - (defun filter-directories (search-directories raw-spec) (remove-if (lambda (x) (and (notany (lambda (dir) @@ -288,11 +282,15 @@ (string/= (gethash "tag" x) "const"))) raw-spec)) -(defun run (path-to-header-file &key search-directories name-transformer) +(defun run (path-to-header-file &key additional-directories name-transformer) + (unless (probe-file path-to-header-file) + (error (format t "The header file ~a doesn't exist!" path-to-header-file))) (when (not (find-package +target-package+)) (make-package +target-package+)) - (let* ((raw-spec (get-raw-spec path-to-header-file search-directories)) - (spec (classify-definitions (filter-directories search-directories raw-spec))) + (setf path-to-header-file (parse-namestring path-to-header-file)) + (push (directory-namestring path-to-header-file) additional-directories) + (let* ((raw-spec (get-raw-spec (namestring path-to-header-file) additional-directories)) + (spec (classify-definitions (filter-directories additional-directories raw-spec))) (code (codegen spec (or name-transformer (lambda (name kind) name))))) - (to-file code (concatenate 'string (file-name path-to-header-file) ".lisp"))) + (to-file code (concatenate 'string (pathname-name path-to-header-file) ".lisp"))) (delete-package (find-package +target-package+))) -- cgit v1.2.3