#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
#include "cfunc.h"
extern cptr slist_methods[meth_max];
extern cptr sset_methods[meth_max];
extern cptr boolean_methods[meth_max];
extern cptr strpool_methods[meth_max];

extern cint boolean_True;
extern cint boolean_False;
extern cint strpool_str_88;


cptr lazy_methods[meth_max];

cint lazy_alloc(cint lazy_self, cint lazy_b){
  cint lazy_result;
  cint t1, t2;
  t2 = object_alloc((cint)lazy_self);
  lazy_result = t2;
  ((cptr)lazy_self)[4] /* class_of*/ = strpool_str_88;
  ((cptr)lazy_self)[7] /* body*/ = lazy_b;
  t1 = lazy_result;
  goto t1_label;
  t1_label: return t1;
}

cint lazy_reclaim(cint lazy_self){
  cint t3;
  object_reclaim((cint)lazy_self);
  t3_label: return t3;
}

cint lazy_Eval(cint lazy_self){
  cint lazy_result;
  cint t4;
  lazy_result = cfunc_fcall((cint)((cptr)lazy_self)[7] /* body*/);
  object_Dec_ref(lazy_self);
  t4 = lazy_result;
  goto t4_label;
  t4_label: return t4;
}

cint lazy_Forany(cint lazy_self, cint lazy_ob){
  cint lazy_result;
  cint t5, t6, t7, t10, t11, t12, t13, t14;
  lazy_result = boolean_True;
  t8:
  t10 = ((cptr)(((cptr)lazy_ob)[0]))[55];
  t11 = ((f0)t10)((cint)lazy_ob); /* iterate*/
  t12 = t11 != 0;
  t13 = t12;
  if (t13){
    t14 = lazy_result == boolean_True;
    t13 = t14;
  };
  if (!t13) goto t9;
    lazy_result = cfunc_fcall((cint)((cptr)lazy_self)[7] /* body*/);
  goto t8;
  t9:;
  object_Dec_ref(lazy_self);
  object_Dec_ref(lazy_ob);
  t5 = lazy_result;
  goto t5_label;
  t5_label: return t5;
}

cint lazy_Forsome(cint lazy_self, cint lazy_ob){
  cint lazy_result;
  cint t15, t16, t17, t20, t21, t22, t23, t24;
  lazy_result = boolean_False;
  t18:
  t20 = ((cptr)(((cptr)lazy_ob)[0]))[55];
  t21 = ((f0)t20)((cint)lazy_ob); /* iterate*/
  t22 = t21 != 0;
  t23 = t22;
  if (t23){
    t24 = lazy_result == boolean_False;
    t23 = t24;
  };
  if (!t23) goto t19;
    lazy_result = cfunc_fcall((cint)((cptr)lazy_self)[7] /* body*/);
  goto t18;
  t19:;
  object_Dec_ref(lazy_self);
  object_Dec_ref(lazy_ob);
  t15 = lazy_result;
  goto t15_label;
  t15_label: return t15;
}

cint lazy_Make_elist(cint lazy_self, cint lazy_ob){
  cint lazy_result;
  cint t25, t26, t27, t28, t29, t32, t33, t34, t35, t36, t37;
  t26 = mem_malloc(40); ((cptr)t26)[0] = slist_methods;
  t27 = slist_alloc((cint)t26, (cint)0);
  lazy_result = t27;
  t30:
  t32 = ((cptr)(((cptr)lazy_ob)[0]))[55];
  t33 = ((f0)t32)((cint)lazy_ob); /* iterate*/
  t34 = t33 != 0;
  if (!t34) goto t31;
    t35 = ((cptr)(((cptr)lazy_result)[0]))[7];
    t36 = ((f0)t35)((cint)lazy_result, (cint)cfunc_fcall((cint)((cptr)lazy_self)[7] /* body*/)); /* Append*/
    lazy_result = t36;
  goto t30;
  t31:;
  object_Dec_ref(lazy_self);
  object_Dec_ref(lazy_ob);
  t25 = lazy_result;
  goto t25_label;
  t25_label: return t25;
}

cint lazy_Make_eset(cint lazy_self, cint lazy_ob){
  cint lazy_result;
  cint t38, t39, t40, t41, t42, t45, t46, t47, t48, t49, t50;
  t39 = mem_malloc(48); ((cptr)t39)[0] = sset_methods;
  t40 = sset_alloc((cint)t39);
  lazy_result = t40;
  t43:
  t45 = ((cptr)(((cptr)lazy_ob)[0]))[55];
  t46 = ((f0)t45)((cint)lazy_ob); /* iterate*/
  t47 = t46 != 0;
  if (!t47) goto t44;
    t48 = ((cptr)(((cptr)lazy_result)[0]))[7];
    t49 = ((f0)t48)((cint)lazy_result, (cint)cfunc_fcall((cint)((cptr)lazy_self)[7] /* body*/)); /* Append*/
    lazy_result = t49;
  goto t43;
  t44:;
  object_Dec_ref(lazy_self);
  object_Dec_ref(lazy_ob);
  t38 = lazy_result;
  goto t38_label;
  t38_label: return t38;
}

void init_lazy(){
  copy_meth_table(lazy_methods, object_methods);
  lazy_methods[0] = 32;
  lazy_methods[3] = lazy_alloc;
  lazy_methods[4] = lazy_reclaim;
  lazy_methods[38] = lazy_Eval;
  lazy_methods[262] = lazy_Forany;
  lazy_methods[263] = lazy_Forsome;
  lazy_methods[64] = lazy_Make_elist;
  lazy_methods[65] = lazy_Make_eset;
}
