Merge branch 'devel' of github.com:nim-lang/Nim into devel

This commit is contained in:
Andreas Rumpf 2019-03-21 09:34:02 +01:00
commit 83c105c3a3
16 changed files with 75 additions and 25 deletions

View file

@ -20,6 +20,7 @@ proc hasNoInit(call: PNode): bool {.inline.} =
proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc, proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc,
callee, params: Rope) = callee, params: Rope) =
genLineDir(p, ri)
var pl = callee & ~"(" & params var pl = callee & ~"(" & params
# getUniqueType() is too expensive here: # getUniqueType() is too expensive here:
var typ = skipTypes(ri.sons[0].typ, abstractInst) var typ = skipTypes(ri.sons[0].typ, abstractInst)

View file

@ -2453,7 +2453,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
putIntoDest(p, d, n, genLiteral(p, n)) putIntoDest(p, d, n, genLiteral(p, n))
of nkCall, nkHiddenCallConv, nkInfix, nkPrefix, nkPostfix, nkCommand, of nkCall, nkHiddenCallConv, nkInfix, nkPrefix, nkPostfix, nkCommand,
nkCallStrLit: nkCallStrLit:
genLineDir(p, n) genLineDir(p, n) # may be redundant, it is generated in fixupCall as well
let op = n.sons[0] let op = n.sons[0]
if n.typ.isNil: if n.typ.isNil:
# discard the value: # discard the value:

View file

@ -246,8 +246,8 @@ proc cacheGetType(tab: TypeCache; sig: SigHash): Rope =
result = tab.getOrDefault(sig) result = tab.getOrDefault(sig)
proc addAbiCheck(m: BModule, t: PType, name: Rope) = proc addAbiCheck(m: BModule, t: PType, name: Rope) =
if isDefined(m.config, "checkabi"): if isDefined(m.config, "checkabi") and (let size = getSize(m.config, t); size != szUnknownSize):
addf(m.s[cfsTypeInfo], "NIM_CHECK_SIZE($1, $2);$n", [name, rope(getSize(m.config, t))]) addf(m.s[cfsTypeInfo], "NIM_CHECK_SIZE($1, $2);$n", [name, rope(size)])
proc ccgIntroducedPtr(conf: ConfigRef; s: PSym): bool = proc ccgIntroducedPtr(conf: ConfigRef; s: PSym): bool =
var pt = skipTypes(s.typ, typedescInst) var pt = skipTypes(s.typ, typedescInst)

View file

