#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
extern cptr string_methods[meth_max];
extern cptr scope_methods[meth_max];
extern cptr identifier_methods[meth_max];
#include "croutine.h"
#include "cint.h"
extern cptr stdout_methods[meth_max];
extern cptr integer_methods[meth_max];
extern cptr strpool_methods[meth_max];
extern cptr clib_methods[meth_max];
#include "cstring.h"
extern cptr debug_methods[meth_max];
#include "cfile.h"
extern cptr parameter_methods[meth_max];
extern cptr exprfunc_methods[meth_max];
extern cptr slist_methods[meth_max];
extern cptr selector_methods[meth_max];
extern cptr function_methods[meth_max];

extern cint object_Undefined;
extern cint clib_Trace;
extern cint clib_stdo;
extern cint scope_curr;
extern cint strpool_str_13;
extern cint strpool_str_15;
extern cint strpool_str_81;
extern cint strpool_str_37;


cptr procedure_methods[meth_max];

cint procedure_alloc(cint procedure_self, cint procedure_b, cint procedure_id, cint procedure_mid){
  cint procedure_result, procedure_p, procedure_first_par_is_self;
  cint t1, t2, t3, t4, t5, t6, t7, t8, t9;
  t2 = object_alloc((cint)procedure_self);
  procedure_result = t2;
  ((cptr)procedure_self)[4] /* class_of*/ = strpool_str_81;
  ((cptr)procedure_self)[7] /* module*/ = procedure_mid;
  ((cptr)((cptr)procedure_id)[7] /* name*/)[1] += 1;
  ((cptr)procedure_self)[8] /* name*/ = ((cptr)procedure_id)[7] /* name*/;
  ((cptr)procedure_self)[9] /* body*/ = procedure_b;
  ((cptr)procedure_self)[10] /* efunc*/ = 0;
  ((cptr)scope_curr)[1] += 1;
  ((cptr)((cptr)procedure_id)[7] /* name*/)[1] += 1;
  t3 = ((cptr)(((cptr)scope_curr)[0]))[9];
  t4 = ((f0)t3)((cint)scope_curr, (cint)((cptr)procedure_id)[7] /* name*/); /* Apply*/
  ((cptr)procedure_self)[11] /* ffunc*/ = t4;
  t6 = ((cptr)procedure_self)[11] /* ffunc*/ == object_Undefined;
  t7 = t6;
  if (!t7){    t8 = ((cptr)((cptr)procedure_self)[11] /* ffunc*/)[4] /* class_of*/ != strpool_str_37;
    t7 = t8;
  };
  if (t7){
    ((cptr)procedure_self)[11] /* ffunc*/ = 0;
  };
  t9 = (cptr)(((cptr)(((cptr)scope_curr)[0]))[121]); /* enter_into*/
  ((f0)t9)((cint)scope_curr, (cint)((cptr)procedure_id)[7] /* name*/, (cint)procedure_self);
  ((cptr)procedure_self)[12] /* escope*/ = scope_curr;
  object_Dec_ref(procedure_id);
  t1 = procedure_result;
  goto t1_label;
  t1_label: return t1;
}

cint procedure_alloc_new(cint procedure_p, cint procedure_id, cint procedure_scop){
  cint procedure_result, procedure_saved_curr;
  cint t10, t11, t12;
  procedure_saved_curr = scope_curr;
  scope_curr = procedure_scop;
  t11 = mem_malloc(52); ((cptr)t11)[0] = procedure_methods;
  t12 = procedure_alloc((cint)t11, (cint)0, (cint)procedure_id, (cint)0);
  procedure_result = t12;
  ((cptr)procedure_result)[10] /* efunc*/ = procedure_p;
  scope_curr = procedure_saved_curr;
  t10 = procedure_result;
  goto t10_label;
  t10_label: return t10;
}

cint procedure_reclaim(cint procedure_self){
  cint t13;
  object_Dec_ref(((cptr)procedure_self)[8] /* name*/);
  object_reclaim((cint)procedure_self);
  t13_label: return t13;
}

