diff options
Diffstat (limited to 'cmamut.lisp')
-rw-r--r-- | cmamut.lisp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/cmamut.lisp b/cmamut.lisp index 2b7628c..e37da7d 100644 --- a/cmamut.lisp +++ b/cmamut.lisp @@ -1,11 +1,19 @@ (in-package #:cmamut) -; TODO: Use c2ffi to extract the spec.json using the header file as parameter - (defparameter +target-package+ (gensym)) (defun get-raw-spec (filename) - (json:from-file filename)) + (sb-ext:run-program "/usr/bin/c2ffi" (list filename + "--macro-file" "defines.h" + "--output" "spec.json")) + (sb-ext:run-program "/usr/bin/c2ffi" '("defines.h" + "--output" "defines.json")) + (let ((spec (json:from-file "spec.json")) + (defines (json:from-file "defines.json"))) + (delete-file "spec.json") + (delete-file "defines.json") + (delete-file "defines.h") + (concatenate `(simple-vector ,(+ (length spec) (length defines))) spec defines))) (defun cook-type (raw-type type-associations) (let ((tag (gethash "tag" raw-type))) @@ -250,11 +258,16 @@ (*package* (find-package +target-package+))) (format f "~{~s~&~}" code)))) -(defun run (input output &optional function-filter) +(defun file-name (path) + (subseq path + (1+ (or (position #\/ path :from-end t) -1)) + (position #\. path))) + +(defun run (input &optional function-filter) (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))) - (to-file code output)) + (to-file code (concatenate 'string (file-name input) ".lisp"))) (delete-package (find-package +target-package+))) |