/* Generated by Nim Compiler v0.12.0 */
/*   (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32

#include "nimbase.h"
#include <stdio.h>
#include <setjmp.h>
#include <string.h>
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Streamobj150427 Streamobj150427;
typedef struct TNimObject TNimObject;
typedef struct Filestreamobj151667 Filestreamobj151667;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Exception Exception;
typedef struct TSafePoint TSafePoint;
typedef struct Ioerror4031 Ioerror4031;
typedef struct Systemerror4029 Systemerror4029;
typedef struct Cell49147 Cell49147;
typedef struct Cellseq49163 Cellseq49163;
typedef struct Gcheap51218 Gcheap51218;
typedef struct Gcstack51216 Gcstack51216;
typedef struct Cellset49159 Cellset49159;
typedef struct Pagedesc49155 Pagedesc49155;
typedef struct Memregion31090 Memregion31090;
typedef struct Smallchunk31042 Smallchunk31042;
typedef struct Llchunk31084 Llchunk31084;
typedef struct Bigchunk31044 Bigchunk31044;
typedef struct Intset31017 Intset31017;
typedef struct Trunk31013 Trunk31013;
typedef struct Avlnode31088 Avlnode31088;
typedef struct Gcstat51214 Gcstat51214;
typedef struct Stringstreamobj151511 Stringstreamobj151511;
typedef struct Basechunk31040 Basechunk31040;
typedef struct Freecell31032 Freecell31032;
typedef N_NIMCALL_PTR(void, TY3889) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3894) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3889 marker;
TY3894 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  TNimObject  {
TNimType* m_type;
};
typedef N_NIMCALL_PTR(void, TY150428) (Streamobj150427* s);
typedef N_NIMCALL_PTR(NIM_BOOL, TY150432) (Streamobj150427* s);
typedef N_NIMCALL_PTR(void, TY150436) (Streamobj150427* s, NI pos);
typedef N_NIMCALL_PTR(NI, TY150441) (Streamobj150427* s);
typedef N_NIMCALL_PTR(NI, TY150445) (Streamobj150427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(NI, TY150451) (Streamobj150427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY150457) (Streamobj150427* s, void* buffer, NI buflen);
typedef N_NIMCALL_PTR(void, TY150463) (Streamobj150427* s);
struct  Streamobj150427  {
  TNimObject Sup;
TY150428 closeimpl;
TY150432 atendimpl;
TY150436 setpositionimpl;
TY150441 getpositionimpl;
TY150445 readdataimpl;
TY150451 peekdataimpl;
TY150457 writedataimpl;
TY150463 flushimpl;
};
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Filestreamobj151667  {
  Streamobj150427 Sup;
FILE* f;
};
struct  Exception  {
  TNimObject Sup;
Exception* parent;
NCSTRING name;
NimStringDesc* message;
NimStringDesc* trace;
};
typedef struct {
N_NIMCALL_PTR(NIM_BOOL, ClPrc) (Exception* e, void* ClEnv);
void* ClEnv;
} TY19411;
struct  TSafePoint  {
TSafePoint* prev;
NI status;
jmp_buf context;
NIM_BOOL hasRaiseAction;
TY19411 raiseAction;
};
struct  Systemerror4029  {
  Exception Sup;
};
struct  Ioerror4031  {
  Systemerror4029 Sup;
};
struct  Cell49147  {
NI refcount;
TNimType* typ;
};
struct  Cellseq49163  {
NI len;
NI cap;
Cell49147** d;
};
struct  Cellset49159  {
NI counter;
NI max;
Pagedesc49155* head;
Pagedesc49155** data;
};
typedef Smallchunk31042* TY31105[512];
typedef Trunk31013* Trunkbuckets31015[256];
struct  Intset31017  {
Trunkbuckets31015 data;
};
struct  Memregion31090  {
NI minlargeobj;
NI maxlargeobj;
TY31105 freesmallchunks;
Llchunk31084* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk31044* freechunkslist;
Intset31017 chunkstarts;
Avlnode31088* root;
Avlnode31088* deleted;
Avlnode31088* last;
Avlnode31088* freeavlnodes;
};
struct  Gcstat51214  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51218  {
Gcstack51216* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq49163 zct;
Cellseq49163 decstack;
Cellset49159 cycleroots;
Cellseq49163 tempstack;
NI recgclock;
Memregion31090 region;
Gcstat51214 stat;
};
struct  Stringstreamobj151511  {
  Streamobj150427 Sup;
NimStringDesc* data;
NI pos;
};
struct  Gcstack51216  {
Gcstack51216* prev;
Gcstack51216* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY31021[16];
struct  Pagedesc49155  {
Pagedesc49155* next;
NI key;
TY31021 bits;
};
struct  Basechunk31040  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk31042  {
  Basechunk31040 Sup;
Smallchunk31042* next;
Smallchunk31042* prev;
Freecell31032* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk31084  {
NI size;
NI acc;
Llchunk31084* next;
};
struct  Bigchunk31044  {
  Basechunk31040 Sup;
Bigchunk31044* next;
Bigchunk31044* prev;
NI align;
NF data;
};
struct  Trunk31013  {
Trunk31013* next;
NI key;
TY31021 bits;
};
typedef Avlnode31088* TY31095[2];
struct  Avlnode31088  {
TY31095 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell31032  {
Freecell31032* next;
NI zerofield;
};
N_NIMCALL(void, TMP2789)(void* p, NI op);
N_NIMCALL(NIM_BOOL, open_17003)(FILE** f, NimStringDesc* filename, NU8 mode, NI bufsize);
N_NIMCALL(Filestreamobj151667*, newfilestream_151743)(FILE* f);
N_NIMCALL(void, TMP2790)(void* p, NI op);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
N_NIMCALL(void, fsclose_151671)(Streamobj150427* s);
N_NIMCALL(NIM_BOOL, fsatend_151695)(Streamobj150427* s);
N_NIMCALL(NIM_BOOL, endoffile_17060)(FILE* f);
N_NIMCALL(void, fssetposition_151702)(Streamobj150427* s, NI pos);
N_NIMCALL(void, setfilepos_17187)(FILE* f, NI64 pos);
N_NIMCALL(NI, fsgetposition_151709)(Streamobj150427* s);
N_NIMCALL(NI64, getfilepos_17191)(FILE* f);
N_NIMCALL(NI, fsreaddata_151716)(Streamobj150427* s, void* buffer, NI buflen);
N_NIMCALL(NI, readbuffer_17160)(FILE* f, void* buffer, NI len);
N_NIMCALL(NI, fspeekdata_151725)(Streamobj150427* s, void* buffer, NI buflen);
static N_INLINE(void, pushSafePoint)(TSafePoint* s);
static N_INLINE(void, popSafePoint)(void);
N_NIMCALL(void, reraiseException)(void);
N_NIMCALL(void, fswritedata_151735)(Streamobj150427* s, void* buffer, NI buflen);
N_NIMCALL(NI, writebuffer_17182)(FILE* f, void* buffer, NI len);
N_NIMCALL(Ioerror4031*, neweio_150405)(NimStringDesc* msg);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(Cell49147*, usrtocell_52846)(void* usr);
static N_INLINE(void, rtladdzct_54404)(Cell49147* c);
N_NOINLINE(void, addzct_52817)(Cellseq49163* s, Cell49147* c);
N_NIMCALL(void, raiseException)(Exception* e, NCSTRING ename);
N_NIMCALL(void, fsflush_151689)(Streamobj150427* s);
N_NIMCALL(void, writedata_150648)(Streamobj150427* s, void* buffer, NI buflen);
N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_NIMCALL(NIM_CHAR, readchar_150784)(Streamobj150427* s);
N_NIMCALL(NI, readdata_150580)(Streamobj150427* s, void* buffer, NI buflen);
N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP3058)(void* p, NI op);
N_NIMCALL(void, ssclose_151636)(Streamobj150427* s_151638);
N_NIMCALL(NIM_BOOL, ssatend_151522)(Streamobj150427* s_151524);
N_NIMCALL(void, sssetposition_151533)(Streamobj150427* s_151535, NI pos);
N_NIMCALL(NI, clamp_151539)(NI x, NI a, NI b);
N_NIMCALL(NI, ssgetposition_151558)(Streamobj150427* s_151560);
N_NIMCALL(NI, ssreaddata_151569)(Streamobj150427* s_151571, void* buffer, NI buflen);
N_NIMCALL(NI, sspeekdata_151596)(Streamobj150427* s_151598, void* buffer, NI buflen);
N_NIMCALL(void, sswritedata_151614)(Streamobj150427* s_151616, void* buffer, NI buflen);
N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newlen);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
STRING_LITERAL(TMP2794, "cannot write to stream", 22);
STRING_LITERAL(TMP3014, "", 0);
extern TNimType NTI4011; /* RootObj */
TNimType NTI150427; /* StreamObj */
TNimType NTI150428; /* proc (s: Stream){.gcsafe.} */
TNimType NTI150432; /* proc (s: Stream): bool{.gcsafe.} */
TNimType NTI150436; /* proc (s: Stream, pos: int){.gcsafe.} */
TNimType NTI150441; /* proc (s: Stream): int{.gcsafe.} */
TNimType NTI150445; /* proc (s: Stream, buffer: pointer, bufLen: int): int{.gcsafe.} */
TNimType NTI150451; /* proc (s: Stream, buffer: pointer, bufLen: int): int{.gcsafe.} */
TNimType NTI150457; /* proc (s: Stream, buffer: pointer, bufLen: int){.gcsafe.} */
TNimType NTI150463; /* proc (s: Stream){.gcsafe.} */
TNimType NTI150425; /* Stream */
TNimType NTI151667; /* FileStreamObj */
extern TNimType NTI16604; /* File */
TNimType NTI151665; /* FileStream */
extern TSafePoint* exchandler_21043;
extern TNimType NTI83017; /* ref IOError */
extern TNimType NTI4031; /* IOError */
extern Gcheap51218 gch_51259;
TNimType NTI151511; /* StringStreamObj */
extern TNimType NTI149; /* string */
extern TNimType NTI108; /* int */
TNimType NTI151509; /* StringStream */
N_NIMCALL(void, TMP2789)(void* p, NI op) {
	Streamobj150427* a;
	a = (Streamobj150427*)p;
}

