#include "cdefs.h"
#include "mem.h"
extern cptr object_methods[meth_max];
extern cptr collection_methods[meth_max];
#include "cint.h"
#include "cstring.h"
#include "cfile.h"
#include "croutine.h"
#include "cprocess.h"
extern cptr strpool_methods[meth_max];
extern cptr integer_methods[meth_max];
extern cptr boolean_methods[meth_max];
extern cptr character_methods[meth_max];
extern cptr slicestr_methods[meth_max];
extern cptr sstring_methods[meth_max];
extern cptr pstring_methods[meth_max];
extern cptr identifier_methods[meth_max];
extern cptr scope_methods[meth_max];
extern cptr function_methods[meth_max];
extern cptr float_methods[meth_max];
extern cptr debug_methods[meth_max];
extern cptr procedure_methods[meth_max];

extern cint strpool_str_6;
extern cint strpool_str_5;
extern cint object_Undefined;
extern cint scope_global;
extern cint scope_last_imported;
extern cint function_Calling_scope;
extern cint strpool_str_33;
extern cint character_close_quote;
extern cint scope_curr;
extern cint character_open_quote;


cptr string_methods[meth_max];

cint string_alloc(cint string_self){
  cint string_result;
  cint t1, t2;
  t2 = collection_alloc((cint)string_self);
  string_result = t2;
  ((cptr)string_result)[4] /* class_of*/ = strpool_str_6;
  ((cptr)string_result)[8] /* buf*/ = 0;
  t1 = string_result;
  goto t1_label;
  t1_label: return t1;
}

cint string_reclaim(cint string_self){
  cint t3;
  collection_reclaim((cint)string_self);
  t3_label: return t3;
}

cint string_Apply_indirect(cint string_self, cint string_params){
  cint string_result, string_Saved_curr_scope, string_id;
  cint t4, t5, t6, t7, t8, t9;
  string_Saved_curr_scope = scope_curr;
  scope_curr = function_Calling_scope;
  t5 = mem_malloc(32); ((cptr)t5)[0] = identifier_methods;
  t6 = identifier_salloc((cint)t5, (cint)string_self);
  string_id = t6;
  t7 = ((cptr)(((cptr)string_id)[0]))[9];
  t8 = ((f0)t7)((cint)string_id, (cint)string_params); /* Apply*/
  string_result = t8;
  scope_curr = string_Saved_curr_scope;
  t4 = string_result;
  goto t4_label;
  t4_label: return t4;
}

cint string_All_but_last(cint string_self){
  cint string_result;
  cint t10, t11, t12, t13, t14, t15;
  t11 = ((cptr)string_self)[3] /* len*/ == 0;
  if (t11){
    object_Dec_ref(string_self);
    t10 = object_Undefined;
    goto t10_label;
  };
  t12 = ((cptr)string_self)[3] /* len*/ == 1;
  if (t12){
    object_Dec_ref(string_self);
    ((cptr)strpool_str_33)[1] += 1;
    t10 = strpool_str_33;
    goto t10_label;
  };
  t13 = mem_malloc(48); ((cptr)t13)[0] = slicestr_methods;
  t14 = ((cptr)string_self)[3] /* len*/ - 1;
  t15 = slicestr_alloc((cint)t13, (cint)string_self, (cint)1, (cint)t14);
  t10 = t15;
  goto t10_label;
  t10_label: return t10;
}

cint string_Append(cint string_self, cint string_item){
  cint string_result;
  cint t16, t17, t18, t19, t20;
  t17 = ((cptr)string_item)[4] /* class_of*/ == strpool_str_6;
  if (t17){
    t18 = ((cptr)(((cptr)string_self)[0]))[97];
    t19 = ((f0)t18)((cint)string_self, (cint)string_item); /* Plus*/
    t16 = t19;
    goto t16_label;
  };
  object_Dec_ref(string_self);
  object_Dec_ref(string_item);
  t16 = object_Undefined;
  goto t16_label;
  t16_label: return t16;
}

