#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
#include "cint.h"
extern cptr strpool_methods[meth_max];
extern cptr iterator_methods[meth_max];
extern cptr filter_methods[meth_max];

extern cint strpool_str_73;


cptr niterator_methods[meth_max];

cint niterator_alloc(cint niterator_self, cint niterator_o, cint niterator_t, cint niterator_s){
  cint niterator_result;
  cint t1, t2;
  t2 = object_alloc((cint)niterator_self);
  niterator_result = t2;
  ((cptr)niterator_self)[4] /* class_of*/ = strpool_str_73;
  ((cptr)niterator_self)[10] /* outer*/ = niterator_o;
  ((cptr)niterator_self)[8] /* inner_t*/ = niterator_t;
  ((cptr)niterator_self)[9] /* inner_s*/ = niterator_s;
  ((cptr)niterator_self)[11] /* cursor*/ = 0;
  t1 = niterator_result;
  goto t1_label;
  t1_label: return t1;
}

cint niterator_reclaim(cint niterator_self){
  cint t3;
  object_Dec_ref(((cptr)niterator_self)[10] /* outer*/);
  object_Dec_ref(((cptr)niterator_self)[8] /* inner_t*/);
  object_Dec_ref(((cptr)niterator_self)[9] /* inner_s*/);
  object_reclaim((cint)niterator_self);
  t3_label: return t3;
}

cint niterator_iterate(cint niterator_self){
  cint niterator_result;
  cint t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29;
  t5 = ((cptr)niterator_self)[11] /* cursor*/ == 0;
  if (t5){
    t6 = ((cptr)(((cptr)((cptr)niterator_self)[10] /* outer*/)[0]))[55];
    t7 = ((f0)t6)((cint)((cptr)niterator_self)[10] /* outer*/); /* iterate*/
    niterator_result = t7;
    t9 = mem_malloc(52); ((cptr)t9)[0] = iterator_methods;
    ((cptr)((cptr)niterator_self)[8] /* inner_t*/)[1] += 1;
    ((cptr)((cptr)niterator_self)[9] /* inner_s*/)[1] += 1;
    t10 = ((cptr)(((cptr)((cptr)niterator_self)[9] /* inner_s*/)[0]))[38];
    t11 = ((f0)t10)((cint)((cptr)niterator_self)[9] /* inner_s*/); /* Eval*/
    t12 = iterator_alloc((cint)t9, (cint)((cptr)niterator_self)[8] /* inner_t*/, (cint)t11);
    ((cptr)niterator_self)[7] /* inner*/ = t12;
  };
  t14 = ((cptr)(((cptr)((cptr)niterator_self)[7] /* inner*/)[0]))[55];
  t15 = ((f0)t14)((cint)((cptr)niterator_self)[7] /* inner*/); /* iterate*/
  niterator_result = t15;
  t17 = niterator_result == 0;
  if (t17){
    object_Dec_ref(((cptr)niterator_self)[7] /* inner*/);
    t18 = ((cptr)(((cptr)((cptr)niterator_self)[10] /* outer*/)[0]))[55];
    t19 = ((f0)t18)((cint)((cptr)niterator_self)[10] /* outer*/); /* iterate*/
    niterator_result = t19;
    t21 = niterator_result != 0;
    if (t21){
      t22 = mem_malloc(52); ((cptr)t22)[0] = iterator_methods;
      ((cptr)((cptr)niterator_self)[8] /* inner_t*/)[1] += 1;
      ((cptr)((cptr)niterator_self)[9] /* inner_s*/)[1] += 1;
      t23 = ((cptr)(((cptr)((cptr)niterator_self)[9] /* inner_s*/)[0]))[38];
      t24 = ((f0)t23)((cint)((cptr)niterator_self)[9] /* inner_s*/); /* Eval*/
      t25 = iterator_alloc((cint)t22, (cint)((cptr)niterator_self)[8] /* inner_t*/, (cint)t24);
      ((cptr)niterator_self)[7] /* inner*/ = t25;
      t27 = ((cptr)(((cptr)((cptr)niterator_self)[7] /* inner*/)[0]))[55];
      t28 = ((f0)t27)((cint)((cptr)niterator_self)[7] /* inner*/); /* iterate*/
      niterator_result = t28;
    };
  };
  ((cptr)niterator_self)[11] /* cursor*/ = niterator_result;
  t4 = niterator_result;
  goto t4_label;
  t4_label: return t4;
}

cint niterator_Make_filter(cint niterator_self, cint niterator_le){
  cint niterator_result;
  cint t30, t31, t32;
  t31 = mem_malloc(36); ((cptr)t31)[0] = filter_methods;
  t32 = filter_alloc((cint)t31, (cint)niterator_self, (cint)niterator_le);
  t30 = t32;
  goto t30_label;
  t30_label: return t30;
}

cint niterator_Make_nested_iterator(cint niterator_self, cint niterator_t, cint niterator_s){
  cint niterator_result;
  cint t33, t34, t35;
  t34 = mem_malloc(48); ((cptr)t34)[0] = niterator_methods;
  t35 = niterator_alloc((cint)t34, (cint)niterator_self, (cint)niterator_t, (cint)niterator_s);
  t33 = t35;
  goto t33_label;
  t33_label: return t33;
}

void init_niterator(){
  copy_meth_table(niterator_methods, object_methods);
  niterator_methods[0] = 48;
  niterator_methods[3] = niterator_alloc;
  niterator_methods[4] = niterator_reclaim;
  niterator_methods[55] = niterator_iterate;
  niterator_methods[66] = niterator_Make_filter;
  niterator_methods[71] = niterator_Make_nested_iterator;
}
