code.h 1.23 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
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
67
void init_code();

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

71
#endif // __CODE_H