#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
extern cptr scope_methods[meth_max];
extern cptr strpool_methods[meth_max];

extern cint object_Undefined;


cptr jscope_methods[meth_max];

cint jscope_alloc(cint jscope_self, cint jscope_s1, cint jscope_s2){
  cint jscope_result;
  cint t1, t2;
  t2 = object_alloc((cint)jscope_self);
  jscope_result = t2;
  ((cptr)jscope_self)[7] /* scope1*/ = jscope_s1;
  ((cptr)jscope_self)[8] /* scope2*/ = jscope_s2;
  t1 = jscope_result;
  goto t1_label;
  t1_label: return t1;
}

cint jscope_reclaim(cint jscope_self){
  cint t3;
  object_reclaim((cint)jscope_self);
  t3_label: return t3;
}

cint jscope_Apply(cint jscope_self, cint jscope_params){
  cint jscope_result;
  cint t4, t5, t6, t7, t8, t9, t10, t11;
  ((cptr)((cptr)jscope_self)[7] /* scope1*/)[1] += 1;
  ((cptr)jscope_params)[1] += 1;
  t5 = ((cptr)(((cptr)((cptr)jscope_self)[7] /* scope1*/)[0]))[9];
  t6 = ((f0)t5)((cint)((cptr)jscope_self)[7] /* scope1*/, (cint)jscope_params); /* Apply*/
  jscope_result = t6;
  t8 = jscope_result == object_Undefined;
  if (t8){
    ((cptr)((cptr)jscope_self)[8] /* scope2*/)[1] += 1;
    ((cptr)jscope_params)[1] += 1;
    t9 = ((cptr)(((cptr)((cptr)jscope_self)[8] /* scope2*/)[0]))[9];
    t10 = ((f0)t9)((cint)((cptr)jscope_self)[8] /* scope2*/, (cint)jscope_params); /* Apply*/
    jscope_result = t10;
  };
  object_Dec_ref(jscope_self);
  object_Dec_ref(jscope_params);
  t4 = jscope_result;
  goto t4_label;
  t4_label: return t4;
}

cint jscope_incl(cint jscope_self, cint jscope_other){
  cint jscope_result;
  cint t12, t13, t14, t15, t16, t17, t18, t19, t20;
  t13 = jscope_self == jscope_other;
  if (t13){
    t12 = 1;
    goto t12_label;
  };
  t14 = ((cptr)(((cptr)((cptr)jscope_self)[7] /* scope1*/)[0]))[52];
  t15 = ((f0)t14)((cint)((cptr)jscope_self)[7] /* scope1*/, (cint)jscope_other); /* incl*/
  jscope_result = t15;
  t17 = jscope_result == 0;
  if (t17){
    t18 = ((cptr)(((cptr)((cptr)jscope_self)[8] /* scope2*/)[0]))[52];
    t19 = ((f0)t18)((cint)((cptr)jscope_self)[8] /* scope2*/, (cint)jscope_other); /* incl*/
    jscope_result = t19;
  };
  t12 = jscope_result;
  goto t12_label;
  t12_label: return t12;
}

cint jscope_join(cint jscope_self, cint jscope_other){
  cint jscope_result;
  cint t21, t22, t23, t24, t25, t26, t27, t28, t29;
  t24 = jscope_other == object_Undefined;
  t25 = t24;
  if (!t25){  t22 = ((cptr)(((cptr)jscope_self)[0]))[52];
  t23 = ((f0)t22)((cint)jscope_self, (cint)jscope_other); /* incl*/
    t25 = t23;
  };
  if (t25){
    t21 = jscope_self;
    goto t21_label;
  };
  t26 = ((cptr)(((cptr)jscope_other)[0]))[52];
  t27 = ((f0)t26)((cint)jscope_other, (cint)jscope_self); /* incl*/
  if (t27){
    t21 = jscope_other;
    goto t21_label;
  };
  t28 = mem_malloc(36); ((cptr)t28)[0] = jscope_methods;
  t29 = jscope_alloc((cint)t28, (cint)jscope_self, (cint)jscope_other);
  t21 = t29;
  goto t21_label;
  t21_label: return t21;
}

void init_jscope(){
  copy_meth_table(jscope_methods, object_methods);
  jscope_methods[0] = 36;
  jscope_methods[3] = jscope_alloc;
  jscope_methods[4] = jscope_reclaim;
  jscope_methods[9] = jscope_Apply;
  jscope_methods[52] = jscope_incl;
  jscope_methods[56] = jscope_join;
}
