Backport from sid to buster
[hcoop/debian/mlton.git] / include / common-main.h
1 /* Copyright (C) 2014 Matthew Fluet.
2 * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
3 * Jagannathan, and Stephen Weeks.
4 * Copyright (C) 1997-2000 NEC Research Institute.
5 *
6 * MLton is released under a BSD-style license.
7 * See the file MLton-LICENSE for details.
8 */
9
10 #ifndef _COMMON_MAIN_H_
11 #define _COMMON_MAIN_H_
12
13 #include "mlton-main.h"
14
15 #define MLTON_GC_INTERNAL_TYPES
16 #define MLTON_GC_INTERNAL_BASIS
17 #include "platform.h"
18
19 /* The label must be declared as weak because gcc's optimizer may prove that
20 * the code that declares the label is dead and hence eliminate the declaration.
21 */
22 #define DeclareProfileLabel(l) \
23 extern char l __attribute__ ((weak))
24
25 #define BeginVectorInits static struct GC_vectorInit vectorInits[] = {
26 #define VectorInitElem(es, gi, l, w) { es, gi, l, w },
27 #define EndVectorInits };
28
29 #define LoadArray(a, f) if (fread (a, sizeof(*a), cardof(a), f) != cardof(a)) return -1;
30 #define SaveArray(a, f) if (fwrite(a, sizeof(*a), cardof(a), f) != cardof(a)) return -1;
31
32 PRIVATE Pointer gcStateAddress;
33
34 #define Initialize(al, mg, mfs, mmc, pk, ps) \
35 gcStateAddress = (pointer)&gcState; \
36 gcState.alignment = al; \
37 gcState.atMLtons = atMLtons; \
38 gcState.atMLtonsLength = cardof(atMLtons); \
39 gcState.frameLayouts = frameLayouts; \
40 gcState.frameLayoutsLength = cardof(frameLayouts); \
41 gcState.globals = (objptr*)globalObjptr; \
42 gcState.globalsLength = cardof(globalObjptr); \
43 gcState.loadGlobals = loadGlobals; \
44 gcState.magic = mg; \
45 gcState.maxFrameSize = mfs; \
46 gcState.mutatorMarksCards = mmc; \
47 gcState.objectTypes = objectTypes; \
48 gcState.objectTypesLength = cardof(objectTypes); \
49 gcState.returnAddressToFrameIndex = returnAddressToFrameIndex; \
50 gcState.saveGlobals = saveGlobals; \
51 gcState.vectorInits = vectorInits; \
52 gcState.vectorInitsLength = cardof(vectorInits); \
53 gcState.sourceMaps.frameSources = frameSources; \
54 gcState.sourceMaps.frameSourcesLength = cardof(frameSources); \
55 gcState.sourceMaps.sourceLabels = sourceLabels; \
56 gcState.sourceMaps.sourceLabelsLength = cardof(sourceLabels); \
57 gcState.sourceMaps.sourceNames = sourceNames; \
58 gcState.sourceMaps.sourceNamesLength = cardof(sourceNames); \
59 gcState.sourceMaps.sourceSeqs = sourceSeqs; \
60 gcState.sourceMaps.sourceSeqsLength = cardof(sourceSeqs); \
61 gcState.sourceMaps.sources = sources; \
62 gcState.sourceMaps.sourcesLength = cardof(sources); \
63 gcState.profiling.kind = pk; \
64 gcState.profiling.stack = ps; \
65 MLton_init (argc, argv, &gcState); \
66
67 #define LIB_PASTE(x,y) x ## y
68 #define LIB_OPEN(x) LIB_PASTE(x, _open)
69 #define LIB_CLOSE(x) LIB_PASTE(x, _close)
70
71 static void MLton_callFromC ();
72
73 #endif /* #ifndef _COMMON_MAIN_H_ */