diff options
author | Araq <rumpf_a@web.de> | 2011-10-23 21:39:02 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-10-23 21:39:02 +0200 |
commit | 627d33da0803e3cad7840fa72ade2a8a114ef799 (patch) | |
tree | fec128973ebe79a84790c092fdc979f07a06f274 /compiler | |
parent | bd1cb9e77befaab83a4d78d9211480cc7ee1b95b (diff) | |
download | Nim-627d33da0803e3cad7840fa72ade2a8a114ef799.tar.gz |
compilation cache: small fixes; methods still not working
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/cgen.nim | 7 | ||||
-rwxr-xr-x | compiler/cgmeth.nim | 28 | ||||
-rwxr-xr-x | compiler/rodwrite.nim | 5 | ||||
-rwxr-xr-x | compiler/transf.nim | 4 |
4 files changed, 26 insertions, 18 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 787fbbe0a..51d6f2f84 100755 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -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 diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 2751e0900..3c90f3343 100755 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -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 = @[] diff --git a/compiler/rodwrite.nim b/compiler/rodwrite.nim index b735aee6a..faea83d9a 100755 --- a/compiler/rodwrite.nim +++ b/compiler/rodwrite.nim @@ -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) = diff --git a/compiler/transf.nim b/compiler/transf.nim index 0fb3dd2c6..f8475f853 100755 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -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) |