/* Generated by Nim Compiler v0.17.0 */
/*   (c) 2017 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, arm, gcc */
/* Command for C compiler:
   gcc -c  -w -O3 -fno-strict-aliasing -fPIC  -I/build/nim/src/Nim-0.17.0/lib -o lib/nimcache/stdlib_lexbase.o lib/nimcache/stdlib_lexbase.c */
#define NIM_NEW_MANGLING_RULES
#define NIM_INTBITS 32

#include "nimbase.h"
#include <string.h>
#undef linux
#undef near
typedef struct BaseLexer_B6cGbTPhMsqMovc9cOcIHRw BaseLexer_B6cGbTPhMsqMovc9cOcIHRw;
typedef struct StreamObj_RShkcoDOPnoCVhtpN1hDPQ StreamObj_RShkcoDOPnoCVhtpN1hDPQ;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef NU8 TY_nmiMWKVIe46vacnhAFrQvw_Set[32];
typedef NU8 TNimKind_jIBKr1ejBgsfM33Kxw4j7A;
typedef NU8 TNimTypeFlag_v8QUszD1sWlSIWZz7mC4bQ_Set;
typedef N_NIMCALL_PTR(void, TY_ojoeKfW4VYIm36I9cpDTQIg) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY_WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p);
struct  TNimType  {
NI size;
TNimKind_jIBKr1ejBgsfM33Kxw4j7A kind;
TNimTypeFlag_v8QUszD1sWlSIWZz7mC4bQ_Set flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY_ojoeKfW4VYIm36I9cpDTQIg marker;
TY_WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct  BaseLexer_B6cGbTPhMsqMovc9cOcIHRw  {
  TNimObject Sup;
NI bufpos;
NCSTRING buf;
NI bufLen;
StreamObj_RShkcoDOPnoCVhtpN1hDPQ* input;
NI lineNumber;
NI sentinel;
NI lineStart;
TY_nmiMWKVIe46vacnhAFrQvw_Set refillChars;
};
typedef N_NIMCALL_PTR(void, TY_cnkJEp9bna8U6yi9aVW9cAJ0Q) (StreamObj_RShkcoDOPnoCVhtpN1hDPQ* s);
typedef N_NIMCALL_PTR(NIM_BOOL, TY_KjFcmLOhf4VQvVcyLJWXZw) (StreamObj_RShkcoDOPnoCVhtpN1hDPQ* s);
typedef N_NIMCALL_PTR(void, TY_jlOYFw9cHausuCbPoWx2iiA) (StreamObj_RShkcoDOPnoCVhtpN1hDPQ* s, NI pos);
typedef N_NIMCALL_PTR(NI, TY_Xzm85qBLb9cf9cu8VOfAr8PQ) (StreamObj_RShkcoDOPnoCVhtpN1hDPQ* s);
typedef N_NIMCALL_PTR(NI, TY_tjaJtoUzLe1BMUbItlcGhQ) (StreamObj_RShkcoDOPnoCVhtpN1hDPQ* s, void* buffer, NI bufLen);
typedef N_NIMCALL_PTR(void, TY_b9bsIuILxTLVZHPvJBW187A) (StreamObj_RShkcoDOPnoCVhtpN1hDPQ* s, void* buffer, NI bufLen);
struct  StreamObj_RShkcoDOPnoCVhtpN1hDPQ  {
  TNimObject Sup;
TY_cnkJEp9bna8U6yi9aVW9cAJ0Q closeImpl;
TY_KjFcmLOhf4VQvVcyLJWXZw atEndImpl;
TY_jlOYFw9cHausuCbPoWx2iiA setPositionImpl;
TY_Xzm85qBLb9cf9cu8VOfAr8PQ getPositionImpl;
TY_tjaJtoUzLe1BMUbItlcGhQ readDataImpl;
TY_tjaJtoUzLe1BMUbItlcGhQ peekDataImpl;
TY_b9bsIuILxTLVZHPvJBW187A writeDataImpl;
TY_cnkJEp9bna8U6yi9aVW9cAJ0Q flushImpl;
};
typedef NU8 TNimNodeKind_unfNsxrcATrufDZmpBq4HQ;
struct  TNimNode  {
TNimNodeKind_unfNsxrcATrufDZmpBq4HQ kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_LIB_EXPORT N_NOCONV(void*, nimrtl_alloc)(NI size);
N_NIMCALL(void, fillBuffer_QbedUCk2XwI9c7bbRzXBY0g)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L);
static N_INLINE(void, moveMem_fPlwH3r9agN9aEHB6yCPMh0wlexbase)(void* dest, void* source, NI size);
N_NIMCALL(NI, readData_Gnwdizh7H5Q9cYivUoGHrVA)(StreamObj_RShkcoDOPnoCVhtpN1hDPQ* s, void* buffer, NI bufLen);
N_LIB_EXPORT N_NOCONV(void*, nimrtl_realloc)(void* p, NI newSize);
N_NIMCALL(void, skipUtf8Bom_BMPUUaJVkFzDJfE3dUzOCw)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L);
N_LIB_EXPORT N_NOCONV(void, nimrtl_dealloc)(void* p);
N_NIMCALL(void, close_4ed7IXme7lqtClFI7s2sTQ)(StreamObj_RShkcoDOPnoCVhtpN1hDPQ* s);
N_NIMCALL(NI, fillBaseLexer_IwUEvMBOLRY9cqyar6XKEaw_2)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L, NI pos);

static N_INLINE(void, moveMem_fPlwH3r9agN9aEHB6yCPMh0wlexbase)(void* dest, void* source, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memmove(dest, source, ((size_t) (size)));
}

N_NIMCALL(void, fillBuffer_QbedUCk2XwI9c7bbRzXBY0g)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L) {
	NI charsRead;
	NI toCopy;
	NI s;
	NI oldBufLen;
	NI T5_;
	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_fPlwH3r9agN9aEHB6yCPMh0wlexbase(((void*) ((*L).buf)), ((void*) ((&(*L).buf[(NI)((*L).sentinel + ((NI) 1))]))), ((NI) ((NI)(toCopy * ((NI) 1)))));
	}
	LA3_: ;
	T5_ = (NI)0;
	T5_ = readData_Gnwdizh7H5Q9cYivUoGHrVA((*L).input, ((void*) ((&(*L).buf[toCopy]))), (NI)((NI)((*L).sentinel + ((NI) 1)) * ((NI) 1)));
	charsRead = (NI)(T5_ / ((NI) 1));
	s = (NI)(toCopy + charsRead);
	{
		if (!(charsRead < (NI)((*L).sentinel + ((NI) 1)))) goto LA8_;
		(*L).buf[s] = 0;
		(*L).sentinel = s;
	}
	goto LA6_;
	LA8_: ;
	{
		s -= ((NI) 1);
		{
			while (1) {
				{
					while (1) {
						NIM_BOOL T15_;
						T15_ = (NIM_BOOL)0;
						T15_ = (((NI) 0) <= s);
						if (!(T15_)) goto LA16_;
						T15_ = !((((*L).refillChars[(NU)(((NU8)((*L).buf[s])))>>3] &(1U<<((NU)(((NU8)((*L).buf[s])))&7U)))!=0));
						LA16_: ;
						if (!T15_) goto LA14;
						s -= ((NI) 1);
					} LA14: ;
				}
				{
					if (!(((NI) 0) <= s)) goto LA19_;
					(*L).sentinel = s;
					goto LA11;
				}
				goto LA17_;
				LA19_: ;
				{
					void* T22_;
					NI T23_;
					oldBufLen = (*L).bufLen;
					(*L).bufLen = (NI)((*L).bufLen * ((NI) 2));
					T22_ = (void*)0;
					T22_ = nimrtl_realloc(((void*) ((*L).buf)), ((NI) ((NI)((*L).bufLen * ((NI) 1)))));
					(*L).buf = ((NCSTRING) (T22_));
					T23_ = (NI)0;
					T23_ = readData_Gnwdizh7H5Q9cYivUoGHrVA((*L).input, ((void*) ((&(*L).buf[oldBufLen]))), (NI)(oldBufLen * ((NI) 1)));
					charsRead = (NI)(T23_ / ((NI) 1));
					{
						if (!(charsRead < oldBufLen)) goto LA26_;
						(*L).buf[(NI)(oldBufLen + charsRead)] = 0;
						(*L).sentinel = (NI)(oldBufLen + charsRead);
						goto LA11;
					}
					LA26_: ;
					s = (NI)((*L).bufLen - ((NI) 1));
				}
				LA17_: ;
			}
		} LA11: ;
	}
	LA6_: ;
}

