/* Generated by forth2c, (C) Martin Maierhofer 1994 */ /* size of data space, can be changed ! */ int _C_DATA_SIZE = 8192; #include "forth.h" /* general forth definitions */ #include "forth2c.h" /* forth2c specific definitions */ Cells2 mybounds(Cell p0, Cell p1) { Cells2 _c_result; Cell x0; { /* over */ Cell n1, n2; n2 = p0; n1 = p1; p1 = n1; p0 = n2; x0 = n1; } { /* plus */ Cell n1, n2, n; n1 = x0; n2 = p0; n = n2 + n1; p0 = n; } { /* swap */ Cell n1, n2; n1 = p0; n2 = p1; p1 = n1; p0 = n2; } { /* exit */ _c_result.cell0 = p0; _c_result.cell1 = p1; return (_c_result); } } Char seed[4]; void initiate_seed(void) { Cell x0; Cell x1; { /* Literal */ x0 = 74755; } { x1 = (Cell) (&seed[0]); } { /* store */ Cell *a, n; a = (Cell *) x1; n = x0; *a = n; } { /* exit */ return; } } Cell random(void) { Cell _c_result; Cell x0; Cell x1; Cell x2; { x0 = (Cell) (&seed[0]); } { /* fetch */ Cell *a; a = (Cell *) x0; x0 = *a; } { /* Literal */ x1 = 1309; } { /* star */ Cell n1, n2, n; n1 = x1; n2 = x0; n = n2 * n1; x0 = n; } { /* Literal */ x1 = 13849; } { /* plus */ Cell n1, n2, n; n1 = x1; n2 = x0; n = n2 + n1; x0 = n; } { /* Literal */ x1 = 65535; } { /* and */ Cell n1, n2, n; n1 = x1; n2 = x0; n = n2 & n1; x0 = n; } { /* dup */ Cell n; n = x0; x0 = n; x1 = n; } { x2 = (Cell) (&seed[0]); } { /* store */ Cell *a, n; a = (Cell *) x2; n = x1; *a = n; } { /* exit */ _c_result = x0; return (_c_result); } } #define elements 6000 Char list[24000]; void initiate_list(void) { Cell x0; Cell x1; Cell r0; Cell r1; { x0 = (Cell) (&list[0]); } { x1 = (Cell) elements; } { /* cells */ Cell n; n = x1; x1 = n * sizeof(Cell); } { /* plus */ Cell n1, n2, n; n1 = x1; n2 = x0; n = n2 + n1; x0 = n; } { x1 = (Cell) (&list[0]); } { /* do */ Cell bound, index; index = x1; bound = x0; r0 = bound; r1 = index; } label0: { Cell _C_locret; _C_locret = random(); x0 = _C_locret; } { /* i */ Cell n = r1; x1 = n; } { /* store */ Cell *a, n; a = (Cell *) x1; n = x0; *a = n; } { /* cell */ x0 = sizeof(Cell); } { /* +loop */ Cell step, index, bound; index = r1; bound = r0; step = x0; index += step; if ((step > 0 && index < bound) || (step <= 0 && index >= bound)) { r0 = bound; r1 = index; goto label0; } } { /* unloop */ } { /* exit */ return; } } void dump_list(void) { Cell x0; Cell x1; Cell r0; Cell r1; { x0 = (Cell) (&list[0]); } { x1 = (Cell) elements; } { /* cells */ Cell n; n = x1; x1 = n * sizeof(Cell); } { /* plus */ Cell n1, n2, n; n1 = x1; n2 = x0; n = n2 + n1; x0 = n; } { x1 = (Cell) (&list[0]); } { /* do */ Cell bound, index; index = x1; bound = x0; r0 = bound; r1 = index; } label0: { /* i */ Cell n = r1; x0 = n; } { /* fetch */ Cell *a; a = (Cell *) x0; x0 = *a; } { /* dot */ printf("%d ", x0); fflush(stdout); } { /* cell */ x0 = sizeof(Cell); } { /* +loop */ Cell step, index, bound; index = r1; bound = r0; step = x0; index += step; if ((step > 0 && index < bound) || (step <= 0 && index >= bound)) { r0 = bound; r1 = index; goto label0; } } { /* unloop */ } { /* c_r */ printf("\n"); } { /* exit */ return; } } void verify_list(void) { Cell x0; Cell x1; Cell r0; Cell r1; { x0 = (Cell) (&list[0]); } { x1 = (Cell) elements; } { /* one_minus */ Cell n; n = x1; x1 = n - 1; } { /* cells */ Cell n; n = x1; x1 = n * sizeof(Cell); } { Cells2 _C_locret; _C_locret = mybounds(x1, x0); x0 = _C_locret.cell1; x1 = _C_locret.cell0; } { /* do */ Cell bound, index; index = x1; bound = x0; r0 = bound; r1 = index; } label0: { /* i */ Cell n = r1; x0 = n; } { /* two_fetch */ Cell *a; a = (Cell *) x0; x0 = a[1]; x1 = a[0]; } { /* greater-than */ Cell n1, n2, n; n1 = x1; n2 = x0; n = FLAG(n2 > n1); x0 = n; } { /* abort_quote */ Cell n; n = x0; if (n != 0) { fputs("\nbubble-sort: not sorted\n", stdout); exit(n); } } { /* cell */ x0 = sizeof(Cell); } { /* +loop */ Cell step, index, bound; index = r1; bound = r0; step = x0; index += step; if ((step > 0 && index < bound) || (step <= 0 && index >= bound)) { r0 = bound; r1 = index; goto label0; } } { /* unloop */ } { /* exit */ return; } } Cell bubble(void) { Cell _c_result; Cell x0; Cell x1; Cell x2; Cell x3; Cell r0; Cell r1; Cell r2; Cell r3; { /* dot_quote */ fputs("bubbling...", stdout); fflush(stdout); } { /* c_r */ printf("\n"); } { /* Literal */ x0 = 1; } { x1 = (Cell) elements; } { /* Literal */ x2 = 1; } { /* do */ Cell bound, index; index = x2; bound = x1; r0 = bound; r1 = index; } label0: { x1 = (Cell) (&list[0]); } { x2 = (Cell) elements; } { /* i */ Cell n = r1; x3 = n; } { /* minus */ Cell n1, n2, n; n1 = x3; n2 = x2; n = n2 - n1; x2 = n; } { /* cells */ Cell n; n = x2; x2 = n * sizeof(Cell); } { Cells2 _C_locret; _C_locret = mybounds(x2, x1); x1 = _C_locret.cell1; x2 = _C_locret.cell0; } { /* do */ Cell bound, index; index = x2; bound = x1; r2 = bound; r3 = index; } label1: { /* i */ Cell n = r3; x1 = n; } { /* two_fetch */ Cell *a; a = (Cell *) x1; x1 = a[1]; x2 = a[0]; } { /* greater-than */ Cell n1, n2, n; n1 = x2; n2 = x1; n = FLAG(n2 > n1); x1 = n; } if (!x1) goto label2; { /* i */ Cell n = r3; x1 = n; } { /* two_fetch */ Cell *a; a = (Cell *) x1; x1 = a[1]; x2 = a[0]; } { /* swap */ Cell n1, n2; n1 = x2; n2 = x1; x1 = n1; x2 = n2; } { /* i */ Cell n = r3; x3 = n; } { /* two_store */ Cell *a, n1, n2; a = (Cell *) x3; n1 = x2; n2 = x1; a[0] = n1; a[1] = n2; } label2: { /* cell */ x1 = sizeof(Cell); } { /* +loop */ Cell step, index, bound; index = r3; bound = r2; step = x1; index += step; if ((step > 0 && index < bound) || (step <= 0 && index >= bound)) { r2 = bound; r3 = index; goto label1; } } { /* unloop */ } { /* loop */ Cell index, bound; index = r1; bound = r0; index++; if (index != bound) { r0 = bound; r1 = index; goto label0; } } { /* unloop */ } { /* exit */ _c_result = x0; return (_c_result); } } Cell bubble_sort(void) { Cell _c_result; Cell x0; { initiate_seed(); } { initiate_list(); } { Cell _C_locret; _C_locret = bubble(); x0 = _C_locret; } { verify_list(); } { /* exit */ _c_result = x0; return (_c_result); } } Cell bubble_with_flag(void) { Cell _c_result; Cell x0; Cell x1; Cell x2; Cell x3; Cell x4; Cell r0; Cell r1; Cell r2; Cell r3; { /* Literal */ x0 = 1; } { x1 = (Cell) elements; } { /* Literal */ x2 = 1; } { /* do */ Cell bound, index; index = x2; bound = x1; r0 = bound; r1 = index; } label0: { /* Literal */ x1 = -1; } { x2 = (Cell) (&list[0]); } { x3 = (Cell) elements; } { /* i */ Cell n = r1; x4 = n; } { /* minus */ Cell n1, n2, n; n1 = x4; n2 = x3; n = n2 - n1; x3 = n; } { /* cells */ Cell n; n = x3; x3 = n * sizeof(Cell); } { Cells2 _C_locret; _C_locret = mybounds(x3, x2); x2 = _C_locret.cell1; x3 = _C_locret.cell0; } { /* do */ Cell bound, index; index = x3; bound = x2; r2 = bound; r3 = index; } label1: { /* i */ Cell n = r3; x2 = n; } { /* two_fetch */ Cell *a; a = (Cell *) x2; x2 = a[1]; x3 = a[0]; } { /* greater-than */ Cell n1, n2, n; n1 = x3; n2 = x2; n = FLAG(n2 > n1); x2 = n; } if (!x2) goto label2; { /* i */ Cell n = r3; x2 = n; } { /* two_fetch */ Cell *a; a = (Cell *) x2; x2 = a[1]; x3 = a[0]; } { /* swap */ Cell n1, n2; n1 = x3; n2 = x2; x2 = n1; x3 = n2; } { /* i */ Cell n = r3; x4 = n; } { /* two_store */ Cell *a, n1, n2; a = (Cell *) x4; n1 = x3; n2 = x2; a[0] = n1; a[1] = n2; } { /* drop */ } { /* Literal */ x1 = 0; } label2: { /* cell */ x2 = sizeof(Cell); } { /* +loop */ Cell step, index, bound; index = r3; bound = r2; step = x2; index += step; if ((step > 0 && index < bound) || (step <= 0 && index >= bound)) { r2 = bound; r3 = index; goto label1; } } { /* unloop */ } if (!x1) goto label3; goto label4; label3: { /* loop */ Cell index, bound; index = r1; bound = r0; index++; if (index != bound) { r0 = bound; r1 = index; goto label0; } } label4: { /* unloop */ } { /* exit */ _c_result = x0; return (_c_result); } } Cell bubble_sort_with_flag(void) { Cell _c_result; Cell x0; { initiate_seed(); } { initiate_list(); } { Cell _C_locret; _C_locret = bubble_with_flag(); x0 = _C_locret; } { verify_list(); } { /* exit */ _c_result = x0; return (_c_result); } } Cell main(void) { Cell _c_result; Cell x0; { Cell _C_locret; _C_locret = bubble_sort(); x0 = _C_locret; } { /* exit */ _c_result = x0; return (_c_result); } }