cint string_as_string(cint string_self){
  cint string_result, string_siz, string_r, string_i;
  cint t21, t22, t24, t25, t26, t27;
  string_siz = ((cptr)string_self)[3] /* len*/;
  t22 = string_siz + 1;
  string_r = cstring_mem_malloc((cint)t22);
  for (string_i = 1; string_i <= string_siz; string_i++){
    t24 = string_i - 1;
    t25 = ((cptr)(((cptr)string_self)[0]))[62];
    t26 = ((f0)t25)((cint)string_self, (cint)string_i); /* lookup*/
    cstring_update_char((cint)string_r, (cint)t24, (cint)((cptr)t26)[2] /* hashval*/);
  };t23:;
  cstring_update_char((cint)string_r, (cint)string_siz, (cint)0);
  t21 = string_r;
  goto t21_label;
  t21_label: return t21;
}

cint string_Assign_to_component(cint string_self, cint string_param, cint string_new_val, cint string_op){
  cint string_result;
  cint t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40, t41, t42, t43;
  t29 = ((cptr)string_param)[4] /* class_of*/ == strpool_str_5;
  t30 = t29;
  if (t30){
    t31 = ((cptr)string_param)[2] /* hashval*/ > 0;
    t30 = t31;
  };
  t32 = t30;
  if (t32){
    t33 = string_op == 0;
    t32 = t33;
  };
  t34 = t32;
  if (t34){
    t35 = ((cptr)string_new_val)[4] /* class_of*/ == strpool_str_6;
    t34 = t35;
  };
  t36 = t34;
  if (t36){
    t37 = ((cptr)string_new_val)[3] /* len*/ == 1;
    t36 = t37;
  };
  if (t36){
    t38 = ((cptr)(((cptr)string_self)[0]))[130];
    t39 = ((f0)t38)((cint)string_self, (cint)((cptr)string_param)[2] /* hashval*/, (cint)((cptr)string_new_val)[2] /* hashval*/); /* update*/
    string_result = t39;
    object_Dec_ref(string_param);
    object_Dec_ref(string_new_val);
  }else{
    t41 = ((cptr)(((cptr)string_self)[0]))[21];
    t42 = ((f0)t41)((cint)string_self); /* copy_of*/
    string_result = t42;
    object_Dec_ref(string_param);
    object_Dec_ref(string_new_val);
  };
  t28 = string_result;
  goto t28_label;
  t28_label: return t28;
}

cint string_Delete_ith(cint string_self, cint string_i){
  cint string_result, string_sl1, string_sl2;
  cint t44, t45, t46, t47, t48, t49, t50, t51, t52, t53, t54, t55, t56, t57, t58, t59, t60;
  t45 = string_i == 1;
  if (t45){
    t46 = mem_malloc(48); ((cptr)t46)[0] = slicestr_methods;
    t47 = slicestr_alloc((cint)t46, (cint)string_self, (cint)2, (cint)((cptr)string_self)[3] /* len*/);
    t44 = t47;
    goto t44_label;
  }else{
  t48 = string_i == ((cptr)string_self)[3] /* len*/;
  if (t48){
    t49 = mem_malloc(48); ((cptr)t49)[0] = slicestr_methods;
    t50 = string_i - 1;
    t51 = slicestr_alloc((cint)t49, (cint)string_self, (cint)1, (cint)t50);
    t44 = t51;
    goto t44_label;
  }else{
    t52 = mem_malloc(48); ((cptr)t52)[0] = slicestr_methods;
    t53 = string_i - 1;
    t54 = slicestr_alloc((cint)t52, (cint)string_self, (cint)1, (cint)t53);
    string_sl1 = t54;
    t55 = mem_malloc(48); ((cptr)t55)[0] = slicestr_methods;
    ((cptr)string_self)[1] += 1;
    t56 = string_i + 1;
    t57 = slicestr_alloc((cint)t55, (cint)string_self, (cint)t56, (cint)((cptr)string_self)[3] /* len*/);
    string_sl2 = t57;
    t58 = ((cptr)(((cptr)string_sl1)[0]))[97];
    t59 = ((f0)t58)((cint)string_sl1, (cint)string_sl2); /* Plus*/
    t44 = t59;
    goto t44_label;
  };};
  t44 = string_result;
  goto t44_label;
  t44_label: return t44;
}

