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

#include "desc.h"
5
#include "thunk.h"
6
7
8
9

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

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
13
14
15
16
17
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
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
28
struct CleanString {
    int length;
    char chars[];
29
30
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
31
32
33
34
35
36
37
38
39
40
struct LitEntry {
    struct Code base;

    union {
        int _int;
        double _real;
        char _char;
        int _bool;
        struct CleanString _string;
    };
41
42
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
43
44
#define VAR_LOCAL		0 
#define VAR_FN			1
45

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
46
47
48
49
50
51
52
struct VarEntry {
    struct Code base;

    union {
        int index; // index on the stack
        struct Desc* f;
    };
53
54
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
55
56
struct AppEntry {
    struct Code base;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
57
    struct VarEntry var;
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
58
    struct Code* args[];
59
60
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
61
62
63
64
#define SC_CONS			1
#define SC_LIT			2
#define SC_DEFAULT		3

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
65
66
67
68
69
70
71
72
struct SelectCaseEntry {
    int type;
    struct Code* body;

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

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
75
76
77
78
struct SelectEntry {
    struct Code base;
    struct Code* expr;
    struct SelectCaseEntry cases[];
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
79
80
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
81
82
83
84
85
struct IfEntry {
    struct Code base;
    struct Code* cond;
    struct Code* texpr;
    struct Code* fexpr;
86
87
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
88
void exec(Code* expr, int frame_ptr, int root_frame_ptr, struct Thunk* target, bool force);
89

90
#endif // __CODE_H