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

This commit is contained in:
Andreas Rumpf 2019-02-18 15:23:43 +01:00
commit c8cb567938
6 changed files with 85 additions and 35 deletions

View file

@ -719,26 +719,34 @@ proc pragmaGuard(c: PContext; it: PNode; kind: TSymKind): PSym =
result = qualifiedLookUp(c, n, {checkUndeclared}) result = qualifiedLookUp(c, n, {checkUndeclared})
proc semCustomPragma(c: PContext, n: PNode): PNode = proc semCustomPragma(c: PContext, n: PNode): PNode =
var callNode: PNode
if n.kind == nkIdent: if n.kind == nkIdent:
result = newTree(nkCall, n) # pragma -> pragma()
callNode = newTree(nkCall, n)
elif n.kind == nkExprColonExpr: elif n.kind == nkExprColonExpr:
# pragma: arg -> pragma(arg) # pragma: arg -> pragma(arg)
result = newTree(nkCall, n[0], n[1]) callNode = newTree(nkCall, n[0], n[1])
elif n.kind in nkPragmaCallKinds: elif n.kind in nkPragmaCallKinds:
result = n callNode = n
else: else:
invalidPragma(c, n) invalidPragma(c, n)
return n return n
let r = c.semOverloadedCall(c, result, n, {skTemplate}, {efNoUndeclared}) let r = c.semOverloadedCall(c, callNode, n, {skTemplate}, {efNoUndeclared})
if r.isNil or sfCustomPragma notin r[0].sym.flags: if r.isNil or sfCustomPragma notin r[0].sym.flags:
invalidPragma(c, n) invalidPragma(c, n)
else: return n
result = r result = r
if n.kind == nkIdent: # Transform the nkCall node back to its original form if possible
if n.kind == nkIdent and r.len == 1:
# pragma() -> pragma
result = result[0] result = result[0]
elif n.kind == nkExprColonExpr: elif n.kind == nkExprColonExpr and r.len == 2:
result.kind = n.kind # pragma(arg) -> pragma: arg # pragma(arg) -> pragma: arg
result.kind = n.kind
proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
validPragmas: TSpecialWords, comesFromPush: bool) : bool = validPragmas: TSpecialWords, comesFromPush: bool) : bool =

View file

@ -1136,7 +1136,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
# its evaluated result here so that we don't execute it once again in the # its evaluated result here so that we don't execute it once again in the
# final pass # final pass
if a[2].kind in nkCallKinds: if a[2].kind in nkCallKinds:
a[2] = newNodeIT(nkType, a[2].info, t) incl a[2].flags, nfSem # bug #10548
if sfExportc in s.flags and s.typ.kind == tyAlias: if sfExportc in s.flags and s.typ.kind == tyAlias:
localError(c.config, name.info, "{.exportc.} not allowed for type aliases") localError(c.config, name.info, "{.exportc.} not allowed for type aliases")
let aa = a.sons[2] let aa = a.sons[2]
@ -1191,6 +1191,9 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
# compute the type's size and check for illegal recursions: # compute the type's size and check for illegal recursions:
if a.sons[1].kind == nkEmpty: if a.sons[1].kind == nkEmpty:
var x = a[2] var x = a[2]
if x.kind in nkCallKinds and nfSem in x.flags:
discard "already semchecked, see line marked with bug #10548"
else:
while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0: while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0:
x = x.lastSon x = x.lastSon
if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty} and if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty} and

View file

@ -291,13 +291,14 @@ proc boot(args: string) =
hostOs & "_" & hostCpu hostOs & "_" & hostCpu
let nimStart = findStartNim() let nimStart = findStartNim()
copyExe(nimStart, 0.thVersion)
for i in 0..2: for i in 0..2:
let defaultCommand = if useCpp: "cpp" else: "c" let defaultCommand = if useCpp: "cpp" else: "c"
let bootOptions = if args.len == 0 or args.startsWith("-"): defaultCommand else: "" let bootOptions = if args.len == 0 or args.startsWith("-"): defaultCommand else: ""
echo "iteration: ", i+1 echo "iteration: ", i+1
var extraOption = "" var extraOption = ""
var nimi = i.thVersion
if i == 0: if i == 0:
nimi = nimStart
extraOption.add " --skipUserCfg --skipParentCfg" extraOption.add " --skipUserCfg --skipParentCfg"
# The configs are skipped for bootstrap # The configs are skipped for bootstrap
# (1st iteration) to prevent newer flags from breaking bootstrap phase. # (1st iteration) to prevent newer flags from breaking bootstrap phase.
@ -307,8 +308,9 @@ proc boot(args: string) =
if version.startsWith "Nim Compiler Version 0.19.0": if version.startsWith "Nim Compiler Version 0.19.0":
extraOption.add " -d:nimBoostrapCsources0_19_0" extraOption.add " -d:nimBoostrapCsources0_19_0"
# remove this when csources get updated # remove this when csources get updated
exec i.thVersion & " $# $# $# --nimcache:$# compiler" / "nim.nim" %
[bootOptions, extraOption, args, smartNimcache] exec "$# $# $# $# --nimcache:$# compiler" / "nim.nim" %
[nimi, bootOptions, extraOption, args, smartNimcache]
if sameFileContent(output, i.thVersion): if sameFileContent(output, i.thVersion):
copyExe(output, finalDest) copyExe(output, finalDest)
echo "executables are equal: SUCCESS!" echo "executables are equal: SUCCESS!"

View file

@ -1515,7 +1515,7 @@ macro getCustomPragmaVal*(n: typed, cp: typed{nkSym}): untyped =
else: else:
let def = p[0].getImpl[3] let def = p[0].getImpl[3]
result = newTree(nnkPar) result = newTree(nnkPar)
for i in 1..<p.len: for i in 1 ..< def.len:
let key = def[i][0] let key = def[i][0]
let val = p[i] let val = p[i]
result.add newTree(nnkExprColonExpr, key, val) result.add newTree(nnkExprColonExpr, key, val)

View file

@ -38,3 +38,33 @@ block:
Club = Blub Club = Blub
static: doAssert(c == 1) static: doAssert(c == 1)
# bug #10702
type
VectorElementType = SomeNumber | bool
Vec*[N : static[int], T: VectorElementType] = object
arr*: array[N, T]
type
Vec4*[T: VectorElementType] = Vec[4,T]
Vec3*[T: VectorElementType] = Vec[3,T]
Vec2*[T: VectorElementType] = Vec[2,T]
template vecGen(U:untyped,V:typed):typed=
## ``U`` suffix
## ``V`` valType
##
type
`Vec2 U`* {.inject.} = Vec2[V]
`Vec3 U`* {.inject.} = Vec3[V]
`Vec4 U`* {.inject.} = Vec4[V]
vecGen(f, float32)
macro foobar(arg: typed): untyped =
let typ = arg.getTypeInst
doAssert typ.getImpl[^1].kind == nnkCall
var x: Vec2f
foobar(x)

View file

@ -233,3 +233,10 @@ block:
doAssert ps.first == ps[0] and ps.first == "one" doAssert ps.first == ps[0] and ps.first == "one"
doAssert ps.second == ps[1] and ps.second == 2 doAssert ps.second == ps[1] and ps.second == 2
doAssert ps.third == ps[2] and ps.third == 3.0 doAssert ps.third == ps[2] and ps.third == 3.0
# pragma with implicit&explicit generic types
block:
template fooBar[T](x: T; c: static[int] = 42; m: char) {.pragma.}
var e {.fooBar("foo", 123, 'u').}: int
doAssert(hasCustomPragma(e, fooBar))
doAssert(getCustomPragmaVal(e, fooBar).c == 123)