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

#include "nimbase.h"
#include <string.h>
#include <stdio.h>
#undef linux
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA;
typedef struct TNimObject TNimObject;
typedef struct Tllstream_IHsOGFu33dIY69a9bLlFHlHw Tllstream_IHsOGFu33dIY69a9bLlFHlHw;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef NU8 Tnimkind_jIBKr1ejBgsfM33Kxw4j7A;
typedef NU8 Tnimtypeflag_v8QUszD1sWlSIWZz7mC4bQ_Set;
typedef N_NIMCALL_PTR(void, TY_ojoeKfW4VYIm36I9cpDTQIg) (void* p0, NI op0);
typedef N_NIMCALL_PTR(void*, TY_WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p0);
struct  TNimType  {
NI size;
Tnimkind_jIBKr1ejBgsfM33Kxw4j7A kind;
Tnimtypeflag_v8QUszD1sWlSIWZz7mC4bQ_Set flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY_ojoeKfW4VYIm36I9cpDTQIg marker;
TY_WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
};
typedef NU8 Tnimnodekind_unfNsxrcATrufDZmpBq4HQ;
struct  TNimNode  {
Tnimnodekind_unfNsxrcATrufDZmpBq4HQ kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA  {
  TNimObject Sup;
NI bufpos;
NCSTRING buf;
NI buflen;
Tllstream_IHsOGFu33dIY69a9bLlFHlHw* stream;
NI linenumber;
NI sentinel;
NI linestart;
};
typedef NU8 Tllstreamkind_jVcKY16LbOamXE9bxXUD6pQ;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Tllstream_IHsOGFu33dIY69a9bLlFHlHw  {
  TNimObject Sup;
Tllstreamkind_jVcKY16LbOamXE9bxXUD6pQ kind;
FILE* f;
NimStringDesc* s;
NI rd;
NI wr;
NI lineoffset;
};
N_NOCONV(void*, alloc_4cubgSerkjpuLcj5MXjiLw_2)(NI size0);
N_NIMCALL(void, unsureAsgnRef)(void** dest0, void* src0);
N_NIMCALL(void, fillbuffer_cotVgXvyGKbiStcXgf0NTw)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0);
static N_INLINE(void, movemem_fPlwH3r9agN9aEHB6yCPMh0wnimlexbase)(void* dest0, void* source0, NI size0);
N_NIMCALL(NI, llstreamread_rgyTKC8s50wthTlyUpoMQg)(Tllstream_IHsOGFu33dIY69a9bLlFHlHw* s0, void* buf0, NI buflen0);
N_NOCONV(void*, realloc_epWYXy7oruYtiNJhUF25Zg)(void* p0, NI newsize0);
N_NIMCALL(void, skiputf8bom_fpEvLjybfvf8F82rXLe7RQ)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0);
N_NIMCALL(NI, fillbaselexer_BH0xyTNNGjFdfKKVBEL5rw_2)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0, NI pos0);
N_NOCONV(void, dealloc_RCjNtRnHdRYntrcE7YtwWw)(void* p0);
N_NIMCALL(void, llstreamclose_TQe1mwqs39ccgay5ywsr9azw)(Tllstream_IHsOGFu33dIY69a9bLlFHlHw* s0);
extern TNimType NTI_13RNkKqUOX1TtorOUlKtqA;
TNimType NTI_z9a7O76kH1tJ9aXJ3h2MdEzA;
extern TNimType NTI_rR5Bzr1D5krxoo1NcNyeMA;
extern TNimType NTI_S9agCYBinaYZnGWcjTdxclg;
extern TNimType NTI_f4WZajr79aZLBPITqz2rcdA;

static N_INLINE(void, movemem_fPlwH3r9agN9aEHB6yCPMh0wnimlexbase)(void* dest0, void* source0, NI size0) {
	void* LOC1;
	LOC1 = (void*)0;
	LOC1 = memmove(dest0, source0, ((size_t) (size0)));
}

