renamed writeln to writeLine in compiler

This commit is contained in:
patrick dw 2015-06-19 01:45:12 -05:00
commit 2a0f7b5de7
8 changed files with 228 additions and 228 deletions

View file

@ -452,7 +452,7 @@ proc debug(n: PSym) =
elif n.kind == skUnknown: elif n.kind == skUnknown:
msgWriteln("skUnknown") msgWriteln("skUnknown")
else: else:
#writeln(stdout, $symToYaml(n, 0, 1)) #writeLine(stdout, $symToYaml(n, 0, 1))
msgWriteln("$1_$2: $3, $4, $5, $6" % [ msgWriteln("$1_$2: $3, $4, $5, $6" % [
n.name.s, $n.id, $flagsToStr(n.flags), $flagsToStr(n.loc.flags), n.name.s, $n.id, $flagsToStr(n.flags), $flagsToStr(n.loc.flags),
$lineInfoToStr(n.info), $n.kind]) $lineInfoToStr(n.info), $n.kind])

View file

@ -596,7 +596,7 @@ proc externalFileChanged(filename: string): bool =
result = true result = true
if result: if result:
if open(f, crcFile, fmWrite): if open(f, crcFile, fmWrite):
f.writeln($currentCrc) f.writeLine($currentCrc)
close(f) close(f)
proc addExternalFileToCompile*(filename: string) = proc addExternalFileToCompile*(filename: string) =

View file

@ -18,26 +18,26 @@ const
when debugIds: when debugIds:
import intsets import intsets
var usedIds = initIntSet() var usedIds = initIntSet()
proc registerID*(id: PIdObj) = proc registerID*(id: PIdObj) =
when debugIds: when debugIds:
if id.id == -1 or containsOrIncl(usedIds, id.id): if id.id == -1 or containsOrIncl(usedIds, id.id):
internalError("ID already used: " & $id.id) internalError("ID already used: " & $id.id)
proc getID*(): int {.inline.} = proc getID*(): int {.inline.} =
result = gFrontEndId result = gFrontEndId
inc(gFrontEndId) inc(gFrontEndId)
proc backendId*(): int {.inline.} = proc backendId*(): int {.inline.} =
result = gBackendId result = gBackendId
inc(gBackendId) inc(gBackendId)
proc setId*(id: int) {.inline.} = proc setId*(id: int) {.inline.} =
gFrontEndId = max(gFrontEndId, id + 1) gFrontEndId = max(gFrontEndId, id + 1)
proc idSynchronizationPoint*(idRange: int) = proc idSynchronizationPoint*(idRange: int) =
gFrontEndId = (gFrontEndId div idRange + 1) * idRange + 1 gFrontEndId = (gFrontEndId div idRange + 1) * idRange + 1
proc toGid(f: string): string = proc toGid(f: string): string =
@ -48,10 +48,10 @@ proc toGid(f: string): string =
proc saveMaxIds*(project: string) = proc saveMaxIds*(project: string) =
var f = open(project.toGid, fmWrite) var f = open(project.toGid, fmWrite)
f.writeln($gFrontEndId) f.writeLine($gFrontEndId)
f.writeln($gBackendId) f.writeLine($gBackendId)
f.close() f.close()
proc loadMaxIds*(project: string) = proc loadMaxIds*(project: string) =
var f: File var f: File
if open(f, project.toGid, fmRead): if open(f, project.toGid, fmRead):

View file

@ -593,7 +593,7 @@ var
proc suggestWriteln*(s: string) = proc suggestWriteln*(s: string) =
if eStdOut in errorOutputs: if eStdOut in errorOutputs:
if isNil(writelnHook): writeln(stdout, s) if isNil(writelnHook): writeLine(stdout, s)
else: writelnHook(s) else: writelnHook(s)
proc msgQuit*(x: int8) = quit x proc msgQuit*(x: int8) = quit x
@ -688,7 +688,7 @@ var gTrackPos*: TLineInfo
proc outWriteln*(s: string) = proc outWriteln*(s: string) =
## Writes to stdout. Always. ## Writes to stdout. Always.
if eStdOut in errorOutputs: writeln(stdout, s) if eStdOut in errorOutputs: writeLine(stdout, s)
proc msgWriteln*(s: string) = proc msgWriteln*(s: string) =
## Writes to stdout. If --stdout option is given, writes to stderr instead. ## Writes to stdout. If --stdout option is given, writes to stderr instead.
@ -698,9 +698,9 @@ proc msgWriteln*(s: string) =
if not isNil(writelnHook): if not isNil(writelnHook):
writelnHook(s) writelnHook(s)
elif optStdout in gGlobalOptions: elif optStdout in gGlobalOptions:
if eStdErr in errorOutputs: writeln(stderr, s) if eStdErr in errorOutputs: writeLine(stderr, s)
else: else:
if eStdOut in errorOutputs: writeln(stdout, s) if eStdOut in errorOutputs: writeLine(stdout, s)
macro callIgnoringStyle(theProc: typed, first: typed, macro callIgnoringStyle(theProc: typed, first: typed,
args: varargs[expr]): stmt = args: varargs[expr]): stmt =
@ -735,13 +735,13 @@ template styledMsgWriteln*(args: varargs[expr]) =
if not isNil(writelnHook): if not isNil(writelnHook):
callIgnoringStyle(callWritelnHook, nil, args) callIgnoringStyle(callWritelnHook, nil, args)
elif optStdout in gGlobalOptions: elif optStdout in gGlobalOptions:
if eStdErr in errorOutputs: callIgnoringStyle(writeln, stderr, args) if eStdErr in errorOutputs: callIgnoringStyle(writeLine, stderr, args)
else: else:
if eStdOut in errorOutputs: if eStdOut in errorOutputs:
if optUseColors in gGlobalOptions: if optUseColors in gGlobalOptions:
callStyledEcho(args) callStyledEcho(args)
else: else:
callIgnoringStyle(writeln, stdout, args) callIgnoringStyle(writeLine, stdout, args)
proc coordToStr(coord: int): string = proc coordToStr(coord: int): string =
if coord == -1: result = "???" if coord == -1: result = "???"

View file

@ -82,7 +82,7 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
proc handleCmdLine() = proc handleCmdLine() =
if paramCount() == 0: if paramCount() == 0:
stdout.writeln(Usage) stdout.writeLine(Usage)
else: else:
processCmdLine(passCmd1, "") processCmdLine(passCmd1, "")
if gProjectName != "": if gProjectName != "":

View file

@ -304,7 +304,7 @@ proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
when noTimeMachine: when noTimeMachine:
excludeDirFromTimeMachine(subdir) excludeDirFromTimeMachine(subdir)
except OSError: except OSError:
writeln(stdout, "cannot create directory: " & subdir) writeLine(stdout, "cannot create directory: " & subdir)
quit(1) quit(1)
result = joinPath(subdir, tail) result = joinPath(subdir, tail)
#echo "completeGeneratedFilePath(", f, ") = ", result #echo "completeGeneratedFilePath(", f, ") = ", result

View file

@ -12,7 +12,7 @@
# Reading and writing binary files are really hard to debug. Therefore we use # Reading and writing binary files are really hard to debug. Therefore we use
# a "creative" text/binary hybrid format. ROD-files are more efficient # a "creative" text/binary hybrid format. ROD-files are more efficient
# to process because symbols can be loaded on demand. # to process because symbols can be loaded on demand.
# #
# A ROD file consists of: # A ROD file consists of:
# #
# - a header: # - a header:
@ -44,7 +44,7 @@
# ) # )
# - a compiler proc section: # - a compiler proc section:
# COMPILERPROCS( # COMPILERPROCS(
# identifier1 id\n # id is the symbol's id # identifier1 id\n # id is the symbol's id
# ) # )
# - an index consisting of (ID, linenumber)-pairs: # - an index consisting of (ID, linenumber)-pairs:
# INDEX( # INDEX(
@ -52,7 +52,7 @@
# id-diff idx-diff\n # id-diff idx-diff\n
# ) # )
# #
# Since the whole index has to be read in advance, we compress it by # Since the whole index has to be read in advance, we compress it by
# storing the integer differences to the last entry instead of using the # storing the integer differences to the last entry instead of using the
# real numbers. # real numbers.
# #
@ -88,11 +88,11 @@
# by using a mem'mapped file. # by using a mem'mapped file.
# #
import import
os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms, os, options, strutils, nversion, ast, astalgo, msgs, platform, condsyms,
ropes, idents, securehash, idgen, types, rodutils, memfiles ropes, idents, securehash, idgen, types, rodutils, memfiles
type type
TReasonForRecompile* = enum ## all the reasons that can trigger recompilation TReasonForRecompile* = enum ## all the reasons that can trigger recompilation
rrEmpty, # dependencies not yet computed rrEmpty, # dependencies not yet computed
rrNone, # no need to recompile rrNone, # no need to recompile
@ -104,14 +104,14 @@ type
rrInclDeps, # an include has changed rrInclDeps, # an include has changed
rrModDeps # a module this module depends on has been changed rrModDeps # a module this module depends on has been changed
const const
reasonToFrmt*: array[TReasonForRecompile, string] = ["", reasonToFrmt*: array[TReasonForRecompile, string] = ["",
"no need to recompile: $1", "symbol file for $1 does not exist", "no need to recompile: $1", "symbol file for $1 does not exist",
"symbol file for $1 has the wrong version", "symbol file for $1 has the wrong version",
"file edited since last compilation: $1", "file edited since last compilation: $1",
"list of conditional symbols changed for: $1", "list of conditional symbols changed for: $1",
"list of options changed for: $1", "list of options changed for: $1",
"an include file edited: $1", "an include file edited: $1",
"a module $1 depends on has changed"] "a module $1 depends on has changed"]
type type
@ -120,7 +120,7 @@ type
tab*: TIITable tab*: TIITable
r*: string # writers use this r*: string # writers use this
offset*: int # readers use this offset*: int # readers use this
TRodReader* = object of RootObj TRodReader* = object of RootObj
pos: int # position; used for parsing pos: int # position; used for parsing
s: cstring # mmap'ed file contents s: cstring # mmap'ed file contents
@ -142,7 +142,7 @@ type
methods*: TSymSeq methods*: TSymSeq
origFile: string origFile: string
inViewMode: bool inViewMode: bool
PRodReader* = ref TRodReader PRodReader* = ref TRodReader
var rodCompilerprocs*: TStrTable var rodCompilerprocs*: TStrTable
@ -161,16 +161,16 @@ proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym
# `info` is only used for debugging purposes # `info` is only used for debugging purposes
proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType
proc decodeLineInfo(r: PRodReader, info: var TLineInfo) = proc decodeLineInfo(r: PRodReader, info: var TLineInfo) =
if r.s[r.pos] == '?': if r.s[r.pos] == '?':
inc(r.pos) inc(r.pos)
if r.s[r.pos] == ',': info.col = -1'i16 if r.s[r.pos] == ',': info.col = -1'i16
else: info.col = int16(decodeVInt(r.s, r.pos)) else: info.col = int16(decodeVInt(r.s, r.pos))
if r.s[r.pos] == ',': if r.s[r.pos] == ',':
inc(r.pos) inc(r.pos)
if r.s[r.pos] == ',': info.line = -1'i16 if r.s[r.pos] == ',': info.line = -1'i16
else: info.line = int16(decodeVInt(r.s, r.pos)) else: info.line = int16(decodeVInt(r.s, r.pos))
if r.s[r.pos] == ',': if r.s[r.pos] == ',':
inc(r.pos) inc(r.pos)
info = newLineInfo(r.files[decodeVInt(r.s, r.pos)], info.line, info.col) info = newLineInfo(r.files[decodeVInt(r.s, r.pos)], info.line, info.col)
@ -188,56 +188,56 @@ proc skipNode(r: PRodReader) =
inc pos inc pos
r.pos = pos+1 # skip ')' r.pos = pos+1 # skip ')'
proc decodeNodeLazyBody(r: PRodReader, fInfo: TLineInfo, proc decodeNodeLazyBody(r: PRodReader, fInfo: TLineInfo,
belongsTo: PSym): PNode = belongsTo: PSym): PNode =
result = nil result = nil
if r.s[r.pos] == '(': if r.s[r.pos] == '(':
inc(r.pos) inc(r.pos)
if r.s[r.pos] == ')': if r.s[r.pos] == ')':
inc(r.pos) inc(r.pos)
return # nil node return # nil node
result = newNodeI(TNodeKind(decodeVInt(r.s, r.pos)), fInfo) result = newNodeI(TNodeKind(decodeVInt(r.s, r.pos)), fInfo)
decodeLineInfo(r, result.info) decodeLineInfo(r, result.info)
if r.s[r.pos] == '$': if r.s[r.pos] == '$':
inc(r.pos) inc(r.pos)
result.flags = cast[TNodeFlags](int32(decodeVInt(r.s, r.pos))) result.flags = cast[TNodeFlags](int32(decodeVInt(r.s, r.pos)))
if r.s[r.pos] == '^': if r.s[r.pos] == '^':
inc(r.pos) inc(r.pos)
var id = decodeVInt(r.s, r.pos) var id = decodeVInt(r.s, r.pos)
result.typ = rrGetType(r, id, result.info) result.typ = rrGetType(r, id, result.info)
case result.kind case result.kind
of nkCharLit..nkInt64Lit: of nkCharLit..nkInt64Lit:
if r.s[r.pos] == '!': if r.s[r.pos] == '!':
inc(r.pos) inc(r.pos)
result.intVal = decodeVBiggestInt(r.s, r.pos) result.intVal = decodeVBiggestInt(r.s, r.pos)
of nkFloatLit..nkFloat64Lit: of nkFloatLit..nkFloat64Lit:
if r.s[r.pos] == '!': if r.s[r.pos] == '!':
inc(r.pos) inc(r.pos)
var fl = decodeStr(r.s, r.pos) var fl = decodeStr(r.s, r.pos)
result.floatVal = parseFloat(fl) result.floatVal = parseFloat(fl)
of nkStrLit..nkTripleStrLit: of nkStrLit..nkTripleStrLit:
if r.s[r.pos] == '!': if r.s[r.pos] == '!':
inc(r.pos) inc(r.pos)
result.strVal = decodeStr(r.s, r.pos) result.strVal = decodeStr(r.s, r.pos)
else: else:
result.strVal = "" # BUGFIX result.strVal = "" # BUGFIX
of nkIdent: of nkIdent:
if r.s[r.pos] == '!': if r.s[r.pos] == '!':
inc(r.pos) inc(r.pos)
var fl = decodeStr(r.s, r.pos) var fl = decodeStr(r.s, r.pos)
result.ident = getIdent(fl) result.ident = getIdent(fl)
else: else:
internalError(result.info, "decodeNode: nkIdent") internalError(result.info, "decodeNode: nkIdent")
of nkSym: of nkSym:
if r.s[r.pos] == '!': if r.s[r.pos] == '!':
inc(r.pos) inc(r.pos)
var id = decodeVInt(r.s, r.pos) var id = decodeVInt(r.s, r.pos)
result.sym = rrGetSym(r, id, result.info) result.sym = rrGetSym(r, id, result.info)
else: else:
internalError(result.info, "decodeNode: nkSym") internalError(result.info, "decodeNode: nkSym")
else: else:
var i = 0 var i = 0
while r.s[r.pos] != ')': while r.s[r.pos] != ')':
if belongsTo != nil and i == bodyPos: if belongsTo != nil and i == bodyPos:
addSonNilAllowed(result, nil) addSonNilAllowed(result, nil)
belongsTo.offset = r.pos belongsTo.offset = r.pos
@ -252,93 +252,93 @@ proc decodeNodeLazyBody(r: PRodReader, fInfo: TLineInfo,
proc decodeNode(r: PRodReader, fInfo: TLineInfo): PNode = proc decodeNode(r: PRodReader, fInfo: TLineInfo): PNode =
result = decodeNodeLazyBody(r, fInfo, nil) result = decodeNodeLazyBody(r, fInfo, nil)
proc decodeLoc(r: PRodReader, loc: var TLoc, info: TLineInfo) = proc decodeLoc(r: PRodReader, loc: var TLoc, info: TLineInfo) =
if r.s[r.pos] == '<': if r.s[r.pos] == '<':
inc(r.pos) inc(r.pos)
if r.s[r.pos] in {'0'..'9', 'a'..'z', 'A'..'Z'}: if r.s[r.pos] in {'0'..'9', 'a'..'z', 'A'..'Z'}:
loc.k = TLocKind(decodeVInt(r.s, r.pos)) loc.k = TLocKind(decodeVInt(r.s, r.pos))
else: else:
loc.k = low(loc.k) loc.k = low(loc.k)
if r.s[r.pos] == '*': if r.s[r.pos] == '*':
inc(r.pos) inc(r.pos)
loc.s = TStorageLoc(decodeVInt(r.s, r.pos)) loc.s = TStorageLoc(decodeVInt(r.s, r.pos))
else: else:
loc.s = low(loc.s) loc.s = low(loc.s)
if r.s[r.pos] == '$': if r.s[r.pos] == '$':
inc(r.pos) inc(r.pos)
loc.flags = cast[TLocFlags](int32(decodeVInt(r.s, r.pos))) loc.flags = cast[TLocFlags](int32(decodeVInt(r.s, r.pos)))
else: else:
loc.flags = {} loc.flags = {}
if r.s[r.pos] == '^': if r.s[r.pos] == '^':
inc(r.pos) inc(r.pos)
loc.t = rrGetType(r, decodeVInt(r.s, r.pos), info) loc.t = rrGetType(r, decodeVInt(r.s, r.pos), info)
else: else:
loc.t = nil loc.t = nil
if r.s[r.pos] == '!': if r.s[r.pos] == '!':
inc(r.pos) inc(r.pos)
loc.r = rope(decodeStr(r.s, r.pos)) loc.r = rope(decodeStr(r.s, r.pos))
else: else:
loc.r = nil loc.r = nil
if r.s[r.pos] == '>': inc(r.pos) if r.s[r.pos] == '>': inc(r.pos)
else: internalError(info, "decodeLoc " & r.s[r.pos]) else: internalError(info, "decodeLoc " & r.s[r.pos])
proc decodeType(r: PRodReader, info: TLineInfo): PType = proc decodeType(r: PRodReader, info: TLineInfo): PType =
result = nil result = nil
if r.s[r.pos] == '[': if r.s[r.pos] == '[':
inc(r.pos) inc(r.pos)
if r.s[r.pos] == ']': if r.s[r.pos] == ']':
inc(r.pos) inc(r.pos)
return # nil type return # nil type
new(result) new(result)
result.kind = TTypeKind(decodeVInt(r.s, r.pos)) result.kind = TTypeKind(decodeVInt(r.s, r.pos))
if r.s[r.pos] == '+': if r.s[r.pos] == '+':
inc(r.pos) inc(r.pos)
result.id = decodeVInt(r.s, r.pos) result.id = decodeVInt(r.s, r.pos)
setId(result.id) setId(result.id)
if debugIds: registerID(result) if debugIds: registerID(result)
else: else:
internalError(info, "decodeType: no id") internalError(info, "decodeType: no id")
# here this also avoids endless recursion for recursive type # here this also avoids endless recursion for recursive type
idTablePut(gTypeTable, result, result) idTablePut(gTypeTable, result, result)
if r.s[r.pos] == '(': result.n = decodeNode(r, unknownLineInfo()) if r.s[r.pos] == '(': result.n = decodeNode(r, unknownLineInfo())
if r.s[r.pos] == '$': if r.s[r.pos] == '$':
inc(r.pos) inc(r.pos)
result.flags = cast[TTypeFlags](int32(decodeVInt(r.s, r.pos))) result.flags = cast[TTypeFlags](int32(decodeVInt(r.s, r.pos)))
if r.s[r.pos] == '?': if r.s[r.pos] == '?':
inc(r.pos) inc(r.pos)
result.callConv = TCallingConvention(decodeVInt(r.s, r.pos)) result.callConv = TCallingConvention(decodeVInt(r.s, r.pos))
if r.s[r.pos] == '*': if r.s[r.pos] == '*':
inc(r.pos) inc(r.pos)
result.owner = rrGetSym(r, decodeVInt(r.s, r.pos), info) result.owner = rrGetSym(r, decodeVInt(r.s, r.pos), info)
if r.s[r.pos] == '&': if r.s[r.pos] == '&':
inc(r.pos) inc(r.pos)
result.sym = rrGetSym(r, decodeVInt(r.s, r.pos), info) result.sym = rrGetSym(r, decodeVInt(r.s, r.pos), info)
if r.s[r.pos] == '/': if r.s[r.pos] == '/':
inc(r.pos) inc(r.pos)
result.size = decodeVInt(r.s, r.pos) result.size = decodeVInt(r.s, r.pos)
else: else:
result.size = - 1 result.size = - 1
if r.s[r.pos] == '=': if r.s[r.pos] == '=':
inc(r.pos) inc(r.pos)
result.align = decodeVInt(r.s, r.pos).int16 result.align = decodeVInt(r.s, r.pos).int16
else: else:
result.align = 2 result.align = 2
decodeLoc(r, result.loc, info) decodeLoc(r, result.loc, info)
while r.s[r.pos] == '^': while r.s[r.pos] == '^':
inc(r.pos) inc(r.pos)
if r.s[r.pos] == '(': if r.s[r.pos] == '(':
inc(r.pos) inc(r.pos)
if r.s[r.pos] == ')': inc(r.pos) if r.s[r.pos] == ')': inc(r.pos)
else: internalError(info, "decodeType ^(" & r.s[r.pos]) else: internalError(info, "decodeType ^(" & r.s[r.pos])
rawAddSon(result, nil) rawAddSon(result, nil)
else: else:
var d = decodeVInt(r.s, r.pos) var d = decodeVInt(r.s, r.pos)
rawAddSon(result, rrGetType(r, d, info)) rawAddSon(result, rrGetType(r, d, info))
proc decodeLib(r: PRodReader, info: TLineInfo): PLib = proc decodeLib(r: PRodReader, info: TLineInfo): PLib =
result = nil result = nil
if r.s[r.pos] == '|': if r.s[r.pos] == '|':
new(result) new(result)
inc(r.pos) inc(r.pos)
result.kind = TLibKind(decodeVInt(r.s, r.pos)) result.kind = TLibKind(decodeVInt(r.s, r.pos))
@ -349,31 +349,31 @@ proc decodeLib(r: PRodReader, info: TLineInfo): PLib =
inc(r.pos) inc(r.pos)
result.path = decodeNode(r, info) result.path = decodeNode(r, info)
proc decodeSym(r: PRodReader, info: TLineInfo): PSym = proc decodeSym(r: PRodReader, info: TLineInfo): PSym =
var var
id: int id: int
ident: PIdent ident: PIdent
result = nil result = nil
if r.s[r.pos] == '{': if r.s[r.pos] == '{':
inc(r.pos) inc(r.pos)
if r.s[r.pos] == '}': if r.s[r.pos] == '}':
inc(r.pos) inc(r.pos)
return # nil sym return # nil sym
var k = TSymKind(decodeVInt(r.s, r.pos)) var k = TSymKind(decodeVInt(r.s, r.pos))
if r.s[r.pos] == '+': if r.s[r.pos] == '+':
inc(r.pos) inc(r.pos)
id = decodeVInt(r.s, r.pos) id = decodeVInt(r.s, r.pos)
setId(id) setId(id)
else: else:
internalError(info, "decodeSym: no id") internalError(info, "decodeSym: no id")
if r.s[r.pos] == '&': if r.s[r.pos] == '&':
inc(r.pos) inc(r.pos)
ident = getIdent(decodeStr(r.s, r.pos)) ident = getIdent(decodeStr(r.s, r.pos))
else: else:
internalError(info, "decodeSym: no ident") internalError(info, "decodeSym: no ident")
#echo "decoding: {", ident.s #echo "decoding: {", ident.s
result = PSym(idTableGet(r.syms, id)) result = PSym(idTableGet(r.syms, id))
if result == nil: if result == nil:
new(result) new(result)
result.id = id result.id = id
idTablePut(r.syms, result, result) idTablePut(r.syms, result, result)
@ -388,35 +388,35 @@ proc decodeSym(r: PRodReader, info: TLineInfo): PSym =
result.id = id result.id = id
result.kind = k result.kind = k
result.name = ident # read the rest of the symbol description: result.name = ident # read the rest of the symbol description:
if r.s[r.pos] == '^': if r.s[r.pos] == '^':
inc(r.pos) inc(r.pos)
result.typ = rrGetType(r, decodeVInt(r.s, r.pos), info) result.typ = rrGetType(r, decodeVInt(r.s, r.pos), info)
decodeLineInfo(r, result.info) decodeLineInfo(r, result.info)
if r.s[r.pos] == '*': if r.s[r.pos] == '*':
inc(r.pos) inc(r.pos)
result.owner = rrGetSym(r, decodeVInt(r.s, r.pos), result.info) result.owner = rrGetSym(r, decodeVInt(r.s, r.pos), result.info)
if r.s[r.pos] == '$': if r.s[r.pos] == '$':
inc(r.pos) inc(r.pos)
result.flags = cast[TSymFlags](int32(decodeVInt(r.s, r.pos))) result.flags = cast[TSymFlags](int32(decodeVInt(r.s, r.pos)))
if r.s[r.pos] == '@': if r.s[r.pos] == '@':
inc(r.pos) inc(r.pos)
result.magic = TMagic(decodeVInt(r.s, r.pos)) result.magic = TMagic(decodeVInt(r.s, r.pos))
if r.s[r.pos] == '!': if r.s[r.pos] == '!':
inc(r.pos) inc(r.pos)
result.options = cast[TOptions](int32(decodeVInt(r.s, r.pos))) result.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
else: else:
result.options = r.options result.options = r.options
if r.s[r.pos] == '%': if r.s[r.pos] == '%':
inc(r.pos) inc(r.pos)
result.position = decodeVInt(r.s, r.pos) result.position = decodeVInt(r.s, r.pos)
elif result.kind notin routineKinds + {skModule}: elif result.kind notin routineKinds + {skModule}:
result.position = 0 result.position = 0
# this may have been misused as reader index! But we still # this may have been misused as reader index! But we still
# need it for routines as the body is loaded lazily. # need it for routines as the body is loaded lazily.
if r.s[r.pos] == '`': if r.s[r.pos] == '`':
inc(r.pos) inc(r.pos)
result.offset = decodeVInt(r.s, r.pos) result.offset = decodeVInt(r.s, r.pos)
else: else:
result.offset = - 1 result.offset = - 1
decodeLoc(r, result.loc, result.info) decodeLoc(r, result.loc, result.info)
result.annex = decodeLib(r, info) result.annex = decodeLib(r, info)
@ -433,35 +433,35 @@ proc decodeSym(r: PRodReader, info: TLineInfo): PSym =
result.ast = decodeNode(r, result.info) result.ast = decodeNode(r, result.info)
#echo "decoded: ", ident.s, "}" #echo "decoded: ", ident.s, "}"
proc skipSection(r: PRodReader) = proc skipSection(r: PRodReader) =
if r.s[r.pos] == ':': if r.s[r.pos] == ':':
while r.s[r.pos] > '\x0A': inc(r.pos) while r.s[r.pos] > '\x0A': inc(r.pos)
elif r.s[r.pos] == '(': elif r.s[r.pos] == '(':
var c = 0 # count () pairs var c = 0 # count () pairs
inc(r.pos) inc(r.pos)
while true: while true:
case r.s[r.pos] case r.s[r.pos]
of '\x0A': inc(r.line) of '\x0A': inc(r.line)
of '(': inc(c) of '(': inc(c)
of ')': of ')':
if c == 0: if c == 0:
inc(r.pos) inc(r.pos)
break break
elif c > 0: elif c > 0:
dec(c) dec(c)
of '\0': break # end of file of '\0': break # end of file
else: discard else: discard
inc(r.pos) inc(r.pos)
else: else:
internalError("skipSection " & $r.line) internalError("skipSection " & $r.line)
proc rdWord(r: PRodReader): string = proc rdWord(r: PRodReader): string =
result = "" result = ""
while r.s[r.pos] in {'A'..'Z', '_', 'a'..'z', '0'..'9'}: while r.s[r.pos] in {'A'..'Z', '_', 'a'..'z', '0'..'9'}:
add(result, r.s[r.pos]) add(result, r.s[r.pos])
inc(r.pos) inc(r.pos)
proc newStub(r: PRodReader, name: string, id: int): PSym = proc newStub(r: PRodReader, name: string, id: int): PSym =
new(result) new(result)
result.kind = skStub result.kind = skStub
result.id = id result.id = id
@ -469,11 +469,11 @@ proc newStub(r: PRodReader, name: string, id: int): PSym =
result.position = r.readerIndex result.position = r.readerIndex
setId(id) #MessageOut(result.name.s); setId(id) #MessageOut(result.name.s);
if debugIds: registerID(result) if debugIds: registerID(result)
proc processInterf(r: PRodReader, module: PSym) = proc processInterf(r: PRodReader, module: PSym) =
if r.interfIdx == 0: internalError("processInterf") if r.interfIdx == 0: internalError("processInterf")
r.pos = r.interfIdx r.pos = r.interfIdx
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'): while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
var w = decodeStr(r.s, r.pos) var w = decodeStr(r.s, r.pos)
inc(r.pos) inc(r.pos)
var key = decodeVInt(r.s, r.pos) var key = decodeVInt(r.s, r.pos)
@ -483,28 +483,28 @@ proc processInterf(r: PRodReader, module: PSym) =
strTableAdd(module.tab, s) strTableAdd(module.tab, s)
idTablePut(r.syms, s, s) idTablePut(r.syms, s, s)
proc processCompilerProcs(r: PRodReader, module: PSym) = proc processCompilerProcs(r: PRodReader, module: PSym) =
if r.compilerProcsIdx == 0: internalError("processCompilerProcs") if r.compilerProcsIdx == 0: internalError("processCompilerProcs")
r.pos = r.compilerProcsIdx r.pos = r.compilerProcsIdx
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'): while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
var w = decodeStr(r.s, r.pos) var w = decodeStr(r.s, r.pos)
inc(r.pos) inc(r.pos)
var key = decodeVInt(r.s, r.pos) var key = decodeVInt(r.s, r.pos)
inc(r.pos) # #10 inc(r.pos) # #10
var s = PSym(idTableGet(r.syms, key)) var s = PSym(idTableGet(r.syms, key))
if s == nil: if s == nil:
s = newStub(r, w, key) s = newStub(r, w, key)
s.owner = module s.owner = module
idTablePut(r.syms, s, s) idTablePut(r.syms, s, s)
strTableAdd(rodCompilerprocs, s) strTableAdd(rodCompilerprocs, s)
proc processIndex(r: PRodReader; idx: var TIndex; outf: File = nil) = proc processIndex(r: PRodReader; idx: var TIndex; outf: File = nil) =
var key, val, tmp: int var key, val, tmp: int
inc(r.pos, 2) # skip "(\10" inc(r.pos, 2) # skip "(\10"
inc(r.line) inc(r.line)
while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'): while (r.s[r.pos] > '\x0A') and (r.s[r.pos] != ')'):
tmp = decodeVInt(r.s, r.pos) tmp = decodeVInt(r.s, r.pos)
if r.s[r.pos] == ' ': if r.s[r.pos] == ' ':
inc(r.pos) inc(r.pos)
key = idx.lastIdxKey + tmp key = idx.lastIdxKey + tmp
val = decodeVInt(r.s, r.pos) + idx.lastIdxVal val = decodeVInt(r.s, r.pos) + idx.lastIdxVal
@ -516,11 +516,11 @@ proc processIndex(r: PRodReader; idx: var TIndex; outf: File = nil) =
idx.lastIdxKey = key idx.lastIdxKey = key
idx.lastIdxVal = val idx.lastIdxVal = val
setId(key) # ensure that this id will not be used setId(key) # ensure that this id will not be used
if r.s[r.pos] == '\x0A': if r.s[r.pos] == '\x0A':
inc(r.pos) inc(r.pos)
inc(r.line) inc(r.line)
if r.s[r.pos] == ')': inc(r.pos) if r.s[r.pos] == ')': inc(r.pos)
proc cmdChangeTriggersRecompilation(old, new: TCommands): bool = proc cmdChangeTriggersRecompilation(old, new: TCommands): bool =
if old == new: return false if old == new: return false
# we use a 'case' statement without 'else' so that addition of a # we use a 'case' statement without 'else' so that addition of a
@ -532,34 +532,34 @@ proc cmdChangeTriggersRecompilation(old, new: TCommands): bool =
cmdInteractive}: cmdInteractive}:
return false return false
of cmdNone, cmdDoc, cmdInterpret, cmdPretty, cmdGenDepend, cmdDump, of cmdNone, cmdDoc, cmdInterpret, cmdPretty, cmdGenDepend, cmdDump,
cmdCheck, cmdParse, cmdScan, cmdIdeTools, cmdDef, cmdCheck, cmdParse, cmdScan, cmdIdeTools, cmdDef,
cmdRst2html, cmdRst2tex, cmdInteractive, cmdRun: cmdRst2html, cmdRst2tex, cmdInteractive, cmdRun:
discard discard
# else: trigger recompilation: # else: trigger recompilation:
result = true result = true
proc processRodFile(r: PRodReader, crc: SecureHash) = proc processRodFile(r: PRodReader, crc: SecureHash) =
var var
w: string w: string
d: int d: int
var inclCrc: SecureHash var inclCrc: SecureHash
while r.s[r.pos] != '\0': while r.s[r.pos] != '\0':
var section = rdWord(r) var section = rdWord(r)
if r.reason != rrNone: if r.reason != rrNone:
break # no need to process this file further break # no need to process this file further
case section case section
of "CRC": of "CRC":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
if crc != parseSecureHash(decodeStr(r.s, r.pos)): if crc != parseSecureHash(decodeStr(r.s, r.pos)):
r.reason = rrCrcChange r.reason = rrCrcChange
of "ID": of "ID":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
r.moduleID = decodeVInt(r.s, r.pos) r.moduleID = decodeVInt(r.s, r.pos)
setId(r.moduleID) setId(r.moduleID)
of "ORIGFILE": of "ORIGFILE":
inc(r.pos) inc(r.pos)
r.origFile = decodeStr(r.s, r.pos) r.origFile = decodeStr(r.s, r.pos)
of "OPTIONS": of "OPTIONS":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos))) r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
if options.gOptions != r.options: r.reason = rrOptions if options.gOptions != r.options: r.reason = rrOptions
@ -574,14 +574,14 @@ proc processRodFile(r: PRodReader, crc: SecureHash) =
of "DEFINES": of "DEFINES":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
d = 0 d = 0
while r.s[r.pos] > '\x0A': while r.s[r.pos] > '\x0A':
w = decodeStr(r.s, r.pos) w = decodeStr(r.s, r.pos)
inc(d) inc(d)
if not condsyms.isDefined(getIdent(w)): if not condsyms.isDefined(getIdent(w)):
r.reason = rrDefines #MessageOut('not defined, but should: ' + w); r.reason = rrDefines #MessageOut('not defined, but should: ' + w);
if r.s[r.pos] == ' ': inc(r.pos) if r.s[r.pos] == ' ': inc(r.pos)
if (d != countDefinedSymbols()): r.reason = rrDefines if (d != countDefinedSymbols()): r.reason = rrDefines
of "FILES": of "FILES":
inc(r.pos, 2) # skip "(\10" inc(r.pos, 2) # skip "(\10"
inc(r.line) inc(r.line)
while r.s[r.pos] != ')': while r.s[r.pos] != ')':
@ -592,17 +592,17 @@ proc processRodFile(r: PRodReader, crc: SecureHash) =
inc(r.pos) # skip #10 inc(r.pos) # skip #10
inc(r.line) inc(r.line)
if r.s[r.pos] == ')': inc(r.pos) if r.s[r.pos] == ')': inc(r.pos)
of "INCLUDES": of "INCLUDES":
inc(r.pos, 2) # skip "(\10" inc(r.pos, 2) # skip "(\10"
inc(r.line) inc(r.line)
while r.s[r.pos] != ')': while r.s[r.pos] != ')':
w = r.files[decodeVInt(r.s, r.pos)].toFullPath w = r.files[decodeVInt(r.s, r.pos)].toFullPath
inc(r.pos) # skip ' ' inc(r.pos) # skip ' '
inclCrc = parseSecureHash(decodeStr(r.s, r.pos)) inclCrc = parseSecureHash(decodeStr(r.s, r.pos))
if r.reason == rrNone: if r.reason == rrNone:
if not existsFile(w) or (inclCrc != secureHashFile(w)): if not existsFile(w) or (inclCrc != secureHashFile(w)):
r.reason = rrInclDeps r.reason = rrInclDeps
if r.s[r.pos] == '\x0A': if r.s[r.pos] == '\x0A':
inc(r.pos) inc(r.pos)
inc(r.line) inc(r.line)
if r.s[r.pos] == ')': inc(r.pos) if r.s[r.pos] == ')': inc(r.pos)
@ -611,28 +611,28 @@ proc processRodFile(r: PRodReader, crc: SecureHash) =
while r.s[r.pos] > '\x0A': while r.s[r.pos] > '\x0A':
r.modDeps.add(r.files[int32(decodeVInt(r.s, r.pos))]) r.modDeps.add(r.files[int32(decodeVInt(r.s, r.pos))])
if r.s[r.pos] == ' ': inc(r.pos) if r.s[r.pos] == ' ': inc(r.pos)
of "INTERF": of "INTERF":
r.interfIdx = r.pos + 2 r.interfIdx = r.pos + 2
skipSection(r) skipSection(r)
of "COMPILERPROCS": of "COMPILERPROCS":
r.compilerProcsIdx = r.pos + 2 r.compilerProcsIdx = r.pos + 2
skipSection(r) skipSection(r)
of "INDEX": of "INDEX":
processIndex(r, r.index) processIndex(r, r.index)
of "IMPORTS": of "IMPORTS":
processIndex(r, r.imports) processIndex(r, r.imports)
of "CONVERTERS": of "CONVERTERS":
r.convertersIdx = r.pos + 1 r.convertersIdx = r.pos + 1
skipSection(r) skipSection(r)
of "METHODS": of "METHODS":
r.methodsIdx = r.pos + 1 r.methodsIdx = r.pos + 1
skipSection(r) skipSection(r)
of "DATA": of "DATA":
r.dataIdx = r.pos + 2 # "(\10" r.dataIdx = r.pos + 2 # "(\10"
# We do not read the DATA section here! We read the needed objects on # We do not read the DATA section here! We read the needed objects on
# demand. And the DATA section comes last in the file, so we stop here: # demand. And the DATA section comes last in the file, so we stop here:
break break
of "INIT": of "INIT":
r.initIdx = r.pos + 2 # "(\10" r.initIdx = r.pos + 2 # "(\10"
skipSection(r) skipSection(r)
else: else:
@ -641,7 +641,7 @@ proc processRodFile(r: PRodReader, crc: SecureHash) =
#MsgWriteln("skipping section: " & section & #MsgWriteln("skipping section: " & section &
# " at " & $r.line & " in " & r.filename) # " at " & $r.line & " in " & r.filename)
skipSection(r) skipSection(r)
if r.s[r.pos] == '\x0A': if r.s[r.pos] == '\x0A':
inc(r.pos) inc(r.pos)
inc(r.line) inc(r.line)
@ -652,7 +652,7 @@ proc startsWith(buf: cstring, token: string, pos = 0): bool =
result = s == token.len result = s == token.len
proc newRodReader(modfilename: string, crc: SecureHash, proc newRodReader(modfilename: string, crc: SecureHash,
readerIndex: int): PRodReader = readerIndex: int): PRodReader =
new(result) new(result)
try: try:
result.memfile = memfiles.open(modfilename) result.memfile = memfiles.open(modfilename)
@ -671,7 +671,7 @@ proc newRodReader(modfilename: string, crc: SecureHash,
# we terminate the file explicitly with ``\0``, so the cast to `cstring` # we terminate the file explicitly with ``\0``, so the cast to `cstring`
# is safe: # is safe:
r.s = cast[cstring](r.memfile.mem) r.s = cast[cstring](r.memfile.mem)
if startsWith(r.s, "NIM:"): if startsWith(r.s, "NIM:"):
initIiTable(r.index.tab) initIiTable(r.index.tab)
initIiTable(r.imports.tab) # looks like a ROD file initIiTable(r.imports.tab) # looks like a ROD file
inc(r.pos, 4) inc(r.pos, 4)
@ -680,16 +680,16 @@ proc newRodReader(modfilename: string, crc: SecureHash,
add(version, r.s[r.pos]) add(version, r.s[r.pos])
inc(r.pos) inc(r.pos)
if r.s[r.pos] == '\x0A': inc(r.pos) if r.s[r.pos] == '\x0A': inc(r.pos)
if version != RodFileVersion: if version != RodFileVersion:
# since ROD files are only for caching, no backwards compatibility is # since ROD files are only for caching, no backwards compatibility is
# needed # needed
result = nil result = nil
else: else:
result = nil result = nil
proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType = proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType =
result = PType(idTableGet(gTypeTable, id)) result = PType(idTableGet(gTypeTable, id))
if result == nil: if result == nil:
# load the type: # load the type:
var oldPos = r.pos var oldPos = r.pos
var d = iiTableGet(r.index.tab, id) var d = iiTableGet(r.index.tab, id)
@ -698,8 +698,8 @@ proc rrGetType(r: PRodReader, id: int, info: TLineInfo): PType =
result = decodeType(r, info) result = decodeType(r, info)
r.pos = oldPos r.pos = oldPos
type type
TFileModuleRec{.final.} = object TFileModuleRec{.final.} = object
filename*: string filename*: string
reason*: TReasonForRecompile reason*: TReasonForRecompile
rd*: PRodReader rd*: PRodReader
@ -710,7 +710,7 @@ type
var gMods*: TFileModuleMap = @[] var gMods*: TFileModuleMap = @[]
proc decodeSymSafePos(rd: PRodReader, offset: int, info: TLineInfo): PSym = proc decodeSymSafePos(rd: PRodReader, offset: int, info: TLineInfo): PSym =
# all compiled modules # all compiled modules
if rd.dataIdx == 0: internalError(info, "dataIdx == 0") if rd.dataIdx == 0: internalError(info, "dataIdx == 0")
var oldPos = rd.pos var oldPos = rd.pos
@ -719,9 +719,9 @@ proc decodeSymSafePos(rd: PRodReader, offset: int, info: TLineInfo): PSym =
rd.pos = oldPos rd.pos = oldPos
proc findSomeWhere(id: int) = proc findSomeWhere(id: int) =
for i in countup(0, high(gMods)): for i in countup(0, high(gMods)):
var rd = gMods[i].rd var rd = gMods[i].rd
if rd != nil: if rd != nil:
var d = iiTableGet(rd.index.tab, id) var d = iiTableGet(rd.index.tab, id)
if d != InvalidKey: if d != InvalidKey:
echo "found id ", id, " in ", gMods[i].filename echo "found id ", id, " in ", gMods[i].filename
@ -736,12 +736,12 @@ proc getReader(moduleId: int): PRodReader =
if result != nil and result.moduleID == moduleId: return result if result != nil and result.moduleID == moduleId: return result
return nil return nil
proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym = proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym =
result = PSym(idTableGet(r.syms, id)) result = PSym(idTableGet(r.syms, id))
if result == nil: if result == nil:
# load the symbol: # load the symbol:
var d = iiTableGet(r.index.tab, id) var d = iiTableGet(r.index.tab, id)
if d == InvalidKey: if d == InvalidKey:
# import from other module: # import from other module:
var moduleID = iiTableGet(r.imports.tab, id) var moduleID = iiTableGet(r.imports.tab, id)
if moduleID < 0: if moduleID < 0:
@ -750,24 +750,24 @@ proc rrGetSym(r: PRodReader, id: int, info: TLineInfo): PSym =
internalError(info, "missing from both indexes: +" & x) internalError(info, "missing from both indexes: +" & x)
var rd = getReader(moduleID) var rd = getReader(moduleID)
d = iiTableGet(rd.index.tab, id) d = iiTableGet(rd.index.tab, id)
if d != InvalidKey: if d != InvalidKey:
result = decodeSymSafePos(rd, d, info) result = decodeSymSafePos(rd, d, info)
else: else:
var x = "" var x = ""
encodeVInt(id, x) encodeVInt(id, x)
when false: findSomeWhere(id) when false: findSomeWhere(id)
internalError(info, "rrGetSym: no reader found: +" & x) internalError(info, "rrGetSym: no reader found: +" & x)
else: else:
# own symbol: # own symbol:
result = decodeSymSafePos(r, d, info) result = decodeSymSafePos(r, d, info)
if result != nil and result.kind == skStub: rawLoadStub(result) 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") if r.initIdx == 0 or r.dataIdx == 0: internalError("loadInitSection")
var oldPos = r.pos var oldPos = r.pos
r.pos = r.initIdx r.pos = r.initIdx
result = newNode(nkStmtList) result = newNode(nkStmtList)
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')': while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
var d = decodeVInt(r.s, r.pos) var d = decodeVInt(r.s, r.pos)
inc(r.pos) # #10 inc(r.pos) # #10
var p = r.pos var p = r.pos
@ -776,13 +776,13 @@ proc loadInitSection(r: PRodReader): PNode =
r.pos = p r.pos = p
r.pos = oldPos r.pos = oldPos
proc loadConverters(r: PRodReader) = proc loadConverters(r: PRodReader) =
# We have to ensure that no exported converter is a stub anymore, and the # We have to ensure that no exported converter is a stub anymore, and the
# import mechanism takes care of the rest. # import mechanism takes care of the rest.
if r.convertersIdx == 0 or r.dataIdx == 0: if r.convertersIdx == 0 or r.dataIdx == 0:
internalError("importConverters") internalError("importConverters")
r.pos = r.convertersIdx r.pos = r.convertersIdx
while r.s[r.pos] > '\x0A': while r.s[r.pos] > '\x0A':
var d = decodeVInt(r.s, r.pos) var d = decodeVInt(r.s, r.pos)
discard rrGetSym(r, d, unknownLineInfo()) discard rrGetSym(r, d, unknownLineInfo())
if r.s[r.pos] == ' ': inc(r.pos) if r.s[r.pos] == ' ': inc(r.pos)
@ -801,7 +801,7 @@ proc getCRC*(fileIdx: int32): SecureHash =
if gMods[fileIdx].crcDone: if gMods[fileIdx].crcDone:
return gMods[fileIdx].crc return gMods[fileIdx].crc
result = secureHashFile(fileIdx.toFilename) result = secureHashFile(fileIdx.toFilename)
gMods[fileIdx].crc = result gMods[fileIdx].crc = result
@ -811,7 +811,7 @@ template growCache*(cache, pos) =
proc checkDep(fileIdx: int32): TReasonForRecompile = proc checkDep(fileIdx: int32): TReasonForRecompile =
assert fileIdx != InvalidFileIDX assert fileIdx != InvalidFileIDX
growCache gMods, fileIdx growCache gMods, fileIdx
if gMods[fileIdx].reason != rrEmpty: if gMods[fileIdx].reason != rrEmpty:
# reason has already been computed for this module: # reason has already been computed for this module:
return gMods[fileIdx].reason return gMods[fileIdx].reason
let filename = fileIdx.toFilename let filename = fileIdx.toFilename
@ -821,12 +821,12 @@ proc checkDep(fileIdx: int32): TReasonForRecompile =
var r: PRodReader = nil var r: PRodReader = nil
var rodfile = toGeneratedFile(filename.withPackageName, RodExt) var rodfile = toGeneratedFile(filename.withPackageName, RodExt)
r = newRodReader(rodfile, crc, fileIdx) r = newRodReader(rodfile, crc, fileIdx)
if r == nil: if r == nil:
result = (if existsFile(rodfile): rrRodInvalid else: rrRodDoesNotExist) result = (if existsFile(rodfile): rrRodInvalid else: rrRodDoesNotExist)
else: else:
processRodFile(r, crc) processRodFile(r, crc)
result = r.reason result = r.reason
if result == rrNone: if result == rrNone:
# check modules it depends on # check modules it depends on
# NOTE: we need to process the entire module graph so that no ID will # NOTE: we need to process the entire module graph so that no ID will
# be used twice! However, compilation speed does not suffer much from # be used twice! However, compilation speed does not suffer much from
@ -846,10 +846,10 @@ proc checkDep(fileIdx: int32): TReasonForRecompile =
r = nil r = nil
gMods[fileIdx].rd = r gMods[fileIdx].rd = r
gMods[fileIdx].reason = result # now we know better gMods[fileIdx].reason = result # now we know better
proc handleSymbolFile(module: PSym): PRodReader = proc handleSymbolFile(module: PSym): PRodReader =
let fileIdx = module.fileIdx let fileIdx = module.fileIdx
if optSymbolFiles notin gGlobalOptions: if optSymbolFiles notin gGlobalOptions:
module.id = getID() module.id = getID()
return nil return nil
idgen.loadMaxIds(options.gProjectPath / options.gProjectName) idgen.loadMaxIds(options.gProjectPath / options.gProjectName)
@ -857,7 +857,7 @@ proc handleSymbolFile(module: PSym): PRodReader =
discard checkDep(fileIdx) discard checkDep(fileIdx)
if gMods[fileIdx].reason == rrEmpty: internalError("handleSymbolFile") if gMods[fileIdx].reason == rrEmpty: internalError("handleSymbolFile")
result = gMods[fileIdx].rd result = gMods[fileIdx].rd
if result != nil: if result != nil:
module.id = result.moduleID module.id = result.moduleID
idTablePut(result.syms, module, module) idTablePut(result.syms, module, module)
processInterf(result, module) processInterf(result, module)
@ -878,13 +878,13 @@ proc rawLoadStub(s: PSym) =
#echo "rs: ", toHex(cast[int](rs.position), int.sizeof * 2), #echo "rs: ", toHex(cast[int](rs.position), int.sizeof * 2),
# "\ns: ", toHex(cast[int](s.position), int.sizeof * 2) # "\ns: ", toHex(cast[int](s.position), int.sizeof * 2)
internalError(rs.info, "loadStub: wrong symbol") internalError(rs.info, "loadStub: wrong symbol")
elif rs.id != theId: elif rs.id != theId:
internalError(rs.info, "loadStub: wrong ID") internalError(rs.info, "loadStub: wrong ID")
#MessageOut('loaded stub: ' + s.name.s); #MessageOut('loaded stub: ' + s.name.s);
proc loadStub*(s: PSym) = proc loadStub*(s: PSym) =
## loads the stub symbol `s`. ## loads the stub symbol `s`.
# deactivate the GC here because we do a deep recursion and generate no # deactivate the GC here because we do a deep recursion and generate no
# garbage when restoring parts of the object graph anyway. # garbage when restoring parts of the object graph anyway.
# Since we die with internal errors if this fails, no try-finally is # Since we die with internal errors if this fails, no try-finally is
@ -892,7 +892,7 @@ proc loadStub*(s: PSym) =
GC_disable() GC_disable()
rawLoadStub(s) rawLoadStub(s)
GC_enable() GC_enable()
proc getBody*(s: PSym): PNode = proc getBody*(s: PSym): PNode =
## retrieves the AST's body of `s`. If `s` has been loaded from a rod-file ## retrieves the AST's body of `s`. If `s` has been loaded from a rod-file
## it may perform an expensive reload operation. Otherwise it's a simple ## it may perform an expensive reload operation. Otherwise it's a simple
@ -908,7 +908,7 @@ proc getBody*(s: PSym): PNode =
r.pos = oldPos r.pos = oldPos
s.ast.sons[bodyPos] = result s.ast.sons[bodyPos] = result
s.offset = 0 s.offset = 0
initIdTable(gTypeTable) initIdTable(gTypeTable)
initStrTable(rodCompilerprocs) initStrTable(rodCompilerprocs)
@ -921,16 +921,16 @@ proc writeNode(f: File; n: PNode) =
f.write('^') f.write('^')
f.write(n.typ.id) f.write(n.typ.id)
case n.kind case n.kind
of nkCharLit..nkInt64Lit: of nkCharLit..nkInt64Lit:
if n.intVal != 0: if n.intVal != 0:
f.write('!') f.write('!')
f.write(n.intVal) f.write(n.intVal)
of nkFloatLit..nkFloat64Lit: of nkFloatLit..nkFloat64Lit:
if n.floatVal != 0.0: if n.floatVal != 0.0:
f.write('!') f.write('!')
f.write($n.floatVal) f.write($n.floatVal)
of nkStrLit..nkTripleStrLit: of nkStrLit..nkTripleStrLit:
if n.strVal != "": if n.strVal != "":
f.write('!') f.write('!')
f.write(n.strVal.escape) f.write(n.strVal.escape)
of nkIdent: of nkIdent:
@ -940,7 +940,7 @@ proc writeNode(f: File; n: PNode) =
f.write('!') f.write('!')
f.write(n.sym.id) f.write(n.sym.id)
else: else:
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
writeNode(f, n.sons[i]) writeNode(f, n.sons[i])
f.write(")") f.write(")")
@ -966,10 +966,10 @@ proc writeSym(f: File; s: PSym) =
if s.magic != mNone: if s.magic != mNone:
f.write('@') f.write('@')
f.write($s.magic) f.write($s.magic)
if s.options != gOptions: if s.options != gOptions:
f.write('!') f.write('!')
f.write($s.options) f.write($s.options)
if s.position != 0: if s.position != 0:
f.write('%') f.write('%')
f.write($s.position) f.write($s.position)
if s.offset != -1: if s.offset != -1:
@ -990,12 +990,12 @@ proc writeType(f: File; t: PType) =
f.write($t.kind) f.write($t.kind)
f.write('+') f.write('+')
f.write($t.id) f.write($t.id)
if t.n != nil: if t.n != nil:
f.writeNode(t.n) f.writeNode(t.n)
if t.flags != {}: if t.flags != {}:
f.write('$') f.write('$')
f.write($t.flags) f.write($t.flags)
if t.callConv != low(t.callConv): if t.callConv != low(t.callConv):
f.write('?') f.write('?')
f.write($t.callConv) f.write($t.callConv)
if t.owner != nil: if t.owner != nil:
@ -1010,11 +1010,11 @@ proc writeType(f: File; t: PType) =
if t.align != 2: if t.align != 2:
f.write('=') f.write('=')
f.write($t.align) f.write($t.align)
for i in countup(0, sonsLen(t) - 1): for i in countup(0, sonsLen(t) - 1):
if t.sons[i] == nil: if t.sons[i] == nil:
f.write("^()") f.write("^()")
else: else:
f.write('^') f.write('^')
f.write($t.sons[i].id) f.write($t.sons[i].id)
f.write("]\n") f.write("]\n")
@ -1031,28 +1031,28 @@ proc viewFile(rodfile: string) =
case section case section
of "CRC": of "CRC":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
outf.writeln("CRC:", $decodeVInt(r.s, r.pos)) outf.writeLine("CRC:", $decodeVInt(r.s, r.pos))
of "ID": of "ID":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
r.moduleID = decodeVInt(r.s, r.pos) r.moduleID = decodeVInt(r.s, r.pos)
setId(r.moduleID) setId(r.moduleID)
outf.writeln("ID:", $r.moduleID) outf.writeLine("ID:", $r.moduleID)
of "ORIGFILE": of "ORIGFILE":
inc(r.pos) inc(r.pos)
r.origFile = decodeStr(r.s, r.pos) r.origFile = decodeStr(r.s, r.pos)
outf.writeln("ORIGFILE:", r.origFile) outf.writeLine("ORIGFILE:", r.origFile)
of "OPTIONS": of "OPTIONS":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos))) r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
outf.writeln("OPTIONS:", $r.options) outf.writeLine("OPTIONS:", $r.options)
of "GOPTIONS": of "GOPTIONS":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
let dep = cast[TGlobalOptions](int32(decodeVInt(r.s, r.pos))) let dep = cast[TGlobalOptions](int32(decodeVInt(r.s, r.pos)))
outf.writeln("GOPTIONS:", $dep) outf.writeLine("GOPTIONS:", $dep)
of "CMD": of "CMD":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
let dep = cast[TCommands](int32(decodeVInt(r.s, r.pos))) let dep = cast[TCommands](int32(decodeVInt(r.s, r.pos)))
outf.writeln("CMD:", $dep) outf.writeLine("CMD:", $dep)
of "DEFINES": of "DEFINES":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
var d = 0 var d = 0
@ -1074,18 +1074,18 @@ proc viewFile(rodfile: string) =
r.files.add(finalPath.fileInfoIdx) r.files.add(finalPath.fileInfoIdx)
inc(r.pos) # skip #10 inc(r.pos) # skip #10
inc(r.line) inc(r.line)
outf.writeln finalPath outf.writeLine finalPath
if r.s[r.pos] == ')': inc(r.pos) if r.s[r.pos] == ')': inc(r.pos)
outf.write(")\n") outf.write(")\n")
of "INCLUDES": of "INCLUDES":
inc(r.pos, 2) # skip "(\10" inc(r.pos, 2) # skip "(\10"
inc(r.line) inc(r.line)
outf.write("INCLUDES(\n") outf.write("INCLUDES(\n")
while r.s[r.pos] != ')': while r.s[r.pos] != ')':
let w = r.files[decodeVInt(r.s, r.pos)] let w = r.files[decodeVInt(r.s, r.pos)]
inc(r.pos) # skip ' ' inc(r.pos) # skip ' '
let inclCrc = decodeVInt(r.s, r.pos) let inclCrc = decodeVInt(r.s, r.pos)
if r.s[r.pos] == '\x0A': if r.s[r.pos] == '\x0A':
inc(r.pos) inc(r.pos)
inc(r.line) inc(r.line)
outf.write(w, " ", inclCrc, "\n") outf.write(w, " ", inclCrc, "\n")
@ -1094,7 +1094,7 @@ proc viewFile(rodfile: string) =
of "DEPS": of "DEPS":
inc(r.pos) # skip ':' inc(r.pos) # skip ':'
outf.write("DEPS:") outf.write("DEPS:")
while r.s[r.pos] > '\x0A': while r.s[r.pos] > '\x0A':
let v = int32(decodeVInt(r.s, r.pos)) let v = int32(decodeVInt(r.s, r.pos))
r.modDeps.add(r.files[v]) r.modDeps.add(r.files[v])
if r.s[r.pos] == ' ': inc(r.pos) if r.s[r.pos] == ' ': inc(r.pos)
@ -1126,7 +1126,7 @@ proc viewFile(rodfile: string) =
if section == "METHODS": r.methodsIdx = r.pos if section == "METHODS": r.methodsIdx = r.pos
else: r.convertersIdx = r.pos else: r.convertersIdx = r.pos
outf.write(section, ":") outf.write(section, ":")
while r.s[r.pos] > '\x0A': while r.s[r.pos] > '\x0A':
let d = decodeVInt(r.s, r.pos) let d = decodeVInt(r.s, r.pos)
outf.write(" ", $d) outf.write(" ", $d)
if r.s[r.pos] == ' ': inc(r.pos) if r.s[r.pos] == ' ': inc(r.pos)
@ -1152,7 +1152,7 @@ proc viewFile(rodfile: string) =
outf.write("INIT(\n") outf.write("INIT(\n")
inc r.pos, 2 inc r.pos, 2
r.initIdx = r.pos r.initIdx = r.pos
while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')': while r.s[r.pos] > '\x0A' and r.s[r.pos] != ')':
let d = decodeVInt(r.s, r.pos) let d = decodeVInt(r.s, r.pos)
inc(r.pos) # #10 inc(r.pos) # #10
#let p = r.pos #let p = r.pos

View file

@ -218,12 +218,12 @@ proc cmpCandidates*(a, b: TCandidate): int =
result = complexDisambiguation(a.callee, b.callee) result = complexDisambiguation(a.callee, b.callee)
proc writeMatches*(c: TCandidate) = proc writeMatches*(c: TCandidate) =
writeln(stdout, "exact matches: " & $c.exactMatches) writeLine(stdout, "exact matches: " & $c.exactMatches)
writeln(stdout, "generic matches: " & $c.genericMatches) writeLine(stdout, "generic matches: " & $c.genericMatches)
writeln(stdout, "subtype matches: " & $c.subtypeMatches) writeLine(stdout, "subtype matches: " & $c.subtypeMatches)
writeln(stdout, "intconv matches: " & $c.intConvMatches) writeLine(stdout, "intconv matches: " & $c.intConvMatches)
writeln(stdout, "conv matches: " & $c.convMatches) writeLine(stdout, "conv matches: " & $c.convMatches)
writeln(stdout, "inheritance: " & $c.inheritancePenalty) writeLine(stdout, "inheritance: " & $c.inheritancePenalty)
proc argTypeToString(arg: PNode; prefer: TPreferedDesc): string = proc argTypeToString(arg: PNode; prefer: TPreferedDesc): string =
if arg.kind in nkSymChoices: if arg.kind in nkSymChoices: