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