code.h 1.49 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
    CT_VAR, CT_VAR_STRICT, 
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
8
    CT_APP_PRIM1, CT_APP_PRIM_S, 
9
    CT_APP_PRIM2, CT_APP_PRIM_ST, CT_APP_PRIM_TS, CT_APP_PRIM_SS, CT_APP_PRIM_TA, CT_APP_PRIM_AT, CT_APP_PRIM_AS, CT_APP_PRIM_SA,
10
    CT_APP_THUNK, CT_APP_FUN, CT_APP_DYN, 
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
11
12
    CT_SELECT, CT_IF, 
    CT_THUNK
13
};
14

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

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

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

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

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

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

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

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

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

69
70
typedef Thunk* (*create_thunk_fun)(Code*, int);

71
void set_create_thunk_fun(Code* code);
72

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
73
void exec(Code* expr, int frame_ptr, int root_frame_ptr);
74
struct Thunk* eval(Thunk* thunk);
75

76
#endif // __CODE_H