+#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ < 409
+#include <Rts.h>
+#endif
#include <HsFFI.h>
+
#include <stddef.h>
#include <string.h>
#include <stdio.h>
+#include <stdarg.h>
+#include <ctype.h>
#ifndef offsetof
#define offsetof(t, f) ((size_t) &((t *)0)->f)
#endif
-static int hsc_options_started = 0;
-
-static void hsc_option (const char *s)
-{
- if (!hsc_options_started)
- {
- printf ("{-# OPTIONS");
- hsc_options_started = 1;
- }
- printf (" %s", s);
-}
-
-static void hsc_end_options (void)
-{
- if (hsc_options_started) printf (" #-}\n");
-}
+#if __NHC__
+#define hsc_line(line, file) \
+ printf ("# %d \"%s\"\n", line, file);
+#else
+#define hsc_line(line, file) \
+ printf ("{-# LINE %d \"%s\" #-}\n", line, file);
+#endif
#define hsc_const(x) \
if ((x) < 0) \
printf ("\\%d%s", \
(unsigned char) *s, \
s[1] >= '0' && s[1] <= '9' ? "\\&" : ""); \
- s++; \
+ ++s; \
} \
printf ("\""); \
}
#define hsc_ptr(t, f) \
printf ("(\\hsc_ptr -> hsc_ptr `plusPtr` %ld)", (long) offsetof (t, f));
+#define hsc_enum(t, f, print_name, x) \
+ print_name; \
+ printf (" :: %s\n", #t); \
+ print_name; \
+ printf (" = %s ", #f); \
+ if ((x) < 0) \
+ printf ("(%ld)\n", (long)(x)); \
+ else \
+ printf ("%lu\n", (unsigned long)(x));
+
+#define hsc_haskellize(x) \
+ { \
+ const char *s = (x); \
+ int upper = 0; \
+ if (*s != '\0') \
+ { \
+ putchar (tolower (*s)); \
+ ++s; \
+ while (*s != '\0') \
+ { \
+ if (*s == '_') \
+ upper = 1; \
+ else \
+ { \
+ putchar (upper ? toupper (*s) : tolower (*s)); \
+ upper = 0; \
+ } \
+ ++s; \
+ } \
+ } \
+ }