cint procedure_Apply(cint procedure_self, cint procedure_params){
  cint procedure_result;
  cint t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31;
  t15 = ((cptr)procedure_self)[10] /* efunc*/ != 0;
  if (t15){
    t16 = procedure_params != 0;
    if (t16){
      ((cptr)((cptr)procedure_self)[10] /* efunc*/)[1] += 1;
      t17 = mem_malloc(40); ((cptr)t17)[0] = slist_methods;
      t18 = slist_alloc((cint)t17, (cint)1);
      ((cptr)t18)[1] += 1;
      ((cptr)procedure_params)[1] += 1;
      t19 = ((cptr)(((cptr)t18)[0]))[7];
      t20 = ((f0)t19)((cint)t18, (cint)procedure_params); /* Append*/
      t21 = (cptr)(((cptr)(((cptr)((cptr)procedure_self)[10] /* efunc*/)[0]))[9]); /* Apply*/
      ((f0)t21)((cint)((cptr)procedure_self)[10] /* efunc*/, (cint)t20);
    }else{
      ((cptr)((cptr)procedure_self)[10] /* efunc*/)[1] += 1;
      t22 = (cptr)(((cptr)(((cptr)((cptr)procedure_self)[10] /* efunc*/)[0]))[9]); /* Apply*/
      ((f0)t22)((cint)((cptr)procedure_self)[10] /* efunc*/, (cint)0);
    };
    object_Dec_ref(procedure_self);
  }else{
  t23 = ((cptr)procedure_self)[11] /* ffunc*/ != 0;
  if (t23){
    t24 = procedure_params != 0;
    if (t24){
      ((cptr)((cptr)procedure_self)[11] /* ffunc*/)[1] += 1;
      t25 = ((cptr)(((cptr)((cptr)procedure_self)[11] /* ffunc*/)[0]))[9];
      t26 = ((f0)t25)((cint)((cptr)procedure_self)[11] /* ffunc*/, (cint)procedure_params); /* Apply*/
      procedure_result = t26;
    }else{
      ((cptr)((cptr)procedure_self)[11] /* ffunc*/)[1] += 1;
      t28 = ((cptr)(((cptr)((cptr)procedure_self)[11] /* ffunc*/)[0]))[9];
      t29 = ((f0)t28)((cint)((cptr)procedure_self)[11] /* ffunc*/, (cint)0); /* Apply*/
      procedure_result = t29;
    };
    object_Dec_ref(procedure_self);
    t14 = procedure_result;
    goto t14_label;
  }else{
    t31 = (cptr)(((cptr)(((cptr)procedure_self)[0]))[18]); /* Call_with_params*/
    ((f0)t31)((cint)procedure_self, (cint)procedure_params);
  };};
  t14 = object_Undefined;
  goto t14_label;
  t14_label: return t14;
}

cint procedure_Call(cint procedure_self){
  cint t32, t33;
  t33 = (cptr)(((cptr)(((cptr)procedure_self)[0]))[18]); /* Call_with_params*/
  ((f0)t33)((cint)procedure_self, (cint)0);
  t32_label: return t32;
}

