

#include "BUILTIN.h"
extern OBJ _ACom_23(OBJ);extern OBJ __ACom_23;
extern OBJ _ACom_47(OBJ,OBJ);extern OBJ __ACom_47;

#include "Nat.h"
extern OBJ __ASeq_6;
extern OBJ _AComCompose_3(OBJ,OBJ);extern OBJ __AComCompose_3;
extern OBJ _AComCompose_5(OBJ,OBJ);extern OBJ __AComCompose_5;
extern OBJ _AComCompose_6(OBJ,OBJ);extern OBJ __AComCompose_6;
extern OBJ __AComAction_1;
extern OBJ _AComAgent_3(OBJ);extern OBJ __AComAgent_3;
extern OBJ __AComService_4;
extern OBJ _AComService_5(OBJ,OBJ);extern OBJ __AComService_5;
extern OBJ _AComService_6(OBJ,OBJ,OBJ);extern OBJ __AComService_6;
extern OBJ _AComService_7(OBJ,OBJ);extern OBJ __AComService_7;
OBJ __AComSemaphor_2; /* semaphor */
extern OBJ _AComSemaphor_3(OBJ);OBJ __AComSemaphor_3; /* reserve */
extern OBJ _AComSemaphor_4(OBJ);OBJ __AComSemaphor_4; /* release */
extern OBJ _AComSemaphor_5(OBJ,OBJ);OBJ __AComSemaphor_5; /* atomic */
extern OBJ _AComSemaphor_6(OBJ);OBJ __AComSemaphor_6; /* semaphor,1 */
extern OBJ _AComSemaphor_7(OBJ);OBJ __AComSemaphor_7; /* semaphor? */
extern OBJ _AComSemaphor_8(OBJ);OBJ __AComSemaphor_8; /* sap */
extern OBJ _AComSemaphor_9(OBJ,OBJ);OBJ __AComSemaphor_9; /* semaphorAgent */
extern OBJ _AComSemaphor_10(OBJ,OBJ);OBJ __AComSemaphor_10; /* atomic'10 */
extern OBJ _AComSemaphor_11(OBJ,OBJ);OBJ __AComSemaphor_11; /* atomic'11 */
extern OBJ _AComSemaphor_12(OBJ,OBJ,OBJ);OBJ __AComSemaphor_12; /* atomic'12 */
extern OBJ _AComSemaphor_13(OBJ,OBJ);OBJ __AComSemaphor_13; /* semaphorAgent'13 */
extern OBJ _AComSemaphor_14(OBJ);OBJ __AComSemaphor_14; /* semaphorAgent'14 */
extern OBJ _AComSemaphor_15(OBJ,OBJ,OBJ);OBJ __AComSemaphor_15; /* semaphorAgent'15 */
extern OBJ _AComSemaphor_16(OBJ);OBJ __AComSemaphor_16; /* semaphor'16 */

extern OBJ _AComSemaphor_3(OBJ x1) /* reserve */
{OBJ r;
 CPPRD(__AComAction_1,1);
 {OBJ x2;
  x2=_AComService_5(x1,__ABUILTIN_5);
  r=_AComCompose_6(x2,__AComAction_1);}
 return r;}

extern OBJ _AComSemaphor_4(OBJ x1) /* release */
{OBJ r;
 CPPRD(__AComAction_1,1);
 {OBJ x2;
  x2=_AComService_5(x1,__ABUILTIN_3);
  r=_AComCompose_6(x2,__AComAction_1);}
 return r;}

extern OBJ _AComSemaphor_5(OBJ x1,OBJ x2) /* atomic */
{OBJ r;
 CPCLS(__AComSemaphor_12,1);
 CPPRD(__AComAction_1,1);
 CPPRD(x1,1);
 {OBJ x3;OBJ x4;OBJ x5;
  x3=_AComService_5(x1,__ABUILTIN_5);
  x4=_AComCompose_6(x3,__AComAction_1);
  x5=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(__AComSemaphor_12,2))(__AComSemaphor_12,x1,x2);
  r=_AComCompose_5(x4,x5);}
 return r;}

extern OBJ _AComSemaphor_6(OBJ x1) /* semaphor,1 */
{OBJ r;
 r=x1;
 return r;}

extern OBJ _AComSemaphor_7(OBJ x1) /* semaphor? */
{OBJ r;
 FRPRD(x1,1);
 r=__ABUILTIN_5;
 return r;}

extern OBJ _AComSemaphor_8(OBJ x1) /* sap */
{OBJ r;
 r=x1;
 return r;}

