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

#include "nimbase.h"
typedef struct Rstnode313008 Rstnode313008;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Rstnodeseq313006 Rstnodeseq313006;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Cell47505 Cell47505;
typedef struct Cellseq47521 Cellseq47521;
typedef struct Gcheap49818 Gcheap49818;
typedef struct Gcstack49816 Gcstack49816;
typedef struct Cellset47517 Cellset47517;
typedef struct Pagedesc47513 Pagedesc47513;
typedef struct Memregion29688 Memregion29688;
typedef struct Smallchunk29640 Smallchunk29640;
typedef struct Llchunk29682 Llchunk29682;
typedef struct Bigchunk29642 Bigchunk29642;
typedef struct Intset29614 Intset29614;
typedef struct Trunk29610 Trunk29610;
typedef struct Avlnode29686 Avlnode29686;
typedef struct Gcstat49814 Gcstat49814;
typedef struct Basechunk29638 Basechunk29638;
typedef struct Freecell29630 Freecell29630;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  Rstnode313008  {
NU8 kind;
NimStringDesc* text;
NI level;
Rstnodeseq313006* sons;
};
typedef N_NIMCALL_PTR(void, TY3489) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3494) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3489 marker;
TY3494 deepcopy;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct  Cell47505  {
NI refcount;
TNimType* typ;
};
struct  Cellseq47521  {
NI len;
NI cap;
Cell47505** d;
};
struct  Cellset47517  {
NI counter;
NI max;
Pagedesc47513* head;
Pagedesc47513** data;
};
typedef Smallchunk29640* TY29703[512];
typedef Trunk29610* Trunkbuckets29612[256];
struct  Intset29614  {
Trunkbuckets29612 data;
};
struct  Memregion29688  {
NI minlargeobj;
NI maxlargeobj;
TY29703 freesmallchunks;
Llchunk29682* llmem;
NI currmem;
NI maxmem;
NI freemem;
NI lastsize;
Bigchunk29642* freechunkslist;
Intset29614 chunkstarts;
Avlnode29686* root;
Avlnode29686* deleted;
Avlnode29686* last;
Avlnode29686* freeavlnodes;
};
struct  Gcstat49814  {
NI stackscans;
NI cyclecollections;
NI maxthreshold;
NI maxstacksize;
NI maxstackcells;
NI cycletablesize;
NI64 maxpause;
};
struct  Gcheap49818  {
Gcstack49816* stack;
void* stackbottom;
NI cyclethreshold;
Cellseq47521 zct;
Cellseq47521 decstack;
Cellset47517 cycleroots;
Cellseq47521 tempstack;
NI recgclock;
Memregion29688 region;
Gcstat49814 stat;
};
struct  Gcstack49816  {
Gcstack49816* prev;
Gcstack49816* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY29619[8];
struct  Pagedesc47513  {
Pagedesc47513* next;
NI key;
TY29619 bits;
};
struct  Basechunk29638  {
NI prevsize;
NI size;
NIM_BOOL used;
};
struct  Smallchunk29640  {
  Basechunk29638 Sup;
Smallchunk29640* next;
Smallchunk29640* prev;
Freecell29630* freelist;
NI free;
NI acc;
NF data;
};
struct  Llchunk29682  {
NI size;
NI acc;
Llchunk29682* next;
};
struct  Bigchunk29642  {
  Basechunk29638 Sup;
Bigchunk29642* next;
Bigchunk29642* prev;
NI align;
NF data;
};
struct  Trunk29610  {
Trunk29610* next;
NI key;
TY29619 bits;
};
typedef Avlnode29686* TY29693[2];
struct  Avlnode29686  {
TY29693 link;
NI key;
NI upperbound;
NI level;
};
struct  Freecell29630  {
Freecell29630* next;
NI zerofield;
};
struct Rstnodeseq313006 {
  TGenericSeq Sup;
  Rstnode313008* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP2605)(void* p, NI op);
N_NIMCALL(void, TMP2606)(void* p, NI op);
N_NIMCALL(Rstnode313008*, newrstnode_313093)(NU8 kind);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(Cell47505*, usrtocell_51440)(void* usr);
static N_INLINE(void, rtladdzct_53001)(Cell47505* c);
N_NOINLINE(void, addzct_51417)(Cellseq47521* s, Cell47505* 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_313138)(Rstnode313008* father, Rstnode313008* son);
TNimType NTI313008; /* RstNode */
TNimType NTI313002; /* RstNodeKind */
extern TNimType NTI138; /* string */
extern TNimType NTI104; /* int */
TNimType NTI313006; /* RstNodeSeq */
TNimType NTI313004; /* PRstNode */
extern Gcheap49818 gch_49859;

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

N_NIMCALL(Rstnode313008*, lastson_313126)(Rstnode313008* n) {
	Rstnode313008* result;
	result = 0;
	result = (*n).sons->data[(NI)(((*n).sons ? (*n).sons->Sup.len : 0) - ((NI) 1))];
	return result;
}
N_NIMCALL(void, TMP2605)(void* p, NI op) {
	Rstnodeseq313006* a;
	NI LOC1;
	a = (Rstnodeseq313006*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}
N_NIMCALL(void, TMP2606)(void* p, NI op) {
	Rstnode313008* a;
	a = (Rstnode313008*)p;
	nimGCvisit((void*)(*a).text, op);
	nimGCvisit((void*)(*a).sons, op);
}

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

static N_INLINE(void, rtladdzct_53001)(Cell47505* c) {
	addzct_51417((&gch_49859.zct), c);
}

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

N_NIMCALL(Rstnode313008*, newrstnode_313093)(NU8 kind) {
	Rstnode313008* result;
	result = 0;
	result = (Rstnode313008*) newObj((&NTI313004), sizeof(Rstnode313008));
	if ((*result).sons) nimGCunrefNoCycle((*result).sons);
	(*result).sons = (Rstnodeseq313006*) newSeqRC1((&NTI313006), 0);
	(*result).kind = kind;
	return result;
}

N_NIMCALL(Rstnode313008*, newrstnode_313121)(NU8 kind, NimStringDesc* s) {
	Rstnode313008* result;
	NimStringDesc* LOC1;
	result = 0;
	result = newrstnode_313093(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) {
	{
		Cell47505* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_51440(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell47505* c;
		if (!!(((*dest) == NIM_NIL))) goto LA7;
		c = usrtocell_51440((*dest));
		{
			(*c).refcount -= ((NI) 8);
			if (!((NU64)((*c).refcount) < (NU64)(((NI) 8)))) goto LA11;
			rtladdzct_53001(c);
		}
		LA11: ;
	}
	LA7: ;
	(*dest) = src;
}

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

N_NIMCALL(void, addifnotnil_313152)(Rstnode313008* father, Rstnode313008* son) {
	{
		if (!!((son == NIM_NIL))) goto LA3;
		add_313138(father, son);
	}
	LA3: ;
}
NIM_EXTERNC N_NOINLINE(void, docutils_rstastInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, docutils_rstastDatInit000)(void) {
static TNimNode* TMP2601[4];
static TNimNode* TMP2602[65];
NI TMP2604;
static char* NIM_CONST TMP2603[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 TMP965[71];
NTI313008.size = sizeof(Rstnode313008);
NTI313008.kind = 18;
NTI313008.base = 0;
NTI313008.flags = 2;
TMP2601[0] = &TMP965[1];
NTI313002.size = sizeof(NU8);
NTI313002.kind = 14;
NTI313002.base = 0;
NTI313002.flags = 3;
for (TMP2604 = 0; TMP2604 < 65; TMP2604++) {
TMP965[TMP2604+2].kind = 1;
TMP965[TMP2604+2].offset = TMP2604;
TMP965[TMP2604+2].name = TMP2603[TMP2604];
TMP2602[TMP2604] = &TMP965[TMP2604+2];
}
TMP965[67].len = 65; TMP965[67].kind = 2; TMP965[67].sons = &TMP2602[0];
NTI313002.node = &TMP965[67];
TMP965[1].kind = 1;
TMP965[1].offset = offsetof(Rstnode313008, kind);
TMP965[1].typ = (&NTI313002);
TMP965[1].name = "kind";
TMP2601[1] = &TMP965[68];
TMP965[68].kind = 1;
TMP965[68].offset = offsetof(Rstnode313008, text);
TMP965[68].typ = (&NTI138);
TMP965[68].name = "text";
TMP2601[2] = &TMP965[69];
TMP965[69].kind = 1;
TMP965[69].offset = offsetof(Rstnode313008, level);
TMP965[69].typ = (&NTI104);
TMP965[69].name = "level";
TMP2601[3] = &TMP965[70];
NTI313006.size = sizeof(Rstnodeseq313006*);
NTI313006.kind = 24;
NTI313006.base = (&NTI313004);
NTI313006.flags = 2;
NTI313006.marker = TMP2605;
TMP965[70].kind = 1;
TMP965[70].offset = offsetof(Rstnode313008, sons);
TMP965[70].typ = (&NTI313006);
TMP965[70].name = "sons";
TMP965[0].len = 4; TMP965[0].kind = 2; TMP965[0].sons = &TMP2601[0];
NTI313008.node = &TMP965[0];
NTI313004.size = sizeof(Rstnode313008*);
NTI313004.kind = 22;
NTI313004.base = (&NTI313008);
NTI313004.flags = 2;
NTI313004.marker = TMP2606;
}

