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

#include "nimbase.h"
typedef struct Rstnode332011 Rstnode332011;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Rstnodeseq332009 Rstnodeseq332009;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Cell48946 Cell48946;
typedef struct Cellseq48962 Cellseq48962;
typedef struct Gcheap51018 Gcheap51018;
typedef struct Gcstack51016 Gcstack51016;
typedef struct Cellset48958 Cellset48958;
typedef struct Pagedesc48954 Pagedesc48954;
typedef struct Memregion30891 Memregion30891;
typedef struct Smallchunk30843 Smallchunk30843;
typedef struct Llchunk30885 Llchunk30885;
typedef struct Bigchunk30845 Bigchunk30845;
typedef struct Intset30817 Intset30817;
typedef struct Trunk30813 Trunk30813;
typedef struct Avlnode30889 Avlnode30889;
typedef struct Gcstat51014 Gcstat51014;
typedef struct Basechunk30841 Basechunk30841;
typedef struct Freecell30833 Freecell30833;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Rstnode332011  {
NU8 kind;
NimStringDesc* text;
NI level;
Rstnodeseq332009* sons;
};
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  Cell48946  {
NI refcount;
TNimType* typ;
};
struct  Cellseq48962  {
NI len;
NI cap;
Cell48946** d;
};
struct  Cellset48958  {
NI counter;
NI max;
Pagedesc48954* head;
Pagedesc48954** data;
};
typedef Smallchunk30843* TY30906[512];
typedef Trunk30813* Trunkbuckets30815[256];
struct  Intset30817  {
Trunkbuckets30815 data;
};
struct  Memregion30891  {
NI minlargeobj;
NI maxlargeobj;
TY30906 freesmallchunks;
Llchunk30885* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk30845* freechunkslist;
Intset30817 chunkstarts;
Avlnode30889* root;
Avlnode30889* deleted;
Avlnode30889* last;
Avlnode30889* freeavlnodes;
};
struct  Gcstat51014  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap51018  {
Gcstack51016* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq48962 zct;
Cellseq48962 decstack;
Cellset48958 cycleroots;
Cellseq48962 tempstack;
NI recgclock;
Memregion30891 region;
Gcstat51014 stat;
};
struct  Gcstack51016  {
Gcstack51016* prev;
Gcstack51016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY30822[8];
struct  Pagedesc48954  {
Pagedesc48954* next;
NI key;
TY30822 bits;
};
struct  Basechunk30841  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk30843  {
  Basechunk30841 Sup;
Smallchunk30843* next;
Smallchunk30843* prev;
Freecell30833* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk30885  {
NI size;
NI acc;
Llchunk30885* next;
};
struct  Bigchunk30845  {
  Basechunk30841 Sup;
Bigchunk30845* next;
Bigchunk30845* prev;
NI align;
NF data;
};
struct  Trunk30813  {
Trunk30813* next;
NI key;
TY30822 bits;
};
typedef Avlnode30889* TY30896[2];
struct  Avlnode30889  {
TY30896 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell30833  {
Freecell30833* next;
NI zerofield;
};
struct Rstnodeseq332009 {
  TGenericSeq Sup;
  Rstnode332011* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP2566)(void* p, NI op);
N_NIMCALL(void, TMP2567)(void* p, NI op);
N_NIMCALL(Rstnode332011*, newrstnode_332108)(NU8 kind);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(Cell48946*, usrtocell_52646)(void* usr);
static N_INLINE(void, rtladdzct_54204)(Cell48946* c);
N_NOINLINE(void, addzct_52617)(Cellseq48962* s, Cell48946* c);
N_NIMCALL(void*, newSeqRC1)(TNimType* typ, NI len);
N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src);
N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq, NI elemsize);
static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src);
N_NIMCALL(void, add_332171)(Rstnode332011* father, Rstnode332011* son);
TNimType NTI332011; /* RstNode */
TNimType NTI332005; /* RstNodeKind */
extern TNimType NTI149; /* string */
extern TNimType NTI108; /* int */
TNimType NTI332009; /* RstNodeSeq */
TNimType NTI332007; /* PRstNode */
extern Gcheap51018 gch_51059;

