diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-04-10 20:53:44 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-04-10 20:53:44 +0300 |
commit | a64f03230afa69f2143b0eb159c9294998c5e19b (patch) | |
tree | 5abc9f9ae2faf8fbbf1462a06fbeb3688e38b254 /compiler | |
parent | e941a147670442e706d1777f4a1bc368d0cbcdba (diff) | |
download | Nim-a64f03230afa69f2143b0eb159c9294998c5e19b.tar.gz |
proper order of initialization for .global. variables
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/ccgstmts.nim | 2 | ||||
-rwxr-xr-x | compiler/cgen.nim | 6 | ||||
-rw-r--r-- | compiler/cgendata.nim | 4 |
3 files changed, 10 insertions, 2 deletions
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 |