/* 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 Rstnode330011 Rstnode330011;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct Rstnodeseq330009 Rstnodeseq330009;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct Cell48947 Cell48947;
typedef struct Cellseq48963 Cellseq48963;
typedef struct Gcheap51018 Gcheap51018;
typedef struct Gcstack51016 Gcstack51016;
typedef struct Cellset48959 Cellset48959;
typedef struct Pagedesc48955 Pagedesc48955;
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  Rstnode330011  {
NU8 kind;
NimStringDesc* text;
NI level;
Rstnodeseq330009* 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  Cell48947  {
NI refcount;
TNimType* typ;
};
struct  Cellseq48963  {
NI len;
NI cap;
Cell48947** d;
};
struct  Cellset48959  {
NI counter;
NI max;
Pagedesc48955* head;
Pagedesc48955** 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;
Cellseq48963 zct;
Cellseq48963 decstack;
Cellset48959 cycleroots;
Cellseq48963 tempstack;
NI recgclock;
Memregion30891 region;
Gcstat51014 stat;
};
struct  Gcstack51016  {
Gcstack51016* prev;
Gcstack51016* next;
void* starts;
void* pos;
NI maxstacksize;
};
typedef NI TY30822[8];
struct  Pagedesc48955  {
Pagedesc48955* 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 Rstnodeseq330009 {
  TGenericSeq Sup;
  Rstnode330011* data[SEQ_DECL_SIZE];
};
N_NIMCALL(void, nimGCvisit)(void* d, NI op);
N_NIMCALL(void, TMP2564)(void* p, NI op);
N_NIMCALL(void, TMP2565)(void* p, NI op);
N_NIMCALL(Rstnode330011*, newrstnode_330108)(NU8 kind);
N_NIMCALL(void*, newObj)(TNimType* typ, NI size);
static N_INLINE(void, nimGCunrefNoCycle)(void* p);
static N_INLINE(Cell48947*, usrtocell_52646)(void* usr);
static N_INLINE(void, rtladdzct_54204)(Cell48947* c);
N_NOINLINE(void, addzct_52617)(Cellseq48963* s, Cell48947* 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_330171)(Rstnode330011* father, Rstnode330011* son);
TNimType NTI330011; /* RstNode */
TNimType NTI330005; /* RstNodeKind */
extern TNimType NTI149; /* string */
extern TNimType NTI108; /* int */
TNimType NTI330009; /* RstNodeSeq */
TNimType NTI330007; /* PRstNode */
extern Gcheap51018 gch_51059;

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

N_NIMCALL(Rstnode330011*, lastson_330153)(Rstnode330011* n) {
	Rstnode330011* result;
	result = 0;
	result = (*n).sons->data[(NI)(((*n).sons ? (*n).sons->Sup.len : 0) - ((NI) 1))];
	return result;
}
N_NIMCALL(void, TMP2564)(void* p, NI op) {
	Rstnodeseq330009* a;
	NI LOC1;
	a = (Rstnodeseq330009*)p;
	LOC1 = 0;
	for (LOC1 = 0; LOC1 < a->Sup.len; LOC1++) {
	nimGCvisit((void*)a->data[LOC1], op);
	}
}
N_NIMCALL(void, TMP2565)(void* p, NI op) {
	Rstnode330011* a;
	a = (Rstnode330011*)p;
	nimGCvisit((void*)(*a).text, op);
	nimGCvisit((void*)(*a).sons, op);
}

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

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

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

N_NIMCALL(Rstnode330011*, newrstnode_330108)(NU8 kind) {
	Rstnode330011* result;
	result = 0;
	result = (Rstnode330011*) newObj((&NTI330007), sizeof(Rstnode330011));
	if ((*result).sons) nimGCunrefNoCycle((*result).sons);
	(*result).sons = (Rstnodeseq330009*) newSeqRC1((&NTI330009), 0);
	(*result).kind = kind;
	return result;
}

N_NIMCALL(Rstnode330011*, newrstnode_330142)(NU8 kind, NimStringDesc* s) {
	Rstnode330011* result;
	NimStringDesc* LOC1;
	result = 0;
	result = newrstnode_330108(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) {
	{
		Cell48947* c;
		if (!!((src == NIM_NIL))) goto LA3;
		c = usrtocell_52646(src);
		(*c).refcount += ((NI) 8);
	}
	LA3: ;
	{
		Cell48947* 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_330171)(Rstnode330011* father, Rstnode330011* son) {
	(*father).sons = (Rstnodeseq330009*) incrSeqV2(&((*father).sons)->Sup, sizeof(Rstnode330011*));
	asgnRefNoCycle((void**) (&(*father).sons->data[(*father).sons->Sup.len]), son);
	++(*father).sons->Sup.len;
}

N_NIMCALL(void, addifnotnil_330191)(Rstnode330011* father, Rstnode330011* son) {
	{
		if (!!((son == NIM_NIL))) goto LA3;
		add_330171(father, son);
	}
	LA3: ;
}
NIM_EXTERNC N_NOINLINE(void, docutils_rstastInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, docutils_rstastDatInit000)(void) {
static TNimNode* TMP2560[4];
static TNimNode* TMP2561[65];
NI TMP2563;
static char* NIM_CONST TMP2562[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 TMP961[71];
NTI330011.size = sizeof(Rstnode330011);
NTI330011.kind = 18;
NTI330011.base = 0;
NTI330011.flags = 2;
TMP2560[0] = &TMP961[1];
NTI330005.size = sizeof(NU8);
NTI330005.kind = 14;
NTI330005.base = 0;
NTI330005.flags = 3;
for (TMP2563 = 0; TMP2563 < 65; TMP2563++) {
TMP961[TMP2563+2].kind = 1;
TMP961[TMP2563+2].offset = TMP2563;
TMP961[TMP2563+2].name = TMP2562[TMP2563];
TMP2561[TMP2563] = &TMP961[TMP2563+2];
}
TMP961[67].len = 65; TMP961[67].kind = 2; TMP961[67].sons = &TMP2561[0];
NTI330005.node = &TMP961[67];
TMP961[1].kind = 1;
TMP961[1].offset = offsetof(Rstnode330011, kind);
TMP961[1].typ = (&NTI330005);
TMP961[1].name = "kind";
TMP2560[1] = &TMP961[68];
TMP961[68].kind = 1;
TMP961[68].offset = offsetof(Rstnode330011, text);
TMP961[68].typ = (&NTI149);
TMP961[68].name = "text";
TMP2560[2] = &TMP961[69];
TMP961[69].kind = 1;
TMP961[69].offset = offsetof(Rstnode330011, level);
TMP961[69].typ = (&NTI108);
TMP961[69].name = "level";
TMP2560[3] = &TMP961[70];
NTI330009.size = sizeof(Rstnodeseq330009*);
NTI330009.kind = 24;
NTI330009.base = (&NTI330007);
NTI330009.flags = 2;
NTI330009.marker = TMP2564;
TMP961[70].kind = 1;
TMP961[70].offset = offsetof(Rstnode330011, sons);
TMP961[70].typ = (&NTI330009);
TMP961[70].name = "sons";
TMP961[0].len = 4; TMP961[0].kind = 2; TMP961[0].sons = &TMP2560[0];
NTI330011.node = &TMP961[0];
NTI330007.size = sizeof(Rstnode330011*);
NTI330007.kind = 22;
NTI330007.base = (&NTI330011);
NTI330007.flags = 2;
NTI330007.marker = TMP2565;
}

