

#include "BUILTIN.h"
extern OBJ _AString_4(OBJ);extern OBJ __AString_4;
extern OBJ _AString_5(OBJ);extern OBJ __AString_5;
extern OBJ __AString_6;
extern OBJ _AString_24(OBJ,OBJ);extern OBJ __AString_24;
extern OBJ _AString_31(OBJ,OBJ);extern OBJ __AString_31;
extern OBJ _AString_32(OBJ,OBJ);extern OBJ __AString_32;
extern TUP2 _AString_33(OBJ,OBJ);extern OBJ __AString_33;
extern OBJ _AString_39(OBJ);extern OBJ __AString_39;

#include "Char.h"

#include "Nat.h"
extern OBJ __AOption_5;

#include "Denotation.h"
extern OBJ _AOptionMap_3(OBJ,OBJ);extern OBJ __AOptionMap_3;

#include "Int.h"
extern OBJ _AStringIndex_1(OBJ,OBJ);OBJ __AStringIndex_1; /* ! */
extern OBJ _AStringIndex_2(OBJ,OBJ);OBJ __AStringIndex_2; /* pos */
extern OBJ _AStringIndex_3(OBJ,OBJ,OBJ);OBJ __AStringIndex_3; /* slice */
extern OBJ _AStringIndex_4(OBJ,OBJ,OBJ);OBJ __AStringIndex_4; /* upd */
extern OBJ _AStringIndex_5(OBJ,OBJ,OBJ);OBJ __AStringIndex_5; /* upd,1 */
extern OBJ _AStringIndex_6(OBJ,OBJ,OBJ);OBJ __AStringIndex_6; /* swap */
extern OBJ _AStringIndex_7(OBJ,OBJ,OBJ);OBJ __AStringIndex_7; /* repl */
extern OBJ _AStringIndex_8(OBJ,OBJ,OBJ);OBJ __AStringIndex_8; /* insert */
extern OBJ _AStringIndex_9(OBJ,OBJ,OBJ);OBJ __AStringIndex_9; /* delete */
OBJ __AStringIndex_10; /* pos'10 */

extern OBJ _AStringIndex_1(register OBJ x1,register OBJ x2) /* ! */
{OBJ r;
 for(;;){
  if(ISPRM(x1)){
   HLT("!\'StringIndex: index out of range");
  }else{
   {OBJ x32=FLD1(x1,1);OBJ x33=FLD1(x1,2);OBJ x34=FLD1(x1,3);
    CPPRD(x33,1);COPY(x34,1);
    {OBJ x35;
     ANat_76(x2,__ANat_5,x35);
     if(ISTGPRM(x35,1)){
      FRPRD(x33,1);
      FREE(x34,1);
      r=_AString_5(x1);
     }else{
      if(EXPRD(x1,1)){
       DSPRD(x1);
      }else{
       DCPRD(x1,1);}
      CPPRD(x33,1);
      {OBJ x37;OBJ x38;OBJ x39;
       ADenotation_15(x33,x37);
       ANat_62(x37,x32,x38);
       ANat_80(x2,x38,x39);
       if(ISTGPRM(x39,1)){
	FREE(x34,1);
	{OBJ x40;
	 ANat_61(x32,x2,x40);
	 ADenotation_14(x33,x40,r);}
       }else{
	FRPRD(x33,1);
	{OBJ x41;
	 ANat_62(x2,x38,x41);
	 x1=x34;x2=x41;continue;}}}}}}}
  break;}
 return r;}

extern OBJ _AStringIndex_2(OBJ x1,OBJ x2) /* pos */
{OBJ r;
 if(ISPRM(x2)){
  FRCLS(x1,1);
  r=__AOption_5;
 }else{
  CPCLS(x1,1);
  CPPRD(x2,1);
  {OBJ x18;OBJ x19;OBJ x20;
   x18=_AString_4(x2);
   x19=_AString_5(x2);
   x20=(*(OBJ(*)(OBJ,OBJ))METHOD(x1,1))(x1,x19);
   if(ISTGPRM(x20,1)){
    FRCLS(x1,1);
    FREE(x18,1);
    COPY(__AStringIndex_10,1);
    r=__AStringIndex_10;
   }else{
    CPCLS(__ANat_2,1);
    {OBJ x21;
     x21=_AStringIndex_2(x1,x18);
     r=_AOptionMap_3(__ANat_2,x21);}}}}
 return r;}

extern OBJ _AStringIndex_3(OBJ x1,OBJ x2,OBJ x3) /* slice */
{OBJ r;
 {OBJ x4;
  ANat_81(x2,x3,x4);
  if(ISTGPRM(x4,1)){
   FREE(x1,1);
   r=__AString_6;
  }else{
   {OBJ x5;OBJ x6;OBJ x7;
    ANat_62(x3,x2,x5);
    x6=_AString_32(x2,x1);
    ANat_61(x5,__ANat_8,x7);
    r=_AString_31(x7,x6);}}}
 return r;}

extern OBJ _AStringIndex_4(register OBJ x1,register OBJ x2,register OBJ x3) /* upd */
{OBJ r;OBJ* p1=&r;
 for(;;){
  COPY(x3,1);
  {OBJ x4;OBJ x5;
   x4=_AString_39(x3);
   ANat_80(x1,x4,x5);
   if(ISTGPRM(x5,1)){
    {OBJ x17;OBJ x13;OBJ x9;OBJ x18;OBJ x19;OBJ x20;
     if(ISPRM(x3)){
      HLT("String at <unknown> : undefined selection start\'String:string->nat");
     }else{
      {OBJ x28=FLD1(x3,1);OBJ x29=FLD1(x3,2);OBJ x30=FLD1(x3,3);
       if(EXPRD(x3,1)){
	x17=x28;x13=x29;x9=x30;
	DSPRDF(x3);
       }else{
	CPPRD(x29,1);COPY(x30,1);
	x17=x28;x13=x29;x9=x30;
	FRPRD(x3,1);}}}
     CPPRD(x13,1);
     ADenotation_15(x13,x18);
     ANat_62(x18,x17,x19);
     ANat_80(x1,x19,x20);
     if(ISTGPRM(x20,1)){
      {OBJ x21;
       ANat_61(x17,x1,x21);
       PRD1(3,*p1);FLD1(*p1,1)=x17;FLD1(*p1,3)=x9;
       ADenotation_9(x13,x21,x2,FLD1(*p1,2));}
     }else{
      {OBJ x23;
       ANat_62(x1,x19,x23);
       PRD1(3,*p1);FLD1(*p1,1)=x17;FLD1(*p1,2)=x13;
       x1=x23;x3=x9;p1=&FLD1(*p1,3);continue;}}}
   }else{
    *p1=x3;}}
  break;}
 return r;}

extern OBJ _AStringIndex_5(register OBJ x1,register OBJ x2,register OBJ x3) /* upd,1 */
{OBJ r;OBJ* p1=&r;
 for(;;){
  COPY(x3,1);
  {OBJ x4;OBJ x5;
   x4=_AString_39(x3);
   ANat_80(x1,x4,x5);
   if(ISTGPRM(x5,1)){
    {OBJ x17;OBJ x13;OBJ x9;OBJ x18;OBJ x19;OBJ x20;
     if(ISPRM(x3)){
      HLT("String at <unknown> : undefined selection start\'String:string->nat");
     }else{
      {OBJ x30=FLD1(x3,1);OBJ x31=FLD1(x3,2);OBJ x32=FLD1(x3,3);
       if(EXPRD(x3,1)){
	x17=x30;x13=x31;x9=x32;
	DSPRDF(x3);
       }else{
	CPPRD(x31,1);COPY(x32,1);
	x17=x30;x13=x31;x9=x32;
	FRPRD(x3,1);}}}
     CPPRD(x13,1);
     ADenotation_15(x13,x18);
     ANat_62(x18,x17,x19);
     ANat_80(x1,x19,x20);
     if(ISTGPRM(x20,1)){
      CPPRD(x13,1);
      {OBJ x21;OBJ x22;OBJ x23;
       ANat_61(x17,x1,x21);
       ADenotation_14(x13,x21,x22);
       x23=(*(OBJ(*)(OBJ,OBJ))METHOD(x2,1))(x2,x22);
       PRD1(3,*p1);FLD1(*p1,1)=x17;FLD1(*p1,3)=x9;
       ADenotation_9(x13,x21,x23,FLD1(*p1,2));}
     }else{
      {OBJ x25;
       ANat_62(x1,x19,x25);
       PRD1(3,*p1);FLD1(*p1,1)=x17;FLD1(*p1,2)=x13;
       x1=x25;x3=x9;p1=&FLD1(*p1,3);continue;}}}
   }else{
    FRCLS(x2,1);
    *p1=x3;}}
  break;}
 return r;}

