Skip to content

Commit

Permalink
Merge pull request #1 from nim-lang/devel
Browse files Browse the repository at this point in the history
pull-23-04-18
  • Loading branch information
survivorm authored Apr 23, 2018
2 parents 04df7f1 + a8b70c5 commit 17d3c6f
Show file tree
Hide file tree
Showing 81 changed files with 1,074 additions and 1,398 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
to deal with!
- Indexing into a ``cstring`` for the JS target is now mapped
to ``charCodeAt``.
- Assignments that would "slice" an object into its supertype are not prevented
at runtime. Use ``ref object`` with inheritance rather than ``object`` with
inheritance to prevent this issue.


#### Breaking changes in the standard library

Expand All @@ -27,6 +31,7 @@
- ``proc `-`*(a, b: Time): int64`` in the ``times`` module has changed return type
to ``times.Duration`` in order to support higher time resolutions.
The proc is no longer deprecated.
- ``posix.Timeval.tv_sec`` has changed type to ``posix.Time``.

#### Breaking changes in the compiler

Expand Down
10 changes: 5 additions & 5 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,9 @@ proc newNode*(kind: TNodeKind): PNode =
new(result)
result.kind = kind
#result.info = UnknownLineInfo() inlined:
result.info.fileIndex = int32(-1)
result.info.fileIndex = InvalidFileIdx
result.info.col = int16(-1)
result.info.line = int16(-1)
result.info.line = uint16(0)
when defined(useNodeIds):
result.id = gNodeId
if result.id == nodeIdToDebug:
Expand Down Expand Up @@ -1116,13 +1116,13 @@ proc linkTo*(s: PSym, t: PType): PSym {.discardable.} =
s.typ = t
result = s

template fileIdx*(c: PSym): int32 =
template fileIdx*(c: PSym): FileIndex =
# XXX: this should be used only on module symbols
c.position.int32
c.position.FileIndex

template filename*(c: PSym): string =
# XXX: this should be used only on module symbols
c.position.int32.toFilename
c.position.FileIndex.toFilename

proc appendToModule*(m: PSym, n: PNode) =
## The compiler will use this internally to add nodes that will be
Expand Down
37 changes: 19 additions & 18 deletions compiler/bitsets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,25 @@ proc bitSetContains(x, y: TBitSet): bool =
result = true

# Number of set bits for all values of int8
const populationCount: array[low(int8)..high(int8), int8] = [
1.int8, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7
]
const populationCount: array[low(int8)..high(int8), int8] = block:
var arr: array[low(int8)..high(int8), int8]