N_NIMCALL(NI, len_332090)(Rstnode332011* n) {
	NI result;
	result = 0;
	result = ((*n).sons ? (*n).sons->Sup.len : 0);
	return result;
}

N_NIMCALL(Rstnode332011*, lastson_332153)(Rstnode332011* n) {
	Rstnode332011* result;
	result = 0;
	result = (*n).sons->data[(NI)(((*n).sons ? (*n).sons->Sup.len : 0) - ((NI) 1))];
	return result;
}
N_NIMCALL(void, TMP2566)(void* p, NI op) {
	Rstnodeseq332009* a;
	NI LOC1;
	a = (Rstnodeseq332009*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}
N_NIMCALL(void, TMP2567)(void* p, NI op) {
	Rstnode332011* a;
	a = (Rstnode332011*)p;
	nimGCvisit((void*)(*a).text, op);
	nimGCvisit((void*)(*a).sons, op);
}

static N_INLINE(Cell48946*, usrtocell_52646)(void* usr) {
	Cell48946* result;
	result = 0;
	result = ((Cell48946*) ((NI)((NU64)(((NI) (usr))) - (NU64)(((NI)sizeof(Cell48946))))));
	return result;
}

static N_INLINE(void, rtladdzct_54204)(Cell48946* c) {
	addzct_52617((&gch_51059.zct), c);
}

static N_INLINE(void, nimGCunrefNoCycle)(void* p) {
	Cell48946* c;
	c = usrtocell_52646(p);
	{
		(*c).refcount -= ((NI) 8);
		if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA3;
		rtladdzct_54204(c);
	}
	LA3: ;
}

N_NIMCALL(Rstnode332011*, newrstnode_332108)(NU8 kind) {
	Rstnode332011* result;
	result = 0;
	result = (Rstnode332011*) newObj((&NTI332007), sizeof(Rstnode332011));
	if ((*result).sons) nimGCunrefNoCycle((*result).sons);
	(*result).sons = (Rstnodeseq332009*) newSeqRC1((&NTI332009), 0);
	(*result).kind = kind;
	return result;
}

N_NIMCALL(Rstnode332011*, newrstnode_332142)(NU8 kind, NimStringDesc* s) {
	Rstnode332011* result;
	NimStringDesc* LOC1;
	result = 0;
	result = newrstnode_332108(kind);
	LOC1 = 0;
	LOC1 = (*result).text; (*result).text = copyStringRC1(s);
	if (LOC1) nimGCunrefNoCycle(LOC1);
	return result;
}

static N_INLINE(void, asgnRefNoCycle)(void** dest, void* src) {
	{
		Cell48946* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_52646(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell48946* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_52646((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA11;
			rtladdzct_54204(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

N_NIMCALL(void, add_332171)(Rstnode332011* father, Rstnode332011* son) {
	(*father).sons = (Rstnodeseq332009*) incrSeqV2(&((*father).sons)->Sup, sizeof(Rstnode332011*));
	asgnRefNoCycle((void**) (&(*father).sons->data[(*father).sons->Sup.len]), son);
	++(*father).sons->Sup.len;
}

N_NIMCALL(void, addifnotnil_332191)(Rstnode332011* father, Rstnode332011* son) {
	{
		if (!!((son == NIM_NIL))) goto LA3;
		add_332171(father, son);
	}
	LA3: ;
}
NIM_EXTERNC N_NOINLINE(void, docutils_rstastInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, docutils_rstastDatInit000)(void) {
static TNimNode* TMP2562[4];
static TNimNode* TMP2563[65];
NI TMP2565;
static char* NIM_CONST TMP2564[65] = {
"rnInner", 
"rnHeadline", 
"rnOverline", 
"rnTransition", 
"rnParagraph", 
"rnBulletList", 
"rnBulletItem", 
"rnEnumList", 
"rnEnumItem", 
"rnDefList", 
"rnDefItem", 
"rnDefName", 
"rnDefBody", 
"rnFieldList", 
"rnField", 
"rnFieldName", 
"rnFieldBody", 
"rnOptionList", 
"rnOptionListItem", 
"rnOptionGroup", 
"rnOption", 
"rnOptionString", 
"rnOptionArgument", 
"rnDescription", 
"rnLiteralBlock", 
"rnQuotedLiteralBlock", 
"rnLineBlock", 
"rnLineBlockItem", 
"rnBlockQuote", 
"rnTable", 
"rnGridTable", 
"rnTableRow", 
"rnTableHeaderCell", 
"rnTableDataCell", 
"rnLabel", 
"rnFootnote", 
"rnCitation", 
"rnStandaloneHyperlink", 
"rnHyperlink", 
"rnRef", 
"rnDirective", 
"rnDirArg", 
"rnRaw", 
"rnTitle", 
"rnContents", 
"rnImage", 
"rnFigure", 
"rnCodeBlock", 
"rnRawHtml", 
"rnRawLatex", 
"rnContainer", 
"rnIndex", 
"rnSubstitutionDef", 
"rnGeneralRole", 
"rnSub", 
"rnSup", 
"rnIdx", 
"rnEmphasis", 
"rnStrongEmphasis", 
"rnTripleEmphasis", 
"rnInterpretedText", 
"rnInlineLiteral", 
"rnSubstitutionReferences", 
"rnSmiley", 
"rnLeaf"};
static TNimNode TMP963[71];
NTI332011.size = sizeof(Rstnode332011);
NTI332011.kind = 18;
NTI332011.base = 0;
NTI332011.flags = 2;
TMP2562[0] = &TMP963[1];
NTI332005.size = sizeof(NU8);
NTI332005.kind = 14;
NTI332005.base = 0;
NTI332005.flags = 3;
for (TMP2565 = 0; TMP2565 < 65; TMP2565++) {
TMP963[TMP2565+2].kind = 1;
TMP963[TMP2565+2].offset = TMP2565;
TMP963[TMP2565+2].name = TMP2564[TMP2565];
TMP2563[TMP2565] = &TMP963[TMP2565+2];
}
TMP963[67].len = 65; TMP963[67].kind = 2; TMP963[67].sons = &TMP2563[0];
NTI332005.node = &TMP963[67];
TMP963[1].kind = 1;
TMP963[1].offset = offsetof(Rstnode332011, kind);
TMP963[1].typ = (&NTI332005);
TMP963[1].name = "kind";
TMP2562[1] = &TMP963[68];
TMP963[68].kind = 1;
TMP963[68].offset = offsetof(Rstnode332011, text);
TMP963[68].typ = (&NTI149);
TMP963[68].name = "text";
TMP2562[2] = &TMP963[69];
TMP963[69].kind = 1;
TMP963[69].offset = offsetof(Rstnode332011, level);
TMP963[69].typ = (&NTI108);
TMP963[69].name = "level";
TMP2562[3] = &TMP963[70];
NTI332009.size = sizeof(Rstnodeseq332009*);
NTI332009.kind = 24;
NTI332009.base = (&NTI332007);
NTI332009.flags = 2;
NTI332009.marker = TMP2566;
TMP963[70].kind = 1;
TMP963[70].offset = offsetof(Rstnode332011, sons);
TMP963[70].typ = (&NTI332009);
TMP963[70].name = "sons";
TMP963[0].len = 4; TMP963[0].kind = 2; TMP963[0].sons = &TMP2562[0];
NTI332011.node = &TMP963[0];
NTI332007.size = sizeof(Rstnode332011*);
NTI332007.kind = 22;
NTI332007.base = (&NTI332011);
NTI332007.flags = 2;
NTI332007.marker = TMP2567;
}

