/* Generated by Nim Compiler v1.4.2 */
/*   (c) 2020 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 64
#define NIM_EmulateOverflowChecks

/* section: NIM_merge_HEADERS */

#include "nimbase.h"
#include <string.h>
#include <stdio.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix

/* section: NIM_merge_FRAME_DEFINES */
#define nimfr_(x, y)
#define nimln_(x, y)

/* section: NIM_merge_FORWARD_TYPES */
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag;
typedef struct RootObj RootObj;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tyObject_TLLStream__a5oZYQ9aTktYME2449ayEi6g tyObject_TLLStream__a5oZYQ9aTktYME2449ayEi6g;

/* section: NIM_merge_TYPES */
typedef NU8 tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A;
typedef NU8 tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ;
typedef N_NIMCALL_PTR(void, tyProc__ojoeKfW4VYIm36I9cpDTQIg) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p);
struct TNimType {
NI size;
NI align;
tyEnum_TNimKind__jIBKr1ejBgsfM33Kxw4j7A kind;
tySet_tyEnum_TNimTypeFlag__v8QUszD1sWlSIWZz7mC4bQ flags;
TNimType* base;
TNimNode* node;
void* finalizer;
tyProc__ojoeKfW4VYIm36I9cpDTQIg marker;
tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
};
typedef NU8 tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ;
struct TNimNode {
tyEnum_TNimNodeKind__unfNsxrcATrufDZmpBq4HQ kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct RootObj {
TNimType* m_type;
};
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag {
  RootObj Sup;
NI bufpos;
NCSTRING buf;
NimStringDesc* bufStorage;
NI bufLen;
tyObject_TLLStream__a5oZYQ9aTktYME2449ayEi6g* stream;
NI lineNumber;
NI sentinel;
NI lineStart;
NI offsetBase;
};
typedef NU8 tyEnum_TLLStreamKind__jVcKY16LbOamXE9bxXUD6pQ;
typedef struct {
N_NIMCALL_PTR(NI, ClP_0) (tyObject_TLLStream__a5oZYQ9aTktYME2449ayEi6g* s, void* buf, NI bufLen, void* ClE_0);
void* ClE_0;
} tyProc__9cZV5JMJLsdOPMv55VbpOVg;
struct tyObject_TLLStream__a5oZYQ9aTktYME2449ayEi6g {
  RootObj Sup;
tyEnum_TLLStreamKind__jVcKY16LbOamXE9bxXUD6pQ kind;
FILE* f;
NimStringDesc* s;
NI rd;
NI wr;
NI lineOffset;
tyProc__9cZV5JMJLsdOPMv55VbpOVg repl;
};

/* section: NIM_merge_PROC_HEADERS */
N_NIMCALL(NimStringDesc*, mnewString)(NI len);
N_LIB_PRIVATE N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s);
N_LIB_PRIVATE N_NIMCALL(void, fillBuffer__X9aea9bJavePT9cGIdd7JRH7Q)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L);
static N_INLINE(void, moveMem__i80o3k0SgEI5gTRCzYdyWA_2system)(void* dest, void* source, NI size);
N_LIB_PRIVATE N_NIMCALL(NI, llStreamRead__ioi0zlIEx7dNasBjD9brSbA)(tyObject_TLLStream__a5oZYQ9aTktYME2449ayEi6g* s, void* buf, NI bufLen);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newLen);
N_LIB_PRIVATE N_NIMCALL(void, skipUTF8BOM__X9aea9bJavePT9cGIdd7JRH7Q_2)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L);
N_LIB_PRIVATE N_NIMCALL(NI, fillBaseLexer__pFv9ajpk2zhJHQ7x61CSE2A_2)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L, NI pos);
N_LIB_PRIVATE N_NIMCALL(void, llStreamClose__pzACjlxXGrH2rRQU5WrSmg)(tyObject_TLLStream__a5oZYQ9aTktYME2449ayEi6g* s);

/* section: NIM_merge_DATA */
extern TNimType NTI__ytyiCJqK439aF9cIibuRVpAg_;
N_LIB_PRIVATE TNimType NTI__jTxk7Uc2dfr9aTDL2dZhO9ag_;
extern TNimType NTI__rR5Bzr1D5krxoo1NcNyeMA_;
extern TNimType NTI__S9agCYBinaYZnGWcjTdxclg_;
extern TNimType NTI__77mFvmsOLKik79ci2hXkHEg_;
extern TNimType NTI__WO3j4yVQ0yN0aRCt9bFEbtg_;

