[initialize CAFs statically, add hs_init and friends to the rts to be compliant with the FFI spec, allow compiling without generating a 'main'
John Meacham <john@repetae.net>**20090813053325
 Ignore-this: 8970666bd27accca219beede653459da
] hunk ./Makefile.am 213
-MAINTAINERCLEANFILES= $(BUILT_SOURCES)  $(DRIFTFILES)
+MAINTAINERCLEANFILES= $(BUILT_SOURCES) $(DRIFTFILES)
+
+LIB_OPTIONS=$(RTSOPTS) $(JHC_TEST) --noauto -L- -L.
hunk ./Makefile.am 217
-base-1.0.hl: lib/base/base.cabal jhc-1.0.hl
-	mkdir -p tmp/libho
-	./jhc -funboxed-tuples $(RTSOPTS) $(JHC_TEST)  --ho-dir tmp/libho -ilib/base --noauto -L. -pjhc --build-hl lib/base/base.cabal -o $@
hunk ./Makefile.am 219
-	mkdir -p tmp/libho
-	./jhc $(RTSOPTS) $(JHC_TEST)  --ho-dir tmp/libho -ilib/jhc --noauto --build-hl $< -o $@
+	./jhc $(LIB_OPTIONS) -ilib/jhc --build-hl $< -o $@
+
+base-1.0.hl: lib/base/base.cabal jhc-1.0.hl
+	./jhc $(LIB_OPTIONS) -ilib/base -pjhc --build-hl $< -o $@
hunk ./Makefile.am 225
-	mkdir -p tmp/libho
-	./jhc $(RTSOPTS) $(JHC_TEST)  --ho-dir tmp/libho -ilib/applicative  --noauto -L- -L. -pjhc -p base --build-hl lib/applicative/applicative.cabal -o $@
+	./jhc $(LIB_OPTIONS) -ilib/applicative -pjhc -pbase --build-hl $< -o $@
hunk ./Makefile.am 228
-	mkdir -p tmp/libho
-	./jhc $(RTSOPTS) $(JHC_TEST) -Isrc/data -Ilib/containers/include --ho-dir tmp/libho -ilib/containers  --noauto -L- -L. -pjhc -p base -p applicative --build-hl lib/containers.cabal -fcpp -o $@
+	./jhc $(LIB_OPTIONS) -Isrc/data -Ilib/containers/include -ilib/containers -pjhc -pbase -papplicative -fcpp --build-hl $<  -o $@
hunk ./Makefile.am 231
-	mkdir -p tmp/libho
-	./jhc $(RTSOPTS) $(JHC_TEST) --ho-dir tmp/libho -ilib/haskell98 --noauto -L- -L. -pjhc -p base --build-hl lib/haskell98.cabal -o $@
+	./jhc $(LIB_OPTIONS) -ilib/haskell98 -pjhc -pbase --build-hl $< -o $@
hunk ./src/C/FromGrin2.hs 108
-    ans = vcat $ includes ++ [text "", enum_tag_t, header, cafs,buildConstants grin finalHcHash, body]
+    ans = vcat $ includes ++ [text "", enum_tag_t, header,cafs, buildConstants grin finalHcHash, body]
hunk ./src/C/FromGrin2.hs 112
-    ((),finalHcHash,Written { wRequires = req, wFunctions = fm, wEnums = wenum, wStructures = sm, wTags = ts }) = runC grin go
+    (cafs',finalHcHash,Written { wRequires = req, wFunctions = fm, wEnums = wenum, wStructures = sm, wTags = ts }) = runC grin $ go >> mapM convertCAF (grinCafs grin)
hunk ./src/C/FromGrin2.hs 129
-    cafs = text "/* CAFS */" $$ (vcat $ map ccaf (grinCafs grin))
+    cafs = text "/* CAFS */" $$ (vcat $ cafs')
+    convertCAF (v,val@(NodeC a [])) = do
+        en <- declareEvalFunc a
+        let ef =  drawG $ f_EVALFUNC (reference $ variable en)
+        let ts =  text "/* " <> text (show v) <> text " = " <> (text $ P.render (pprint val)) <> text "*/\n" <>
+                text "static node_t _" <> tshow (varName v) <> text " = { .head = " <> ef <> text " };\n" <>
+                text "#define " <> tshow (varName v) <+>  text "(EVALTAGC(&_" <> tshow (varName v) <> text "))\n";
+        return ts
+        
hunk ./src/C/Generate.hs 597
-        return (shead $$ line $$ shead2, vcat protos $$ line $$  vsep bodys)
+        return (shead $$ line $$ shead2 $$ vcat protos, line $$  vsep bodys)
hunk ./src/Grin/FromE.hs 231
-            grinCafs = [ (x,NodeC tagHole []) | (x,_) <- cafs]
+            grinCafs = [ (x,node) | (x,node) <- cafs]
hunk ./src/data/rts/jhc_rts.c 155
-int  A_COLD
+#if _JHC_STANDALONE
+int
hunk ./src/data/rts/jhc_rts.c 159
-        /* A few random assertions about the architecture that the compiler
-         * assumes. should be true of any but the oddest of beasts.
-         */
+        hs_init(&argc,&argv);
+        if (jhc_setjmp(jhc_uncaught))
+                jhc_error("Uncaught Exception");
+        else
+                _amain();
+        hs_exit();
+        return 0;
+}
+#endif
hunk ./src/data/rts/jhc_rts.c 169
-        assert(sizeof(HsPtr) == sizeof(HsFunPtr));
-        assert(sizeof(HsPtr) == sizeof(intptr_t));
-        assert(sizeof(HsPtr) == sizeof(uintptr_t));
-        assert(CHAR_BIT == 8);
-        assert(EOF == -1);
hunk ./src/data/rts/jhc_rts.c 170
-        jhc_arch_assert();
-        jhc_malloc_init();
+void hs_set_argv(int argc, char *argv[])
+{
hunk ./src/data/rts/jhc_rts.c 175
+}
+
+static int hs_init_count;
+
+void
+hs_init(int *argc, char **argv[])
+{
+
+        if(!hs_init_count++) {
+                /* A few random assertions about the architecture that the compiler
+                 * assumes. should be true of any but the oddest of beasts.
+                 */
+
+                assert(sizeof(HsPtr) == sizeof(HsFunPtr));
+                assert(sizeof(HsPtr) == sizeof(intptr_t));
+                assert(sizeof(HsPtr) == sizeof(uintptr_t));
+                assert(CHAR_BIT == 8);
+                assert(EOF == -1);
+
+                jhc_arch_assert();
+                jhc_malloc_init();
+                hs_set_argv(*argc,*argv);
hunk ./src/data/rts/jhc_rts.c 198
-        if(!uname(&jhc_utsname)) {
-                jhc_options_arch = jhc_utsname.machine;
-                jhc_options_os   = jhc_utsname.sysname;
-        }
+                if(!uname(&jhc_utsname)) {
+                        jhc_options_arch = jhc_utsname.machine;
+                        jhc_options_os   = jhc_utsname.sysname;
+                }
hunk ./src/data/rts/jhc_rts.c 203
-        setlocale(LC_ALL,"");
-        if (jhc_setjmp(jhc_uncaught))
-                jhc_error("Uncaught Exception");
-        else
-                _amain();
-        jhc_print_profile();
-        return 0;
+                setlocale(LC_ALL,"");
+        }
hunk ./src/data/rts/jhc_rts.c 207
+void hs_exit (void)
+{
+        if(!--hs_init_count)
+                jhc_print_profile();
+}
hunk ./src/data/rts/jhc_rts2.c 11
-#define EVALFUNC(fn) ((fptr_t)((uintptr_t)(fn) | P_FUNC))
+#define EVALFUNC(fn) ((fptr_t)((uintptr_t)(fn) + P_FUNC))
hunk ./src/data/rts/jhc_rts_alloc.c 13
+void hs_perform_gc(void) {}
+void hs_free_stable_ptr(HsStablePtr sp) {}
+void hs_free_fun_ptr(HsFunPtr fp) {}
+
hunk ./src/data/rts/jhc_rts_header.h 47
+#ifndef _JHC_STANDALONE
+#define _JHC_STANDALONE 1
+#endif
+