1 /* Generated by Nim Compiler v1.6.2 */
2 #define NIM_INTBITS 32
3
4 #include "nimbase.h"
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <string.h>
8 #include <errno.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11 #include <setjmp.h>
12 #undef LANGUAGE_C
13 #undef MIPSEB
14 #undef MIPSEL
15 #undef PPC
16 #undef R3000
17 #undef R4000
18 #undef i386
19 #undef linux
20 #undef mips
21 #undef near
22 #undef far
23 #undef powerpc
24 #undef unix
25 #define nimfr_(x, y)
26 #define nimln_(x, y)
27 typedef struct NimStringDesc NimStringDesc;
28 typedef struct TGenericSeq TGenericSeq;
29 typedef struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ tySequence__sM4lkSb7zS6F7OVMvW9cffQ;
30 typedef struct TNimType TNimType;
31 typedef struct TNimNode TNimNode;
32 typedef struct tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw;
33 typedef struct tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA;
34 typedef struct Exception Exception;
35 typedef struct RootObj RootObj;
36 typedef struct tySequence__uB9b75OUPRENsBAu4AnoePA tySequence__uB9b75OUPRENsBAu4AnoePA;
37 typedef struct tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g;
38 typedef struct tyObject_CellSeq__Axo1XVm9aaQueTOldv8le5w tyObject_CellSeq__Axo1XVm9aaQueTOldv8le5w;
39 typedef struct tyObject_GcHeap__1TRH1TZMaVZTnLNcIHuNFQ tyObject_GcHeap__1TRH1TZMaVZTnLNcIHuNFQ;
40 typedef struct tyObject_GcStack__7fytPA5bBsob6See21YMRA tyObject_GcStack__7fytPA5bBsob6See21YMRA;
41 typedef struct tyObject_MemRegion__x81NhDv59b8ercDZ9bi85jyg tyObject_MemRegion__x81NhDv59b8ercDZ9bi85jyg;
42 typedef struct tyObject_SmallChunk__tXn60W2f8h3jgAYdEmy5NQ tyObject_SmallChunk__tXn60W2f8h3jgAYdEmy5NQ;
43 typedef struct tyObject_BigChunk__Rv9c70Uhp2TytkX7eH78qEg tyObject_BigChunk__Rv9c70Uhp2TytkX7eH78qEg;
44 typedef struct tyObject_LLChunk__XsENErzHIZV9bhvyJx56wGw tyObject_LLChunk__XsENErzHIZV9bhvyJx56wGw;
45 typedef struct tyObject_IntSet__EZObFrE3NC9bIb3YMkY9crZA tyObject_IntSet__EZObFrE3NC9bIb3YMkY9crZA;
46 typedef struct tyObject_Trunk__W0r8S0Y3UGke6T9bIUWnnuw tyObject_Trunk__W0r8S0Y3UGke6T9bIUWnnuw;
47 typedef struct tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw;
48 typedef struct tyObject_HeapLinks__PDV1HBZ8CQSQJC9aOBFNRSg tyObject_HeapLinks__PDV1HBZ8CQSQJC9aOBFNRSg;
49 typedef struct tyTuple__ujsjpB2O9cjj3uDHsXbnSzg tyTuple__ujsjpB2O9cjj3uDHsXbnSzg;
50 typedef struct tyObject_GcStat__0RwLoVBHZPfUAcLczmfQAg tyObject_GcStat__0RwLoVBHZPfUAcLczmfQAg;
51 typedef struct tyObject_CellSet__jG87P0AI9aZtss9ccTYBIISQ tyObject_CellSet__jG87P0AI9aZtss9ccTYBIISQ;
52 typedef struct tyObject_PageDesc__fublkgIY4LG3mT51LU2WHg tyObject_PageDesc__fublkgIY4LG3mT51LU2WHg;
53 typedef struct TSafePoint TSafePoint;
54 typedef struct tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg;
55 typedef struct tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA;
56 struct TGenericSeq {
57 NI len;
58 NI reserved;
59 };
60 struct NimStringDesc {
61 TGenericSeq Sup;
62 NIM_CHAR data[SEQ_DECL_SIZE];
63 };
64 typedef NU8 tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A;
65 typedef NU8 tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ;
66 typedef N_NIMCALL_PTR(void, tyProc__ojoeKfW4VYIm36I9cpDTQIg) (void* p, NI op);
67 typedef N_NIMCALL_PTR(void*, tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p);
68 struct TNimType {
69 NI size;
70 NI align;
71 tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A kind;
72 tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ flags;
73 TNimType* base;
74 TNimNode* node;
75 void* finalizer;
76 tyProc__ojoeKfW4VYIm36I9cpDTQIg marker;
77 tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
78 };
79 typedef NU8 tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ;
80 struct TNimNode {
81 tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ kind;
82 NI offset;
83 TNimType* typ;
84 NCSTRING name;
85 NI len;
86 TNimNode** sons;
87 };
88 struct RootObj {
89 TNimType* m_type;
90 };
91 struct Exception {
92 RootObj Sup;
93 Exception* parent;
94 NCSTRING name;
95 NimStringDesc* message;
96 tySequence__uB9b75OUPRENsBAu4AnoePA* trace;
97 Exception* up;
98 };
99 struct tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA {
100 Exception Sup;
101 };
102 struct tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw {
103 tyObject_CatchableError__qrLSDoe2oBoAqNtJ9badtnA Sup;
104 };
105 struct tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g {
106 NI refcount;
107 TNimType* typ;
108 };
109 struct tyObject_GcStack__7fytPA5bBsob6See21YMRA {
110 void* bottom;
111 };
112 struct tyObject_CellSeq__Axo1XVm9aaQueTOldv8le5w {
113 NI len;
114 NI cap;
115 tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g** d;
116 };
117 typedef tyObject_SmallChunk__tXn60W2f8h3jgAYdEmy5NQ* tyArray__SPr7N6UKfuF549bNPiUvSRw[256];
118 typedef NU32 tyArray__BHbOSqU1t9b3Gt7K2c6fQig[24];
119 typedef tyObject_BigChunk__Rv9c70Uhp2TytkX7eH78qEg* tyArray__N1u1nqOgmuJN9cSZrnMHgOQ[32];
120 typedef tyArray__N1u1nqOgmuJN9cSZrnMHgOQ tyArray__B6durA4ZCi1xjJvRtyYxMg[24];
121 typedef tyObject_Trunk__W0r8S0Y3UGke6T9bIUWnnuw* tyArray__lh2A89ahMmYg9bCmpVaplLbA[256];
122 struct tyObject_IntSet__EZObFrE3NC9bIb3YMkY9crZA {
123 tyArray__lh2A89ahMmYg9bCmpVaplLbA data;
124 };
125 typedef tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw* tyArray__0aOLqZchNi8nWtMTi8ND8w[2];
126 struct tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw {
127 tyArray__0aOLqZchNi8nWtMTi8ND8w link;
128 NI key;
129 NI upperBound;
130 NI level;
131 };
132 struct tyTuple__ujsjpB2O9cjj3uDHsXbnSzg {
133 tyObject_BigChunk__Rv9c70Uhp2TytkX7eH78qEg* Field0;
134 NI Field1;
135 };
136 typedef tyTuple__ujsjpB2O9cjj3uDHsXbnSzg tyArray__LzOv2eCDGiceMKQstCLmhw[30];
137 struct tyObject_HeapLinks__PDV1HBZ8CQSQJC9aOBFNRSg {
138 NI len;
139 tyArray__LzOv2eCDGiceMKQstCLmhw chunks;
140 tyObject_HeapLinks__PDV1HBZ8CQSQJC9aOBFNRSg* next;
141 };
142 struct tyObject_MemRegion__x81NhDv59b8ercDZ9bi85jyg {
143 NI minLargeObj;
144 NI maxLargeObj;
145 tyArray__SPr7N6UKfuF549bNPiUvSRw freeSmallChunks;
146 NU32 flBitmap;
147 tyArray__BHbOSqU1t9b3Gt7K2c6fQig slBitmap;
148 tyArray__B6durA4ZCi1xjJvRtyYxMg matrix;
149 tyObject_LLChunk__XsENErzHIZV9bhvyJx56wGw* llmem;
150 NI currMem;
151 NI maxMem;
152 NI freeMem;
153 NI occ;
154 NI lastSize;
155 tyObject_IntSet__EZObFrE3NC9bIb3YMkY9crZA chunkStarts;
156 tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw* root;
157 tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw* deleted;
158 tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw* last;
159 tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw* freeAvlNodes;
160 NIM_BOOL locked;
161 NIM_BOOL blockChunkSizeIncrease;
162 NI nextChunkSize;
163 tyObject_AvlNode__IaqjtwKhxLEpvDS9bct9blEw bottomData;
164 tyObject_HeapLinks__PDV1HBZ8CQSQJC9aOBFNRSg heapLinks;
165 };
166 struct tyObject_GcStat__0RwLoVBHZPfUAcLczmfQAg {
167 NI stackScans;
168 NI cycleCollections;
169 NI maxThreshold;
170 NI maxStackSize;
171 NI maxStackCells;
172 NI cycleTableSize;
173 NI64 maxPause;
174 };
175 struct tyObject_CellSet__jG87P0AI9aZtss9ccTYBIISQ {
176 NI counter;
177 NI max;
178 tyObject_PageDesc__fublkgIY4LG3mT51LU2WHg* head;
179 tyObject_PageDesc__fublkgIY4LG3mT51LU2WHg** data;
180 };
181 struct tyObject_GcHeap__1TRH1TZMaVZTnLNcIHuNFQ {
182 tyObject_GcStack__7fytPA5bBsob6See21YMRA stack;
183 NI cycleThreshold;
184 NI zctThreshold;
185 tyObject_CellSeq__Axo1XVm9aaQueTOldv8le5w zct;
186 tyObject_CellSeq__Axo1XVm9aaQueTOldv8le5w decStack;
187 tyObject_CellSeq__Axo1XVm9aaQueTOldv8le5w tempStack;
188 NI recGcLock;
189 tyObject_MemRegion__x81NhDv59b8ercDZ9bi85jyg region;
190 tyObject_GcStat__0RwLoVBHZPfUAcLczmfQAg stat;
191 tyObject_CellSet__jG87P0AI9aZtss9ccTYBIISQ marked;
192 tyObject_CellSeq__Axo1XVm9aaQueTOldv8le5w additionalRoots;
193 NI gcThreadId;
194 };
195 typedef NU8 tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg;
196 typedef NCSTRING tyArray__Djap3EijveoDksCG9bY8s5w[5];
197 struct TSafePoint {
198 TSafePoint* prev;
199 NI status;
200 jmp_buf context;
201 };
202 struct tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg {
203 tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw Sup;
204 };
205 typedef NU8 tyEnum_FileSeekPos__I9aQjuvWxs8BspGbxwsngWw;
206 struct tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA {
207 NCSTRING procname;
208 NI line;
209 NCSTRING filename;
210 };
211 struct tySequence__sM4lkSb7zS6F7OVMvW9cffQ {
212 TGenericSeq Sup;
213 NimStringDesc* data[SEQ_DECL_SIZE];
214 };
215 struct tySequence__uB9b75OUPRENsBAu4AnoePA {
216 TGenericSeq Sup;
217 tyObject_StackTraceEntry__oLyohQ7O2XOvGnflOss8EA data[SEQ_DECL_SIZE];
218 };
219 static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s);
220 N_LIB_PRIVATE N_NIMCALL(void*, newSeq)(TNimType* typ, NI len);
221 N_LIB_PRIVATE N_NIMCALL(NI, writeBuffer__systemZio_176)(FILE* f, void* buffer, NI len);
222 N_LIB_PRIVATE N_NIMCALL(void, checkErr__systemZio_141)(FILE* f);
223 static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
224 static N_INLINE(void, copyMem__system_1727)(void* dest, void* source, NI size);
225 static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
226 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___systemZdollars_3)(NI x);
227 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, cstrToNimstr)(NCSTRING str);
228 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
229 N_LIB_PRIVATE N_NOINLINE(void, raiseEIO__systemZio_96)(NimStringDesc* msg) __attribute__((noreturn));
230 N_LIB_PRIVATE N_NOINLINE(void*, newObj)(TNimType* typ, NI size);
231 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
232 static N_INLINE(void, nimGCunrefNoCycle)(void* p);
233 static N_INLINE(void, decRef__system_5315)(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* c);
234 static N_INLINE(NI, minuspercent___system_716)(NI x, NI y);
235 static N_INLINE(NIM_BOOL, ltpercent___system_1005)(NI x, NI y);
236 static N_INLINE(void, rtlAddZCT__system_5313)(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* c);
237 N_LIB_PRIVATE N_NOINLINE(void, addZCT__system_5264)(tyObject_CellSeq__Axo1XVm9aaQueTOldv8le5w* s, tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* c);
238 static N_INLINE(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g*, usrToCell__system_5270)(void* usr);
239 static N_INLINE(void, asgnRef)(void** dest, void* src);
240 static N_INLINE(void, incRef__system_5308)(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* c);
241 static N_INLINE(NI, pluspercent___system_696)(NI x, NI y);
242 N_LIB_PRIVATE N_NIMCALL(void, raiseExceptionEx)(Exception* e, NCSTRING ename, NCSTRING procname, NCSTRING filename, NI line);
243 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__systemZio_391)(FILE** f, NimStringDesc* filename, tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg mode, NI bufSize);
244 N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__systemZio_229)(FILE* f);
245 N_LIB_PRIVATE N_NIMCALL(void, close__systemZio_218)(FILE* f);
246 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, setInheritable__systemZio_235)(int f, NIM_BOOL inheritable);
247 N_LIB_PRIVATE N_NIMCALL(int, getOsFileHandle__systemZio_232)(FILE* f);
248 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newLen);
249 N_LIB_PRIVATE N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
250 static N_INLINE(NIM_BOOL, eqeq___system_7723)(NCSTRING x, NCSTRING y);
251 static N_INLINE(void, pushSafePoint)(TSafePoint* s);
252 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAll__systemZio_352)(FILE* file);
253 N_LIB_PRIVATE N_NIMCALL(NI64, rawFileSize__systemZio_335)(FILE* file);
254 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAllFile__systemZio_343)(FILE* file, NI64 len);
255 N_NIMCALL(NimStringDesc*, mnewString)(NI len);
256 N_LIB_PRIVATE N_NIMCALL(NI, readBuffer__systemZio_144)(FILE* f, void* buffer, NI len);
257 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, endOfFile__systemZio_339)(FILE* f);
258 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAllBuffer__systemZio_330)(FILE* file);
259 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
260 static N_INLINE(void, popSafePoint)(void);
261 N_LIB_PRIVATE N_NIMCALL(void, nimLeaveFinally)(void);
262 N_LIB_PRIVATE N_NIMCALL(void, reraiseException)(void);
263 N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
264 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, readLine__systemZio_240)(FILE* f, NimStringDesc** line);
265 N_LIB_PRIVATE N_NOINLINE(void, raiseEOF__systemZio_117)(void) __attribute__((noreturn));
266 N_LIB_PRIVATE N_NIMCALL(void, write__systemZio_205)(FILE* f, NimStringDesc* s);
267 N_LIB_PRIVATE N_NIMCALL(tySequence__sM4lkSb7zS6F7OVMvW9cffQ*, newSeq__systemZio_503)(NI len);
268 extern TNimType NTIseqLstringT__sM4lkSb7zS6F7OVMvW9cffQ_;
269 STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_2, "errno: ", 7);
270 STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_3, " `", 2);
271 STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_4, "`", 1);
272 extern TNimType NTIrefioerror__HMIVdYjdZYWskTmTQVo5BQ_;
273 extern TNimType NTIioerror__iLZrPn9anoh9ad1MmO0RczFw_;
274 STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_5, "cannot write string to file", 27);
275 N_LIB_PRIVATE NIM_CONST tyArray__Djap3EijveoDksCG9bY8s5w FormatOpen__systemZio_373 = {"rb",
276 "wb",
277 "w+b",
278 "r+b",
279 "ab"}
280 ;
281 STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_6, "cannot open: ", 13);
282 extern TNimType NTIrefeoferror__LEclZrWX2FQAodlapxGITw_;
283 extern TNimType NTIeoferror__KGSY1JdrNB7Xi8KDhXFhSg_;
284 STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_8, "EOF reached", 11);
285 N_LIB_PRIVATE TNimType NTIcfile__MAWzaQJYFu3mlxj0Ppxhmw_;
286 N_LIB_PRIVATE TNimType NTIfile__XBeRj4rw9bUuE7CB3DS1rgg_;
287 N_LIB_PRIVATE TNimType NTIfilehandle__2gIj3gQlK3HZJjQaYCP6ZQ_;
288 STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_11, "cannot set file position", 24);
289 STRING_LITERAL(TM__MnCJ0VAmeZ9aTATUB39cx60Q_12, "cannot retrieve file position", 29);
290 extern tyObject_GcHeap__1TRH1TZMaVZTnLNcIHuNFQ gch__system_5217;
291 extern TSafePoint* excHandler__system_2565;
292 extern TSafePoint* excHandler__system_2565;
293 extern TSafePoint* excHandler__system_2565;
294 extern TSafePoint* excHandler__system_2565;
N_INLINE(NCSTRING,nimToCStringConv)295 static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s) {
296 NCSTRING result;
297 result = (NCSTRING)0;
298 {
299 NIM_BOOL T3_;
300 T3_ = (NIM_BOOL)0;
301 T3_ = (s == ((NimStringDesc*) NIM_NIL));
302 if (T3_) goto LA4_;
303 T3_ = ((*s).Sup.len == ((NI) 0));
304 LA4_: ;
305 if (!T3_) goto LA5_;
306 result = "";
307 }
308 goto LA1_;
309 LA5_: ;
310 {
311 result = ((NCSTRING) ((*s).data));
312 }
313 LA1_: ;
314 return result;
315 }
N_NIMCALL(void,echoBinSafe)316 N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringDesc** args, NI argsLen_0) {
317 int T5_;
318 int T6_;
319 flockfile(stdout);
320 {
321 NimStringDesc** s;
322 NI i;
323 s = (NimStringDesc**)0;
324 i = ((NI) 0);
325 {
326 while (1) {
327 int T4_;
328 if (!(i < argsLen_0)) goto LA3;
329 s = (&args[i]);
330 T4_ = (int)0;
331 T4_ = fwrite(((void*) (nimToCStringConv((*s)))), ((size_t) (((*s) ? (*s)->Sup.len : 0))), ((size_t) 1), stdout);
332 (void)(T4_);
333 i += ((NI) 1);
334 } LA3: ;
335 }
336 }
337 T5_ = (int)0;
338 T5_ = fwrite(((void*) ("\012")), ((size_t) 1), ((size_t) 1), stdout);
339 (void)(T5_);
340 T6_ = (int)0;
341 T6_ = fflush(stdout);
342 (void)(T6_);
343 funlockfile(stdout);
344 }
N_NIMCALL(int,getFileHandle__systemZio_229)345 N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__systemZio_229)(FILE* f) {
346 int result;
347 result = (int)0;
348 result = fileno(f);
349 return result;
350 }
N_NIMCALL(tySequence__sM4lkSb7zS6F7OVMvW9cffQ *,newSeq__systemZio_503)351 N_LIB_PRIVATE N_NIMCALL(tySequence__sM4lkSb7zS6F7OVMvW9cffQ*, newSeq__systemZio_503)(NI len) {
352 tySequence__sM4lkSb7zS6F7OVMvW9cffQ* result;
353 result = NIM_NIL;
354 result = (tySequence__sM4lkSb7zS6F7OVMvW9cffQ*) newSeq((&NTIseqLstringT__sM4lkSb7zS6F7OVMvW9cffQ_), len);
355 return result;
356 }
N_INLINE(void,nimCopyMem)357 static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size) {
358 void* T1_;
359 T1_ = (void*)0;
360 T1_ = memcpy(dest, source, ((size_t) (size)));
361 }
N_INLINE(void,copyMem__system_1727)362 static N_INLINE(void, copyMem__system_1727)(void* dest, void* source, NI size) {
363 nimCopyMem(dest, source, size);
364 }
N_INLINE(void,appendString)365 static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
366 {
367 if (!!((src == ((NimStringDesc*) NIM_NIL)))) goto LA3_;
368 copyMem__system_1727(((void*) ((&(*dest).data[(*dest).Sup.len]))), ((void*) ((*src).data)), ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
369 (*dest).Sup.len += (*src).Sup.len;
370 }
371 LA3_: ;
372 }
N_INLINE(NI,minuspercent___system_716)373 static N_INLINE(NI, minuspercent___system_716)(NI x, NI y) {
374 NI result;
375 result = (NI)0;
376 result = ((NI) ((NU)((NU32)(((NU) (x))) - (NU32)(((NU) (y))))));
377 return result;
378 }
N_INLINE(NIM_BOOL,ltpercent___system_1005)379 static N_INLINE(NIM_BOOL, ltpercent___system_1005)(NI x, NI y) {
380 NIM_BOOL result;
381 result = (NIM_BOOL)0;
382 result = ((NU32)(((NU) (x))) < (NU32)(((NU) (y))));
383 return result;
384 }
N_INLINE(void,rtlAddZCT__system_5313)385 static N_INLINE(void, rtlAddZCT__system_5313)(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* c) {
386 addZCT__system_5264((&gch__system_5217.zct), c);
387 }
N_INLINE(void,decRef__system_5315)388 static N_INLINE(void, decRef__system_5315)(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* c) {
389 (*c).refcount = minuspercent___system_716((*c).refcount, ((NI) 8));
390 {
391 NIM_BOOL T3_;
392 T3_ = (NIM_BOOL)0;
393 T3_ = ltpercent___system_1005((*c).refcount, ((NI) 8));
394 if (!T3_) goto LA4_;
395 rtlAddZCT__system_5313(c);
396 }
397 LA4_: ;
398 }
N_INLINE(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g *,usrToCell__system_5270)399 static N_INLINE(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g*, usrToCell__system_5270)(void* usr) {
400 tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* result;
401 NI T1_;
402 result = (tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g*)0;
403 T1_ = (NI)0;
404 T1_ = minuspercent___system_716(((NI) (ptrdiff_t) (usr)), ((NI) 8));
405 result = ((tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g*) (T1_));
406 return result;
407 }
N_INLINE(void,nimGCunrefNoCycle)408 static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
409 tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* T1_;
410 T1_ = (tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g*)0;
411 T1_ = usrToCell__system_5270(p);
412 decRef__system_5315(T1_);
413 }
N_INLINE(NI,pluspercent___system_696)414 static N_INLINE(NI, pluspercent___system_696)(NI x, NI y) {
415 NI result;
416 result = (NI)0;
417 result = ((NI) ((NU)((NU32)(((NU) (x))) + (NU32)(((NU) (y))))));
418 return result;
419 }
N_INLINE(void,incRef__system_5308)420 static N_INLINE(void, incRef__system_5308)(tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* c) {
421 (*c).refcount = pluspercent___system_696((*c).refcount, ((NI) 8));
422 }
N_INLINE(void,asgnRef)423 static N_INLINE(void, asgnRef)(void** dest, void* src) {
424 {
425 tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* T5_;
426 if (!!((src == NIM_NIL))) goto LA3_;
427 T5_ = (tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g*)0;
428 T5_ = usrToCell__system_5270(src);
429 incRef__system_5308(T5_);
430 }
431 LA3_: ;
432 {
433 tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g* T10_;
434 if (!!(((*dest) == NIM_NIL))) goto LA8_;
435 T10_ = (tyObject_Cell__1zcF9cV8XIAtbN8h5HRUB8g*)0;
436 T10_ = usrToCell__system_5270((*dest));
437 decRef__system_5315(T10_);
438 }
439 LA8_: ;
440 (*dest) = src;
441 }
N_NOINLINE(void,raiseEIO__systemZio_96)442 N_LIB_PRIVATE N_NOINLINE(void, raiseEIO__systemZio_96)(NimStringDesc* msg) {
443 tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw* T1_;
444 NimStringDesc* T2_;
445 T1_ = NIM_NIL;
446 T1_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*) newObj((&NTIrefioerror__HMIVdYjdZYWskTmTQVo5BQ_), sizeof(tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw));
447 (*T1_).Sup.Sup.Sup.m_type = (&NTIioerror__iLZrPn9anoh9ad1MmO0RczFw_);
448 (*T1_).Sup.Sup.name = "IOError";
449 T2_ = NIM_NIL;
450 T2_ = (*T1_).Sup.Sup.message; (*T1_).Sup.Sup.message = copyStringRC1(msg);
451 if (T2_) nimGCunrefNoCycle(T2_);
452 asgnRef((void**) (&(*T1_).Sup.Sup.parent), ((Exception*) NIM_NIL));
453 raiseExceptionEx((Exception*)T1_, "IOError", "raiseEIO", "io.nim", 139);
454 }
N_NIMCALL(void,checkErr__systemZio_141)455 N_LIB_PRIVATE N_NIMCALL(void, checkErr__systemZio_141)(FILE* f) {
456 {
457 int T3_;
458 NimStringDesc* msg;
459 NimStringDesc* T6_;
460 NimStringDesc* T7_;
461 NCSTRING T8_;
462 NimStringDesc* T9_;
463 T3_ = (int)0;
464 T3_ = ferror(f);
465 if (!!((T3_ == ((NI32) 0)))) goto LA4_;
466 T6_ = NIM_NIL;
467 T7_ = NIM_NIL;
468 T7_ = dollar___systemZdollars_3(((NI) (errno)));
469 T8_ = (NCSTRING)0;
470 T8_ = strerror(errno);
471 T9_ = NIM_NIL;
472 T9_ = cstrToNimstr(T8_);
473 T6_ = rawNewString((T7_ ? T7_->Sup.len : 0) + (T9_ ? T9_->Sup.len : 0) + 10);
474 appendString(T6_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_2));
475 appendString(T6_, T7_);
476 appendString(T6_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_3));
477 appendString(T6_, T9_);
478 appendString(T6_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_4));
479 msg = T6_;
480 clearerr(f);
481 raiseEIO__systemZio_96(msg);
482 }
483 LA4_: ;
484 }
N_NIMCALL(NI,writeBuffer__systemZio_176)485 N_LIB_PRIVATE N_NIMCALL(NI, writeBuffer__systemZio_176)(FILE* f, void* buffer, NI len) {
486 NI result;
487 int T1_;
488 result = (NI)0;
489 T1_ = (int)0;
490 T1_ = fwrite(buffer, ((size_t) 1), ((size_t) (len)), f);
491 result = ((NI) (T1_));
492 checkErr__systemZio_141(f);
493 return result;
494 }
N_NIMCALL(void,write__systemZio_205)495 N_LIB_PRIVATE N_NIMCALL(void, write__systemZio_205)(FILE* f, NimStringDesc* s) {
496 {
497 NI T3_;
498 T3_ = (NI)0;
499 T3_ = writeBuffer__systemZio_176(f, ((void*) (nimToCStringConv(s))), ((NI) ((s ? s->Sup.len : 0))));
500 if (!!((T3_ == (s ? s->Sup.len : 0)))) goto LA4_;
501 raiseEIO__systemZio_96(((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_5));
502 }
503 LA4_: ;
504 }
N_NIMCALL(void,flushFile__systemZio_227)505 N_LIB_PRIVATE N_NIMCALL(void, flushFile__systemZio_227)(FILE* f) {
506 int T1_;
507 T1_ = (int)0;
508 T1_ = fflush(f);
509 (void)(T1_);
510 }
N_NIMCALL(void,close__systemZio_218)511 N_LIB_PRIVATE N_NIMCALL(void, close__systemZio_218)(FILE* f) {
512 {
513 int T5_;
514 if (!!((f == 0))) goto LA3_;
515 T5_ = (int)0;
516 T5_ = fclose(f);
517 (void)(T5_);
518 }
519 LA3_: ;
520 }
N_NIMCALL(NIM_BOOL,setInheritable__systemZio_235)521 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, setInheritable__systemZio_235)(int f, NIM_BOOL inheritable) {
522 NIM_BOOL result;
523 int flags;
524 int T10_;
525 { result = (NIM_BOOL)0;
526 flags = fcntl(f, F_GETFD);
527 {
528 if (!(flags == ((NI32) -1))) goto LA3_;
529 result = NIM_FALSE;
530 goto BeforeRet_;
531 }
532 LA3_: ;
533 {
534 if (!inheritable) goto LA7_;
535 flags = (NI32)(flags & (NI32)((NU32) ~(FD_CLOEXEC)));
536 }
537 goto LA5_;
538 LA7_: ;
539 {
540 flags = (NI32)(flags | FD_CLOEXEC);
541 }
542 LA5_: ;
543 T10_ = (int)0;
544 T10_ = fcntl(f, F_SETFD, flags);
545 result = !((T10_ == ((NI32) -1)));
546 }BeforeRet_: ;
547 return result;
548 }
N_NIMCALL(int,getOsFileHandle__systemZio_232)549 N_LIB_PRIVATE N_NIMCALL(int, getOsFileHandle__systemZio_232)(FILE* f) {
550 int result;
551 result = (int)0;
552 result = fileno(f);
553 return result;
554 }
N_NIMCALL(NIM_BOOL,open__systemZio_391)555 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__systemZio_391)(FILE** f, NimStringDesc* filename, tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg mode, NI bufSize) {
556 NIM_BOOL result;
557 void* p;
558 { result = (NIM_BOOL)0;
559 p = fopen(nimToCStringConv(filename), FormatOpen__systemZio_373[(mode)- 0]);
560 {
561 FILE* f2;
562 struct stat res;
563 if (!!((p == NIM_NIL))) goto LA3_;
564 f2 = ((FILE*) (p));
565 {
566 NIM_BOOL T7_;
567 int T8_;
568 int T9_;
569 T7_ = (NIM_BOOL)0;
570 T8_ = (int)0;
571 T8_ = getFileHandle__systemZio_229(f2);
572 T9_ = (int)0;
573 T9_ = fstat(T8_, (&res));
574 T7_ = (((NI32) 0) <= T9_);
575 if (!(T7_)) goto LA10_;
576 T7_ = S_ISDIR(res.st_mode);
577 LA10_: ;
578 if (!T7_) goto LA11_;
579 close__systemZio_218(f2);
580 result = NIM_FALSE;
581 goto BeforeRet_;
582 }
583 LA11_: ;
584 {
585 int T15_;
586 NIM_BOOL T16_;
587 T15_ = (int)0;
588 T15_ = getOsFileHandle__systemZio_232(f2);
589 T16_ = (NIM_BOOL)0;
590 T16_ = setInheritable__systemZio_235(T15_, NIM_FALSE);
591 if (!!(T16_)) goto LA17_;
592 close__systemZio_218(f2);
593 result = NIM_FALSE;
594 goto BeforeRet_;
595 }
596 LA17_: ;
597 result = NIM_TRUE;
598 (*f) = ((FILE*) (p));
599 {
600 NIM_BOOL T21_;
601 int T25_;
602 T21_ = (NIM_BOOL)0;
603 T21_ = (((NI) 0) < bufSize);
604 if (!(T21_)) goto LA22_;
605 T21_ = (bufSize <= ((NI) 2147483647));
606 LA22_: ;
607 if (!T21_) goto LA23_;
608 T25_ = (int)0;
609 T25_ = setvbuf((*f), NIM_NIL, _IOFBF, ((size_t) (bufSize)));
610 (void)(T25_);
611 }
612 goto LA19_;
613 LA23_: ;
614 {
615 int T29_;
616 if (!(bufSize == ((NI) 0))) goto LA27_;
617 T29_ = (int)0;
618 T29_ = setvbuf((*f), NIM_NIL, _IONBF, ((size_t) 0));
619 (void)(T29_);
620 }
621 goto LA19_;
622 LA27_: ;
623 LA19_: ;
624 }
625 LA3_: ;
626 }BeforeRet_: ;
627 return result;
628 }
N_NIMCALL(FILE *,open__systemZio_432)629 N_LIB_PRIVATE N_NIMCALL(FILE*, open__systemZio_432)(NimStringDesc* filename, tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg mode, NI bufSize) {
630 FILE* result;
631 result = (FILE*)0;
632 {
633 NIM_BOOL T3_;
634 tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw* T6_;
635 NimStringDesc* T7_;
636 T3_ = (NIM_BOOL)0;
637 T3_ = open__systemZio_391(&result, filename, mode, bufSize);
638 if (!!(T3_)) goto LA4_;
639 T6_ = NIM_NIL;
640 T6_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*) newObj((&NTIrefioerror__HMIVdYjdZYWskTmTQVo5BQ_), sizeof(tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw));
641 (*T6_).Sup.Sup.Sup.m_type = (&NTIioerror__iLZrPn9anoh9ad1MmO0RczFw_);
642 (*T6_).Sup.Sup.name = "IOError";
643 T7_ = NIM_NIL;
644 T7_ = rawNewString((filename ? filename->Sup.len : 0) + 13);
645 appendString(T7_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_6));
646 appendString(T7_, filename);
647 asgnRef((void**) (&(*T6_).Sup.Sup.message), T7_);
648 asgnRef((void**) (&(*T6_).Sup.Sup.parent), ((Exception*) NIM_NIL));
649 raiseExceptionEx((Exception*)T6_, "IOError", "open", "io.nim", 745);
650 }
651 LA4_: ;
652 return result;
653 }
N_INLINE(NIM_BOOL,eqeq___system_7723)654 static N_INLINE(NIM_BOOL, eqeq___system_7723)(NCSTRING x, NCSTRING y) {
655 NIM_BOOL result;
656 result = (NIM_BOOL)0;
657 {
658 if (!(((void*) (x)) == ((void*) (y)))) goto LA3_;
659 result = NIM_TRUE;
660 }
661 goto LA1_;
662 LA3_: ;
663 {
664 NIM_BOOL T6_;
665 T6_ = (NIM_BOOL)0;
666 T6_ = (x == 0);
667 if (T6_) goto LA7_;
668 T6_ = (y == 0);
669 LA7_: ;
670 if (!T6_) goto LA8_;
671 result = NIM_FALSE;
672 }
673 goto LA1_;
674 LA8_: ;
675 {
676 int T11_;
677 T11_ = (int)0;
678 T11_ = strcmp(x, y);
679 result = (T11_ == ((NI32) 0));
680 }
681 LA1_: ;
682 return result;
683 }
N_NIMCALL(NIM_BOOL,readLine__systemZio_240)684 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, readLine__systemZio_240)(FILE* f, NimStringDesc** line) {
685 NIM_BOOL result;
686 NI pos;
687 NI sp;
688 { result = (NIM_BOOL)0;
689 pos = ((NI) 0);
690 sp = ((((*line) ? (*line)->Sup.len : 0) >= ((NI) 80)) ? ((*line) ? (*line)->Sup.len : 0) : ((NI) 80));
691 unsureAsgnRef((void**) (&(*line)), setLengthStr((*line), ((NI) (sp))));
692 {
693 while (1) {
694 NIM_BOOL fgetsSuccess;
695 void* m;
696 {
697 NI i;
698 NI i_2;
699 i = (NI)0;
700 i_2 = ((NI) 0);
701 {
702 while (1) {
703 if (!(i_2 < sp)) goto LA5;
704 i = i_2;
705 (*line)->data[(NI)(pos + i)] = 10;
706 i_2 += ((NI) 1);
707 } LA5: ;
708 }
709 }
710 fgetsSuccess = (NIM_BOOL)0;
711 {
712 while (1) {
713 {
714 NCSTRING T9_;
715 NIM_BOOL T10_;
716 T9_ = (NCSTRING)0;
717 T9_ = fgets(((NCSTRING) ((&(*line)->data[pos]))), ((int) (sp)), f);
718 T10_ = (NIM_BOOL)0;
719 T10_ = eqeq___system_7723(T9_, ((NCSTRING) NIM_NIL));
720 fgetsSuccess = !(T10_);
721 {
722 if (!fgetsSuccess) goto LA13_;
723 goto LA6;
724 }
725 LA13_: ;
726 {
727 if (!(errno == EINTR)) goto LA17_;
728 errno = ((int) 0);
729 clearerr(f);
730 goto LA8;
731 }
732 LA17_: ;
733 checkErr__systemZio_141(f);
734 goto LA6;
735 } LA8: ;
736 }
737 } LA6: ;
738 m = memchr(((void*) ((&(*line)->data[pos]))), ((int) 10), ((size_t) (sp)));
739 {
740 NI last;
741 NIM_BOOL T42_;
742 if (!!((m == NIM_NIL))) goto LA21_;
743 last = (NI)(((NI) (ptrdiff_t) (m)) - ((NI) (ptrdiff_t) ((&(*line)->data[((NI) 0)]))));
744 {
745 NIM_BOOL T25_;
746 NIM_BOOL T29_;
747 T25_ = (NIM_BOOL)0;
748 T25_ = (((NI) 0) < last);
749 if (!(T25_)) goto LA26_;
750 T25_ = ((NU8)((*line)->data[(NI)(last - ((NI) 1))]) == (NU8)(13));
751 LA26_: ;
752 if (!T25_) goto LA27_;
753 unsureAsgnRef((void**) (&(*line)), setLengthStr((*line), ((NI) ((NI)(last - ((NI) 1))))));
754 T29_ = (NIM_BOOL)0;
755 T29_ = (((NI) 1) < last);
756 if (T29_) goto LA30_;
757 T29_ = fgetsSuccess;
758 LA30_: ;
759 result = T29_;
760 goto BeforeRet_;
761 }
762 goto LA23_;
763 LA27_: ;
764 {
765 NIM_BOOL T32_;
766 T32_ = (NIM_BOOL)0;
767 T32_ = (((NI) 0) < last);
768 if (!(T32_)) goto LA33_;
769 T32_ = ((NU8)((*line)->data[(NI)(last - ((NI) 1))]) == (NU8)(0));
770 LA33_: ;
771 if (!T32_) goto LA34_;
772 {
773 NIM_BOOL T38_;
774 T38_ = (NIM_BOOL)0;
775 T38_ = (last < (NI)((NI)(pos + sp) - ((NI) 1)));
776 if (!(T38_)) goto LA39_;
777 T38_ = !(((NU8)((*line)->data[(NI)(last + ((NI) 1))]) == (NU8)(0)));
778 LA39_: ;
779 if (!T38_) goto LA40_;
780 last -= ((NI) 1);
781 }
782 LA40_: ;
783 }
784 goto LA23_;
785 LA34_: ;
786 LA23_: ;
787 unsureAsgnRef((void**) (&(*line)), setLengthStr((*line), ((NI) (last))));
788 T42_ = (NIM_BOOL)0;
789 T42_ = (((NI) 0) < last);
790 if (T42_) goto LA43_;
791 T42_ = fgetsSuccess;
792 LA43_: ;
793 result = T42_;
794 goto BeforeRet_;
795 }
796 goto LA19_;
797 LA21_: ;
798 {
799 sp -= ((NI) 1);
800 }
801 LA19_: ;
802 pos += sp;
803 sp = ((NI) 128);
804 unsureAsgnRef((void**) (&(*line)), setLengthStr((*line), ((NI) ((NI)(pos + sp)))));
805 }
806 }
807 }BeforeRet_: ;
808 return result;
809 }
N_INLINE(void,pushSafePoint)810 static N_INLINE(void, pushSafePoint)(TSafePoint* s) {
811 (*s).prev = excHandler__system_2565;
812 excHandler__system_2565 = s;
813 }
N_NIMCALL(NI64,rawFileSize__systemZio_335)814 N_LIB_PRIVATE N_NIMCALL(NI64, rawFileSize__systemZio_335)(FILE* file) {
815 NI64 result;
816 NI64 oldPos;
817 int T1_;
818 int T2_;
819 result = (NI64)0;
820 oldPos = ftello(file);
821 T1_ = (int)0;
822 T1_ = fseeko(file, IL64(0), ((int) 2));
823 (void)(T1_);
824 result = ftello(file);
825 T2_ = (int)0;
826 T2_ = fseeko(file, oldPos, ((int) 0));
827 (void)(T2_);
828 return result;
829 }
N_NIMCALL(NI,readBuffer__systemZio_144)830 N_LIB_PRIVATE N_NIMCALL(NI, readBuffer__systemZio_144)(FILE* f, void* buffer, NI len) {
831 NI result;
832 size_t T1_;
833 result = (NI)0;
834 T1_ = (size_t)0;
835 T1_ = fread(buffer, ((size_t) 1), ((size_t) (len)), f);
836 result = ((NI) (T1_));
837 {
838 if (!!((result == ((NI) (len))))) goto LA4_;
839 checkErr__systemZio_141(f);
840 }
841 LA4_: ;
842 return result;
843 }
N_NIMCALL(NIM_BOOL,endOfFile__systemZio_339)844 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, endOfFile__systemZio_339)(FILE* f) {
845 NIM_BOOL result;
846 int c;
847 int T1_;
848 { result = (NIM_BOOL)0;
849 c = fgetc(f);
850 T1_ = (int)0;
851 T1_ = ungetc(c, f);
852 (void)(T1_);
853 result = (c < ((NI32) 0));
854 goto BeforeRet_;
855 }BeforeRet_: ;
856 return result;
857 }
N_NIMCALL(NimStringDesc *,readAllBuffer__systemZio_330)858 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAllBuffer__systemZio_330)(FILE* file) {
859 NimStringDesc* result;
860 NimStringDesc* buffer;
861 result = NIM_NIL;
862 result = ((NimStringDesc*) NIM_NIL);
863 buffer = mnewString(((NI) 4000));
864 {
865 while (1) {
866 NI bytesRead;
867 bytesRead = readBuffer__systemZio_144(file, ((void*) ((&buffer->data[((NI) 0)]))), ((NI) 4000));
868 {
869 if (!(bytesRead == ((NI) 4000))) goto LA5_;
870 result = resizeString(result, (buffer ? buffer->Sup.len : 0) + 0);
871 appendString(result, buffer);
872 }
873 goto LA3_;
874 LA5_: ;
875 {
876 buffer = setLengthStr(buffer, ((NI) (bytesRead)));
877 result = resizeString(result, (buffer ? buffer->Sup.len : 0) + 0);
878 appendString(result, buffer);
879 goto LA1;
880 }
881 LA3_: ;
882 }
883 } LA1: ;
884 return result;
885 }
N_NIMCALL(NimStringDesc *,readAllFile__systemZio_343)886 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAllFile__systemZio_343)(FILE* file, NI64 len) {
887 NimStringDesc* result;
888 NI bytes;
889 result = NIM_NIL;
890 result = mnewString(((NI) (len)));
891 bytes = readBuffer__systemZio_144(file, ((void*) ((&result->data[((NI) 0)]))), ((NI) (len)));
892 {
893 NIM_BOOL T3_;
894 T3_ = (NIM_BOOL)0;
895 T3_ = endOfFile__systemZio_339(file);
896 if (!T3_) goto LA4_;
897 {
898 if (!(((NI64) (bytes)) < len)) goto LA8_;
899 result = setLengthStr(result, ((NI) (bytes)));
900 }
901 LA8_: ;
902 }
903 goto LA1_;
904 LA4_: ;
905 {
906 NimStringDesc* T11_;
907 T11_ = NIM_NIL;
908 T11_ = readAllBuffer__systemZio_330(file);
909 result = resizeString(result, (T11_ ? T11_->Sup.len : 0) + 0);
910 appendString(result, T11_);
911 }
912 LA1_: ;
913 return result;
914 }
N_NIMCALL(NimStringDesc *,readAll__systemZio_352)915 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readAll__systemZio_352)(FILE* file) {
916 NimStringDesc* result;
917 NI64 len;
918 result = NIM_NIL;
919 {
920 if (!!((file == stdin))) goto LA3_;
921 len = rawFileSize__systemZio_335(file);
922 }
923 goto LA1_;
924 LA3_: ;
925 {
926 len = IL64(-1);
927 }
928 LA1_: ;
929 {
930 if (!(IL64(0) < len)) goto LA8_;
931 result = readAllFile__systemZio_343(file, len);
932 }
933 goto LA6_;
934 LA8_: ;
935 {
936 result = readAllBuffer__systemZio_330(file);
937 }
938 LA6_: ;
939 return result;
940 }
N_INLINE(void,popSafePoint)941 static N_INLINE(void, popSafePoint)(void) {
942 excHandler__system_2565 = (*excHandler__system_2565).prev;
943 }
N_NIMCALL(NimStringDesc *,readFile__systemZio_471)944 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readFile__systemZio_471)(NimStringDesc* filename) {
945 NimStringDesc* volatile result;
946 FILE* f;
947 result = NIM_NIL;
948 f = ((FILE*) NIM_NIL);
949 {
950 NIM_BOOL T3_;
951 TSafePoint TM__MnCJ0VAmeZ9aTATUB39cx60Q_7;
952 T3_ = (NIM_BOOL)0;
953 T3_ = open__systemZio_391(&f, filename, ((tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg) 0), ((NI) -1));
954 if (!T3_) goto LA4_;
955 pushSafePoint(&TM__MnCJ0VAmeZ9aTATUB39cx60Q_7);
956 TM__MnCJ0VAmeZ9aTATUB39cx60Q_7.status = _setjmp(TM__MnCJ0VAmeZ9aTATUB39cx60Q_7.context);
957 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_7.status == 0) {
958 result = readAll__systemZio_352(f);
959 popSafePoint();
960 }
961 else {
962 popSafePoint();
963 }
964 {
965 close__systemZio_218(f);
966 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_7.status != 0) nimLeaveFinally();
967 }
968 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_7.status != 0) reraiseException();
969 }
970 goto LA1_;
971 LA4_: ;
972 {
973 tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw* T9_;
974 NimStringDesc* T10_;
975 T9_ = NIM_NIL;
976 T9_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*) newObj((&NTIrefioerror__HMIVdYjdZYWskTmTQVo5BQ_), sizeof(tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw));
977 (*T9_).Sup.Sup.Sup.m_type = (&NTIioerror__iLZrPn9anoh9ad1MmO0RczFw_);
978 (*T9_).Sup.Sup.name = "IOError";
979 T10_ = NIM_NIL;
980 T10_ = rawNewString((filename ? filename->Sup.len : 0) + 13);
981 appendString(T10_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_6));
982 appendString(T10_, filename);
983 asgnRef((void**) (&(*T9_).Sup.Sup.message), T10_);
984 asgnRef((void**) (&(*T9_).Sup.Sup.parent), ((Exception*) NIM_NIL));
985 raiseExceptionEx((Exception*)T9_, "IOError", "readFile", "io.nim", 853);
986 }
987 LA1_: ;
988 return result;
989 }
N_NIMCALL(NI,readChars__systemZio_156)990 N_LIB_PRIVATE N_NIMCALL(NI, readChars__systemZio_156)(FILE* f, NIM_CHAR* a, NI aLen_0) {
991 NI result;
992 result = (NI)0;
993 result = readBuffer__systemZio_144(f, ((void*) ((&a[((NI) 0)]))), ((NI) (aLen_0)));
994 return result;
995 }
N_NOINLINE(void,raiseEOF__systemZio_117)996 N_LIB_PRIVATE N_NOINLINE(void, raiseEOF__systemZio_117)(void) {
997 tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg* T1_;
998 NimStringDesc* T2_;
999 T1_ = NIM_NIL;
1000 T1_ = (tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg*) newObj((&NTIrefeoferror__LEclZrWX2FQAodlapxGITw_), sizeof(tyObject_EOFError__KGSY1JdrNB7Xi8KDhXFhSg));
1001 (*T1_).Sup.Sup.Sup.Sup.m_type = (&NTIeoferror__KGSY1JdrNB7Xi8KDhXFhSg_);
1002 (*T1_).Sup.Sup.Sup.name = "EOFError";
1003 T2_ = NIM_NIL;
1004 T2_ = (*T1_).Sup.Sup.Sup.message; (*T1_).Sup.Sup.Sup.message = copyStringRC1(((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_8));
1005 if (T2_) nimGCunrefNoCycle(T2_);
1006 asgnRef((void**) (&(*T1_).Sup.Sup.Sup.parent), ((Exception*) NIM_NIL));
1007 raiseExceptionEx((Exception*)T1_, "EOFError", "raiseEOF", "io.nim", 142);
1008 }
N_NIMCALL(NimStringDesc *,readLine__systemZio_273)1009 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, readLine__systemZio_273)(FILE* f) {
1010 NimStringDesc* result;
1011 result = NIM_NIL;
1012 result = rawNewString(((NI) 80));
1013 {
1014 NIM_BOOL T3_;
1015 T3_ = (NIM_BOOL)0;
1016 T3_ = readLine__systemZio_240(f, (&result));
1017 if (!!(T3_)) goto LA4_;
1018 raiseEOF__systemZio_117();
1019 }
1020 LA4_: ;
1021 return result;
1022 }
N_NIMCALL(void,writeFile__systemZio_476)1023 N_LIB_PRIVATE N_NIMCALL(void, writeFile__systemZio_476)(NimStringDesc* filename, NimStringDesc* content) {
1024 FILE* f;
1025 f = ((FILE*) NIM_NIL);
1026 {
1027 NIM_BOOL T3_;
1028 TSafePoint TM__MnCJ0VAmeZ9aTATUB39cx60Q_9;
1029 T3_ = (NIM_BOOL)0;
1030 T3_ = open__systemZio_391(&f, filename, ((tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg) 1), ((NI) -1));
1031 if (!T3_) goto LA4_;
1032 pushSafePoint(&TM__MnCJ0VAmeZ9aTATUB39cx60Q_9);
1033 TM__MnCJ0VAmeZ9aTATUB39cx60Q_9.status = _setjmp(TM__MnCJ0VAmeZ9aTATUB39cx60Q_9.context);
1034 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_9.status == 0) {
1035 write__systemZio_205(f, content);
1036 popSafePoint();
1037 }
1038 else {
1039 popSafePoint();
1040 }
1041 {
1042 close__systemZio_218(f);
1043 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_9.status != 0) nimLeaveFinally();
1044 }
1045 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_9.status != 0) reraiseException();
1046 }
1047 goto LA1_;
1048 LA4_: ;
1049 {
1050 tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw* T9_;
1051 NimStringDesc* T10_;
1052 T9_ = NIM_NIL;
1053 T9_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*) newObj((&NTIrefioerror__HMIVdYjdZYWskTmTQVo5BQ_), sizeof(tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw));
1054 (*T9_).Sup.Sup.Sup.m_type = (&NTIioerror__iLZrPn9anoh9ad1MmO0RczFw_);
1055 (*T9_).Sup.Sup.name = "IOError";
1056 T10_ = NIM_NIL;
1057 T10_ = rawNewString((filename ? filename->Sup.len : 0) + 13);
1058 appendString(T10_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_6));
1059 appendString(T10_, filename);
1060 asgnRef((void**) (&(*T9_).Sup.Sup.message), T10_);
1061 asgnRef((void**) (&(*T9_).Sup.Sup.parent), ((Exception*) NIM_NIL));
1062 raiseExceptionEx((Exception*)T9_, "IOError", "writeFile", "io.nim", 866);
1063 }
1064 LA1_: ;
1065 }
N_NIMCALL(tySequence__sM4lkSb7zS6F7OVMvW9cffQ *,readLines__systemZio_494)1066 N_LIB_PRIVATE N_NIMCALL(tySequence__sM4lkSb7zS6F7OVMvW9cffQ*, readLines__systemZio_494)(NimStringDesc* filename, NI n) {
1067 tySequence__sM4lkSb7zS6F7OVMvW9cffQ* volatile result;
1068 FILE* f;
1069 result = NIM_NIL;
1070 f = ((FILE*) NIM_NIL);
1071 {
1072 NIM_BOOL T3_;
1073 TSafePoint TM__MnCJ0VAmeZ9aTATUB39cx60Q_10;
1074 T3_ = (NIM_BOOL)0;
1075 T3_ = open__systemZio_391(&f, filename, ((tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg) 0), ((NI) -1));
1076 if (!T3_) goto LA4_;
1077 pushSafePoint(&TM__MnCJ0VAmeZ9aTATUB39cx60Q_10);
1078 TM__MnCJ0VAmeZ9aTATUB39cx60Q_10.status = _setjmp(TM__MnCJ0VAmeZ9aTATUB39cx60Q_10.context);
1079 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_10.status == 0) {
1080 result = newSeq__systemZio_503(n);
1081 {
1082 NI i;
1083 NI colontmp_;
1084 NI res;
1085 i = (NI)0;
1086 colontmp_ = (NI)0;
1087 colontmp_ = (NI)(((NI) (n)) - ((NI) 1));
1088 res = ((NI) 0);
1089 {
1090 while (1) {
1091 if (!(res <= colontmp_)) goto LA8;
1092 i = res;
1093 {
1094 NIM_BOOL T11_;
1095 T11_ = (NIM_BOOL)0;
1096 T11_ = readLine__systemZio_240(f, (&result->data[i]));
1097 if (!!(T11_)) goto LA12_;
1098 raiseEOF__systemZio_117();
1099 }
1100 LA12_: ;
1101 res += ((NI) 1);
1102 } LA8: ;
1103 }
1104 }
1105 popSafePoint();
1106 }
1107 else {
1108 popSafePoint();
1109 }
1110 {
1111 close__systemZio_218(f);
1112 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_10.status != 0) nimLeaveFinally();
1113 }
1114 if (TM__MnCJ0VAmeZ9aTATUB39cx60Q_10.status != 0) reraiseException();
1115 }
1116 goto LA1_;
1117 LA4_: ;
1118 {
1119 tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw* T17_;
1120 NimStringDesc* T18_;
1121 T17_ = NIM_NIL;
1122 T17_ = (tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw*) newObj((&NTIrefioerror__HMIVdYjdZYWskTmTQVo5BQ_), sizeof(tyObject_IOError__iLZrPn9anoh9ad1MmO0RczFw));
1123 (*T17_).Sup.Sup.Sup.m_type = (&NTIioerror__iLZrPn9anoh9ad1MmO0RczFw_);
1124 (*T17_).Sup.Sup.name = "IOError";
1125 T18_ = NIM_NIL;
1126 T18_ = rawNewString((filename ? filename->Sup.len : 0) + 13);
1127 appendString(T18_, ((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_6));
1128 appendString(T18_, filename);
1129 asgnRef((void**) (&(*T17_).Sup.Sup.message), T18_);
1130 asgnRef((void**) (&(*T17_).Sup.Sup.parent), ((Exception*) NIM_NIL));
1131 raiseExceptionEx((Exception*)T17_, "IOError", "readLines", "io.nim", 896);
1132 }
1133 LA1_: ;
1134 return result;
1135 }
N_NIMCALL(NIM_BOOL,open__systemZio_422)1136 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__systemZio_422)(FILE** f, int filehandle, tyEnum_FileMode__ZJfK20XeZ9bv2j1pZjw9aswg mode) {
1137 NIM_BOOL result;
1138 int oshandle;
1139 { result = (NIM_BOOL)0;
1140 oshandle = filehandle;
1141 {
1142 NIM_BOOL T3_;
1143 T3_ = (NIM_BOOL)0;
1144 T3_ = setInheritable__systemZio_235(oshandle, NIM_FALSE);
1145 if (!!(T3_)) goto LA4_;
1146 result = NIM_FALSE;
1147 goto BeforeRet_;
1148 }
1149 LA4_: ;
1150 (*f) = fdopen(filehandle, FormatOpen__systemZio_373[(mode)- 0]);
1151 result = !(((*f) == ((FILE*) NIM_NIL)));
1152 }BeforeRet_: ;
1153 return result;
1154 }
N_NIMCALL(void,setFilePos__systemZio_438)1155 N_LIB_PRIVATE N_NIMCALL(void, setFilePos__systemZio_438)(FILE* f, NI64 pos, tyEnum_FileSeekPos__I9aQjuvWxs8BspGbxwsngWw relativeTo) {
1156 {
1157 int T3_;
1158 T3_ = (int)0;
1159 T3_ = fseeko(f, pos, ((int) (relativeTo)));
1160 if (!!((T3_ == ((NI32) 0)))) goto LA4_;
1161 raiseEIO__systemZio_96(((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_11));
1162 }
1163 LA4_: ;
1164 }
N_NIMCALL(NI64,getFilePos__systemZio_451)1165 N_LIB_PRIVATE N_NIMCALL(NI64, getFilePos__systemZio_451)(FILE* f) {
1166 NI64 result;
1167 result = (NI64)0;
1168 result = ftello(f);
1169 {
1170 if (!(result < IL64(0))) goto LA3_;
1171 raiseEIO__systemZio_96(((NimStringDesc*) &TM__MnCJ0VAmeZ9aTATUB39cx60Q_12));
1172 }
1173 LA3_: ;
1174 return result;
1175 }
N_NIMCALL(void,write__systemZio_306)1176 N_LIB_PRIVATE N_NIMCALL(void, write__systemZio_306)(FILE* f, NimStringDesc** a, NI aLen_0) {
1177 {
1178 NimStringDesc** x;
1179 NI i;
1180 x = (NimStringDesc**)0;
1181 i = ((NI) 0);
1182 {
1183 while (1) {
1184 if (!(i < aLen_0)) goto LA3;
1185 x = (&a[i]);
1186 write__systemZio_205(f, (*x));
1187 i += ((NI) 1);
1188 } LA3: ;
1189 }
1190 }
1191 }
N_NIMCALL(void,stdlib_ioDatInit000)1192 N_LIB_PRIVATE N_NIMCALL(void, stdlib_ioDatInit000)(void) {
1193 static TNimNode TM__MnCJ0VAmeZ9aTATUB39cx60Q_0[1];
1194 NTIcfile__MAWzaQJYFu3mlxj0Ppxhmw_.size = sizeof(void*);
1195 NTIcfile__MAWzaQJYFu3mlxj0Ppxhmw_.align = NIM_ALIGNOF(void*);
1196 NTIcfile__MAWzaQJYFu3mlxj0Ppxhmw_.kind = 18;
1197 NTIcfile__MAWzaQJYFu3mlxj0Ppxhmw_.base = 0;
1198 NTIcfile__MAWzaQJYFu3mlxj0Ppxhmw_.flags = 1;
1199 NTIcfile__MAWzaQJYFu3mlxj0Ppxhmw_.node = &TM__MnCJ0VAmeZ9aTATUB39cx60Q_0[0];
1200 NTIfile__XBeRj4rw9bUuE7CB3DS1rgg_.size = sizeof(FILE*);
1201 NTIfile__XBeRj4rw9bUuE7CB3DS1rgg_.align = NIM_ALIGNOF(FILE*);
1202 NTIfile__XBeRj4rw9bUuE7CB3DS1rgg_.kind = 21;
1203 NTIfile__XBeRj4rw9bUuE7CB3DS1rgg_.base = (&NTIcfile__MAWzaQJYFu3mlxj0Ppxhmw_);
1204 NTIfile__XBeRj4rw9bUuE7CB3DS1rgg_.flags = 3;
1205 NTIfilehandle__2gIj3gQlK3HZJjQaYCP6ZQ_.size = sizeof(int);
1206 NTIfilehandle__2gIj3gQlK3HZJjQaYCP6ZQ_.align = NIM_ALIGNOF(int);
1207 NTIfilehandle__2gIj3gQlK3HZJjQaYCP6ZQ_.kind = 34;
1208 NTIfilehandle__2gIj3gQlK3HZJjQaYCP6ZQ_.base = 0;
1209 NTIfilehandle__2gIj3gQlK3HZJjQaYCP6ZQ_.flags = 3;
1210 }
1211
1212