-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.h
117 lines (86 loc) · 2.89 KB
/
compile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef INCLUDE_COMPILE
#define INCLUDE_COMPILE
#include "linked_list.h"
#include "dictionary.h"
#include "parse.h"
#define LOCAL 8
#define GLOBAL 9
#define LOCALINDIRECT 10
#define GLOBALINDIRECT 11
#define REGISTER 12
#define REGISTERINDIRECT 13
#define STACKRELATIVE 14
typedef struct block block;
struct block{
linked_list *statements;
dictionary *variables;
unsigned int *local_size;
unsigned int num_args;
};
typedef struct variable variable;
struct variable{
unsigned char type;
unsigned char is_function;
unsigned int offset;
char *name;
block *function;
unsigned int reg;
};
typedef struct constant constant;
struct constant{
unsigned char type;
union{
int int_value;
char char_value;
char *string_value;
};
unsigned char offset;
};
typedef struct expression expression;
struct expression{
unsigned char type;
unsigned char sub_type;
expression *expr1;
expression *expr2;
unsigned char do_order;
expression *condition;
block *code_block;
variable *var_pointer;
constant *const_pointer;
linked_list *func_arguments;
expression *parent;
unsigned int reg;
unsigned char to_stack;
};
typedef struct statement statement;
struct statement{
unsigned char type;
unsigned char sub_type;
union{
struct{
expression *expr;
block *code;
};
variable *var_pointer;
};
};
constant *create_constant(unsigned char type, unsigned int offset);
void free_constant(constant *c);
variable *create_variable(unsigned char type, unsigned int offset, char *name);
void free_variable(variable *var);
block *create_block(dictionary *variables, unsigned int *local_size);
void free_block(block *b);
expression *create_expression(unsigned char type, unsigned char sub_type);
void free_expression(expression *e);
statement *create_statement(unsigned char type, unsigned char sub_type);
void free_statement(statement *s);
void free_space(dictionary global_space);
expression *variable_expression(dictionary *global_space, dictionary *local_space, char *var_string);
expression *literal_expression(token t, linked_list **const_list, unsigned int *const_offset);
void to_stack_expression(expression *expr);
void order_expression(expression **expr);
expression *compile_expression(dictionary *global_space, dictionary *local_space, token **token_list, unsigned int *token_length, linked_list **const_list, unsigned int *const_offset);
statement *compile_statement(dictionary *global_space, dictionary *local_space, token **token_list, unsigned int *token_length, linked_list **const_list, unsigned int *const_offset, unsigned int *local_offset);
block *compile_block(dictionary *global_space, dictionary *local_space, token **token_list, unsigned int *token_length, linked_list **const_list, unsigned int *const_offset, unsigned int *local_offset);
void compile_program(dictionary *global_space, token **token_list, unsigned int *token_length, linked_list **const_list, unsigned int *const_offset);
#endif