proper order of initialization for .global. variables
This commit is contained in:
parent
e941a14767
commit
a64f03230a
7 changed files with 62 additions and 3 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 = @[]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue