Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* BEGIN cowbel runtime library
- *
- * Written in 2012 by David Given.
- *
- * To the extent possible under law, the author of the cowbel runtime
- * library (of which this code, up to the string 'END cowbel runtime library',
- * is part), has dedicated all copyright and related and neighboring rights
- * to this software to the public domain worldwide. This software is
- * distributed without any warranty.
- *
- * Please see the file COPYING.CC0 in the distribution package for more
- * information.
- */
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdint.h>
- #include <stddef.h>
- #include <stdarg.h>
- #include <string.h>
- typedef int s_boolean_t;
- typedef int s_int_t;
- typedef struct s_string s_string_t;
- struct s_string
- {
- s_string_t* prev;
- s_string_t* next;
- const char* data;
- unsigned seglength;
- unsigned totallength;
- const char* cdata;
- };
- typedef void s_string_traverse_cb(s_string_t* s, void* user);
- static void s_string_traverse(s_string_t* s, s_string_traverse_cb* cb, void* user)
- {
- if (s->prev)
- s_string_traverse(s->prev, cb, user);
- cb(s, user);
- if (s->next)
- s_string_traverse(s->next, cb, user);
- }
- typedef struct s_array s_array_t;
- struct s_array
- {
- unsigned length;
- unsigned allocedlength;
- unsigned itemsize;
- char* data;
- };
- #define S_ALLOC_CONSTRUCTOR(type) \
- ((sizeof(type) > 0) ? ((type*) calloc(1, sizeof(type))) : NULL)
- #define S_CONSTRUCT_CONSTANT_STRING(data) \
- ((s_string_t
- static void s_throw(const char* message)
- {
- fflush(stdout);
- fprintf(stderr, "Runtime error: %s\n", message);
- exit(1);
- }
- /* Boolean methods */
- #define S_METHOD_BOOLEAN__NOT(b, z) (*z) = !(b)
- #define S_METHOD_BOOLEAN__OR(a, b, z) (*z) = (a) | (b)
- /* Integer methods */
- #define S_METHOD_INTEGER__ADD(a, b, z) (*z) = (a) + (b)
- #define S_METHOD_INTEGER__SUB(a, b, z) (*z) = (a) - (b)
- #define S_METHOD_INTEGER__EQUALS(a, b, z) (*z) = (a) == (b)
- #define S_METHOD_INTEGER__NOTEQUALS(a, b, z) (*z) = (a) != (b)
- #define S_METHOD_INTEGER__GT(a, b, z) (*z) = (a) > (b)
- #define S_METHOD_INTEGER__LT(a, b, z) (*z) = (a) < (b)
- static void S_METHOD_INTEGER_TOSTRING(int value, s_string_t** result)
- {
- s_string_t* s = (s_string_t*) malloc(sizeof(s_string_t));
- s->prev = s->next = NULL;
- char* buffer = (char*) malloc(32);
- sprintf(buffer, "%d", value);
- s->data = s->cdata = buffer;
- s->seglength = s->totallength = strlen(buffer);
- *result = s;
- }
- /* String methods */
- static void s_method_string_print_cb(s_string_t* s, void* user)
- {
- fwrite(s->data, 1, s->seglength, stdout);
- }
- static void S_METHOD_STRING_PRINT(s_string_t* s)
- {
- s_string_traverse(s, s_method_string_print_cb, NULL);
- putchar('\n');
- }
- static void S_METHOD_STRING__ADD(s_string_t* left, s_string_t* right,
- s_string_t** result)
- {
- s_string_t* newstring = (s_string_t*) malloc(sizeof(s_string_t));
- newstring->prev = left;
- newstring->next = right;
- newstring->seglength = 0;
- newstring->totallength = left->totallength + right->totallength;
- newstring->data = newstring->cdata = NULL;
- *result = newstring;
- }
- static void S_METHOD_STRING__EQUALS(s_string_t* left, s_string_t* right,
- s_boolean_t* result)
- {
- int count;
- const char* pleft = NULL;
- int lseg = 0;
- const char* pright = NULL;
- int rseg = 0;
- if (left == right)
- goto success;
- if (left->totallength != right->totallength)
- goto fail;
- count = left->totallength;
- lseg = left->seglength;
- pleft = left->data;
- rseg = right->seglength;
- pright = right->data;
- while (count--)
- {
- while (lseg == 0)
- {
- left = left->next;
- lseg = left->seglength;
- pleft = left->data;
- }
- while (rseg == 0)
- {
- right = right->next;
- rseg = right->seglength;
- pright = right->data;
- }
- if (*pleft++ != *pright++)
- goto fail;
- lseg--;
- rseg--;
- }
- success:
- *result = 1;
- return;
- fail:
- *result = 0;
- return;
- }
- /* END cowbel runtime library */
- struct C0__main_;
- struct C1__main_;
- struct C2_Maybe;
- struct C3_Maybe;
- struct C4_valid;
- struct C5_get;
- struct C6_get;
- struct C7_next;
- struct C8_isEmpty;
- struct C9_push;
- struct C10_pop;
- struct C11_Maybe;
- struct C12_Maybe;
- struct C13_valid;
- struct C14_get;
- struct C15_Queue;
- struct C16_Queue;
- struct C17_Queue;
- struct C18_Node;
- struct C19_Node;
- struct I0_8_interface8;
- struct I1_12_T;
- struct I2_13_interface13;
- static void cowbel_main();
- static void f0_Maybe(void* vc0__main_, struct I1_12_T* s0_value, struct I2_13_interface13** s1__return_5);
- static void f2_valid(void* vc3_Maybe, s_boolean_t* s2__return_6);
- static void f3_get(void* vc3_Maybe, struct I1_12_T** s3__return_7);
- static void f4_get(void* vc19_Node, s_int_t* s4__return_14);
- static void f5_next(void* vc19_Node, struct I2_13_interface13** s5__return_15);
- static void f6_isEmpty(void* vc17_Queue, s_boolean_t* s6__return_16);
- static void f7_push(void* vc17_Queue, s_int_t s7_value);
- static void f8_pop(void* vc17_Queue, s_int_t* s8__return_17);
- static void f9_Maybe(void* vc0__main_, struct I2_13_interface13** s9__return_2);
- static void f10_valid(void* vc12_Maybe, s_boolean_t* s10__return_3);
- static void f11_get(void* vc12_Maybe, struct I1_12_T** s11__return_4);
- static void f12_Queue(void* vc0__main_, struct I0_8_interface8** s12__return_10);
- static void f13_Node(void* vc16_Queue, s_int_t s13_value, struct I2_13_interface13* s14_next, struct I1_12_T** s15__return_13);
- struct I0_8_interface8
- {
- void* o;
- void (*m0_1)(void*, s_boolean_t*);
- void (*m1_0)(void*, s_int_t);
- void (*m2_21)(void*, s_int_t*);
- };
- struct I1_12_T
- {
- void* o;
- void (*m3_27)(void*, s_int_t*);
- void (*m4_28)(void*, struct I2_13_interface13**);
- };
- struct I2_13_interface13
- {
- void* o;
- void (*m5_25)(void*, s_boolean_t*);
- void (*m6_26)(void*, struct I1_12_T**);
- };
- struct C0__main_
- {
- };
- struct C1__main_
- {
- struct C0__main_* c0__main_;
- };
- struct C2_Maybe
- {
- struct I1_12_T* s0_value;
- };
- struct C3_Maybe
- {
- struct C2_Maybe* c2_Maybe;
- struct I2_13_interface13 i3_13_interface13;
- };
- struct C4_valid
- {
- };
- struct C5_get
- {
- struct C2_Maybe* c2_Maybe;
- struct C3_Maybe* c3_Maybe;
- };
- struct C6_get
- {
- struct C18_Node* c18_Node;
- struct C19_Node* c19_Node;
- };
- struct C7_next
- {
- struct C18_Node* c18_Node;
- struct C19_Node* c19_Node;
- };
- struct C8_isEmpty
- {
- struct C16_Queue* c16_Queue;
- struct C17_Queue* c17_Queue;
- };
- struct C9_push
- {
- struct C0__main_* c0__main_;
- struct C15_Queue* c15_Queue;
- struct C16_Queue* c16_Queue;
- struct C17_Queue* c17_Queue;
- };
- struct C10_pop
- {
- struct C16_Queue* c16_Queue;
- struct C17_Queue* c17_Queue;
- };
- struct C11_Maybe
- {
- };
- struct C12_Maybe
- {
- struct I2_13_interface13 i3_13_interface13;
- };
- struct C13_valid
- {
- };
- struct C14_get
- {
- };
- struct C15_Queue
- {
- struct C0__main_* c0__main_;
- };
- struct C16_Queue
- {
- struct I2_13_interface13* s16_head;
- struct C0__main_* c0__main_;
- struct C15_Queue* c15_Queue;
- };
- struct C17_Queue
- {
- struct C0__main_* c0__main_;
- struct C15_Queue* c15_Queue;
- struct C16_Queue* c16_Queue;
- struct I0_8_interface8 i3_8_interface8;
- };
- struct C18_Node
- {
- s_int_t s13_value;
- struct I2_13_interface13* s14_next;
- };
- struct C19_Node
- {
- struct C18_Node* c18_Node;
- struct I1_12_T i3_12_T;
- };
- static void cowbel_main()
- {
- B0__main_:;
- struct C0__main_* c0__main_ = S_ALLOC_CONSTRUCTOR(struct C0__main_);
- struct I0_8_interface8* s17_q;
- struct I0_8_interface8* s18__temp_18;
- s_int_t s19__temp_19;
- s_int_t s20__temp_20;
- s_int_t s21__temp_21;
- s_int_t s22__temp_22;
- s_boolean_t s23__temp_23;
- s_boolean_t s24__temp_24;
- f12_Queue(c0__main_, &s18__temp_18);
- s17_q = s18__temp_18;
- s19__temp_19 = 1;
- s17_q->m1_0(s17_q->o, s19__temp_19);
- s20__temp_20 = 2;
- s17_q->m1_0(s17_q->o, s20__temp_20);
- s21__temp_21 = 3;
- s17_q->m1_0(s17_q->o, s21__temp_21);
- s22__temp_22 = 4;
- s17_q->m1_0(s17_q->o, s22__temp_22);
- goto B1__main_;
- B1__main_:;
- s17_q->m0_1(s17_q->o, &s23__temp_23);
- S_METHOD_BOOLEAN__NOT(s23__temp_23, &s24__temp_24);
- if (s24__temp_24) goto B2__main_; else goto B3__main_;
- B3__main_:;
- goto B4__main_;
- B4__main_:;
- return;
- B2__main_:;
- struct C1__main_ f0_storage;
- struct C1__main_* c1__main_ = &f0_storage;
- c1__main_->c0__main_ = c0__main_;
- s_int_t s25_i;
- s_int_t s26__temp_25;
- s_string_t* s27__temp_26;
- s17_q->m2_21(s17_q->o, &s26__temp_25);
- s25_i = s26__temp_25;
- S_METHOD_INTEGER_TOSTRING(s25_i, &s27__temp_26);
- S_METHOD_STRING_PRINT(s27__temp_26);
- goto B1__main_;
- }
- static void f0_Maybe(void* vc0__main_, struct I1_12_T* s0_value, struct I2_13_interface13** s1__return_5)
- {
- struct C0__main_* c0__main_ = vc0__main_;
- B5_Maybe:;
- struct C2_Maybe* c2_Maybe = S_ALLOC_CONSTRUCTOR(struct C2_Maybe);
- struct C3_Maybe* s28__temp_27;
- struct I2_13_interface13* s29__temp_28;
- c2_Maybe->s0_value = s0_value;
- struct C3_Maybe* c3_Maybe = S_ALLOC_CONSTRUCTOR(struct C3_Maybe);
- c3_Maybe->c2_Maybe = c2_Maybe;
- c3_Maybe->i3_13_interface13.o = c3_Maybe;
- c3_Maybe->i3_13_interface13.m5_25 = f2_valid;
- c3_Maybe->i3_13_interface13.m6_26 = f3_get;
- s28__temp_27 = c3_Maybe;
- s29__temp_28 = &s28__temp_27->i3_13_interface13;
- *s1__return_5 = s29__temp_28;
- goto B6_Maybe;
- B6_Maybe:;
- return;
- }
- static void f2_valid(void* vc3_Maybe, s_boolean_t* s2__return_6)
- {
- struct C3_Maybe* c3_Maybe = vc3_Maybe;
- B7_valid:;
- struct C4_valid f0_storage;
- struct C4_valid* c4_valid = &f0_storage;
- s_boolean_t s30__temp_29;
- s30__temp_29 = 1;
- *s2__return_6 = s30__temp_29;
- goto B8_valid;
- B8_valid:;
- return;
- }
- static void f3_get(void* vc3_Maybe, struct I1_12_T** s3__return_7)
- {
- struct C3_Maybe* c3_Maybe = vc3_Maybe;
- B9_get:;
- struct C5_get f0_storage;
- struct C5_get* c5_get = &f0_storage;
- c5_get->c2_Maybe = c3_Maybe->c2_Maybe;
- c5_get->c3_Maybe = c3_Maybe;
- *s3__return_7 = c5_get->c2_Maybe->s0_value;
- goto B10_get;
- B10_get:;
- return;
- }
- static void f4_get(void* vc19_Node, s_int_t* s4__return_14)
- {
- struct C19_Node* c19_Node = vc19_Node;
- B11_get:;
- struct C6_get f0_storage;
- struct C6_get* c6_get = &f0_storage;
- c6_get->c18_Node = c19_Node->c18_Node;
- c6_get->c19_Node = c19_Node;
- *s4__return_14 = c6_get->c18_Node->s13_value;
- goto B12_get;
- B12_get:;
- return;
- }
- static void f5_next(void* vc19_Node, struct I2_13_interface13** s5__return_15)
- {
- struct C19_Node* c19_Node = vc19_Node;
- B13_next:;
- struct C7_next f0_storage;
- struct C7_next* c7_next = &f0_storage;
- c7_next->c18_Node = c19_Node->c18_Node;
- c7_next->c19_Node = c19_Node;
- *s5__return_15 = c7_next->c18_Node->s14_next;
- goto B14_next;
- B14_next:;
- return;
- }
- static void f6_isEmpty(void* vc17_Queue, s_boolean_t* s6__return_16)
- {
- struct C17_Queue* c17_Queue = vc17_Queue;
- B15_isEmpty:;
- struct C8_isEmpty f0_storage;
- struct C8_isEmpty* c8_isEmpty = &f0_storage;
- c8_isEmpty->c16_Queue = c17_Queue->c16_Queue;
- c8_isEmpty->c17_Queue = c17_Queue;
- s_boolean_t s31__temp_30;
- s_boolean_t s32__temp_31;
- c8_isEmpty->c16_Queue->s16_head->m5_25(c8_isEmpty->c16_Queue->s16_head->o, &s31__temp_30);
- S_METHOD_BOOLEAN__NOT(s31__temp_30, &s32__temp_31);
- *s6__return_16 = s32__temp_31;
- goto B16_isEmpty;
- B16_isEmpty:;
- return;
- }
- static void f7_push(void* vc17_Queue, s_int_t s7_value)
- {
- struct C17_Queue* c17_Queue = vc17_Queue;
- B17_push:;
- struct C9_push f0_storage;
- struct C9_push* c9_push = &f0_storage;
- c9_push->c0__main_ = c17_Queue->c0__main_;
- c9_push->c15_Queue = c17_Queue->c15_Queue;
- c9_push->c16_Queue = c17_Queue->c16_Queue;
- c9_push->c17_Queue = c17_Queue;
- struct I1_12_T* s33_node;
- struct I1_12_T* s34__temp_32;
- struct I2_13_interface13* s35__temp_33;
- f13_Node(c9_push->c16_Queue, s7_value, c9_push->c16_Queue->s16_head, &s34__temp_32);
- s33_node = s34__temp_32;
- f0_Maybe(c9_push->c0__main_, s33_node, &s35__temp_33);
- c9_push->c16_Queue->s16_head = s35__temp_33;
- goto B18_push;
- B18_push:;
- return;
- }
- static void f8_pop(void* vc17_Queue, s_int_t* s8__return_17)
- {
- struct C17_Queue* c17_Queue = vc17_Queue;
- B19_pop:;
- struct C10_pop f0_storage;
- struct C10_pop* c10_pop = &f0_storage;
- c10_pop->c16_Queue = c17_Queue->c16_Queue;
- c10_pop->c17_Queue = c17_Queue;
- struct I1_12_T* s36_node;
- s_int_t s37_value;
- struct I1_12_T* s38__temp_34;
- s_int_t s39__temp_35;
- struct I2_13_interface13* s40__temp_36;
- c10_pop->c16_Queue->s16_head->m6_26(c10_pop->c16_Queue->s16_head->o, &s38__temp_34);
- s36_node = s38__temp_34;
- s36_node->m3_27(s36_node->o, &s39__temp_35);
- s37_value = s39__temp_35;
- s36_node->m4_28(s36_node->o, &s40__temp_36);
- c10_pop->c16_Queue->s16_head = s40__temp_36;
- *s8__return_17 = s37_value;
- goto B20_pop;
- B20_pop:;
- return;
- }
- static void f9_Maybe(void* vc0__main_, struct I2_13_interface13** s9__return_2)
- {
- struct C0__main_* c0__main_ = vc0__main_;
- B21_Maybe:;
- struct C11_Maybe f0_storage;
- struct C11_Maybe* c11_Maybe = &f0_storage;
- struct C12_Maybe* s41__temp_37;
- struct I2_13_interface13* s42__temp_38;
- struct C12_Maybe* c12_Maybe = S_ALLOC_CONSTRUCTOR(struct C12_Maybe);
- c12_Maybe->i3_13_interface13.o = c12_Maybe;
- c12_Maybe->i3_13_interface13.m5_25 = f10_valid;
- c12_Maybe->i3_13_interface13.m6_26 = f11_get;
- s41__temp_37 = c12_Maybe;
- s42__temp_38 = &s41__temp_37->i3_13_interface13;
- *s9__return_2 = s42__temp_38;
- goto B22_Maybe;
- B22_Maybe:;
- return;
- }
- static void f10_valid(void* vc12_Maybe, s_boolean_t* s10__return_3)
- {
- struct C12_Maybe* c12_Maybe = vc12_Maybe;
- B23_valid:;
- struct C13_valid f0_storage;
- struct C13_valid* c13_valid = &f0_storage;
- s_boolean_t s43__temp_39;
- s43__temp_39 = 0;
- *s10__return_3 = s43__temp_39;
- goto B24_valid;
- B24_valid:;
- return;
- }
- static void f11_get(void* vc12_Maybe, struct I1_12_T** s11__return_4)
- {
- struct C12_Maybe* c12_Maybe = vc12_Maybe;
- B25_get:;
- struct C14_get f0_storage;
- struct C14_get* c14_get = &f0_storage;
- goto B26_get;
- B26_get:;
- return;
- }
- static void f12_Queue(void* vc0__main_, struct I0_8_interface8** s12__return_10)
- {
- struct C0__main_* c0__main_ = vc0__main_;
- B27_Queue:;
- struct C15_Queue* c15_Queue = S_ALLOC_CONSTRUCTOR(struct C15_Queue);
- c15_Queue->c0__main_ = c0__main_;
- struct C16_Queue* c16_Queue = S_ALLOC_CONSTRUCTOR(struct C16_Queue);
- c16_Queue->c0__main_ = c15_Queue->c0__main_;
- c16_Queue->c15_Queue = c15_Queue;
- struct I2_13_interface13* s44__temp_40;
- struct C17_Queue* s45__temp_41;
- struct I0_8_interface8* s46__temp_42;
- f9_Maybe(c16_Queue->c0__main_, &s44__temp_40);
- c16_Queue->s16_head = s44__temp_40;
- struct C17_Queue* c17_Queue = S_ALLOC_CONSTRUCTOR(struct C17_Queue);
- c17_Queue->c0__main_ = c16_Queue->c0__main_;
- c17_Queue->c15_Queue = c15_Queue;
- c17_Queue->c16_Queue = c16_Queue;
- c17_Queue->i3_8_interface8.o = c17_Queue;
- c17_Queue->i3_8_interface8.m0_1 = f6_isEmpty;
- c17_Queue->i3_8_interface8.m1_0 = f7_push;
- c17_Queue->i3_8_interface8.m2_21 = f8_pop;
- s45__temp_41 = c17_Queue;
- s46__temp_42 = &s45__temp_41->i3_8_interface8;
- *s12__return_10 = s46__temp_42;
- goto B28_Queue;
- B28_Queue:;
- return;
- }
- static void f13_Node(void* vc16_Queue, s_int_t s13_value, struct I2_13_interface13* s14_next, struct I1_12_T** s15__return_13)
- {
- struct C16_Queue* c16_Queue = vc16_Queue;
- B29_Node:;
- struct C18_Node* c18_Node = S_ALLOC_CONSTRUCTOR(struct C18_Node);
- struct C19_Node* s47__temp_43;
- struct I1_12_T* s48__temp_44;
- c18_Node->s13_value = s13_value;
- c18_Node->s14_next = s14_next;
- struct C19_Node* c19_Node = S_ALLOC_CONSTRUCTOR(struct C19_Node);
- c19_Node->c18_Node = c18_Node;
- c19_Node->i3_12_T.o = c19_Node;
- c19_Node->i3_12_T.m3_27 = f4_get;
- c19_Node->i3_12_T.m4_28 = f5_next;
- s47__temp_43 = c19_Node;
- s48__temp_44 = &s47__temp_43->i3_12_T;
- *s15__return_13 = s48__temp_44;
- goto B30_Node;
- B30_Node:;
- return;
- }
- /* BEGIN cowbel runtime library
- *
- * Written in 2012 by David Given.
- *
- * To the extent possible under law, the author of the cowbel runtime
- * library (of which this code, up to the string 'END cowbel runtime library',
- * is part), has dedicated all copyright and related and neighboring rights
- * to this software to the public domain worldwide. This software is
- * distributed without any warranty.
- *
- * Please see the file COPYING.CC0 in the distribution package for more
- * information.
- */
- int main(int argc, const char* argv[])
- {
- cowbel_main();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement