diff options
-rwxr-xr-x[-rw-r--r--] | build.sh | 0 | ||||
-rw-r--r-- | compiler/installer.ini | 4 | ||||
-rw-r--r-- | compiler/jsgen.nim | 12 | ||||
-rw-r--r-- | compiler/parampatterns.nim | 41 | ||||
-rw-r--r-- | compiler/semparallel.nim | 7 | ||||
-rw-r--r-- | compiler/semtypes.nim | 2 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 21 | ||||
-rw-r--r-- | compiler/vm.nim | 2 | ||||
-rw-r--r-- | doc/docgen.txt | 2 | ||||
-rw-r--r-- | doc/manual/type_rel.txt | 169 | ||||
-rw-r--r-- | doc/manual/types.txt | 20 | ||||
-rw-r--r-- | koch.nim | 16 | ||||
-rw-r--r-- | lib/impure/osinfo_posix.nim | 87 | ||||
-rw-r--r-- | lib/impure/osinfo_win.nim | 421 | ||||
-rw-r--r-- | lib/pure/fenv.nim | 78 | ||||
-rw-r--r-- | lib/pure/logging.nim | 2 | ||||
-rw-r--r-- | lib/pure/os.nim | 4 | ||||
-rw-r--r-- | lib/pure/redis.nim | 24 | ||||
-rw-r--r-- | lib/system/jssys.nim | 18 | ||||
-rw-r--r-- | lib/system/sysio.nim | 2 | ||||
-rw-r--r-- | lib/system/threads.nim | 4 | ||||
-rw-r--r-- | tests/cpp/tthread_createthread.nim | 14 | ||||
-rw-r--r-- | tests/js/taddr.nim | 36 | ||||
-rw-r--r-- | tests/types/tinfiniterecursion.nim | 8 | ||||
-rw-r--r-- | todo.txt | 4 | ||||
-rw-r--r-- | tools/niminst/buildsh.tmpl | 4 | ||||
-rw-r--r-- | tools/niminst/makefile.tmpl | 168 | ||||
-rw-r--r-- | tools/niminst/niminst.nim | 20 | ||||
-rw-r--r-- | web/news.txt | 410 |
29 files changed, 928 insertions, 672 deletions
diff --git a/build.sh b/build.sh index 139c28359..139c28359 100644..100755 --- a/build.sh +++ b/build.sh diff --git a/compiler/installer.ini b/compiler/installer.ini index 48cd0b3b9..b4160cab3 100644 --- a/compiler/installer.ini +++ b/compiler/installer.ini @@ -61,7 +61,7 @@ Files: "icons/koch.res" Files: "icons/koch_icon.o" Files: "compiler/readme.txt" -Files: "compiler/nim.ini" +Files: "compiler/installer.ini" Files: "compiler/nim.nimrod.cfg" Files: "compiler/*.nim" Files: "doc/*.txt" @@ -77,7 +77,7 @@ Files: "tools/niminst/*.nim" Files: "tools/niminst/*.cfg" Files: "tools/niminst/*.tmpl" Files: "tools/niminst/*.nsh" -Files: "web/nim.ini" +Files: "web/website.ini" Files: "web/*.nim" Files: "web/*.txt" diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 75c4ddfa0..0bdaeff83 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -961,18 +961,18 @@ proc genAddr(p: PProc, n: PNode, r: var TCompRes) = of nkCheckedFieldExpr: genCheckedFieldAddr(p, n, r) of nkDotExpr: - genFieldAddr(p, n, r) + genFieldAddr(p, n.sons[0], r) of nkBracketExpr: var ty = skipTypes(n.sons[0].typ, abstractVarRange) if ty.kind in {tyRef, tyPtr}: ty = skipTypes(ty.lastSon, abstractVarRange) case ty.kind of tyArray, tyArrayConstr, tyOpenArray, tySequence, tyString, tyCString, - tyVarargs: - genArrayAddr(p, n, r) + tyVarargs, tyChar: + genArrayAddr(p, n.sons[0], r) of tyTuple: - genFieldAddr(p, n, r) - else: internalError(n.info, "expr(nkBracketExpr, " & $ty.kind & ')') - else: internalError(n.info, "genAddr") + genFieldAddr(p, n.sons[0], r) + else: internalError(n.sons[0].info, "expr(nkBracketExpr, " & $ty.kind & ')') + else: internalError(n.sons[0].info, "genAddr") proc genSym(p: PProc, n: PNode, r: var TCompRes) = var s = n.sym diff --git a/compiler/parampatterns.nim b/compiler/parampatterns.nim index 8db786a25..58b5c5681 100644 --- a/compiler/parampatterns.nim +++ b/compiler/parampatterns.nim @@ -24,7 +24,7 @@ type ppEof = 1, # end of compiled pattern ppOr, # we could short-cut the evaluation for 'and' and 'or', ppAnd, # but currently we don't - ppNot, + ppNot, ppSym, ppAtom, ppLit, @@ -56,7 +56,7 @@ proc whichAlias*(p: PSym): TAliasRequest = proc compileConstraints(p: PNode, result: var TPatternCode) = case p.kind of nkCallKinds: - if p.sons[0].kind != nkIdent: + if p.sons[0].kind != nkIdent: patternError(p.sons[0]) return let op = p.sons[0].ident @@ -168,8 +168,8 @@ proc checkForSideEffects(n: PNode): TSideEffectAnalysis = elif ret == seUnknown and result == seNoSideEffect: result = seUnknown -type - TAssignableResult* = enum +type + TAssignableResult* = enum arNone, # no l-value and no discriminant arLValue, # is an l-value arLocalLValue, # is an l-value, but local var; must not escape @@ -183,26 +183,26 @@ proc isAssignable*(owner: PSym, n: PNode): TAssignableResult = of nkSym: # don't list 'skLet' here: if n.sym.kind in {skVar, skResult, skTemp}: - if owner != nil and owner.id == n.sym.owner.id and + if owner != nil and owner.id == n.sym.owner.id and sfGlobal notin n.sym.flags: result = arLocalLValue else: result = arLValue - of nkDotExpr: - if skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc}).kind in - {tyVar, tyPtr, tyRef}: + of nkDotExpr: + if skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc}).kind in + {tyVar, tyPtr, tyRef}: result = arLValue else: result = isAssignable(owner, n.sons[0]) - if result != arNone and sfDiscriminant in n.sons[1].sym.flags: + if result != arNone and sfDiscriminant in n.sons[1].sym.flags: result = arDiscriminant - of nkBracketExpr: + of nkBracketExpr: if skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc}).kind in - {tyVar, tyPtr, tyRef}: + {tyVar, tyPtr, tyRef}: result = arLValue else: result = isAssignable(owner, n.sons[0]) - of nkHiddenStdConv, nkHiddenSubConv, nkConv: + of nkHiddenStdConv, nkHiddenSubConv, nkConv: # Object and tuple conversions are still addressable, so we skip them # XXX why is 'tyOpenArray' allowed here? if skipTypes(n.typ, abstractPtrs-{tyTypeDesc}).kind in @@ -211,9 +211,9 @@ proc isAssignable*(owner: PSym, n: PNode): TAssignableResult = elif compareTypes(n.typ, n.sons[1].typ, dcEqIgnoreDistinct): # types that are equal modulo distinction preserve l-value: result = isAssignable(owner, n.sons[1]) - of nkHiddenDeref, nkDerefExpr: + of nkHiddenDeref, nkDerefExpr, nkHiddenAddr: result = arLValue - of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr: + of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr: result = isAssignable(owner, n.sons[0]) of nkCallKinds: # builtin slice keeps lvalue-ness: @@ -221,24 +221,27 @@ proc isAssignable*(owner: PSym, n: PNode): TAssignableResult = else: discard +proc isLValue*(n: PNode): bool = + isAssignable(nil, n) in {arLValue, arLocalLValue} + proc matchNodeKinds*(p, n: PNode): bool = - # matches the parameter constraint 'p' against the concrete AST 'n'. + # matches the parameter constraint 'p' against the concrete AST 'n'. # Efficiency matters here. var stack {.noinit.}: array[0..MaxStackSize, bool] # empty patterns are true: stack[0] = true var sp = 1 - + template push(x: bool) = stack[sp] = x inc sp - + let code = p.strVal var pc = 1 while true: case TOpcode(code[pc]) of ppEof: break - of ppOr: + of ppOr: stack[sp-2] = stack[sp-1] or stack[sp-2] dec sp of ppAnd: @@ -264,4 +267,4 @@ proc matchNodeKinds*(p, n: PNode): bool = of ppNoSideEffect: push checkForSideEffects(n) != seSideEffect inc pc result = stack[sp-1] - + diff --git a/compiler/semparallel.nim b/compiler/semparallel.nim index 6572a7f49..fbcd6b6da 100644 --- a/compiler/semparallel.nim +++ b/compiler/semparallel.nim @@ -317,8 +317,9 @@ proc analyseIf(c: var AnalysisCtx; n: PNode) = proc analyse(c: var AnalysisCtx; n: PNode) = case n.kind of nkAsgn, nkFastAsgn: - if n[0].isSingleAssignable and n[1].isLocal: - let slot = c.getSlot(n[1].sym) + let y = n[1].skipConv + if n[0].isSingleAssignable and y.isLocal: + let slot = c.getSlot(y.sym) slot.alias = n[0].sym elif n[0].isLocal: # since we already ensure sfAddrTaken is not in s.flags, we only need to @@ -334,7 +335,7 @@ proc analyse(c: var AnalysisCtx; n: PNode) = analyse(c, n[0]) else: analyseSons(c, n) - addAsgnFact(c.guards, n[0], n[1]) + addAsgnFact(c.guards, n[0], y) of nkCallKinds: # direct call: if n[0].kind == nkSym: analyseCall(c, n, n[0].sym) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index ac0636211..8a9f4a988 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -787,6 +787,8 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode, result = addImplicitGeneric(typ) else: for i in 0 .. <paramType.sons.len: + if paramType.sons[i] == paramType: + globalError(info, errIllegalRecursionInTypeX, typeToString(paramType)) var lifted = liftingWalk(paramType.sons[i]) if lifted != nil: paramType.sons[i] = lifted diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index f1fd84326..e56d82a5b 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -191,21 +191,6 @@ proc complexDisambiguation(a, b: PType): int = for i in 1 .. <a.len: x += a.sons[i].sumGeneric for i in 1 .. <b.len: y += b.sons[i].sumGeneric result = x - y - when false: - proc betterThan(a, b: PType): bool {.inline.} = a.sumGeneric > b.sumGeneric - - if a.len > 1 and b.len > 1: - let aa = a.sons[1].sumGeneric - let bb = b.sons[1].sumGeneric - var a = a - var b = b - - if aa < bb: swap(a, b) - # all must be better - for i in 2 .. <min(a.len, b.len): - if not a.sons[i].betterThan(b.sons[i]): return 0 - # a must be longer or of the same length as b: - result = a.len - b.len proc cmpCandidates*(a, b: TCandidate): int = result = a.exactMatches - b.exactMatches @@ -1463,6 +1448,12 @@ proc matchesAux(c: PContext, n, nOrig: PNode, else: m.state = csNoMatch return + if formal.typ.kind == tyVar: + if n.isLValue: + inc(m.genericMatches, 100) + else: + m.state = csNoMatch + return var # iterates over formal parameters diff --git a/compiler/vm.nim b/compiler/vm.nim index f0a0135e8..3b5c8e7f3 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -814,7 +814,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = leValueConv(regs[ra].regToNode, regs[rc].regToNode)): stackTrace(c, tos, pc, errGenerated, msgKindToString(errIllegalConvFromXtoY) % [ - "unknown type" , "unknown type"]) + $regs[ra].regToNode, "[" & $regs[rb].regToNode & ".." & $regs[rc].regToNode & "]"]) of opcIndCall, opcIndCallAsgn: # dest = call regStart, n; where regStart = fn, arg1, ... let rb = instr.regB diff --git a/doc/docgen.txt b/doc/docgen.txt index f4e28a49f..40c464ebd 100644 --- a/doc/docgen.txt +++ b/doc/docgen.txt @@ -195,7 +195,7 @@ In the case of Nim's own documentation, the ``txt`` value is just a commit hash to append to a formatted URL to https://github.com/Araq/Nim. The ``tools/nimweb.nim`` helper queries the current git commit hash during doc generation, but since you might be working on an unpublished repository, it -also allows specifying a ``githash`` value in ``web/nim.ini`` to force a +also allows specifying a ``githash`` value in ``web/website.ini`` to force a specific commit in the output. diff --git a/doc/manual/type_rel.txt b/doc/manual/type_rel.txt index 74539f907..d1593a02e 100644 --- a/doc/manual/type_rel.txt +++ b/doc/manual/type_rel.txt @@ -18,7 +18,7 @@ algorithm (in pseudo-code) determines type equality: incl(s, (a,b)) if a.kind == b.kind: case a.kind - of int, intXX, float, floatXX, char, string, cstring, pointer, + of int, intXX, float, floatXX, char, string, cstring, pointer, bool, nil, void: # leaf type: kinds identical; nothing more to check result = true @@ -61,7 +61,7 @@ with an auxiliary set ``s`` is omitted: proc typeEqualsOrDistinct(a, b: PType): bool = if a.kind == b.kind: case a.kind - of int, intXX, float, floatXX, char, string, cstring, pointer, + of int, intXX, float, floatXX, char, string, cstring, pointer, bool, nil, void: # leaf type: kinds identical; nothing more to check result = true @@ -90,7 +90,7 @@ with an auxiliary set ``s`` is omitted: result = typeEqualsOrDistinct(a.baseType, b) elif b.kind == distinct: result = typeEqualsOrDistinct(a, b.baseType) - + Subtype relation ---------------- @@ -145,7 +145,7 @@ algorithm returns true: A type ``a`` is **explicitly** convertible to type ``b`` iff the following algorithm returns true: - + .. code-block:: nim proc isIntegralType(t: PType): bool = result = isOrdinal(t) or t.kind in {float, float32, float64} @@ -156,8 +156,8 @@ algorithm returns true: if typeEqualsOrDistinct(a, b): return true if isIntegralType(a) and isIntegralType(b): return true if isSubtype(a, b) or isSubtype(b, a): return true - -The convertible relation can be relaxed by a user-defined type + +The convertible relation can be relaxed by a user-defined type `converter`:idx:. .. code-block:: nim @@ -174,7 +174,7 @@ The convertible relation can be relaxed by a user-defined type x = chr.toInt echo x # => 97 -The type conversion ``T(a)`` is an L-value if ``a`` is an L-value and +The type conversion ``T(a)`` is an L-value if ``a`` is an L-value and ``typeEqualsOrDistinct(T, type(a))`` holds. @@ -186,6 +186,157 @@ An expression ``b`` can be assigned to an expression ``a`` iff ``a`` is an Overloading resolution ----------------------- +====================== + +In a call ``p(args)`` the routine ``p`` that matches best is selected. If +multiple routines match equally well, the ambiguity is reported at compiletime. + +Every arg in args needs to match. There are multiple different category how an +argument can match. Let ``f`` be the formal parameter's type and ``a`` the type +of the argument. + +1. Exact match: ``a`` and ``f`` are of the same type. +2. Literal match: ``a`` is an integer literal of value ``v`` + and ``f`` is a signed or unsigned integer type and ``v`` is in ``f``'s + range. Or: ``a`` is a floating point literal of value ``v`` + and ``f`` is a floating point type and ``v`` is in ``f``'s + range. +3. Generic match: ``f`` is a generic type and ``a`` matches, for + instance ``a`` is ``int`` and ``f`` is a generic (constrained) parameter + type (like in ``[T]`` or ``[T: int|char]``. +4. Subrange or subtype match: ``a`` is a ``range[T]`` and ``T`` + matches ``f`` exactly. Or: ``a`` is a subtype of ``f``. +5. Integral conversion match: ``a`` is convertible to ``f`` and ``f`` and ``a`` + is some integer or floating point type. +6. Conversion match: ``a`` is convertible to ``f``, possibly via a user + defined ``converter``. + +These matching categories have a priority: An exact match is better than a +literal match and that is better than a generic match etc. In the following +``count(p, m)`` counts the number of matches of the matching category ``m`` +for the routine ``p``. + +A routine ``p`` matches better than a routine ``q`` if the following +algorithm returns true:: + + for each matching category m in ["exact match", "literal match", + "generic match", "subtype match", + "integral match", "conversion match"]: + if count(p, m) > count(q, m): return true + elif count(p, m) == count(q, m): + discard "continue with next category m" + else: + return false + return "ambiguous" + + +Some examples: + +.. code-block:: nim + proc takesInt(x: int) = echo "int" + proc takesInt[T](x: T) = echo "T" + proc takesInt(x: int16) = echo "int16" + + takesInt(4) # "int" + var x: int32 + takesInt(x) # "T" + var y: int16 + takesInt(y) # "int16" + var z: range[0..4] = 0 + takesInt(z) # "T" + + +If this algorithm returns "ambiguous" further disambiguation is performed: +If the argument ``a`` matches both the parameter type ``f`` of ``p`` +and ``g`` of ``q`` via a subtyping relation, the inheritance depth is taken +into account: + +.. code-block:: nim + type + A = object of RootObj + B = object of A + C = object of B + + proc p(obj: A) = + echo "A" + + proc p(obj: B) = + echo "B" + + var c = C() + # not ambiguous, calls 'B', not 'A' since B is a subtype of A + # but not vice versa: + p(c) + + proc pp(obj: A, obj2: B) = echo "A B" + proc pp(obj: B, obj2: A) = echo "B A" + + # but this is ambiguous: + pp(c, c) + + +Likewise for generic matches the most specialized generic type (that still +matches) is preferred: + +.. code-block:: nim + proc gen[T](x: ref ref T) = echo "ref ref T" + proc gen[T](x: ref T) = echo "ref T" + proc gen[T](x: T) = echo "T" + + var ri: ref int + gen(ri) # "ref T" + + +Overloading based on 'var T' +---------------------------- + +If the formal parameter ``f`` is of type ``var T`` in addition to the ordinary +type checking, the argument is checked to be an `l-value`:idx:. ``var T`` +matches better than just ``T`` then. + + +Automatic dereferencing +----------------------- + +If the `experimental mode <experimental pragma>`_ is active and no other match +is found, the first argument ``a`` is dereferenced automatically if it's a +pointer type and overloading resolution is tried with ``a[]`` instead. + + +Lazy type resolution for expr +----------------------------- + +**Note**: An `unresolved`:idx: expression is an expression for which no symbol +lookups and no type checking have been performed. + +Since templates and macros that are not declared as ``immediate`` participate +in overloading resolution it's essential to have a way to pass unresolved +expressions to a template or macro. This is what the meta-type ``expr`` +accomplishes: + +.. code-block:: nim + template rem(x: expr) = discard + + rem unresolvedExpression(undeclaredIdentifier) + +A parameter of type ``expr`` always matches any argument (as long as there is +any argument passed to it). + +But one has to watch out because other overloads might trigger the +argument's resolution: + +.. code-block:: nim + template rem(x: expr) = discard + proc rem[T](x: T) = discard + + # undeclared identifier: 'unresolvedExpression' + rem unresolvedExpression(undeclaredIdentifier) + +``expr`` is the only metatype that is lazy in this sense, the other +metatypes ``stmt`` and ``typedesc`` are not lazy. + + +Varargs matching +---------------- -To be written. +See `Varargs`_. diff --git a/doc/manual/types.txt b/doc/manual/types.txt index a20701121..c78984db8 100644 --- a/doc/manual/types.txt +++ b/doc/manual/types.txt @@ -497,6 +497,24 @@ type conversions in this context: In this example ``$`` is applied to any argument that is passed to the parameter ``a``. (Note that ``$`` applied to strings is a nop.) +Note that an explicit array constructor passed to a ``varargs`` parameter is +not wrapped in another implicit array construction: + +.. code-block:: nim + proc takeV[T](a: varargs[T]) = discard + + takeV([123, 2, 1]) # takeV's T is "int", not "array of int" + + +``varargs[expr]`` is treated specially: It matches a variable list of arguments +of arbitrary type but *always* constructs an implicit array. This is required +so that the builtin ``echo`` proc does what is expected: + +.. code-block:: nim + proc echo*(x: varargs[expr, `$`]) {...} + + echo(@[1, 2, 3]) + # prints "@[1, 2, 3]" and not "123" Tuples and object types @@ -695,7 +713,7 @@ via ``{.experimental.}``: new(n) echo n.depth # no need to write n[].depth either - + In order to simplify structural type checking, recursive tuples are not valid: diff --git a/koch.nim b/koch.nim index 34cb1317d..508d7e007 100644 --- a/koch.nim +++ b/koch.nim @@ -41,7 +41,7 @@ Options: Possible Commands: boot [options] bootstraps with given command line options install [bindir] installs to given directory; Unix only! - clean cleans Nimrod project; removes generated files + clean cleans Nim project; removes generated files web [options] generates the website and the full documentation website [options] generates only the website csource [options] builds the C sources for installation @@ -59,7 +59,7 @@ Boot options: -d:useGnuReadline use the GNU readline library for interactive mode (not needed on Windows) -d:nativeStacktrace use native stack traces (only for Mac OS X or Linux) - -d:noCaas build Nimrod without CAAS support + -d:noCaas build Nim without CAAS support -d:avoidTimeMachine only for Mac OS X, excludes nimcache dir from backups Web options: --googleAnalytics:UA-... add the given google analytics code to the docs. To @@ -97,13 +97,13 @@ const compileNimInst = "-d:useLibzipSrc tools/niminst/niminst" proc csource(args: string) = - exec("$4 cc $1 -r $3 --var:version=$2 --var:mingw=none csource compiler/installer.ini $1" % + exec("$4 cc $1 -r $3 --var:version=$2 --var:mingw=none csource --main:compiler/nim.nim compiler/installer.ini $1" % [args, VersionAsString, compileNimInst, findNim()]) proc zip(args: string) = - exec("$3 cc -r $2 --var:version=$1 --var:mingw=none scripts compiler/installer.ini" % + exec("$3 cc -r $2 --var:version=$1 --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" % [VersionAsString, compileNimInst, findNim()]) - exec("$# --var:version=$# --var:mingw=none zip compiler/installer.ini" % + exec("$# --var:version=$# --var:mingw=none --main:compiler/nim.nim zip compiler/installer.ini" % ["tools/niminst/niminst".exe, VersionAsString]) proc buildTool(toolname, args: string) = @@ -121,7 +121,7 @@ proc nsis(args: string) = " nsis compiler/nim") % [VersionAsString, $(sizeof(pointer)*8)]) proc install(args: string) = - exec("$# cc -r $# --var:version=$# --var:mingw=none scripts compiler/installer.ini" % + exec("$# cc -r $# --var:version=$# --var:mingw=none --main:compiler/nim.nim scripts compiler/installer.ini" % [findNim(), compileNimInst, VersionAsString]) exec("sh ./install.sh $#" % args) @@ -282,7 +282,7 @@ when defined(withUpdate): when defined(haveZipLib): echo("Falling back.. Downloading source code from repo...") # use dom96's httpclient to download zip - downloadFile("https://github.com/Araq/Nimrod/zipball/master", + downloadFile("https://github.com/Araq/Nim/zipball/master", thisDir / "update.zip") try: echo("Extracting source code from archive...") @@ -320,7 +320,7 @@ proc winRelease() = run7z("win32", "bin/nim.exe", "bin/c2nim.exe", "bin/nimgrep.exe", "bin/nimfix.exe", - "bin/babel.exe", "bin/*.dll", + "bin/nimble.exe", "bin/*.dll", "config", "dist/*.dll", "examples", "lib", "readme.txt", "contributors.txt", "copying.txt") # second step: XXX build 64 bit version diff --git a/lib/impure/osinfo_posix.nim b/lib/impure/osinfo_posix.nim index 0ed4289c4..0362fca12 100644 --- a/lib/impure/osinfo_posix.nim +++ b/lib/impure/osinfo_posix.nim @@ -1,77 +1,10 @@ -import posix, strutils, os - -when false: - type - Tstatfs {.importc: "struct statfs64", - header: "<sys/statfs.h>", final, pure.} = object - f_type: int - f_bsize: int - f_blocks: int - f_bfree: int - f_bavail: int - f_files: int - f_ffree: int - f_fsid: int - f_namelen: int - - proc statfs(path: string, buf: var Tstatfs): int {. - importc, header: "<sys/vfs.h>".} - - -proc getSystemVersion*(): string = - result = "" - - var unix_info: TUtsname - - if uname(unix_info) != 0: - os.raiseOSError(osLastError()) - - if $unix_info.sysname == "Linux": - # Linux - result.add("Linux ") - - result.add($unix_info.release & " ") - result.add($unix_info.machine) - elif $unix_info.sysname == "Darwin": - # Darwin - result.add("Mac OS X ") - if "14" in $unix_info.release: - result.add("v10.10 Yosemite") - elif "13" in $unix_info.release: - result.add("v10.9 Mavericks") - elif "12" in $unix_info.release: - result.add("v10.8 Mountian Lion") - elif "11" in $unix_info.release: - result.add("v10.7 Lion") - elif "10" in $unix_info.release: - result.add("v10.6 Snow Leopard") - elif "9" in $unix_info.release: - result.add("v10.5 Leopard") - elif "8" in $unix_info.release: - result.add("v10.4 Tiger") - elif "7" in $unix_info.release: - result.add("v10.3 Panther") - elif "6" in $unix_info.release: - result.add("v10.2 Jaguar") - elif "1.4" in $unix_info.release: - result.add("v10.1 Puma") - elif "1.3" in $unix_info.release: - result.add("v10.0 Cheetah") - elif "0" in $unix_info.release: - result.add("Server 1.0 Hera") - else: - result.add($unix_info.sysname & " " & $unix_info.release) - - -when false: - var unix_info: TUtsname - echo(uname(unix_info)) - echo(unix_info.sysname) - echo("8" in $unix_info.release) - - echo(getSystemVersion()) - - var stfs: TStatfs - echo(statfs("sysinfo_posix.nim", stfs)) - echo(stfs.f_files) - +# +# +# Nim's Runtime Library +# (c) Copyright 2015 Dominik Picheta +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +{.error: "This module has been moved to the 'osinfo' nimble package.".} diff --git a/lib/impure/osinfo_win.nim b/lib/impure/osinfo_win.nim index 94a27eb03..0362fca12 100644 --- a/lib/impure/osinfo_win.nim +++ b/lib/impure/osinfo_win.nim @@ -1,411 +1,10 @@ -# XXX clean up this mess! - -import winlean - -const - INVALID_HANDLE_VALUE = int(- 1) # GetStockObject - -type - TMEMORYSTATUSEX {.final, pure.} = object - dwLength: int32 - dwMemoryLoad: int32 - ullTotalPhys: int64 - ullAvailPhys: int64 - ullTotalPageFile: int64 - ullAvailPageFile: int64 - ullTotalVirtual: int64 - ullAvailVirtual: int64 - ullAvailExtendedVirtual: int64 - - SYSTEM_INFO* {.final, pure.} = object - wProcessorArchitecture*: int16 - wReserved*: int16 - dwPageSize*: int32 - lpMinimumApplicationAddress*: pointer - lpMaximumApplicationAddress*: pointer - dwActiveProcessorMask*: int32 - dwNumberOfProcessors*: int32 - dwProcessorType*: int32 - dwAllocationGranularity*: int32 - wProcessorLevel*: int16 - wProcessorRevision*: int16 - - LPSYSTEM_INFO* = ptr SYSTEM_INFO - TSYSTEMINFO* = SYSTEM_INFO - - TMemoryInfo* = object - MemoryLoad*: int ## occupied memory, in percent - TotalPhysMem*: int64 ## Total Physical memory, in bytes - AvailablePhysMem*: int64 ## Available physical memory, in bytes - TotalPageFile*: int64 ## The current committed memory limit - ## for the system or the current process, whichever is smaller, in bytes. - AvailablePageFile*: int64 ## The maximum amount of memory the current process can commit, in bytes. - TotalVirtualMem*: int64 ## Total virtual memory, in bytes - AvailableVirtualMem*: int64 ## Available virtual memory, in bytes - - TOSVERSIONINFOEX {.final, pure.} = object - dwOSVersionInfoSize: int32 - dwMajorVersion: int32 - dwMinorVersion: int32 - dwBuildNumber: int32 - dwPlatformId: int32 - szCSDVersion: array[0..127, char] - wServicePackMajor: int16 - wServicePackMinor: int16 - wSuiteMask: int16 - wProductType: int8 - wReserved: char - - TVersionInfo* = object - majorVersion*: int - minorVersion*: int - buildNumber*: int - platformID*: int - SPVersion*: string ## Full Service pack version string - SPMajor*: int ## Major service pack version - SPMinor*: int ## Minor service pack version - SuiteMask*: int - ProductType*: int - - TPartitionInfo* = tuple[FreeSpace, TotalSpace: Tfiletime] - -const - # SuiteMask - VersionInfo.SuiteMask - VER_SUITE_BACKOFFICE* = 0x00000004 - VER_SUITE_BLADE* = 0x00000400 - VER_SUITE_COMPUTE_SERVER* = 0x00004000 - VER_SUITE_DATACENTER* = 0x00000080 - VER_SUITE_ENTERPRISE* = 0x00000002 - VER_SUITE_EMBEDDEDNT* = 0x00000040 - VER_SUITE_PERSONAL* = 0x00000200 - VER_SUITE_SINGLEUSERTS* = 0x00000100 - VER_SUITE_SMALLBUSINESS* = 0x00000001 - VER_SUITE_SMALLBUSINESS_RESTRICTED* = 0x00000020 - VER_SUITE_STORAGE_SERVER* = 0x00002000 - VER_SUITE_TERMINAL* = 0x00000010 - VER_SUITE_WH_SERVER* = 0x00008000 - - # ProductType - VersionInfo.ProductType - VER_NT_DOMAIN_CONTROLLER* = 0x0000002 - VER_NT_SERVER* = 0x0000003 - VER_NT_WORKSTATION* = 0x0000001 - - VER_PLATFORM_WIN32_NT* = 2 - - # Product Info - getProductInfo() - (Remove unused ones ?) - PRODUCT_BUSINESS* = 0x00000006 - PRODUCT_BUSINESS_N* = 0x00000010 - PRODUCT_CLUSTER_SERVER* = 0x00000012 - PRODUCT_DATACENTER_SERVER* = 0x00000008 - PRODUCT_DATACENTER_SERVER_CORE* = 0x0000000C - PRODUCT_DATACENTER_SERVER_CORE_V* = 0x00000027 - PRODUCT_DATACENTER_SERVER_V* = 0x00000025 - PRODUCT_ENTERPRISE* = 0x00000004 - PRODUCT_ENTERPRISE_E* = 0x00000046 - PRODUCT_ENTERPRISE_N* = 0x0000001B - PRODUCT_ENTERPRISE_SERVER* = 0x0000000A - PRODUCT_ENTERPRISE_SERVER_CORE* = 0x0000000E - PRODUCT_ENTERPRISE_SERVER_CORE_V* = 0x00000029 - PRODUCT_ENTERPRISE_SERVER_IA64* = 0x0000000F - PRODUCT_ENTERPRISE_SERVER_V* = 0x00000026 - PRODUCT_HOME_BASIC* = 0x00000002 - PRODUCT_HOME_BASIC_E* = 0x00000043 - PRODUCT_HOME_BASIC_N* = 0x00000005 - PRODUCT_HOME_PREMIUM* = 0x00000003 - PRODUCT_HOME_PREMIUM_E* = 0x00000044 - PRODUCT_HOME_PREMIUM_N* = 0x0000001A - PRODUCT_HYPERV* = 0x0000002A - PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT* = 0x0000001E - PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING* = 0x00000020 - PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY* = 0x0000001F - PRODUCT_PROFESSIONAL* = 0x00000030 - PRODUCT_PROFESSIONAL_E* = 0x00000045 - PRODUCT_PROFESSIONAL_N* = 0x00000031 - PRODUCT_SERVER_FOR_SMALLBUSINESS* = 0x00000018 - PRODUCT_SERVER_FOR_SMALLBUSINESS_V* = 0x00000023 - PRODUCT_SERVER_FOUNDATION* = 0x00000021 - PRODUCT_SMALLBUSINESS_SERVER* = 0x00000009 - PRODUCT_STANDARD_SERVER* = 0x00000007 - PRODUCT_STANDARD_SERVER_CORE * = 0x0000000D - PRODUCT_STANDARD_SERVER_CORE_V* = 0x00000028 - PRODUCT_STANDARD_SERVER_V* = 0x00000024 - PRODUCT_STARTER* = 0x0000000B - PRODUCT_STARTER_E* = 0x00000042 - PRODUCT_STARTER_N* = 0x0000002F - PRODUCT_STORAGE_ENTERPRISE_SERVER* = 0x00000017 - PRODUCT_STORAGE_EXPRESS_SERVER* = 0x00000014 - PRODUCT_STORAGE_STANDARD_SERVER* = 0x00000015 - PRODUCT_STORAGE_WORKGROUP_SERVER* = 0x00000016 - PRODUCT_UNDEFINED* = 0x00000000 - PRODUCT_ULTIMATE* = 0x00000001 - PRODUCT_ULTIMATE_E* = 0x00000047 - PRODUCT_ULTIMATE_N* = 0x0000001C - PRODUCT_WEB_SERVER* = 0x00000011 - PRODUCT_WEB_SERVER_CORE* = 0x0000001D - - PROCESSOR_ARCHITECTURE_AMD64* = 9 ## x64 (AMD or Intel) - PROCESSOR_ARCHITECTURE_IA64* = 6 ## Intel Itanium Processor Family (IPF) - PROCESSOR_ARCHITECTURE_INTEL* = 0 ## x86 - PROCESSOR_ARCHITECTURE_UNKNOWN* = 0xffff ## Unknown architecture. - - # GetSystemMetrics - SM_SERVERR2 = 89 - -proc globalMemoryStatusEx*(lpBuffer: var TMEMORYSTATUSEX){.stdcall, dynlib: "kernel32", - importc: "GlobalMemoryStatusEx".} - -proc getMemoryInfo*(): TMemoryInfo = - ## Retrieves memory info - var statex: TMEMORYSTATUSEX - statex.dwLength = sizeof(statex).int32 - - globalMemoryStatusEx(statex) - result.MemoryLoad = statex.dwMemoryLoad - result.TotalPhysMem = statex.ullTotalPhys - result.AvailablePhysMem = statex.ullAvailPhys - result.TotalPageFile = statex.ullTotalPageFile - result.AvailablePageFile = statex.ullAvailPageFile - result.TotalVirtualMem = statex.ullTotalVirtual - result.AvailableVirtualMem = statex.ullAvailExtendedVirtual - -proc getVersionEx*(lpVersionInformation: var TOSVERSIONINFOEX): WINBOOL{.stdcall, - dynlib: "kernel32", importc: "GetVersionExA".} - -proc getProcAddress*(hModule: int, lpProcName: cstring): pointer{.stdcall, - dynlib: "kernel32", importc: "GetProcAddress".} - -proc getModuleHandleA*(lpModuleName: cstring): int{.stdcall, - dynlib: "kernel32", importc: "GetModuleHandleA".} - -proc getVersionInfo*(): TVersionInfo = - ## Retrieves operating system info - var osvi: TOSVERSIONINFOEX - osvi.dwOSVersionInfoSize = sizeof(osvi).int32 - discard getVersionEx(osvi) - result.majorVersion = osvi.dwMajorVersion - result.minorVersion = osvi.dwMinorVersion - result.buildNumber = osvi.dwBuildNumber - result.platformID = osvi.dwPlatformId - result.SPVersion = $osvi.szCSDVersion - result.SPMajor = osvi.wServicePackMajor - result.SPMinor = osvi.wServicePackMinor - result.SuiteMask = osvi.wSuiteMask - result.ProductType = osvi.wProductType - -proc getProductInfo*(majorVersion, minorVersion, SPMajorVersion, - SPMinorVersion: int): int = - ## Retrieves Windows' ProductInfo, this function only works in Vista and 7 - var pGPI = cast[proc (dwOSMajorVersion, dwOSMinorVersion, - dwSpMajorVersion, dwSpMinorVersion: int32, outValue: Pint32){.stdcall.}](getProcAddress( - getModuleHandleA("kernel32.dll"), "GetProductInfo")) - - if pGPI != nil: - var dwType: int32 - pGPI(int32(majorVersion), int32(minorVersion), int32(SPMajorVersion), int32(SPMinorVersion), addr(dwType)) - result = int(dwType) - else: - return PRODUCT_UNDEFINED - -proc getSystemInfo*(lpSystemInfo: LPSYSTEM_INFO){.stdcall, dynlib: "kernel32", - importc: "GetSystemInfo".} - -proc getSystemInfo*(): TSYSTEM_INFO = - ## Returns the SystemInfo - - # Use GetNativeSystemInfo if it's available - var pGNSI = cast[proc (lpSystemInfo: LPSYSTEM_INFO){.stdcall.}](getProcAddress( - getModuleHandleA("kernel32.dll"), "GetNativeSystemInfo")) - - var systemi: TSYSTEM_INFO - if pGNSI != nil: - pGNSI(addr(systemi)) - else: - getSystemInfo(addr(systemi)) - - return systemi - -proc getSystemMetrics*(nIndex: int32): int32{.stdcall, dynlib: "user32", - importc: "GetSystemMetrics".} - -proc `$`*(osvi: TVersionInfo): string = - ## Turns a VersionInfo object, into a string - - if osvi.platformID == VER_PLATFORM_WIN32_NT and osvi.majorVersion > 4: - result = "Microsoft " - - var si = getSystemInfo() - # Test for the specific product - if osvi.majorVersion == 6: - if osvi.minorVersion == 0: - if osvi.ProductType == VER_NT_WORKSTATION: - result.add("Windows Vista ") - else: result.add("Windows Server 2008 ") - elif osvi.minorVersion == 1: - if osvi.ProductType == VER_NT_WORKSTATION: - result.add("Windows 7 ") - else: result.add("Windows Server 2008 R2 ") - elif osvi.minorVersion == 2: - if osvi.ProductType == VER_NT_WORKSTATION: - result.add("Windows 8 ") - else: result.add("Windows Server 2012 ") - elif osvi.minorVersion == 3: - if osvi.ProductType == VER_NT_WORKSTATION: - result.add("Windows 8.1 ") - else: result.add("Windows Server 2012 R2 ") - - var dwType = getProductInfo(osvi.majorVersion, osvi.minorVersion, 0, 0) - case dwType - of PRODUCT_ULTIMATE: - result.add("Ultimate Edition") - of PRODUCT_PROFESSIONAL: - result.add("Professional") - of PRODUCT_HOME_PREMIUM: - result.add("Home Premium Edition") - of PRODUCT_HOME_BASIC: - result.add("Home Basic Edition") - of PRODUCT_ENTERPRISE: - result.add("Enterprise Edition") - of PRODUCT_BUSINESS: - result.add("Business Edition") - of PRODUCT_STARTER: - result.add("Starter Edition") - of PRODUCT_CLUSTER_SERVER: - result.add("Cluster Server Edition") - of PRODUCT_DATACENTER_SERVER: - result.add("Datacenter Edition") - of PRODUCT_DATACENTER_SERVER_CORE: - result.add("Datacenter Edition (core installation)") - of PRODUCT_ENTERPRISE_SERVER: - result.add("Enterprise Edition") - of PRODUCT_ENTERPRISE_SERVER_CORE: - result.add("Enterprise Edition (core installation)") - of PRODUCT_ENTERPRISE_SERVER_IA64: - result.add("Enterprise Edition for Itanium-based Systems") - of PRODUCT_SMALLBUSINESS_SERVER: - result.add("Small Business Server") - of PRODUCT_STANDARD_SERVER: - result.add("Standard Edition") - of PRODUCT_STANDARD_SERVER_CORE: - result.add("Standard Edition (core installation)") - of PRODUCT_WEB_SERVER: - result.add("Web Server Edition") - else: - discard - # End of Windows 6.* - - if osvi.majorVersion == 5 and osvi.minorVersion == 2: - if getSystemMetrics(SM_SERVERR2) != 0: - result.add("Windows Server 2003 R2, ") - elif (osvi.SuiteMask and VER_SUITE_PERSONAL) != 0: # Not sure if this will work - result.add("Windows Storage Server 2003") - elif (osvi.SuiteMask and VER_SUITE_WH_SERVER) != 0: - result.add("Windows Home Server") - elif osvi.ProductType == VER_NT_WORKSTATION and - si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64: - result.add("Windows XP Professional x64 Edition") - else: - result.add("Windows Server 2003, ") - - # Test for the specific product - if osvi.ProductType != VER_NT_WORKSTATION: - if ze(si.wProcessorArchitecture) == PROCESSOR_ARCHITECTURE_IA64: - if (osvi.SuiteMask and VER_SUITE_DATACENTER) != 0: - result.add("Datacenter Edition for Itanium-based Systems") - elif (osvi.SuiteMask and VER_SUITE_ENTERPRISE) != 0: - result.add("Enterprise Edition for Itanium-based Systems") - elif ze(si.wProcessorArchitecture) == PROCESSOR_ARCHITECTURE_AMD64: - if (osvi.SuiteMask and VER_SUITE_DATACENTER) != 0: - result.add("Datacenter x64 Edition") - elif (osvi.SuiteMask and VER_SUITE_ENTERPRISE) != 0: - result.add("Enterprise x64 Edition") - else: - result.add("Standard x64 Edition") - else: - if (osvi.SuiteMask and VER_SUITE_COMPUTE_SERVER) != 0: - result.add("Compute Cluster Edition") - elif (osvi.SuiteMask and VER_SUITE_DATACENTER) != 0: - result.add("Datacenter Edition") - elif (osvi.SuiteMask and VER_SUITE_ENTERPRISE) != 0: - result.add("Enterprise Edition") - elif (osvi.SuiteMask and VER_SUITE_BLADE) != 0: - result.add("Web Edition") - else: - result.add("Standard Edition") - # End of 5.2 - - if osvi.majorVersion == 5 and osvi.minorVersion == 1: - result.add("Windows XP ") - if (osvi.SuiteMask and VER_SUITE_PERSONAL) != 0: - result.add("Home Edition") - else: - result.add("Professional") - # End of 5.1 - - if osvi.majorVersion == 5 and osvi.minorVersion == 0: - result.add("Windows 2000 ") - if osvi.ProductType == VER_NT_WORKSTATION: - result.add("Professional") - else: - if (osvi.SuiteMask and VER_SUITE_DATACENTER) != 0: - result.add("Datacenter Server") - elif (osvi.SuiteMask and VER_SUITE_ENTERPRISE) != 0: - result.add("Advanced Server") - else: - result.add("Server") - # End of 5.0 - - # Include service pack (if any) and build number. - if len(osvi.SPVersion) > 0: - result.add(" ") - result.add(osvi.SPVersion) - - result.add(" (build " & $osvi.buildNumber & ")") - - if osvi.majorVersion >= 6: - if ze(si.wProcessorArchitecture) == PROCESSOR_ARCHITECTURE_AMD64: - result.add(", 64-bit") - elif ze(si.wProcessorArchitecture) == PROCESSOR_ARCHITECTURE_INTEL: - result.add(", 32-bit") - - else: - # Windows 98 etc... - result = "Unknown version of windows[Kernel version <= 4]" - - -proc getFileSize*(file: string): BiggestInt = - var fileData: TWIN32_FIND_DATA - - when useWinUnicode: - var aa = newWideCString(file) - var hFile = findFirstFileW(aa, fileData) - else: - var hFile = findFirstFileA(file, fileData) - - if hFile == INVALID_HANDLE_VALUE: - raise newException(IOError, $getLastError()) - - return fileData.nFileSizeLow - -proc getDiskFreeSpaceEx*(lpDirectoryName: cstring, lpFreeBytesAvailableToCaller, - lpTotalNumberOfBytes, - lpTotalNumberOfFreeBytes: var TFiletime): WINBOOL{. - stdcall, dynlib: "kernel32", importc: "GetDiskFreeSpaceExA".} - -proc getPartitionInfo*(partition: string): TPartitionInfo = - ## Retrieves partition info, for example ``partition`` may be ``"C:\"`` - var freeBytes, totalBytes, totalFreeBytes: TFiletime - discard getDiskFreeSpaceEx(r"C:\", freeBytes, totalBytes, - totalFreeBytes) - return (freeBytes, totalBytes) - -when isMainModule: - var r = getMemoryInfo() - echo("Memory load: ", r.MemoryLoad, "%") - - var osvi = getVersionInfo() - - echo($osvi) - - echo(getFileSize(r"lib\impure\osinfo_win.nim") div 1024, " KB") - - echo(rdFileTime(getPartitionInfo(r"C:\")[0])) +# +# +# Nim's Runtime Library +# (c) Copyright 2015 Dominik Picheta +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +{.error: "This module has been moved to the 'osinfo' nimble package.".} diff --git a/lib/pure/fenv.nim b/lib/pure/fenv.nim index 6f9085c92..fd0eab310 100644 --- a/lib/pure/fenv.nim +++ b/lib/pure/fenv.nim @@ -101,3 +101,81 @@ proc feupdateenv*(envp: ptr Tfenv): cint {.importc, header: "<fenv.h>".} ## Save current exceptions in temporary storage, install environment ## represented by object pointed to by `envp` and raise exceptions ## according to saved exceptions. + +var FP_RADIX_INTERNAL {. importc: "FLT_RADIX" header: "<float.h>" .} : int + +template fpRadix* : int = FLT_RADIX_INTERNAL + ## The (integer) value of the radix used to represent any floating + ## point type on the architecture used to build the program. + +var FLT_MANT_DIG {. importc: "FLT_MANT_DIG" header: "<float.h>" .} : int +var FLT_DIG {. importc: "FLT_DIG" header: "<float.h>" .} : int +var FLT_MIN_EXP {. importc: "FLT_MIN_EXP" header: "<float.h>" .} : int +var FLT_MAX_EXP {. importc: "FLT_MAX_EXP" header: "<float.h>" .} : int +var FLT_MIN_10_EXP {. importc: "FLT_MIN_10_EXP" header: "<float.h>" .} : int +var FLT_MAX_10_EXP {. importc: "FLT_MAX_10_EXP" header: "<float.h>" .} : int +var FLT_MIN {. importc: "FLT_MIN" header: "<float.h>" .} : cfloat +var FLT_MAX {. importc: "FLT_MAX" header: "<float.h>" .} : cfloat +var FLT_EPSILON {. importc: "FLT_EPSILON" header: "<float.h>" .} : cfloat + +var DBL_MANT_DIG {. importc: "DBL_MANT_DIG" header: "<float.h>" .} : int +var DBL_DIG {. importc: "DBL_DIG" header: "<float.h>" .} : int +var DBL_MIN_EXP {. importc: "DBL_MIN_EXP" header: "<float.h>" .} : int +var DBL_MAX_EXP {. importc: "DBL_MAX_EXP" header: "<float.h>" .} : int +var DBL_MIN_10_EXP {. importc: "DBL_MIN_10_EXP" header: "<float.h>" .} : int +var DBL_MAX_10_EXP {. importc: "DBL_MAX_10_EXP" header: "<float.h>" .} : int +var DBL_MIN {. importc: "DBL_MIN" header: "<float.h>" .} : cdouble +var DBL_MAX {. importc: "DBL_MAX" header: "<float.h>" .} : cdouble +var DBL_EPSILON {. importc: "DBL_EPSILON" header: "<float.h>" .} : cdouble + +template mantissaDigits*(T : typedesc[float32]) : int = FLT_MANT_DIG + ## Number of digits (in base ``floatingPointRadix``) in the mantissa + ## of 32-bit floating-point numbers. +template digits*(T : typedesc[float32]) : int = FLT_DIG + ## Number of decimal digits that can be represented in a + ## 32-bit floating-point type without losing precision. +template minExponent*(T : typedesc[float32]) : int = FLT_MIN_EXP + ## Minimum (negative) exponent for 32-bit floating-point numbers. +template maxExponent*(T : typedesc[float32]) : int = FLT_MAX_EXP + ## Maximum (positive) exponent for 32-bit floating-point numbers. +template min10Exponent*(T : typedesc[float32]) : int = FLT_MIN_10_EXP + ## Minimum (negative) exponent in base 10 for 32-bit floating-point + ## numbers. +template max10Exponent*(T : typedesc[float32]) : int = FLT_MAX_10_EXP + ## Maximum (positive) exponent in base 10 for 32-bit floating-point + ## numbers. +template minimumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MIN + ## The smallest positive (nonzero) number that can be represented in a + ## 32-bit floating-point type. +template maximumPositiveValue*(T : typedesc[float32]) : float32 = FLT_MAX + ## The largest positive number that can be represented in a 32-bit + ## floating-point type. +template epsilon*(T : typedesc[float32]): float32 = FLT_EPSILON + ## The difference between 1.0 and the smallest number greater than + ## 1.0 that can be represented in a 32-bit floating-point type. + +template mantissaDigits*(T : typedesc[float64]) : int = DBL_MANT_DIG + ## Number of digits (in base ``floatingPointRadix``) in the mantissa + ## of 64-bit floating-point numbers. +template digits*(T : typedesc[float64]) : int = DBL_DIG + ## Number of decimal digits that can be represented in a + ## 64-bit floating-point type without losing precision. +template minExponent*(T : typedesc[float64]) : int = DBL_MIN_EXP + ## Minimum (negative) exponent for 64-bit floating-point numbers. +template maxExponent*(T : typedesc[float64]) : int = DBL_MAX_EXP + ## Maximum (positive) exponent for 64-bit floating-point numbers. +template min10Exponent*(T : typedesc[float64]) : int = DBL_MIN_10_EXP + ## Minimum (negative) exponent in base 10 for 64-bit floating-point + ## numbers. +template max10Exponent*(T : typedesc[float64]) : int = DBL_MAX_10_EXP + ## Maximum (positive) exponent in base 10 for 64-bit floating-point + ## numbers. +template minimumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MIN + ## The smallest positive (nonzero) number that can be represented in a + ## 64-bit floating-point type. +template maximumPositiveValue*(T : typedesc[float64]) : float64 = DBL_MAX + ## The largest positive number that can be represented in a 64-bit + ## floating-point type. +template epsilon*(T : typedesc[float64]): float64 = DBL_EPSILON + ## The difference between 1.0 and the smallest number greater than + ## 1.0 that can be represented in a 64-bit floating-point type. diff --git a/lib/pure/logging.nim b/lib/pure/logging.nim index b64437c89..16c36e1f0 100644 --- a/lib/pure/logging.nim +++ b/lib/pure/logging.nim @@ -217,7 +217,7 @@ method log*(logger: RollingFileLogger, level: Level, logger.curLine = 0 logger.f = open(logger.baseName, logger.baseMode) - writeln(logger.f, LevelNames[level], " ", frmt % args) + writeln(logger.f, LevelNames[level], " ",substituteLog(logger.fmtStr), frmt % args) logger.curLine.inc # -------- diff --git a/lib/pure/os.nim b/lib/pure/os.nim index d2e112c18..82d6177e1 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1121,8 +1121,8 @@ when defined(windows): else: const - useNSGetEnviron = defined(macosx) and - (defined(createNimRtl) or defined(useNimRtl)) + useNSGetEnviron = defined(macosx) + when useNSGetEnviron: # From the manual: # Shared libraries and bundles don't have direct access to environ, diff --git a/lib/pure/redis.nim b/lib/pure/redis.nim index 64d3e1470..9177ddee5 100644 --- a/lib/pure/redis.nim +++ b/lib/pure/redis.nim @@ -285,6 +285,30 @@ proc keys*(r: Redis, pattern: string): RedisList = r.sendCommand("KEYS", pattern) return r.readArray() +proc scan*(r: Redis, cursor: var BiggestInt): RedisList = + ## Find all keys matching the given pattern and yield it to client in portions + ## using default Redis values for MATCH and COUNT parameters + r.sendCommand("SCAN", $cursor) + let reply = r.readArray() + cursor = strutils.parseBiggestInt(reply[0]) + return reply[1..high(reply)] + +proc scan*(r: Redis, cursor: var BiggestInt, pattern: string): RedisList = + ## Find all keys matching the given pattern and yield it to client in portions + ## using cursor as a client query identifier. Using default Redis value for COUNT argument + r.sendCommand("SCAN", $cursor, ["MATCH", pattern]) + let reply = r.readArray() + cursor = strutils.parseBiggestInt(reply[0]) + return reply[1..high(reply)] + +proc scan*(r: Redis, cursor: var BiggestInt, pattern: string, count: int): RedisList = + ## Find all keys matching the given pattern and yield it to client in portions + ## using cursor as a client query identifier. + r.sendCommand("SCAN", $cursor, ["MATCH", pattern, "COUNT", $count]) + let reply = r.readArray() + cursor = strutils.parseBiggestInt(reply[0]) + return reply[1..high(reply)] + proc move*(r: Redis, key: string, db: int): bool = ## Move a key to another database. Returns `true` on a successful move. r.sendCommand("MOVE", key, $db) diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 15b00f8f1..3b55f62ca 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -322,10 +322,10 @@ when defined(kwin): } print(buf); """ - + elif defined(nodejs): proc ewriteln(x: cstring) = log(x) - + proc rawEcho {.compilerproc, asmNoStackFrame.} = asm """ var buf = ""; @@ -339,12 +339,12 @@ else: var document {.importc, nodecl.}: ref TDocument - proc ewriteln(x: cstring) = + proc ewriteln(x: cstring) = var node = document.getElementsByTagName("body")[0] - if node != nil: + if node != nil: node.appendChild(document.createTextNode(x)) node.appendChild(document.createElement("br")) - else: + else: raise newException(ValueError, "<body> element does not exist yet!") proc rawEcho {.compilerproc.} = @@ -563,7 +563,11 @@ proc nimCopy(x: pointer, ti: PNimType): pointer = } """ of tyString: - asm "`result` = `x`.slice(0);" + asm """ + if (`x` !== null) { + `result` = `x`.slice(0); + } + """ else: result = x @@ -679,7 +683,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, start = 0): int { if s[i] == 'I' or s[i] == 'i': if s[i+1] == 'N' or s[i+1] == 'n': if s[i+2] == 'F' or s[i+2] == 'f': - if s[i+3] notin IdentChars: + if s[i+3] notin IdentChars: number = Inf*sign return i+3 - start return 0 diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 48adb895d..468af1713 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -154,7 +154,7 @@ proc readAll(file: File): TaintedString = proc readFile(filename: string): TaintedString = var f = open(filename) try: - result = readAllFile(f).TaintedString + result = readAll(f).TaintedString finally: close(f) diff --git a/lib/system/threads.nim b/lib/system/threads.nim index 81d9e5d73..d8e011ecb 100644 --- a/lib/system/threads.nim +++ b/lib/system/threads.nim @@ -127,7 +127,7 @@ else: importc, header: "<pthread.h>".} proc pthread_create(a1: var TSysThread, a2: var TPthread_attr, - a3: proc (x: pointer) {.noconv.}, + a3: proc (x: pointer): pointer {.noconv.}, a4: pointer): cint {.importc: "pthread_create", header: "<pthread.h>".} proc pthread_join(a1: TSysThread, a2: ptr pointer): cint {. @@ -315,7 +315,7 @@ when defined(windows): threadProcWrapperBody(closure) # implicitly return 0 else: - proc threadProcWrapper[TArg](closure: pointer) {.noconv.} = + proc threadProcWrapper[TArg](closure: pointer): pointer {.noconv.} = threadProcWrapperBody(closure) {.pop.} diff --git a/tests/cpp/tthread_createthread.nim b/tests/cpp/tthread_createthread.nim new file mode 100644 index 000000000..0dc081268 --- /dev/null +++ b/tests/cpp/tthread_createthread.nim @@ -0,0 +1,14 @@ +discard """ + cmd: "nim cpp --hints:on --threads:on $options $file" +""" + +proc threadMain(a: int) {.thread.} = + discard + +proc main() = + var thread: TThread[int] + + thread.createThread(threadMain, 0) + thread.joinThreads() + +main() \ No newline at end of file diff --git a/tests/js/taddr.nim b/tests/js/taddr.nim new file mode 100644 index 000000000..6a60aa902 --- /dev/null +++ b/tests/js/taddr.nim @@ -0,0 +1,36 @@ +type T = object + x: int + s: string + +var obj: T +var fieldAddr = addr(obj.x) +var objAddr = addr(obj) + +# Integer tests +var field = fieldAddr[] +doAssert field == 0 + +var objDeref = objAddr[] +doAssert objDeref.x == 0 + +# Change value +obj.x = 42 + +doAssert field == 0 +doAssert objDeref.x == 0 + +field = fieldAddr[] +objDeref = objAddr[] + +doAssert field == 42 +doAssert objDeref.x == 42 + +# String tests +obj.s = "lorem ipsum dolor sit amet" +var indexAddr = addr(obj.s[2]) + +doAssert indexAddr[] == '4' + +indexAddr[] = 'd' + +doAssert indexAddr[] == 'd' diff --git a/tests/types/tinfiniterecursion.nim b/tests/types/tinfiniterecursion.nim new file mode 100644 index 000000000..52eaaa93b --- /dev/null +++ b/tests/types/tinfiniterecursion.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "illegal recursion in type 'XIM'" + line: 8 +""" + +type + XIM* = ptr XIM + XIMProc* = proc (a2: XIM) diff --git a/todo.txt b/todo.txt index 31c3a46db..b77c276b7 100644 --- a/todo.txt +++ b/todo.txt @@ -3,7 +3,6 @@ version 0.10.4 - improve GC-unsafety warnings - make 'nil' work for 'add' and 'len' -- get rid of 'mget'; aka priority of 'var' needs to be 'var{lvalue}' - disallow negative indexing - improve the parser; deal with echo $foo gotcha @@ -59,9 +58,9 @@ Bugs version 0.9.x ============= +- pragmas need 'bindSym' support - allow simple read accesses to global variables --> difficult to ensure that no data races happen -- pragmas need 'bindSym' support - pragmas need re-work: 'push' is dangerous, 'hasPragma' does not work reliably with user-defined pragmas - memory manager: add a measure of fragmentation @@ -76,7 +75,6 @@ version 0.9.X ============= - macros as type pragmas -- document how lazy overloading resolution works - document NimMain and check whether it works for threading GC diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl index 980915be3..52da351be 100644 --- a/tools/niminst/buildsh.tmpl +++ b/tools/niminst/buildsh.tmpl @@ -1,7 +1,7 @@ #! stdtmpl(subsChar='?') | standard #proc generateBuildShellScript(c: ConfigData): string = # result = "#! /bin/sh\n# Generated from niminst\n" & -# "# Template is in tools/buildsh.tmpl\n" & +# "# Template is in tools/niminst/buildsh.tmpl\n" & # "# To regenerate run ``niminst csource`` or ``koch csource``\n" set -e @@ -111,7 +111,7 @@ case $ucpu in LINK_FLAGS="$LINK_FLAGS -m64" fi mycpu="powerpc64" ;; - *power*|*Power*|*ppc* ) + *power*|*ppc* ) mycpu="powerpc" ;; *mips* ) mycpu="mips" ;; diff --git a/tools/niminst/makefile.tmpl b/tools/niminst/makefile.tmpl new file mode 100644 index 000000000..8ab3b89d1 --- /dev/null +++ b/tools/niminst/makefile.tmpl @@ -0,0 +1,168 @@ +#! stdtmpl(subsChar='?') | standard +#proc generateMakefile(c: ConfigData): string = +# result = "# Generated from niminst\n" & +# "# Template is in tools/niminst/makefile.tmpl\n" & +# "# To regenerate run ``niminst csource`` or ``koch csource``\n" + +CC = gcc +LINKER = gcc +COMP_FLAGS = ?{c.ccompiler.flags} +LINK_FLAGS = ?{c.linker.flags} +binDir = ?{firstBinPath(c).toUnix} + +koch := $(shell sh -c 'test -s ../koch.nim && echo "yes"') +ifeq ($(koch),yes) + binDir = ../bin +endif + +ucpu := $(shell sh -c 'uname -m | tr "[:upper:]" "[:lower:]"') +uos := $(shell sh -c 'uname | tr "[:upper:]" "[:lower:]"') + +ifeq ($(uos),linux) + myos = linux + LINK_FLAGS += -ldl -lm +endif +ifeq ($(uos),dragonfly) + myos = freebsd + LINK_FLAGS += -lm +endif +ifeq ($(uos),freebsd) + myos= freebsd + CC = clang + LINKER = clang + LINK_FLAGS += -lm +endif +ifeq ($(uos),openbsd) + myos = openbsd + LINK_FLAGS += -lm +endif +ifeq ($(uos),netbsd) + myos = netbsd + LINK_FLAGS += -lm +endif +ifeq ($(uos),darwin) + myos = macosx + CC = clang + LINKER = clang + LINK_FLAGS += -ldl -lm + ifeq ($HOSTTYPE,x86_64) + ucpu = amd64 + endif +endif +ifeq ($(uos),aix) + myos = aix + LINK_FLAGS += -dl -lm +endif +ifeq ($(uos),solaris) + myos = solaris + LINK_FLAGS += -ldl -lm -lsocket -lnsl +endif +ifeq ($(uos),sun) + myos = solaris + LINK_FLAGS += -ldl -lm -lsocket -lnsl +endif +ifeq ($(uos),haiku) + myos = haiku +endif +ifndef uos + @echo "Error: unknown operating system: $(uos)" + @exit 1 +endif + +ifeq ($(ucpu),i386) + mycpu = i386 +endif +ifeq ($(ucpu),i486) + mycpu = i386 +endif +ifeq ($(ucpu),i586) + mycpu = i386 +endif +ifeq ($(ucpu),i686) + mycpu = i386 +endif +ifeq ($(ucpu),bepc) + mycpu = i386 +endif +ifeq ($(ucpu),i86pc) + mycpu = i386 +endif +ifeq ($(ucpu),amd64) + mycpu = amd64 +endif +ifeq ($(ucpu),x86-64) + mycpu = amd64 +endif +ifeq ($(ucpu),x86_64) + mycpu = amd64 +endif +ifeq ($(ucpu),sparc) + mycpu = sparc +endif +ifeq ($(ucpu),sun) + mycpu = sparc +endif +ifeq ($(ucpu),ppc64) + mycpu = powerpc64 + ifeq ($(myos),linux) + COMP_FLAGS += -m64 + LINK_FLAGS += -m64 + endif +endif +ifeq ($(ucpu),powerpc) + mycpu = powerpc +endif +ifeq ($(ucpu),ppc) + mycpu = ppc +endif +ifeq ($(ucpu),mips) + mycpu = mips +endif +ifeq ($(ucpu),arm) + mycpu = arm +endif +ifeq ($(ucpu),armeb) + mycpu = arm +endif +ifeq ($(ucpu),armel) + mycpu = arm +endif +ifeq ($(ucpu),armv6l) + mycpu = arm +endif +ifndef ucpu + @echo "Error: unknown processor : $(ucpu)" + @exit 1 +endif + +# for osA in 1..c.oses.len: +ifeq ($(myos),?{c.oses[osA-1]}) +# for cpuA in 1..c.cpus.len: + ifeq ($(mycpu),?{c.cpus[cpuA-1]}) +# var oFiles = "" +# for ff in c.cfiles[osA][cpuA].items: +# oFiles.add(" " & changeFileExt(ff.toUnix, "o")) +# end for + oFiles =?oFiles + endif +# end for +endif +# end for + +ifeq ($(strip $(oFiles)),) + @echo "Error: no C code generated for: [$(myos): $(mycpu)]" + @exit 1 +endif + +%.o: %.c + $(CC) $(COMP_FLAGS) -Ic_code -c $< -o $@ + +?{"$(binDir)/" & toLower(c.name)}: $(oFiles) + @mkdir -p $(binDir) + $(LINKER) -o $@ $^ $(LINK_FLAGS) + @echo "SUCCESS" + +.PHONY: clean + +clean: + rm -f $(oFiles) ?{"$(binDir)/" & toLower(c.name)} diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim index 357c1ffbc..e50b251d3 100644 --- a/tools/niminst/niminst.nim +++ b/tools/niminst/niminst.nim @@ -22,6 +22,7 @@ const buildShFile = "build.sh" buildBatFile32 = "build.bat" buildBatFile64 = "build64.bat" + makeFile = "makefile" installShFile = "install.sh" deinstallShFile = "deinstall.sh" @@ -56,7 +57,7 @@ type platforms: array[1..maxOS, array[1..maxCPU, bool]] ccompiler, linker, innosetup, nsisSetup: tuple[path, flags: string] name, displayName, version, description, license, infile, outdir: string - libpath: string + mainfile, libpath: string innoSetupFlag, installScript, uninstallScript: bool explicitPlatforms: bool vars: StringTableRef @@ -87,6 +88,7 @@ proc iniConfigData(c: var ConfigData) = c.description = "" c.license = "" c.infile = "" + c.mainfile = "" c.outdir = "" c.nimArgs = "" c.libpath = "" @@ -122,6 +124,7 @@ proc skipRoot(f: string): string = include "inno.tmpl" include "nsis.tmpl" include "buildsh.tmpl" +include "makefile.tmpl" include "buildbat.tmpl" include "install.tmpl" include "deinstall.tmpl" @@ -144,6 +147,8 @@ Command: deb create files for debhelper Options: -o, --output:dir set the output directory + -m, --main:file set the main nim file, by default ini-file with .nim + extension --var:name=value set the value of a variable -h, --help shows this help -v, --version shows the version @@ -183,6 +188,7 @@ proc parseCmdLine(c: var ConfigData) = stdout.write(Version & "\n") quit(0) of "o", "output": c.outdir = val + of "m", "main": c.mainfile = changeFileExt(val, "nim") of "var": var idx = val.find('=') if idx < 0: quit("invalid command line") @@ -190,6 +196,7 @@ proc parseCmdLine(c: var ConfigData) = else: quit(Usage) of cmdEnd: break if c.infile.len == 0: quit(Usage) + if c.mainfile.len == 0: c.mainfile = changeFileExt(c.infile, "nim") proc walkDirRecursively(s: var seq[string], root: string) = for k, f in walkDir(root): @@ -358,7 +365,7 @@ proc parseIniFile(c: var ConfigData) = of cfgOption: quit(errorStr(p, "syntax error")) of cfgError: quit(errorStr(p, k.msg)) close(p) - if c.name.len == 0: c.name = changeFileExt(extractFilename(c.infile), "") + if c.name.len == 0: c.name = changeFileExt(extractFilename(c.mainfile), "") if c.displayName.len == 0: c.displayName = c.name else: quit("cannot open: " & c.infile) @@ -436,8 +443,10 @@ proc removeDuplicateFiles(c: var ConfigData) = proc writeInstallScripts(c: var ConfigData) = if c.installScript: writeFile(installShFile, generateInstallScript(c), "\10") + inclFilePermissions(installShFile, {fpUserExec, fpGroupExec, fpOthersExec}) if c.uninstallScript: writeFile(deinstallShFile, generateDeinstallScript(c), "\10") + inclFilePermissions(deinstallShFile, {fpUserExec, fpGroupExec, fpOthersExec}) proc srcdist(c: var ConfigData) = if not existsDir(getOutputDir(c) / "c_code"): @@ -462,8 +471,7 @@ proc srcdist(c: var ConfigData) = var cmd = ("nim compile -f --symbolfiles:off --compileonly " & "--gen_mapping --cc:gcc --skipUserCfg" & " --os:$# --cpu:$# $# $#") % - [osname, cpuname, c.nimArgs, - changeFileExt(c.infile, "nim")] + [osname, cpuname, c.nimArgs, c.mainfile] echo(cmd) if execShellCmd(cmd) != 0: quit("Error: call to nim compiler failed") @@ -476,6 +484,8 @@ proc srcdist(c: var ConfigData) = # second pass: remove duplicate files removeDuplicateFiles(c) writeFile(getOutputDir(c) / buildShFile, generateBuildShellScript(c), "\10") + inclFilePermissions(getOutputDir(c) / buildShFile, {fpUserExec, fpGroupExec, fpOthersExec}) + writeFile(getOutputDir(c) / makeFile, generateMakefile(c), "\10") if winIndex >= 0: if intel32Index >= 0: writeFile(getOutputDir(c) / buildBatFile32, @@ -531,6 +541,7 @@ when haveZipLib: addFile(z, proj / buildBatFile32, "build" / buildBatFile32) addFile(z, proj / buildBatFile64, "build" / buildBatFile64) addFile(z, proj / buildShFile, "build" / buildShFile) + addFile(z, proj / makeFile, "build" / makeFile) addFile(z, proj / installShFile, installShFile) addFile(z, proj / deinstallShFile, deinstallShFile) for f in walkFiles(c.libpath / "lib/*.h"): @@ -571,6 +582,7 @@ proc debDist(c: var ConfigData) = # Don't copy all files, only the ones specified in the config: copyNimDist(buildShFile, buildShFile) + copyNimDist(makeFile, makeFile) copyNimDist(installShFile, installShFile) createDir(workingDir / upstreamSource / "build") for f in walkFiles(c.libpath / "lib/*.h"): diff --git a/web/news.txt b/web/news.txt index aa093be46..7cf1ae28f 100644 --- a/web/news.txt +++ b/web/news.txt @@ -3,8 +3,8 @@ News ==== .. - 2015-03-01 Version 1.0.0 released - ================================= + 2015-03-01 Version 0.10.4 released + ================================== Changes affecting backwards compatibility @@ -23,7 +23,7 @@ News - *arrow like* operators are not right associative anymore. - Typeless parameters are now only allowed in templates and macros. The old way turned out to be too error-prone. - + Language Additions ------------------ @@ -46,14 +46,230 @@ News - Ordinary parameters can follow after a varargs parameter. This means the following is finally accepted by the compiler: - .. code-block:: nim + .. code-block:: nim template takesBlock(a, b: int, x: varargs[expr]; blck: stmt) = blck echo a, b takesBlock 1, 2, "some", 0.90, "random stuff": echo "yay" - + + - Overloading by 'var T' is now finally possible: + + .. code-block:: nim + proc varOrConst(x: var int) = echo "var" + proc varOrConst(x: int) = echo "const" + + var x: int + varOrConst(x) # "var" + varOrConst(45) # "const" + + + Library additions + ----------------- + + - ``reversed`` proc added to the ``unicode`` module. + - Added multipart param to httpclient's ``post`` and ``postContent`` together + with a ``newMultipartData`` proc. + - Added `%*` operator for JSON. + - The compiler is now available as Nimble package for c2nim. + + + Bugfixes + -------- + + - Fixed internal compiler error when using ``char()`` in an echo call + (`#1788 <https://github.com/Araq/Nim/issues/1788>`_). + - Fixed Windows cross-compilation on Linux. + - Overload resolution now works for types distinguished only by a + ``static[int]`` param + (`#1056 <https://github.com/Araq/Nim/issues/1056>`_). + - Other fixes relating to generic types and static params. + - Fixed some compiler crashes with unnamed tuples + (`#1774 <https://github.com/Araq/Nim/issues/1774>`_). + - Fixed ``channels.tryRecv`` blocking + (`#1816 <https://github.com/Araq/Nim/issues/1816>`_). + - Fixed generic instantiation errors with ``typedesc`` + (`#419 <https://github.com/Araq/Nim/issues/419>`_). + - Fixed generic regression where the compiler no longer detected constant + expressions properly (`#544 <https://github.com/Araq/Nim/issues/544>`_). + - Fixed internal error with generic proc using ``static[T]`` in a specific + way (`#1049 <https://github.com/Araq/Nim/issues/1049>`_). + - More fixes relating to generics + (`#1820 <https://github.com/Araq/Nim/issues/1820>`_, + `#1050 <https://github.com/Araq/Nim/issues/1050>`_, + `#1859 <https://github.com/Araq/Nim/issues/1859>`_, + `#1858 <https://github.com/Araq/Nim/issues/1858>`_). + - Fixed httpclient to properly encode queries. + - Many fixes to the ``uri`` module. + - Async sockets are now closed on error. + - Fixes to httpclient's handling of multipart data. + - Fixed GC segfaults with asynchronous sockets + (`#1796 <https://github.com/Araq/Nim/issues/1796>`_). + - Added more versions to openssl's DLL version list + (`076f993 <https://github.com/Araq/Nim/commit/076f993>`_). + - Fixed shallow copy in iterators being broken + (`#1803 <https://github.com/Araq/Nim/issues/1803>`_). + - ``nil`` can now be inserted into tables with the ``db_sqlite`` module + (`#1866 <https://github.com/Araq/Nim/issues/1866>`_). + - Fixed "Incorrect assembler generated" + (`#1907 <https://github.com/Araq/Nim/issues/1907>`_) + - Fixed "Expression templates that define macros are unusable in some contexts" + (`#1903 <https://github.com/Araq/Nim/issues/1903>`_) + - Fixed "a second level generic subclass causes the compiler to crash" + (`#1919 <https://github.com/Araq/Nim/issues/1919>`_) + - Fixed "nim 0.10.2 generates invalid AsyncHttpClient C code for MSVC " + (`#1901 <https://github.com/Araq/Nim/issues/1901>`_) + - Fixed "1 shl n produces wrong C code" + (`#1928 <https://github.com/Araq/Nim/issues/1928>`_) + - Fixed "Internal error on tuple yield" + (`#1838 <https://github.com/Araq/Nim/issues/1838>`_) + - Fixed "ICE with template" + (`#1915 <https://github.com/Araq/Nim/issues/1915>`_) + - Fixed "include the tool directory in the installer as it is required by koch" + (`#1947 <https://github.com/Araq/Nim/issues/1947>`_) + - Fixed "Can't compile if file location contains spaces on Windows" + (`#1955 <https://github.com/Araq/Nim/issues/1955>`_) + - Fixed "List comprehension macro only supports infix checks as guards" + (`#1920 <https://github.com/Araq/Nim/issues/1920>`_) + - Fixed "wrong field names of compatible tuples in generic types" + (`#1910 <https://github.com/Araq/Nim/issues/1910>`_) + - Fixed "Macros within templates no longer work as expected" + (`#1944 <https://github.com/Araq/Nim/issues/1944>`_) + - Fixed "Compiling for Standalone AVR broken in 0.10.2" + (`#1964 <https://github.com/Araq/Nim/issues/1964>`_) + - Fixed "Compiling for Standalone AVR broken in 0.10.2" + (`#1964 <https://github.com/Araq/Nim/issues/1964>`_) + - Fixed "Code generation for mitems with tuple elements" + (`#1833 <https://github.com/Araq/Nim/issues/1833>`_) + - Fixed "httpclient.HttpMethod should not be an enum" + (`#1962 <https://github.com/Araq/Nim/issues/1962>`_) + - Fixed "terminal / eraseScreen() throws an OverflowError" + (`#1906 <https://github.com/Araq/Nim/issues/1906>`_) + - Fixed "setControlCHook(nil) disables registered quit procs" + (`#1546 <https://github.com/Araq/Nim/issues/1546>`_) + - Fixed "Unexpected idetools behaviour" + (`#325 <https://github.com/Araq/Nim/issues/325>`_) + - Fixed "Unused lifted lambda does not compile" + (`#1642 <https://github.com/Araq/Nim/issues/1642>`_) + - Fixed "'low' and 'high' don't work with cstring asguments" + (`#2030 <https://github.com/Araq/Nim/issues/2030>`_) + - Fixed "Converting to int does not round in JS backend" + (`#1959 <https://github.com/Araq/Nim/issues/1959>`_) + - Fixed "Internal error genRecordField 2 when adding region to pointer." + (`#2039 <https://github.com/Araq/Nim/issues/2039>`_) + - Fixed "Macros fail to compile when compiled with --os:standalone" + (`#2041 <https://github.com/Araq/Nim/issues/2041>`_) + - Fixed "Reading from {.compileTime.} variables can cause code generation to fail" + (`#2022 <https://github.com/Araq/Nim/issues/2022>`_) + - Fixed "Passing overloaded symbols to templates fails inside generic procedures" + (`#1988 <https://github.com/Araq/Nim/issues/1988>`_) + - Fixed "Compiling iterator with object assignment in release mode causes "var not init"" + (`#2023 <https://github.com/Araq/Nim/issues/2023>`_) + - Fixed "calling a large number of macros doing some computation fails" + (`#1989 <https://github.com/Araq/Nim/issues/1989>`_) + - Fixed "Can't get Koch to install nim under Windows" + (`#2061 <https://github.com/Araq/Nim/issues/2061>`_) + - Fixed "Template with two stmt parameters segfaults compiler" + (`#2057 <https://github.com/Araq/Nim/issues/2057>`_) + - Fixed "`noSideEffect` not affected by `echo`" + (`#2011 <https://github.com/Araq/Nim/issues/2011>`_) + - Fixed "Compiling with the cpp backend ignores --passc" + (`#1601 <https://github.com/Araq/Nim/issues/1601>`_) + - Fixed "Put untyped procedure parameters behind the experimental pragma" + (`#1956 <https://github.com/Araq/Nim/issues/1956>`_) + - Fixed "generic regression" + (`#2073 <https://github.com/Araq/Nim/issues/2073>`_) + - Fixed "generic regression" + (`#2073 <https://github.com/Araq/Nim/issues/2073>`_) + - Fixed "Regression in template lookup with generics" + (`#2004 <https://github.com/Araq/Nim/issues/2004>`_) + - Fixed "GC's growObj is wrong for edge cases" + (`#2070 <https://github.com/Araq/Nim/issues/2070>`_) + - Fixed "Compiler internal error when creating an array out of a typeclass" + (`#1131 <https://github.com/Araq/Nim/issues/1131>`_) + - Fixed "GC's growObj is wrong for edge cases" + (`#2070 <https://github.com/Araq/Nim/issues/2070>`_) + - Fixed "Invalid Objective-C code generated when calling class method" + (`#2068 <https://github.com/Araq/Nim/issues/2068>`_) + - Fixed "walkDirRec Error" + (`#2116 <https://github.com/Araq/Nim/issues/2116>`_) + - Fixed "Typo in code causes compiler SIGSEGV in evalAtCompileTime" + (`#2113 <https://github.com/Araq/Nim/issues/2113>`_) + - Fixed "Regression on exportc" + (`#2118 <https://github.com/Araq/Nim/issues/2118>`_) + - Fixed "Error message" + (`#2102 <https://github.com/Araq/Nim/issues/2102>`_) + - Fixed "hint[path] = off not working in nim.cfg" + (`#2103 <https://github.com/Araq/Nim/issues/2103>`_) + - Fixed "compiler crashes when getting a tuple from a sequence of generic tuples" + (`#2121 <https://github.com/Araq/Nim/issues/2121>`_) + - Fixed "nim check hangs with when" + (`#2123 <https://github.com/Araq/Nim/issues/2123>`_) + - Fixed "static[T] param in nested type resolve/caching issue" + (`#2125 <https://github.com/Araq/Nim/issues/2125>`_) + - Fixed "repr should display ``\0``" + (`#2124 <https://github.com/Araq/Nim/issues/2124>`_) + - Fixed "'nim check' never ends in case of recursive dependency " + (`#2051 <https://github.com/Araq/Nim/issues/2051>`_) + - Fixed "From macros: Error: unhandled exception: sons is not accessible" + (`#2167 <https://github.com/Araq/Nim/issues/2167>`_) + - Fixed "`fieldPairs` doesn't work inside templates" + (`#1902 <https://github.com/Araq/Nim/issues/1902>`_) + - Fixed "fields iterator misbehavior on break statement" + (`#2134 <https://github.com/Araq/Nim/issues/2134>`_) + - Fixed "Fix for compiler not building anymore since #c3244ef1ff" + (`#2193 <https://github.com/Araq/Nim/issues/2193>`_) + - Fixed "JSON parser fails in cpp output mode" + (`#2199 <https://github.com/Araq/Nim/issues/2199>`_) + - Fixed "macros.getType mishandles void return" + (`#2211 <https://github.com/Araq/Nim/issues/2211>`_) + - Fixed "Regression involving templates instantiated within generics" + (`#2215 <https://github.com/Araq/Nim/issues/2215>`_) + - Fixed ""Error: invalid type" for 'not nil' on generic type." + (`#2216 <https://github.com/Araq/Nim/issues/2216>`_) + - Fixed "--threads:on breaks async" + (`#2074 <https://github.com/Araq/Nim/issues/2074>`_) + - Fixed "Type mismatch not always caught, can generate bad code for C backend." + (`#2169 <https://github.com/Araq/Nim/issues/2169>`_) + - Fixed "Failed C compilation when storing proc to own type in object" + (`#2233 <https://github.com/Araq/Nim/issues/2233>`_) + - Fixed "Unknown line/column number in constant declaration type conversion error" + (`#2252 <https://github.com/Araq/Nim/issues/2252>`_) + - Fixed "Adding {.compile.} fails if nimcache already exists." + (`#2247 <https://github.com/Araq/Nim/issues/2247>`_) + - Fixed "Two different type names generated for a single type (C backend)" + (`#2250 <https://github.com/Araq/Nim/issues/2250>`_) + - Fixed "Ambigous call when it should not be" + (`#2229 <https://github.com/Araq/Nim/issues/2229>`_) + - Fixed "Make sure we can load root urls" + (`#2227 <https://github.com/Araq/Nim/issues/2227>`_) + - Fixed "Failure to slice a string with an int subrange type" + (`#794 <https://github.com/Araq/Nim/issues/794>`_) + - Fixed "documentation error" + (`#2205 <https://github.com/Araq/Nim/issues/2205>`_) + - Fixed "Code growth when using `const`" + (`#1940 <https://github.com/Araq/Nim/issues/1940>`_) + - Fixed "Instances of generic types confuse overload resolution" + (`#2220 <https://github.com/Araq/Nim/issues/2220>`_) + - Fixed "Compiler error when initializing sdl2's EventType" + (`#2316 <https://github.com/Araq/Nim/issues/2316>`_) + - Fixed "Parallel disjoint checking can't handle `<`, `items`, or arrays" + (`#2287 <https://github.com/Araq/Nim/issues/2287>`_) + - Fixed "Strings aren't copied in parallel loop" + (`#2286 <https://github.com/Araq/Nim/issues/2286>`_) + - Fixed "JavaScript compiler crash with tables" + (`#2298 <https://github.com/Araq/Nim/issues/2298>`_) + - Fixed "Range checker too restrictive" + (`#1845 <https://github.com/Araq/Nim/issues/1845>`_) + - Fixed "Failure to slice a string with an int subrange type" + (`#794 <https://github.com/Araq/Nim/issues/794>`_) + - Fixed "Remind user when compiling in debug mode" + (`#1868 <https://github.com/Araq/Nim/issues/1868>`_) + - Fixed "Compiler user guide has jumbled options/commands." + (`#1819 <https://github.com/Araq/Nim/issues/1819>`_) + - Fixed "using `method`: 1 in a objects constructor fails when compiling" + (`#1791 <https://github.com/Araq/Nim/issues/1791>`_) 2014-12-29 Version 0.10.2 released ================================== @@ -253,8 +469,8 @@ Bugfixes 2014-12-09 New website design! ============================== -A brand new website including an improved forum is now live. -All thanks go to Philip Witte and +A brand new website including an improved forum is now live. +All thanks go to Philip Witte and Dominik Picheta, Philip Witte for the design of the website (together with the logo) as well as the HTML and CSS code for his template, and Dominik Picheta for integrating Philip's design with Nim's forum. We're sure you will @@ -321,7 +537,7 @@ Library Additions - ``sequtils.distnct`` has been renamed to ``sequtils.deduplicate``. - Added ``algorithm.reversed`` - Added ``uri.combine`` and ``uri.parseUri``. -- Some sockets procedures now support a ``SafeDisconn`` flag which causes +- Some sockets procedures now support a ``SafeDisconn`` flag which causes them to handle disconnection errors and not raise them. @@ -336,7 +552,7 @@ unfortunately some do not fulfill our quality standards yet.** Prebuilt binaries and instructions for building from source are available on the `download page <download.html>`_. -This release includes about +This release includes about `1400 changes <https://github.com/Araq/Nimrod/compare/v0.9.2...v0.9.4>`_ in total including various bug fixes, new languages features and standard library additions and improvements. @@ -395,10 +611,10 @@ Note that this feature has been implemented with Nimrod's macro system and so Syntactic sugar for anonymous procedures has also been introduced. It too has been implemented as a macro. The following shows some simple usage of the new syntax: - + .. code-block::nim import future - + var s = @[1, 2, 3, 4, 5] echo(s.map((x: int) => x * 5)) @@ -425,14 +641,14 @@ Library Additions Changes affecting backwards compatibility ----------------------------------------- -- The scoping rules for the ``if`` statement changed for better interaction +- The scoping rules for the ``if`` statement changed for better interaction with the new syntactic construct ``(;)``. - ``OSError`` family of procedures has been deprecated. Procedures with the same name but which take different parameters have been introduced. These procs now require an error code to be passed to them. This error code can be retrieved using the new ``OSLastError`` proc. - ``os.parentDir`` now returns "" if there is no parent dir. -- In CGI scripts stacktraces are shown to the user only +- In CGI scripts stacktraces are shown to the user only if ``cgi.setStackTraceStdout`` is used. - The symbol binding rules for clean templates changed: ``bind`` for any symbol that's not a parameter is now the default. ``mixin`` can be used @@ -466,7 +682,7 @@ Compiler Additions evaluation. - ``--gc:none`` produces warnings when code uses the GC. - A ``union`` pragma for better C interoperability is now supported. -- A ``packed`` pragma to control the memory packing/alignment of fields in +- A ``packed`` pragma to control the memory packing/alignment of fields in an object. - Arrays can be annotated to be ``unchecked`` for easier low level manipulations of memory. @@ -515,13 +731,13 @@ as the cover story in the February 2014 issue of Dr. Dobb's Journal. Andreas Rumpf presented *Nimrod: A New Approach to Metaprogramming* at `Strange Loop 2013<https://thestrangeloop.com/sessions/nimrod-a-new-approach-to-meta-programming>`_. The `video and slides<http://www.infoq.com/presentations/nimrod>`_ -of the talk are now available. +of the talk are now available. 2013-05-20 New website design! ============================== -A brand new website is now live. All thanks go to Philip Witte and +A brand new website is now live. All thanks go to Philip Witte and Dominik Picheta, Philip Witte for the design of the website (together with the logo) as well as the HTML and CSS code for his template, and Dominik Picheta for integrating Philip's design with the ``nimweb`` utility. We're sure you will @@ -537,7 +753,7 @@ to any other release. This release brings with it many new features and bug fixes, a list of which can be seen later. One of the major new features is the effect system together -with exception tracking which allows for checked exceptions and more, +with exception tracking which allows for checked exceptions and more, for further details check out the `manual <manual.html#effect-system>`_. Another major new feature is the introduction of statement list expressions, more details on these can be found `here <manual.html#statement-list-expression>`_. @@ -550,12 +766,12 @@ Bugfixes -------- - The old GC never collected cycles correctly. Fixed but it can cause - performance regressions. However you can deactivate the cycle collector - with ``GC_disableMarkAndSweep`` and run it explicitly at an appropriate time - or not at all. There is also a new GC you can activate + performance regressions. However you can deactivate the cycle collector + with ``GC_disableMarkAndSweep`` and run it explicitly at an appropriate time + or not at all. There is also a new GC you can activate with ``--gc:markAndSweep`` which does not have this problem but is slower in general and has no realtime guarantees. -- ``cast`` for floating point types now does the bitcast as specified in the +- ``cast`` for floating point types now does the bitcast as specified in the manual. This breaks code that erroneously uses ``cast`` to convert different floating point values. - SCGI module's performance has been improved greatly, it will no longer block @@ -566,7 +782,7 @@ Bugfixes Library Additions ----------------- -- There is a new experimental mark&sweep GC which can be faster (or much +- There is a new experimental mark&sweep GC which can be faster (or much slower) than the default GC. Enable with ``--gc:markAndSweep``. - Added ``system.onRaise`` to support a condition system. - Added ``system.locals`` that provides access to a proc's locals. @@ -603,41 +819,41 @@ Compiler Additions to be turned on explicitly via ``--warning[ShadowIdent]:on``. - The compiler now supports almost every pragma in a ``push`` pragma. - Generic converters have been implemented. -- Added a **highly experimental** ``noforward`` pragma enabling a special +- Added a **highly experimental** ``noforward`` pragma enabling a special compilation mode that largely eliminates the need for forward declarations. Language Additions ------------------ - ``case expressions`` are now supported. -- Table constructors now mimic more closely the syntax of the ``case`` +- Table constructors now mimic more closely the syntax of the ``case`` statement. - Nimrod can now infer the return type of a proc from its body. - Added a ``mixin`` declaration to affect symbol binding rules in generics. - Exception tracking has been added and the ``doc2`` command annotates possible exceptions for you. -- User defined effects ("tags") tracking has been added and the ``doc2`` +- User defined effects ("tags") tracking has been added and the ``doc2`` command annotates possible tags for you. - Types can be annotated with the new syntax ``not nil`` to explicitly state that ``nil`` is not allowed. However currently the compiler performs no advanced static checking for this; for now it's merely for documentation purposes. - An ``export`` statement has been added to the language: It can be used for - symbol forwarding so client modules don't have to import a module's + symbol forwarding so client modules don't have to import a module's dependencies explicitly. - Overloading based on ASTs has been implemented. - Generics are now supported for multi methods. - Objects can be initialized via an *object constructor expression*. -- There is a new syntactic construct ``(;)`` unifying expressions and +- There is a new syntactic construct ``(;)`` unifying expressions and statements. - You can now use ``from module import nil`` if you want to import the module but want to enforce fully qualified access to every symbol in ``module``. - + Notes for the future -------------------- -- The scope rules of ``if`` statements will change in 0.9.4. This affects the +- The scope rules of ``if`` statements will change in 0.9.4. This affects the ``=~`` pegs/re templates. - The ``sockets`` module will become a low-level wrapper of OS-specific socket functions. All the high-level features of the current ``sockets`` module @@ -681,14 +897,14 @@ Library Additions assignments. - Added ``system.eval`` that can execute an anonymous block of code at compile time as if was a macro. -- Added ``system.staticExec`` and ``system.gorge`` for compile-time execution +- Added ``system.staticExec`` and ``system.gorge`` for compile-time execution of external programs. - Added ``system.staticRead`` as a synonym for ``system.slurp``. - Added ``macros.emit`` that can emit an arbitrary computed string as nimrod code during compilation. - Added ``strutils.parseEnum``. - Added ``json.%`` constructor operator. -- The stdlib can now be avoided to a point where C code generation for 16bit +- The stdlib can now be avoided to a point where C code generation for 16bit micro controllers is feasible. - Added module ``oids``. - Added module ``endians``. @@ -704,7 +920,7 @@ Library Additions - Added ``strutils.continuesWith``. - Added ``system.getStackTrace``. - Added ``system.||`` for parallel ``for`` loop support. -- The GC supports (soft) realtime systems via ``GC_setMaxPause`` +- The GC supports (soft) realtime systems via ``GC_setMaxPause`` and ``GC_step`` procs. - The sockets module now supports ssl through the OpenSSL library, ``recvLine`` is now much more efficient thanks to the newly implemented sockets buffering. @@ -715,14 +931,14 @@ Library Additions only support fixed length arrays). - Added ``system.compiles`` which can be used to check whether a type supports some operation. -- Added ``strutils.format``, ``subexes.format`` which use the +- Added ``strutils.format``, ``subexes.format`` which use the new ``varargs`` type. - Added module ``fsmonitor``. Changes affecting backwards compatibility ----------------------------------------- -- On Windows filenames and paths are supposed to be in UTF-8. +- On Windows filenames and paths are supposed to be in UTF-8. The ``system``, ``os``, ``osproc`` and ``memfiles`` modules use the wide string versions of the WinAPI. Use the ``-d:useWinAnsi`` switch to revert back to the old behaviour which uses the Ansi string versions. @@ -747,21 +963,21 @@ Changes affecting backwards compatibility - Deprecated ``nimrod pretty`` as it never worked good enough and has some inherent problems. - The integer promotion rules changed; the compiler is now less picky in some - situations and more picky in other situations: In particular implicit + situations and more picky in other situations: In particular implicit conversions from ``int`` to ``int32`` are now forbidden. -- ``system.byte`` is now an alias for ``uint8``; it used to be an alias +- ``system.byte`` is now an alias for ``uint8``; it used to be an alias to ``int8``. - ``bind`` expressions in templates are not properly supported anymore. Use the declarative ``bind`` statement instead. - The default calling convention for a procedural **type** is now ``closure``, for procs it remains ``nimcall`` (which is compatible to ``closure``). - Activate the warning ``ImplicitClosure`` to make the compiler list the + Activate the warning ``ImplicitClosure`` to make the compiler list the occurrences of proc types which are affected. - The Nimrod type system now distinguishes ``openarray`` from ``varargs``. - Templates are now ``hygienic``. Use the ``dirty`` pragma to get the old behaviour. -- Objects that have no ancestor are now implicitly ``final``. Use - the ``inheritable`` pragma to introduce new object roots apart +- Objects that have no ancestor are now implicitly ``final``. Use + the ``inheritable`` pragma to introduce new object roots apart from ``TObject``. - Macros now receive parameters like templates do; use the ``callsite`` builtin to gain access to the invocation AST. @@ -772,14 +988,14 @@ Compiler Additions ------------------ - Win64 is now an officially supported target. -- The Nimrod compiler works on BSD again, but has some issues +- The Nimrod compiler works on BSD again, but has some issues as ``os.getAppFilename`` and ``os.getAppDir`` cannot work reliably on BSD. - The compiler can detect and evaluate calls that can be evaluated at compile time for optimization purposes with the ``--implicitStatic`` command line option or pragma. - The compiler now generates marker procs that the GC can use instead of RTTI. This speeds up the GC quite a bit. -- The compiler now includes a new advanced documentation generator +- The compiler now includes a new advanced documentation generator via the ``doc2`` command. This new generator uses all of the semantic passes of the compiler and can thus generate documentation for symbols hiding in macros. @@ -798,7 +1014,7 @@ Language Additions - Added ``global`` pragma that can be used to introduce new global variables from within procs. - ``when`` expressions are now allowed just like ``if`` expressions. -- The precedence for operators starting with ``@`` is different now +- The precedence for operators starting with ``@`` is different now allowing for *sigil-like* operators. - Stand-alone ``finally`` and ``except`` blocks are now supported. - Macros and templates can now be invoked as pragmas. @@ -806,7 +1022,7 @@ Language Additions - Unsigned integer types have been added. - The integer promotion rules changed. - Nimrod now tracks proper intervals for ``range`` over some built-in operators. -- In parameter lists a semicolon instead of a comma can be used to improve +- In parameter lists a semicolon instead of a comma can be used to improve readability: ``proc divmod(a, b: int; resA, resB: var int)``. - A semicolon can now be used to have multiple simple statements on a single line: ``inc i; inc j``. @@ -848,9 +1064,9 @@ Bugfixes Changes affecting backwards compatibility ----------------------------------------- -- Removed deprecated ``os.AppendFileExt``, ``os.executeShellCommand``, +- Removed deprecated ``os.AppendFileExt``, ``os.executeShellCommand``, ``os.iterOverEnvironment``, ``os.pcDirectory``, ``os.pcLinkToDirectory``, - ``os.SplitPath``, ``os.extractDir``, ``os.SplitFilename``, + ``os.SplitPath``, ``os.extractDir``, ``os.SplitFilename``, ``os.extractFileTrunk``, ``os.extractFileExt``, ``osproc.executeProcess``, ``osproc.executeCommand``. - Removed deprecated ``parseopt.init``, ``parseopt.getRestOfCommandLine``. @@ -860,7 +1076,7 @@ Changes affecting backwards compatibility - ``implies`` is no keyword anymore. - The ``is`` operator is now the ``of`` operator. - The ``is`` operator is now used to check type equivalence in generic code. -- The ``pure`` pragma for procs has been renamed to ``noStackFrame``. +- The ``pure`` pragma for procs has been renamed to ``noStackFrame``. - The threading API has been completely redesigned. - The ``unidecode`` module is now thread-safe and its interface has changed. - The ``bind`` expression is deprecated, use a ``bind`` declaration instead. @@ -870,13 +1086,13 @@ Changes affecting backwards compatibility - Changed exception handling/error reporting for ``os.removeFile`` and ``os.removeDir``. - The algorithm for searching and loading configuration files has been changed. -- Operators now have diffent precedence rules: Assignment-like operators - (like ``*=``) are now special-cased. -- The fields in ``TStream`` have been renamed to have an ``Impl`` suffix - because they should not be used directly anymore. +- Operators now have diffent precedence rules: Assignment-like operators + (like ``*=``) are now special-cased. +- The fields in ``TStream`` have been renamed to have an ``Impl`` suffix + because they should not be used directly anymore. Wrapper procs have been created that should be used instead. - ``export`` is now a keyword. -- ``assert`` is now implemented in pure Nimrod as a template; it's easy +- ``assert`` is now implemented in pure Nimrod as a template; it's easy to implement your own assertion templates with ``system.astToStr``. @@ -889,7 +1105,7 @@ Language Additions - Return types may be of the type ``var T`` to return an l-value. - The error pragma can now be used to mark symbols whose *usage* should trigger a compile-time error. -- There is a new ``discardable`` pragma that can be used to mark a routine +- There is a new ``discardable`` pragma that can be used to mark a routine so that its result can be discarded implicitly. - Added a new ``noinit`` pragma to prevent automatic initialization to zero of variables. @@ -900,7 +1116,7 @@ Language Additions - ``bind`` (used for symbol binding in templates and generics) is now a declarative statement. - Nimrod now supports single assignment variables via the ``let`` statement. -- Iterators named ``items`` and ``pairs`` are implicitly invoked when +- Iterators named ``items`` and ``pairs`` are implicitly invoked when an explicit iterator is missing. - The slice assignment ``a[i..j] = b`` where ``a`` is a sequence or string now supports *splicing*. @@ -918,9 +1134,9 @@ Compiler Additions definitions. - Added a ``--nimcache:PATH`` configuration option for control over the output directory for generated code. -- The ``--genScript`` option now produces different compilation scripts +- The ``--genScript`` option now produces different compilation scripts which do not contain absolute paths. -- Added ``--cincludes:dir``, ``--clibdir:lib`` configuration options for +- Added ``--cincludes:dir``, ``--clibdir:lib`` configuration options for modifying the C compiler's header/library search path in cross-platform way. - Added ``--clib:lib`` configuration option for specifying additional C libraries to be linked. @@ -935,7 +1151,7 @@ Compiler Additions are declared with the ``TaintedString`` string type. If the taint mode is turned on it is a distinct string type which helps to detect input validation errors. -- The compiler now supports the compilation cache via ``--symbolFiles:on``. +- The compiler now supports the compilation cache via ``--symbolFiles:on``. This potentially speeds up compilations by an order of magnitude, but is still highly experimental! - Added ``--import:file`` and ``--include:file`` configuration options @@ -947,7 +1163,7 @@ Compiler Additions for ``on|off`` switches in pragmas. In order to not break existing code, ``on`` and ``off`` are now aliases for ``true`` and ``false`` and declared in the system module. -- The compiler finally supports **closures**. This is a preliminary +- The compiler finally supports **closures**. This is a preliminary implementation, which does not yet support nestings deeper than 1 level and still has many known bugs. @@ -955,7 +1171,7 @@ Compiler Additions Library Additions ----------------- -- Added ``system.allocShared``, ``system.allocShared0``, +- Added ``system.allocShared``, ``system.allocShared0``, ``system.deallocShared``, ``system.reallocShared``. - Slicing as implemented by the system module now supports *splicing*. - Added explicit channels for thread communication. @@ -969,8 +1185,8 @@ Library Additions - Added ``os.isAbsolute``, ``os.dynLibFormat``, ``os.isRootDir``, ``os.parentDirs``. - Added ``parseutils.interpolatedFragments``. -- Added ``macros.treeRepr``, ``macros.lispRepr``, ``macros.dumpTree``, - ``macros.dumpLisp``, ``macros.parseExpr``, ``macros.parseStmt``, +- Added ``macros.treeRepr``, ``macros.lispRepr``, ``macros.dumpTree``, + ``macros.dumpLisp``, ``macros.parseExpr``, ``macros.parseStmt``, ``macros.getAst``. - Added ``locks`` core module for more flexible locking support. - Added ``irc`` module. @@ -982,7 +1198,7 @@ Library Additions - Added ``actors`` module. - Added ``algorithm`` module for generic ``sort``, ``reverse`` etc. operations. - Added ``osproc.startCmd``, ``osproc.execCmdEx``. -- The ``osproc`` module now uses ``posix_spawn`` instead of ``fork`` +- The ``osproc`` module now uses ``posix_spawn`` instead of ``fork`` and ``exec`` on Posix systems. Define the symbol ``useFork`` to revert to the old implementation. - Added ``intsets.assign``. @@ -1017,20 +1233,20 @@ Bugfixes Changes affecting backwards compatibility ----------------------------------------- -- Operators starting with ``^`` are now right-associative and have the highest +- Operators starting with ``^`` are now right-associative and have the highest priority. - Deprecated ``os.getApplicationFilename``: Use ``os.getAppFilename`` instead. - Deprecated ``os.getApplicationDir``: Use ``os.getAppDir`` instead. - Deprecated ``system.copy``: Use ``substr`` or string slicing instead. - Changed and documented how generalized string literals work: The syntax ``module.re"abc"`` is now supported. -- Changed the behaviour of ``strutils.%``, ``ropes.%`` +- Changed the behaviour of ``strutils.%``, ``ropes.%`` if both notations ``$#`` and ``$i`` are involved. -- The ``pegs`` and ``re`` modules distinguish between ``replace`` +- The ``pegs`` and ``re`` modules distinguish between ``replace`` and ``replacef`` operations. - The pointer dereference operation ``p^`` is deprecated and might become - ``^p`` in later versions or be dropped entirely since it is rarely used. - Use the new notation ``p[]`` in the rare cases where you need to + ``^p`` in later versions or be dropped entirely since it is rarely used. + Use the new notation ``p[]`` in the rare cases where you need to dereference a pointer explicitly. - ``system.readFile`` does not return ``nil`` anymore but raises an ``EIO`` exception instead. @@ -1046,15 +1262,15 @@ Language Additions - Case statement branches support constant sets for programming convenience. - Tuple unpacking is not enforced in ``for`` loops anymore. - The compiler now supports array, sequence and string slicing. -- A field in an ``enum`` may be given an explicit string representation. - This yields more maintainable code than using a constant +- A field in an ``enum`` may be given an explicit string representation. + This yields more maintainable code than using a constant ``array[TMyEnum, string]`` mapping. - Indices in array literals may be explicitly given, enhancing readability: ``[enumValueA: "a", enumValueB: "b"]``. -- Added thread support via the ``threads`` core module and +- Added thread support via the ``threads`` core module and the ``--threads:on`` command line switch. - The built-in iterators ``system.fields`` and ``system.fieldPairs`` can be - used to iterate over any field of a tuple. With this mechanism operations + used to iterate over any field of a tuple. With this mechanism operations like ``==`` and ``hash`` are lifted to tuples. - The slice ``..`` is now a first-class operator, allowing code like: ``x in 1000..100_000``. @@ -1064,12 +1280,12 @@ Compiler Additions ------------------ - The compiler supports IDEs via the new group of ``idetools`` command line - options. -- The *interactive mode* (REPL) has been improved and documented for the + options. +- The *interactive mode* (REPL) has been improved and documented for the first time. - The compiler now might use hashing for string case statements depending on the number of string literals in the case statement. - + Library Additions ----------------- @@ -1091,11 +1307,11 @@ Library Additions ``\title``, ``\white``. - Pegs support the new built-in ``\skip`` operation. - Pegs support the ``$`` and ``^`` anchors. -- Additional operations were added to the ``complex`` module. +- Additional operations were added to the ``complex`` module. - Added ``strutils.formatFloat``, ``strutils.formatBiggestFloat``. - Added unary ``<`` for nice looking excluding upper bounds in ranges. - Added ``math.floor``. -- Added ``system.reset`` and a version of ``system.open`` that +- Added ``system.reset`` and a version of ``system.open`` that returns a ``TFile`` and raises an exception in case of an error. - Added a wrapper for ``redis``. - Added a wrapper for ``0mq`` via the ``zmq`` module. @@ -1121,12 +1337,12 @@ Bugfixes - Bugfix: Passing a ``ref`` pointer to the untyped ``pointer`` type is invalid. - Bugfix: Updated ``keyval`` example. - Bugfix: ``system.splitChunk`` still contained code for debug output. -- Bugfix: ``dialogs.ChooseFileToSave`` uses ``STOCK_SAVE`` instead of +- Bugfix: ``dialogs.ChooseFileToSave`` uses ``STOCK_SAVE`` instead of ``STOCK_OPEN`` for the GTK backend. - Bugfix: Various bugs concerning exception handling fixed. - Bugfix: ``low(somestring)`` crashed the compiler. - Bugfix: ``strutils.endsWith`` lacked range checking. -- Bugfix: Better detection for AMD64 on Mac OS X. +- Bugfix: Better detection for AMD64 on Mac OS X. Changes affecting backwards compatibility @@ -1135,7 +1351,7 @@ Changes affecting backwards compatibility - Reversed parameter order for ``os.copyFile`` and ``os.moveFile``!!! - Procs not marked as ``procvar`` cannot only be passed to a procvar anymore, unless they are used in the same module. -- Deprecated ``times.getStartMilsecs``: Use ``epochTime`` or ``cpuTime`` +- Deprecated ``times.getStartMilsecs``: Use ``epochTime`` or ``cpuTime`` instead. - Removed ``system.OpenFile``. - Removed ``system.CloseFile``. @@ -1144,7 +1360,7 @@ Changes affecting backwards compatibility - Removed ``strutils.splitLinesSeq``. - Removed ``strutils.splitSeq``. - Removed ``strutils.toString``. -- If a DLL cannot be loaded (via the ``dynlib`` pragma) ``EInvalidLibrary`` +- If a DLL cannot be loaded (via the ``dynlib`` pragma) ``EInvalidLibrary`` is not raised anymore. Instead ``system.quit()`` is called. This is because raising an exception requires heap allocations. However the memory manager might be contained in the DLL that failed to load. @@ -1154,19 +1370,19 @@ Changes affecting backwards compatibility Additions --------- -- The ``{.compile: "file.c".}`` pragma uses a CRC check to see if the file +- The ``{.compile: "file.c".}`` pragma uses a CRC check to see if the file needs to be recompiled. -- Added ``system.reopen``. +- Added ``system.reopen``. - Added ``system.getCurrentException``. - Added ``system.appType``. -- Added ``system.compileOption``. -- Added ``times.epochTime`` and ``times.cpuTime``. +- Added ``system.compileOption``. +- Added ``times.epochTime`` and ``times.cpuTime``. - Implemented explicit type arguments for generics. - Implemented ``{.size: sizeof(cint).}`` pragma for enum types. This is useful for interfacing with C. - Implemented ``{.pragma.}`` pragma for user defined pragmas. - Implemented ``{.extern.}`` pragma for better control of name mangling. -- The ``importc`` and ``exportc`` pragmas support format strings: +- The ``importc`` and ``exportc`` pragmas support format strings: ``proc p{.exportc: "nim_$1".}`` exports ``p`` as ``nim_p``. This is useful for user defined pragmas. - The standard library can be built as a DLL. Generating DLLs has been @@ -1174,7 +1390,7 @@ Additions - Added ``expat`` module. - Added ``json`` module. - Added support for a *Tiny C* backend. Currently this only works on Linux. - You need to bootstrap with ``-d:tinyc`` to enable Tiny C support. Nimrod + You need to bootstrap with ``-d:tinyc`` to enable Tiny C support. Nimrod can then execute code directly via ``nimrod run myfile``. @@ -1193,9 +1409,9 @@ Bugfixes zeros. - Fixed a bug in ``os.setFilePermissions`` for Windows. - An overloadable symbol can now have the same name as an imported module. -- Fixed a serious bug in ``strutils.cmpIgnoreCase``. -- Fixed ``unicode.toUTF8``. -- The compiler now rejects ``'\n'`` (use ``"\n"`` instead). +- Fixed a serious bug in ``strutils.cmpIgnoreCase``. +- Fixed ``unicode.toUTF8``. +- The compiler now rejects ``'\n'`` (use ``"\n"`` instead). - ``times.getStartMilsecs()`` now works on Mac OS X. - Fixed a bug in ``pegs.match`` concerning start offsets. - Lots of other little bugfixes. @@ -1227,14 +1443,14 @@ Additions - Added ``graphics`` module. - Added ``colors`` module. - Many wrappers now do not contain redundant name prefixes (like ``GTK_``, - ``lua``). The old wrappers are still available in ``lib/oldwrappers``. + ``lua``). The old wrappers are still available in ``lib/oldwrappers``. You can change your configuration file to use these. - Triple quoted strings allow for ``"`` in more contexts. - ``""`` within raw string literals stands for a single quotation mark. - Arguments to ``openArray`` parameters can be left out. - More extensive subscript operator overloading. (To be documented.) - The documentation generator supports the ``.. raw:: html`` directive. -- The Pegs module supports back references via the notation ``$capture_index``. +- The Pegs module supports back references via the notation ``$capture_index``. Changes affecting backwards compatibility @@ -1242,9 +1458,9 @@ Changes affecting backwards compatibility - Overloading of the subscript operator only works if the type does not provide a built-in one. -- The search order for libraries which is affected by the ``path`` option - has been reversed, so that the project's path is searched before - the standard library's path. +- The search order for libraries which is affected by the ``path`` option + has been reversed, so that the project's path is searched before + the standard library's path. - The compiler does not include a Pascal parser for bootstrapping purposes any more. Instead there is a ``pas2nim`` tool that contains the old functionality. - The procs ``os.copyFile`` and ``os.moveFile`` have been deprecated @@ -1271,7 +1487,7 @@ Bugfixes - Method call syntax for iterators works again (``for x in lines.split()``). - Fixed a typo in ``removeDir`` for POSIX that lead to an infinite recursion. - The compiler now checks that module filenames are valid identifiers. -- Empty patterns for the ``dynlib`` pragma are now possible. +- Empty patterns for the ``dynlib`` pragma are now possible. - ``os.parseCmdLine`` returned wrong results for trailing whitespace. - Inconsequent tuple usage (using the same tuple with and without named fields) does not crash the code generator anymore. @@ -1300,11 +1516,11 @@ Changes affecting backwards compatibility has changed. - ``os.splitFile(".xyz")`` now returns ``("", ".xyz", "")`` instead of ``("", "", ".xyz")``. So filenames starting with a dot are handled - differently. + differently. - ``strutils.split(s: string, seps: set[char])`` never yields the empty string - anymore. This behaviour is probably more appropriate for whitespace splitting. + anymore. This behaviour is probably more appropriate for whitespace splitting. - The compiler now stops after the ``--version`` command line switch. -- Removed support for enum inheritance in the parser; enum inheritance has +- Removed support for enum inheritance in the parser; enum inheritance has never been documented anyway. - The ``msg`` field of ``system.E_base`` has now the type ``string``, instead of ``cstring``. This improves memory safety. |