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

4
#include "thunk.h"
5
6
7
8

#define CT_LIT	 			1
#define CT_VAR 				2
#define CT_APP 				3
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
9
#define CT_SELECT			4
10
#define CT_IF				5
11

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
12
13
14
15
16
struct Code {
    unsigned int type : 3;
    unsigned int local_type : 3;
    unsigned int nr_args : 5; // used in AppEntry
    unsigned int nr_cases : 5; // used in SelectEntry
17
18
19
20
21
22
23
24
};

#define LIT_INT   			1
#define LIT_REAL   			2
#define LIT_CHAR			3
#define LIT_BOOL			4
#define LIT_STRING			5

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
25
26
struct LitEntry {
    struct Code base;
27
    struct Thunk thunk;
28
29
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
30
31
#define VAR_LOCAL		0 
#define VAR_FN			1
32

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
33
34
35
36
37
38
39
struct VarEntry {
    struct Code base;

    union {
        int index; // index on the stack
        struct Desc* f;
    };
40
41
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
42
43
struct AppEntry {
    struct Code base;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
44
    struct VarEntry var;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
45
    struct Code* args[];
46
47
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
48
49
50
51
#define SC_CONS			1
#define SC_LIT			2
#define SC_DEFAULT		3

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
52
53
54
55
56
57
58
59
struct SelectCaseEntry {
    int type;
    struct Code* body;

    union {
        struct ADTEntry* cons;
        struct LitEntry* lit;
    };
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
60
61
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
62
63
64
65
struct SelectEntry {
    struct Code base;
    struct Code* expr;
    struct SelectCaseEntry cases[];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
66
67
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
68
69
70
71
72
struct IfEntry {
    struct Code base;
    struct Code* cond;
    struct Code* texpr;
    struct Code* fexpr;
73
74
};

75
void exec(Code* expr, int frame_ptr, int root_frame_ptr);
76

77
#endif // __CODE_H