Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
c8cb567938
6 changed files with 85 additions and 35 deletions
|
|
@ -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
|
|
||||||
if n.kind == nkIdent:
|
result = r
|
||||||
result = result[0]
|
# Transform the nkCall node back to its original form if possible
|
||||||
elif n.kind == nkExprColonExpr:
|
if n.kind == nkIdent and r.len == 1:
|
||||||
result.kind = n.kind # pragma(arg) -> pragma: arg
|
# pragma() -> pragma
|
||||||
|
result = result[0]
|
||||||
|
elif n.kind == nkExprColonExpr and r.len == 2:
|
||||||
|
# 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 =
|
||||||
|
|
|
||||||
|
|
@ -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,24 +1191,27 @@ 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]
|
||||||
while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0:
|
if x.kind in nkCallKinds and nfSem in x.flags:
|
||||||
x = x.lastSon
|
discard "already semchecked, see line marked with bug #10548"
|
||||||
if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty} and
|
else:
|
||||||
s.typ.kind notin {tyObject, tyEnum}:
|
while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0:
|
||||||
# type aliases are hard:
|
x = x.lastSon
|
||||||
var t = semTypeNode(c, x, nil)
|
if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty} and
|
||||||
assert t != nil
|
s.typ.kind notin {tyObject, tyEnum}:
|
||||||
if s.typ != nil and s.typ.kind notin {tyAlias, tySink}:
|
# type aliases are hard:
|
||||||
if t.kind in {tyProc, tyGenericInst} and not t.isMetaType:
|
var t = semTypeNode(c, x, nil)
|
||||||
assignType(s.typ, t)
|
assert t != nil
|
||||||
s.typ.id = t.id
|
if s.typ != nil and s.typ.kind notin {tyAlias, tySink}:
|
||||||
elif t.kind in {tyObject, tyEnum, tyDistinct}:
|
if t.kind in {tyProc, tyGenericInst} and not t.isMetaType:
|
||||||
assert s.typ != nil
|
assignType(s.typ, t)
|
||||||
assignType(s.typ, t)
|
s.typ.id = t.id
|
||||||
s.typ.id = t.id # same id
|
elif t.kind in {tyObject, tyEnum, tyDistinct}:
|
||||||
checkConstructedType(c.config, s.info, s.typ)
|
assert s.typ != nil
|
||||||
if s.typ.kind in {tyObject, tyTuple} and not s.typ.n.isNil:
|
assignType(s.typ, t)
|
||||||
checkForMetaFields(c, s.typ.n)
|
s.typ.id = t.id # same id
|
||||||
|
checkConstructedType(c.config, s.info, s.typ)
|
||||||
|
if s.typ.kind in {tyObject, tyTuple} and not s.typ.n.isNil:
|
||||||
|
checkForMetaFields(c, s.typ.n)
|
||||||
instAllTypeBoundOp(c, n.info)
|
instAllTypeBoundOp(c, n.info)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
8
koch.nim
8
koch.nim
|
|
@ -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!"
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ macro checkType(ex: typed; expected: string): untyped =
|
||||||
macro checkProcType(fn: typed): untyped =
|
macro checkProcType(fn: typed): untyped =
|
||||||
let fn_sym = if fn.kind == nnkProcDef: fn[0] else: fn
|
let fn_sym = if fn.kind == nnkProcDef: fn[0] else: fn
|
||||||
echo fn_sym, "; ", fn_sym.typeKind, "; ", fn_sym.getType.repr, "; ", fn_sym.getTypeImpl.repr
|
echo fn_sym, "; ", fn_sym.typeKind, "; ", fn_sym.getType.repr, "; ", fn_sym.getTypeImpl.repr
|
||||||
|
|
||||||
|
|
||||||
proc voidProc = echo "hello"
|
proc voidProc = echo "hello"
|
||||||
proc intProc(a: int, b: float): int {.checkProcType.} = 10
|
proc intProc(a: int, b: float): int {.checkProcType.} = 10
|
||||||
|
|
||||||
checkType(voidProc(), "void")
|
checkType(voidProc(), "void")
|
||||||
checkType(intProc(10, 20.0), "int")
|
checkType(intProc(10, 20.0), "int")
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue