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/semtypes.nim | 2 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 21 | ||||
-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/system/jssys.nim | 18 | ||||
-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 | 229 |
20 files changed, 600 insertions, 192 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/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/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/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/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 cb4f0006f..7cf1ae28f 100644 --- a/web/news.txt +++ b/web/news.txt @@ -4,7 +4,7 @@ News .. 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,7 +46,7 @@ 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 @@ -54,6 +54,17 @@ News 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 ----------------- @@ -61,8 +72,8 @@ News - Added multipart param to httpclient's ``post`` and ``postContent`` together with a ``newMultipartData`` proc. - Added `%*` operator for JSON. - - The compiler is now a Nimble package. - - + - The compiler is now available as Nimble package for c2nim. + Bugfixes -------- @@ -103,8 +114,7 @@ News (`#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 -" + - 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>`_) @@ -116,8 +126,7 @@ News (`#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 - " + - 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>`_) @@ -151,14 +160,11 @@ News (`#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 f -ail" + - 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 procedur -es" + - 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"" + - 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>`_) @@ -196,8 +202,7 @@ es" (`#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 tupl -es" + - 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>`_) @@ -225,13 +230,11 @@ es" (`#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. -" + - 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 er -ror" + - 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>`_) @@ -466,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 @@ -534,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. @@ -549,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. @@ -608,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)) @@ -638,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 @@ -679,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. @@ -728,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 @@ -750,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>`_. @@ -763,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 @@ -779,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. @@ -816,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 @@ -894,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``. @@ -917,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. @@ -928,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. @@ -960,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. @@ -985,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. @@ -1011,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. @@ -1019,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``. @@ -1061,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``. @@ -1073,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. @@ -1083,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``. @@ -1102,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. @@ -1113,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*. @@ -1131,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. @@ -1148,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 @@ -1160,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. @@ -1168,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. @@ -1182,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. @@ -1195,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``. @@ -1230,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. @@ -1259,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``. @@ -1277,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 ----------------- @@ -1304,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. @@ -1334,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 @@ -1348,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``. @@ -1357,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. @@ -1367,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 @@ -1387,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``. @@ -1406,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. @@ -1440,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 @@ -1455,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 @@ -1484,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. @@ -1513,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. |