N_NIMCALL(void, fillbuffer_cotVgXvyGKbiStcXgf0NTw)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0) {
	NI charsread0;
	NI tocopy0;
	NI s0;
	NI oldbuflen0;
	NI LOC5;
	charsread0 = (NI)0;
	tocopy0 = (NI)0;
	s0 = (NI)0;
	oldbuflen0 = (NI)0;
	tocopy0 = (NI)((NI)((*L0).buflen - (*L0).sentinel) - ((NI) 1));
	{
		if (!(((NI) 0) < tocopy0)) goto LA3;
		movemem_fPlwH3r9agN9aEHB6yCPMh0wnimlexbase(((void*) ((*L0).buf)), ((void*) ((&(*L0).buf[(NI)((*L0).sentinel + ((NI) 1))]))), ((NI) ((NI)(tocopy0 * ((NI) 1)))));
	}
	LA3: ;
	LOC5 = (NI)0;
	LOC5 = llstreamread_rgyTKC8s50wthTlyUpoMQg((*L0).stream, ((void*) ((&(*L0).buf[tocopy0]))), (NI)((NI)((*L0).sentinel + ((NI) 1)) * ((NI) 1)));
	charsread0 = (NI)(LOC5 / ((NI) 1));
	s0 = (NI)(tocopy0 + charsread0);
	{
		if (!(charsread0 < (NI)((*L0).sentinel + ((NI) 1)))) goto LA8;
		(*L0).buf[s0] = 0;
		(*L0).sentinel = s0;
	}
	goto LA6;
	LA8: ;
	{
		s0 -= ((NI) 1);
		{
			while (1) {
				{
					while (1) {
						NIM_BOOL LOC15;
						LOC15 = (NIM_BOOL)0;
						LOC15 = (((NI) 0) <= s0);
						if (!(LOC15)) goto LA16;
						LOC15 = !((((NU8)((*L0).buf[s0])) == ((NU8)(13)) || ((NU8)((*L0).buf[s0])) == ((NU8)(10))));
						LA16: ;
						if (!LOC15) goto LA14;
						s0 -= ((NI) 1);
					} LA14: ;
				}
				{
					if (!(((NI) 0) <= s0)) goto LA19;
					(*L0).sentinel = s0;
					goto LA11;
				}
				goto LA17;
				LA19: ;
				{
					void* LOC22;
					NI LOC23;
					oldbuflen0 = (*L0).buflen;
					(*L0).buflen = (NI)((*L0).buflen * ((NI) 2));
					LOC22 = (void*)0;
					LOC22 = realloc_epWYXy7oruYtiNJhUF25Zg(((void*) ((*L0).buf)), ((NI) ((NI)((*L0).buflen * ((NI) 1)))));
					(*L0).buf = ((NCSTRING) (LOC22));
					LOC23 = (NI)0;
					LOC23 = llstreamread_rgyTKC8s50wthTlyUpoMQg((*L0).stream, ((void*) ((&(*L0).buf[oldbuflen0]))), (NI)(oldbuflen0 * ((NI) 1)));
					charsread0 = (NI)(LOC23 / ((NI) 1));
					{
						if (!(charsread0 < oldbuflen0)) goto LA26;
						(*L0).buf[(NI)(oldbuflen0 + charsread0)] = 0;
						(*L0).sentinel = (NI)(oldbuflen0 + charsread0);
						goto LA11;
					}
					LA26: ;
					s0 = (NI)((*L0).buflen - ((NI) 1));
				}
				LA17: ;
			}
		} LA11: ;
	}
	LA6: ;
}

N_NIMCALL(void, skiputf8bom_fpEvLjybfvf8F82rXLe7RQ)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0) {
	{
		NIM_BOOL LOC3;
		NIM_BOOL LOC4;
		LOC3 = (NIM_BOOL)0;
		LOC4 = (NIM_BOOL)0;
		LOC4 = ((NU8)((*L0).buf[((NI) 0)]) == (NU8)(239));
		if (!(LOC4)) goto LA5;
		LOC4 = ((NU8)((*L0).buf[((NI) 1)]) == (NU8)(187));
		LA5: ;
		LOC3 = LOC4;
		if (!(LOC3)) goto LA6;
		LOC3 = ((NU8)((*L0).buf[((NI) 2)]) == (NU8)(191));
		LA6: ;
		if (!LOC3) goto LA7;
		(*L0).bufpos += ((NI) 3);
		(*L0).linestart += ((NI) 3);
	}
	LA7: ;
}