N_NIMCALL(NI, readdata_150580)(Streamobj150427* s, void* buffer, NI buflen) {
	NI result;
	result = 0;
	result = (*s).readdataimpl(s, buffer, buflen);
	return result;
}
N_NIMCALL(void, TMP2790)(void* p, NI op) {
	Filestreamobj151667* a;
	a = (Filestreamobj151667*)p;
}

N_NIMCALL(void, fsclose_151671)(Streamobj150427* s) {
	{
		if (!!(((*((Filestreamobj151667*) (s))).f == NIM_NIL))) goto LA3;
		fclose((*((Filestreamobj151667*) (s))).f);
		(*((Filestreamobj151667*) (s))).f = NIM_NIL;
	}
	LA3: ;
}

N_NIMCALL(NIM_BOOL, fsatend_151695)(Streamobj150427* s) {
	NIM_BOOL result;
{	result = 0;
	result = endoffile_17060((*((Filestreamobj151667*) (s))).f);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(void, fssetposition_151702)(Streamobj150427* s, NI pos) {
	setfilepos_17187((*((Filestreamobj151667*) (s))).f, ((NI64) (pos)));
}

N_NIMCALL(NI, fsgetposition_151709)(Streamobj150427* s) {
	NI result;
	NI64 LOC1;
{	result = 0;
	LOC1 = 0;
	LOC1 = getfilepos_17191((*((Filestreamobj151667*) (s))).f);
	result = ((NI) (LOC1));
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, fsreaddata_151716)(Streamobj150427* s, void* buffer, NI buflen) {
	NI result;
	result = 0;
	result = readbuffer_17160((*((Filestreamobj151667*) (s))).f, buffer, ((NI) (buflen)));
	return result;
}

static N_INLINE(void, pushSafePoint)(TSafePoint* s) {
	(*s).hasRaiseAction = NIM_FALSE;
	(*s).prev = exchandler_21043;
	exchandler_21043 = s;
}

static N_INLINE(void, popSafePoint)(void) {
	exchandler_21043 = (*exchandler_21043).prev;
}

N_NIMCALL(NI, fspeekdata_151725)(Streamobj150427* s, void* buffer, NI buflen) {
	NI volatile result;
	NI pos;
	TSafePoint TMP2793;
	result = 0;
	pos = fsgetposition_151709(s);
	pushSafePoint(&TMP2793);
	TMP2793.status = _setjmp(TMP2793.context);
	if (TMP2793.status == 0) {
		result = readbuffer_17160((*((Filestreamobj151667*) (s))).f, buffer, ((NI) (buflen)));
		popSafePoint();
	}
	else {
		popSafePoint();
	}
	{
		fssetposition_151702(s, pos);
	}
	if (TMP2793.status != 0) reraiseException();
	return result;
}

static N_INLINE(Cell49147*, usrtocell_52846)(void* usr) {
	Cell49147* result;
	result = 0;
	result = ((Cell49147*) ((NI)((NU32)(((NI) (usr))) - (NU32)(((NI)sizeof(Cell49147))))));
	return result;
}

static N_INLINE(void, rtladdzct_54404)(Cell49147* c) {
	addzct_52817((&gch_51259.zct), c);
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	Cell49147* c;
	c = usrtocell_52846(p);
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU32)((*c).refcount) < (NU32)(((NI) 8)))) goto LA3;
		rtladdzct_54404(c);
	}
	LA3: ;
}

