work-in-progress for compiling generics in their owner module
This commit is contained in:
parent
3e79e9f981
commit
b01d9b6181
4 changed files with 17 additions and 8 deletions
|
|
@ -152,7 +152,7 @@ proc genSingleVar(p: BProc, a: PNode) =
|
||||||
var immediateAsgn = a.sons[2].kind != nkEmpty
|
var immediateAsgn = a.sons[2].kind != nkEmpty
|
||||||
if sfGlobal in v.flags:
|
if sfGlobal in v.flags:
|
||||||
if v.owner.kind != skModule:
|
if v.owner.kind != skModule:
|
||||||
targetProc = p.module.preInitProc
|
targetProc = p.module.postInitProc
|
||||||
assignGlobalVar(targetProc, v)
|
assignGlobalVar(targetProc, v)
|
||||||
# XXX: be careful here.
|
# XXX: be careful here.
|
||||||
# Global variables should not be zeromem-ed within loops
|
# Global variables should not be zeromem-ed within loops
|
||||||
|
|
|
||||||
|
|
@ -1031,8 +1031,9 @@ proc genInitCode(m: BModule) =
|
||||||
app(prc, initGCFrame(m.initProc))
|
app(prc, initGCFrame(m.initProc))
|
||||||
|
|
||||||
app(prc, genSectionStart(cpsLocals))
|
app(prc, genSectionStart(cpsLocals))
|
||||||
app(prc, m.initProc.s(cpsLocals))
|
|
||||||
app(prc, m.preInitProc.s(cpsLocals))
|
app(prc, m.preInitProc.s(cpsLocals))
|
||||||
|
app(prc, m.initProc.s(cpsLocals))
|
||||||
|
app(prc, m.postInitProc.s(cpsLocals))
|
||||||
app(prc, genSectionEnd(cpsLocals))
|
app(prc, genSectionEnd(cpsLocals))
|
||||||
|
|
||||||
if optStackTrace in m.initProc.options and not m.FrameDeclared:
|
if optStackTrace in m.initProc.options and not m.FrameDeclared:
|
||||||
|
|
@ -1048,11 +1049,13 @@ proc genInitCode(m: BModule) =
|
||||||
app(prc, genSectionStart(cpsInit))
|
app(prc, genSectionStart(cpsInit))
|
||||||
app(prc, m.preInitProc.s(cpsInit))
|
app(prc, m.preInitProc.s(cpsInit))
|
||||||
app(prc, m.initProc.s(cpsInit))
|
app(prc, m.initProc.s(cpsInit))
|
||||||
|
app(prc, m.postInitProc.s(cpsInit))
|
||||||
app(prc, genSectionEnd(cpsInit))
|
app(prc, genSectionEnd(cpsInit))
|
||||||
|
|
||||||
app(prc, genSectionStart(cpsStmts))
|
app(prc, genSectionStart(cpsStmts))
|
||||||
app(prc, m.preInitProc.s(cpsStmts))
|
app(prc, m.preInitProc.s(cpsStmts))
|
||||||
app(prc, m.initProc.s(cpsStmts))
|
app(prc, m.initProc.s(cpsStmts))
|
||||||
|
app(prc, m.postInitProc.s(cpsStmts))
|
||||||
app(prc, genSectionEnd(cpsStmts))
|
app(prc, genSectionEnd(cpsStmts))
|
||||||
if optStackTrace in m.initProc.options and not m.PreventStackTrace:
|
if optStackTrace in m.initProc.options and not m.PreventStackTrace:
|
||||||
app(prc, deinitFrame(m.initProc))
|
app(prc, deinitFrame(m.initProc))
|
||||||
|
|
@ -1097,6 +1100,11 @@ proc newPreInitProc(m: BModule): BProc =
|
||||||
# little hack so that unique temporaries are generated:
|
# little hack so that unique temporaries are generated:
|
||||||
result.labels = 100_000
|
result.labels = 100_000
|
||||||
|
|
||||||
|
proc newPostInitProc(m: BModule): BProc =
|
||||||
|
result = newProc(nil, m)
|
||||||
|
# little hack so that unique temporaries are generated:
|
||||||
|
result.labels = 200_000
|
||||||
|
|
||||||
proc rawNewModule(module: PSym, filename: string): BModule =
|
proc rawNewModule(module: PSym, filename: string): BModule =
|
||||||
new(result)
|
new(result)
|
||||||
InitLinkedList(result.headerFiles)
|
InitLinkedList(result.headerFiles)
|
||||||
|
|
@ -1111,6 +1119,7 @@ proc rawNewModule(module: PSym, filename: string): BModule =
|
||||||
result.initProc = newProc(nil, result)
|
result.initProc = newProc(nil, result)
|
||||||
result.initProc.options = gOptions
|
result.initProc.options = gOptions
|
||||||
result.preInitProc = newPreInitProc(result)
|
result.preInitProc = newPreInitProc(result)
|
||||||
|
result.postInitProc = newPostInitProc(result)
|
||||||
initNodeTable(result.dataCache)
|
initNodeTable(result.dataCache)
|
||||||
result.typeStack = @[]
|
result.typeStack = @[]
|
||||||
result.forwardedProcs = @[]
|
result.forwardedProcs = @[]
|
||||||
|
|
@ -1131,6 +1140,7 @@ proc resetModule*(m: var BModule) =
|
||||||
m.initProc = newProc(nil, m)
|
m.initProc = newProc(nil, m)
|
||||||
m.initProc.options = gOptions
|
m.initProc.options = gOptions
|
||||||
m.preInitProc = newPreInitProc(m)
|
m.preInitProc = newPreInitProc(m)
|
||||||
|
m.postInitProc = newPostInitProc(m)
|
||||||
initNodeTable(m.dataCache)
|
initNodeTable(m.dataCache)
|
||||||
m.typeStack = @[]
|
m.typeStack = @[]
|
||||||
m.forwardedProcs = @[]
|
m.forwardedProcs = @[]
|
||||||
|
|
|
||||||
|
|
@ -100,10 +100,8 @@ type
|
||||||
headerFiles*: TLinkedList # needed headers to include
|
headerFiles*: TLinkedList # needed headers to include
|
||||||
typeInfoMarker*: TIntSet # needed for generating type information
|
typeInfoMarker*: TIntSet # needed for generating type information
|
||||||
initProc*: BProc # code for init procedure
|
initProc*: BProc # code for init procedure
|
||||||
|
postInitProc*: BProc # code to be executed after the init proc
|
||||||
preInitProc*: BProc # code executed before the init proc
|
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
|
typeStack*: TTypeSeq # used for type generation
|
||||||
dataCache*: TNodeTable
|
dataCache*: TNodeTable
|
||||||
forwardedProcs*: TSymSeq # keep forwarded procs here
|
forwardedProcs*: TSymSeq # keep forwarded procs here
|
||||||
|
|
|
||||||
|
|
@ -233,11 +233,11 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
# we set the friend module:
|
# we set the friend module:
|
||||||
var oldFriend = c.friendModule
|
var oldFriend = c.friendModule
|
||||||
c.friendModule = getModule(fn)
|
c.friendModule = getModule(fn)
|
||||||
|
#let oldScope = c.currentScope
|
||||||
|
#c.currentScope = fn.scope
|
||||||
result = copySym(fn, false)
|
result = copySym(fn, false)
|
||||||
incl(result.flags, sfFromGeneric)
|
incl(result.flags, sfFromGeneric)
|
||||||
# keep the owner if it's an inner proc (for proper closure transformations):
|
result.owner = fn
|
||||||
if fn.owner.kind == skModule:
|
|
||||||
result.owner = getCurrOwner().owner
|
|
||||||
result.ast = n
|
result.ast = n
|
||||||
pushOwner(result)
|
pushOwner(result)
|
||||||
openScope(c)
|
openScope(c)
|
||||||
|
|
@ -267,6 +267,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
popInfoContext()
|
popInfoContext()
|
||||||
closeScope(c) # close scope for parameters
|
closeScope(c) # close scope for parameters
|
||||||
popOwner()
|
popOwner()
|
||||||
|
#c.currentScope = oldScope
|
||||||
c.friendModule = oldFriend
|
c.friendModule = oldFriend
|
||||||
dec(c.InstCounter)
|
dec(c.InstCounter)
|
||||||
if result.kind == skMethod: finishMethod(c, result)
|
if result.kind == skMethod: finishMethod(c, result)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue