code.h 974 Bytes
Newer Older
1
2
3
4
#ifndef __CODE_H
#define __CODE_H

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

#define CT_LIT	 			1
#define CT_VAR 				2
#define CT_APP 				3

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

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

struct CleanString
{
	int length;
27
	char chars[];
28
29
30
31
};

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

43
44
45
#define VAR_ARG			1
#define VAR_LOCAL		2
#define VAR_FN			3
46
47
48

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

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

64
struct Thunk* exec(Code* expr, int frame_ptr, Thunk* target);
65

66
#endif // __CODE_H