cint procedure_Call_with_params(cint procedure_self, cint procedure_params){
  cint procedure_Calling_scope, procedure_Saved_module;
  cint t34, t35, t36, t37, t38, t39, t40, t41, t42, t43, t44, t45, t46, t47, t48, t49, t50, t51;
  t35 = ((cptr)procedure_self)[10] /* efunc*/ != 0;
  if (t35){
    t36 = procedure_params != 0;
    if (t36){
      ((cptr)((cptr)procedure_self)[10] /* efunc*/)[1] += 1;
      t37 = mem_malloc(40); ((cptr)t37)[0] = slist_methods;
      t38 = slist_alloc((cint)t37, (cint)1);
      ((cptr)t38)[1] += 1;
      ((cptr)procedure_params)[1] += 1;
      t39 = ((cptr)(((cptr)t38)[0]))[7];
      t40 = ((f0)t39)((cint)t38, (cint)procedure_params); /* Append*/
      t41 = (cptr)(((cptr)(((cptr)((cptr)procedure_self)[10] /* efunc*/)[0]))[9]); /* Apply*/
      ((f0)t41)((cint)((cptr)procedure_self)[10] /* efunc*/, (cint)t40);
    }else{
      ((cptr)((cptr)procedure_self)[10] /* efunc*/)[1] += 1;
      t42 = (cptr)(((cptr)(((cptr)((cptr)procedure_self)[10] /* efunc*/)[0]))[9]); /* Apply*/
      ((f0)t42)((cint)((cptr)procedure_self)[10] /* efunc*/, (cint)0);
    };
    object_Dec_ref(procedure_self);
    goto t34_label;
  };
  t43 = ((cptr)clib_Trace)[2] /* hashval*/ > 0;
  if (t43){
    stdout_Put_indent();
    t44 = ((cptr)procedure_self)[7] /* module*/ != 0;
    if (t44){
      cfile_fprintf((cint)clib_stdo, (cint)((cptr)procedure_self)[7] /* module*/);
    };
    ((cptr)((cptr)procedure_self)[8] /* name*/)[1] += 1;
    stdout_Put((cint)((cptr)procedure_self)[8] /* name*/);
    ((cptr)strpool_str_13)[1] += 1;
    stdout_Put((cint)strpool_str_13);
    t45 = ((cptr)clib_Trace)[2] /* hashval*/ > 1;
    if (t45){
      t46 = procedure_params != 0;
      if (t46){
        ((cptr)procedure_params)[1] += 1;
        stdout_Put((cint)procedure_params);
      };
    };
    ((cptr)strpool_str_15)[1] += 1;
    stdout_Put((cint)strpool_str_15);
    stdout_Put_eol();
    stdout_Inc_indent();
  };
  procedure_Calling_scope = scope_curr;
  t47 = mem_malloc(60); ((cptr)t47)[0] = scope_methods;
  t48 = scope_alloc((cint)t47, (cint)((cptr)procedure_self)[12] /* escope*/, (cint)procedure_params);
  scope_curr = t48;
  t49 = debug_get_module();
  procedure_Saved_module = t49;
  t50 = ((cptr)procedure_self)[7] /* module*/ != 0;
  if (t50){
    debug_set_module((cint)((cptr)procedure_self)[7] /* module*/);
  };
  croutine_call((cint)((cptr)procedure_self)[9] /* body*/);
  debug_set_module((cint)procedure_Saved_module);
  object_Dec_ref(scope_curr);
  object_Dec_ref(procedure_self);
  scope_curr = procedure_Calling_scope;
  t51 = ((cptr)clib_Trace)[2] /* hashval*/ > 0;
  if (t51){
    stdout_Dec_indent();
  };
  t34_label: return t34;
}

cint procedure_Make_parameter(cint procedure_self, cint procedure_ob){
  cint procedure_result;
  cint t52, t53, t54;
  t53 = mem_malloc(36); ((cptr)t53)[0] = parameter_methods;
  t54 = parameter_alloc((cint)t53, (cint)procedure_self, (cint)procedure_ob);
  t52 = t54;
  goto t52_label;
  t52_label: return t52;
}

cint procedure_Make_selector(cint procedure_self, cint procedure_ob){
  cint procedure_result;
  cint t55, t56, t57;
  t56 = mem_malloc(36); ((cptr)t56)[0] = selector_methods;
  t57 = selector_alloc((cint)t56, (cint)procedure_self, (cint)procedure_ob);
  t55 = t57;
  goto t55_label;
  t55_label: return t55;
}

cint procedure_Mkstr(cint procedure_self){
  cint procedure_result;
  cint t58;
  ((cptr)((cptr)procedure_self)[8] /* name*/)[1] += 1;
  procedure_result = ((cptr)procedure_self)[8] /* name*/;
  object_Dec_ref(procedure_self);
  t58 = procedure_result;
  goto t58_label;
  t58_label: return t58;
}

void init_procedure(){
  copy_meth_table(procedure_methods, object_methods);
  procedure_methods[0] = 52;
  procedure_methods[3] = procedure_alloc;
  procedure_methods[119] = procedure_alloc_new;
  procedure_methods[4] = procedure_reclaim;
  procedure_methods[9] = procedure_Apply;
  procedure_methods[16] = procedure_Call;
  procedure_methods[18] = procedure_Call_with_params;
  procedure_methods[77] = procedure_Make_parameter;
  procedure_methods[73] = procedure_Make_selector;
  procedure_methods[88] = procedure_Mkstr;
}
