Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
f540a3683f
17 changed files with 218 additions and 43 deletions
|
|
@ -601,8 +601,18 @@ proc generateHeaders(m: BModule) =
|
||||||
addf(m.s[cfsHeaders], "#include \"$1\"$N", [rope(it)])
|
addf(m.s[cfsHeaders], "#include \"$1\"$N", [rope(it)])
|
||||||
else:
|
else:
|
||||||
addf(m.s[cfsHeaders], "#include $1$N", [rope(it)])
|
addf(m.s[cfsHeaders], "#include $1$N", [rope(it)])
|
||||||
|
add(m.s[cfsHeaders], "#undef LANGUAGE_C" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef MIPSEB" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef MIPSEL" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef PPC" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef R3000" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef R4000" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef i386" & tnl)
|
||||||
add(m.s[cfsHeaders], "#undef linux" & tnl)
|
add(m.s[cfsHeaders], "#undef linux" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef mips" & tnl)
|
||||||
add(m.s[cfsHeaders], "#undef near" & tnl)
|
add(m.s[cfsHeaders], "#undef near" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef powerpc" & tnl)
|
||||||
|
add(m.s[cfsHeaders], "#undef unix" & tnl)
|
||||||
|
|
||||||
proc initFrame(p: BProc, procname, filename: Rope): Rope =
|
proc initFrame(p: BProc, procname, filename: Rope): Rope =
|
||||||
discard cgsym(p.module, "nimFrame")
|
discard cgsym(p.module, "nimFrame")
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,8 @@ proc isCastable(dst, src: PType): bool =
|
||||||
result = false
|
result = false
|
||||||
elif typeAllowed(dst, skParam) != nil:
|
elif typeAllowed(dst, skParam) != nil:
|
||||||
result = false
|
result = false
|
||||||
|
elif dst.kind == tyProc and dst.callConv == ccClosure:
|
||||||
|
result = src.kind == tyProc and src.callConv == ccClosure
|
||||||
else:
|
else:
|
||||||
result = (dstSize >= srcSize) or
|
result = (dstSize >= srcSize) or
|
||||||
(skipTypes(dst, abstractInst).kind in IntegralTypes) or
|
(skipTypes(dst, abstractInst).kind in IntegralTypes) or
|
||||||
|
|
@ -227,7 +229,10 @@ proc semCast(c: PContext, n: PNode): PNode =
|
||||||
if tfHasMeta in targetType.flags:
|
if tfHasMeta in targetType.flags:
|
||||||
localError(n.sons[0].info, errCastToANonConcreteType, $targetType)
|
localError(n.sons[0].info, errCastToANonConcreteType, $targetType)
|
||||||
if not isCastable(targetType, castedExpr.typ):
|
if not isCastable(targetType, castedExpr.typ):
|
||||||
localError(n.info, errExprCannotBeCastToX, $targetType)
|
let tar = $targetType
|
||||||
|
let alt = typeToString(targetType, preferDesc)
|
||||||
|
let msg = if tar != alt: tar & "=" & alt else: tar
|
||||||
|
localError(n.info, errExprCannotBeCastToX, msg)
|
||||||
result = newNodeI(nkCast, n.info)
|
result = newNodeI(nkCast, n.info)
|
||||||
result.typ = targetType
|
result.typ = targetType
|
||||||
addSon(result, copyTree(n.sons[0]))
|
addSon(result, copyTree(n.sons[0]))
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,8 @@ proc sameInstantiation(a, b: TInstantiation): bool =
|
||||||
if a.concreteTypes.len == b.concreteTypes.len:
|
if a.concreteTypes.len == b.concreteTypes.len:
|
||||||
for i in 0..a.concreteTypes.high:
|
for i in 0..a.concreteTypes.high:
|
||||||
if not compareTypes(a.concreteTypes[i], b.concreteTypes[i],
|
if not compareTypes(a.concreteTypes[i], b.concreteTypes[i],
|
||||||
flags = {ExactTypeDescValues}): return
|
flags = {ExactTypeDescValues,
|
||||||
|
ExactGcSafety}): return
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc genericCacheGet(genericSym: PSym, entry: TInstantiation;
|
proc genericCacheGet(genericSym: PSym, entry: TInstantiation;
|
||||||
|
|
|
||||||
|
|
@ -218,12 +218,11 @@ proc listGcUnsafety(s: PSym; onlyWarning: bool; cycleCheck: var IntSet) =
|
||||||
message(s.info, msgKind,
|
message(s.info, msgKind,
|
||||||
"'$#' is not GC-safe as it calls '$#'" %
|
"'$#' is not GC-safe as it calls '$#'" %
|
||||||
[s.name.s, u.name.s])
|
[s.name.s, u.name.s])
|
||||||
of skParam:
|
of skParam, skForVar:
|
||||||
message(s.info, msgKind,
|
message(s.info, msgKind,
|
||||||
"'$#' is not GC-safe as it performs an indirect call via '$#'" %
|
"'$#' is not GC-safe as it performs an indirect call via '$#'" %
|
||||||
[s.name.s, u.name.s])
|
[s.name.s, u.name.s])
|
||||||
else:
|
else:
|
||||||
internalAssert u.kind == skUnknown
|
|
||||||
message(u.info, msgKind,
|
message(u.info, msgKind,
|
||||||
"'$#' is not GC-safe as it performs an indirect call here" % s.name.s)
|
"'$#' is not GC-safe as it performs an indirect call here" % s.name.s)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,7 @@ proc instCopyType*(cl: var TReplTypeVars, t: PType): PType =
|
||||||
proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
# tyGenericInvocation[A, tyGenericInvocation[A, B]]
|
# tyGenericInvocation[A, tyGenericInvocation[A, B]]
|
||||||
# is difficult to handle:
|
# is difficult to handle:
|
||||||
|
const eqFlags = eqTypeFlags + {tfGcSafe}
|
||||||
var body = t.sons[0]
|
var body = t.sons[0]
|
||||||
if body.kind != tyGenericBody: internalError(cl.info, "no generic body")
|
if body.kind != tyGenericBody: internalError(cl.info, "no generic body")
|
||||||
var header: PType = t
|
var header: PType = t
|
||||||
|
|
@ -252,7 +253,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
else:
|
else:
|
||||||
result = searchInstTypes(t)
|
result = searchInstTypes(t)
|
||||||
|
|
||||||
if result != nil and eqTypeFlags*result.flags == eqTypeFlags*t.flags: return
|
if result != nil and eqFlags*result.flags == eqFlags*t.flags: return
|
||||||
for i in countup(1, sonsLen(t) - 1):
|
for i in countup(1, sonsLen(t) - 1):
|
||||||
var x = t.sons[i]
|
var x = t.sons[i]
|
||||||
if x.kind in {tyGenericParam}:
|
if x.kind in {tyGenericParam}:
|
||||||
|
|
@ -267,7 +268,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
if header != t:
|
if header != t:
|
||||||
# search again after first pass:
|
# search again after first pass:
|
||||||
result = searchInstTypes(header)
|
result = searchInstTypes(header)
|
||||||
if result != nil and eqTypeFlags*result.flags == eqTypeFlags*t.flags: return
|
if result != nil and eqFlags*result.flags == eqFlags*t.flags: return
|
||||||
else:
|
else:
|
||||||
header = instCopyType(cl, t)
|
header = instCopyType(cl, t)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,9 @@ proc getProcHeader*(sym: PSym; prefer: TPreferedDesc = preferName): string =
|
||||||
add(result, ')')
|
add(result, ')')
|
||||||
if n.sons[0].typ != nil:
|
if n.sons[0].typ != nil:
|
||||||
result.add(": " & typeToString(n.sons[0].typ, prefer))
|
result.add(": " & typeToString(n.sons[0].typ, prefer))
|
||||||
|
result.add "[declared in "
|
||||||
|
result.add($sym.info)
|
||||||
|
result.add "]"
|
||||||
|
|
||||||
proc elemType*(t: PType): PType =
|
proc elemType*(t: PType): PType =
|
||||||
assert(t != nil)
|
assert(t != nil)
|
||||||
|
|
@ -688,6 +691,7 @@ type
|
||||||
ExactTypeDescValues
|
ExactTypeDescValues
|
||||||
ExactGenericParams
|
ExactGenericParams
|
||||||
ExactConstraints
|
ExactConstraints
|
||||||
|
ExactGcSafety
|
||||||
AllowCommonBase
|
AllowCommonBase
|
||||||
|
|
||||||
TTypeCmpFlags* = set[TTypeCmpFlag]
|
TTypeCmpFlags* = set[TTypeCmpFlag]
|
||||||
|
|
@ -976,6 +980,8 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
cycleCheck()
|
cycleCheck()
|
||||||
if a.kind == tyUserTypeClass and a.n != nil: return a.n == b.n
|
if a.kind == tyUserTypeClass and a.n != nil: return a.n == b.n
|
||||||
result = sameChildrenAux(a, b, c) and sameFlags(a, b)
|
result = sameChildrenAux(a, b, c) and sameFlags(a, b)
|
||||||
|
if result and ExactGcSafety in c.flags:
|
||||||
|
result = a.flags * {tfThread} == b.flags * {tfThread}
|
||||||
if result and a.kind == tyProc:
|
if result and a.kind == tyProc:
|
||||||
result = ((IgnoreCC in c.flags) or a.callConv == b.callConv) and
|
result = ((IgnoreCC in c.flags) or a.callConv == b.callConv) and
|
||||||
((ExactConstraints notin c.flags) or sameConstraints(a.n, b.n))
|
((ExactConstraints notin c.flags) or sameConstraints(a.n, b.n))
|
||||||
|
|
|
||||||
12
koch.nim
12
koch.nim
|
|
@ -470,6 +470,17 @@ proc temp(args: string) =
|
||||||
copyExe(output, finalDest)
|
copyExe(output, finalDest)
|
||||||
if programArgs.len > 0: exec(finalDest & " " & programArgs)
|
if programArgs.len > 0: exec(finalDest & " " & programArgs)
|
||||||
|
|
||||||
|
proc xtemp(cmd: string) =
|
||||||
|
let d = getAppDir()
|
||||||
|
copyExe(d / "bin" / "nim".exe, d / "bin" / "nim_backup".exe)
|
||||||
|
try:
|
||||||
|
withDir(d):
|
||||||
|
temp"-d:debug"
|
||||||
|
copyExe(d / "bin" / "nim_temp".exe, d / "bin" / "nim".exe)
|
||||||
|
exec(cmd)
|
||||||
|
finally:
|
||||||
|
copyExe(d / "bin" / "nim_backup".exe, d / "bin" / "nim".exe)
|
||||||
|
|
||||||
proc pushCsources() =
|
proc pushCsources() =
|
||||||
if not dirExists("../csources/.git"):
|
if not dirExists("../csources/.git"):
|
||||||
quit "[Error] no csources git repository found"
|
quit "[Error] no csources git repository found"
|
||||||
|
|
@ -545,6 +556,7 @@ of cmdArgument:
|
||||||
of "testinstall": testUnixInstall()
|
of "testinstall": testUnixInstall()
|
||||||
of "test", "tests": tests(op.cmdLineRest)
|
of "test", "tests": tests(op.cmdLineRest)
|
||||||
of "temp": temp(op.cmdLineRest)
|
of "temp": temp(op.cmdLineRest)
|
||||||
|
of "xtemp": xtemp(op.cmdLineRest)
|
||||||
of "winrelease": winRelease()
|
of "winrelease": winRelease()
|
||||||
of "wintools": bundleWinTools()
|
of "wintools": bundleWinTools()
|
||||||
of "nimble": buildNimble(existsDir(".git"))
|
of "nimble": buildNimble(existsDir(".git"))
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ proc parseProtocol(protocol: string): tuple[orig: string, major, minor: int] =
|
||||||
i.inc protocol.parseInt(result.minor, i)
|
i.inc protocol.parseInt(result.minor, i)
|
||||||
|
|
||||||
proc sendStatus(client: AsyncSocket, status: string): Future[void] =
|
proc sendStatus(client: AsyncSocket, status: string): Future[void] =
|
||||||
client.send("HTTP/1.1 " & status & "\c\L")
|
client.send("HTTP/1.1 " & status & "\c\L\c\L")
|
||||||
|
|
||||||
proc processClient(client: AsyncSocket, address: string,
|
proc processClient(client: AsyncSocket, address: string,
|
||||||
callback: proc (request: Request):
|
callback: proc (request: Request):
|
||||||
|
|
|
||||||
|
|
@ -139,9 +139,14 @@ proc hash*(x: cstring): Hash =
|
||||||
## efficient hashing of null-terminated strings
|
## efficient hashing of null-terminated strings
|
||||||
var h: Hash = 0
|
var h: Hash = 0
|
||||||
var i = 0
|
var i = 0
|
||||||
while x[i] != 0.char:
|
when defined(js):
|
||||||
h = h !& ord(x[i])
|
while i < x.len:
|
||||||
inc i
|
h = h !& ord(x[i])
|
||||||
|
inc i
|
||||||
|
else:
|
||||||
|
while x[i] != 0.char:
|
||||||
|
h = h !& ord(x[i])
|
||||||
|
inc i
|
||||||
result = !$h
|
result = !$h
|
||||||
|
|
||||||
proc hash*(sBuf: string, sPos, ePos: int): Hash =
|
proc hash*(sBuf: string, sPos, ePos: int): Hash =
|
||||||
|
|
|
||||||
|
|
@ -149,26 +149,41 @@ proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo$1".} =
|
||||||
## retrieves the rest of the command line that has not been parsed yet.
|
## retrieves the rest of the command line that has not been parsed yet.
|
||||||
result = strip(substr(p.cmd, p.pos, len(p.cmd) - 1)).TaintedString
|
result = strip(substr(p.cmd, p.pos, len(p.cmd) - 1)).TaintedString
|
||||||
|
|
||||||
|
iterator getopt*(p: var OptParser): tuple[kind: CmdLineKind, key, val: TaintedString] =
|
||||||
|
## This is an convenience iterator for iterating over the given OptParser object.
|
||||||
|
## Example:
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var p = initOptParser("--left --debug:3 -l=4 -r:2")
|
||||||
|
## for kind, key, val in p.getopt():
|
||||||
|
## case kind
|
||||||
|
## of cmdArgument:
|
||||||
|
## filename = key
|
||||||
|
## of cmdLongOption, cmdShortOption:
|
||||||
|
## case key
|
||||||
|
## of "help", "h": writeHelp()
|
||||||
|
## of "version", "v": writeVersion()
|
||||||
|
## of cmdEnd: assert(false) # cannot happen
|
||||||
|
## if filename == "":
|
||||||
|
## # no filename has been given, so we show the help:
|
||||||
|
## writeHelp()
|
||||||
|
p.pos = 0
|
||||||
|
while true:
|
||||||
|
next(p)
|
||||||
|
if p.kind == cmdEnd: break
|
||||||
|
yield (p.kind, p.key, p.val)
|
||||||
|
|
||||||
when declared(initOptParser):
|
when declared(initOptParser):
|
||||||
iterator getopt*(): tuple[kind: CmdLineKind, key, val: TaintedString] =
|
iterator getopt*(): tuple[kind: CmdLineKind, key, val: TaintedString] =
|
||||||
## This is an convenience iterator for iterating over the command line.
|
## This is an convenience iterator for iterating over the command line arguments.
|
||||||
## This uses the OptParser object. Example:
|
## This create a new OptParser object.
|
||||||
|
## See above for a more detailed example
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## var
|
|
||||||
## filename = ""
|
|
||||||
## for kind, key, val in getopt():
|
## for kind, key, val in getopt():
|
||||||
## case kind
|
## # this will iterate over all arguments passed to the cmdline.
|
||||||
## of cmdArgument:
|
## continue
|
||||||
## filename = key
|
##
|
||||||
## of cmdLongOption, cmdShortOption:
|
|
||||||
## case key
|
|
||||||
## of "help", "h": writeHelp()
|
|
||||||
## of "version", "v": writeVersion()
|
|
||||||
## of cmdEnd: assert(false) # cannot happen
|
|
||||||
## if filename == "":
|
|
||||||
## # no filename has been given, so we show the help:
|
|
||||||
## writeHelp()
|
|
||||||
var p = initOptParser()
|
var p = initOptParser()
|
||||||
while true:
|
while true:
|
||||||
next(p)
|
next(p)
|
||||||
|
|
|
||||||
|
|
@ -123,26 +123,41 @@ type
|
||||||
|
|
||||||
{.deprecated: [TGetoptResult: GetoptResult].}
|
{.deprecated: [TGetoptResult: GetoptResult].}
|
||||||
|
|
||||||
|
iterator getopt*(p: var OptParser): GetoptResult =
|
||||||
|
## This is an convenience iterator for iterating over the given OptParser object.
|
||||||
|
## Example:
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var p = initOptParser("--left --debug:3 -l=4 -r:2")
|
||||||
|
## for kind, key, val in p.getopt():
|
||||||
|
## case kind
|
||||||
|
## of cmdArgument:
|
||||||
|
## filename = key
|
||||||
|
## of cmdLongOption, cmdShortOption:
|
||||||
|
## case key
|
||||||
|
## of "help", "h": writeHelp()
|
||||||
|
## of "version", "v": writeVersion()
|
||||||
|
## of cmdEnd: assert(false) # cannot happen
|
||||||
|
## if filename == "":
|
||||||
|
## # no filename has been given, so we show the help:
|
||||||
|
## writeHelp()
|
||||||
|
p.pos = 0
|
||||||
|
while true:
|
||||||
|
next(p)
|
||||||
|
if p.kind == cmdEnd: break
|
||||||
|
yield (p.kind, p.key, p.val)
|
||||||
|
|
||||||
when declared(paramCount):
|
when declared(paramCount):
|
||||||
iterator getopt*(): GetoptResult =
|
iterator getopt*(): GetoptResult =
|
||||||
## This is an convenience iterator for iterating over the command line.
|
## This is an convenience iterator for iterating over the command line arguments.
|
||||||
## This uses the OptParser object. Example:
|
## This create a new OptParser object.
|
||||||
|
## See above for a more detailed example
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## var
|
|
||||||
## filename = ""
|
|
||||||
## for kind, key, val in getopt():
|
## for kind, key, val in getopt():
|
||||||
## case kind
|
## # this will iterate over all arguments passed to the cmdline.
|
||||||
## of cmdArgument:
|
## continue
|
||||||
## filename = key
|
##
|
||||||
## of cmdLongOption, cmdShortOption:
|
|
||||||
## case key
|
|
||||||
## of "help", "h": writeHelp()
|
|
||||||
## of "version", "v": writeVersion()
|
|
||||||
## of cmdEnd: assert(false) # cannot happen
|
|
||||||
## if filename == "":
|
|
||||||
## # no filename has been given, so we show the help:
|
|
||||||
## writeHelp()
|
|
||||||
var p = initOptParser()
|
var p = initOptParser()
|
||||||
while true:
|
while true:
|
||||||
next(p)
|
next(p)
|
||||||
|
|
|
||||||
|
|
@ -255,12 +255,21 @@ elif defined(gogc):
|
||||||
next_gc: uint64 # next GC (in heap_alloc time)
|
next_gc: uint64 # next GC (in heap_alloc time)
|
||||||
last_gc: uint64 # last GC (in absolute time)
|
last_gc: uint64 # last GC (in absolute time)
|
||||||
pause_total_ns: uint64
|
pause_total_ns: uint64
|
||||||
pause_ns: array[256, uint64]
|
pause_ns: array[256, uint64] # circular buffer of recent gc pause lengths
|
||||||
|
pause_end: array[256, uint64] # circular buffer of recent gc end times (nanoseconds since 1970)
|
||||||
numgc: uint32
|
numgc: uint32
|
||||||
|
numforcedgc: uint32 # number of user-forced GCs
|
||||||
|
gc_cpu_fraction: float64 # fraction of CPU time used by GC
|
||||||
enablegc: cbool
|
enablegc: cbool
|
||||||
debuggc: cbool
|
debuggc: cbool
|
||||||
# Statistics about allocation size classes.
|
# Statistics about allocation size classes.
|
||||||
by_size: array[goNumSizeClasses, goMStats_inner_struct]
|
by_size: array[goNumSizeClasses, goMStats_inner_struct]
|
||||||
|
# Statistics below here are not exported to MemStats directly.
|
||||||
|
tinyallocs: uint64 # number of tiny allocations that didn't cause actual allocation; not exported to go directly
|
||||||
|
gc_trigger: uint64
|
||||||
|
heap_live: uint64
|
||||||
|
heap_scan: uint64
|
||||||
|
heap_marked: uint64
|
||||||
|
|
||||||
proc goRuntime_ReadMemStats(a2: ptr goMStats) {.cdecl,
|
proc goRuntime_ReadMemStats(a2: ptr goMStats) {.cdecl,
|
||||||
importc: "runtime_ReadMemStats",
|
importc: "runtime_ReadMemStats",
|
||||||
|
|
|
||||||
17
tests/generics/tproctypecache_falsepositive.nim
Normal file
17
tests/generics/tproctypecache_falsepositive.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
import asyncdispatch
|
||||||
|
|
||||||
|
type
|
||||||
|
Callback = proc() {.closure, gcsafe.}
|
||||||
|
GameState = ref object
|
||||||
|
playerChangeHandlers: seq[Callback]
|
||||||
|
|
||||||
|
#proc dummy() =
|
||||||
|
# var x = newSeq[proc() {.cdecl, gcsafe.}]()
|
||||||
|
|
||||||
|
proc newGameState(): GameState =
|
||||||
|
result = GameState(
|
||||||
|
playerChangeHandlers: newSeq[Callback]() # this fails
|
||||||
|
)
|
||||||
|
|
||||||
|
#dummy()
|
||||||
23
tests/misc/tcast.nim
Normal file
23
tests/misc/tcast.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
Hello World
|
||||||
|
Hello World'''
|
||||||
|
"""
|
||||||
|
type MyProc = proc() {.cdecl.}
|
||||||
|
type MyProc2 = proc() {.nimcall.}
|
||||||
|
type MyProc3 = proc() #{.closure.} is implicit
|
||||||
|
|
||||||
|
proc testProc() = echo "Hello World"
|
||||||
|
|
||||||
|
proc callPointer(p: pointer) =
|
||||||
|
# can cast to proc(){.cdecl.}
|
||||||
|
let ffunc0 = cast[MyProc](p)
|
||||||
|
# can cast to proc(){.nimcall.}
|
||||||
|
let ffunc1 = cast[MyProc2](p)
|
||||||
|
# cannot cast to proc(){.closure.}
|
||||||
|
doAssert(not compiles(cast[MyProc3](p)))
|
||||||
|
|
||||||
|
ffunc0()
|
||||||
|
ffunc1()
|
||||||
|
|
||||||
|
callPointer(cast[pointer](testProc))
|
||||||
57
tests/misc/tparseopt.nim
Normal file
57
tests/misc/tparseopt.nim
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
discard """
|
||||||
|
file: "tparseopt.nim"
|
||||||
|
output: '''
|
||||||
|
parseopt
|
||||||
|
first round
|
||||||
|
kind: cmdLongOption key:val -- left:
|
||||||
|
second round
|
||||||
|
kind: cmdLongOption key:val -- left:
|
||||||
|
kind: cmdLongOption key:val -- debug:3
|
||||||
|
kind: cmdShortOption key:val -- l:4
|
||||||
|
kind: cmdShortOption key:val -- r:2
|
||||||
|
parseopt2
|
||||||
|
first round
|
||||||
|
kind: cmdLongOption key:val -- left:
|
||||||
|
second round
|
||||||
|
kind: cmdLongOption key:val -- left:
|
||||||
|
kind: cmdLongOption key:val -- debug:3
|
||||||
|
kind: cmdShortOption key:val -- l:4
|
||||||
|
kind: cmdShortOption key:val -- r:2'''
|
||||||
|
"""
|
||||||
|
from parseopt import nil
|
||||||
|
from parseopt2 import nil
|
||||||
|
|
||||||
|
|
||||||
|
block:
|
||||||
|
echo "parseopt"
|
||||||
|
for kind, key, val in parseopt.getopt():
|
||||||
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
||||||
|
# pass custom cmdline arguments
|
||||||
|
echo "first round"
|
||||||
|
var argv = "--left --debug:3 -l=4 -r:2"
|
||||||
|
var p = parseopt.initOptParser(argv)
|
||||||
|
for kind, key, val in parseopt.getopt(p):
|
||||||
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
break
|
||||||
|
# reset getopt iterator and check arguments are returned correctly.
|
||||||
|
echo "second round"
|
||||||
|
for kind, key, val in parseopt.getopt(p):
|
||||||
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
||||||
|
block:
|
||||||
|
echo "parseopt2"
|
||||||
|
for kind, key, val in parseopt2.getopt():
|
||||||
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
||||||
|
# pass custom cmdline arguments
|
||||||
|
echo "first round"
|
||||||
|
var argv: seq[string] = @["--left", "--debug:3", "-l=4", "-r:2"]
|
||||||
|
var p = parseopt2.initOptParser(argv)
|
||||||
|
for kind, key, val in parseopt2.getopt(p):
|
||||||
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
break
|
||||||
|
# reset getopt iterator and check arguments are returned correctly.
|
||||||
|
echo "second round"
|
||||||
|
for kind, key, val in parseopt2.getopt(p):
|
||||||
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
line: 8
|
line: 8
|
||||||
errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)' has non-public forward declaration in "
|
errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)[declared in tmismatchedvisibility.nim(6,5)]' has non-public forward declaration in "
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc foo(a: int): int
|
proc foo(a: int): int
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
nimout: '''
|
nimout: '''
|
||||||
compile start
|
compile start
|
||||||
tused.nim(15, 8) Hint: 'tused.echoSub(a: int, b: int)' is declared but not used [XDeclaredButNotUsed]
|
tused.nim(15, 8) Hint: 'tused.echoSub(a: int, b: int)[declared in tused.nim(15,7)]' is declared but not used [XDeclaredButNotUsed]
|
||||||
compile end'''
|
compile end'''
|
||||||
output: "8\n8"
|
output: "8\n8"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue