From a64f03230afa69f2143b0eb159c9294998c5e19b Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 10 Apr 2012 20:53:44 +0300 Subject: proper order of initialization for .global. variables --- compiler/ccgstmts.nim | 2 +- compiler/cgen.nim | 6 +++++- compiler/cgendata.nim | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'compiler') diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index f627ee036..e018a3ac9 100755 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -53,7 +53,7 @@ proc genSingleVar(p: BProc, a: PNode) = var targetProc = p var immediateAsgn = a.sons[2].kind != nkEmpty if sfGlobal in v.flags: - targetProc = p.module.initProc + targetProc = p.module.preInitProc assignGlobalVar(targetProc, v) genObjectInit(targetProc, cpsInit, v.typ, v.loc, true) else: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index a56053f79..de91205e2 100755 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -859,6 +859,7 @@ proc genInitCode(m: BModule) = app(prc, genSectionStart(cpsLocals)) app(prc, m.initProc.s[cpsLocals]) + app(prc, m.preInitProc.s[cpsLocals]) app(prc, genSectionEnd(cpsLocals)) app(prc, genSectionStart(cfsTypeInit1)) @@ -875,10 +876,12 @@ proc genInitCode(m: BModule) = app(prc, genSectionEnd(i)) app(prc, genSectionStart(cpsInit)) + app(prc, m.preInitProc.s[cpsInit]) app(prc, m.initProc.s[cpsInit]) app(prc, genSectionEnd(cpsInit)) - app(prc, genSectionStart(cpsStmts)) + app(prc, genSectionStart(cpsStmts)) + app(prc, m.preInitProc.s[cpsStmts]) app(prc, m.initProc.s[cpsStmts]) if optStackTrace in m.initProc.options and not m.PreventStackTrace: app(prc, deinitFrame(m.initProc)) @@ -916,6 +919,7 @@ proc rawNewModule(module: PSym, filename: string): BModule = result.typeInfoMarker = initIntSet() result.initProc = newProc(nil, result) result.initProc.options = gOptions + result.preInitProc = newProc(nil, result) initNodeTable(result.dataCache) result.typeStack = @[] result.forwardedProcs = @[] diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index c58c64250..fafccce18 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -93,6 +93,10 @@ type headerFiles*: TLinkedList # needed headers to include typeInfoMarker*: TIntSet # needed for generating type information initProc*: BProc # code for init procedure + preInitProc*: BProc # code executed before the init proc + # used for initialization code for + # .global. variables + # (or instantiated generic variables) typeStack*: TTypeSeq # used for type generation dataCache*: TNodeTable forwardedProcs*: TSymSeq # keep forwarded procs here -- cgit 1.4.1-2-gfad0