proc countSetBits(x: int8): int8 =
return
( x and 0b00000001'i8) +
((x and 0b00000010'i8) shr 1) +
((x and 0b00000100'i8) shr 2) +
((x and 0b00001000'i8) shr 3) +
((x and 0b00010000'i8) shr 4) +
((x and 0b00100000'i8) shr 5) +
((x and 0b01000000'i8) shr 6) +
((x and 0b10000000'i8) shr 7)


for it in low(int8)..high(int8):
arr[it] = countSetBits(it)

arr

proc bitSetCard(x: TBitSet): BiggestInt =
for it in x:
Expand Down
2 changes: 1 addition & 1 deletion compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ template genStmtListExprImpl(exprOrStmt) {.dirty.} =
let theMacro = it[0].sym
add p.s(cpsStmts), initFrameNoDebug(p, frameName,
makeCString theMacro.name.s,
theMacro.info.quotedFilename, it.info.line)
theMacro.info.quotedFilename, it.info.line.int)
else:
genStmts(p, it)
if n.len > 0: exprOrStmt
Expand Down
12 changes: 6 additions & 6 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ proc genLineDir(p: BProc, t: PNode) =
line.rope, makeCString(toFilename(tt.info)))
elif ({optLineTrace, optStackTrace} * p.options ==
{optLineTrace, optStackTrace}) and
(p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex >= 0:
(p.prc == nil or sfPure notin p.prc.flags) and tt.info.fileIndex != InvalidFileIDX:
if freshLineInfo(p, tt.info):
linefmt(p, cpsStmts, "nimln_($1, $2);$n",
line.rope, tt.info.quotedFilename)
Expand Down Expand Up @@ -678,7 +678,7 @@ proc generateHeaders(m: BModule) =

proc openNamespaceNim(): Rope =
result.add("namespace Nim {" & tnl)

proc closeNamespaceNim(): Rope =
result.add("}" & tnl)

Expand Down Expand Up @@ -1090,7 +1090,7 @@ proc genMainProc(m: BModule) =
appcg(m, m.s[cfsProcs], nimMain,
[m.g.mainModInit, initStackBottomCall, rope(m.labels)])
if optNoMain notin gGlobalOptions:
if useNimNamespace:
if useNimNamespace:
m.s[cfsProcs].add closeNamespaceNim() & "using namespace Nim;" & tnl

appcg(m, m.s[cfsProcs], otherMain, [])
Expand Down Expand Up @@ -1202,7 +1202,7 @@ proc genModule(m: BModule, cfile: Cfile): Rope =
add(result, genSectionStart(i))
add(result, m.s[i])
add(result, genSectionEnd(i))
if useNimNamespace and i == cfsHeaders: result.add openNamespaceNim()
if useNimNamespace and i == cfsHeaders: result.add openNamespaceNim()
add(result, m.s[cfsInitProc])
if useNimNamespace: result.add closeNamespaceNim()

Expand Down Expand Up @@ -1301,7 +1301,7 @@ proc resetCgenModules*(g: BModuleList) =
for m in cgenModules(g): resetModule(m)

proc rawNewModule(g: BModuleList; module: PSym): BModule =
result = rawNewModule(g, module, module.position.int32.toFullPath)
result = rawNewModule(g, module, module.position.FileIndex.toFullPath)

proc newModule(g: BModuleList; module: PSym): BModule =
# we should create only one cgen module for each module sym
Expand All @@ -1311,7 +1311,7 @@ proc newModule(g: BModuleList; module: PSym): BModule =

if (optDeadCodeElim in gGlobalOptions):
if (sfDeadCodeElim in module.flags):
internalError("added pending module twice: " & module.filename)
internalError("added pending module twice: " & toFilename(FileIndex module.position))

template injectG(config) {.dirty.} =
if graph.backend == nil:
Expand Down
14 changes: 12 additions & 2 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ proc writeAdvancedUsage(pass: TCmdLinePass) =
{msgStdout})
msgQuit(0)

proc writeFullhelp(pass: TCmdLinePass) =
if pass == passCmd1:
msgWriteln(`%`(HelpMessage, [VersionAsString,
platform.OS[platform.hostOS].name,
CPU[platform.hostCPU].name]) & Usage & AdvancedUsage,
{msgStdout})
msgQuit(0)

proc writeVersionInfo(pass: TCmdLinePass) =
if pass == passCmd1:
msgWriteln(`%`(HelpMessage, [VersionAsString,
Expand Down Expand Up @@ -311,7 +319,7 @@ proc trackDirty(arg: string, info: TLineInfo) =
localError(info, errInvalidNumber, a[2])

let dirtyOriginalIdx = a[1].fileInfoIdx
if dirtyOriginalIdx >= 0:
if dirtyOriginalIdx.int32 >= 0:
msgs.setDirtyFile(dirtyOriginalIdx, a[0])

gTrackPos = newLineInfo(dirtyOriginalIdx, line, column)
Expand Down Expand Up @@ -611,6 +619,9 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "advanced":
expectNoArg(switch, arg, pass, info)
writeAdvancedUsage(pass)
of "fullhelp":
expectNoArg(switch, arg, pass, info)
writeFullhelp(pass)
of "help", "h":
expectNoArg(switch, arg, pass, info)
helpOnError(pass)
Expand Down Expand Up @@ -702,7 +713,6 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
expectNoArg(switch, arg, pass, info)
useNimNamespace = true
defineSymbol("cppCompileToNamespace")

else:
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
else: invalidCmdLineOption(pass, switch, info)
Expand Down
10 changes: 5 additions & 5 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ proc genJsonItem(d: PDoc, n, nameNode: PNode, k: TSymKind): JsonNode =

initTokRender(r, n, {renderNoBody, renderNoComments, renderDocComments})

result = %{ "name": %name, "type": %($k), "line": %n.info.line,
result = %{ "name": %name, "type": %($k), "line": %n.info.line.int,
"col": %n.info.col}
if comm != nil and comm != "":
result["description"] = %comm
Expand Down Expand Up @@ -618,7 +618,7 @@ proc generateJson*(d: PDoc, n: PNode) =
of nkCommentStmt:
if n.comment != nil and startsWith(n.comment, "##"):
let stripped = n.comment.substr(2).strip
d.add %{ "comment": %stripped, "line": %n.info.line,
d.add %{ "comment": %stripped, "line": %n.info.line.int,
"col": %n.info.col }
of nkProcDef:
when useEffectSystem: documentRaises(n)
Expand Down Expand Up @@ -790,7 +790,7 @@ proc writeOutputJson*(d: PDoc, filename, outExt: string,
discard "fixme: error report"

proc commandDoc*() =
var ast = parseFile(gProjectMainIdx, newIdentCache())
var ast = parseFile(gProjectMainIdx.FileIndex, newIdentCache())
if ast == nil: return
var d = newDocumentor(gProjectFull, options.gConfigVars)
d.hasToc = true
Expand Down Expand Up @@ -840,7 +840,7 @@ proc commandRst2TeX*() =
commandRstAux(gProjectFull, TexExt)

proc commandJson*() =
var ast = parseFile(gProjectMainIdx, newIdentCache())
var ast = parseFile(gProjectMainIdx.FileIndex, newIdentCache())
if ast == nil: return
var d = newDocumentor(gProjectFull, options.gConfigVars)
d.hasToc = true
Expand All @@ -855,7 +855,7 @@ proc commandJson*() =
writeRope(content, getOutFile(gProjectFull, JsonExt), useWarning = false)

proc commandTags*() =
var ast = parseFile(gProjectMainIdx, newIdentCache())
var ast = parseFile(gProjectMainIdx.FileIndex, newIdentCache())
if ast == nil: return
var d = newDocumentor(gProjectFull, options.gConfigVars)
d.hasToc = true
Expand Down
5 changes: 3 additions & 2 deletions compiler/evaltempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ proc evalTemplateArgs(n: PNode, s: PSym; fromHlo: bool): PNode =
for i in 1 .. genericParams:
result.addSon n.sons[givenRegularParams + i]

# to prevent endless recursion in template instantiation
const evalTemplateLimit* = 1000
var evalTemplateCounter* = 0
# to prevent endless recursion in templates instantiation

proc wrapInComesFrom*(info: TLineInfo; sym: PSym; res: PNode): PNode =
when true:
Expand All @@ -133,7 +134,7 @@ proc wrapInComesFrom*(info: TLineInfo; sym: PSym; res: PNode): PNode =

proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; fromHlo=false): PNode =
inc(evalTemplateCounter)
if evalTemplateCounter > 100:
if evalTemplateCounter > evalTemplateLimit:
globalError(n.info, errTemplateInstantiationTooNested)
result = n

Expand Down
6 changes: 3 additions & 3 deletions compiler/filter_tmpl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const
proc newLine(p: var TTmplParser) =
llStreamWrite(p.outp, repeat(')', p.emitPar))
p.emitPar = 0
if p.info.line > int16(1): llStreamWrite(p.outp, "\n")
if p.info.line > uint16(1): llStreamWrite(p.outp, "\n")
if p.pendingExprLine:
llStreamWrite(p.outp, spaces(2))
p.pendingExprLine = false
Expand Down Expand Up @@ -212,9 +212,9 @@ proc filterTmpl*(stdin: PLLStream, filename: string, call: PNode): PLLStream =
p.x = newStringOfCap(120)
# do not process the first line which contains the directive:
if llStreamReadLine(p.inp, p.x):
p.info.line = p.info.line + int16(1)
p.info.line = p.info.line + 1'u16
while llStreamReadLine(p.inp, p.x):
p.info.line = p.info.line + int16(1)
p.info.line = p.info.line + 1'u16
parseLine(p)
newLine(p)
result = p.outp
Expand Down
2 changes: 1 addition & 1 deletion compiler/hlo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ proc applyPatterns(c: PContext, n: PNode): PNode =
assert x.kind in {nkStmtList, nkCall}
# better be safe than sorry, so check evalTemplateCounter too:
inc(evalTemplateCounter)
if evalTemplateCounter > 100:
if evalTemplateCounter > evalTemplateLimit:
globalError(n.info, errTemplateInstantiationTooNested)
# deactivate this pattern:
c.patterns[i] = nil
Expand Down
Loading

0 comments on commit 17d3c6f

Please sign in to comment.