extern OBJ _AStringIndex_6(OBJ x1,OBJ x2,OBJ x3) /* swap */
{OBJ r;
 COPY(x3,2);
 {OBJ x4;OBJ x5;OBJ x6;
  x4=_AStringIndex_1(x3,x2);
  x5=_AStringIndex_1(x3,x1);
  x6=_AStringIndex_4(x2,x5,x3);
  r=_AStringIndex_4(x1,x4,x6);}
 return r;}

extern OBJ _AStringIndex_7(OBJ x1,OBJ x2,OBJ x3) /* repl */
{OBJ r;
 COPY(x1,1);
 COPY(x3,1);
 {OBJ x5;OBJ x6;TUP2 x7;OBJ x9;OBJ x10;OBJ x11;
  x5=_AString_39(x3);
  x6=_AString_39(x1);
  x7=_AString_33(x2,x1);
  x9=_AString_32(x5,x7.c2);
  x10=_AString_24(x3,x9);
  x11=_AString_24(x7.c1,x10);
  r=_AString_31(x6,x11);}
 return r;}

extern OBJ _AStringIndex_8(OBJ x1,OBJ x2,OBJ x3) /* insert */
{OBJ r;
 {TUP2 x5;OBJ x7;
  x5=_AString_33(x2,x1);
  x7=_AString_24(x3,x5.c2);
  r=_AString_24(x5.c1,x7);}
 return r;}

extern OBJ _AStringIndex_9(OBJ x1,OBJ x2,OBJ x3) /* delete */
{OBJ r;
 {OBJ x4;
  ANat_80(x3,x2,x4);
  if(ISTGPRM(x4,1)){
   r=x1;
  }else{
   {OBJ x6;OBJ x7;TUP2 x8;OBJ x10;
    ANat_62(x3,x2,x6);
    ANat_2(x6,x7);
    x8=_AString_33(x2,x1);
    x10=_AString_32(x7,x8.c2);
    r=_AString_24(x8.c1,x10);}}}
 return r;}


init_AStringIndex()
{
 static int visited=0; if(visited) return; visited=1;
 init_AString();
 init_AChar();
 init_ANat();
 init_AOption();
 init_ASeq();
 init_ADenotation();
 init_AOptionMap();
 init_AInt();
 CLS(3,_AStringIndex_9,__AStringIndex_9);
 CLS(3,_AStringIndex_8,__AStringIndex_8);
 CLS(3,_AStringIndex_7,__AStringIndex_7);
 CLS(3,_AStringIndex_6,__AStringIndex_6);
 CLS(3,_AStringIndex_5,__AStringIndex_5);
 CLS(3,_AStringIndex_4,__AStringIndex_4);
 CLS(3,_AStringIndex_3,__AStringIndex_3);
 CLS(2,_AStringIndex_2,__AStringIndex_2);
 CLS(2,_AStringIndex_1,__AStringIndex_1);
 PRD1F(1,__AStringIndex_10);FLD1(__AStringIndex_10,1)=__ANat_5;}

