]> mj.ucw.cz Git - umpf.git/blob - umpf.h
add more binary operators
[umpf.git] / umpf.h
1 #include "lists.h"
2
3 /* cond.h */
4 int yylex (void);
5 void yyerror (char const *);
6
7 enum keyword {
8         K_DISCARD,
9         K_COPY,
10         K_MAIL,
11         K_PIPE,
12         K_EMPTY
13 };
14
15 struct tree {
16         enum {
17                 ST_IF,
18                 ST_COND,
19                 ST_BLOCK,
20                 ST_ASS,
21                 ST_LEAF,
22                 ST_EMPTY,
23                 ST_ARROW,
24                 ST_OP
25         } st;   /* subtree type */
26         union {
27                 struct {
28                         struct tree* c; /* condition */
29                         struct tree* i; /* if */
30                         struct tree* e; /* else */
31                 } tif;
32
33                 struct {
34                         enum {
35                                 OP_REL,
36                                 OP_BOOL,
37                                 JUST_BOOL /* value only in left, no op */       
38                         } type;
39                         int op;
40                         struct tree* left;
41                         struct tree* right;
42                 } cond; /* binary operator */
43
44                 struct {
45                         struct tree* head;
46                         struct tree* tail;
47                 } block;
48
49                 struct {
50                         struct tree* left;
51                         struct tree* right;
52                 } ass;
53
54                 struct {
55                         enum {
56                                 L_VAR,
57                                 L_CONST,
58                         } type;
59                         char* value;
60                         int n;
61                 } leaf;
62
63                 struct {
64                         enum keyword left;
65                         enum keyword right;
66                         struct tree* s;
67                 } arrow;
68
69                 struct {
70                         int op;
71                         struct tree* left;
72                         struct tree* right;
73                 } op;
74
75         } pt;
76 };
77
78 struct tree* input_tree;
79
80 /* lex.c */
81 #define CC(a,b) ((a<<8)|b)
82 void* xmalloc(size_t size);
83 void* xrealloc(void* buf, size_t size);
84 char* xstrdup(char* s);
85 void __attribute__ ((noreturn)) die(char* msg, ...);
86 void read_conf(char* filename);
87 int line;
88 FILE* conf;
89
90 /* int.c */
91 struct hlist {
92         struct node car;
93         char* name;
94         char* value;
95 };
96
97 struct email {
98         struct list* headers;
99         char* body;
100         int body_len;
101 };
102
103 struct action {
104         char* l;
105         char* r;
106         char* s;
107         struct email e;
108 };
109
110 /* ham.c */
111 char* default_mailbox;
112
113 struct list* current_headers;
114 struct email* current_body;
115 struct list* make_hlist(void);
116 void print_headers(struct list* l);
117 void do_action(struct action* a);
118 struct email* get_body(void);
119
120 /* lock.c */
121 void save_gids(void);
122 void close_mailbox(int fd, char* path, int is_default_mailbox);
123 int open_mailbox(char* path, int is_default_mailbox);
124 char* cat(char* l, char* r);
125
126 /* code.c */
127 #define BUFSIZE 4096 
128 struct code {
129         struct node car;
130         enum {
131                 OPC_SET,
132                 OPC_JUMP,
133                 OPC_JUMP_IF,
134                 OPC_JUMP_UNLESS,
135                 OPC_DELIVER,
136                 OPC_CALL_EXT,
137                 OPC_NOP,
138                 OPC_CAT,
139                 OPC_GT,
140                 OPC_LT,
141                 OPC_LE,
142                 OPC_GE,
143                 OPC_EQ,
144                 OPC_NEQ,
145                 OPC_RE,
146                 OPC_NRE,
147                 OPC_AND,
148                 OPC_OR,
149                 OPC_XOR,
150                 OPC_NOT,
151                 OPC_PLUS,
152                 OPC_MINUS,
153                 OPC_MUL,
154                 OPC_DIV,
155                 OPC_PIPE,
156                 OPC_MAIL,
157                 OPC_STORE,
158                 OPC_DISCARD
159         } opcode;
160
161         union {
162                 struct {
163                         struct code* target;
164                 } jump;
165                 struct {
166                         struct code* target;
167                         int cond;
168                 } jump_if;
169                 struct {
170                         struct code* target;
171                         int cond;
172                 } jump_unless;
173                 struct {
174                         int l;
175                         int r;
176                 } set;
177                 struct {
178                         int l;
179                         int r;
180                         int res; /* result */
181                 } tpop;
182                 struct {
183                         int par;
184                         int res; /* result */
185                 } dpop;
186                 struct {
187                         int copy;
188                         int what;
189                 } arrow;
190                 struct {
191                 } nop;
192         } u;
193 };
194
195 struct variable {
196         struct node car;
197         char* name;
198         int varcode;    
199 };
200
201 struct list input_code;
202 struct list* var_hash;
203 int current_varcode;
204 int temp_varcode_start;
205 char** var_tab; 
206 char** const_tab;
207 int cur_const_n;
208 int cur_const_s;
209
210 void init(void);
211 void compile(struct tree* t, struct list* where);
212 int find_var(char* name, struct list* hash);
213 int store_const(char* c);
214 struct list* new_var_hash(void);
215 void print_code(void);