extern OBJ _AComSemaphor_9(OBJ x1,OBJ x2) /* semaphorAgent */
{OBJ r;
 {OBJ x3;
  ANat_6(x2,x3);
  if(ISTGPRM(x3,1)){
   CPPRD(x1,1);
   CPCLS(__AComSemaphor_13,1);
   CPCLS(__ACom_23,1);
   {OBJ x4;OBJ x5;
    x4=_AComService_7(x1,__ACom_23);
    x5=(*(OBJ(*)(OBJ,OBJ))METHOD(__AComSemaphor_13,1))(__AComSemaphor_13,x1);
    r=_AComCompose_5(x4,x5);}
  }else{
   {OBJ x6;
    ANat_3(x2,x6);
    if(ISTGPRM(x6,1)){
     CPPRD(x1,1);
     CPCLS(__AComSemaphor_14,1);
     CPCLS(__AComSemaphor_15,1);
     CPCLS(__ACom_23,1);
     {OBJ x7;OBJ x8;OBJ x9;
      ANat_4(x2,x7);
      x8=_AComService_6(x1,__AComSemaphor_14,__ACom_23);
      x9=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(__AComSemaphor_15,2))(__AComSemaphor_15,x1,x7);
      r=_AComCompose_5(x8,x9);}
    }else{
     HLT("ComSemaphor at <27,5-17> : missing else in semaphorAgent\'ComSemaphor:sap**nat->com");}}}}
 return r;}

extern OBJ _AComSemaphor_10(OBJ x1,OBJ x2) /* atomic'10 */
{OBJ r;
 CPCLS(__ACom_47,1);
 {OBJ x3;
  x3=(*(OBJ(*)(OBJ,OBJ))METHOD(__ACom_47,1))(__ACom_47,x1);
  PRD(2,0,r);FLD(r,1)=x3;FLD(r,2)=__ASeq_6;}
 return r;}

extern OBJ _AComSemaphor_11(OBJ x1,OBJ x2) /* atomic'11 */
{OBJ r;
 CPCLS(__AComSemaphor_10,1);
 CPPRD(__AComAction_1,1);
 {OBJ x3;OBJ x4;OBJ x5;
  x3=_AComService_5(x1,__ABUILTIN_3);
  x4=_AComCompose_6(x3,__AComAction_1);
  x5=(*(OBJ(*)(OBJ,OBJ))METHOD(__AComSemaphor_10,1))(__AComSemaphor_10,x2);
  r=_AComCompose_5(x4,x5);}
 return r;}

extern OBJ _AComSemaphor_12(OBJ x1,OBJ x2,OBJ x3) /* atomic'12 */
{OBJ r;
 CPCLS(__AComSemaphor_11,1);
 {OBJ x4;
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__AComSemaphor_11,1))(__AComSemaphor_11,x1);
  r=_AComCompose_3(x2,x4);}
 return r;}

extern OBJ _AComSemaphor_13(OBJ x1,OBJ x2) /* semaphorAgent'13 */
{OBJ r;
 if(ISTGPRM(x2,1)){
  r=_AComSemaphor_9(x1,__ANat_8);
 }else{
  HLT("release\'ComSemaphor: semaphor is not reserved");}
 return r;}

extern OBJ _AComSemaphor_14(OBJ x1) /* semaphorAgent'14 */
{OBJ r;
 if(ISTGPRM(x1,1)){
  r=__ABUILTIN_3;
 }else{
  r=__ABUILTIN_5;}
 return r;}

extern OBJ _AComSemaphor_15(OBJ x1,OBJ x2,OBJ x3) /* semaphorAgent'15 */
{OBJ r;
 r=_AComSemaphor_9(x1,x2);
 return r;}

extern OBJ _AComSemaphor_16(OBJ x1) /* semaphor'16 */
{OBJ r;
 CPPRD(x1,1);
 {OBJ x2;OBJ x3;OBJ x4;
  x2=_AComSemaphor_9(x1,__ANat_5);
  x3=_ACom_23(x1);
  x4=_AComAgent_3(x2);
  r=_AComCompose_6(x4,x3);}
 return r;}


init_AComSemaphor()
{
 static int visited=0; if(visited) return; visited=1;
 init_AVoid();
 init_ACom();
 init_ANat();
 init_ASeq();
 init_AOption();
 init_AComCompose();
 init_AComAction();
 init_AComAgent();
 init_AComService();
 init_ASeqMap();
 init_AEQUALITY();
 CLS(1,_AComSemaphor_16,__AComSemaphor_16);
 CLS(3,_AComSemaphor_15,__AComSemaphor_15);
 CLS(1,_AComSemaphor_14,__AComSemaphor_14);
 CLS(2,_AComSemaphor_13,__AComSemaphor_13);
 CLS(3,_AComSemaphor_12,__AComSemaphor_12);
 CLS(2,_AComSemaphor_11,__AComSemaphor_11);
 CLS(2,_AComSemaphor_10,__AComSemaphor_10);
 CLS(2,_AComSemaphor_9,__AComSemaphor_9);
 CLS(1,_AComSemaphor_8,__AComSemaphor_8);
 CLS(1,_AComSemaphor_7,__AComSemaphor_7);
 CLS(1,_AComSemaphor_6,__AComSemaphor_6);
 CLS(2,_AComSemaphor_5,__AComSemaphor_5);
 CLS(1,_AComSemaphor_4,__AComSemaphor_4);
 CLS(1,_AComSemaphor_3,__AComSemaphor_3);
 CPCLS(__AComSemaphor_16,1);
 CPPRD(__AComService_4,1);
 __AComSemaphor_2=_AComCompose_5(__AComService_4,__AComSemaphor_16);}

