/* Compiler: ECL 26.3.27                                                      */
/* Source: /build/ecl/src/ecl-26.3.27/src/clos/cpl.lsp                        */
#include <ecl/ecl-cmp.h>
#include "clos/cpl.eclh"
/* function definition for COMPUTE-CLOS-CLASS-PRECEDENCE-LIST                 */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L788compute_clos_class_precedence_list(cl_object v1new_class, cl_object v2superclasses)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 if (!(v2superclasses==ECL_NIL)){
  goto L2;
 }
 value0 = ecl_list1(v1new_class);
 cl_env_copy->nvalues = 1;
 return value0;
L2:;
 T0 = ecl_cdr(v2superclasses);
 if (!(ecl_endp(T0))){
  goto L4;
 }
 {
  cl_object v3class;
  v3class = ecl_car(v2superclasses);
  T0 = cl_slot_value(v3class, VV[12]);
  value0 = CONS(v1new_class,T0);
  cl_env_copy->nvalues = 1;
  return value0;
 }
L4:;
 {
  cl_object v4;                                   /*  CLASS-LIST              */
  cl_object v5;                                   /*  PRECEDENCE-LISTS        */
  value0 = LC782walk_supers(v2superclasses);
  {
   const int v6 = cl_env_copy->nvalues;
   v4 = value0;
   cl_object v7;
   v7 = (v6<=1)? ECL_NIL : cl_env_copy->values[1];
   v5 = v7;
  }
  {
   cl_object v6cpl;
   v6cpl = ecl_list1(v1new_class);
   goto L11;
L10:;
   {
    cl_object v7candidates;
    cl_object v8next;
    v7candidates = LC785free_elements(v4, v5);
    v8next = LC786next_element(v7candidates, v6cpl);
    if (v8next!=ECL_NIL) {
     goto L16;
    }
    LC783cycle_error(v1new_class);
L16:;
    v5 = LC787delete_class(v8next, v5);
    v4 = cl_delete(2, v8next, v4);
    v6cpl = CONS(v8next,v6cpl);
   }
L11:;
   if (v4==ECL_NIL) {
    goto L23;
   }
   goto L10;
L23:;
   if (Null(v5)){
    goto L25;
   }
   value0 = LC783cycle_error(v1new_class);
   return value0;
L25:;
   value0 = cl_nreverse(v6cpl);
   return value0;
  }
 }
}
static cl_object L788compute_clos_class_precedence_list_va(cl_narg narg, cl_object v4new_class, cl_object v5superclasses, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[0]);
 {
  return L788compute_clos_class_precedence_list(v4new_class, v5superclasses);
 }
}
/* local function DELETE-CLASS                                                */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC787delete_class(cl_object v1class, cl_object v2precedence_lists)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3l;
  v3l = v2precedence_lists;
  goto L5;
L4:;
  {
   cl_object v4one_list;
   v4one_list = ecl_car(v3l);
   T0 = ecl_car(v4one_list);
   if (!((v1class)==(T0))){
    goto L7;
   }
   {
    cl_object v5;
    v5 = ecl_cdr(v4one_list);
    {
     cl_object v6;
     v6 = v3l;
     if (ecl_unlikely(ECL_ATOM(v6))) FEtype_error_cons(v6);
     value0 = ECL_NIL;
     cl_env_copy->nvalues = 0;
     T0 = v6;
    }
    (ECL_CONS_CAR(T0)=v5,T0);
   }
  }
L7:;
  v3l = ecl_cdr(v3l);
L5:;
  if (v3l==ECL_NIL) {
   goto L17;
  }
  goto L4;
