code.h 1.33 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
struct Code {
    unsigned int type : 3;
    unsigned int local_type : 3;
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
20
21
22
23
24
25
};

#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
26
27
struct LitEntry {
    struct Code base;
28
    struct Thunk thunk;
29
30
};

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

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

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

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

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

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

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

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

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

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

78
#endif // __CODE_H