#define KTYPE_IMP

#include "ldc4.hh"

tSORT_TBL sort_tbl= {  { 0, FALSE, NULL, NULL, NULL, NULL, NULL },
  { 1, FALSE, "bool", NULL, NULL, NULL, NULL },
  { 2, FALSE, "digit", NULL, NULL, NULL, NULL }
};

unsigned sort_tbl_size= 3;

static int _arg_buf[]= {  2
};

kdatum _eval_opn(_oid, _arg)
int _oid;
kdatum _arg[];
{
  return NULL;
}

tOPN_TBL opn_tbl= {  { 0, 0, 0, NULL, FALSE, FALSE, NULL, NULL },
  { 1, 1, 0, NULL, FALSE, FALSE, "true", (kdatum(*)())g1 },
  { 2, 1, 0, NULL, FALSE, FALSE, "false", (kdatum(*)())g2 },
  { 3, 2, 0, NULL, FALSE, FALSE, "D0", (kdatum(*)())g3 },
  { 4, 2, 0, NULL, FALSE, FALSE, "D1", (kdatum(*)())g4 },
  { 5, 2, 0, NULL, FALSE, FALSE, "D2", (kdatum(*)())g5 },
  { 6, 2, 0, NULL, FALSE, FALSE, "D3", (kdatum(*)())g6 },
  { 7, 2, 0, NULL, FALSE, FALSE, "D4", (kdatum(*)())g7 },
  { 8, 2, 0, NULL, FALSE, FALSE, "D5", (kdatum(*)())g8 },
  { 9, 2, 0, NULL, FALSE, FALSE, "D6", (kdatum(*)())g9 },
  { 10, 2, 0, NULL, FALSE, FALSE, "D7", (kdatum(*)())g10 },
  { 11, 2, 0, NULL, FALSE, FALSE, "D8", (kdatum(*)())g11 },
  { 12, 2, 0, NULL, FALSE, FALSE, "D9", (kdatum(*)())g12 },
  { 13, 1, 1, _arg_buf, FALSE, FALSE, "non_zero", (kdatum(*)())g13 }
};

unsigned opn_tbl_size= 14;

/* D0: -> digit */
kdatum g3()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 3;
    (void) kd_const(_v);
  }
  return _v;
}

/* D1: -> digit */
kdatum g4()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 4;
    (void) kd_const(_v);
  }
  return _v;
}

/* D2: -> digit */
kdatum g5()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 5;
    (void) kd_const(_v);
  }
  return _v;
}

/* D3: -> digit */
kdatum g6()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 6;
    (void) kd_const(_v);
  }
  return _v;
}

/* D4: -> digit */
kdatum g7()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 7;
    (void) kd_const(_v);
  }
  return _v;
}

/* D5: -> digit */
kdatum g8()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 8;
    (void) kd_const(_v);
  }
  return _v;
}

/* D6: -> digit */
kdatum g9()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 9;
    (void) kd_const(_v);
  }
  return _v;
}

/* D7: -> digit */
kdatum g10()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 10;
    (void) kd_const(_v);
  }
  return _v;
}

/* D8: -> digit */
kdatum g11()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 11;
    (void) kd_const(_v);
  }
  return _v;
}

/* D9: -> digit */
kdatum g12()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 12;
    (void) kd_const(_v);
  }
  return _v;
}

/* non_zero: digit -> bool */
kdatum g13(_p1)
kdatum _p1;
{  kdatum _v= NULL;
  klink _s1;

  switch (_p1->opn)
  {  case 3: /* D0 */
      _v= g2();
      break;
    case 4: /* D1 */
      _v= g1();
      break;
    case 5: /* D2 */
      _v= g1();
      break;
    case 6: /* D3 */
      _v= g1();
      break;
    case 7: /* D4 */
      _v= g1();
      break;
    case 8: /* D5 */
      _v= g1();
      break;
    case 9: /* D6 */
      _v= g1();
      break;
    case 10: /* D7 */
      _v= g1();
      break;
    case 11: /* D8 */
      _v= g1();
      break;
    case 12: /* D9 */
      _v= g1();
      break;
  }

  if (_v == NULL)
  {  put_error("non-constructor failure: (unable to build term of external sort)\n");
    put_error("                   name: non_zero (see line 16 of file \"scnry4.lot\")\n");
    put_error("                  arg 1: %s\n", kd_draw(_p1));
    exit(1);
  }
  else
  {  kd_free(_p1);
  }

  return _v;
}

/* true: -> bool */
kdatum g1()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 1;
    (void) kd_const(_v);
  }
  return _v;
}

/* false: -> bool */
kdatum g2()
{  static kdatum _v= NULL;

  if (_v == NULL)
  {  _v= kd_alloc();
    _v->opn= 2;
    (void) kd_const(_v);
  }
  return _v;
}

void ldcinit() {}