cint string_equal(cint string_self, cint string_s){
  cint string_result, string_i;
  cint t61, t62, t63, t64, t65, t67, t68, t69, t70, t71;
  t62 = string_self == string_s;
  if (t62){
    t61 = 1;
    goto t61_label;
  };
  t63 = ((cptr)string_s)[4] /* class_of*/ != strpool_str_6;
  if (t63){
    t61 = 0;
    goto t61_label;
  };
  t64 = ((cptr)string_self)[2] /* hashval*/ != ((cptr)string_s)[2] /* hashval*/;
  if (t64){
    t61 = 0;
    goto t61_label;
  };
  t65 = ((cptr)string_self)[3] /* len*/ != ((cptr)string_s)[3] /* len*/;
  if (t65){
    t61 = 0;
    goto t61_label;
  };
  for (string_i = 1; string_i <= ((cptr)string_self)[3] /* len*/; string_i++){
    t67 = ((cptr)(((cptr)string_self)[0]))[63];
    t68 = ((f0)t67)((cint)string_self, (cint)string_i); /* lookup_as_cint*/
    t69 = ((cptr)(((cptr)string_s)[0]))[63];
    t70 = ((f0)t69)((cint)string_s, (cint)string_i); /* lookup_as_cint*/
    t71 = t68 != t70;
    if (t71){
      t61 = 0;
      goto t61_label;
    };
  };t66:;
  t61 = 1;
  goto t61_label;
  t61_label: return t61;
}

cint string_Import(cint string_self){
  cint string_Saved_module, string_init;
  cint t72, t73, t74, t75, t76, t77;
  t73 = debug_get_module();
  string_Saved_module = t73;
  ((cptr)scope_global)[1] += 1;
  ((cptr)string_self)[1] += 1;
  t74 = ((cptr)(((cptr)scope_global)[0]))[9];
  t75 = ((f0)t74)((cint)scope_global, (cint)string_self); /* Apply*/
  string_init = t75;
  t77 = string_init == object_Undefined;
  if (t77){
    object_Dec_ref(string_self);
    goto t72_label;
  };
  croutine_call((cint)((cptr)string_init)[9] /* body*/);
  ((cptr)scope_last_imported)[14] /* module_name*/ = string_self;
  debug_set_module((cint)string_Saved_module);
  object_Dec_ref(string_init);
  t72_label: return t72;
}

cint string_Import_into(cint string_self, cint string_scop){
  cint string_id;
  cint t78, t79, t80, t81;
  t79 = mem_malloc(32); ((cptr)t79)[0] = identifier_methods;
  t80 = identifier_salloc((cint)t79, (cint)string_self);
  string_id = t80;
  t81 = (cptr)(((cptr)(((cptr)string_id)[0]))[126]); /* Import_into*/
  ((f0)t81)((cint)string_id, (cint)string_scop);
  t78_label: return t78;
}

cint string_less_than(cint string_self, cint string_s){
  cint string_result, string_i, string_ch1, string_ch2, string_j;
  cint t82, t83, t84, t85, t86, t87, t89, t90, t91, t92, t93, t94, t95, t96, t97;
  t83 = ((cptr)string_s)[4] /* class_of*/ != strpool_str_6;
  if (t83){
    t82 = 0;
    goto t82_label;
  };
  t84 = ((cptr)(((cptr)string_s)[0]))[37];
  t85 = ((f0)t84)((cint)string_s, (cint)string_self); /* equal*/
  t86 = t85 == 1;
  if (t86){
    t82 = 0;
    goto t82_label;
  };
  string_i = ((cptr)string_self)[3] /* len*/;
  t87 = string_i > ((cptr)string_s)[3] /* len*/;
  if (t87){
    string_i = ((cptr)string_s)[3] /* len*/;
  };
  for (string_j = 1; string_j <= string_i; string_j++){
    t89 = ((cptr)(((cptr)string_self)[0]))[63];
    t90 = ((f0)t89)((cint)string_self, (cint)string_j); /* lookup_as_cint*/
    string_ch1 = t90;
    t92 = ((cptr)(((cptr)string_s)[0]))[63];
    t93 = ((f0)t92)((cint)string_s, (cint)string_j); /* lookup_as_cint*/
    string_ch2 = t93;
    t95 = string_ch1 < string_ch2;
    if (t95){
      t82 = 1;
      goto t82_label;
    };
    t96 = string_ch1 > string_ch2;
    if (t96){
      t82 = 0;
      goto t82_label;
    };
  };t88:;
  t97 = string_i < ((cptr)string_s)[3] /* len*/;
  if (t97){
    t82 = 1;
    goto t82_label;
  };
  t82 = 0;
  goto t82_label;
  t82_label: return t82;
}

cint string_Locase(cint string_self){
  cint string_result, string_buf, string_i, string_ch;
  cint t98, t99, t101, t102, t103, t104, t105, t106, t107, t108, t109, t110;
  t99 = ((cptr)string_self)[3] /* len*/ + 1;
  string_buf = cstring_mem_malloc((cint)t99);
  for (string_i = 1; string_i <= ((cptr)string_self)[3] /* len*/; string_i++){
    t101 = ((cptr)(((cptr)string_self)[0]))[63];
    t102 = ((f0)t101)((cint)string_self, (cint)string_i); /* lookup_as_cint*/
    string_ch = t102;
    t104 = string_ch >= 65;
    t105 = t104;
    if (t105){
      t106 = string_ch <= 90;
      t105 = t106;
    };
    if (t105){
      t107 = string_ch + 32;
      string_ch = t107;
    };
    t108 = string_i - 1;
    cstring_update_char((cint)string_buf, (cint)t108, (cint)string_ch);
  };t100:;
  cstring_update_char((cint)string_buf, (cint)((cptr)string_self)[3] /* len*/, (cint)0);
  t109 = mem_malloc(40); ((cptr)t109)[0] = sstring_methods;
  t110 = sstring_alloc((cint)t109, (cint)string_buf);
  string_result = t110;
  object_Dec_ref(string_self);
  t98 = string_result;
  goto t98_label;
  t98_label: return t98;
}

cint string_lookup_as_cint(cint string_self, cint string_i){
  cint string_result;
  cint t111, t112, t113, t114;
  t112 = ((cptr)(((cptr)string_self)[0]))[62];
  t113 = ((f0)t112)((cint)string_self, (cint)string_i); /* lookup*/
  t111 = ((cptr)t113)[2] /* hashval*/;
  goto t111_label;
  t111_label: return t111;
}

cint string_Mknum(cint string_self){
  cint string_result, string_has_point, string_has_exponent, string_has_minus, string_has_digit, string_buf, string_i, string_ch;
  cint t115, t116, t117, t118, t119, t120, t123, t124, t125, t126, t127, t128, t129, t130, t131, t132, t133, t134, t135, t136, t137, t138, t139, t140, t141, t142, t143, t144, t145, t146, t147, t148, t149, t150, t151, t152, t153, t154;
  t116 = ((cptr)string_self)[3] /* len*/ == 0;
  if (t116){
    object_Dec_ref(string_self);
    t115 = object_Undefined;
    goto t115_label;
  };
  string_has_point = 0;
  string_has_exponent = 0;
  string_has_minus = 0;
  string_has_digit = 0;
  t117 = ((cptr)string_self)[3] /* len*/ + 1;
  string_buf = cstring_mem_malloc((cint)t117);
  t118 = ((cptr)(((cptr)string_self)[0]))[63];
  t119 = ((f0)t118)((cint)string_self, (cint)1); /* lookup_as_cint*/
  t120 = t119 != 45;
  if (t120){
    string_i = 1;
  }else{
    cstring_update_char((cint)string_buf, (cint)0, (cint)45);
    string_i = 2;
  };
  t121:
  t123 = string_i <= ((cptr)string_self)[3] /* len*/;
  if (!t123) goto t122;
    t124 = ((cptr)(((cptr)string_self)[0]))[63];
    t125 = ((f0)t124)((cint)string_self, (cint)string_i); /* lookup_as_cint*/
    string_ch = t125;
    t127 = string_ch == 46;
    t128 = t127;
    if (t128){
      t129 = string_has_point == 0;
      t128 = t129;
    };
    t130 = t128;
    if (t130){
      t131 = string_has_exponent == 0;
      t130 = t131;
    };
    if (t130){
      string_has_point = 1;
    }else{
    t132 = string_ch == 69;
    t133 = t132;
    if (!t133){      t134 = string_ch == 101;
      t133 = t134;
    };
    t135 = t133;
    if (t135){
      t136 = string_has_exponent == 0;
      t135 = t136;
    };
    if (t135){
      string_has_exponent = 1;
    }else{
    t137 = string_ch == 45;
    t138 = t137;
    if (t138){
      t139 = string_has_exponent == 1;
      t138 = t139;
    };
    t140 = t138;
    if (t140){
      t141 = string_has_minus == 0;
      t140 = t141;
    };
    if (t140){
      string_has_minus = 1;
    }else{
    t142 = 48 <= string_ch;
    t143 = t142;
    if (t143){
      t144 = string_ch <= 57;
      t143 = t144;
    };
    if (t143){
      string_has_digit = 1;
    }else{
      cstring_mem_free((cint)string_buf);
      object_Dec_ref(string_self);
      t115 = object_Undefined;
      goto t115_label;
    };};};};
    t145 = string_i - 1;
    cstring_update_char((cint)string_buf, (cint)t145, (cint)string_ch);
    t146 = string_i + 1;
    string_i = t146;
  goto t121;
  t122:;
  t147 = string_has_digit == 0;
  if (t147){
    cstring_mem_free((cint)string_buf);
    object_Dec_ref(string_self);
    t115 = object_Undefined;
    goto t115_label;
  };
  cstring_update_char((cint)string_buf, (cint)((cptr)string_self)[3] /* len*/, (cint)0);
  t148 = string_has_point == 1;
  t149 = t148;
  if (!t149){    t150 = string_has_exponent == 1;
    t149 = t150;
  };
  if (t149){
    t151 = mem_malloc(32); ((cptr)t151)[0] = float_methods;
    t152 = float_alloc((cint)t151, (cint)string_buf);
    string_result = t152;
  }else{
    t153 = mem_malloc(28); ((cptr)t153)[0] = integer_methods;
    t154 = integer_alloc((cint)t153, (cint)string_buf);
    string_result = t154;
  };
  cstring_mem_free((cint)string_buf);
  object_Dec_ref(string_self);
  t115 = string_result;
  goto t115_label;
  t115_label: return t115;
}

