X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-grovel%2Fdef-to-lisp.lisp;h=3b2cba1aa8110ca1f9a1bd3abb56395a74ee8d4f;hb=81ccc83350c9caae310bfeb0ddd71284f25e1e1f;hp=2440775ea1708a770f00429107af80a3f84e5c36;hpb=d1de626e8dcd1ab98ceedf818f055f64f3060a7b;p=sbcl.git diff --git a/contrib/sb-grovel/def-to-lisp.lisp b/contrib/sb-grovel/def-to-lisp.lisp index 2440775..3b2cba1 100644 --- a/contrib/sb-grovel/def-to-lisp.lisp +++ b/contrib/sb-grovel/def-to-lisp.lisp @@ -5,7 +5,7 @@ (destructuring-bind (c-name &rest elements) c-struct (format stream "printf(\"(sb-grovel::define-c-struct ~A %d)\\n\",sizeof (~A));~%" lisp-name c-name) (dolist (e elements) - (destructuring-bind (lisp-type lisp-el-name c-type c-el-name) e + (destructuring-bind (lisp-type lisp-el-name c-type c-el-name &key distrust-length) e ;; FIXME: this format string doesn't actually guarantee ;; non-multilined-string-constantness, it just makes it more ;; likely. Sort out the required behaviour (and maybe make @@ -18,8 +18,10 @@ (format stream "{ ~A t;printf(\"%d \",((unsigned long)&(t.~A)) - ((unsigned long)&(t)) ); }~%" c-name c-el-name) ;; length - (format stream "{ ~A t;printf(\"%d\",(sizeof t.~A));}~%" - c-name c-el-name) + (if distrust-length + (format stream "printf(\"|CL|:|NIL|\");") + (format stream "{ ~A t;printf(\"%d\",(sizeof t.~A));}~%" + c-name c-el-name)) (format stream "printf(\")\\n\");~%"))))) (defun c-for-function (stream lisp-name alien-defn) @@ -34,7 +36,7 @@ (let ((*print-right-margin* nil)) (format stream "#define SIGNEDP(x) (((x)-1)<0)~%") (format stream "#define SIGNED_(x) (SIGNEDP(x)?\"\":\"un\")~%") - (loop for i in headers + (loop for i in (cons "stdio.h" headers) do (format stream "#include <~A>~%" i)) (format stream "main() { ~% printf(\"(in-package ~S)\\\n\");~%" package-name) @@ -48,8 +50,12 @@ printf(\"(in-package ~S)\\\n\");~%" package-name) (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)) + "#ifdef ~A~%~ + printf(\"(cl:defconstant ~A %d \\\"~A\\\")\\\n\",~A);~%~ + #else~%~ + printf(\"(sb-int:style-warn \\\"Couln't grovel definition for ~A (unknown to the C compiler).\\\")\\n\");~%~ + #endif~%" + cname lispname doc cname cname)) ((eq type :type) (format stream "printf(\"(sb-alien:define-alien-type ~A (sb-alien:%ssigned %d))\\\n\",SIGNED_(~A),8*(sizeof(~A)));~%"