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

4
#include "thunk.h"
5

6
enum CodeType {
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
7
8
9
10
    CT_VAR, CT_VAR_STRICT, 
    CT_APP_THUNK, CT_APP_PRIM, CT_APP_FUN, CT_APP_DYN, 
    CT_SELECT, CT_IF, 
    CT_THUNK
11
};
12

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
13
struct Code {
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
14
    CodeType type : 4;
15
16
17
    unsigned int nr_args : 5;       // used in AppEntry
    unsigned int nr_cases : 5;      // used in SelectEntry
    unsigned int strict : 1;        // used in VarEntry
18
    struct Thunk* (*create_thunk)(Code*, int);
19
20
};

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

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

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

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

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

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

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

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

67
void init_code();
68
extern Thunk* (*create_thunk_funs[9]) (Code* expr, int frame_ptr);
69

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
70
void exec(Code* expr, int frame_ptr, int root_frame_ptr);
71
struct Thunk* eval(Thunk* thunk);
72

73
#endif // __CODE_H