L17:;
  value0 = cl_delete(2, ECL_NIL, v2precedence_lists);
  return value0;
 }
}
static cl_object LC787delete_class_va(cl_narg narg, cl_object v4class, cl_object v5precedence_lists, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[11]);
 {
  return LC787delete_class(v4class, v5precedence_lists);
 }
}
/* local function NEXT-ELEMENT                                                */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC786next_element(cl_object v1free_list, cl_object v2cpl)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 if (v2cpl==ECL_NIL) {
  goto L4;
 }
 if (ecl_endp(v1free_list)) {
  goto L4;
 }
 T0 = ecl_cdr(v1free_list);
 if (!(ecl_endp(T0))){
  goto L2;
 }
 goto L3;
L4:;
L3:;
 value0 = ecl_car(v1free_list);
 cl_env_copy->nvalues = 1;
 return value0;
L2:;
 {
  cl_object v3;
  v3 = v2cpl;
  goto L10;
L9:;
  {
   cl_object v4i;
   v4i = ecl_car(v3);
   {
    cl_object v5;
    v5 = cl_slot_value(v4i, VV[5]);
    goto L18;
L17:;
    {
     cl_object v6j;
     v6j = ecl_car(v5);
     {
      cl_object v7;
      cl_object v8;
      v7 = v6j;
      v8 = v1free_list;
      if (Null(ecl_memql(v7,v8))){
       goto L22;
      }
     }
     value0 = v6j;
     cl_env_copy->nvalues = 1;
     return value0;
L22:;
    }
    v5 = ecl_cdr(v5);
L18:;
    if (Null(v5)){
     goto L28;
    }
    goto L17;
L28:;
   }
  }
  v3 = ecl_cdr(v3);
L10:;
  if (Null(v3)){
   goto L32;
  }
  goto L9;
L32:;
  value0 = ECL_NIL;
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
static cl_object LC786next_element_va(cl_narg narg, cl_object v4free_list, cl_object v5cpl, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[10]);
 {
  return LC786next_element(v4free_list, v5cpl);
 }
}
/* local function FREE-ELEMENTS                                               */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC785free_elements(cl_object v1class_list, cl_object v2precedence_lists)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3output;
  v3output = ECL_NIL;
  {
   cl_object v4;
   v4 = v1class_list;
   goto L7;
L6:;
   {
    cl_object v5class;
    v5class = ecl_car(v4);
    if (Null(LC784has_no_precedent(v5class, v2precedence_lists))){
     goto L11;
    }
    v3output = CONS(v5class,v3output);
L11:;
   }
   v4 = ecl_cdr(v4);
L7:;
   if (Null(v4)){
    goto L16;
   }
   goto L6;
L16:;
  }
  value0 = v3output;
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
static cl_object LC785free_elements_va(cl_narg narg, cl_object v4class_list, cl_object v5precedence_lists, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[9]);
 {
  return LC785free_elements(v4class_list, v5precedence_lists);
 }
}
/* local function HAS-NO-PRECEDENT                                            */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC784has_no_precedent(cl_object v1class, cl_object v2precedence_lists)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  v3 = v2precedence_lists;
  goto L5;
L4:;
  {
   cl_object v4partial_order;
   v4partial_order = ecl_car(v3);
   {
    cl_object v5;
    cl_object v6;
    cl_object v7;
    v5 = ecl_cdr(v4partial_order);
    v6 = v1class;
    v7 = v5;
    if (Null(ecl_memql(v6,v7))){
     goto L9;
    }
   }
   value0 = ECL_NIL;
   cl_env_copy->nvalues = 1;
   return value0;
L9:;
  }
  v3 = ecl_cdr(v3);
L5:;
  if (Null(v3)){
   goto L16;
  }
  goto L4;