cint string_Mkstr(cint string_self){
  cint string_result;
  cint t155, t156, t157, t158, t159, t160, t161, t162, t163, t164;
  ((cptr)character_open_quote)[1] += 1;
  t156 = ((cptr)(((cptr)string_self)[0]))[112];
  t157 = ((f0)t156)((cint)string_self); /* ubstr*/
  t158 = ((cptr)(((cptr)character_open_quote)[0]))[97];
  t159 = ((f0)t158)((cint)character_open_quote, (cint)t157); /* Plus*/
  ((cptr)character_close_quote)[1] += 1;
  t162 = ((cptr)(((cptr)t159)[0]))[97];
  t163 = ((f0)t162)((cint)t159, (cint)character_close_quote); /* Plus*/
  t155 = t163;
  goto t155_label;
  t155_label: return t155;
}

cint string_Plus(cint string_self, cint string_ob){
  cint string_result;
  cint t165, t166, t167, t168, t169, t170, t171, t172, t173, t174;
  t166 = ((cptr)string_self)[3] /* len*/ == 0;
  t167 = t166;
  if (t167){
    t168 = ((cptr)string_ob)[4] /* class_of*/ == strpool_str_6;
    t167 = t168;
  };
  if (t167){
    object_Dec_ref(string_self);
    t165 = string_ob;
    goto t165_label;
  };
  t169 = ((cptr)string_ob)[3] /* len*/ == 0;
  t170 = t169;
  if (t170){
    t171 = ((cptr)string_ob)[4] /* class_of*/ == strpool_str_6;
    t170 = t171;
  };
  if (t170){
    object_Dec_ref(string_ob);
    t165 = string_self;
    goto t165_label;
  };
  t172 = ((cptr)string_ob)[4] /* class_of*/ == strpool_str_6;
  if (t172){
    t173 = mem_malloc(44); ((cptr)t173)[0] = pstring_methods;
    t174 = pstring_alloc((cint)t173, (cint)string_self, (cint)string_ob);
    t165 = t174;
    goto t165_label;
  };
  object_Dec_ref(string_self);
  object_Dec_ref(string_ob);
  t165 = object_Undefined;
  goto t165_label;
  t165_label: return t165;
}

