]> mj.ucw.cz Git - umpf.git/blob - umpf.h
unify BUFSIZE
[umpf.git] / umpf.h
1 #include "lists.h"
2
3 /* cond.h */
4 int yylex (void);
5 void yyerror (char const *);
6
7 struct tree {
8         enum {
9                 ST_IF,
10                 ST_COND,
11                 ST_BLOCK,
12                 ST_ASS,
13                 ST_LEAF,
14                 ST_EMPTY,
15                 ST_ARROW,
16                 ST_OP
17         } st;   /* subtree type */
18         union {
19                 struct {
20                         struct tree* c; /* condition */
21                         struct tree* i; /* if */
22                         struct tree* e; /* else */
23                 } tif;
24
25                 struct {
26                         enum {
27                                 OP_REL,
28                                 OP_BOOL,
29                                 JUST_BOOL /* value only in left */      
30                         } type;
31                         int op;
32                         struct tree* left;
33                         struct tree* right;
34                 } cond; /* binary operator */
35
36                 struct {
37                         struct tree* head;
38                         struct tree* tail;
39                 } block;
40
41                 struct {
42                         struct tree* left;
43                         struct tree* right;
44                 } ass;
45
46                 struct {
47                         enum {
48                                 L_VAR,
49                                 L_CONST,
50                         } type;
51                         char* value;
52                         int n;
53                 } leaf;
54
55                 struct {
56                         char* kw_left;
57                         char* kw_right; 
58                         struct tree* s;
59                 } arrow;
60
61                 struct {
62                         int op;
63                         struct tree* left;
64                         struct tree* right;
65                 } op;
66
67         } pt;
68 };
69
70 struct tree* input_tree;
71
72 /* lex.c */
73 #define CC(a,b) ((a<<8)|b)
74 void* xmalloc(size_t size);
75 void* xrealloc(void* buf, size_t size);
76 char* xstrdup(char* s);
77 void __attribute__ ((noreturn)) die(char* msg, ...);
78 void read_conf(char* filename);
79 int line;
80 FILE* conf;
81
82 /* int.c */
83 struct hlist {
84         struct node car;
85         char* name;
86         char* value;
87 };
88
89 struct email {
90         struct list* headers;
91         char* body;
92         int body_len;
93 };
94
95 struct action {
96         char* l;
97         char* r;
98         char* s;
99         struct email e;
100 };
101
102 /* ham.c */
103 char* default_mailbox;
104
105 struct list* current_headers;
106 struct email* current_body;
107 struct list* make_hlist(void);
108 void print_headers(struct list* l);
109 void do_action(struct action* a);
110 struct email* get_body(void);
111
112 /* lock.c */
113 void save_gids(void);
114 void close_mailbox(int fd, char* path, int is_default_mailbox);
115 int open_mailbox(char* path, int is_default_mailbox);
116 char* cat(char* l, char* r);
117
118 /* code.c */
119 #define BUFSIZE 4096 
120 struct code {
121         struct node car;
122         enum {
123                 SET,
124                 JUMP,
125                 JUMP_IF,
126                 JUMP_UNLESS,
127                 DELIVER,
128                 CALL_EXT,
129                 NOP,
130                 CAT
131         } opcode;
132
133         union {
134                 struct {
135                         struct code* target;
136                 } jump;
137                 struct {
138                         struct code* target;
139                         int cond;
140                 } jump_if;
141                 struct {
142                         struct code* target;
143                         int cond;
144                 } jump_unless;
145                 struct {
146                         int l;
147                         int r;
148                 } set;
149                 struct {
150                         int l;
151                         int r;
152                         int res; /* result */
153                 } cat;
154                 struct {
155                 } nop;
156         } u;
157 };
158
159 struct variable {
160         struct node car;
161         char* name;
162         int varcode;    
163 };
164
165 struct list input_code;
166 struct list* var_hash;
167 int current_varcode;
168 int temp_varcode_start;
169 char** var_tab; 
170 char** const_tab;
171 int cur_const_n;
172 int cur_const_s;
173
174 void init(void);
175 void compile(struct tree* t);
176 int find_var(char* name, struct list* hash);
177 int store_const(char* c);
178 struct list* new_var_hash(void);
179 void print_code(void);