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

4
#include "thunk.h"
5

6
7
8
enum CodeType {
    CT_VAR, CT_VAR_STRICT, CT_APP, CT_APP_DYN, CT_SELECT, CT_IF, CT_THUNK
};
9

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

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
17
struct ThunkEntry {
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
18
    struct Code base;
19
    struct Thunk thunk;
20
21
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
22
23
struct VarEntry {
    struct Code base;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
24
    int index; // index on the stack
25
26
};

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

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
36
37
38
39
#define SC_CONS			1
#define SC_LIT			2
#define SC_DEFAULT		3

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
40
41
42
43
44
45
struct SelectCaseEntry {
    int type;
    struct Code* body;

    union {
        struct ADTEntry* cons;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
46
        struct ThunkEntry* lit;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
47
    };
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
48
49
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
50
51
52
53
struct SelectEntry {
    struct Code base;
    struct Code* expr;
    struct SelectCaseEntry cases[];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
54
55
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
56
57
58
59
60
struct IfEntry {
    struct Code base;
    struct Code* cond;
    struct Code* texpr;
    struct Code* fexpr;
61
62
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
63
void exec(Code* expr, int frame_ptr, int root_frame_ptr);
64
struct Thunk* eval(Thunk* thunk);
65

66
#endif // __CODE_H