cint string_put_on(cint string_self, cint string_f, cint string_i, cint string_j){
  cint string_k;
  cint t175, t177, t178;
  for (string_k = string_i; string_k <= string_j; string_k++){
    t177 = ((cptr)(((cptr)string_self)[0]))[63];
    t178 = ((f0)t177)((cint)string_self, (cint)string_k); /* lookup_as_cint*/
    cfile_fputc((cint)t178, (cint)string_f);
  };t176:;
  t175_label: return t175;
}

cint string_Tail(cint string_self){
  cint string_result;
  cint t179, t180, t181, t182, t183;
  t180 = ((cptr)string_self)[3] /* len*/ == 0;
  if (t180){
    object_Dec_ref(string_self);
    t179 = object_Undefined;
    goto t179_label;
  };
  t181 = ((cptr)string_self)[3] /* len*/ == 1;
  if (t181){
    object_Dec_ref(string_self);
    ((cptr)strpool_str_33)[1] += 1;
    t179 = strpool_str_33;
    goto t179_label;
  };
  t182 = mem_malloc(48); ((cptr)t182)[0] = slicestr_methods;
  t183 = slicestr_alloc((cint)t182, (cint)string_self, (cint)2, (cint)((cptr)string_self)[3] /* len*/);
  t179 = t183;
  goto t179_label;
  t179_label: return t179;
}

cint string_Upcase(cint string_self){
  cint string_result, string_buf, string_i, string_ch;
  cint t184, t185, t187, t188, t189, t190, t191, t192, t193, t194, t195, t196;
  t185 = ((cptr)string_self)[3] /* len*/ + 1;
  string_buf = cstring_mem_malloc((cint)t185);
  for (string_i = 1; string_i <= ((cptr)string_self)[3] /* len*/; string_i++){
    t187 = ((cptr)(((cptr)string_self)[0]))[63];
    t188 = ((f0)t187)((cint)string_self, (cint)string_i); /* lookup_as_cint*/
    string_ch = t188;
    t190 = string_ch >= 97;
    t191 = t190;
    if (t191){
      t192 = string_ch <= 122;
      t191 = t192;
    };
    if (t191){
      t193 = string_ch - 32;
      string_ch = t193;
    };
    t194 = string_i - 1;
    cstring_update_char((cint)string_buf, (cint)t194, (cint)string_ch);
  };t186:;
  cstring_update_char((cint)string_buf, (cint)((cptr)string_self)[3] /* len*/, (cint)0);
  t195 = mem_malloc(40); ((cptr)t195)[0] = sstring_methods;
  t196 = sstring_alloc((cint)t195, (cint)string_buf);
  string_result = t196;
  object_Dec_ref(string_self);
  t184 = string_result;
  goto t184_label;
  t184_label: return t184;
}

cint string_ubstr(cint string_self){
  cint string_result;
  cint t197;
  ((cptr)string_self)[1] += 1;
  t197 = string_self;
  goto t197_label;
  t197_label: return t197;
}

cint string_update(cint string_self, cint string_i, cint string_ch){
  cint string_result;
  cint t198;
  t198 = string_self;
  goto t198_label;
  t198_label: return t198;
}

void init_string(){
  copy_meth_table(string_methods, collection_methods);
  string_methods[0] = 36;
  string_methods[3] = string_alloc;
  string_methods[4] = string_reclaim;
  string_methods[10] = string_Apply_indirect;
  string_methods[6] = string_All_but_last;
  string_methods[7] = string_Append;
  string_methods[366] = string_as_string;
  string_methods[15] = string_Assign_to_component;
  string_methods[29] = string_Delete_ith;
  string_methods[37] = string_equal;
  string_methods[49] = string_Import;
  string_methods[126] = string_Import_into;
  string_methods[60] = string_less_than;
  string_methods[127] = string_Locase;
  string_methods[63] = string_lookup_as_cint;
  string_methods[87] = string_Mknum;
  string_methods[88] = string_Mkstr;
  string_methods[97] = string_Plus;
  string_methods[128] = string_put_on;
  string_methods[106] = string_Tail;
  string_methods[129] = string_Upcase;
  string_methods[112] = string_ubstr;
  string_methods[130] = string_update;
}
