# include "lbc1.hh"

value     v[3];
gate_list gts;
var_list  vrs;
int       i;

frame M;

PUBLIC void
c0 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    b = mkhd (b, 1);
    gts = b->fth->gte;
    gts[1] = TRUE;
    gts[2] = TRUE;
    M = b->frm;

    mkpe (b, 2, 5);
    gts = b->gte;
    gts[1] = TRUE;
    c0 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 2: {
    mkpe (b, 3, 4);
    gts = b->gte;
    gts[1] = TRUE;
    gts[2] = TRUE;
    c0 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 3: {
    v[0] = (udatum)n3 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 1;
    c1 (b);
    break;
  }
  case 4: {
    M->ent = 0;
    M->but = 2;
    c2 (b);
    break;
  }
  case 5: {
    M->ent = 0;
    M->but = 3;
    c3 (b);
    break;
  }
  }
}

PUBLIC void
c1 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    mkch (b, 1, 3);
    c1 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 1: {
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 2, 1, 1, 0, -1, 0);
    break;
  }
  case 2: {
    v[0] = (udatum)plus (ud_copy (2, M->rav[0]), n2 ());
    if (M->rav[0] != NULL) {
      ud_free (2, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    goto again;
  }
  case 3: {
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 4, 2, 1, 0, -1, 0);
    break;
  }
  case 4: {
    v[0] = (udatum)plus (ud_copy (2, M->rav[0]), n2 ());
    if (M->rav[0] != NULL) {
      ud_free (2, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    goto again;
  }
  }
}

PUBLIC void
c2 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    mkmo (0);
    mkad (b, 1, 1, 1, 0, -1, 0);
    break;
  }
  case 1: {
    mkpe (b, 2, 3);
    gts = b->gte;
    gts[1] = TRUE;
    c2 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 2: {
    if (M->rav[0] != NULL) {
      ud_free (2, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->ent = 0;
    goto again;
  }
  case 3: {
    v[0] = ud_copy (2, M->rav[0]);
    if (M->rav[0] != NULL) {
      ud_free (2, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 4;
    c4 (b);
    break;
  }
  }
}

PUBLIC void
c4 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    mkch (b, 1, 3);
    c4 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 1: {
    mkmo (1);
    mkad (b, 2, 1, 1, 0, 0, 0);
    break;
  }
  case 2: {
    v[0] = ud_copy (2, M->rav[0]);
    for (i = 0; i < 2; i++)
      if (M->rav[i] != NULL) {
        ud_free (TSsorts[4][i], M->rav[i]);
        M->rav[i] = NULL;
      }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    goto again;
  }
  case 3: {
    mkmo (1);
    mkad (b, 4, 2, 1, 0, 1, 0);
    break;
  }
  case 4: {
    v[0] = ud_copy (2, M->rav[0]);
    for (i = 0; i < 2; i++)
      if (M->rav[i] != NULL) {
        ud_free (TSsorts[4][i], M->rav[i]);
        M->rav[i] = NULL;
      }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    goto again;
  }
  }
}

PUBLIC void
c3 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    mkmo (0);
    mkad (b, 1, 1, 1, 0, -1, 0);
    break;
  }
  case 1: {
#line 65 "eratos1.lot"
printf ("-> %s\n", ud_draw (int_sort, xto[0]));
    if (M->rav[0] != NULL) {
      ud_free (2, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->ent = 0;
    goto again;
  }
  }
}

PUBLIC int
t000 (M)
  frame M;
{
  static value x2 = NULL;
  if (x2 == NULL)
    x2 = ud_const (1, (udatum)(true ()));
  if (xto[0] == NULL) return PRD_NRDY;
  return ud_gequal (1, x2, (udatum)(noteq (mod (ud_copy (2, xto[0]), ud_copy (2, M->rav[0])), n0 ())), 3);
}

PUBLIC int
t001 (M)
  frame M;
{
  static value x2 = NULL;
  if (x2 == NULL)
    x2 = ud_const (2, (udatum)(n0 ()));
  if (xto[0] == NULL) return PRD_NRDY;
  return ud_gequal (2, x2, (udatum)(mod (ud_copy (2, xto[0]), ud_copy (2, M->rav[0]))), 3);
}


char*  TSprocesses[]= {""};

char** TSgates[]= {TSprocesses};

char** TSvariables[]= {TSprocesses};

static int TSsort0[]= { NULL }; /* Eratosthenes_Sieve */

static int TSsort1[]= { /* generate */
  2, 0
  };

static int TSsort2[]= { /* mkfilter */
  2, 0
  };

static int TSsort3[]= { /* listen */
  2, 0
  };

static int TSsort4[]= { /* filter */
  2, 2, 0
  };

int*  TSsorts[]= {
  TSsort0, TSsort1, TSsort2, TSsort3, TSsort4
  };

int TSsizes[]= {
  1
  };

static int TSsbe0[] = { 2 };

int *TSsbes[]= {
  TSsbe0
  };

eval_f TSevals[]= { NULL };

int specpar = 0;
int max_accepted = 1;
int max_gte = 3;
int max_val = 3;
int max_exp = 2;
boolean g_flag = FALSE;

predicate ftbl[]= {
  t000, t001
  };

coroutine ctbl[]= { c0, c1, c2, c3, c4 };

