compilation cache: small fixes; methods still not working

This commit is contained in:
Araq
2011-10-23 21:39:02 +02:00
parent bd1cb9e77b
commit 627d33da08
5 changed files with 30 additions and 22 deletions

View File

@@ -936,6 +936,11 @@ proc writeModule(m: BModule, pending: bool) =
var code = genModule(m, cfilenoext)
writeRope(code, cfile)
addFileToCompile(cfilenoext)
elif not ExistsFile(toObjFile(cfilenoext)):
# Consider: first compilation compiles ``system.nim`` and produces
# ``system.c`` but then compilation fails due to an error. This means
# that ``system.o`` is missing, so we need to call the C compiler for it:
addFileToCompile(cfilenoext)
addFileToLink(cfilenoext)
proc myClose(b: PPassContext, n: PNode): PNode =
@@ -953,7 +958,7 @@ proc myClose(b: PPassContext, n: PNode): PNode =
finishModule(m)
if sfMainModule in m.module.flags:
var disp = generateMethodDispatchers()
for i in 0..sonsLen(disp)-1: genProcAux(gNimDat, disp.sons[i].sym)
for i in 0..sonsLen(disp)-1: genProcAux(m, disp.sons[i].sym)
genMainProc(m)
# we need to process the transitive closure because recursive module
# deps are allowed (and the system module is processed in the wrong

View File

@@ -38,8 +38,9 @@ proc methodCall*(n: PNode): PNode =
result.sons[0].sym = disp
for i in countup(1, sonsLen(result) - 1):
result.sons[i] = genConv(result.sons[i], disp.typ.sons[i], true)
var gMethods: seq[TSymSeq]
# save for incremental compilation:
var gMethods: seq[TSymSeq] = @[]
proc sameMethodBucket(a, b: PSym): bool =
result = false
@@ -66,22 +67,24 @@ proc sameMethodBucket(a, b: PSym): bool =
return
result = true
proc methodDef*(s: PSym) =
proc methodDef*(s: PSym, fromCache: bool) =
var L = len(gMethods)
for i in countup(0, L - 1):
if sameMethodBucket(gMethods[i][0], s):
add(gMethods[i], s) # store a symbol to the dispatcher:
addSon(s.ast, lastSon(gMethods[i][0].ast))
return
add(gMethods, @[s]) # create a new dispatcher:
var disp = copySym(s)
disp.typ = copyType(disp.typ, disp.typ.owner, false)
if disp.typ.callConv == ccInline: disp.typ.callConv = ccDefault
disp.ast = copyTree(s.ast)
disp.ast.sons[codePos] = ast.emptyNode
if s.typ.sons[0] != nil:
disp.ast.sons[resultPos].sym = copySym(s.ast.sons[resultPos].sym)
addSon(s.ast, newSymNode(disp))
add(gMethods, @[s])
# create a new dispatcher:
if not fromCache:
var disp = copySym(s)
disp.typ = copyType(disp.typ, disp.typ.owner, false)
if disp.typ.callConv == ccInline: disp.typ.callConv = ccDefault
disp.ast = copyTree(s.ast)
disp.ast.sons[codePos] = ast.emptyNode
if s.typ.sons[0] != nil:
disp.ast.sons[resultPos].sym = copySym(s.ast.sons[resultPos].sym)
addSon(s.ast, newSymNode(disp))
proc relevantCol(methods: TSymSeq, col: int): bool =
# returns true iff the position is relevant
@@ -177,4 +180,3 @@ proc generateMethodDispatchers*(): PNode =
sortBucket(gMethods[bucket], relevantCols)
addSon(result, newSymNode(genDispatcher(gMethods[bucket], relevantCols)))
gMethods = @[]

View File

@@ -338,7 +338,7 @@ proc symStack(w: PRodWriter) =
#intSetIncl(debugWritten, s.id)
encodeSym(w, s, w.data)
add(w.data, rodNL)
if sfExported in s.flags:
if sfExported in s.flags and s.kind in ExportableSymKinds:
encodeStr(s.name.s, w.interf)
add(w.interf, ' ')
encodeVInt(s.id, w.interf)
@@ -386,7 +386,8 @@ proc rawAddInterfaceSym(w: PRodWriter, s: PSym) =
proc addInterfaceSym(w: PRodWriter, s: PSym) =
if w == nil: return
if {sfExported, sfCompilerProc} * s.flags != {}:
if s.kind in ExportableSymKinds and
{sfExported, sfCompilerProc} * s.flags != {}:
rawAddInterfaceSym(w, s)
proc addStmt(w: PRodWriter, n: PNode) =

View File

@@ -676,7 +676,7 @@ proc transform(c: PTransf, n: PNode): PTransNode =
of nkProcDef, nkMethodDef, nkIteratorDef, nkMacroDef, nkConverterDef:
if n.sons[genericParamsPos].kind == nkEmpty:
n.sons[codePos] = PNode(transform(c, n.sons[codePos]))
if n.kind == nkMethodDef: methodDef(n.sons[namePos].sym)
if n.kind == nkMethodDef: methodDef(n.sons[namePos].sym, false)
result = PTransNode(n)
of nkContinueStmt:
result = PTransNode(newNode(nkBreakStmt))
@@ -742,7 +742,7 @@ proc openTransf(module: PSym, filename: string): PPassContext =
proc openTransfCached(module: PSym, filename: string,
rd: PRodReader): PPassContext =
result = openTransf(module, filename)
for m in items(rd.methods): methodDef(m)
for m in items(rd.methods): methodDef(m, true)
proc transfPass(): TPass =
initPass(result)

View File

@@ -18,16 +18,16 @@ incremental compilation
- adapt thread var implementation to care about the new merge operation
- write test cases: needs test script support
- test G, A, B example from the documentation
- fix method generation
- test thread var
- test method generation; could work, needs ROD support though
- test init sections
- test DLL interfacing!
- hallo.rod is missing initial statements: feature or bug?
- stress test with whole compiler
- automate tests:
- test basic recompilation scheme
- test type converters
- test G, A, B example from the documentation
- test init sections
- fix remaining bugs