Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Groveler: move boilerplate C code to common.h

  • Loading branch information...
commit 1b464f292f53a12a53a690f66abe5b13174ebed5 1 parent 939edc8
@sionescu sionescu authored
Showing with 55 additions and 51 deletions.
  1. +1 −0  cffi-grovel.asd
  2. +48 −0 grovel/common.h
  3. +6 −51 grovel/grovel.lisp
View
1  cffi-grovel.asd
@@ -36,6 +36,7 @@
:components
((:file "package")
(:file "invoke")
+ (:static-file "common.h")
(:file "grovel")
(:file "asdf")))))
View
48 grovel/common.h
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#ifndef offsetof
+#define offsetof(type, slot) ((int) ((char *) &(((type *) 0)->slot)))
+#endif
+#define sizeofslot(type, slot) (sizeof(((type *) 0)->slot))
+#define stringify(x) #x
+#define indirect_stringify(x) stringify(x)
+
+#define SIGNEDP(x) (((x)-1)<0)
+#define SIGNED_(x) (SIGNEDP(x)?"":"un")
+#define SIGNED64P(x) ( x <= 0x7FFFFFFFFFFFFFFFLL )
+
+void type_name(FILE *output, int signed_p, int size) {
+ if (signed_p) {
+ switch (size) {
+ case 1: fprintf(output, ":int8"); break;
+ case 2: fprintf(output, ":int16"); break;
+ case 4: fprintf(output, ":int32"); break;
+ case 8: fprintf(output, ":int64"); break;
+ default: goto error;
+ }
+ } else {
+ switch(size) {
+ case 1: fprintf(output, ":uint8"); break;
+ case 2: fprintf(output, ":uint16"); break;
+ case 4: fprintf(output, ":uint32"); break;
+ case 8: fprintf(output, ":uint64"); break;
+ default: goto error;
+ }
+ }
+
+ return;
+
+error:
+ fprintf(output, "(cl:error \"No type of size ~D.\" %i)\n", size);
+}
+
+char* print_double_for_lisp(double n)
+{
+ static char buf[256];
+ memset(buf, 0, 256);
+ snprintf(buf, 255, "(let ((*read-default-float-format* 'double-float)) (coerce (read-from-string \"%.20E\") 'double-float))", n);
+ return buf;
+}
View
57 grovel/grovel.lisp
@@ -68,24 +68,7 @@
(defparameter *prologue*
"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-
-#ifndef offsetof
-#define offsetof(type, slot) ((int) ((char *) &(((type *) 0)->slot)))
-#endif
-#define sizeofslot(type, slot) (sizeof(((type *) 0)->slot))
-#define stringify(x) #x
-#define indirect_stringify(x) stringify(x)
-
-#define SIGNEDP(x) (((x)-1)<0)
-#define SIGNED_(x) (SIGNEDP(x)?\"\":\"un\")
-#define SIGNED64P(x) ( x <= 0x7FFFFFFFFFFFFFFFLL )
-
-void type_name(FILE *output, int signed_p, int size);
-char* print_double_for_lisp(double n);
+#include <grovel/common.h>
int main(int argc, char**argv) {
FILE *output = argc > 1 ? fopen(argv[1], \"w\") : stdout;
@@ -99,39 +82,6 @@ int main(int argc, char**argv) {
fclose(output);
return 0;
}
-
-void type_name(FILE *output, int signed_p, int size) {
- if (signed_p) {
- switch (size) {
- case 1: fprintf(output, \":int8\"); break;
- case 2: fprintf(output, \":int16\"); break;
- case 4: fprintf(output, \":int32\"); break;
- case 8: fprintf(output, \":int64\"); break;
- default: goto error;
- }
- } else {
- switch(size) {
- case 1: fprintf(output, \":uint8\"); break;
- case 2: fprintf(output, \":uint16\"); break;
- case 4: fprintf(output, \":uint32\"); break;
- case 8: fprintf(output, \":uint64\"); break;
- default: goto error;
- }
- }
-
- return;
-
-error:
- fprintf(output, \"(cl:error \\\"No type of size ~D.\\\" %i)\\n\", size);
-}
-
-char* print_double_for_lisp(double n)
-{
- static char buf[256];
- memset(buf, 0, 256);
- snprintf(buf, 255, \"(let ((*read-default-float-format* 'double-float)) (coerce (read-from-string \\\"%.20E\\\") 'double-float))\", n);
- return buf;
-}
")
(defun unescape-for-c (text)
@@ -303,6 +253,11 @@ char* print_double_for_lisp(double n)
`(,(or (getenv "CC") *cc*)
,@*cpu-word-size-flags*
,@*cc-flags*
+ ;; add the cffi directory to the include path to make common.h visible
+ ,(format nil "-I~A"
+ (directory-namestring
+ (truename
+ (asdf:system-definition-pathname :cffi-grovel))))
,@(when library *platform-library-flags*)
"-fPIC" "-o"
,(native-namestring output-file)
Please sign in to comment.
Something went wrong with that request. Please try again.