code.h 1.22 KB
Newer Older
1
2
3
#ifndef __CODE_H
#define __CODE_H

4
#include "thunk.h"
5

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
6
7
8
9
10
#define CT_THUNK        1   // Shared thunk
#define CT_VAR 		2
#define CT_APP 		3
#define CT_SELECT	4
#define CT_IF		5
11

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
12
13
struct Code {
    unsigned int type : 3;
14
    unsigned int nr_args : 5;       // used in AppEntry
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
15
    unsigned int dyn_app : 1;       // used in AppEntry
16
17
    unsigned int nr_cases : 5;      // used in SelectEntry
    unsigned int strict : 1;        // used in VarEntry
18
19
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
20
struct ThunkEntry {
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
21
    struct Code base;
22
    struct Thunk thunk;
23
24
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
25
26
struct VarEntry {
    struct Code base;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
27
    int index; // index on the stack
28
29
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
30
31
struct AppEntry {
    struct Code base;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
32
33
34
35
    union {
        struct VarEntry var;
        struct Desc* f;
    };
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
36
    struct Code* args[];
37
38
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
39
40
41
42
#define SC_CONS			1
#define SC_LIT			2
#define SC_DEFAULT		3

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
43
44
45
46
47
48
struct SelectCaseEntry {
    int type;
    struct Code* body;

    union {
        struct ADTEntry* cons;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
49
        struct ThunkEntry* lit;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
50
    };
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
51
52
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
53
54
55
56
struct SelectEntry {
    struct Code base;
    struct Code* expr;
    struct SelectCaseEntry cases[];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
57
58
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
59
60
61
62
63
struct IfEntry {
    struct Code base;
    struct Code* cond;
    struct Code* texpr;
    struct Code* fexpr;
64
65
};

66
void exec(Code* expr, int frame_ptr, int root_frame_ptr);
67

68
#endif // __CODE_H