]> mj.ucw.cz Git - umpf.git/blob - umpf.h
add arrows
[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                 SET,
132                 JUMP,
133                 JUMP_IF,
134                 JUMP_UNLESS,
135                 DELIVER,
136                 CALL_EXT,
137                 NOP,
138                 CAT,
139                 GT,
140                 AND,
141                 PIPE,
142                 MAIL,
143                 STORE,
144                 DISCARD
145         } opcode;
146
147         union {
148                 struct {
149                         struct code* target;
150                 } jump;
151                 struct {
152                         struct code* target;
153                         int cond;
154                 } jump_if;
155                 struct {
156                         struct code* target;
157                         int cond;
158                 } jump_unless;
159                 struct {
160                         int l;
161                         int r;
162                 } set;
163                 struct {
164                         int l;
165                         int r;
166                         int res; /* result */
167                 } tpop;
168                 struct {
169                         int copy;
170                         int what;
171                 } arrow;
172                 struct {
173                 } nop;
174         } u;
175 };
176
177 struct variable {
178         struct node car;
179         char* name;
180         int varcode;    
181 };
182
183 struct list input_code;
184 struct list* var_hash;
185 int current_varcode;
186 int temp_varcode_start;
187 char** var_tab; 
188 char** const_tab;
189 int cur_const_n;
190 int cur_const_s;
191
192 void init(void);
193 void compile(struct tree* t, struct list* where);
194 int find_var(char* name, struct list* hash);
195 int store_const(char* c);
196 struct list* new_var_hash(void);
197 void print_code(void);