#include "../../EnginePl/gp_config.h"
#include "../../EnginePl/pl_params.h"
#include "../../EnginePl/obj_chain.h"
#include "mach.h"

#define YY(k) Y(E,k)
extern unsigned var;
extern void *label;
       long v1[100];
static long v2[100];
extern long v3[100];

void foo();
void foo1();
void pl_call1();

int x,y;

extern long foreign_long[];
extern double foreign_double[];





/* to define Asm_Start() */



/* to define Code_Start() (global/not global) and Code_Stop() */

void TRANS_code_start_global()
{
}



static void TRANS_code_start_non_global()

{
}




/* to define Pl_Jump() */

void TRANS_pl_jump()
{
 M_Direct_Goto(foo1);
_foo1: ;
}



/* to define Pl_Call() */

void TRANS_pl_call()
{
 CP =(CodePtr) pl_call1;
 M_Direct_Goto(foo)
#ifdef M_ix86_win32
_foo: ;
#else
 asm("pl_call1:");
#endif
}


/* to define Pl_Fail() */

void TRANS_pl_fail()

{
 M_Indirect_Goto(ALTB(B))
}





/* to define Pl_Ret() */

void TRANS_pl_ret()

{
 M_Indirect_Goto(CP)
}



/* to define Jump() */

void TRANS_jump()

{
 if (x<3)
    {
     bar(x);
     goto a;
    }
 x++;
 a: ;
}


/* to define Move_From/To_Reg_X/Y() */

void TRANS_move_x_to_x()

{
 X(3)=X(5);
}

void TRANS_move_x_to_y()

{
 YY(10)=X(2);
}

void TRANS_move_y_to_x()

{
 X(0)=YY(3);
}

void TRANS_move_y_to_y()

{
 YY(2)=YY(4);
}



/* to define Call_C_Start() + Call_C_Arg()... + Call_C_Stop() */

void TRANS_call_c(void)

{
/*  &label,var,int, double,         string */
 bar(foo,  var, 12,4098,-4095,(double) 1.20e-10,"this is a string","a\14b");

 /* v(index) */
 bar1(v1[2],v1[0],&v1[12],v2[2],v2[0],&v2[4]);
 bar1(v3[4],&v3[2],v3[0]);

 /* regs / &regs */
 bar2(X(2),&X(4),YY(0),&YY(12));
}



void TRANS_call_c_lot_of_args(void)

{
/*  &label,var,int, double,         string */
 bar(3,4,5,6,7,8,9,10,foo,  var, 12,4098,-4095,(double) 1.20e-10,"this is a string","a\14b");

 /* regs / &regs */
 bar1(0,0,0,0,0,0,X(2),&X(4),YY(0),&YY(12));
}



void TRANS_call_c_foreign(void)

{
 bar(foreign_long[0],foreign_long[4],&foreign_long[0],&foreign_long[8]);
 bar(foreign_double[0],foreign_double[4],&foreign_double[0],&foreign_double[8]);
}
/* to define Jump_Ret() */

void TRANS_jump_ret()

{
#if defined(M_ix86_win32)
  register long adr=(long) bar (12,"toto");
  _asm {
    jmp adr
  }
#else
 goto *bar(12,"toto");
#endif
}





/* to define Fail_Ret() */

void TRANS_fail_ret()

{
 if (test(1,2,3)==0)
     goto a;

 x++;
a: ;
}



/* to define Move_Ret_To_Mem() */

void TRANS_move_ret_to_mem()

{
 var=bar(3);
 v1[4096]=bar(15);
}



/* to define Move_Ret_To_Reg_X() */

void TRANS_move_ret_to_reg_x()

{
 X(4)=bar(3);
}



/* to define Move_Ret_To_Reg_Y() */

void TRANS_move_ret_to_reg_y()

{
 YY(2)=bar(3);
}



/* to define Move_Ret_To_Foreign_L() */

void TRANS_move_ret_to_foreign_l()

{
 foreign_long[123]=bar(3);
}




/* to define Move_Ret_To_Foreign_D() */

void TRANS_move_ret_to_foreign_d()

{
 double bard(void);

 foreign_double[123]=bard();
}




/* to define Cmp_Ret_And_Int() */

void TRANS_cmp_ret_and_int()

{
 if (bar(foo)==0)                                          /* case ret = 0 */
     goto a;

 if (bar(foo)==12345678)                                 /* case ret !- 0 */
     goto a;

 x++;
a: ;
}


/* to define Jump_If_Equal() */

void TRANS_jump_if_equal()

{
 if (x==y)
     goto a;

 x++;
a: ;
}




/* to define Jump_If_Greater() */
/* maybe the C compiler does not generate a jg but a jl, reverse if needed */

void TRANS_jump_if_greater()

{
 if (x>12)
     goto a;

 if (y>x)
     goto a;

 x++;
a:
 foo(1);
}


/* to define C_Ret() */

void TRANS_c_ret()

{
}



/* to define Dico_String_Start() + Dico_String() + Dico_String_Stop() */
/* see definitions of strings in the asm file produced                */

void TRANS_dico_string()

{
 bar("str1","str2","str3","str\r\tend\n","str\019toto");
}




/* to define Dico_Long_Start() + Dico_Long() + Dico_Long_Stop()         */
/* see definitions of longs in the asm file produced (global/not global)*/

static long long1;
static long long1b=0;
static long long2=100;
long long3;
long long4=128;

static long local_array[128];
long global_array[128];

/* to define Data_Start() + Data_Stop */
/* between obj_chain_start and obj_chain_stop */

Declare_Object_Initializer(initializer_fct)
static void initializer_fct()
{
}



# if 0

/* this should not be useful */

int see_switch()

{
 int y;
 int x=bar();
    
 if (x==10)
     y+=11;
 if (x>10)
     y+=12;
 if (x<10)
     y+=13;


 if (x==0)
     y+=1;
 if (x>0)
     y+=2;
 if (x<0)
     y+=3;

 return y;
}


#endif