N_NIMCALL(Ioerror4031*, neweio_150405)(NimStringDesc* msg) {
	Ioerror4031* result;
	NimStringDesc* LOC1;
	result = 0;
	result = (Ioerror4031*) newObj((&NTI83017), sizeof(Ioerror4031));
	(*result).Sup.Sup.Sup.m_type = (&NTI4031);
	LOC1 = 0;
	LOC1 = (*result).Sup.Sup.message; (*result).Sup.Sup.message = copyStringRC1(msg);
	if (LOC1) nimGCunrefNoCycle(LOC1);
	return result;
}

N_NIMCALL(void, fswritedata_151735)(Streamobj150427* s, void* buffer, NI buflen) {
	{
		NI LOC3;
		Ioerror4031* LOC6;
		LOC3 = 0;
		LOC3 = writebuffer_17182((*((Filestreamobj151667*) (s))).f, buffer, ((NI) (buflen)));
		if (!!((LOC3 == buflen))) goto LA4;
		LOC6 = 0;
		LOC6 = neweio_150405(((NimStringDesc*) &TMP2794));
		raiseException((Exception*)LOC6, "IOError");
	}
	LA4: ;
}

N_NIMCALL(void, fsflush_151689)(Streamobj150427* s) {
	fflush((*((Filestreamobj151667*) (s))).f);
}