N_NIMCALL(void, openbaselexer_AhdjJJ6lkJ2zIxQnYdvcGQ)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0, Tllstream_IHsOGFu33dIY69a9bLlFHlHw* inputstream0, NI buflen0) {
	void* LOC1;
	(*L0).bufpos = ((NI) 0);
	(*L0).buflen = buflen0;
	LOC1 = (void*)0;
	LOC1 = alloc_4cubgSerkjpuLcj5MXjiLw_2(((NI) ((NI)(buflen0 * ((NI) 1)))));
	(*L0).buf = ((NCSTRING) (LOC1));
	(*L0).sentinel = (NI)(buflen0 - ((NI) 1));
	(*L0).linestart = ((NI) 0);
	(*L0).linenumber = ((NI) 1);
	unsureAsgnRef((void**) (&(*L0).stream), inputstream0);
	fillbuffer_cotVgXvyGKbiStcXgf0NTw(L0);
	skiputf8bom_fpEvLjybfvf8F82rXLe7RQ(L0);
}

N_NIMCALL(NI, getcolnumber_nRhrv4ZpI0tz0OPBe1mDKw)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0, NI pos0) {
	NI result0;
	result0 = (NI)0;
	result0 = ((NI)(pos0 - (*L0).linestart) > 0? ((NI)(pos0 - (*L0).linestart)) : -((NI)(pos0 - (*L0).linestart)));
	return result0;
}

N_NIMCALL(NI, fillbaselexer_BH0xyTNNGjFdfKKVBEL5rw_2)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0, NI pos0) {
	NI result0;
	result0 = (NI)0;
	{
		if (!(pos0 < (*L0).sentinel)) goto LA3;
		result0 = (NI)(pos0 + ((NI) 1));
	}
	goto LA1;
	LA3: ;
	{
		fillbuffer_cotVgXvyGKbiStcXgf0NTw(L0);
		(*L0).bufpos = ((NI) 0);
		result0 = ((NI) 0);
	}
	LA1: ;
	(*L0).linestart = result0;
	return result0;
}

N_NIMCALL(NI, handlecr_BH0xyTNNGjFdfKKVBEL5rw)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0, NI pos0) {
	NI result0;
	result0 = (NI)0;
	(*L0).linenumber += ((NI) 1);
	result0 = fillbaselexer_BH0xyTNNGjFdfKKVBEL5rw_2(L0, pos0);
	{
		if (!((NU8)((*L0).buf[result0]) == (NU8)(10))) goto LA3;
		result0 = fillbaselexer_BH0xyTNNGjFdfKKVBEL5rw_2(L0, result0);
	}
	LA3: ;
	return result0;
}

N_NIMCALL(NI, handlelf_BH0xyTNNGjFdfKKVBEL5rw_3)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0, NI pos0) {
	NI result0;
	result0 = (NI)0;
	(*L0).linenumber += ((NI) 1);
	result0 = fillbaselexer_BH0xyTNNGjFdfKKVBEL5rw_2(L0, pos0);
	return result0;
}