@ -344,9 +344,9 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe
if procTokenPos == tokenPos-2 and procLink != nil: if procTokenPos == tokenPos-2 and procLink != nil:
dispA(d.conf, result, "<a href=\"#$2\"><span class=\"Identifier\">$1</span></a>", dispA(d.conf, result, "<a href=\"#$2\"><span class=\"Identifier\">$1</span></a>",
"\\spanIdentifier{$1}", [rope(esc(d.target, literal)), procLink]) "\\spanIdentifier{$1}", [rope(esc(d.target, literal)), procLink])
elif s != nil and s.kind == skType and sfExported in s.flags and elif s != nil and s.kind in {skType, skVar, skLet, skConst} and
s.owner != nil and belongsToPackage(d.conf, s.owner) and sfExported in s.flags and s.owner != nil and
d.target == outHtml: belongsToPackage(d.conf, s.owner) and d.target == outHtml:
let external = externalDep(d, s.owner) let external = externalDep(d, s.owner)
result.addf "<a href=\"$1#$2\"><span class=\"Identifier\">$3</span></a>", result.addf "<a href=\"$1#$2\"><span class=\"Identifier\">$3</span></a>",
[rope changeFileExt(external, "html"), rope literal, [rope changeFileExt(external, "html"), rope literal,

View file

@ -400,7 +400,8 @@ proc exprList(p: var TParser, endTok: TTokType, result: PNode) =
proc exprColonEqExprListAux(p: var TParser, endTok: TTokType, result: PNode) = proc exprColonEqExprListAux(p: var TParser, endTok: TTokType, result: PNode) =
assert(endTok in {tkCurlyRi, tkCurlyDotRi, tkBracketRi, tkParRi}) assert(endTok in {tkCurlyRi, tkCurlyDotRi, tkBracketRi, tkParRi})
getTok(p) getTok(p)
optInd(p, result) flexComment(p, result)
optPar(p)
# progress guaranteed # progress guaranteed
while p.tok.tokType != endTok and p.tok.tokType != tkEof: while p.tok.tokType != endTok and p.tok.tokType != tkEof:
var a = exprColonEqExpr(p) var a = exprColonEqExpr(p)
@ -2085,7 +2086,7 @@ proc parseConstant(p: var TParser): PNode =
addSon(result, p.emptyNode) addSon(result, p.emptyNode)
eat(p, tkEquals) eat(p, tkEquals)
optInd(p, result) optInd(p, result)
addSon(result, parseExpr(p)) addSon(result, parseStmtListExpr(p))
indAndComment(p, result) indAndComment(p, result)
proc parseBind(p: var TParser, k: TNodeKind): PNode = proc parseBind(p: var TParser, k: TNodeKind): PNode =

View file

@ -1217,8 +1217,14 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
else: else:
put(g, tkDistinct, "distinct") put(g, tkDistinct, "distinct")
of nkTypeDef: of nkTypeDef:
gsub(g, n, 0) if n.sons[0].kind == nkPragmaExpr:
gsub(g, n, 1) # generate pragma after generic
gsub(g, n.sons[0], 0)
gsub(g, n, 1)
gsub(g, n.sons[0], 1)
else:
gsub(g, n, 0)
gsub(g, n, 1)
put(g, tkSpaces, Space) put(g, tkSpaces, Space)
if n.len > 2 and n.sons[2].kind != nkEmpty: if n.len > 2 and n.sons[2].kind != nkEmpty:
putWithSpace(g, tkEquals, "=") putWithSpace(g, tkEquals, "=")

View file

@ -17,7 +17,7 @@ const
byteExcess* = 128 # we use excess-K for immediates byteExcess* = 128 # we use excess-K for immediates
wordExcess* = 32768 wordExcess* = 32768
MaxLoopIterations* = 3_000_000 # max iterations of all loops MaxLoopIterations* = 10_000_000 # max iterations of all loops
type type

View file

@ -442,7 +442,7 @@ proc extractOptions(pattern: string): tuple[pattern: string, flags: int, study:
# }}} # }}}
proc destroyRegex(pattern: Regex) = proc destroyRegex(pattern: Regex) =
pcre.free(pattern.pcreObj) pcre.free_substring(cast[cstring](pattern.pcreObj))
pattern.pcreObj = nil pattern.pcreObj = nil
if pattern.pcreExtra != nil: if pattern.pcreExtra != nil:
pcre.free_study(pattern.pcreExtra) pcre.free_study(pattern.pcreExtra)

View file

@ -60,9 +60,12 @@ proc rawCompile(pattern: string, flags: cint): ptr Pcre =
raiseInvalidRegex($msg & "\n" & pattern & "\n" & spaces(offset) & "^\n") raiseInvalidRegex($msg & "\n" & pattern & "\n" & spaces(offset) & "^\n")
proc finalizeRegEx(x: Regex) = proc finalizeRegEx(x: Regex) =
pcre.free(x.h) # XXX This is a hack, but PCRE does not export its "free" function properly.
# Sigh. The hack relies on PCRE's implementation (see ``pcre_get.c``).
# Fortunately the implementation is unlikely to change.
pcre.free_substring(cast[cstring](x.h))
if not isNil(x.e): if not isNil(x.e):
pcre.free_study(x.e) pcre.free_substring(cast[cstring](x.e))
proc re*(s: string, flags = {reStudy}): Regex = proc re*(s: string, flags = {reStudy}): Regex =
## Constructor of regular expressions. ## Constructor of regular expressions.

View file

@ -35,6 +35,7 @@
## `execShellCmd proc <#execShellCmd,string>`_ ## `execShellCmd proc <#execShellCmd,string>`_
## * `parseopt module <parseopt.html>`_ for command-line parser beyond ## * `parseopt module <parseopt.html>`_ for command-line parser beyond
## `parseCmdLine proc <#parseCmdLine,string>`_ ## `parseCmdLine proc <#parseCmdLine,string>`_
## * `uri module <uri.html>`_
## * `distros module <distros.html>`_ ## * `distros module <distros.html>`_
## * `dynlib module <dynlib.html>`_ ## * `dynlib module <dynlib.html>`_
## * `streams module <streams.html>`_ ## * `streams module <streams.html>`_
@ -115,13 +116,15 @@ proc joinPath*(head, tail: string): string {.
## ##
## If `head` is the empty string, `tail` is returned. If `tail` is the empty ## If `head` is the empty string, `tail` is returned. If `tail` is the empty
## string, `head` is returned with a trailing path separator. If `tail` starts ## string, `head` is returned with a trailing path separator. If `tail` starts
## with a path separator it will be removed when concatenated to `head`. Other ## with a path separator it will be removed when concatenated to `head`.
## path separators not located on boundaries won't be modified. ## Path separators will be normalized.
## ##
## See also: ## See also:
## * `joinPath(varargs) proc <#joinPath,varargs[string]>`_ ## * `joinPath(varargs) proc <#joinPath,varargs[string]>`_
## * `/ proc <#/,string,string>`_ ## * `/ proc <#/,string,string>`_
## * `splitPath proc <#splitPath,string>`_ ## * `splitPath proc <#splitPath,string>`_
## * `uri.combine proc <uri.html#combine,Uri,Uri>`_
## * `uri./ proc <uri.html#/,Uri,string>`_
runnableExamples: runnableExamples:
when defined(posix): when defined(posix):
assert joinPath("usr", "lib") == "usr/lib" assert joinPath("usr", "lib") == "usr/lib"
@ -186,6 +189,8 @@ proc `/`*(head, tail: string): string {.noSideEffect.} =
## * `joinPath(head, tail) proc <#joinPath,string,string>`_ ## * `joinPath(head, tail) proc <#joinPath,string,string>`_
## * `joinPath(varargs) proc <#joinPath,varargs[string]>`_ ## * `joinPath(varargs) proc <#joinPath,varargs[string]>`_
## * `splitPath proc <#splitPath,string>`_ ## * `splitPath proc <#splitPath,string>`_
## * `uri.combine proc <uri.html#combine,Uri,Uri>`_
## * `uri./ proc <uri.html#/,Uri,string>`_
runnableExamples: runnableExamples:
when defined(posix): when defined(posix):
assert "usr" / "" == "usr/" assert "usr" / "" == "usr/"

View file

@ -29,8 +29,7 @@ const
nativeStackTraceSupported = false nativeStackTraceSupported = false
hasSomeStackTrace = false hasSomeStackTrace = false
proc quitOrDebug() {.inline.} = proc quitOrDebug() {.noreturn, importc: "abort", header: "<stdlib.h>", nodecl.}
quit(1)
proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} = proc raiseException(e: ref Exception, ename: cstring) {.compilerRtl.} =
sysFatal(ReraiseError, "exception handling is not available") sysFatal(ReraiseError, "exception handling is not available")

View file

@ -38,10 +38,15 @@ proc showErrorMessage(data: cstring) {.gcsafe.} =
writeToStdErr(data) writeToStdErr(data)
proc quitOrDebug() {.inline.} = proc quitOrDebug() {.inline.} =
when not defined(endb): when defined(endb):
quit(1)
else:
endbStep() # call the debugger endbStep() # call the debugger
elif not defined(nodejs) and not defined(nimscript):
when nimvm:
quit(1)
else:
c_abort()
else:
quit(1)
proc chckIndx(i, a, b: int): int {.inline, compilerproc, benign.} proc chckIndx(i, a, b: int): int {.inline, compilerproc, benign.}
proc chckRange(i, a, b: int): int {.inline, compilerproc, benign.} proc chckRange(i, a, b: int): int {.inline, compilerproc, benign.}

View file

@ -341,8 +341,6 @@ proc compile2*(pattern: cstring,
erroffset: ptr cint, erroffset: ptr cint,
tableptr: pointer): ptr Pcre tableptr: pointer): ptr Pcre
proc free*(p: ptr Pcre)
proc config*(what: cint, proc config*(what: cint,
where: pointer): cint where: pointer): cint

View file

@ -907,7 +907,7 @@ The enum B.
<h1><a class="toc-backref" href="#8">Vars</a></h1> <h1><a class="toc-backref" href="#8">Vars</a></h1>
<dl class="item"> <dl class="item">
<a id="aVariable"></a> <a id="aVariable"></a>
<dt><pre><span class="Identifier">aVariable</span><span class="Other">:</span> <span class="Identifier">array</span><span class="Other">[</span><span class="DecNumber">1</span><span class="Other">,</span> <span class="Identifier">int</span><span class="Other">]</span></pre></dt> <dt><pre><a href="testproject.html#aVariable"><span class="Identifier">aVariable</span></a><span class="Other">:</span> <span class="Identifier">array</span><span class="Other">[</span><span class="DecNumber">1</span><span class="Other">,</span> <span class="Identifier">int</span><span class="Other">]</span></pre></dt>
<dd> <dd>

View file

@ -0,0 +1,18 @@
discard """
outputsub: '''tcall_with_default_arg.nim(16) anotherFoo'''
exitcode: 1
"""
# issue: #5604
proc fail() =
raise newException(ValueError, "dead")
proc getDefault(): int = 123
proc bar*(arg1: int = getDefault()) =
fail()
proc anotherFoo(input: string) =
bar()
anotherFoo("123")

View file

@ -58,4 +58,18 @@ block:
var y = 2 var y = 2
echo "block expression works" echo "block expression works"
y*y y*y
doAssert x == 4 doAssert x == 4
# bug 10861
macro foo(a: untyped): untyped =
a
let c1 = foo:
1 + 1
const c2 = foo:
1 + 1
const c3 =
foo: 1 + 1