- (destructuring-bind (type lispname cname &optional doc) def
- (cond ((eq type :integer)
- (format stream
- "printf(\"(cl:defconstant ~A %d \\\"~A\\\")\\\n\",~A);~%"
- lispname doc cname))
- ((eq type :type)
- (format stream
- "printf(\"(sb-alien:define-alien-type ~A (sb-alien:%ssigned %d))\\\n\",SIGNED_(~A),8*(sizeof(~A)));~%"
- lispname cname cname))
- ((eq type :string)
- (format stream
- "printf(\"(cl:defvar ~A %S \\\"~A\\\")\\\n\",~A);~%"
- lispname doc cname))
- ((eq type :function)
- (c-for-function stream lispname cname))
- ((eq type :structure)
- (c-for-structure stream lispname cname))
- (t
- (format stream
- "printf(\";; Non hablo Espagnol, Monsieur~%")))))
- (format stream "exit(0);~%}")))
+ (destructuring-bind (type lispname cname &optional doc export) def
+ (case type
+ (:integer
+ (as-c "#ifdef" cname)
+ (printf "(cl:defconstant ~A %d \"~A\")" lispname doc
+ cname)
+ (as-c "#else")
+ (printf "(sb-int:style-warn \"Couldn't grovel for ~A (unknown to the C compiler).\")" cname)
+ (as-c "#endif"))
+ (:type
+ (printf "(cl:eval-when (:compile-toplevel :load-toplevel :execute) (sb-alien:define-alien-type ~A (sb-alien:%ssigned %d)))" lispname
+ (format nil "SIGNED_(~A)" cname)
+ (format nil "(8*sizeof(~A))" cname)))
+ (:string
+ (printf "(cl:defparameter ~A %s \"~A\"" lispname doc
+ cname))
+ (:function
+ (printf "(cl:declaim (cl:inline ~A))" lispname)
+ (destructuring-bind (f-cname &rest definition) cname
+ (printf "(sb-grovel::define-foreign-routine (\"~A\" ~A)" f-cname lispname)
+ (printf "~{ ~W~^\\n~})" definition)))
+ (:structure
+ ;; FIXME: structure slots should be auto-exportable as well.
+ (c-for-structure lispname cname))
+ (otherwise
+ ;; should we really not sprechen espagnol, monsieurs?
+ (error "Unknown grovel keyword encountered: ~A" type)))
+ (when export
+ (printf "(cl:export '~A)" lispname))))
+ (as-c "return 0;")
+ (as-c "}")))