• R/O
  • SSH
  • HTTPS

jpl: Commit


Commit MetaInfo

Revisão29 (tree)
Hora2018-07-13 20:00:23
Autorjakobthomsen

Mensagem de Log

ignore compiled tests

Mudança Sumário

  • delete: trunk/ideal/inverse_tests/inverse_test_stack_partial_let_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_pure_calls_action_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_self_shadow_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_stack_in_struct_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_mismatched_return_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_redef_fn_partial_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_empty_block_in_expression_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_stack_partial_result_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_stack_partial_assign_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_unused_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_const_assign_par_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_const_assign_let_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_decl_mismatch_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_missing_else_effect_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_total_selfcall_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_mismatched_argument_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_pure_calls_partial_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_const_assign_stack_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_unconst_param_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_typevar_stack_mismatch_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_dynamic_in_struct_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_mismatched_assign_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_missing_else_pure_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_ffi_eof_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_missing_assign_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_stack_nested_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_self_assign_compiled.c
  • delete: trunk/ideal/inverse_tests/inverse_test_missing_result_compiled.c
  • normal: trunk/ideal/inverse_tests

Diff

--- trunk/ideal/inverse_tests/inverse_test_stack_partial_let_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_stack_partial_let_compiled.c (nonexistent)
@@ -1,845 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void assign(void *_0, const struct stack$/*u8*/ *t)
843-{
844- {
845- struct stack$/*u8*/ _s; memset(&_s, 0, sizeof(struct stack$/*u8*/));
--- trunk/ideal/inverse_tests/inverse_test_pure_calls_action_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_pure_calls_action_compiled.c (nonexistent)
@@ -1,849 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void Test(uint64_t *_0)
843-{
844- *_0 = 2;
845-}
846-
847-void pure(uint64_t *_0)
848-{
849- {
--- trunk/ideal/inverse_tests/inverse_test_self_shadow_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_self_shadow_compiled.c (nonexistent)
@@ -1,852 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-int main()
843-{
844- struct Streams$ _streams[1];
845- struct Streams$ *streams = _streams;
846- streams->in.f = stdin;
847- streams->out.f = stdout;
848- streams->err.f = stderr;
849- uint32_t _0[1];
850- {
851- uint64_t _x; memset(&_x, 0, sizeof(uint64_t));
852- _x = 42;
--- trunk/ideal/inverse_tests/inverse_test_stack_in_struct_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_stack_in_struct_compiled.c (nonexistent)
@@ -1,850 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-// ERROR: struct containing dynamic memory must be marked PARTIAL!
843-struct s
844-{
845- struct stack$/*u32*/ x;
846-};
847-
848-void s$copy(struct s *copy, struct s const *orig)
849-{
850-
\ No newline at end of file
--- trunk/ideal/inverse_tests/inverse_test_mismatched_return_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_mismatched_return_compiled.c (nonexistent)
@@ -1,844 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void test(uint32_t *_0, const uint64_t *x)
843-{
844- *_0 = (*x);
--- trunk/ideal/inverse_tests/inverse_test_redef_fn_partial_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_redef_fn_partial_compiled.c (nonexistent)
@@ -1,847 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void test$(uint64_t *_0)
843-{
844- *_0 = 1;
845-}
846-
847-void test$(uint64_t *_0)
\ No newline at end of file
--- trunk/ideal/inverse_tests/inverse_test_empty_block_in_expression_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_empty_block_in_expression_compiled.c (nonexistent)
@@ -1,849 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-int main()
843-{
844- struct Streams$ _streams[1];
845- struct Streams$ *streams = _streams;
846- streams->in.f = stdin;
847- streams->out.f = stdout;
848- streams->err.f = stderr;
849- uint32_t _0[1];
--- trunk/ideal/inverse_tests/inverse_test_stack_partial_result_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_stack_partial_result_compiled.c (nonexistent)
@@ -1,843 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void test(struct stack$/*u8*/ *_0, const struct stack$/*u8*/ *s)
843-{
--- trunk/ideal/inverse_tests/inverse_test_stack_partial_assign_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_stack_partial_assign_compiled.c (nonexistent)
@@ -1,844 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void assign(void *_0, struct stack$/*u8*/ *s, const struct stack$/*u8*/ *t)
843-{
844- {
--- trunk/ideal/inverse_tests/inverse_test_unused_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_unused_compiled.c (nonexistent)
@@ -1,857 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-int main()
843-{
844- struct Streams$ _streams[1];
845- struct Streams$ *streams = _streams;
846- streams->in.f = stdin;
847- streams->out.f = stdout;
848- streams->err.f = stderr;
849- uint32_t _0[1];
850- {
851- uint8_t _c; memset(&_c, 0, sizeof(uint8_t));
852- _c = 0;
853- uint32_t _1; memset(&_1, 0, sizeof(uint32_t));
854- _1 = 0;
855- *_0 = _1;
856- _IGNORE_(_1);
857- _IGNORE_(_c);
--- trunk/ideal/inverse_tests/inverse_test_const_assign_par_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_const_assign_par_compiled.c (nonexistent)
@@ -1,844 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void test(void *_0, const uint64_t *x)
843-{
844- {
--- trunk/ideal/inverse_tests/inverse_test_const_assign_let_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_const_assign_let_compiled.c (nonexistent)
@@ -1,854 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-int main()
843-{
844- struct Streams$ _streams[1];
845- struct Streams$ *streams = _streams;
846- streams->in.f = stdin;
847- streams->out.f = stdout;
848- streams->err.f = stderr;
849- uint32_t _0[1];
850- {
851- uint64_t _x; memset(&_x, 0, sizeof(uint64_t));
852- _x = 0;
853- uint64_t _y; memset(&_y, 0, sizeof(uint64_t));
854- _y = 1;
--- trunk/ideal/inverse_tests/inverse_test_decl_mismatch_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_decl_mismatch_compiled.c (nonexistent)
@@ -1,843 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void Test$(uint8_t *_0, const uint8_t *x, const uint16_t *y);
843-void Test$(uint8_t *_0, const uint32_t *x, const uint64_t *z)
\ No newline at end of file
--- trunk/ideal/inverse_tests/inverse_test_missing_else_effect_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_missing_else_effect_compiled.c (nonexistent)
@@ -1,862 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-int main()
843-{
844- struct Streams$ _streams[1];
845- struct Streams$ *streams = _streams;
846- streams->in.f = stdin;
847- streams->out.f = stdout;
848- streams->err.f = stderr;
849- uint32_t _0[1];
850- {
851- uint32_t _1; memset(&_1, 0, sizeof(uint32_t));
852- bool _2;
853- _2 = 1;
854- if(_2)
855- {
856- {
857- uint32_t _3; memset(&_3, 0, sizeof(uint32_t));
858- _3 = 2;
859- _1 = _3;
860- _IGNORE_(_3);
861- }
862- }
--- trunk/ideal/inverse_tests/inverse_test_total_selfcall_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_total_selfcall_compiled.c (nonexistent)
@@ -1,844 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void test(uint32_t *_0)
843-{
844- {
--- trunk/ideal/inverse_tests/inverse_test_mismatched_argument_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_mismatched_argument_compiled.c (nonexistent)
@@ -1,851 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void ignore(uint64_t *_0, const uint8_t *c)
843-{
844- *_0 = 0;
845-}
846-
847-void test(void *_0, const uint64_t *v)
848-{
849- {
850- {
851- uint64_t _1; memset(&_1, 0, sizeof(uint64_t));
--- trunk/ideal/inverse_tests/inverse_test_pure_calls_partial_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_pure_calls_partial_compiled.c (nonexistent)
@@ -1,849 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void test$(uint64_t *_0)
843-{
844- *_0 = 2;
845-}
846-
847-void pure(uint64_t *_0)
848-{
849- {
--- trunk/ideal/inverse_tests/inverse_test_const_assign_stack_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_const_assign_stack_compiled.c (nonexistent)
@@ -1,845 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void assign$(void *_0, const struct stack$/*u8*/ *s, const struct stack$/*u8*/ *t)
843-{
844- {
845- clone$(&*s, &(*t), sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
--- trunk/ideal/inverse_tests/inverse_test_unconst_param_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_unconst_param_compiled.c (nonexistent)
@@ -1,852 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void Mutate(void *_0, uint64_t *x)
843-{
844- {
845- *x = 0;
846- }
847-}
848-
849-void Test(void *_0, const uint64_t *y)
850-{
851- {
852- {
--- trunk/ideal/inverse_tests/inverse_test_typevar_stack_mismatch_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_typevar_stack_mismatch_compiled.c (nonexistent)
@@ -1,844 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void test(uint64_t *_0, const struct stack$/*u8*/ *s)
843-{
844- {
--- trunk/ideal/inverse_tests/inverse_test_dynamic_in_struct_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_dynamic_in_struct_compiled.c (nonexistent)
@@ -1,893 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-struct s$
843-{
844- uint64_t nr;
845-};
846-
847-void s$$copy(struct s$ *copy, struct s$ const *orig)
848-{
849- copy->nr = orig->nr;
850-}
851-
852-void s$$dest(struct s$ *_0)
853-{
854- _IGNORE_(_0->nr);
855-}
856-
857-void s$(struct s$ *_0, const uint64_t *nr)
858-{
859- _0->nr = *nr;
860-}
861-
862-void Print$$s$(void *_0, const struct StreamOut$ *out, const struct s$ *s)
863-{
864- fprintf(out->f, "s$(");
865- Print$$u64(0, out, &s->nr);
866- fprintf(out->f, ")");
867-}
868-
869-void cmp$s$(struct cmp *res, const struct s$ *x, const struct s$ *y)
870-{
871- cmp$u64(res, &x->nr, &y->nr);
872- if(res->type != 1)
873- return;
874-}
875-
876-// ERROR: struct containing dynamic memory must be marked PARTIAL!
877-struct s
878-{
879- struct s$ x;
880-};
881-
882-void s$copy(struct s *copy, struct s const *orig)
883-{
884- s$$copy(&copy->x, &orig->x);
885-}
886-
887-void s$dest(struct s *_0)
888-{
889- s$$dest(&_0->x);
890-}
891-
892-void s(struct s *_0, const struct s$ *x)
893-{
--- trunk/ideal/inverse_tests/inverse_test_mismatched_assign_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_mismatched_assign_compiled.c (nonexistent)
@@ -1,848 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718- {
719- unsigned int raw = fgetc(f->f);
720- *c = (raw < 256) ? (uint8_t)raw : 0;
721- }
722-}
723-
724-void Peek$(uint8_t *const c, const struct StreamIn$ *f)
725-{
726- const int raw = getc(f->f);
727- *c = (uint8_t)(raw == EOF ? 0 : ungetc(raw, f->f));
728-}
729-
730-void StreamOut$$dest(struct StreamOut$ *f)
731-{
732- if(!f->f)
733- {
734- fprintf(stderr, "FILE(out) not open!\n");
735- exit(-1);
736- }
737- else
738- {
739- fclose(f->f);
740- }
741-}
742-
743-void StreamOut$(struct StreamOut$ *stream, const struct string$ *s)
744-{
745- char *r = calloc(s->data.ptr + 1, sizeof(char));
746- if(r)
747- {
748- for(uint64_t i = 0; i < s->data.ptr; i++)
749- {
750- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
751- }
752- r[s->data.ptr] = 0;
753- stream->f = fopen(r, "wb");
754- free(r);
755- }
756-}
757-
758-void Put$(void *dummy, const struct StreamOut$ *f, const uint8_t *c)
759-{
760- if(!f->f)
761- {
762- fprintf(stderr, "FILE (out) not open!\n");
763- exit(-1);
764- }
765- else
766- {
767- (void)fputc(*c, f->f);
768- }
769-}
770-
771-void Print$$string$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
772-{
773- uint64_t i = s->data.ptr;
774- (void)fputc('\"', out->f);
775- while(i--)
776- {
777- (void)fputc((int)((char *)(s->data.data))[i], out->f);
778- }
779- (void)fputc('\"', out->f);
780-}
781-
782-void PutStr$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
783-{
784- uint64_t i = s->data.ptr;
785- while(i--)
786- {
787- (void)fputc((int)((char *)(s->data.data))[i], out->f);
788- }
789-}
790-
791-void PutStrLn$(void *_0, const struct StreamOut$ *out, const struct string$ *s)
792-{
793- PutStr$(0, out, s);
794- (void)fputc((int)'\n', out->f);
795-}
796-
797-struct Streams$
798-{
799- struct StreamIn$ in;
800- struct StreamOut$ out;
801- struct StreamOut$ err;
802-};
803-
804-/* logic */
805-void and(bool *const result, const bool *const x, const bool *const y) { *result = *x && *y; }
806-void or(bool *const result, const bool *const x, const bool *const y) { *result = *x || *y; }
807-void not(bool *const result, const bool *const x) { *result = !*x; }
808-/* casts */
809-void c64bool(bool *const result, const uint64_t *const orig) { *result = !!(*orig); }
810-void c64to8(uint8_t *const result, const uint64_t *const orig) { *result = (uint8_t)(*orig); }
811-/*void c64to16(uint16_t *const result, uint64_t *const orig) { *result = (uint16_t)(*orig); }*/
812-/*void c64to32(uint32_t *const result, uint64_t *const orig) { *result = (uint32_t)(*orig); }*/
813-
814-/*void bool32(bool *const result, uint32_t *const orig) { *result = !!(*orig); }*/
815-/*void c32to8(uint8_t *const result, uint32_t *const orig) { *result = (uint8_t)(*orig); }*/
816-/*void c32to16(uint16_t *const result, uint32_t *const orig) { *result = (uint16_t)(*orig); }*/
817-/*void c32to64(uint64_t *const result, uint32_t *const orig) { *result = (uint64_t)(*orig); }*/
818-
819-/*void bool16(bool *const result, uint16_t *const orig) { *result = !!(*orig); }*/
820-/*void c16to8(uint8_t *const result, uint16_t *const orig) { *result = (uint8_t)(*orig); }*/
821-/*void c16to32(uint32_t *const result, uint16_t *const orig) { *result = (uint32_t)(*orig); }*/
822-/*void c16to64(uint64_t *const result, uint16_t *const orig) { *result = (uint64_t)(*orig); }*/
823-
824-/*void bool8(bool *const result, uint8_t *const orig) { *result = !!(*orig); }*/
825-/*void c8to16(uint16_t *const result, uint8_t *const orig) { *result = (uint16_t)(*orig); }*/
826-/*void c8to32(uint32_t *const result, uint8_t *const orig) { *result = (uint32_t)(*orig); }*/
827-void c8to64(uint64_t *const result, const uint8_t *const orig) { *result = (uint64_t)(*orig); }
828-
829-void sub$(struct stack$/**/ *const res, const uint64_t *x, const uint64_t *y)
830-{
831- if(res)
832- {
833- free$(res, sizeof(uint64_t), 0);
834- }
835- if(*x >= *y)
836- {
837- uint64_t z = *x - *y;
838- push$(0, res, &z, sizeof(uint64_t), 0, 0, 12345/*XXX*/);
839- }
840-}
841-
842-void test(void *_0)
843-{
844- {
845- uint64_t _x; memset(&_x, 0, sizeof(uint64_t));
846- _x = 0;
847- bool _y; memset(&_y, 0, sizeof(bool));
848- _y = (_x);
--- trunk/ideal/inverse_tests/inverse_test_missing_else_pure_compiled.c (revision 28)
+++ trunk/ideal/inverse_tests/inverse_test_missing_else_pure_compiled.c (nonexistent)
@@ -1,855 +0,0 @@
1-#include<stdbool.h>
2-#include<stdint.h>
3-#include<stdio.h>
4-#include<stdlib.h>
5-#include<string.h>
6-
7-#define _IGNORE_(x)
8-
9-struct stack$
10-{
11- uint64_t size;
12- uint64_t ptr;
13- void *data;
14-};
15-
16-void size(uint64_t *const result, const struct stack$/**/ *const s)
17-{
18- *result = s->ptr;
19-}
20-
21-void free$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *))
22-{
23- if(!s) return;
24-
25- if(destr)
26- {
27- while(s->ptr--)
28- {
29- destr(c * s->ptr + (char *)s->data);
30- }
31- }
32-
33- free(s->data);
34- s->size = 0; s->ptr = 0; s->data = 0;
35-}
36-
37-void clone$(struct stack$/**/ *const out, const struct stack$/**/ *const in, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *))
38-{
39- if(in == out) return;
40- if(!out)
41- {
42- fputs("clone$ failed: OUT == 0", stderr);
43- exit(-1);
44- }
45- if(!in)
46- {
47- fputs("clone$ failed: IN == 0", stderr);
48- exit(-1);
49- }
50- if(out->size != in->size)
51- {
52- void *new = calloc(in->size, c);
53- if(!new)
54- {
55- fprintf(stderr, "clone$ failed (size: %d)", (int)(in->size * c));
56- exit(-1);
57- }
58- free$(out, c, destr);
59- out->data = new;
60- }
61- out->size = in->size;
62- out->ptr = in->ptr;
63- if(copy)
64- {
65- for(uint64_t i = 0; i < in->ptr; i++)
66- {
67- copy(c * i + (char *)out->data, c * i + (char *)in->data);
68- }
69- }
70- else
71- {
72- for(uint64_t i = 0; i < in->ptr; i++)
73- {
74- memcpy(c * i + (char *)out->data, c * i + (char *)in->data, c);
75- }
76- }
77-}
78-
79-void cpinto$(void *const out, const void *const in, uint64_t n, uint64_t c, void (*copy)(void *, const void *))
80-{
81- if(in == out || !n) return;
82- if(!out)
83- {
84- fprintf(stderr, "cpinto$ failed: OUT == 0, n == %d\n", (int)n);
85- exit(-1);
86- }
87- if(!in)
88- {
89- fprintf(stderr, "cpinto$ failed: IN == 0, n == %d\n", (int)n);
90- exit(-1);
91- }
92- if(copy)
93- {
94- for(uint64_t i = 0; i < n; i++)
95- {
96- copy(c * i + (char *)out, c * i + (char *)in);
97- }
98- }
99- else
100- {
101- for(uint64_t i = 0; i < n; i++)
102- {
103- memcpy(c * i + (char *)out, c * i + (char *)in, c);
104- }
105- }
106-}
107-
108-void at_set$(const void *const result, struct stack$/**/ *const s, const uint64_t *const i, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
109-{
110- if (*i >= s->ptr)
111- {
112- fprintf(stderr, "line %d: ", (unsigned int)line);
113- fprintf(stderr, "at_set$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
114- exit(-1);
115- }
116- if(copy)
117- {
118- copy(c * (*i) + (char *)s->data, v);
119- }
120- else
121- {
122- memcpy(c * (*i) + (char *)s->data, v, c);
123- }
124-}
125-
126-void at_get$(void *const v, const struct stack$/**/ *const s, const uint64_t *const i, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
127-{
128- if (*i >= s->ptr)
129- {
130- fprintf(stderr, "line %d: ", (unsigned int)line);
131- fprintf(stderr, "at_get$ failed with index %d >= size %d", (unsigned int)*i, (unsigned int)s->ptr);
132- exit(-1);
133- }
134- if(copy)
135- {
136- copy(v, c * (*i) + (char *)s->data);
137- }
138- else
139- {
140- memcpy(v, c * (*i) + (char *)s->data, c);
141- }
142-}
143-
144-void top_set$(const void *const result, struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
145-{
146- uint64_t i = s->ptr - 1;
147- at_set$(result, s, &i, v, c, destr, copy, line);
148-}
149-
150-void top_get$(void *const v, const struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
151-{
152- uint64_t i = s->ptr - 1;
153- at_get$(v, s, &i, c, destr, copy, line);
154-}
155-
156-void push$(const void *const result, struct stack$/**/ *s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
157-{
158- if(s->ptr > s->size)
159- {
160- fprintf(stderr, "line %d: ", (unsigned int)line);
161- fputs("push$ INTERNAL ERROR", stderr);
162- exit(-1);
163- }
164- else if(s->ptr == s->size)
165- {
166- struct stack$ new;
167- new.size = (s->size + 1) * 2 - 1;
168- new.data = calloc(new.size, c);
169- new.ptr = s->ptr;
170- if(!new.data)
171- {
172- fprintf(stderr, "line %d: ", (unsigned int)line);
173- fputs("push$ failed", stderr);
174- exit(-1);
175- }
176- memcpy(new.data, s->data, c * s->ptr);
177- free(s->data);
178- *s = new;
179- }
180- cpinto$(c * s->ptr + (char *)s->data, v, 1, c, copy);
181- s->ptr++;
182-}
183-
184-void pop$(void *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
185-{
186- if(!s->ptr)
187- {
188- fprintf(stderr, "line %d: ", (unsigned int)line);
189- fputs("pop$ failed!", stderr);
190- exit(-1);
191- }
192- if(v)
193- {
194- top_get$(v, s, c, destr, copy, line);
195- }
196- s->ptr--;
197- if(destr)
198- {
199- destr(c * s->ptr + (char *)s->data);
200- memset(c * s->ptr + (char *)s->data, 0, c);
201- }
202- if(4 * (s->ptr + 1) <= (s->size + 1))
203- {
204- if(4 * (s->ptr + 1) < (s->size + 1))
205- {
206- fprintf(stderr, "line %d: ", (unsigned int)line);
207- fputs("pop$ INTERNAL ERROR", stderr);
208- exit(-1);
209- }
210- struct stack$ new;
211- new.size = (s->size + 1) / 2 - 1;
212- new.data = calloc(s->size, c);
213- new.ptr = s->ptr;
214- if(!new.data)
215- {
216- fprintf(stderr, "line %d: ", (unsigned int)line);
217- fputs("pop$ failed", stderr);
218- exit(-1);
219- }
220- memcpy(new.data, s->data, c * s->ptr);
221- free(s->data);
222- *s = new;
223- }
224-}
225-
226-void pop_opt_base$(struct stack$/**/ *const v, struct stack$/**/ *s, const uint64_t *base, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
227-{
228- if(v)
229- {
230- free$(v, c, destr);
231- }
232- if(s->ptr > *base)
233- {
234- if(v)
235- {
236- v->size = 1;
237- v->data = calloc(1, c);
238- v->ptr = 1;
239- if(!v->data)
240- {
241- fprintf(stderr, "line %d: ", (unsigned int)line);
242- fputs("pop$ failed", stderr);
243- exit(-1);
244- }
245- top_get$(v->data, s, c, destr, copy, line);
246- }
247- s->ptr--;
248- if(destr)
249- {
250- destr(c * s->ptr + (char *)s->data);
251- memset(c * s->ptr + (char *)s->data, 0, c);
252- }
253- if(4 * (s->ptr + 1) <= (s->size + 1))
254- {
255- if(4 * (s->ptr + 1) < (s->size + 1))
256- {
257- fprintf(stderr, "line %d: ", (unsigned int)line);
258- fputs("pop$ INTERNAL ERROR", stderr);
259- exit(-1);
260- }
261- struct stack$ new;
262- new.size = (s->size + 1) / 2 - 1;
263- new.data = calloc(s->size, c);
264- new.ptr = s->ptr;
265- if(!new.data)
266- {
267- fprintf(stderr, "line %d: ", (unsigned int)line);
268- fputs("pop$ failed", stderr);
269- exit(-1);
270- }
271- memcpy(new.data, s->data, c * s->ptr);
272- free(s->data);
273- *s = new;
274- }
275- }
276-}
277-
278-void pop_opt$(struct stack$/**/ *const v, struct stack$/**/ *s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
279-{
280- uint64_t base = 0;
281- pop_opt_base$(v, s, &base, c, destr, copy, line);
282-}
283-
284-void stack$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
285-{
286- free$(s, c, destr);
287-}
288-
289-void empty$(struct stack$/**/ *const s, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
290-{
291- free$(s, c, destr);
292-}
293-
294-void solid$(struct stack$/**/ *const s, const void *const v, uint64_t c, void (*destr)(void *), void (*copy)(void *, const void *), uint64_t line)
295-{
296- free$(s, c, destr);
297- push$(0, s, v, c, destr, copy, line);
298-}
299-
300-void swap(void *const v, void *x, void *y, uint64_t c)
301-{
302- if(!x || !y)
303- {
304- fprintf(stderr, "INTERNAL ERROR, in swap: NULL-arg(s)\n");
305- exit(-1);
306- }
307-
308- for(uint64_t i = 0; i < c; i++)
309- {
310- const char h = ((char *)x)[i];
311- ((char *)x)[i] = ((char *)y)[i];
312- ((char *)y)[i] = h;
313- }
314-}
315-
316-struct StreamIn$
317-{
318- FILE *f;
319-};
320-
321-struct StreamOut$
322-{
323- FILE *f;
324-};
325-
326-void Print$$stack$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
327-{
328- (void)fprintf(out->f, "[");
329- for(uint64_t i = 0; i < s->ptr; i++)
330- {
331- if(i > 0)
332- (void)fprintf(out->f, ", ");
333- print(0, out, ((char *)s->data) + i * c);
334- }
335- (void)fprintf(out->f, "]");
336-}
337-
338-void Print$$opt$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
339-{
340- if(s->ptr)
341- {
342- (void)fprintf(out->f, "solid$(");
343- print(0, out, s->data);
344- (void)fprintf(out->f, ")");
345- }
346- else
347- {
348- (void)fprintf(out->f, "empty$");
349- }
350-}
351-
352-void Print$$box$(void *_0, const struct StreamOut$ *out, const struct stack$/**/ *const s, uint64_t c, void (*print)(void *, const struct StreamOut$ *, const void *))
353-{
354- (void)fprintf(out->f, "box$(");
355- print(0, out, s->data);
356- (void)fprintf(out->f, ")");
357-}
358-
359-
360-void Print$$bool(void *_0, const struct StreamOut$ *out, const bool *v)
361-{
362- (void)fputc(*v ? '1' : '0', out->f);
363-}
364-
365-void Print$$u64_internal_(void *_0, const struct StreamOut$ *out, const uint64_t v)
366-{
367- if(v)
368- {
369- Print$$u64_internal_(_0, out, v / 10);
370- (void)fputc((v % 10) + '0', out->f);
371- }
372-}
373-
374-void Print$$u64_internal(void *_0, const struct StreamOut$ *out, const uint64_t v)
375-{
376- if(v)
377- {
378- Print$$u64_internal_(_0, out, v);
379- }
380- else
381- {
382- (void)fputc('0', out->f);
383- }
384-}
385-
386-void Print$$u8(void *_0, const struct StreamOut$ *out, const uint8_t *v)
387-{
388- Print$$u64_internal(_0, out, (uint8_t)*v);
389-}
390-
391-void Print$$u16(void *_0, const struct StreamOut$ *out, const uint16_t *v)
392-{
393- Print$$u64_internal(_0, out, (uint16_t)*v);
394-}
395-
396-void Print$$u32(void *_0, const struct StreamOut$ *out, const uint32_t *v)
397-{
398- Print$$u64_internal(_0, out, (uint32_t)*v);
399-}
400-
401-void Print$$u64(void *_0, const struct StreamOut$ *out, const uint64_t *v)
402-{
403- Print$$u64_internal(_0, out, (uint64_t)*v);
404-}
405-
406-struct string$
407-{
408- struct stack$/*u8*/ data;
409-};
410-
411-void string$$copy(struct string$ *copy, struct string$ const *orig)
412-{
413- clone$(&copy->data, &orig->data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
414-}
415-
416-void string$$dest(struct string$ *_0)
417-{
418- free$(&_0->data, sizeof(uint8_t), 0/*DEST*/);
419-}
420-
421-void string$(struct string$ *_0, const struct stack$/*u8*/ *data)
422-{
423- _0->data.size = 0; _0->data.ptr = 0; _0->data.data = 0; clone$(&_0->data, &*data, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/);
424-}
425-
426-
427-struct cmp
428-{
429- uint64_t type;
430-};
431-
432-void cmp$dest(struct cmp *_0)
433-{
434- switch(_0->type)
435- {
436- case 0: /* _0->LS */; break; // void LS
437- case 1: /* _0->EQ */; break; // void EQ
438- case 2: /* _0->GT */; break; // void GT
439- default: fprintf(stderr, "INTERNAL ERROR IN UNION-DESTR"); break;
440- }
441-}
442-
443-void cmp$copy(struct cmp *copy, struct cmp const *orig)
444-{
445- if(!memcmp(copy, orig, sizeof(struct cmp))) return;
446- if(copy->type != orig->type)
447- {
448- cmp$dest(&*copy);
449- memset(copy, 0, sizeof(struct cmp));
450- }
451-
452- switch(orig->type)
453- {
454- case 0: /* copy->LS = orig->LS */; break;
455- case 1: /* copy->EQ = orig->EQ */; break;
456- case 2: /* copy->GT = orig->GT */; break;
457- default: fprintf(stderr, "INTERNAL ERROR IN UNION-COPY"); break;
458- }
459- copy->type = orig->type;
460-}
461-
462-void LS(struct cmp *new)
463-{
464- cmp$dest(&*new);
465- new->type = 0;
466-}
467-
468-void EQ(struct cmp *new)
469-{
470- cmp$dest(&*new);
471- new->type = 1;
472-}
473-
474-void GT(struct cmp *new)
475-{
476- cmp$dest(&*new);
477- new->type = 2;
478-}
479-
480-void Print$$cmp(void *_0, const struct StreamOut$ *out, const struct cmp *s)
481-{
482- switch(s->type)
483- {
484- case 0:
485- {
486- fprintf(out->f, "LS");
487- break;
488- }
489- case 1:
490- {
491- fprintf(out->f, "EQ");
492- break;
493- }
494- case 2:
495- {
496- fprintf(out->f, "GT");
497- break;
498- }
499- default: fprintf(stderr, "INTERNAL ERROR IN DATA-PRINT"); break;
500- }
501-}
502-
503-
504-void cmp$cmp(struct cmp *res, const struct cmp *x, const struct cmp *y)
505-{
506- if(x->type < y->type)
507- {
508- res->type = 0;
509- }
510- else if(x->type > y->type)
511- {
512- res->type = 2;
513- }
514- else
515- {
516- switch(x->type)
517- {
518- case 0:
519- {
520- res->type = 1;
521- break;
522- }
523- case 1:
524- {
525- res->type = 1;
526- break;
527- }
528- case 2:
529- {
530- res->type = 1;
531- break;
532- }
533- default: fprintf(stderr, "INTERNAL ERROR IN DATA-COMPARE"); break;
534- }
535- }
536-}
537-
538-
539-
540-void is_equ(bool *res, const struct cmp *c)
541-{
542- *res = (c->type == 1);
543-}
544-
545-void cmp$stack$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
546-{
547- uint64_t size = x->ptr < y->ptr ? x->ptr : y->ptr;
548- for(uint64_t i = 0; i < size; i++)
549- {
550- uint64_t j = x->ptr - i - 1;
551- uint64_t k = y->ptr - i - 1;
552- cmp(res, c * j + (char *)x->data, c * k + (char *)y->data);
553- if(res->type != 1)
554- return;
555- }
556- res->type = (x->ptr < y->ptr) ? 0 : (x->ptr > y->ptr) ? 2 : 1;
557-}
558-
559-void cmp$opt$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
560-{
561- cmp$stack$(res, x, y, c, cmp);
562-}
563-
564-void cmp$box$(struct cmp *res, const struct stack$/**/ *x, const struct stack$/**/ *y, uint64_t c, void (*cmp)(struct cmp *, const void *, const void *))
565-{
566- cmp$stack$(res, x, y, c, cmp);
567-}
568-
569-void cmp$bool(struct cmp *res, const bool *x, const bool *y)
570-{
571- res->type = (*x && !*y) ? 0 : (!*x && *y) ? 2 : 1;
572-}
573-
574-void cmp$u8(struct cmp *res, const uint8_t *x, const uint8_t *y)
575-{
576- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
577-}
578-
579-void cmp$u16(struct cmp *res, const uint16_t *x, const uint16_t *y)
580-{
581- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
582-}
583-
584-void cmp$u32(struct cmp *res, const uint32_t *x, const uint32_t *y)
585-{
586- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
587-}
588-
589-void cmp$u64(struct cmp *res, const uint64_t *x, const uint64_t *y)
590-{
591- res->type = (*x < *y) ? 0 : (*x > *y) ? 2 : 1;
592-}
593-
594-void cmp$string$(struct cmp *res, const struct string$ *x, const struct string$ *y)
595-{
596- cmp$stack$(res, &x->data, &y->data, sizeof(uint8_t), (void (*)(struct cmp *, const void *, const void *))cmp$u8);
597-}
598-
599-void reverse(void *_0, struct stack$/**/ *s, uint64_t c)
600-{
601- for(uint64_t i = 0; i < s->ptr / 2; i++)
602- {
603- swap(0, (char *)s->data + c * i, (char *)s->data + s->ptr - 1 - i, c);
604- }
605-}
606-
607-void init$fromliteral(struct string$ *_0, /*const*/ char *s, uint64_t size)
608-{
609- string$$dest(_0);
610- memset(_0, 0, sizeof(struct string$));
611- for(uint64_t i = 0; i < size; i++)
612- {
613- uint8_t c = s[i];
614- if('\\' == c)
615- {
616- c = s[++i];
617- switch(c)
618- {
619- case 'a': c = 7; break;
620- case 'b': c = 8; break;
621- case 'f': c = 12; break;
622- case 'n': c = 10; break;
623- case 't': c = 9; break;
624- case '\\': c = 92; break;
625- case '\'': c = 39; break;
626- case '\"': c = 34; break;
627- default: /* escape is ignored for unknown sequence */;
628- }
629- }
630- push$(0, &_0->data, &c, sizeof(uint8_t), 0/*DEST*/, 0/*COPY*/, ~0);
631- }
632- if(s[size])
633- {
634- fprintf(stderr, "INTERNAL ERROR IN STRING-LITERAL: WRONG SIZE %d / MISSING NULL BYTE\n", (int)size);
635- exit(-1);
636- }
637- for(uint64_t i = 0; i < _0->data.ptr / 2 ; i++)
638- {
639- uint8_t c = ((char *)(_0->data.data))[i];
640- ((char *)(_0->data.data))[i] = ((char *)(_0->data.data))[_0->data.ptr - i - 1];
641- ((char *)(_0->data.data))[_0->data.ptr - i - 1] = c;
642- }
643-}
644-
645-void strequ(bool *_0, const struct string$ *r, const struct string$ *s)
646-{
647- if(r->data.ptr != s->data.ptr)
648- {
649- *_0 = false;
650- }
651- else
652- {
653- *_0 = true;
654- for(uint64_t i = 0; i < s->data.ptr; i++)
655- {
656- if(((char *)(r->data.data))[i] != ((char *)(s->data.data))[i])
657- {
658- *_0 = false;
659- break;
660- }
661- }
662- }
663-}
664-
665-void strcat$(struct string$ *c, const struct string$ *b, const struct string$ *a, uint64_t line)
666-{
667- if(!b || !a)
668- {
669- fprintf(stderr, "INTERNAL ERROR IN strcat$: argument null-reference\n");
670- exit(-1);
671- }
672-
673- string$$copy(c, a);
674-
675- for(uint64_t i = 0; i < b->data.ptr; i++)
676- {
677- char C = ((char *)(b->data.data))[i];
678- push$(0, &(c->data), &C, sizeof(char), 0, 0, line);
679- }
680-}
681-
682-void StreamIn$$dest(struct StreamIn$ *f)
683-{
684- if(!f->f)
685- {
686- fprintf(stderr, "FILE(in) not open!\n");
687- exit(-1);
688- }
689- else
690- {
691- fclose(f->f);
692- }
693-}
694-
695-void StreamIn$(struct StreamIn$ *stream, const struct string$ *s)
696-{
697- char *r = calloc(s->data.ptr + 1, sizeof(char));
698- if(r)
699- {
700- for(uint64_t i = 0; i < s->data.ptr; i++)
701- {
702- r[i] = ((char *)s->data.data)[s->data.ptr - 1 - i];
703- }
704- r[s->data.ptr] = 0;
705- stream->f = fopen(r, "rb");
706- free(r);
707- }
708-}
709-
710-void Get$(uint8_t *c, const struct StreamIn$ *f)
711-{
712- if(!f->f)
713- {
714- fprintf(stderr, "FILE(in) not open!\n");
715- exit(-1);
716- }
717- else
718-

Part of diff was cut off due to size limit. Use your local client to view the full diff.

Show on old repository browser