code.h 1.3 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

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

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

struct CleanString
{
	int length;
29
	char chars[];
30
31
32
33
};

struct LitEntry
{
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
34
	struct Code base;
35
36
37
38
39
40
41
42
43
44
	union 
	{
		int _int;
		double _real;
		char _char;
		int _bool;
		struct CleanString _string;
	};
};

45
46
47
#define VAR_ARG			1
#define VAR_LOCAL		2
#define VAR_FN			3
48
49
50

struct VarEntry
{
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
51
	struct Code base;
52
53
54
	union
	{
		int index; // index on the stack
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
55
		struct Desc* f;
56
57
58
59
60
	};
};

struct AppEntry
{
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
61
	struct Code base;
62
	struct VarEntry* var;  // TODO: remove * here (embed VarEntry to save a space of one pointer)
Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
63
	struct Code* args[];
64
65
};

Laszlo Domoszlai's avatar
Laszlo Domoszlai committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#define SC_CONS			1
#define SC_LIT			2
#define SC_DEFAULT		3

struct SelectCaseEntry
{
	int type;
	struct Code* body;
	union
	{
		struct ADTEntry* cons;
		struct LitEntry* lit;
	};	
};

struct SelectEntry
{
	struct Code base;
	struct Code* expr;
	struct SelectCaseEntry cases[];
};

88
struct Thunk* exec(Code* expr, int frame_ptr, Thunk* target);
89

90
#endif // __CODE_H