N_NIMCALL(Filestreamobj151667*, newfilestream_151743)(FILE* f) {
	Filestreamobj151667* result;
	result = 0;
	result = (Filestreamobj151667*) newObj((&NTI151665), sizeof(Filestreamobj151667));
	(*result).Sup.Sup.m_type = (&NTI151667);
	(*result).f = f;
	(*result).Sup.closeimpl = fsclose_151671;
	(*result).Sup.atendimpl = fsatend_151695;
	(*result).Sup.setpositionimpl = fssetposition_151702;
	(*result).Sup.getpositionimpl = fsgetposition_151709;
	(*result).Sup.readdataimpl = fsreaddata_151716;
	(*result).Sup.peekdataimpl = fspeekdata_151725;
	(*result).Sup.writedataimpl = fswritedata_151735;
	(*result).Sup.flushimpl = fsflush_151689;
	return result;
}

N_NIMCALL(Filestreamobj151667*, newfilestream_151758)(NimStringDesc* filename, NU8 mode) {
	Filestreamobj151667* result;
	FILE* f;
	result = 0;
	f = 0;
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = open_17003(&f, filename, mode, ((NI) -1));
		if (!LOC3) goto LA4;
		result = newfilestream_151743(f);
	}
	LA4: ;
	return result;
}

N_NIMCALL(void, close_150491)(Streamobj150427* s) {
	{
		if (!!((*s).closeimpl == 0)) goto LA3;
		(*s).closeimpl(s);
	}
	LA3: ;
}

N_NIMCALL(void, writedata_150648)(Streamobj150427* s, void* buffer, NI buflen) {
	(*s).writedataimpl(s, buffer, buflen);
}

N_NIMCALL(void, write_150683)(Streamobj150427* s, NimStringDesc* x) {
	writedata_150648(s, ((void*) (x->data)), (x ? x->Sup.len : 0));
}

N_NIMCALL(NIM_BOOL, atend_150517)(Streamobj150427* s) {
	NIM_BOOL result;
	result = 0;
	result = (*s).atendimpl(s);
	return result;
}

N_NIMCALL(NIM_CHAR, readchar_150784)(Streamobj150427* s) {
	NIM_CHAR result;
	result = 0;
	{
		NI LOC3;
		LOC3 = 0;
		LOC3 = readdata_150580(s, ((void*) ((&result))), ((NI) 1));
		if (!!((LOC3 == ((NI) 1)))) goto LA4;
		result = 0;
	}
	LA4: ;
	return result;
}

N_NIMCALL(NimStringDesc*, readline_151477)(Streamobj150427* s) {
	NimStringDesc* result;
	result = 0;
	result = copyString(((NimStringDesc*) &TMP3014));
	{
		while (1) {
			NIM_CHAR c;
			c = readchar_150784(s);
			{
				if (!((NU8)(c) == (NU8)(13))) goto LA5;
				c = readchar_150784(s);
				goto LA1;
			}
			LA5: ;
			{
				NIM_BOOL LOC9;
				LOC9 = 0;
				LOC9 = ((NU8)(c) == (NU8)(10));
				if (LOC9) goto LA10;
				LOC9 = ((NU8)(c) == (NU8)(0));
				LA10: ;
				if (!LOC9) goto LA11;
				goto LA1;
			}
			goto LA7;
			LA11: ;
			{
				result = addChar(result, c);
			}
			LA7: ;
		}
	} LA1: ;
	return result;
}
N_NIMCALL(void, TMP3058)(void* p, NI op) {
	Stringstreamobj151511* a;
	a = (Stringstreamobj151511*)p;
	nimGCvisit((void*)(*a).data, op);
}

N_NIMCALL(void, ssclose_151636)(Streamobj150427* s_151638) {
	Stringstreamobj151511* s;
	NimStringDesc* LOC1;
	s = ((Stringstreamobj151511*) (s_151638));
	LOC1 = 0;
	LOC1 = (*s).data; (*s).data = copyStringRC1(NIM_NIL);
	if (LOC1) nimGCunrefNoCycle(LOC1);
}

N_NIMCALL(NIM_BOOL, ssatend_151522)(Streamobj150427* s_151524) {
	NIM_BOOL result;
	Stringstreamobj151511* s;
{	result = 0;
	s = ((Stringstreamobj151511*) (s_151524));
	result = (((*s).data ? (*s).data->Sup.len : 0) <= (*s).pos);
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(void, sssetposition_151533)(Streamobj150427* s_151535, NI pos) {
	Stringstreamobj151511* s;
	s = ((Stringstreamobj151511*) (s_151535));
	(*s).pos = clamp_151539(pos, ((NI) 0), ((*s).data ? (*s).data->Sup.len : 0));
}

N_NIMCALL(NI, ssgetposition_151558)(Streamobj150427* s_151560) {
	NI result;
	Stringstreamobj151511* s;
{	result = 0;
	s = ((Stringstreamobj151511*) (s_151560));
	result = (*s).pos;
	goto BeforeRet;
	}BeforeRet: ;
	return result;
}

N_NIMCALL(NI, ssreaddata_151569)(Streamobj150427* s_151571, void* buffer, NI buflen) {
	NI result;
	Stringstreamobj151511* s;
	result = 0;
	s = ((Stringstreamobj151511*) (s_151571));
	result = ((buflen <= (NI)(((*s).data ? (*s).data->Sup.len : 0) - (*s).pos)) ? buflen : (NI)(((*s).data ? (*s).data->Sup.len : 0) - (*s).pos));
	{
		if (!(((NI) 0) < result)) goto LA3;
		memcpy(buffer, ((void*) ((&(*s).data->data[(*s).pos]))), ((NI) (result)));
		(*s).pos += result;
	}
	LA3: ;
	return result;
}

N_NIMCALL(NI, sspeekdata_151596)(Streamobj150427* s_151598, void* buffer, NI buflen) {
	NI result;
	Stringstreamobj151511* s;
	result = 0;
	s = ((Stringstreamobj151511*) (s_151598));
	result = ((buflen <= (NI)(((*s).data ? (*s).data->Sup.len : 0) - (*s).pos)) ? buflen : (NI)(((*s).data ? (*s).data->Sup.len : 0) - (*s).pos));
	{
		if (!(((NI) 0) < result)) goto LA3;
		memcpy(buffer, ((void*) ((&(*s).data->data[(*s).pos]))), ((NI) (result)));
	}
	LA3: ;
	return result;
}

N_NIMCALL(void, sswritedata_151614)(Streamobj150427* s_151616, void* buffer, NI buflen) {
	Stringstreamobj151511* s;
{	s = ((Stringstreamobj151511*) (s_151616));
	{
		if (!(buflen <= ((NI) 0))) goto LA3;
		goto BeforeRet;
	}
	LA3: ;
	{
		if (!(((*s).data ? (*s).data->Sup.len : 0) < (NI)((*s).pos + buflen))) goto LA7;
		(*s).data = setLengthStr((*s).data, ((NI) ((NI)((*s).pos + buflen))));
	}
	LA7: ;
	memcpy(((void*) ((&(*s).data->data[(*s).pos]))), buffer, ((NI) (buflen)));
	(*s).pos += buflen;
	}BeforeRet: ;
}

N_NIMCALL(Stringstreamobj151511*, newstringstream_151646)(NimStringDesc* s) {
	Stringstreamobj151511* result;
	NimStringDesc* LOC1;
	result = 0;
	result = (Stringstreamobj151511*) newObj((&NTI151509), sizeof(Stringstreamobj151511));
	(*result).Sup.Sup.m_type = (&NTI151511);
	LOC1 = 0;
	LOC1 = (*result).data; (*result).data = copyStringRC1(s);
	if (LOC1) nimGCunrefNoCycle(LOC1);
	(*result).pos = ((NI) 0);
	(*result).Sup.closeimpl = ssclose_151636;
	(*result).Sup.atendimpl = ssatend_151522;
	(*result).Sup.setpositionimpl = sssetposition_151533;
	(*result).Sup.getpositionimpl = ssgetposition_151558;
	(*result).Sup.readdataimpl = ssreaddata_151569;
	(*result).Sup.peekdataimpl = sspeekdata_151596;
	(*result).Sup.writedataimpl = sswritedata_151614;
	return result;
}

N_NIMCALL(NimStringDesc*, readall_150592)(Streamobj150427* s) {
	NimStringDesc* result;
	NI r;
	result = 0;
	result = mnewString(((NI) 1000));
	r = ((NI) 0);
	{
		while (1) {
			NI readbytes;
			readbytes = readdata_150580(s, ((void*) ((&result->data[r]))), ((NI) 1000));
			{
				if (!(readbytes < ((NI) 1000))) goto LA5;
				result = setLengthStr(result, ((NI) ((NI)(r + readbytes))));
				goto LA1;
			}
			LA5: ;
			r += ((NI) 1000);
			result = setLengthStr(result, ((NI) ((NI)(r + ((NI) 1000)))));
		}
	} LA1: ;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_streamsInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_streamsDatInit000)(void) {
static TNimNode* TMP2788[8];
static TNimNode* TMP3057[2];
static TNimNode TMP33[13];
NTI150427.size = sizeof(Streamobj150427);
NTI150427.kind = 17;
NTI150427.base = (&NTI4011);
NTI150427.flags = 1;
TMP2788[0] = &TMP33[1];
NTI150428.size = sizeof(TY150428);
NTI150428.kind = 25;
NTI150428.base = 0;
NTI150428.flags = 3;
TMP33[1].kind = 1;
TMP33[1].offset = offsetof(Streamobj150427, closeimpl);
TMP33[1].typ = (&NTI150428);
TMP33[1].name = "closeImpl";
TMP2788[1] = &TMP33[2];
NTI150432.size = sizeof(TY150432);
NTI150432.kind = 25;
NTI150432.base = 0;
NTI150432.flags = 3;
TMP33[2].kind = 1;
TMP33[2].offset = offsetof(Streamobj150427, atendimpl);
TMP33[2].typ = (&NTI150432);
TMP33[2].name = "atEndImpl";
TMP2788[2] = &TMP33[3];
NTI150436.size = sizeof(TY150436);
NTI150436.kind = 25;
NTI150436.base = 0;
NTI150436.flags = 3;
TMP33[3].kind = 1;
TMP33[3].offset = offsetof(Streamobj150427, setpositionimpl);
TMP33[3].typ = (&NTI150436);
TMP33[3].name = "setPositionImpl";
TMP2788[3] = &TMP33[4];
NTI150441.size = sizeof(TY150441);
NTI150441.kind = 25;
NTI150441.base = 0;
NTI150441.flags = 3;
TMP33[4].kind = 1;
TMP33[4].offset = offsetof(Streamobj150427, getpositionimpl);
TMP33[4].typ = (&NTI150441);
TMP33[4].name = "getPositionImpl";
TMP2788[4] = &TMP33[5];
NTI150445.size = sizeof(TY150445);
NTI150445.kind = 25;
NTI150445.base = 0;
NTI150445.flags = 3;
TMP33[5].kind = 1;
TMP33[5].offset = offsetof(Streamobj150427, readdataimpl);
TMP33[5].typ = (&NTI150445);
TMP33[5].name = "readDataImpl";
TMP2788[5] = &TMP33[6];
NTI150451.size = sizeof(TY150451);
NTI150451.kind = 25;
NTI150451.base = 0;
NTI150451.flags = 3;
TMP33[6].kind = 1;
TMP33[6].offset = offsetof(Streamobj150427, peekdataimpl);
TMP33[6].typ = (&NTI150451);
TMP33[6].name = "peekDataImpl";
TMP2788[6] = &TMP33[7];
NTI150457.size = sizeof(TY150457);
NTI150457.kind = 25;
NTI150457.base = 0;
NTI150457.flags = 3;
TMP33[7].kind = 1;
TMP33[7].offset = offsetof(Streamobj150427, writedataimpl);
TMP33[7].typ = (&NTI150457);
TMP33[7].name = "writeDataImpl";
TMP2788[7] = &TMP33[8];
NTI150463.size = sizeof(TY150463);
NTI150463.kind = 25;
NTI150463.base = 0;
NTI150463.flags = 3;
TMP33[8].kind = 1;
TMP33[8].offset = offsetof(Streamobj150427, flushimpl);
TMP33[8].typ = (&NTI150463);
TMP33[8].name = "flushImpl";
TMP33[0].len = 8; TMP33[0].kind = 2; TMP33[0].sons = &TMP2788[0];
NTI150427.node = &TMP33[0];
NTI150425.size = sizeof(Streamobj150427*);
NTI150425.kind = 22;
NTI150425.base = (&NTI150427);
NTI150425.marker = TMP2789;
NTI151667.size = sizeof(Filestreamobj151667);
NTI151667.kind = 17;
NTI151667.base = (&NTI150427);
NTI151667.flags = 1;
TMP33[9].kind = 1;
TMP33[9].offset = offsetof(Filestreamobj151667, f);
TMP33[9].typ = (&NTI16604);
TMP33[9].name = "f";
NTI151667.node = &TMP33[9];
NTI151665.size = sizeof(Filestreamobj151667*);
NTI151665.kind = 22;
NTI151665.base = (&NTI151667);
NTI151665.marker = TMP2790;
NTI151511.size = sizeof(Stringstreamobj151511);
NTI151511.kind = 17;
NTI151511.base = (&NTI150427);
TMP3057[0] = &TMP33[11];
TMP33[11].kind = 1;
TMP33[11].offset = offsetof(Stringstreamobj151511, data);
TMP33[11].typ = (&NTI149);
TMP33[11].name = "data";
TMP3057[1] = &TMP33[12];
TMP33[12].kind = 1;
TMP33[12].offset = offsetof(Stringstreamobj151511, pos);
TMP33[12].typ = (&NTI108);
TMP33[12].name = "pos";
TMP33[10].len = 2; TMP33[10].kind = 2; TMP33[10].sons = &TMP3057[0];
NTI151511.node = &TMP33[10];
NTI151509.size = sizeof(Stringstreamobj151511*);
NTI151509.kind = 22;
NTI151509.base = (&NTI151511);
NTI151509.marker = TMP3058;
}

