PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/cyclone-0.9/bin/genfiles/string.c

https://bitbucket.org/mirrorbot/cyclone-full
C | 1007 lines | 947 code | 33 blank | 27 comment | 129 complexity | b01a7784fdcf5ec40e3654372cfd0d8f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0, BSD-3-Clause
  1. #include <setjmp.h>
  2. /* This is a C header used by the output of the Cyclone to
  3. C translator. Corresponding definitions are in file lib/runtime_*.c */
  4. #ifndef _CYC_INCLUDE_H_
  5. #define _CYC_INCLUDE_H_
  6. /* Need one of these per thread (see runtime_stack.c). The runtime maintains
  7. a stack that contains either _handler_cons structs or _RegionHandle structs.
  8. The tag is 0 for a handler_cons and 1 for a region handle. */
  9. struct _RuntimeStack {
  10. int tag;
  11. struct _RuntimeStack *next;
  12. void (*cleanup)(struct _RuntimeStack *frame);
  13. };
  14. #ifndef offsetof
  15. /* should be size_t but int is fine */
  16. #define offsetof(t,n) ((int)(&(((t*)0)->n)))
  17. #endif
  18. /* Fat pointers */
  19. struct _fat_ptr {
  20. unsigned char *curr;
  21. unsigned char *base;
  22. unsigned char *last_plus_one;
  23. };
  24. /* Regions */
  25. struct _RegionPage
  26. {
  27. #ifdef CYC_REGION_PROFILE
  28. unsigned total_bytes;
  29. unsigned free_bytes;
  30. #endif
  31. struct _RegionPage *next;
  32. char data[1];
  33. };
  34. struct _pool;
  35. struct bget_region_key;
  36. struct _RegionAllocFunctions;
  37. struct _RegionHandle {
  38. struct _RuntimeStack s;
  39. struct _RegionPage *curr;
  40. #if(defined(__linux__) && defined(__KERNEL__))
  41. struct _RegionPage *vpage;
  42. #endif
  43. struct _RegionAllocFunctions *fcns;
  44. char *offset;
  45. char *last_plus_one;
  46. struct _pool *released_ptrs;
  47. struct bget_region_key *key;
  48. #ifdef CYC_REGION_PROFILE
  49. const char *name;
  50. #endif
  51. unsigned used_bytes;
  52. unsigned wasted_bytes;
  53. };
  54. // A dynamic region is just a region handle. The wrapper struct is for type
  55. // abstraction.
  56. struct Cyc_Core_DynamicRegion {
  57. struct _RegionHandle h;
  58. };
  59. /* Alias qualifier stuff */
  60. typedef unsigned int _AliasQualHandle_t; // must match aqualt_type() in toc.cyc
  61. struct _RegionHandle _new_region(unsigned int, const char*);
  62. void* _region_malloc(struct _RegionHandle*, _AliasQualHandle_t, unsigned);
  63. void* _region_calloc(struct _RegionHandle*, _AliasQualHandle_t, unsigned t, unsigned n);
  64. void* _region_vmalloc(struct _RegionHandle*, unsigned);
  65. void * _aqual_malloc(_AliasQualHandle_t aq, unsigned int s);
  66. void * _aqual_calloc(_AliasQualHandle_t aq, unsigned int n, unsigned int t);
  67. void _free_region(struct _RegionHandle*);
  68. /* Exceptions */
  69. struct _handler_cons {
  70. struct _RuntimeStack s;
  71. jmp_buf handler;
  72. };
  73. void _push_handler(struct _handler_cons*);
  74. void _push_region(struct _RegionHandle*);
  75. void _npop_handler(int);
  76. void _pop_handler();
  77. void _pop_region();
  78. #ifndef _throw
  79. void* _throw_null_fn(const char*,unsigned);
  80. void* _throw_arraybounds_fn(const char*,unsigned);
  81. void* _throw_badalloc_fn(const char*,unsigned);
  82. void* _throw_match_fn(const char*,unsigned);
  83. void* _throw_fn(void*,const char*,unsigned);
  84. void* _rethrow(void*);
  85. #define _throw_null() (_throw_null_fn(__FILE__,__LINE__))
  86. #define _throw_arraybounds() (_throw_arraybounds_fn(__FILE__,__LINE__))
  87. #define _throw_badalloc() (_throw_badalloc_fn(__FILE__,__LINE__))
  88. #define _throw_match() (_throw_match_fn(__FILE__,__LINE__))
  89. #define _throw(e) (_throw_fn((e),__FILE__,__LINE__))
  90. #endif
  91. void* Cyc_Core_get_exn_thrown();
  92. /* Built-in Exceptions */
  93. struct Cyc_Null_Exception_exn_struct { char *tag; };
  94. struct Cyc_Array_bounds_exn_struct { char *tag; };
  95. struct Cyc_Match_Exception_exn_struct { char *tag; };
  96. struct Cyc_Bad_alloc_exn_struct { char *tag; };
  97. extern char Cyc_Null_Exception[];
  98. extern char Cyc_Array_bounds[];
  99. extern char Cyc_Match_Exception[];
  100. extern char Cyc_Bad_alloc[];
  101. /* Built-in Run-time Checks and company */
  102. #ifdef NO_CYC_NULL_CHECKS
  103. #define _check_null(ptr) (ptr)
  104. #else
  105. #define _check_null(ptr) \
  106. ({ typeof(ptr) _cks_null = (ptr); \
  107. if (!_cks_null) _throw_null(); \
  108. _cks_null; })
  109. #endif
  110. #ifdef NO_CYC_BOUNDS_CHECKS
  111. #define _check_known_subscript_notnull(ptr,bound,elt_sz,index)\
  112. (((char*)ptr) + (elt_sz)*(index))
  113. #ifdef NO_CYC_NULL_CHECKS
  114. #define _check_known_subscript_null _check_known_subscript_notnull
  115. #else
  116. #define _check_known_subscript_null(ptr,bound,elt_sz,index) ({ \
  117. char*_cks_ptr = (char*)(ptr);\
  118. int _index = (index);\
  119. if (!_cks_ptr) _throw_null(); \
  120. _cks_ptr + (elt_sz)*_index; })
  121. #endif
  122. #define _zero_arr_plus_char_fn(orig_x,orig_sz,orig_i,f,l) ((orig_x)+(orig_i))
  123. #define _zero_arr_plus_other_fn(t_sz,orig_x,orig_sz,orig_i,f,l)((orig_x)+(orig_i))
  124. #else
  125. #define _check_known_subscript_null(ptr,bound,elt_sz,index) ({ \
  126. char*_cks_ptr = (char*)(ptr); \
  127. unsigned _cks_index = (index); \
  128. if (!_cks_ptr) _throw_null(); \
  129. if (_cks_index >= (bound)) _throw_arraybounds(); \
  130. _cks_ptr + (elt_sz)*_cks_index; })
  131. #define _check_known_subscript_notnull(ptr,bound,elt_sz,index) ({ \
  132. char*_cks_ptr = (char*)(ptr); \
  133. unsigned _cks_index = (index); \
  134. if (_cks_index >= (bound)) _throw_arraybounds(); \
  135. _cks_ptr + (elt_sz)*_cks_index; })
  136. /* _zero_arr_plus_*_fn(x,sz,i,filename,lineno) adds i to zero-terminated ptr
  137. x that has at least sz elements */
  138. char* _zero_arr_plus_char_fn(char*,unsigned,int,const char*,unsigned);
  139. void* _zero_arr_plus_other_fn(unsigned,void*,unsigned,int,const char*,unsigned);
  140. #endif
  141. /* _get_zero_arr_size_*(x,sz) returns the number of elements in a
  142. zero-terminated array that is NULL or has at least sz elements */
  143. unsigned _get_zero_arr_size_char(const char*,unsigned);
  144. unsigned _get_zero_arr_size_other(unsigned,const void*,unsigned);
  145. /* _zero_arr_inplace_plus_*_fn(x,i,filename,lineno) sets
  146. zero-terminated pointer *x to *x + i */
  147. char* _zero_arr_inplace_plus_char_fn(char**,int,const char*,unsigned);
  148. char* _zero_arr_inplace_plus_post_char_fn(char**,int,const char*,unsigned);
  149. // note: must cast result in toc.cyc
  150. void* _zero_arr_inplace_plus_other_fn(unsigned,void**,int,const char*,unsigned);
  151. void* _zero_arr_inplace_plus_post_other_fn(unsigned,void**,int,const char*,unsigned);
  152. #define _zero_arr_plus_char(x,s,i) \
  153. (_zero_arr_plus_char_fn(x,s,i,__FILE__,__LINE__))
  154. #define _zero_arr_inplace_plus_char(x,i) \
  155. _zero_arr_inplace_plus_char_fn((char**)(x),i,__FILE__,__LINE__)
  156. #define _zero_arr_inplace_plus_post_char(x,i) \
  157. _zero_arr_inplace_plus_post_char_fn((char**)(x),(i),__FILE__,__LINE__)
  158. #define _zero_arr_plus_other(t,x,s,i) \
  159. (_zero_arr_plus_other_fn(t,x,s,i,__FILE__,__LINE__))
  160. #define _zero_arr_inplace_plus_other(t,x,i) \
  161. _zero_arr_inplace_plus_other_fn(t,(void**)(x),i,__FILE__,__LINE__)
  162. #define _zero_arr_inplace_plus_post_other(t,x,i) \
  163. _zero_arr_inplace_plus_post_other_fn(t,(void**)(x),(i),__FILE__,__LINE__)
  164. #ifdef NO_CYC_BOUNDS_CHECKS
  165. #define _check_fat_subscript(arr,elt_sz,index) ((arr).curr + (elt_sz) * (index))
  166. #define _untag_fat_ptr(arr,elt_sz,num_elts) ((arr).curr)
  167. #define _check_fat_at_base(arr) (arr)
  168. #else
  169. #define _check_fat_subscript(arr,elt_sz,index) ({ \
  170. struct _fat_ptr _cus_arr = (arr); \
  171. unsigned char *_cus_ans = _cus_arr.curr + (elt_sz) * (index); \
  172. /* JGM: not needed! if (!_cus_arr.base) _throw_null();*/ \
  173. if (_cus_ans < _cus_arr.base || _cus_ans >= _cus_arr.last_plus_one) \
  174. _throw_arraybounds(); \
  175. _cus_ans; })
  176. #define _untag_fat_ptr(arr,elt_sz,num_elts) ({ \
  177. struct _fat_ptr _arr = (arr); \
  178. unsigned char *_curr = _arr.curr; \
  179. if ((_curr < _arr.base || _curr + (elt_sz) * (num_elts) > _arr.last_plus_one) &&\
  180. _curr != (unsigned char*)0) \
  181. _throw_arraybounds(); \
  182. _curr; })
  183. #define _check_fat_at_base(arr) ({ \
  184. struct _fat_ptr _arr = (arr); \
  185. if (_arr.base != _arr.curr) _throw_arraybounds(); \
  186. _arr; })
  187. #endif
  188. #define _tag_fat(tcurr,elt_sz,num_elts) ({ \
  189. struct _fat_ptr _ans; \
  190. unsigned _num_elts = (num_elts);\
  191. _ans.base = _ans.curr = (void*)(tcurr); \
  192. /* JGM: if we're tagging NULL, ignore num_elts */ \
  193. _ans.last_plus_one = _ans.base ? (_ans.base + (elt_sz) * _num_elts) : 0; \
  194. _ans; })
  195. #define _get_fat_size(arr,elt_sz) \
  196. ({struct _fat_ptr _arr = (arr); \
  197. unsigned char *_arr_curr=_arr.curr; \
  198. unsigned char *_arr_last=_arr.last_plus_one; \
  199. (_arr_curr < _arr.base || _arr_curr >= _arr_last) ? 0 : \
  200. ((_arr_last - _arr_curr) / (elt_sz));})
  201. #define _fat_ptr_plus(arr,elt_sz,change) ({ \
  202. struct _fat_ptr _ans = (arr); \
  203. int _change = (change);\
  204. _ans.curr += (elt_sz) * _change;\
  205. _ans; })
  206. #define _fat_ptr_inplace_plus(arr_ptr,elt_sz,change) ({ \
  207. struct _fat_ptr * _arr_ptr = (arr_ptr); \
  208. _arr_ptr->curr += (elt_sz) * (change);\
  209. *_arr_ptr; })
  210. #define _fat_ptr_inplace_plus_post(arr_ptr,elt_sz,change) ({ \
  211. struct _fat_ptr * _arr_ptr = (arr_ptr); \
  212. struct _fat_ptr _ans = *_arr_ptr; \
  213. _arr_ptr->curr += (elt_sz) * (change);\
  214. _ans; })
  215. //Not a macro since initialization order matters. Defined in runtime_zeroterm.c.
  216. struct _fat_ptr _fat_ptr_decrease_size(struct _fat_ptr,unsigned sz,unsigned numelts);
  217. #ifdef CYC_GC_PTHREAD_REDIRECTS
  218. # define pthread_create GC_pthread_create
  219. # define pthread_sigmask GC_pthread_sigmask
  220. # define pthread_join GC_pthread_join
  221. # define pthread_detach GC_pthread_detach
  222. # define dlopen GC_dlopen
  223. #endif
  224. /* Allocation */
  225. void* GC_malloc(int);
  226. void* GC_malloc_atomic(int);
  227. void* GC_calloc(unsigned,unsigned);
  228. void* GC_calloc_atomic(unsigned,unsigned);
  229. #if(defined(__linux__) && defined(__KERNEL__))
  230. void *cyc_vmalloc(unsigned);
  231. void cyc_vfree(void*);
  232. #endif
  233. // bound the allocation size to be < MAX_ALLOC_SIZE. See macros below for usage.
  234. #define MAX_MALLOC_SIZE (1 << 28)
  235. void* _bounded_GC_malloc(int,const char*,int);
  236. void* _bounded_GC_malloc_atomic(int,const char*,int);
  237. void* _bounded_GC_calloc(unsigned,unsigned,const char*,int);
  238. void* _bounded_GC_calloc_atomic(unsigned,unsigned,const char*,int);
  239. /* these macros are overridden below ifdef CYC_REGION_PROFILE */
  240. #ifndef CYC_REGION_PROFILE
  241. #define _cycalloc(n) _bounded_GC_malloc(n,__FILE__,__LINE__)
  242. #define _cycalloc_atomic(n) _bounded_GC_malloc_atomic(n,__FILE__,__LINE__)
  243. #define _cyccalloc(n,s) _bounded_GC_calloc(n,s,__FILE__,__LINE__)
  244. #define _cyccalloc_atomic(n,s) _bounded_GC_calloc_atomic(n,s,__FILE__,__LINE__)
  245. #endif
  246. static inline unsigned int _check_times(unsigned x, unsigned y) {
  247. unsigned long long whole_ans =
  248. ((unsigned long long) x)*((unsigned long long)y);
  249. unsigned word_ans = (unsigned)whole_ans;
  250. if(word_ans < whole_ans || word_ans > MAX_MALLOC_SIZE)
  251. _throw_badalloc();
  252. return word_ans;
  253. }
  254. #define _CYC_MAX_REGION_CONST 0
  255. #define _CYC_MIN_ALIGNMENT (sizeof(double))
  256. #ifdef CYC_REGION_PROFILE
  257. extern int rgn_total_bytes;
  258. #endif
  259. static inline void*_fast_region_malloc(struct _RegionHandle*r, _AliasQualHandle_t aq, unsigned orig_s) {
  260. if (r > (struct _RegionHandle*)_CYC_MAX_REGION_CONST && r->curr != 0) {
  261. #ifdef CYC_NOALIGN
  262. unsigned s = orig_s;
  263. #else
  264. unsigned s = (orig_s + _CYC_MIN_ALIGNMENT - 1) & (~(_CYC_MIN_ALIGNMENT -1));
  265. #endif
  266. char *result;
  267. result = r->offset;
  268. if (s <= (r->last_plus_one - result)) {
  269. r->offset = result + s;
  270. #ifdef CYC_REGION_PROFILE
  271. r->curr->free_bytes = r->curr->free_bytes - s;
  272. rgn_total_bytes += s;
  273. #endif
  274. return result;
  275. }
  276. }
  277. return _region_malloc(r,aq,orig_s);
  278. }
  279. //doesn't make sense to fast malloc with reaps
  280. #ifndef DISABLE_REAPS
  281. #define _fast_region_malloc _region_malloc
  282. #endif
  283. #ifdef CYC_REGION_PROFILE
  284. /* see macros below for usage. defined in runtime_memory.c */
  285. void* _profile_GC_malloc(int,const char*,const char*,int);
  286. void* _profile_GC_malloc_atomic(int,const char*,const char*,int);
  287. void* _profile_GC_calloc(unsigned,unsigned,const char*,const char*,int);
  288. void* _profile_GC_calloc_atomic(unsigned,unsigned,const char*,const char*,int);
  289. void* _profile_region_malloc(struct _RegionHandle*,_AliasQualHandle_t,unsigned,const char*,const char*,int);
  290. void* _profile_region_calloc(struct _RegionHandle*,_AliasQualHandle_t,unsigned,unsigned,const char *,const char*,int);
  291. void * _profile_aqual_malloc(_AliasQualHandle_t aq, unsigned int s,const char *file, const char *func, int lineno);
  292. void * _profile_aqual_calloc(_AliasQualHandle_t aq, unsigned int t1,unsigned int t2,const char *file, const char *func, int lineno);
  293. struct _RegionHandle _profile_new_region(unsigned int i, const char*,const char*,const char*,int);
  294. void _profile_free_region(struct _RegionHandle*,const char*,const char*,int);
  295. #ifndef RUNTIME_CYC
  296. #define _new_region(i,n) _profile_new_region(i,n,__FILE__,__FUNCTION__,__LINE__)
  297. #define _free_region(r) _profile_free_region(r,__FILE__,__FUNCTION__,__LINE__)
  298. #define _region_malloc(rh,aq,n) _profile_region_malloc(rh,aq,n,__FILE__,__FUNCTION__,__LINE__)
  299. #define _region_calloc(rh,aq,n,t) _profile_region_calloc(rh,aq,n,t,__FILE__,__FUNCTION__,__LINE__)
  300. #define _aqual_malloc(aq,n) _profile_aqual_malloc(aq,n,__FILE__,__FUNCTION__,__LINE__)
  301. #define _aqual_calloc(aq,n,t) _profile_aqual_calloc(aq,n,t,__FILE__,__FUNCTION__,__LINE__)
  302. #endif
  303. #define _cycalloc(n) _profile_GC_malloc(n,__FILE__,__FUNCTION__,__LINE__)
  304. #define _cycalloc_atomic(n) _profile_GC_malloc_atomic(n,__FILE__,__FUNCTION__,__LINE__)
  305. #define _cyccalloc(n,s) _profile_GC_calloc(n,s,__FILE__,__FUNCTION__,__LINE__)
  306. #define _cyccalloc_atomic(n,s) _profile_GC_calloc_atomic(n,s,__FILE__,__FUNCTION__,__LINE__)
  307. #endif //CYC_REGION_PROFILE
  308. #endif //_CYC_INCLUDE_H
  309. # 95 "core.h"
  310. struct _fat_ptr Cyc_Core_new_string(unsigned);
  311. # 99
  312. struct _fat_ptr Cyc_Core_rnew_string(struct _RegionHandle*,unsigned);
  313. # 103
  314. struct _fat_ptr Cyc_Core_rqnew_string(struct _RegionHandle*,unsigned,unsigned);extern char Cyc_Core_Invalid_argument[17U];struct Cyc_Core_Invalid_argument_exn_struct{char*tag;struct _fat_ptr f1;};
  315. # 170
  316. extern struct _RegionHandle*Cyc_Core_heap_region;
  317. # 364 "core.h"
  318. struct _fat_ptr Cyc_Core_mkfat(void*,unsigned,unsigned);struct Cyc_List_List{void*hd;struct Cyc_List_List*tl;};
  319. # 61 "list.h"
  320. extern int Cyc_List_length(struct Cyc_List_List*);
  321. # 310 "cycboot.h"
  322. extern int toupper(int);
  323. # 72 "string.h"
  324. struct _fat_ptr Cyc_strncpy(struct _fat_ptr,struct _fat_ptr,unsigned long);
  325. # 105 "string.h"
  326. struct _fat_ptr Cyc_rstrdup(struct _RegionHandle*,struct _fat_ptr);
  327. # 29 "assert.h"
  328. extern void*Cyc___assert_fail(struct _fat_ptr,struct _fat_ptr,unsigned);
  329. # 37 "string.cyc"
  330. unsigned long Cyc_strlen(struct _fat_ptr s){
  331. # 39
  332. unsigned long i;
  333. unsigned sz=_get_fat_size(s,sizeof(char));
  334. for(i=0U;1 && i < sz;++ i){
  335. if((int)((const char*)s.curr)[(int)i]==0)
  336. return i;}
  337. return i;}
  338. # 47
  339. inline static unsigned Cyc_umin(unsigned i,unsigned j){
  340. # 49
  341. if(i < j)return i;else{return j;}}
  342. # 51
  343. inline static unsigned Cyc_umax(unsigned i,unsigned j){
  344. # 53
  345. if(i > j)return i;else{return j;}}
  346. # 59
  347. int Cyc_strcmp(struct _fat_ptr s1,struct _fat_ptr s2){
  348. if((char*)s1.curr==(char*)s2.curr)
  349. return 0;{
  350. int i=0;
  351. unsigned sz1=_get_fat_size(s1,sizeof(char));
  352. unsigned sz2=_get_fat_size(s2,sizeof(char));
  353. unsigned minsz=Cyc_umin(sz1,sz2);
  354. # 67
  355. for(1;1 &&(unsigned)i < minsz;++ i){
  356. char c1=((const char*)s1.curr)[i];
  357. char c2=((const char*)s2.curr)[i];
  358. if((int)c1==0)
  359. return(int)c2==0?0: -1;
  360. if((int)c2==0)return 1;{
  361. int diff=(int)c1 - (int)c2;
  362. if(diff!=0)return diff;}}
  363. # 76
  364. if(sz1==sz2)return 0;
  365. if(sz1 < sz2)return(int)((const char*)s2.curr)[i]==0?0: -1;
  366. 1;
  367. return(int)((const char*)s1.curr)[i]==0?0: 1;}}
  368. # 82
  369. int Cyc_strptrcmp(struct _fat_ptr*s1,struct _fat_ptr*s2){
  370. return Cyc_strcmp(*s1,*s2);}
  371. # 86
  372. inline static int Cyc_ncmp(struct _fat_ptr s1,unsigned long len1,struct _fat_ptr s2,unsigned long len2,unsigned long n){
  373. # 89
  374. if(n <= 0U)return 0;{
  375. # 91
  376. unsigned long min_len=Cyc_umin(len1,len2);
  377. unsigned long bound=Cyc_umin(min_len,n);
  378. # 94
  379. {unsigned i=0U;for(0;i < bound;++ i){
  380. int retc;
  381. if((retc=(int)((const char*)s1.curr)[(int)i]- (int)((const char*)s2.curr)[(int)i])!=0)
  382. return retc;}}
  383. # 99
  384. if(len1 < n || len2 < n)
  385. return(int)len1 - (int)len2;
  386. return 0;}}
  387. # 106
  388. int Cyc_strncmp(struct _fat_ptr s1,struct _fat_ptr s2,unsigned long n){
  389. unsigned long len1=Cyc_strlen(s1);
  390. unsigned long len2=Cyc_strlen(s2);
  391. 1;
  392. return Cyc_ncmp(s1,len1,s2,len2,n);}
  393. # 117
  394. int Cyc_zstrcmp(struct _fat_ptr a,struct _fat_ptr b){
  395. if((char*)a.curr==(char*)b.curr)
  396. return 0;{
  397. unsigned long as=_get_fat_size(a,sizeof(char));
  398. unsigned long bs=_get_fat_size(b,sizeof(char));
  399. unsigned long min_length=Cyc_umin(as,bs);
  400. int i=-1;
  401. # 125
  402. 1;
  403. # 127
  404. while((++ i,(unsigned long)i < min_length)){
  405. int diff=(int)((const char*)a.curr)[i]- (int)((const char*)b.curr)[i];
  406. if(diff!=0)
  407. return diff;}
  408. # 132
  409. return(int)as - (int)bs;}}
  410. # 135
  411. int Cyc_zstrncmp(struct _fat_ptr s1,struct _fat_ptr s2,unsigned long n){
  412. if(n <= 0U)return 0;{
  413. # 138
  414. unsigned long s1size=_get_fat_size(s1,sizeof(char));
  415. unsigned long s2size=_get_fat_size(s2,sizeof(char));
  416. unsigned long min_size=Cyc_umin(s1size,s2size);
  417. unsigned long bound=Cyc_umin(n,min_size);
  418. # 143
  419. 1;
  420. # 145
  421. {int i=0;for(0;(unsigned long)i < bound;++ i){
  422. if((int)((const char*)s1.curr)[i]< (int)((const char*)s2.curr)[i])
  423. return -1;
  424. if((int)((const char*)s2.curr)[i]< (int)((const char*)s1.curr)[i])
  425. return 1;}}
  426. # 151
  427. if(min_size <= bound)
  428. return 0;
  429. if(s1size < s2size)
  430. return -1;
  431. return 1;}}
  432. # 159
  433. int Cyc_zstrptrcmp(struct _fat_ptr*a,struct _fat_ptr*b){
  434. if((int)a==(int)b)return 0;
  435. return Cyc_zstrcmp(*a,*b);}
  436. # 169
  437. inline static struct _fat_ptr Cyc_int_strcato(struct _fat_ptr dest,struct _fat_ptr src){
  438. int i;
  439. unsigned long dsize;unsigned long slen;unsigned long dlen;
  440. # 173
  441. dsize=_get_fat_size(dest,sizeof(char));
  442. dlen=Cyc_strlen(dest);
  443. slen=Cyc_strlen(src);
  444. # 177
  445. if(slen + dlen <= dsize){
  446. 1;
  447. for(i=0;(unsigned long)i < slen;++ i){
  448. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(dest,sizeof(char),(int)((unsigned long)i + dlen));char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2=((const char*)src.curr)[i];if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});}
  449. # 182
  450. if((unsigned long)i + dlen < dsize)
  451. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(dest,sizeof(char),(int)((unsigned long)i + dlen));char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2='\000';if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});}else{
  452. # 186
  453. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("strcat",sizeof(char),7U);_Tmp0;}));}
  454. return dest;}
  455. # 192
  456. struct _fat_ptr Cyc_strcat(struct _fat_ptr dest,struct _fat_ptr src){
  457. return Cyc_int_strcato(dest,src);}
  458. # 197
  459. struct _fat_ptr Cyc_rstrconcat(struct _RegionHandle*r,struct _fat_ptr a,struct _fat_ptr b){
  460. unsigned alen=Cyc_strlen(a);
  461. unsigned blen=Cyc_strlen(b);
  462. struct _fat_ptr ans=Cyc_Core_rnew_string(r,(alen + blen)+ 1U);
  463. int i;int j;
  464. alen <= _get_fat_size(ans,sizeof(char))?0:({(int(*)(struct _fat_ptr,struct _fat_ptr,unsigned))Cyc___assert_fail;})(_tag_fat("alen <= numelts(ans)",sizeof(char),21U),_tag_fat("string.cyc",sizeof(char),11U),202U);
  465. 1;
  466. for(i=0;(unsigned)i < alen;++ i){({struct _fat_ptr _Tmp0=_fat_ptr_plus(ans,sizeof(char),i);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2=((const char*)a.curr)[i];if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});}
  467. 1;
  468. for(j=0;(unsigned)j < blen;++ j){({struct _fat_ptr _Tmp0=_fat_ptr_plus(ans,sizeof(char),i + j);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2=((const char*)b.curr)[j];if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});}
  469. return ans;}
  470. # 210
  471. struct _fat_ptr Cyc_strconcat(struct _fat_ptr a,struct _fat_ptr b){
  472. return Cyc_rstrconcat(Cyc_Core_heap_region,a,b);}
  473. # 215
  474. struct _fat_ptr Cyc_rstrconcat_l(struct _RegionHandle*r,struct Cyc_List_List*strs){
  475. # 217
  476. unsigned long len;
  477. unsigned long total_len=0U;
  478. struct _fat_ptr ans;
  479. struct _RegionHandle _Tmp0=_new_region(1U,"temp");struct _RegionHandle*temp=& _Tmp0;_push_region(temp);{
  480. struct Cyc_List_List*lens;
  481. lens=_region_malloc(temp,0U,sizeof(struct Cyc_List_List)),lens->hd=(void*)0U,lens->tl=0;{
  482. # 224
  483. struct Cyc_List_List*end=lens;
  484. {struct Cyc_List_List*p=strs;for(0;p!=0;p=p->tl){
  485. len=Cyc_strlen(*((struct _fat_ptr*)p->hd));
  486. total_len +=len;
  487. ({struct Cyc_List_List*_Tmp1=({struct Cyc_List_List*_Tmp2=_region_malloc(temp,0U,sizeof(struct Cyc_List_List));_Tmp2->hd=(void*)len,_Tmp2->tl=0;_Tmp2;});_check_null(end)->tl=_Tmp1;});
  488. end=end->tl;}}
  489. # 231
  490. lens=lens->tl;
  491. ans=Cyc_Core_rnew_string(r,total_len + 1U);{
  492. unsigned long i=0U;
  493. while(strs!=0){
  494. struct _fat_ptr next=*((struct _fat_ptr*)strs->hd);
  495. len=(unsigned long)_check_null(lens)->hd;
  496. ({struct _fat_ptr _Tmp1=_fat_ptr_decrease_size(_fat_ptr_plus(ans,sizeof(char),(int)i),sizeof(char),1U);struct _fat_ptr _Tmp2=(struct _fat_ptr)next;Cyc_strncpy(_Tmp1,_Tmp2,len);});
  497. i +=len;
  498. strs=strs->tl;
  499. lens=lens->tl;}}}}{
  500. # 243
  501. struct _fat_ptr _Tmp1=ans;_npop_handler(0);return _Tmp1;}
  502. # 220
  503. ;_pop_region();}
  504. # 246
  505. struct _fat_ptr Cyc_strconcat_l(struct Cyc_List_List*strs){
  506. return Cyc_rstrconcat_l(Cyc_Core_heap_region,strs);}
  507. # 252
  508. struct _fat_ptr Cyc_rstr_sepstr(struct _RegionHandle*r,struct Cyc_List_List*strs,struct _fat_ptr separator){
  509. if(strs==0)return Cyc_Core_rnew_string(r,0U);
  510. if(strs->tl==0)return Cyc_rstrdup(r,*((struct _fat_ptr*)strs->hd));{
  511. struct Cyc_List_List*p=strs;
  512. struct _RegionHandle _Tmp0=_new_region(1U,"temp");struct _RegionHandle*temp=& _Tmp0;_push_region(temp);
  513. {struct Cyc_List_List*lens;lens=_region_malloc(temp,0U,sizeof(struct Cyc_List_List)),lens->hd=(void*)0U,lens->tl=0;{
  514. struct Cyc_List_List*end=lens;
  515. unsigned long len;
  516. unsigned long total_len=0U;
  517. unsigned long list_len=0U;
  518. for(1;p!=0;p=p->tl){
  519. len=Cyc_strlen(*((struct _fat_ptr*)p->hd));
  520. total_len +=len;
  521. ({struct Cyc_List_List*_Tmp1=({struct Cyc_List_List*_Tmp2=_region_malloc(temp,0U,sizeof(struct Cyc_List_List));_Tmp2->hd=(void*)len,_Tmp2->tl=0;_Tmp2;});_check_null(end)->tl=_Tmp1;});
  522. end=end->tl;
  523. ++ list_len;}
  524. # 269
  525. lens=lens->tl;{
  526. unsigned long seplen=Cyc_strlen(separator);
  527. total_len +=(list_len - 1U)* seplen;{
  528. struct _fat_ptr ans=Cyc_Core_rnew_string(r,total_len + 1U);
  529. unsigned long i=0U;
  530. while(_check_null(strs)->tl!=0){
  531. struct _fat_ptr next=*((struct _fat_ptr*)strs->hd);
  532. len=(unsigned long)_check_null(lens)->hd;
  533. ({struct _fat_ptr _Tmp1=_fat_ptr_decrease_size(_fat_ptr_plus(ans,sizeof(char),(int)i),sizeof(char),1U);struct _fat_ptr _Tmp2=(struct _fat_ptr)next;Cyc_strncpy(_Tmp1,_Tmp2,len);});
  534. i +=len;
  535. ({struct _fat_ptr _Tmp1=_fat_ptr_decrease_size(_fat_ptr_plus(ans,sizeof(char),(int)i),sizeof(char),1U);struct _fat_ptr _Tmp2=separator;Cyc_strncpy(_Tmp1,_Tmp2,seplen);});
  536. i +=seplen;
  537. strs=strs->tl;
  538. lens=lens->tl;}
  539. # 284
  540. ({struct _fat_ptr _Tmp1=_fat_ptr_decrease_size(_fat_ptr_plus(ans,sizeof(char),(int)i),sizeof(char),1U);struct _fat_ptr _Tmp2=(struct _fat_ptr)*((struct _fat_ptr*)strs->hd);Cyc_strncpy(_Tmp1,_Tmp2,(unsigned long)lens->hd);});{
  541. struct _fat_ptr _Tmp1=ans;_npop_handler(0);return _Tmp1;}}}}}
  542. # 257
  543. ;_pop_region();}}
  544. # 289
  545. struct _fat_ptr Cyc_str_sepstr(struct Cyc_List_List*strs,struct _fat_ptr separator){
  546. return Cyc_rstr_sepstr(Cyc_Core_heap_region,strs,separator);}
  547. # 294
  548. struct _fat_ptr Cyc_strncpy(struct _fat_ptr dest,struct _fat_ptr src,unsigned long n){
  549. int i;
  550. n <= _get_fat_size(dest,sizeof(char))?0:({(int(*)(struct _fat_ptr,struct _fat_ptr,unsigned))Cyc___assert_fail;})(_tag_fat("n <= numelts(dest)",sizeof(char),19U),_tag_fat("string.cyc",sizeof(char),11U),296U);
  551. for(i=0;(unsigned long)i < n;++ i){
  552. char srcChar=*((const char*)_check_fat_subscript(src,sizeof(char),i));
  553. if((int)srcChar==0)break;
  554. ((char*)dest.curr)[i]=srcChar;}
  555. # 302
  556. for(1;(unsigned long)i < n;++ i){
  557. ((char*)dest.curr)[i]='\000';}
  558. # 305
  559. return dest;}
  560. # 309
  561. struct _fat_ptr Cyc_zstrncpy(struct _fat_ptr dest,struct _fat_ptr src,unsigned long n){
  562. n <= _get_fat_size(dest,sizeof(char))&& n <= _get_fat_size(src,sizeof(char))?0:({(int(*)(struct _fat_ptr,struct _fat_ptr,unsigned))Cyc___assert_fail;})(_tag_fat("n <= numelts(dest) && n <= numelts(src)",sizeof(char),40U),_tag_fat("string.cyc",sizeof(char),11U),310U);{
  563. int i;
  564. for(i=0;(unsigned long)i < n;++ i){
  565. ((char*)dest.curr)[i]=((const char*)src.curr)[i];}
  566. return dest;}}
  567. # 317
  568. struct _fat_ptr Cyc_strcpy(struct _fat_ptr dest,struct _fat_ptr src){
  569. unsigned ssz=_get_fat_size(src,sizeof(char));
  570. unsigned dsz=_get_fat_size(dest,sizeof(char));
  571. if(ssz <= dsz){
  572. unsigned i;
  573. for(i=0U;i < ssz;++ i){
  574. char srcChar=((const char*)src.curr)[(int)i];
  575. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(dest,sizeof(char),(int)i);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2=srcChar;if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});
  576. if((int)srcChar==0)break;}}else{
  577. # 329
  578. unsigned long len=Cyc_strlen(src);
  579. ({struct _fat_ptr _Tmp0=_fat_ptr_decrease_size(dest,sizeof(char),1U);struct _fat_ptr _Tmp1=src;Cyc_strncpy(_Tmp0,_Tmp1,len);});
  580. if(len < _get_fat_size(dest,sizeof(char)))
  581. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(dest,sizeof(char),(int)len);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2='\000';if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});}
  582. # 334
  583. return dest;}
  584. # 340
  585. struct _fat_ptr Cyc_rstrdup(struct _RegionHandle*r,struct _fat_ptr src){
  586. unsigned long len;
  587. struct _fat_ptr temp;
  588. # 344
  589. len=Cyc_strlen(src);
  590. temp=Cyc_Core_rnew_string(r,len + 1U);
  591. {struct _fat_ptr temp2=_fat_ptr_decrease_size(temp,sizeof(char),1U);
  592. struct _fat_ptr _Tmp0;_Tmp0=temp2;{struct _fat_ptr dst=_Tmp0;
  593. Cyc_strncpy(dst,src,len);}}
  594. # 350
  595. return temp;}
  596. # 353
  597. struct _fat_ptr Cyc_rqstrdup(struct _RegionHandle*r,unsigned q,struct _fat_ptr src){
  598. unsigned long len=Cyc_strlen(src);
  599. struct _fat_ptr temp=Cyc_Core_rqnew_string(r,q,len + 1U);
  600. {
  601. struct _fat_ptr temp2=_fat_ptr_decrease_size(temp,sizeof(char),1U);
  602. struct _fat_ptr _Tmp0;_Tmp0=temp2;{struct _fat_ptr dst=_Tmp0;
  603. Cyc_strncpy(dst,src,len);}}
  604. # 361
  605. return temp;}
  606. # 364
  607. struct _fat_ptr Cyc_strdup(struct _fat_ptr src){
  608. return Cyc_rstrdup(Cyc_Core_heap_region,src);}
  609. # 368
  610. struct _fat_ptr Cyc_rrealloc(struct _RegionHandle*r,struct _fat_ptr s,unsigned long sz){
  611. struct _fat_ptr temp;
  612. unsigned long slen;
  613. # 372
  614. slen=_get_fat_size(s,sizeof(char));
  615. sz=sz > slen?sz: slen;
  616. temp=({unsigned _Tmp0=sz;_tag_fat(_region_calloc(r,0U,sizeof(char),_Tmp0),sizeof(char),_Tmp0);});
  617. # 376
  618. {struct _fat_ptr _Tmp0;_Tmp0=temp;{struct _fat_ptr dst=_Tmp0;
  619. Cyc_strncpy(dst,s,slen);}}
  620. # 380
  621. return temp;}
  622. # 383
  623. struct _fat_ptr Cyc_rexpand(struct _RegionHandle*r,struct _fat_ptr s,unsigned long sz){
  624. struct _fat_ptr temp;
  625. unsigned long slen;
  626. # 387
  627. slen=Cyc_strlen(s);
  628. sz=sz > slen?sz: slen;
  629. temp=Cyc_Core_rnew_string(r,sz);
  630. # 391
  631. {struct _fat_ptr _Tmp0;_Tmp0=temp;{struct _fat_ptr dst=_Tmp0;
  632. Cyc_strncpy(dst,s,slen);}}
  633. # 395
  634. if(slen!=_get_fat_size(s,sizeof(char)))
  635. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(temp,sizeof(char),(int)slen);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2='\000';if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});
  636. # 398
  637. return temp;}
  638. # 401
  639. struct _fat_ptr Cyc_expand(struct _fat_ptr s,unsigned long sz){
  640. return Cyc_rexpand(Cyc_Core_heap_region,s,sz);}
  641. # 405
  642. struct _fat_ptr Cyc_cond_rrealloc_str(struct _RegionHandle*r,struct _fat_ptr str,unsigned long sz){
  643. unsigned long maxsizeP=_get_fat_size(str,sizeof(char));
  644. struct _fat_ptr res=_tag_fat(0,0,0);
  645. # 409
  646. if(maxsizeP==0U){
  647. maxsizeP=Cyc_umax(30U,sz);
  648. res=Cyc_Core_rnew_string(r,maxsizeP);
  649. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(res,sizeof(char),0);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2='\000';if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});}else{
  650. # 414
  651. if(sz > maxsizeP){
  652. maxsizeP=maxsizeP * 2U > (sz * 5U)/ 4U?maxsizeP * 2U:(sz * 5U)/ 4U;{
  653. struct _fat_ptr _Tmp0;_Tmp0=str;{struct _fat_ptr dst=_Tmp0;
  654. res=Cyc_rexpand(r,dst,maxsizeP);}}}}
  655. # 421
  656. return res;}
  657. # 424
  658. struct _fat_ptr Cyc_realloc_str(struct _fat_ptr str,unsigned long sz){
  659. struct _fat_ptr res=Cyc_cond_rrealloc_str(Cyc_Core_heap_region,str,sz);
  660. if((char*)res.curr==(char*)_tag_fat(0,0,0).curr)return str;else{
  661. return res;}}
  662. # 435
  663. struct _fat_ptr Cyc_rsubstring(struct _RegionHandle*r,struct _fat_ptr s,int start,unsigned long amt){
  664. # 439
  665. struct _fat_ptr ans=Cyc_Core_rnew_string(r,amt + 1U);
  666. s=_fat_ptr_plus(s,sizeof(char),start);
  667. amt < _get_fat_size(ans,sizeof(char))&& amt <= _get_fat_size(s,sizeof(char))?0:({(int(*)(struct _fat_ptr,struct _fat_ptr,unsigned))Cyc___assert_fail;})(_tag_fat("amt < numelts(ans) && amt <= numelts(s)",sizeof(char),40U),_tag_fat("string.cyc",sizeof(char),11U),441U);
  668. {unsigned long i=0U;for(0;i < amt;++ i){
  669. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(ans,sizeof(char),(int)i);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2=((const char*)s.curr)[(int)i];if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});}}
  670. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(ans,sizeof(char),(int)amt);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2='\000';if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});
  671. return ans;}
  672. # 448
  673. struct _fat_ptr Cyc_substring(struct _fat_ptr s,int start,unsigned long amt){
  674. return Cyc_rsubstring(Cyc_Core_heap_region,s,start,amt);}
  675. # 454
  676. struct _fat_ptr Cyc_rreplace_suffix(struct _RegionHandle*r,struct _fat_ptr src,struct _fat_ptr curr_suffix,struct _fat_ptr new_suffix){
  677. unsigned long m=_get_fat_size(src,sizeof(char));
  678. unsigned long n=_get_fat_size(curr_suffix,sizeof(char));
  679. struct _fat_ptr err=_tag_fat("replace_suffix",sizeof(char),15U);
  680. if(m < n)
  681. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=err;_Tmp0;}));
  682. {unsigned long i=1U;for(0;i <= n;++ i){
  683. if(({int _Tmp0=(int)*((const char*)_check_fat_subscript(src,sizeof(char),(int)(m - i)));_Tmp0!=(int)*((const char*)_check_fat_subscript(curr_suffix,sizeof(char),(int)(n - i)));}))
  684. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=err;_Tmp0;}));}}{
  685. struct _fat_ptr ans=Cyc_Core_rnew_string(r,((m - n)+ _get_fat_size(new_suffix,sizeof(char)))+ 1U);
  686. ({struct _fat_ptr _Tmp0=_fat_ptr_decrease_size(ans,sizeof(char),1U);struct _fat_ptr _Tmp1=src;Cyc_strncpy(_Tmp0,_Tmp1,m - n);});
  687. ({struct _fat_ptr _Tmp0=_fat_ptr_decrease_size(_fat_ptr_plus(ans,sizeof(char),(int)(m - n)),sizeof(char),1U);struct _fat_ptr _Tmp1=new_suffix;Cyc_strncpy(_Tmp0,_Tmp1,_get_fat_size(new_suffix,sizeof(char)));});
  688. return ans;}}
  689. # 469
  690. struct _fat_ptr Cyc_replace_suffix(struct _fat_ptr src,struct _fat_ptr curr_suffix,struct _fat_ptr new_suffix){
  691. return Cyc_rreplace_suffix(Cyc_Core_heap_region,src,curr_suffix,new_suffix);}
  692. # 476
  693. struct _fat_ptr Cyc_strpbrk(struct _fat_ptr s,struct _fat_ptr accept){
  694. int len=(int)_get_fat_size(s,sizeof(char));
  695. unsigned asize=_get_fat_size(accept,sizeof(char));
  696. char c;
  697. unsigned i;
  698. for(i=0U;i < (unsigned)len &&(int)(c=((const char*)s.curr)[(int)i])!=0;++ i){
  699. unsigned j=0U;for(0;j < asize;++ j){
  700. if((int)c==(int)((const char*)accept.curr)[(int)j])
  701. return _fat_ptr_plus(s,sizeof(char),(int)i);}}
  702. # 486
  703. return _tag_fat(0,0,0);}
  704. # 489
  705. struct _fat_ptr Cyc_mstrpbrk(struct _fat_ptr s,struct _fat_ptr accept){
  706. int len=(int)_get_fat_size(s,sizeof(char));
  707. unsigned asize=_get_fat_size(accept,sizeof(char));
  708. char c;
  709. unsigned i;
  710. for(i=0U;i < (unsigned)len &&(int)(c=((char*)s.curr)[(int)i])!=0;++ i){
  711. unsigned j=0U;for(0;j < asize;++ j){
  712. if((int)c==(int)((const char*)accept.curr)[(int)j])
  713. return _fat_ptr_plus(s,sizeof(char),(int)i);}}
  714. # 499
  715. return _tag_fat(0,0,0);}
  716. # 504
  717. struct _fat_ptr Cyc_mstrchr(struct _fat_ptr s,char c){
  718. int len=(int)_get_fat_size(s,sizeof(char));
  719. char c2;
  720. unsigned i;
  721. # 509
  722. for(i=0U;i < (unsigned)len &&(int)(c2=((char*)s.curr)[(int)i])!=0;++ i){
  723. if((int)c2==(int)c)return _fat_ptr_plus(s,sizeof(char),(int)i);}
  724. # 512
  725. return _tag_fat(0,0,0);}
  726. # 515
  727. struct _fat_ptr Cyc_strchr(struct _fat_ptr s,char c){
  728. int len=(int)_get_fat_size(s,sizeof(char));
  729. char c2;
  730. unsigned i;
  731. # 520
  732. for(i=0U;i < (unsigned)len &&(int)(c2=((const char*)s.curr)[(int)i])!=0;++ i){
  733. if((int)c2==(int)c)return _fat_ptr_plus(s,sizeof(char),(int)i);}
  734. # 523
  735. return _tag_fat(0,0,0);}
  736. # 528
  737. struct _fat_ptr Cyc_strrchr(struct _fat_ptr s0,char c){
  738. int len=(int)Cyc_strlen(s0);
  739. int i=len - 1;
  740. struct _fat_ptr s=s0;
  741. _fat_ptr_inplace_plus(& s,sizeof(char),i);
  742. # 534
  743. for(1;i >= 0;(i --,_fat_ptr_inplace_plus_post(& s,sizeof(char),-1))){
  744. if((int)*((const char*)_check_fat_subscript(s,sizeof(char),0U))==(int)c)
  745. return s;}
  746. # 538
  747. return _tag_fat(0,0,0);}
  748. # 541
  749. struct _fat_ptr Cyc_mstrrchr(struct _fat_ptr s0,char c){
  750. int len=(int)Cyc_strlen(s0);
  751. int i=len - 1;
  752. struct _fat_ptr s=s0;
  753. _fat_ptr_inplace_plus(& s,sizeof(char),i);
  754. # 547
  755. for(1;i >= 0;(i --,_fat_ptr_inplace_plus_post(& s,sizeof(char),-1))){
  756. if((int)*((char*)_check_fat_subscript(s,sizeof(char),0U))==(int)c)
  757. return s;}
  758. # 551
  759. return _tag_fat(0,0,0);}
  760. # 556
  761. struct _fat_ptr Cyc_strstr(struct _fat_ptr haystack,struct _fat_ptr needle){
  762. if(!((unsigned)haystack.curr)|| !((unsigned)needle.curr))_throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("strstr",sizeof(char),7U);_Tmp0;}));
  763. if((int)*((const char*)_check_fat_subscript(needle,sizeof(char),0U))==0)return haystack;{
  764. # 560
  765. int len=(int)Cyc_strlen(needle);
  766. {struct _fat_ptr start=haystack;for(0;({
  767. char*_Tmp0=(char*)(start=Cyc_strchr(start,*((const char*)needle.curr))).curr;_Tmp0!=(char*)_tag_fat(0,0,0).curr;});start=({
  768. struct _fat_ptr _Tmp0=_fat_ptr_plus(start,sizeof(char),1);Cyc_strchr(_Tmp0,*((const char*)needle.curr));})){
  769. if(Cyc_strncmp(start,needle,(unsigned long)len)==0)
  770. return start;}}
  771. # 567
  772. return _tag_fat(0,0,0);}}
  773. # 570
  774. struct _fat_ptr Cyc_mstrstr(struct _fat_ptr haystack,struct _fat_ptr needle){
  775. if(!((unsigned)haystack.curr)|| !((unsigned)needle.curr))_throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("mstrstr",sizeof(char),8U);_Tmp0;}));
  776. if((int)*((const char*)_check_fat_subscript(needle,sizeof(char),0U))==0)return haystack;{
  777. # 574
  778. int len=(int)Cyc_strlen(needle);
  779. {struct _fat_ptr start=haystack;for(0;({
  780. char*_Tmp0=(char*)(start=Cyc_mstrchr(start,*((const char*)needle.curr))).curr;_Tmp0!=(char*)_tag_fat(0,0,0).curr;});start=({
  781. struct _fat_ptr _Tmp0=_fat_ptr_plus(start,sizeof(char),1);Cyc_mstrchr(_Tmp0,*((const char*)needle.curr));})){
  782. if(Cyc_strncmp(start,needle,(unsigned long)len)==0)
  783. return start;}}
  784. # 581
  785. return _tag_fat(0,0,0);}}
  786. # 587
  787. unsigned long Cyc_strspn(struct _fat_ptr s,struct _fat_ptr accept){
  788. struct _fat_ptr b=s;
  789. unsigned long len=Cyc_strlen(b);
  790. unsigned asize=_get_fat_size(accept,sizeof(char));
  791. 1;
  792. {unsigned long i=0U;for(0;i < len;++ i){
  793. int j;
  794. for(j=0;(unsigned)j < asize;++ j){
  795. if((int)((const char*)b.curr)[(int)i]==(int)((const char*)accept.curr)[j])
  796. break;}
  797. if((unsigned)j==asize)
  798. return i;}}
  799. # 601
  800. return len;}
  801. # 607
  802. unsigned long Cyc_strcspn(struct _fat_ptr s,struct _fat_ptr accept){
  803. struct _fat_ptr b=s;
  804. unsigned long len=Cyc_strlen(b);
  805. unsigned asize=_get_fat_size(accept,sizeof(char));
  806. # 612
  807. 1;
  808. {unsigned long i=0U;for(0;i < len;++ i){
  809. int j;
  810. for(j=0;(unsigned)j < asize;++ j){
  811. if((int)((const char*)b.curr)[(int)i]==(int)((const char*)accept.curr)[j])return i;}}}
  812. # 618
  813. return len;}
  814. # 625
  815. struct _fat_ptr Cyc_strtok(struct _fat_ptr s,struct _fat_ptr delim){
  816. # 627
  817. static struct _fat_ptr olds={(void*)0,(void*)0,(void*)(0 + 0)};
  818. struct _fat_ptr token;
  819. # 630
  820. if((char*)s.curr==(char*)_tag_fat(0,0,0).curr){
  821. if((char*)olds.curr==(char*)_tag_fat(0,0,0).curr)
  822. return _tag_fat(0,0,0);
  823. s=olds;}{
  824. # 637
  825. unsigned long inc=Cyc_strspn(s,delim);
  826. if(inc >= _get_fat_size(s,sizeof(char))||(int)*((char*)_fat_ptr_plus(s,sizeof(char),(int)inc).curr)==0){
  827. # 640
  828. olds=_tag_fat(0,0,0);
  829. return _tag_fat(0,0,0);}else{
  830. # 644
  831. _fat_ptr_inplace_plus(& s,sizeof(char),(int)inc);}
  832. # 647
  833. token=s;
  834. s=Cyc_mstrpbrk(token,delim);
  835. if((char*)s.curr==(char*)_tag_fat(0,0,0).curr)
  836. # 651
  837. olds=_tag_fat(0,0,0);else{
  838. # 655
  839. ({struct _fat_ptr _Tmp0=s;char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2='\000';if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});
  840. olds=_fat_ptr_plus(s,sizeof(char),1);}
  841. # 658
  842. return token;}}
  843. # 662
  844. struct Cyc_List_List*Cyc_rexplode(struct _RegionHandle*r,struct _fat_ptr s){
  845. struct Cyc_List_List*result=0;
  846. {int i=(int)(Cyc_strlen(s)- 1U);for(0;i >= 0;-- i){
  847. result=({struct Cyc_List_List*_Tmp0=_region_malloc(r,0U,sizeof(struct Cyc_List_List));_Tmp0->hd=(void*)((int)*((const char*)_check_fat_subscript(s,sizeof(char),i))),_Tmp0->tl=result;_Tmp0;});}}
  848. return result;}
  849. # 669
  850. struct Cyc_List_List*Cyc_explode(struct _fat_ptr s){
  851. return Cyc_rexplode(Cyc_Core_heap_region,s);}
  852. # 673
  853. struct _fat_ptr Cyc_implode(struct Cyc_List_List*chars){
  854. struct _fat_ptr s=Cyc_Core_new_string((unsigned)(Cyc_List_length(chars)+ 1));
  855. unsigned long i=0U;
  856. while(chars!=0){
  857. ({struct _fat_ptr _Tmp0=_fat_ptr_plus(s,sizeof(char),(int)i ++);char _Tmp1=*((char*)_check_fat_subscript(_Tmp0,sizeof(char),0U));char _Tmp2=(char)((int)chars->hd);if(_get_fat_size(_Tmp0,sizeof(char))==1U &&(_Tmp1==0 && _Tmp2!=0))_throw_arraybounds();*((char*)_Tmp0.curr)=_Tmp2;});
  858. chars=chars->tl;}
  859. # 680
  860. return s;}
  861. # 684
  862. inline static int Cyc_casecmp(struct _fat_ptr s1,unsigned long len1,struct _fat_ptr s2,unsigned long len2){
  863. # 688
  864. unsigned long min_length=Cyc_umin(len1,len2);
  865. # 690
  866. 1;{
  867. # 692
  868. int i=-1;
  869. while((++ i,(unsigned long)i < min_length)){
  870. int diff=({int _Tmp0=toupper((int)((const char*)s1.curr)[i]);_Tmp0 - toupper((int)((const char*)s2.curr)[i]);});
  871. if(diff!=0)
  872. return diff;}
  873. # 698
  874. return(int)len1 - (int)len2;}}
  875. # 701
  876. int Cyc_strcasecmp(struct _fat_ptr s1,struct _fat_ptr s2){
  877. if((char*)s1.curr==(char*)s2.curr)
  878. return 0;{
  879. unsigned long len1=Cyc_strlen(s1);
  880. unsigned long len2=Cyc_strlen(s2);
  881. return Cyc_casecmp(s1,len1,s2,len2);}}
  882. # 709
  883. inline static int Cyc_caseless_ncmp(struct _fat_ptr s1,unsigned long len1,struct _fat_ptr s2,unsigned long len2,unsigned long n){
  884. # 713
  885. if(n <= 0U)return 0;{
  886. # 715
  887. unsigned long min_len=Cyc_umin(len1,len2);
  888. unsigned long bound=Cyc_umin(min_len,n);
  889. # 718
  890. 1;
  891. # 720
  892. {int i=0;for(0;(unsigned long)i < bound;++ i){
  893. int retc;
  894. if((retc=({int _Tmp0=toupper((int)((const char*)s1.curr)[i]);_Tmp0 - toupper((int)((const char*)s2.curr)[i]);}))!=0)
  895. return retc;}}
  896. # 725
  897. if(len1 < n || len2 < n)
  898. return(int)len1 - (int)len2;
  899. return 0;}}
  900. # 731
  901. int Cyc_strncasecmp(struct _fat_ptr s1,struct _fat_ptr s2,unsigned long n){
  902. unsigned long len1=Cyc_strlen(s1);
  903. unsigned long len2=Cyc_strlen(s2);
  904. return Cyc_caseless_ncmp(s1,len1,s2,len2,n);}
  905. # 740
  906. extern void*memcpy(void*,const void*,unsigned long);
  907. extern void*memmove(void*,const void*,unsigned long);
  908. extern int memcmp(const void*,const void*,unsigned long);
  909. extern char*memchr(const char*,char,unsigned long);
  910. extern void*memset(void*,int,unsigned long);
  911. extern void bcopy(const void*,void*,unsigned long);
  912. extern void bzero(void*,unsigned long);
  913. extern char*GC_realloc_hint(char*,unsigned,unsigned);
  914. # 753
  915. struct _fat_ptr Cyc_realloc(struct _fat_ptr s,unsigned long n){
  916. unsigned _Tmp0=_get_fat_size(s,sizeof(char));unsigned _Tmp1;_Tmp1=_Tmp0;{unsigned oldsz=_Tmp1;
  917. unsigned _Tmp2;_Tmp2=n;{unsigned l=_Tmp2;
  918. char*res=GC_realloc_hint((char*)_untag_fat_ptr(s,sizeof(char),1U),oldsz,l);
  919. return({(struct _fat_ptr(*)(char*,unsigned,unsigned))Cyc_Core_mkfat;})(_check_null(res),sizeof(char),l);}}}
  920. # 760
  921. struct _fat_ptr Cyc__memcpy(struct _fat_ptr d,struct _fat_ptr s,unsigned long n,unsigned sz){
  922. if((((void*)d.curr==(void*)_tag_fat(0,0,0).curr || _get_fat_size(d,sizeof(void))< n)||(void*)s.curr==(void*)_tag_fat(0,0,0).curr)|| _get_fat_size(s,sizeof(void))< n)
  923. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("memcpy",sizeof(char),7U);_Tmp0;}));
  924. ({void*_Tmp0=(void*)_untag_fat_ptr(d,sizeof(void),1U);const void*_Tmp1=(const void*)_untag_fat_ptr(s,sizeof(void),1U);memcpy(_Tmp0,_Tmp1,n * sz);});
  925. return d;}
  926. # 767
  927. struct _fat_ptr Cyc__memmove(struct _fat_ptr d,struct _fat_ptr s,unsigned long n,unsigned sz){
  928. if((((void*)d.curr==(void*)_tag_fat(0,0,0).curr || _get_fat_size(d,sizeof(void))< n)||(void*)s.curr==(void*)_tag_fat(0,0,0).curr)|| _get_fat_size(s,sizeof(void))< n)
  929. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("memove",sizeof(char),7U);_Tmp0;}));
  930. ({void*_Tmp0=(void*)_untag_fat_ptr(d,sizeof(void),1U);const void*_Tmp1=(const void*)_untag_fat_ptr(s,sizeof(void),1U);memmove(_Tmp0,_Tmp1,n * sz);});
  931. return d;}
  932. # 774
  933. int Cyc_memcmp(struct _fat_ptr s1,struct _fat_ptr s2,unsigned long n){
  934. if((((char*)s1.curr==(char*)_tag_fat(0,0,0).curr ||(char*)s2.curr==(char*)_tag_fat(0,0,0).curr)|| _get_fat_size(s1,sizeof(char))< n)|| _get_fat_size(s2,sizeof(char))< n)
  935. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("memcmp",sizeof(char),7U);_Tmp0;}));
  936. return({const void*_Tmp0=(const void*)_untag_fat_ptr(s1,sizeof(char),1U);const void*_Tmp1=(const void*)_untag_fat_ptr(s2,sizeof(char),1U);memcmp(_Tmp0,_Tmp1,n);});}
  937. # 780
  938. struct _fat_ptr Cyc_memchr(struct _fat_ptr s,char c,unsigned long n){
  939. unsigned sz=_get_fat_size(s,sizeof(char));
  940. if((char*)s.curr==(char*)_tag_fat(0,0,0).curr || n > sz)
  941. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("memchr",sizeof(char),7U);_Tmp0;}));{
  942. char*p=memchr((const char*)_untag_fat_ptr(s,sizeof(char),1U),c,n);
  943. if(p==0)return _tag_fat(0,0,0);{
  944. unsigned sval=(unsigned)((const char*)_untag_fat_ptr(s,sizeof(char),1U));
  945. unsigned pval=(unsigned)((const char*)p);
  946. unsigned delta=pval - sval;
  947. return _fat_ptr_plus(s,sizeof(char),(int)delta);}}}
  948. # 792
  949. struct _fat_ptr Cyc_mmemchr(struct _fat_ptr s,char c,unsigned long n){
  950. unsigned sz=_get_fat_size(s,sizeof(char));
  951. if((char*)s.curr==(char*)_tag_fat(0,0,0).curr || n > sz)
  952. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("mmemchr",sizeof(char),8U);_Tmp0;}));{
  953. char*p=memchr((const char*)_untag_fat_ptr(s,sizeof(char),1U),c,n);
  954. if(p==0)return _tag_fat(0,0,0);{
  955. unsigned sval=(unsigned)((const char*)_untag_fat_ptr(s,sizeof(char),1U));
  956. unsigned pval=(unsigned)p;
  957. unsigned delta=pval - sval;
  958. return _fat_ptr_plus(s,sizeof(char),(int)delta);}}}
  959. # 804
  960. struct _fat_ptr Cyc_memset(struct _fat_ptr s,char c,unsigned long n){
  961. if((char*)s.curr==(char*)_tag_fat(0,0,0).curr || n > _get_fat_size(s,sizeof(char)))
  962. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("memset",sizeof(char),7U);_Tmp0;}));
  963. memset((void*)((char*)_untag_fat_ptr(s,sizeof(char),1U)),(int)c,n);
  964. return s;}
  965. # 811
  966. void Cyc_bzero(struct _fat_ptr s,unsigned long n){
  967. if((char*)s.curr==(char*)_tag_fat(0,0,0).curr || _get_fat_size(s,sizeof(char))< n)
  968. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("bzero",sizeof(char),6U);_Tmp0;}));
  969. ({(void(*)(char*,unsigned long))bzero;})((char*)_untag_fat_ptr(s,sizeof(char),1U),n);}
  970. # 817
  971. void Cyc__bcopy(struct _fat_ptr src,struct _fat_ptr dst,unsigned long n,unsigned sz){
  972. if((((void*)src.curr==(void*)_tag_fat(0,0,0).curr || _get_fat_size(src,sizeof(void))< n)||(void*)dst.curr==(void*)_tag_fat(0,0,0).curr)|| _get_fat_size(dst,sizeof(void))< n)
  973. _throw((void*)({struct Cyc_Core_Invalid_argument_exn_struct*_Tmp0=_cycalloc(sizeof(struct Cyc_Core_Invalid_argument_exn_struct));_Tmp0->tag=Cyc_Core_Invalid_argument,_Tmp0->f1=_tag_fat("bcopy",sizeof(char),6U);_Tmp0;}));
  974. ({const void*_Tmp0=(const void*)_untag_fat_ptr(src,sizeof(void),1U);void*_Tmp1=(void*)_untag_fat_ptr(dst,sizeof(void),1U);bcopy(_Tmp0,_Tmp1,n * sz);});}