diff options
author | Araq <rumpf_a@web.de> | 2016-08-16 20:04:27 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2016-08-16 20:04:27 +0200 |
commit | a13cb26c4084d83df1d4627e5b842c050ed69177 (patch) | |
tree | 87d439fcb03c2c2bcf60e895be033028ca646e9f | |
parent | 8fca04027fe03109657b753b95ded86d2f65e6f3 (diff) | |
download | Nim-a13cb26c4084d83df1d4627e5b842c050ed69177.tar.gz |
next steps in getting symbol files to work again
-rw-r--r-- | compiler/ast.nim | 9 | ||||
-rw-r--r-- | compiler/cgen.nim | 2 | ||||
-rw-r--r-- | compiler/nversion.nim | 2 | ||||
-rw-r--r-- | compiler/pragmas.nim | 2 | ||||
-rw-r--r-- | compiler/rodread.nim | 76 | ||||
-rw-r--r-- | compiler/rodwrite.nim | 72 | ||||
-rw-r--r-- | lib/system.nim | 5 | ||||
-rw-r--r-- | tests/rodfiles/gtkex1.nim | 6 | ||||
-rw-r--r-- | tests/rodfiles/gtkex2.nim | 6 | ||||
-rw-r--r-- | tests/rodfiles/int2bool.nim | 1 | ||||
-rw-r--r-- | tests/testament/categories.nim | 5 |
11 files changed, 140 insertions, 46 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 277a21ba5..75491af6b 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -725,8 +725,8 @@ type s*: TStorageLoc flags*: TLocFlags # location's flags t*: PType # type of location - r*: Rope # rope value of location (code generators) - heapRoot*: Rope # keeps track of the enclosing heap object that + r*: Rope # rope value of location (code generators) + heapRoot*: Rope # keeps track of the enclosing heap object that # owns this location (required by GC algorithms # employing heap snapshots or sliding views) @@ -746,10 +746,6 @@ type TInstantiation* = object sym*: PSym concreteTypes*: seq[PType] - usedBy*: seq[int32] # list of modules using the generic - # needed in caas mode for purging the cache - # XXX: it's possible to switch to a - # simple ref count here compilesId*: CompilesId PInstantiation* = ref TInstantiation @@ -767,7 +763,6 @@ type case kind*: TSymKind of skType, skGenericParam: typeInstCache*: seq[PType] - typScope*: PScope of routineKinds: procInstCache*: seq[PInstantiation] gcUnsafetyReason*: PSym # for better error messages wrt gcsafe diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 9851ab0e2..810f7dfd4 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1020,7 +1020,7 @@ proc genInitCode(m: BModule) = var procname = makeCString(m.module.name.s) add(prc, initFrame(m.initProc, procname, m.module.info.quotedFilename)) else: - add(prc, ~"\tTFrame F; FR.len = 0;$N") + add(prc, ~"\tTFrame FR; FR.len = 0;$N") add(prc, genSectionStart(cpsInit)) add(prc, m.preInitProc.s(cpsInit)) diff --git a/compiler/nversion.nim b/compiler/nversion.nim index 2af66f427..55e337969 100644 --- a/compiler/nversion.nim +++ b/compiler/nversion.nim @@ -13,5 +13,5 @@ const MaxSetElements* = 1 shl 16 # (2^16) to support unicode character sets? VersionAsString* = system.NimVersion - RodFileVersion* = "1216" # modify this if the rod-format changes! + RodFileVersion* = "1218" # modify this if the rod-format changes! diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 1f93f5317..a4c95e1b7 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -572,11 +572,13 @@ proc deprecatedStmt(c: PContext; pragma: PNode) = for n in pragma: if n.kind in {nkExprColonExpr, nkExprEqExpr}: let dest = qualifiedLookUp(c, n[1], {checkUndeclared}) + assert dest != nil let src = considerQuotedIdent(n[0]) let alias = newSym(skAlias, src, dest, n[0].info) incl(alias.flags, sfExported) if sfCompilerProc in dest.flags: markCompilerProc(alias) addInterfaceDecl(c, alias) + n.sons[1] = newSymNode(dest) else: localError(n.info, "key:value pair expected") diff --git a/compiler/rodread.nim b/compiler/rodread.nim index e1fd46bf4..679e7ba15 100644 --- a/compiler/rodread.nim +++ b/compiler/rodread.nim @@ -145,13 +145,7 @@ type PRodReader* = ref TRodReader -var rodCompilerprocs*: TStrTable - -proc handleSymbolFile*(module: PSym): PRodReader -# global because this is needed by magicsys -proc loadInitSection*(r: PRodReader): PNode - -# implementation +var rodCompilerprocs*: TStrTable # global because this is needed by magicsys proc rawLoadStub(s: PSym) @@ -206,7 +200,7 @@ proc decodeNodeLazyBody(r: PRodReader, fInfo: TLineInfo, var id = decodeVInt(r.s, r.pos) result.typ = rrGetType(r, id, result.info) case result.kind - of nkCharLit..nkInt64Lit: + of nkCharLit..nkUInt64Lit: if r.s[r.pos] == '!': inc(r.pos) result.intVal = decodeVBiggestInt(r.s, r.pos) @@ -324,6 +318,29 @@ proc decodeType(r: PRodReader, info: TLineInfo): PType = result.align = decodeVInt(r.s, r.pos).int16 else: result.align = 2 + + if r.s[r.pos] == '\14': + inc(r.pos) + result.lockLevel = decodeVInt(r.s, r.pos).TLockLevel + else: + result.lockLevel = UnspecifiedLockLevel + + if r.s[r.pos] == '\15': + inc(r.pos) + result.destructor = rrGetSym(r, decodeVInt(r.s, r.pos), info) + if r.s[r.pos] == '\16': + inc(r.pos) + result.deepCopy = rrGetSym(r, decodeVInt(r.s, r.pos), info) + if r.s[r.pos] == '\17': + inc(r.pos) + result.assignment = rrGetSym(r, decodeVInt(r.s, r.pos), info) + while r.s[r.pos] == '\18': + inc(r.pos) + let x = decodeVInt(r.s, r.pos) + doAssert r.s[r.pos] == '\19' + inc(r.pos) + let y = rrGetSym(r, decodeVInt(r.s, r.pos), info) + result.methods.safeAdd((x, y)) decodeLoc(r, result.loc, info) while r.s[r.pos] == '^': inc(r.pos) @@ -349,6 +366,22 @@ proc decodeLib(r: PRodReader, info: TLineInfo): PLib = inc(r.pos) result.path = decodeNode(r, info) +proc decodeInstantiations(r: PRodReader; info: TLineInfo; + s: var seq[PInstantiation]) = + while r.s[r.pos] == '\15': + inc(r.pos) + var ii: PInstantiation + new ii + ii.sym = rrGetSym(r, decodeVInt(r.s, r.pos), info) + ii.concreteTypes = @[] + while r.s[r.pos] == '\17': + inc(r.pos) + ii.concreteTypes.add rrGetType(r, decodeVInt(r.s, r.pos), info) + if r.s[r.pos] == '\20': + inc(r.pos) + ii.compilesId = decodeVInt(r.s, r.pos) + s.safeAdd ii + proc decodeSym(r: PRodReader, info: TLineInfo): PSym = var id: int @@ -423,6 +456,27 @@ proc decodeSym(r: PRodReader, info: TLineInfo): PSym = if r.s[r.pos] == '#': inc(r.pos) result.constraint = decodeNode(r, unknownLineInfo()) + case result.kind + of skType, skGenericParam: + while r.s[r.pos] == '\14': + inc(r.pos) + result.typeInstCache.safeAdd rrGetType(r, decodeVInt(r.s, r.pos), result.info) + of routineKinds: + decodeInstantiations(r, result.info, result.procInstCache) + if r.s[r.pos] == '\16': + inc(r.pos) + result.gcUnsafetyReason = rrGetSym(r, decodeVInt(r.s, r.pos), result.info) + of skModule, skPackage: + decodeInstantiations(r, result.info, result.usedGenerics) + of skLet, skVar, skField, skForVar: + if r.s[r.pos] == '\18': + inc(r.pos) + result.guard = rrGetSym(r, decodeVInt(r.s, r.pos), result.info) + if r.s[r.pos] == '\19': + inc(r.pos) + result.bitsize = decodeVInt(r.s, r.pos).int16 + else: discard + if r.s[r.pos] == '(': if result.kind in routineKinds: result.ast = decodeNodeLazyBody(r, result.info, result) @@ -766,7 +820,7 @@ proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym = result = decodeSymSafePos(r, d, info) if result != nil and result.kind == skStub: rawLoadStub(result) -proc loadInitSection(r: PRodReader): PNode = +proc loadInitSection*(r: PRodReader): PNode = if r.initIdx == 0 or r.dataIdx == 0: internalError("loadInitSection") var oldPos = r.pos r.pos = r.initIdx @@ -850,7 +904,7 @@ proc checkDep(fileIdx: int32): TReasonForRecompile = gMods[fileIdx].rd = r gMods[fileIdx].reason = result # now we know better -proc handleSymbolFile(module: PSym): PRodReader = +proc handleSymbolFile*(module: PSym): PRodReader = let fileIdx = module.fileIdx if optSymbolFiles notin gGlobalOptions: module.id = getID() @@ -926,7 +980,7 @@ proc writeNode(f: File; n: PNode) = f.write('^') f.write(n.typ.id) case n.kind - of nkCharLit..nkInt64Lit: + of nkCharLit..nkUInt64Lit: if n.intVal != 0: f.write('!') f.write(n.intVal) diff --git a/compiler/rodwrite.nim b/compiler/rodwrite.nim index ab0774164..557b1dabf 100644 --- a/compiler/rodwrite.nim +++ b/compiler/rodwrite.nim @@ -16,8 +16,6 @@ import condsyms, ropes, idents, securehash, rodread, passes, importer, idgen, rodutils -# implementation - type TRodWriter = object of TPassContext module: PSym @@ -223,6 +221,28 @@ proc encodeType(w: PRodWriter, t: PType, result: var string) = if t.align != 2: add(result, '=') encodeVInt(t.align, result) + if t.lockLevel.ord != UnspecifiedLockLevel.ord: + add(result, '\14') + encodeVInt(t.lockLevel.int16, result) + + if t.destructor != nil: + add(result, '\15') + encodeVInt(t.destructor.id, result) + pushSym(w, t.destructor) + if t.deepCopy != nil: + add(result, '\16') + encodeVInt(t.deepcopy.id, result) + pushSym(w, t.deepcopy) + if t.assignment != nil: + add(result, '\17') + encodeVInt(t.assignment.id, result) + pushSym(w, t.assignment) + for i, s in items(t.methods): + add(result, '\18') + encodeVInt(i, result) + add(result, '\19') + encodeVInt(s.id, result) + pushSym(w, s) encodeLoc(w, t.loc, result) for i in countup(0, sonsLen(t) - 1): if t.sons[i] == nil: @@ -240,6 +260,19 @@ proc encodeLib(w: PRodWriter, lib: PLib, info: TLineInfo, result: var string) = add(result, '|') encodeNode(w, info, lib.path, result) +proc encodeInstantiations(w: PRodWriter; s: seq[PInstantiation]; + result: var string) = + for t in s: + result.add('\15') + encodeVInt(t.sym.id, result) + pushSym(w, t.sym) + for tt in t.concreteTypes: + result.add('\17') + encodeVInt(tt.id, result) + pushType(w, tt) + result.add('\20') + encodeVInt(t.compilesId, result) + proc encodeSym(w: PRodWriter, s: PSym, result: var string) = if s == nil: # nil nodes have to be stored too: @@ -285,6 +318,31 @@ proc encodeSym(w: PRodWriter, s: PSym, result: var string) = if s.constraint != nil: add(result, '#') encodeNode(w, unknownLineInfo(), s.constraint, result) + case s.kind + of skType, skGenericParam: + for t in s.typeInstCache: + result.add('\14') + encodeVInt(t.id, result) + pushType(w, t) + of routineKinds: + encodeInstantiations(w, s.procInstCache, result) + if s.gcUnsafetyReason != nil: + result.add('\16') + encodeVInt(s.gcUnsafetyReason.id, result) + pushSym(w, s.gcUnsafetyReason) + of skModule, skPackage: + encodeInstantiations(w, s.usedGenerics, result) + # we don't serialize: + #tab*: TStrTable # interface table for modules + of skLet, skVar, skField, skForVar: + if s.guard != nil: + result.add('\18') + encodeVInt(s.guard.id, result) + pushSym(w, s.guard) + if s.bitsize != 0: + result.add('\19') + encodeVInt(s.bitsize, result) + else: discard # lazy loading will soon reload the ast lazily, so the ast needs to be # the last entry of a symbol: if s.ast != nil: @@ -292,16 +350,6 @@ proc encodeSym(w: PRodWriter, s: PSym, result: var string) = # it is not necessary, but Nim's heavy compile-time evaluation features # make that unfeasible nowadays: encodeNode(w, s.info, s.ast, result) - when false: - var codeAst: PNode = nil - if not astNeeded(s): - codeAst = s.ast.sons[codePos] - # ugly hack to not store the AST: - s.ast.sons[codePos] = ast.emptyNode - encodeNode(w, s.info, s.ast, result) - if codeAst != nil: - # resore the AST: - s.ast.sons[codePos] = codeAst proc addToIndex(w: var TIndex, key, val: int) = if key - w.lastIdxKey == 1: diff --git a/lib/system.nim b/lib/system.nim index 82980d9da..62405e521 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1831,9 +1831,6 @@ const NimVersion*: string = $NimMajor & "." & $NimMinor & "." & $NimPatch ## is the version of Nim as a string. -{.deprecated: [TEndian: Endianness, NimrodVersion: NimVersion, - NimrodMajor: NimMajor, NimrodMinor: NimMinor, NimrodPatch: NimPatch].} - # GC interface: when not defined(nimscript) and hasAlloc: @@ -3681,4 +3678,4 @@ when defined(nimconfig): when defined(windows) and appType == "console" and not defined(nimconfig): proc setConsoleOutputCP(codepage: cint): cint {.stdcall, dynlib: "kernel32", importc: "SetConsoleOutputCP".} - discard setConsoleOutputCP(65001) # 65001 - utf-8 codepage \ No newline at end of file + discard setConsoleOutputCP(65001) # 65001 - utf-8 codepage diff --git a/tests/rodfiles/gtkex1.nim b/tests/rodfiles/gtkex1.nim index 156ba5322..50779cb9e 100644 --- a/tests/rodfiles/gtkex1.nim +++ b/tests/rodfiles/gtkex1.nim @@ -1,12 +1,12 @@ import cairo, glib2, gtk2 -proc destroy(widget: pWidget, data: pgpointer) {.cdecl.} = +proc destroy(widget: PWidget, data: Pgpointer) {.cdecl.} = main_quit() var - window: pWidget -nimrod_init() + window: PWidget +nim_init() window = window_new(WINDOW_TOPLEVEL) discard signal_connect(window, "destroy", SIGNAL_FUNC(gtkex1.destroy), nil) diff --git a/tests/rodfiles/gtkex2.nim b/tests/rodfiles/gtkex2.nim index 70926bd50..0949e4872 100644 --- a/tests/rodfiles/gtkex2.nim +++ b/tests/rodfiles/gtkex2.nim @@ -2,17 +2,17 @@ import glib2, gtk2 -proc destroy(widget: pWidget, data: pgpointer){.cdecl.} = +proc destroy(widget: PWidget, data: Pgpointer){.cdecl.} = main_quit() var window: PWidget button: PWidget -nimrod_init() +nim_init() window = window_new(WINDOW_TOPLEVEL) button = button_new("Click me") -set_border_width(PContainer(Window), 5) +set_border_width(PContainer(window), 5) add(PContainer(window), button) discard signal_connect(window, "destroy", SIGNAL_FUNC(gtkex2.destroy), nil) diff --git a/tests/rodfiles/int2bool.nim b/tests/rodfiles/int2bool.nim index 0f6fd14e6..bb0682844 100644 --- a/tests/rodfiles/int2bool.nim +++ b/tests/rodfiles/int2bool.nim @@ -2,7 +2,6 @@ {.overflowchecks: on.} converter uglyToBool*(x: int): bool = - {.Breakpoint.} result = x != 0 diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index e534cc161..eebf18f54 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -369,9 +369,8 @@ proc `&?.`(a, b: string): string = proc processCategory(r: var TResults, cat: Category, options: string, fileGlob: string = "t*.nim") = case cat.string.normalize of "rodfiles": - discard # Disabled for now - #compileRodFiles(r, cat, options) - #runRodFiles(r, cat, options) + compileRodFiles(r, cat, options) + runRodFiles(r, cat, options) of "js": # XXX JS doesn't need to be special anymore jsTests(r, cat, options) |