RPA Toolkit
work on AST
[rpatk.git] / tests / rast-test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <sys/mman.h>
9 #include "rmem.h"
10 #include "rjsobject.h"
11 #include "rvmcpu.h"
12 #include "rpadbex.h"
13 #include "rpaerror.h"
14 #include "rvmcodegen.h"
15 #include "rvmcodemap.h"
16 #include "rvmscope.h"
17 #include "rvmoperator.h"
18 #include "rgc.h"
19 #include "rastnode.h"
20
21
22 typedef struct rastcompiler_s {
23         rpa_dbex_handle dbex;
24         rgc_t *gc;
25         rastnode_t *root;
26         rint optimized;
27 } rastcompiler_t;
28
29 void r_astcompiler_loadrules(rastcompiler_t *aco);
30
31
32 static int debuginfo = 0;
33 static int parseinfo = 0;
34 static int verboseinfo = 0;
35 static int compileonly = 0;
36
37
38 void codegen_unmap_file(rstr_t *buf)
39 {
40         if (buf) {
41                 munmap(buf->str, buf->size);
42                 r_free(buf);
43         }
44 }
45
46
47 rstr_t *codegen_map_file(const char *filename)
48 {
49         struct stat st;
50         rstr_t *str;
51         char *buffer;
52
53
54         int fd = open(filename, O_RDONLY);
55         if (fd < 0) {
56                 return (void*)0;
57         }
58         if (fstat(fd, &st) < 0) {
59                 close(fd);
60                 return (void*)0;
61         }
62         buffer = (char*)mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
63         if (buffer == (void*)-1) {
64                 close(fd);
65                 return (void*)0;
66         }
67         str = (rstr_t *)r_malloc(sizeof(*str));
68         if (!str)
69                 goto error;
70         r_memset(str, 0, sizeof(*str));
71         str->str = buffer;
72         str->size = st.st_size;
73         close(fd);
74         return str;
75
76 error:
77         munmap(buffer, st.st_size);
78         close(fd);
79         return str;
80 }
81
82
83 rastcompiler_t *r_astcompiler_create()
84 {
85         rastcompiler_t *aco;
86
87         aco = r_malloc(sizeof(*aco));
88         r_memset(aco, 0, sizeof(*aco));
89         aco->gc = r_gc_create();
90         aco->root = r_astnode_create();
91         r_gc_add(aco->gc, (robject_t*)aco->root);
92         return aco;
93 }
94
95
96 void r_astcompiler_destroy(rastcompiler_t *aco)
97 {
98         if (aco) {
99                 r_object_destroy((robject_t*)aco->gc);
100         }
101         r_free(aco);
102 }
103
104
105 void r_astnode_dump(rastnode_t *node, ruint level)
106 {
107         ruint i;
108         rastval_t *nodename;
109
110         for (i = 0; i < level; i++)
111                 fprintf(stdout, "  ");
112         nodename = (rastval_t*)r_harray_get(node->props, r_harray_lookup_s(node->props, "name"));
113
114         if (node->val.type == R_ASTVAL_ARRAY) {
115                 if (nodename) {
116                         fprintf(stdout, "%s: ", nodename->v.str->s.str);
117                         fwrite(node->src.ptr, sizeof(char), node->src.size, stdout);
118                         fprintf(stdout, "\n");
119                 }
120
121                 for (i = 0; i < r_carray_length(node->val.v.arr); i++) {
122                         rastval_t *val = (rastval_t *)r_carray_slot(node->val.v.arr, i);
123                         r_astnode_dump(val->v.node, level + 1);
124                 }
125
126         } else {
127                 if (nodename) {
128                         fprintf(stdout, "%s: ", nodename->v.str->s.str);
129                 }
130                 fwrite(node->src.ptr, sizeof(char), node->src.size, stdout);
131                 fprintf(stdout, "\n");
132         }
133
134 }
135
136
137 void r_astnode_propery_set_string(rastnode_t *node, const char *key, rstring_t *str)
138 {
139         rastval_t val;
140         R_ASTVAL_SET_STRING(&val, str);
141         r_harray_add_s(node->props, key, &val);
142 }
143
144 void r_astcompiler_dumptree(rastcompiler_t *aco)
145 {
146         r_astnode_dump(aco->root, 0);
147 }
148
149
150 int r_astcompiler_dumpnotification(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
151 {
152         rastcompiler_t *aco = (rastcompiler_t *)userdata;
153
154         if (reason & RPA_REASON_START)
155                 fprintf(stdout, "START ");
156         if (reason & RPA_REASON_MATCHED)
157                 fprintf(stdout, "MATCHED ");
158         if (reason & RPA_REASON_END)
159                 fprintf(stdout, "END ");
160         fprintf(stdout, "%s: ", name);
161         fprintf(stdout, "\n");
162         return size;
163 }
164
165
166 int r_astcompiler_notify(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
167 {
168         rastcompiler_t *aco = (rastcompiler_t *)userdata;
169
170         if (parseinfo)
171                 r_astcompiler_dumpnotification(stat, name, userdata, input, size, reason);
172
173         if (reason & RPA_REASON_START) {
174                 rastnode_t *node = r_astnode_create();
175                 r_gc_add(aco->gc, (robject_t*)node);
176                 node->parent = aco->root;
177                 aco->root = node;
178         } else if (reason & RPA_REASON_MATCHED) {
179                 rastnode_t *node = aco->root;
180                 rstring_t *nodename = r_string_create_from_ansistr(name);
181                 r_gc_add(aco->gc, (robject_t*)nodename);
182                 r_astnode_propery_set_string(node, "name", nodename);
183                 aco->root = node->parent;
184                 r_astnode_addchild(aco->root, node);
185                 node->src.ptr = (rpointer)input;
186                 node->src.size = size;
187         } else {
188                 aco->root = aco->root->parent;
189         }
190
191         return size;
192 }
193
194
195 int main(int argc, char *argv[])
196 {
197         int res, i;
198         rstr_t *script = NULL, *unmapscript = NULL;
199         rastcompiler_t *aco = r_astcompiler_create();
200         aco->dbex = rpa_dbex_create();
201
202
203         for (i = 1; i < argc; i++) {
204                 if (r_strcmp(argv[i], "-L") == 0) {
205                 } else if (r_strcmp(argv[i], "-d") == 0) {
206                         debuginfo = 1;
207                 } else if (r_strcmp(argv[i], "-p") == 0) {
208                         parseinfo = 1;
209                 } else if (r_strcmp(argv[i], "-P") == 0) {
210                         parseinfo = 1;
211                         verboseinfo = 1;
212                 } else if (r_strcmp(argv[i], "-c") == 0) {
213                         compileonly = 1;
214                 } else if (r_strcmp(argv[i], "-o") == 0) {
215                         aco->optimized = 1;
216                 } else if (r_strcmp(argv[i], "-m") == 0) {
217
218                 }
219         }
220
221         r_astcompiler_loadrules(aco);
222
223         for (i = 1; i < argc; i++) {
224                 if (r_strcmp(argv[i], "-e") == 0) {
225                         if (++i < argc) {
226                                 rstr_t script = { argv[i], r_strlen(argv[i]) };
227                                 res = rpa_dbex_parse(aco->dbex, rpa_dbex_default_pattern(aco->dbex), script.str, script.str, script.str + script.size);
228                                 if (res <= 0)
229                                         goto end;
230                         }
231                         goto exec;
232                 }
233         }
234
235         for (i = 1; i < argc; i++) {
236                 if (r_strcmp(argv[i], "-f") == 0) {
237
238                         if (++i < argc) {
239                                 script = codegen_map_file(argv[i]);
240                                 if (script) {
241                                         res = rpa_dbex_parse(aco->dbex, rpa_dbex_default_pattern(aco->dbex), script->str, script->str, script->str + script->size);
242                                         unmapscript = script;
243                                         if (res <= 0)
244                                                 goto end;
245                                 }
246
247                         }
248                         goto exec;
249                 }
250         }
251
252
253 exec:
254         r_astcompiler_dumptree(aco);
255
256
257 end:
258         if (unmapscript)
259                 codegen_unmap_file(unmapscript);
260         rpa_dbex_destroy(aco->dbex);
261         r_astcompiler_destroy(aco);
262
263         if (debuginfo) {
264                 r_printf("Max alloc mem: %ld\n", r_debug_get_maxmem());
265                 r_printf("Leaked mem: %ld\n", r_debug_get_allocmem());
266         }
267         return 0;
268 }
269
270
271
272 extern char _binary_____________tests_astecma262_rpa_start[];
273 extern char _binary_____________tests_astecma262_rpa_end[];
274 extern unsigned long *_binary_____________tests_astecma262_rpa_size;
275
276 void r_astcompiler_loadrules(rastcompiler_t *aco)
277 {
278         int ret, line;
279         int inputsize = _binary_____________tests_astecma262_rpa_end - _binary_____________tests_astecma262_rpa_start;
280         const char *buffer = _binary_____________tests_astecma262_rpa_start;
281         const char *pattern = buffer;
282
283         rpa_dbex_open(aco->dbex);
284         rpa_dbex_add_callback_exact(aco->dbex, "Identifier", RPA_REASON_ALL, r_astcompiler_notify, aco);
285
286
287
288         rpa_dbex_add_callback_exact(aco->dbex, "BitwiseANDOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
289         rpa_dbex_add_callback_exact(aco->dbex, "BitwiseXOROp", RPA_REASON_ALL, r_astcompiler_notify, aco);
290         rpa_dbex_add_callback_exact(aco->dbex, "BitwiseOROp", RPA_REASON_ALL, r_astcompiler_notify, aco);
291         rpa_dbex_add_callback_exact(aco->dbex, "AdditiveExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
292         rpa_dbex_add_callback_exact(aco->dbex, "MultiplicativeExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
293
294 //      rpa_dbex_add_callback_exact(aco->dbex, "AdditiveExpression", RPA_REASON_ALL, r_astcompiler_notify, aco);
295 //      rpa_dbex_add_callback_exact(aco->dbex, "MultiplicativeExpression", RPA_REASON_ALL, r_astcompiler_notify, aco);
296
297
298         rpa_dbex_add_callback_exact(aco->dbex, "ShiftExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
299         rpa_dbex_add_callback_exact(aco->dbex, "EqualityExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
300         rpa_dbex_add_callback_exact(aco->dbex, "RelationalExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
301         rpa_dbex_add_callback_exact(aco->dbex, "LogicalOROp", RPA_REASON_ALL, r_astcompiler_notify, aco);
302         rpa_dbex_add_callback_exact(aco->dbex, "LogicalANDOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
303
304         rpa_dbex_add_callback_exact(aco->dbex, "AssignmentOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
305         rpa_dbex_add_callback_exact(aco->dbex, "EqualityOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
306         rpa_dbex_add_callback_exact(aco->dbex, "RelationalOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
307         rpa_dbex_add_callback_exact(aco->dbex, "AdditiveOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
308         rpa_dbex_add_callback_exact(aco->dbex, "MultiplicativeOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
309         rpa_dbex_add_callback_exact(aco->dbex, "ShiftOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
310         rpa_dbex_add_callback_exact(aco->dbex, "BitwiseANDOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
311         rpa_dbex_add_callback_exact(aco->dbex, "BitwiseXOROperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
312         rpa_dbex_add_callback_exact(aco->dbex, "BitwiseOROperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
313         rpa_dbex_add_callback_exact(aco->dbex, "LogicalANDOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
314         rpa_dbex_add_callback_exact(aco->dbex, "LogicalOROperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
315         rpa_dbex_add_callback_exact(aco->dbex, "LogicalNotOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
316         rpa_dbex_add_callback_exact(aco->dbex, "BitwiseNotOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
317         rpa_dbex_add_callback_exact(aco->dbex, "UnaryOperatorOpcode", RPA_REASON_ALL, r_astcompiler_notify, aco);
318         rpa_dbex_add_callback_exact(aco->dbex, "PrintOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
319
320
321         rpa_dbex_add_callback_exact(aco->dbex, "PostfixOperator", RPA_REASON_ALL, r_astcompiler_notify, aco);
322         rpa_dbex_add_callback_exact(aco->dbex, "PostfixExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
323         rpa_dbex_add_callback_exact(aco->dbex, "PrefixExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
324
325
326         rpa_dbex_add_callback_exact(aco->dbex, "UnaryExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
327         rpa_dbex_add_callback_exact(aco->dbex, "LogicalNotExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
328         rpa_dbex_add_callback_exact(aco->dbex, "BitwiseNotExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
329
330         rpa_dbex_add_callback_exact(aco->dbex, "DecimalIntegerLiteral", RPA_REASON_ALL, r_astcompiler_notify, aco);
331         rpa_dbex_add_callback_exact(aco->dbex, "DecimalNonIntegerLiteral", RPA_REASON_ALL, r_astcompiler_notify, aco);
332         rpa_dbex_add_callback_exact(aco->dbex, "BlockBegin", RPA_REASON_ALL, r_astcompiler_notify, aco);
333         rpa_dbex_add_callback_exact(aco->dbex, "BlockEnd", RPA_REASON_ALL, r_astcompiler_notify, aco);
334
335         rpa_dbex_add_callback_exact(aco->dbex, "DoKeyword", RPA_REASON_ALL, r_astcompiler_notify, aco);
336         rpa_dbex_add_callback_exact(aco->dbex, "IterationDo", RPA_REASON_ALL, r_astcompiler_notify, aco);
337
338         rpa_dbex_add_callback_exact(aco->dbex, "sqstring", RPA_REASON_ALL, r_astcompiler_notify, aco);
339         rpa_dbex_add_callback_exact(aco->dbex, "dqstring", RPA_REASON_ALL, r_astcompiler_notify, aco);
340         rpa_dbex_add_callback_exact(aco->dbex, "DoubleStringCharacters", RPA_REASON_ALL, r_astcompiler_notify, aco);
341         rpa_dbex_add_callback_exact(aco->dbex, "SingleStringCharacters", RPA_REASON_ALL, r_astcompiler_notify, aco);
342         rpa_dbex_add_callback_exact(aco->dbex, "Program", RPA_REASON_ALL, r_astcompiler_notify, aco);
343         rpa_dbex_add_callback_exact(aco->dbex, "Initialiser", RPA_REASON_ALL, r_astcompiler_notify, aco);
344         rpa_dbex_add_callback_exact(aco->dbex, "AssignmentExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
345
346         rpa_dbex_add_callback_exact(aco->dbex, "VariableAllocate", RPA_REASON_ALL, r_astcompiler_notify, aco);
347         rpa_dbex_add_callback_exact(aco->dbex, "VariableAllocateAndInit", RPA_REASON_ALL, r_astcompiler_notify, aco);
348
349         rpa_dbex_add_callback_exact(aco->dbex, "ReturnOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
350
351 //      rpa_dbex_add_callback_exact(aco->dbex, "SwiId", RPA_REASON_ALL, r_astcompiler_notify, aco);
352 //      rpa_dbex_add_callback_exact(aco->dbex, "SwiIdExist", RPA_REASON_ALL, r_astcompiler_notify, aco);
353
354         rpa_dbex_add_callback_exact(aco->dbex, "PostfixExpressionValOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
355         rpa_dbex_add_callback_exact(aco->dbex, "LeftHandSideExpressionPush", RPA_REASON_ALL, r_astcompiler_notify, aco);
356
357         ////////////////
358
359         rpa_dbex_add_callback_exact(aco->dbex, "ThisOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
360         rpa_dbex_add_callback_exact(aco->dbex, "IdentifierOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
361         rpa_dbex_add_callback_exact(aco->dbex, "MemberIdentifierNameOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
362         rpa_dbex_add_callback_exact(aco->dbex, "MemberExpressionBaseOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
363         rpa_dbex_add_callback_exact(aco->dbex, "MemberExpressionIndexOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
364         rpa_dbex_add_callback_exact(aco->dbex, "MemberExpressionNameOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
365         rpa_dbex_add_callback_exact(aco->dbex, "CallExpressionNameOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
366         rpa_dbex_add_callback_exact(aco->dbex, "CallExpressionBaseOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
367         rpa_dbex_add_callback_exact(aco->dbex, "CallExpressionIndexOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
368         rpa_dbex_add_callback_exact(aco->dbex, "AddressLeftHandSideExpression", RPA_REASON_ALL, r_astcompiler_notify, aco);
369
370         ////////////////
371
372
373         rpa_dbex_add_callback_exact(aco->dbex, "ConditionalExpression", RPA_REASON_ALL, r_astcompiler_notify, aco);
374         rpa_dbex_add_callback_exact(aco->dbex, "NewArrayExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
375         rpa_dbex_add_callback_exact(aco->dbex, "compile_error", RPA_REASON_ALL, r_astcompiler_notify, aco);
376
377         rpa_dbex_add_callback_exact(aco->dbex, "ArgumentsOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
378         rpa_dbex_add_callback_exact(aco->dbex, "BracketExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
379         rpa_dbex_add_callback_exact(aco->dbex, "ValLeftHandSideExpression", RPA_REASON_ALL, r_astcompiler_notify, aco);
380
381         rpa_dbex_add_callback_exact(aco->dbex, "FunctionNameLookupAlloc", RPA_REASON_ALL, r_astcompiler_notify, aco);
382         rpa_dbex_add_callback_exact(aco->dbex, "FunctionName", RPA_REASON_ALL, r_astcompiler_notify, aco);
383         rpa_dbex_add_callback_exact(aco->dbex, "FunctionDeclaration", RPA_REASON_ALL, r_astcompiler_notify, aco);
384         rpa_dbex_add_callback_exact(aco->dbex, "FunctionParameter", RPA_REASON_ALL, r_astcompiler_notify, aco);
385         rpa_dbex_add_callback_exact(aco->dbex, "FunctionCallParameter", RPA_REASON_ALL, r_astcompiler_notify, aco);
386         rpa_dbex_add_callback_exact(aco->dbex, "FunctionCallName", RPA_REASON_ALL, r_astcompiler_notify, aco);
387         rpa_dbex_add_callback_exact(aco->dbex, "CallExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
388         rpa_dbex_add_callback_exact(aco->dbex, "NewKeyword", RPA_REASON_ALL, r_astcompiler_notify, aco);
389
390         rpa_dbex_add_callback_exact(aco->dbex, "NewExpressionCallName", RPA_REASON_ALL, r_astcompiler_notify, aco);
391         rpa_dbex_add_callback_exact(aco->dbex, "NewExpressionCallOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
392
393
394         rpa_dbex_add_callback_exact(aco->dbex, "IfConditionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
395         rpa_dbex_add_callback_exact(aco->dbex, "IfOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
396         rpa_dbex_add_callback_exact(aco->dbex, "ElseOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
397         rpa_dbex_add_callback_exact(aco->dbex, "IfElseOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
398
399         rpa_dbex_add_callback_exact(aco->dbex, "WhileConditionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
400         rpa_dbex_add_callback_exact(aco->dbex, "IterationWhileOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
401
402         rpa_dbex_add_callback_exact(aco->dbex, "QuestionMarkOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
403         rpa_dbex_add_callback_exact(aco->dbex, "AssignmentExpressionIfTrueOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
404         rpa_dbex_add_callback_exact(aco->dbex, "AssignmentExpressionIfFalseOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
405
406         rpa_dbex_add_callback_exact(aco->dbex, "ForKeyword", RPA_REASON_ALL, r_astcompiler_notify, aco);
407         rpa_dbex_add_callback_exact(aco->dbex, "ForExpressionInitOp", RPA_REASON_END, r_astcompiler_notify, aco);
408         rpa_dbex_add_callback_exact(aco->dbex, "ForExpressionCompareOp", RPA_REASON_END, r_astcompiler_notify, aco);
409         rpa_dbex_add_callback_exact(aco->dbex, "ForExpressionIncrementOp", RPA_REASON_END, r_astcompiler_notify, aco);
410         rpa_dbex_add_callback_exact(aco->dbex, "IterationForOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
411         rpa_dbex_add_callback_exact(aco->dbex, "BreakOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
412         rpa_dbex_add_callback_exact(aco->dbex, "ContinueOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
413
414         rpa_dbex_add_callback_exact(aco->dbex, "SwitchExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
415         rpa_dbex_add_callback_exact(aco->dbex, "SwitchStatementOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
416         rpa_dbex_add_callback_exact(aco->dbex, "CaseExpressionOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
417         rpa_dbex_add_callback_exact(aco->dbex, "CaseClauseOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
418         rpa_dbex_add_callback_exact(aco->dbex, "DefaultKeywordOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
419         rpa_dbex_add_callback_exact(aco->dbex, "DefaultClauseOp", RPA_REASON_ALL, r_astcompiler_notify, aco);
420
421
422
423 //      rpa_dbex_add_callback(aco->dbex, ".*", RPA_REASON_ALL, r_astcompiler_notify, aco);
424
425         while ((ret = rpa_dbex_load(aco->dbex, pattern, inputsize)) > 0) {
426                 inputsize -= ret;
427                 pattern += ret;
428         }
429         if (ret < 0) {
430                 for (line = 1; pattern >= buffer; --pattern) {
431                         if (*pattern == '\n')
432                                 line += 1;
433                 }
434                 fprintf(stdout, "Line: %d, RPA LOAD ERROR: %s\n", line, (rpa_dbex_get_error(aco->dbex) == RPA_E_SYNTAX_ERROR) ? "Syntax Error." : "Pattern Loading failed.");
435                 goto error;
436         }
437
438 error:
439         rpa_dbex_close(aco->dbex);
440 }