N_NIMCALL(void, skipUtf8Bom_BMPUUaJVkFzDJfE3dUzOCw)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* 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_NIMCALL(void, open_xmgaYJZNnO6QcDtac9bs3Vg)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L, StreamObj_RShkcoDOPnoCVhtpN1hDPQ* input, NI bufLen, TY_nmiMWKVIe46vacnhAFrQvw_Set refillChars) {
	void* T1_;
	unsureAsgnRef((void**) (&(*L).input), input);
	(*L).bufpos = ((NI) 0);
	(*L).bufLen = bufLen;
	memcpy((void*)(*L).refillChars, (NIM_CONST void*)refillChars, 32);
	T1_ = (void*)0;
	T1_ = nimrtl_alloc(((NI) ((NI)(bufLen * ((NI) 1)))));
	(*L).buf = ((NCSTRING) (T1_));
	(*L).sentinel = (NI)(bufLen - ((NI) 1));
	(*L).lineStart = ((NI) 0);
	(*L).lineNumber = ((NI) 1);
	fillBuffer_QbedUCk2XwI9c7bbRzXBY0g(L);
	skipUtf8Bom_BMPUUaJVkFzDJfE3dUzOCw(L);
}

N_NIMCALL(void, close_QbedUCk2XwI9c7bbRzXBY0g_2)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L) {
	nimrtl_dealloc(((void*) ((*L).buf)));
	close_4ed7IXme7lqtClFI7s2sTQ((*L).input);
}

N_NIMCALL(NI, getColNumber_9cj186ckGjLqyndkoW7bBdg)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* 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_NIMCALL(NI, fillBaseLexer_IwUEvMBOLRY9cqyar6XKEaw_2)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L, NI pos) {
	NI result;
	result = (NI)0;
	{
		if (!(pos < (*L).sentinel)) goto LA3_;
		result = (NI)(pos + ((NI) 1));
	}
	goto LA1_;
	LA3_: ;
	{
		fillBuffer_QbedUCk2XwI9c7bbRzXBY0g(L);
		(*L).bufpos = ((NI) 0);
		result = ((NI) 0);
	}
	LA1_: ;
	return result;
}

N_NIMCALL(NI, handleCR_IwUEvMBOLRY9cqyar6XKEaw)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L, NI pos) {
	NI result;
	result = (NI)0;
	(*L).lineNumber += ((NI) 1);
	result = fillBaseLexer_IwUEvMBOLRY9cqyar6XKEaw_2(L, pos);
	{
		if (!((NU8)((*L).buf[result]) == (NU8)(10))) goto LA3_;
		result = fillBaseLexer_IwUEvMBOLRY9cqyar6XKEaw_2(L, result);
	}
	LA3_: ;
	(*L).lineStart = result;
	return result;
}

N_NIMCALL(NI, handleLF_IwUEvMBOLRY9cqyar6XKEaw_3)(BaseLexer_B6cGbTPhMsqMovc9cOcIHRw* L, NI pos) {
	NI result;
	result = (NI)0;
	(*L).lineNumber += ((NI) 1);
	result = fillBaseLexer_IwUEvMBOLRY9cqyar6XKEaw_2(L, pos);
	(*L).lineStart = result;
	return result;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_lexbaseInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_lexbaseDatInit000)(void) {
}

