File: c-main.h

package info (click to toggle)
mlton 20061107-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 27,828 kB
  • ctags: 61,118
  • sloc: ansic: 11,446; makefile: 1,339; sh: 1,160; lisp: 900; pascal: 256; asm: 97
file content (69 lines) | stat: -rw-r--r-- 3,991 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
 *    Jagannathan, and Stephen Weeks.
 * Copyright (C) 1997-2000 NEC Research Institute.
 *
 * MLton is released under a BSD-style license.
 * See the file MLton-LICENSE for details.
 */

#ifndef _C_MAIN_H_
#define _C_MAIN_H_

#include "main.h"
#include "c-common.h"

static Word32 returnAddressToFrameIndex (Word32 w) {
        return w;
}

#define Main(al, mg, mfs, mmc, pk, ps, mc, ml)                          \
/* Globals */                                                           \
int nextFun;                                                            \
bool returnToC;                                                         \
void MLton_callFromC () {                                               \
        struct cont cont;                                               \
        GC_state s;                                                     \
                                                                        \
        if (DEBUG_CCODEGEN)                                             \
                fprintf (stderr, "MLton_callFromC() starting\n");       \
        s = &gcState;                                                   \
        s->savedThread = s->currentThread;                              \
        s->canHandle += 3;                                              \
        /* Switch to the C Handler thread. */                           \
        GC_switchToThread (s, s->callFromCHandler, 0);                  \
        nextFun = *(int*)(s->stackTop - WORD_SIZE);                     \
        cont.nextChunk = nextChunks[nextFun];                           \
        returnToC = FALSE;                                              \
        do {                                                            \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
        } while (not returnToC);                                        \
        GC_switchToThread (s, s->savedThread, 0);                       \
        s->savedThread = BOGUS_THREAD;                                  \
        if (DEBUG_CCODEGEN)                                             \
                fprintf (stderr, "MLton_callFromC done\n");             \
}                                                                       \
int main (int argc, char **argv) {                                      \
        struct cont cont;                                               \
        Initialize (al, mg, mfs, mmc, pk, ps);                          \
        if (gcState.isOriginal) {                                       \
                real_Init();                                            \
                PrepFarJump(mc, ml);                                    \
        } else {                                                        \
                /* Return to the saved world */                         \
                nextFun = *(int*)(gcState.stackTop - WORD_SIZE);        \
                cont.nextChunk = nextChunks[nextFun];                   \
        }                                                               \
        /* Trampoline */                                                \
        while (1) {                                                     \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
                cont=(*(struct cont(*)(void))cont.nextChunk)();         \
        }                                                               \
}

#endif /* #ifndef _C_MAIN_H */