N_NIMCALL(void, closebaselexer_cotVgXvyGKbiStcXgf0NTw_2)(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA* L0) {
	dealloc_RCjNtRnHdRYntrcE7YtwWw(((void*) ((*L0).buf)));
	llstreamclose_TQe1mwqs39ccgay5ywsr9azw((*L0).stream);
}
NIM_EXTERNC N_NOINLINE(void, compiler_nimlexbaseInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, compiler_nimlexbaseDatInit000)(void) {
static TNimNode* T_jNFaG9cOzyJSKBcIonhGRGw_2[7];
static TNimNode T_jNFaG9cOzyJSKBcIonhGRGw_0[8];
NTI_z9a7O76kH1tJ9aXJ3h2MdEzA.size = sizeof(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA);
NTI_z9a7O76kH1tJ9aXJ3h2MdEzA.kind = 17;
NTI_z9a7O76kH1tJ9aXJ3h2MdEzA.base = (&NTI_13RNkKqUOX1TtorOUlKtqA);
T_jNFaG9cOzyJSKBcIonhGRGw_2[0] = &T_jNFaG9cOzyJSKBcIonhGRGw_0[1];
T_jNFaG9cOzyJSKBcIonhGRGw_0[1].kind = 1;
T_jNFaG9cOzyJSKBcIonhGRGw_0[1].offset = offsetof(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA, bufpos);
T_jNFaG9cOzyJSKBcIonhGRGw_0[1].typ = (&NTI_rR5Bzr1D5krxoo1NcNyeMA);
T_jNFaG9cOzyJSKBcIonhGRGw_0[1].name = "bufpos";
T_jNFaG9cOzyJSKBcIonhGRGw_2[1] = &T_jNFaG9cOzyJSKBcIonhGRGw_0[2];
T_jNFaG9cOzyJSKBcIonhGRGw_0[2].kind = 1;
T_jNFaG9cOzyJSKBcIonhGRGw_0[2].offset = offsetof(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA, buf);
T_jNFaG9cOzyJSKBcIonhGRGw_0[2].typ = (&NTI_S9agCYBinaYZnGWcjTdxclg);
T_jNFaG9cOzyJSKBcIonhGRGw_0[2].name = "buf";
T_jNFaG9cOzyJSKBcIonhGRGw_2[2] = &T_jNFaG9cOzyJSKBcIonhGRGw_0[3];
T_jNFaG9cOzyJSKBcIonhGRGw_0[3].kind = 1;
T_jNFaG9cOzyJSKBcIonhGRGw_0[3].offset = offsetof(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA, buflen);
T_jNFaG9cOzyJSKBcIonhGRGw_0[3].typ = (&NTI_rR5Bzr1D5krxoo1NcNyeMA);
T_jNFaG9cOzyJSKBcIonhGRGw_0[3].name = "bufLen";
T_jNFaG9cOzyJSKBcIonhGRGw_2[3] = &T_jNFaG9cOzyJSKBcIonhGRGw_0[4];
T_jNFaG9cOzyJSKBcIonhGRGw_0[4].kind = 1;
T_jNFaG9cOzyJSKBcIonhGRGw_0[4].offset = offsetof(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA, stream);
T_jNFaG9cOzyJSKBcIonhGRGw_0[4].typ = (&NTI_f4WZajr79aZLBPITqz2rcdA);
T_jNFaG9cOzyJSKBcIonhGRGw_0[4].name = "stream";
T_jNFaG9cOzyJSKBcIonhGRGw_2[4] = &T_jNFaG9cOzyJSKBcIonhGRGw_0[5];
T_jNFaG9cOzyJSKBcIonhGRGw_0[5].kind = 1;
T_jNFaG9cOzyJSKBcIonhGRGw_0[5].offset = offsetof(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA, linenumber);
T_jNFaG9cOzyJSKBcIonhGRGw_0[5].typ = (&NTI_rR5Bzr1D5krxoo1NcNyeMA);
T_jNFaG9cOzyJSKBcIonhGRGw_0[5].name = "lineNumber";
T_jNFaG9cOzyJSKBcIonhGRGw_2[5] = &T_jNFaG9cOzyJSKBcIonhGRGw_0[6];
T_jNFaG9cOzyJSKBcIonhGRGw_0[6].kind = 1;
T_jNFaG9cOzyJSKBcIonhGRGw_0[6].offset = offsetof(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA, sentinel);
T_jNFaG9cOzyJSKBcIonhGRGw_0[6].typ = (&NTI_rR5Bzr1D5krxoo1NcNyeMA);
T_jNFaG9cOzyJSKBcIonhGRGw_0[6].name = "sentinel";
T_jNFaG9cOzyJSKBcIonhGRGw_2[6] = &T_jNFaG9cOzyJSKBcIonhGRGw_0[7];
T_jNFaG9cOzyJSKBcIonhGRGw_0[7].kind = 1;
T_jNFaG9cOzyJSKBcIonhGRGw_0[7].offset = offsetof(Tbaselexer_z9a7O76kH1tJ9aXJ3h2MdEzA, linestart);
T_jNFaG9cOzyJSKBcIonhGRGw_0[7].typ = (&NTI_rR5Bzr1D5krxoo1NcNyeMA);
T_jNFaG9cOzyJSKBcIonhGRGw_0[7].name = "lineStart";
T_jNFaG9cOzyJSKBcIonhGRGw_0[0].len = 7; T_jNFaG9cOzyJSKBcIonhGRGw_0[0].kind = 2; T_jNFaG9cOzyJSKBcIonhGRGw_0[0].sons = &T_jNFaG9cOzyJSKBcIonhGRGw_2[0];
NTI_z9a7O76kH1tJ9aXJ3h2MdEzA.node = &T_jNFaG9cOzyJSKBcIonhGRGw_0[0];
}