L16:;
  value0 = ECL_T;
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
static cl_object LC784has_no_precedent_va(cl_narg narg, cl_object v4class, cl_object v5precedence_lists, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[8]);
 {
  return LC784has_no_precedent(v4class, v5precedence_lists);
 }
}
/* local function CYCLE-ERROR                                                 */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC783cycle_error(cl_object v1class)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 T0 = (cl_env_copy->function=(ECL_SYM("CLASS-NAME",938)->symbol.gfdef))->cfun.entry(1, v1class) /*  CLASS-NAME */;
 value0 = cl_error(2, VV[7], T0);
 return value0;
}
static cl_object LC783cycle_error_va(cl_narg narg, cl_object v2class, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[6]);
 {
  return LC783cycle_error(v2class);
 }
}
/* local function WALK-SUPERS                                                 */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC782walk_supers(cl_object v1superclasses)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v2;
  cl_object v3class_list;
  cl_object v4precedence_lists;
  v2 = ecl_list1(v1superclasses);
  v3class_list = ECL_NIL;
  v4precedence_lists = v2;
L5:;
  if (v1superclasses!=ECL_NIL) {
   goto L7;
  }
  cl_env_copy->nvalues = 2;
  cl_env_copy->values[1] = v4precedence_lists;
  cl_env_copy->values[0] = v3class_list;
  return cl_env_copy->values[0];
L7:;
  {
   cl_object v5next_class;
   {
    cl_object v6;
    v6 = v1superclasses;
    {
     cl_object v7;
     v7 = v6;
     {
      bool v8;
      v8 = ECL_LISTP(v7);
      if (ecl_unlikely(!(v8)))
         FEwrong_type_argument(VV[4],v7);
      value0 = ECL_NIL;
      cl_env_copy->nvalues = 0;
     }
    }
    if (Null(v6)){
     goto L14;
    }
    {
     cl_object v7;
     v7 = ECL_CONS_CDR(v6);
     v1superclasses = v7;
     v6 = ECL_CONS_CAR(v6);
    }
L14:;
    v5next_class = v6;
   }
   {
    cl_object v6;
    cl_object v7;
    v6 = v5next_class;
    v7 = v3class_list;
    if (ecl_memql(v6,v7)!=ECL_NIL) {
     goto L6;
    }
   }
   {
    cl_object v6more_classes;
    v6more_classes = cl_slot_value(v5next_class, VV[5]);
    v3class_list = CONS(v5next_class,v3class_list);
    T0 = CONS(v5next_class,v6more_classes);
    v4precedence_lists = CONS(T0,v4precedence_lists);
    v1superclasses = ecl_append(v6more_classes,v1superclasses);
   }
  }
L6:;
  goto L5;
 }
}
static cl_object LC782walk_supers_va(cl_narg narg, cl_object v5superclasses, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[1]);
 {
  return LC782walk_supers(v5superclasses);
 }
}
#include "clos/cpl.data"
#ifdef __cplusplus
extern "C"
#endif

ECL_DLLEXPORT void _eclPtSxnn2WOLgq9_Hu00M881(cl_object flag)
{
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 cl_object *VVtemp;
 if (flag != OBJNULL){
 Cblock = flag;
 #ifndef ECL_DYNAMIC_VV
 flag->cblock.data = VV;
 #endif
 flag->cblock.data_size = VM;
 flag->cblock.temp_data_size = VMtemp;
 flag->cblock.data_text = compiler_data_text;
 flag->cblock.cfuns_size = compiler_cfuns_size;
 flag->cblock.cfuns = compiler_cfuns;
 flag->cblock.source = ecl_make_constant_base_string("SRC:CLOS;CPL.LSP.NEWEST",-1);
 return;}
 #ifdef ECL_DYNAMIC_VV
 VV = Cblock->cblock.data;
 #endif
 Cblock->cblock.data_text = (const cl_object *)"@EcLtAg:_eclPtSxnn2WOLgq9_Hu00M881@";
 VVtemp = Cblock->cblock.temp_data;
 ECL_DEFINE_SETF_FUNCTIONS
/* MAKE-LOAD-FORMs                                                            */
/* TOP-LEVEL-FORMs                                                            */
  si_select_package(VVtemp[0]);
  ecl_cmp_defun(VV[14]);                          /*  COMPUTE-CLOS-CLASS-PRECEDENCE-LIST */
}