/* section: NIM_merge_PROCS */
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringDesc* s) {
	NCSTRING result;
	result = (NCSTRING)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (s == ((NimStringDesc*) NIM_NIL));
		if (T3_) goto LA4_;
		T3_ = ((*s).Sup.len == ((NI) 0));
		LA4_: ;
		if (!T3_) goto LA5_;
		result = "";
	}
	goto LA1_;
	LA5_: ;
	{
		result = ((NCSTRING) ((*s).data));
	}
	LA1_: ;
	return result;
}
static N_INLINE(void, moveMem__i80o3k0SgEI5gTRCzYdyWA_2system)(void* dest, void* source, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memmove(dest, source, ((size_t) (size)));
}
N_LIB_PRIVATE N_NIMCALL(void, fillBuffer__X9aea9bJavePT9cGIdd7JRH7Q)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L) {
	NI charsRead;
	NI toCopy;
	NI s;
	NI oldBufLen;
	charsRead = (NI)0;
	toCopy = (NI)0;
	s = (NI)0;
	oldBufLen = (NI)0;
	toCopy = (NI)((NI)((*L).bufLen - (*L).sentinel) - ((NI) 1));
	{
		if (!(((NI) 0) < toCopy)) goto LA3_;
		moveMem__i80o3k0SgEI5gTRCzYdyWA_2system(((void*) ((&(*L).buf[((NI) 0)]))), ((void*) ((&(*L).buf[(NI)((*L).sentinel + ((NI) 1))]))), ((NI) (toCopy)));
	}
	LA3_: ;
	charsRead = llStreamRead__ioi0zlIEx7dNasBjD9brSbA((*L).stream, ((void*) ((&(*L).buf[toCopy]))), (NI)((*L).sentinel + ((NI) 1)));
	s = (NI)(toCopy + charsRead);
	{
		if (!(charsRead < (NI)((*L).sentinel + ((NI) 1)))) goto LA7_;
		(*L).buf[s] = 0;
		(*L).sentinel = s;
	}
	goto LA5_;
	LA7_: ;
	{
		s -= ((NI) 1);
		{
			while (1) {
				{
					while (1) {
						NIM_BOOL T14_;
						T14_ = (NIM_BOOL)0;
						T14_ = (((NI) 0) <= s);
						if (!(T14_)) goto LA15_;
						T14_ = !((((NU8)((*L).buf[s])) == ((NU8)(13)) || ((NU8)((*L).buf[s])) == ((NU8)(10))));
						LA15_: ;
						if (!T14_) goto LA13;
						s -= ((NI) 1);
					} LA13: ;
				}
				{
					if (!(((NI) 0) <= s)) goto LA18_;
					(*L).sentinel = s;
					goto LA10;
				}
				goto LA16_;
				LA18_: ;
				{
					oldBufLen = (*L).bufLen;
					(*L).bufLen = (NI)((*L).bufLen * ((NI) 2));
					unsureAsgnRef((void**) (&(*L).bufStorage), setLengthStr((*L).bufStorage, ((NI) ((*L).bufLen))));
					(*L).buf = nimToCStringConv((*L).bufStorage);
					charsRead = llStreamRead__ioi0zlIEx7dNasBjD9brSbA((*L).stream, ((void*) ((&(*L).buf[oldBufLen]))), oldBufLen);
					{
						if (!(charsRead < oldBufLen)) goto LA23_;
						(*L).buf[(NI)(oldBufLen + charsRead)] = 0;
						(*L).sentinel = (NI)(oldBufLen + charsRead);
						goto LA10;
					}
					LA23_: ;
					s = (NI)((*L).bufLen - ((NI) 1));
				}
				LA16_: ;
			}
		} LA10: ;
	}
	LA5_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, skipUTF8BOM__X9aea9bJavePT9cGIdd7JRH7Q_2)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L) {
	{
		NIM_BOOL T3_;
		NIM_BOOL T4_;
		T3_ = (NIM_BOOL)0;
		T4_ = (NIM_BOOL)0;
		T4_ = ((NU8)((*L).buf[((NI) 0)]) == (NU8)(239));
		if (!(T4_)) goto LA5_;
		T4_ = ((NU8)((*L).buf[((NI) 1)]) == (NU8)(187));
		LA5_: ;
		T3_ = T4_;
		if (!(T3_)) goto LA6_;
		T3_ = ((NU8)((*L).buf[((NI) 2)]) == (NU8)(191));
		LA6_: ;
		if (!T3_) goto LA7_;
		(*L).bufpos += ((NI) 3);
		(*L).lineStart += ((NI) 3);
	}
	LA7_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, openBaseLexer__V9avLgM3wlB5dKp8bWFOIqg)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L, tyObject_TLLStream__a5oZYQ9aTktYME2449ayEi6g* inputstream, NI bufLen) {
	(*L).bufpos = ((NI) 0);
	(*L).offsetBase = ((NI) 0);
	unsureAsgnRef((void**) (&(*L).bufStorage), mnewString(((NI) (bufLen))));
	(*L).buf = nimToCStringConv((*L).bufStorage);
	(*L).bufLen = bufLen;
	(*L).sentinel = (NI)(bufLen - ((NI) 1));
	(*L).lineStart = ((NI) 0);
	(*L).lineNumber = ((NI) 1);
	unsureAsgnRef((void**) (&(*L).stream), inputstream);
	fillBuffer__X9aea9bJavePT9cGIdd7JRH7Q(L);
	skipUTF8BOM__X9aea9bJavePT9cGIdd7JRH7Q_2(L);
}
N_LIB_PRIVATE N_NIMCALL(NI, getColNumber__D0ufm9c9azweHuDkFTPoIzqQ)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L, NI pos) {
	NI result;
	result = (NI)0;
	result = ((NI)(pos - (*L).lineStart) > 0? ((NI)(pos - (*L).lineStart)) : -((NI)(pos - (*L).lineStart)));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, fillBaseLexer__pFv9ajpk2zhJHQ7x61CSE2A_2)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L, NI pos) {
	NI result;
	result = (NI)0;
	{
		if (!(pos < (*L).sentinel)) goto LA3_;
		result = (NI)(pos + ((NI) 1));
	}
	goto LA1_;
	LA3_: ;
	{
		fillBuffer__X9aea9bJavePT9cGIdd7JRH7Q(L);
		(*L).offsetBase += (NI)(pos + ((NI) 1));
		(*L).bufpos = ((NI) 0);
		result = ((NI) 0);
	}
	LA1_: ;
	(*L).lineStart = result;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, handleCR__pFv9ajpk2zhJHQ7x61CSE2A)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L, NI pos) {
	NI result;
	result = (NI)0;
	(*L).lineNumber += ((NI) 1);
	result = fillBaseLexer__pFv9ajpk2zhJHQ7x61CSE2A_2(L, pos);
	{
		if (!((NU8)((*L).buf[result]) == (NU8)(10))) goto LA3_;
		result = fillBaseLexer__pFv9ajpk2zhJHQ7x61CSE2A_2(L, result);
	}
	LA3_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, handleLF__pFv9ajpk2zhJHQ7x61CSE2A_3)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L, NI pos) {
	NI result;
	result = (NI)0;
	(*L).lineNumber += ((NI) 1);
	result = fillBaseLexer__pFv9ajpk2zhJHQ7x61CSE2A_2(L, pos);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, closeBaseLexer__X9aea9bJavePT9cGIdd7JRH7Q_3)(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag* L) {
	llStreamClose__pzACjlxXGrH2rRQU5WrSmg((*L).stream);
}
N_LIB_PRIVATE N_NIMCALL(void, compiler_nimlexbaseDatInit000)(void) {

/* section: NIM_merge_TYPE_INIT1 */
static TNimNode* TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[9];
static TNimNode TM__jNFaG9cOzyJSKBcIonhGRGw_0[10];

/* section: NIM_merge_TYPE_INIT3 */
NTI__jTxk7Uc2dfr9aTDL2dZhO9ag_.size = sizeof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag);
NTI__jTxk7Uc2dfr9aTDL2dZhO9ag_.align = NIM_ALIGNOF(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag);
NTI__jTxk7Uc2dfr9aTDL2dZhO9ag_.kind = 17;
NTI__jTxk7Uc2dfr9aTDL2dZhO9ag_.base = (&NTI__ytyiCJqK439aF9cIibuRVpAg_);
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[0] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[1];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[1].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[1].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, bufpos);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[1].typ = (&NTI__rR5Bzr1D5krxoo1NcNyeMA_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[1].name = "bufpos";
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[1] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[2];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[2].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[2].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, buf);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[2].typ = (&NTI__S9agCYBinaYZnGWcjTdxclg_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[2].name = "buf";
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[2] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[3];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[3].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[3].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, bufStorage);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[3].typ = (&NTI__77mFvmsOLKik79ci2hXkHEg_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[3].name = "bufStorage";
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[3] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[4];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[4].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[4].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, bufLen);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[4].typ = (&NTI__rR5Bzr1D5krxoo1NcNyeMA_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[4].name = "bufLen";
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[4] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[5];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[5].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[5].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, stream);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[5].typ = (&NTI__WO3j4yVQ0yN0aRCt9bFEbtg_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[5].name = "stream";
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[5] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[6];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[6].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[6].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, lineNumber);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[6].typ = (&NTI__rR5Bzr1D5krxoo1NcNyeMA_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[6].name = "lineNumber";
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[6] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[7];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[7].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[7].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, sentinel);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[7].typ = (&NTI__rR5Bzr1D5krxoo1NcNyeMA_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[7].name = "sentinel";
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[7] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[8];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[8].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[8].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, lineStart);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[8].typ = (&NTI__rR5Bzr1D5krxoo1NcNyeMA_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[8].name = "lineStart";
TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[8] = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[9];
TM__jNFaG9cOzyJSKBcIonhGRGw_0[9].kind = 1;
TM__jNFaG9cOzyJSKBcIonhGRGw_0[9].offset = offsetof(tyObject_TBaseLexer__jTxk7Uc2dfr9aTDL2dZhO9ag, offsetBase);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[9].typ = (&NTI__rR5Bzr1D5krxoo1NcNyeMA_);
TM__jNFaG9cOzyJSKBcIonhGRGw_0[9].name = "offsetBase";
TM__jNFaG9cOzyJSKBcIonhGRGw_0[0].len = 9; TM__jNFaG9cOzyJSKBcIonhGRGw_0[0].kind = 2; TM__jNFaG9cOzyJSKBcIonhGRGw_0[0].sons = &TM__jNFaG9cOzyJSKBcIonhGRGw_2_9[0];
NTI__jTxk7Uc2dfr9aTDL2dZhO9ag_.node = &TM__jNFaG9cOzyJSKBcIonhGRGw_0[0];
}

